Skip to content

Commit

Permalink
MDL-14679 fixed remaining old style update_record()s
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 3, 2010
1 parent a9637e7 commit dd88de0
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 155 deletions.
35 changes: 16 additions & 19 deletions admin/xmldb/actions/test/test.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1024,27 +1024,24 @@ function invoke() {
/// Calculate its length
$textlen = $textlib->strlen($basetext);
$imglen = strlen($basetext);
if ($DB->update_record('newnameforthetable', $rec)) {
if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
$newtextlen = $textlib->strlen($new->intro);
$newimglen = strlen($new->avatar);
if ($basetext === $new->avatar && $basetext === $new->intro) {
$test->sql = array($newtextlen . ' cc. (text) sent and received ok',
$newimglen . ' bytes (binary) sent and received ok');
$test->status = true;
$DB->update_record('newnameforthetable', $rec);
if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
$newtextlen = $textlib->strlen($new->intro);
$newimglen = strlen($new->avatar);
if ($basetext === $new->avatar && $basetext === $new->intro) {
$test->sql = array($newtextlen . ' cc. (text) sent and received ok',
$newimglen . ' bytes (binary) sent and received ok');
$test->status = true;
} else {
if ($rec->avatar !== $new->avatar) {
$test->error = $DB->get_last_error();
$test->sql = array($newimglen . ' bytes (binary) transfer failed. Data changed!');
$test->status = false;
} else {
if ($rec->avatar !== $new->avatar) {
$test->error = $DB->get_last_error();
$test->sql = array($newimglen . ' bytes (binary) transfer failed. Data changed!');
$test->status = false;
} else {
$test->error = $DB->get_last_error();
$test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
$test->status = false;
}
$test->error = $DB->get_last_error();
$test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
$test->status = false;
}
} else {
$test->error = $DB->get_last_error();
}
} else {
$test->error = $DB->get_last_error();
Expand Down
7 changes: 2 additions & 5 deletions auth/db/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,8 @@ function sync_users($do_updates=false) {
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->auth = 'nologin';
if ($DB->update_record('user', $updateuser)) {
echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
} else {
echo "\t"; print_string('auth_dbsuspendusererror', 'auth_db', $user->username); echo "\n";
}
$DB->update_record('user', $updateuser);
echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
}
}
}
Expand Down
14 changes: 4 additions & 10 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,11 +715,8 @@ function sync_users($do_updates=true) {
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->auth = 'nologin';
if ($DB->update_record('user', $updateuser)) {
echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
} else {
echo "\t"; print_string('auth_dbsuspendusererror', 'auth_db', $user->username); echo "\n";
}
$DB->update_record('user', $updateuser);
echo "\t"; print_string('auth_dbsuspenduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
}
}
} else {
Expand All @@ -743,11 +740,8 @@ function sync_users($do_updates=true) {
$updateuser = new object();
$updateuser->id = $user->id;
$updateuser->auth = $this->authtype;
if ($DB->update_record('user', $updateuser)) {
echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
} else {
echo "\t"; print_string('auth_dbrevivedusererror', 'auth_db', $user->username); echo "\n";
}
$DB->update_record('user', $updateuser);
echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
}
} else {
print_string('nouserentriestorevive', 'auth_ldap');
Expand Down
5 changes: 2 additions & 3 deletions blog/external_blog_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@
$external->filtertags = $data->filtertags;
$external->timemodified = mktime();

if ($DB->update_record('blog_external', $external)) {
tag_set('blog_external', $external->id, explode(',', $data->autotags));
}
$DB->update_record('blog_external', $external);
tag_set('blog_external', $external->id, explode(',', $data->autotags));

} else {
print_error('wrongexternalid', 'blog');
Expand Down
104 changes: 40 additions & 64 deletions mod/assignment/type/upload/assignment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,19 +476,11 @@ function upload_notes() {
$updated->timemodified = time();
$updated->data1 = $data->text;

if ($DB->update_record('assignment_submissions', $updated)) {
add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
redirect($returnurl);
$submission = $this->get_submission($USER->id);
$this->update_grade($submission);

} else {
$this->view_header(get_string('notes', 'assignment'));
echo $OUTPUT->notification(get_string('notesupdateerror', 'assignment'));
echo $OUTPUT->continue_button($returnurl);
$this->view_footer();
die;
}
$DB->update_record('assignment_submissions', $updated);
add_to_log($this->course->id, 'assignment', 'upload', 'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
redirect($returnurl);
$submission = $this->get_submission($USER->id);
$this->update_grade($submission);
}

/// show notes edit form
Expand Down Expand Up @@ -550,28 +542,27 @@ function upload_file($mform, $options) {
$updates = new object();
$updates->id = $submission->id;
$updates->timemodified = time();
if ($DB->update_record('assignment_submissions', $updates)) {
add_to_log($this->course->id, 'assignment', 'upload',
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$this->update_grade($submission);
if (!$this->drafts_tracked()) {
$this->email_teachers($submission);
}
$DB->update_record('assignment_submissions', $updates);
add_to_log($this->course->id, 'assignment', 'upload',
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$this->update_grade($submission);
if (!$this->drafts_tracked()) {
$this->email_teachers($submission);
}

// send files to event system
$files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
// Let Moodle know that assessable files were uploaded (eg for plagiarism detection)
$eventdata = new object();
$eventdata->modulename = 'assignment';
$eventdata->cmid = $this->cm->id;
$eventdata->itemid = $submission->id;
$eventdata->courseid = $this->course->id;
$eventdata->userid = $USER->id;
if ($files) {
$eventdata->files = $files;
}
events_trigger('assessable_file_uploaded', $eventdata);
// send files to event system
$files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id);
// Let Moodle know that assessable files were uploaded (eg for plagiarism detection)
$eventdata = new object();
$eventdata->modulename = 'assignment';
$eventdata->cmid = $this->cm->id;
$eventdata->itemid = $submission->id;
$eventdata->courseid = $this->course->id;
$eventdata->userid = $USER->id;
if ($files) {
$eventdata->files = $files;
}
events_trigger('assessable_file_uploaded', $eventdata);
$returnurl = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id));
redirect($returnurl);
}
Expand Down Expand Up @@ -670,19 +661,12 @@ function finalize($forcemode=null) {
$updated->data2 = ASSIGNMENT_STATUS_SUBMITTED;
$updated->timemodified = time();

if ($DB->update_record('assignment_submissions', $updated)) {
add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$submission = $this->get_submission($userid);
$this->update_grade($submission);
$this->email_teachers($submission);
} else {
$this->view_header(get_string('submitformarking', 'assignment'));
echo $OUTPUT->notification(get_string('finalizeerror', 'assignment'));
echo $OUTPUT->continue_button($returnurl);
$this->view_footer();
die;
}
$DB->update_record('assignment_submissions', $updated);
add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$submission = $this->get_submission($userid);
$this->update_grade($submission);
$this->email_teachers($submission);

// Trigger assessable_files_done event to show files are complete
$eventdata = new object();
Expand Down Expand Up @@ -717,12 +701,11 @@ function finalizeclose() {
$updated->id = $submission->id;
$updated->data2 = ASSIGNMENT_STATUS_CLOSED;

if ($DB->update_record('assignment_submissions', $updated)) {
add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$submission = $this->get_submission($userid, false, true);
$this->update_grade($submission);
}
$DB->update_record('assignment_submissions', $updated);
add_to_log($this->course->id, 'assignment', 'upload', //TODO: add finalize action to log
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$submission = $this->get_submission($userid, false, true);
$this->update_grade($submission);
redirect($returnurl);
}

Expand All @@ -745,18 +728,11 @@ function unfinalize($forcemode=null) {
$updated = new object();
$updated->id = $submission->id;
$updated->data2 = '';
if ($DB->update_record('assignment_submissions', $updated)) {
//TODO: add unfinalize action to log
add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$submission = $this->get_submission($userid);
$this->update_grade($submission);
} else {
$this->view_header(get_string('submitformarking', 'assignment'));
echo $OUTPUT->notification(get_string('unfinalizeerror', 'assignment'));
echo $OUTPUT->continue_button($returnurl);
$this->view_footer();
die;
}
$DB->update_record('assignment_submissions', $updated);
//TODO: add unfinalize action to log
add_to_log($this->course->id, 'assignment', 'view submission', 'submissions.php?id='.$this->assignment->id, $this->assignment->id, $this->cm->id);
$submission = $this->get_submission($userid);
$this->update_grade($submission);
}

if ($forcemode==null) {
Expand Down
21 changes: 10 additions & 11 deletions mod/chat/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function chat_add_instance($chat) {
*
* @global object
* @param object $chat
* @return int
* @return bool
*/
function chat_update_instance($chat) {
global $DB;
Expand All @@ -145,22 +145,21 @@ function chat_update_instance($chat) {
$chat->id = $chat->instance;


if ($returnid = $DB->update_record("chat", $chat)) {
$DB->update_record("chat", $chat);

$event = new object();
$event = new object();

if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'chat', 'instance'=>$chat->id))) {
if ($event->id = $DB->get_field('event', 'id', array('modulename'=>'chat', 'instance'=>$chat->id))) {

$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->timestart = $chat->chattime;
$event->name = $chat->name;
$event->description = format_module_intro('chat', $chat, $chat->coursemodule);
$event->timestart = $chat->chattime;

$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
}
$calendarevent = calendar_event::load($event->id);
$calendarevent->update($event);
}

return $returnid;
return true;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions mod/data/restorelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ function data_decode_content_links_caller($restore) {

/// Update record if any field changed
if($changed) {
$status = $DB->update_record("data",$newdata);
$DB->update_record("data",$newdata);
}

/// Do some output
Expand Down Expand Up @@ -650,7 +650,7 @@ function data_decode_content_links_caller($restore) {
if ($result != $content) {
/// Update record
$comment->content = $result;
$status = $DB->update_record("data_comments",$comment);
$DB->update_record("data_comments",$comment);
if (debugging()) {
if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
Expand Down Expand Up @@ -718,7 +718,7 @@ function data_decode_content_links_caller($restore) {
$cnt->content4 = $result4;
}
/// Update record with the changed fields
$status = $DB->update_record("data_content",$cnt);
$DB->update_record("data_content",$cnt);
if (debugging()) {
if (!defined('RESTORE_SILENTLY')) {
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
Expand Down
5 changes: 2 additions & 3 deletions mod/data/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@

// Check for multiple tags, only need to check for add template.
if ($mode != 'addtemplate' or data_tags_check($data->id, $newtemplate->{$mode})) {
if ($DB->update_record('data', $newtemplate)) {
echo $OUTPUT->notification(get_string('templatesaved', 'data'), 'notifysuccess');
}
$DB->update_record('data', $newtemplate);
echo $OUTPUT->notification(get_string('templatesaved', 'data'), 'notifysuccess');
}
add_to_log($course->id, 'data', 'templates saved', "templates.php?id=$cm->id&amp;d=$data->id", $data->id, $cm->id);
}
Expand Down
7 changes: 3 additions & 4 deletions mod/data/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@

$PAGE->set_title($title);
$PAGE->set_heading($course->fullname);

echo $OUTPUT->header();

/// Check to see if groups are being used here
Expand Down Expand Up @@ -407,9 +407,8 @@
if ($approverecord->dataid == $data->id) { // Must be from this database
$newrecord->id = $approverecord->id;
$newrecord->approved = 1;
if ($DB->update_record('data_records', $newrecord)) {
echo $OUTPUT->notification(get_string('recordapproved','data'), 'notifysuccess');
}
$DB->update_record('data_records', $newrecord);
echo $OUTPUT->notification(get_string('recordapproved','data'), 'notifysuccess');
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions mod/feedback/item/label/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,8 @@ function postupdate($item) {

// $item = new object();
// $item->id = $data->id
if($DB->update_record('feedback_item', $item)) {
return $item->id;
}
return false;
$DB->update_record('feedback_item', $item);
return $item->id;
}

function get_hasvalue() {
Expand Down
5 changes: 2 additions & 3 deletions mod/forum/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ function xmldb_forum_upgrade($oldversion) {
$file_record = array('contextid'=>$context->id, 'component'=>'mod_form', 'filearea'=>$filearea, 'itemid'=>$post->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$post->userid);
if ($fs->create_file_from_pathname($file_record, $filepath)) {
$post->attachment = '1';
if ($DB->update_record('forum_posts', $post)) {
unlink($filepath);
}
$DB->update_record('forum_posts', $post);
unlink($filepath);
}
}

Expand Down
5 changes: 2 additions & 3 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -6762,9 +6762,8 @@ function forum_discussion_update_last_post($discussionid) {
$discussionobject->id = $discussionid;
$discussionobject->usermodified = $lastpost->userid;
$discussionobject->timemodified = $lastpost->modified;
if ($DB->update_record('forum_discussions', $discussionobject)) {
return $lastpost->id;
}
$DB->update_record('forum_discussions', $discussionobject);
return $lastpost->id;
}

// To get here either we couldn't find a post for the discussion (weird)
Expand Down
5 changes: 2 additions & 3 deletions mod/glossary/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ function xmldb_glossary_upgrade($oldversion) {
$file_record = array('contextid'=>$context->id, 'component'=>'mod_glossary', 'filearea'=>$filearea, 'itemid'=>$entry->id, 'filepath'=>'/', 'filename'=>$filename, 'userid'=>$entry->userid);
if ($fs->create_file_from_pathname($file_record, $filepath)) {
$entry->attachment = '1';
if ($DB->update_record('glossary_entries', $entry)) {
unlink($filepath);
}
$DB->update_record('glossary_entries', $entry);
unlink($filepath);
}
}

Expand Down
Loading

0 comments on commit dd88de0

Please sign in to comment.