Skip to content

Commit

Permalink
MDL-18293 $DB->something is using exceptions, no need for ifs there, …
Browse files Browse the repository at this point in the history
…removing useless strings
  • Loading branch information
skodak committed Jun 3, 2009
1 parent 7826abc commit 2a7eff4
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 59 deletions.
37 changes: 12 additions & 25 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,6 @@ function do_delete($post) {
tag_set('post', $post->id, array());

add_to_log(SITEID, 'blog', 'delete', 'index.php?userid='. $post->userid, 'deleted blog entry with entry id# '. $post->id);

if (!$status) {
print_error('deleteposterror', 'blog', $returnurl);
}
}

/**
Expand All @@ -173,23 +169,18 @@ function do_add($post, $blogeditform) {
$post->created = time();

// Insert the new blog entry.
if ($post->id = $DB->insert_record('post', $post)) {
// Add blog attachment
if ($blogeditform->get_new_filename('attachment')) {
if ($blogeditform->save_stored_file('attachment', SYSCONTEXTID, 'blog', $post->id, '/', false, $USER->id)) {
$DB->set_field("post", "attachment", 1, array("id"=>$post->id));
}
$post->id = $DB->insert_record('post', $post);
// Add blog attachment
if ($blogeditform->get_new_filename('attachment')) {
if ($blogeditform->save_stored_file('attachment', SYSCONTEXTID, 'blog', $post->id, '/', false, $USER->id)) {
$DB->set_field("post", "attachment", 1, array("id"=>$post->id));
}

// Update tags.
tag_set('post', $post->id, $post->tags);

add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject);

} else {
print_error('deleteposterror', 'blog', $returnurl);
}

// Update tags.
tag_set('post', $post->id, $post->tags);

add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$post->userid.'&postid='.$post->id, $post->subject);
}

/**
Expand All @@ -212,14 +203,10 @@ function do_edit($post, $blogeditform) {
}

// Update record
if ($DB->update_record('post', $post)) {
tag_set('post', $post->id, $post->tags);
$DB->update_record('post', $post);
tag_set('post', $post->id, $post->tags);

add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$USER->id.'&postid='.$post->id, $post->subject);

} else {
print_error('deleteposterror', 'blog', $returnurl);
}
add_to_log(SITEID, 'blog', 'update', 'index.php?userid='.$USER->id.'&postid='.$post->id, $post->subject);
}

?>
1 change: 0 additions & 1 deletion lang/en_utf8/blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
$string['courseblogs'] = 'Users can only see blogs for people who share a course';
$string['donothaveblog'] = 'You do not have your own blog, sorry.';
$string['deleteotagswarn'] = 'Are you sure you want to remove this / these tags <br />from all blog posts and remove it from the system?';
$string['deleteposterror'] = 'Error occured while deleting post';
$string['disableblogs'] = 'Disable blog system completely';
$string['emptybody'] = 'Blog entry body can not be empty';
$string['emptytitle'] = 'Blog entry title can not be empty';
Expand Down
1 change: 0 additions & 1 deletion lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
$string['cannotcreatetempdir'] = 'Cannot create temp directory';
$string['cannotcreatesitedir'] = 'Cannot create site folder. The site administrator needs to fix the file permissions.';
$string['cannotcreateuploaddir'] = 'Cannot create upload folder. The site administrator needs to fix the file permissions.';
$string['cannotcreateuser'] = 'Error creating user record';
$string['cannotcreateorfindstructs'] = 'Error finding or creating section structures for this course';
$string['cannotcreatepopupwin'] = 'Undefined element - cannot create pop-up window';
$string['cannotcustomisefiltersblockuser'] = 'You cannot customise filters settings in user or block contexts.';
Expand Down
9 changes: 2 additions & 7 deletions lib/grade/grade_object.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ public function update($source=null) {

$data = $this->get_record_data();

if (!$DB->update_record($this->table, $data)) {
return false;
}
$DB->update_record($this->table, $data);

if (empty($CFG->disablegradehistory)) {
unset($data->timecreated);
Expand Down Expand Up @@ -290,10 +288,7 @@ public function insert($source=null) {

$data = $this->get_record_data();

if (!$this->id = $DB->insert_record($this->table, $data)) {
debugging("Could not insert object into db");
return false;
}
$this->id = $DB->insert_record($this->table, $data);

// set all object properties from real db data
$this->update_from_db();
Expand Down
2 changes: 1 addition & 1 deletion lib/grade/grade_outcome.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function use_in($courseid) {
$goc = new object();
$goc->courseid = $courseid;
$goc->outcomeid = $this->id;
return (bool)$DB->insert_record('grade_outcomes_courses', $goc);
$DB->insert_record('grade_outcomes_courses', $goc);
}
return true;
}
Expand Down
16 changes: 7 additions & 9 deletions mod/glossary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ function glossary_add_instance($glossary) {
print_error('unknowformat', '', '', $glossary->displayformat);
}

if ($returnid = $DB->insert_record("glossary", $glossary)) {
$glossary->id = $returnid;
glossary_grade_item_update($glossary);
}
$returnid = $DB->insert_record("glossary", $glossary);
$glossary->id = $returnid;
glossary_grade_item_update($glossary);

return $returnid;
}
Expand Down Expand Up @@ -127,12 +126,11 @@ function glossary_update_instance($glossary) {
print_error('unknowformat', '', '', $glossary->displayformat);
}

if ($return = $DB->update_record("glossary", $glossary)) {
if ($glossary->defaultapproval) {
$DB->execute("UPDATE {glossary_entries} SET approved = 1 where approved <> 1 and glossaryid = ?", array($glossary->id));
}
glossary_grade_item_update($glossary);
$return = $DB->update_record("glossary", $glossary);
if ($glossary->defaultapproval) {
$DB->execute("UPDATE {glossary_entries} SET approved = 1 where approved <> 1 and glossaryid = ?", array($glossary->id));
}
glossary_grade_item_update($glossary);

return $return;
}
Expand Down
8 changes: 2 additions & 6 deletions user/editadvanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,11 @@
$usernew->mnethostid = $CFG->mnet_localhost_id; // always local user
$usernew->confirmed = 1;
$usernew->password = hash_internal_user_password($usernew->newpassword);
if (!$usernew->id = $DB->insert_record('user', $usernew)) {
print_error('cannotcreateuser');
}
$usernew->id = $DB->insert_record('user', $usernew);
$usercreated = true;

} else {
if (!$DB->update_record('user', $usernew)) {
print_error('cannotupdateuser', 'message');
}
$DB->update_record('user', $usernew);
// pass a true $userold here
if (! $authplugin->user_update($user, $userform->get_data())) {
// auth update failed, rollback for moodle
Expand Down
15 changes: 6 additions & 9 deletions user/emailupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,12 @@
print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
} else {
// update user email
if (!$DB->set_field('user', 'email', $user->email, array('id' => $user->id))) {
print_error('cannotupdateuser');
} else {
events_trigger('user_updated', $user);
$a->email = $user->email;
$stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth', $a);
print_box($stremailupdatesuccess, 'center');
print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
}
$DB->set_field('user', 'email', $user->email, array('id' => $user->id));
events_trigger('user_updated', $user);
$a->email = $user->email;
$stremailupdatesuccess = get_string('auth_emailupdatesuccess', 'auth', $a);
print_box($stremailupdatesuccess, 'center');
print_continue("$CFG->wwwroot/user/view.php?id=$user->id");
}

} else {
Expand Down

0 comments on commit 2a7eff4

Please sign in to comment.