Skip to content

Commit

Permalink
MDL-14679 fixed multiple old style insert_record calls, we throw exce…
Browse files Browse the repository at this point in the history
…ptions now from DML
  • Loading branch information
skodak committed Sep 3, 2010
1 parent 0424cfe commit 9d97f08
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 86 deletions.
5 changes: 2 additions & 3 deletions admin/generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,9 +896,8 @@ public function generate_module_content($course_users, $courses, $modules) {
$entry->timemodified = time();
$entry->teacherentry = 0;
$entry->approved = 1;
if ($DB->insert_record('glossary_entries', $entry)) {
$entries_count++;
}
$DB->insert_record('glossary_entries', $entry);
$entries_count++;
}
}
if ($entries_count > 0 && !$this->get('quiet')) {
Expand Down
17 changes: 8 additions & 9 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,18 +340,17 @@ public function add() {
$this->created = time();

// Insert the new blog entry.
if ($this->id = $DB->insert_record('post', $this)) {
$this->id = $DB->insert_record('post', $this);

// Update tags.
$this->add_tags_info();
// Update tags.
$this->add_tags_info();

if (!empty($CFG->useblogassociations)) {
$this->add_associations();
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->id, $this->subject);
}

tag_set('post', $this->id, $this->tags);
if (!empty($CFG->useblogassociations)) {
$this->add_associations();
add_to_log(SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->id, $this->subject);
}

tag_set('post', $this->id, $this->tags);
}

/**
Expand Down
41 changes: 16 additions & 25 deletions enrol/imsenterprise/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,9 @@ function process_group_tag($tagcontents){
// Else if we're allowed to create new categories, let's create this one
$newcat->name = $group->category;
$newcat->visible = 0;
if($catid = $DB->insert_record('course_categories', $newcat)){
$course->category = $catid;
$this->log_line("Created new (hidden) category, #$catid: $newcat->name");
}else{
$this->log_line('Failed to create new category: '.$newcat->name);
}
$catid = $DB->insert_record('course_categories', $newcat);
$course->category = $catid;
$this->log_line("Created new (hidden) category, #$catid: $newcat->name");
}else{
// If not found and not allowed to create, stick with default
$this->log_line('Category '.$group->category.' not found in Moodle database, so using default category instead.');
Expand All @@ -394,24 +391,21 @@ function process_group_tag($tagcontents){
// Choose a sort order that puts us at the start of the list!
$course->sortorder = 0;

if ($courseid = $DB->insert_record('course', $course)) {
$courseid = $DB->insert_record('course', $course);

// Setup the blocks
$course = $DB->get_record('course', array('id' => $courseid));
blocks_add_default_course_blocks($course);
// Setup the blocks
$course = $DB->get_record('course', array('id' => $courseid));
blocks_add_default_course_blocks($course);

$section = new object();
$section->course = $course->id; // Create a default section.
$section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section);
$section = new object();
$section->course = $course->id; // Create a default section.
$section->section = 0;
$section->summaryformat = FORMAT_HTML;
$section->id = $DB->insert_record("course_sections", $section);

add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");

$this->log_line("Created course $coursecode in Moodle (Moodle ID is $course->id)");
}else{
$this->log_line('Failed to create course '.$coursecode.' in Moodle');
}
$this->log_line("Created course $coursecode in Moodle (Moodle ID is $course->id)");
}
}elseif($recstatus==3 && ($courseid = $DB->get_field('course', 'id', array('idnumber'=>$coursecode)))){
// If course does exist, but recstatus==3 (delete), then set the course as hidden
Expand Down Expand Up @@ -512,7 +506,7 @@ function process_person_tag($tagcontents){
$person->confirmed = 1;
$person->timemodified = time();
$person->mnethostid = $CFG->mnet_localhost_id;
if($id = $DB->insert_record('user', $person)){
$id = $DB->insert_record('user', $person);
/*
Photo processing is deactivated until we hear from Moodle dev forum about modification to gdlib.
Expand All @@ -531,10 +525,7 @@ function process_person_tag($tagcontents){
}
}
*/
$this->log_line("Created user record for user '$person->username' (ID number $person->idnumber).");
}else{
$this->log_line("Database error while trying to create user record for user '$person->username' (ID number $person->idnumber).");
}
$this->log_line("Created user record for user '$person->username' (ID number $person->idnumber).");
}
} elseif ($createnewusers) {
$this->log_line("User record already exists for user '$person->username' (ID number $person->idnumber).");
Expand Down
5 changes: 2 additions & 3 deletions lib/messagelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ function message_send($eventdata) {

//if there is no more processors that want to process this we can move message to message_read
if ( $DB->count_records('message_working', array('unreadmessageid' => $messageid)) == 0){
if ($DB->insert_record('message_read', $savemessage)) {
$DB->delete_records('message', array('id' => $messageid));
}
$DB->insert_record('message_read', $savemessage);
$DB->delete_records('message', array('id' => $messageid));
}
}

Expand Down
5 changes: 2 additions & 3 deletions message/discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,8 @@
$messageid = $message->id;
unset($message->id);
$message->timeread = time();
if ($DB->insert_record('message_read', $message)) {
$DB->delete_records('message', array('id'=>$messageid));
}
$DB->insert_record('message_read', $message);
$DB->delete_records('message', array('id'=>$messageid));
if ($message->timecreated < $start) {
$start = $message->timecreated; // move start back so that we see all current history
}
Expand Down
19 changes: 7 additions & 12 deletions message/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1643,12 +1643,9 @@ function message_move_userfrom_unread2read($userid) {
$message->timeread = 0; //the message was never read
$messageid = $message->id;
unset($message->id);
if ($DB->insert_record('message_read', $message)) {
$DB->delete_records('message', array('id' => $messageid));
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
} else {
return false;
}
$DB->insert_record('message_read', $message);
$DB->delete_records('message', array('id' => $messageid));
$DB->delete_records('message_working', array('unreadmessageid' => $messageid));
}
}
return true;
Expand Down Expand Up @@ -1678,9 +1675,8 @@ function message_get_popup_messages($destuserid, $fromuserid=NULL){
//delete what we've processed and check if can move message
$DB->delete_records('message_working', array('id' => $msgp->id));
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
if ($DB->insert_record('message_read', $message)) {
$DB->delete_records('message', array('id' => $messageid));
}
$DB->insert_record('message_read', $message);
$DB->delete_records('message', array('id' => $messageid));
}
}
}
Expand All @@ -1706,9 +1702,8 @@ function message_mark_messages_read($touserid, $fromuserid){

//have all message processors completed dealing with this message?
if ( $DB->count_records('message_working', array('unreadmessageid'=>$messageid)) == 0){
if ($DB->insert_record('message_read', $message)) {
$DB->delete_records('message', array('id' => $messageid));
}
$DB->insert_record('message_read', $message);
$DB->delete_records('message', array('id' => $messageid));
}
}
}
35 changes: 16 additions & 19 deletions mod/assignment/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,29 +441,26 @@ function add_instance($assignment) {
$assignment->timemodified = time();
$assignment->courseid = $assignment->course;

if ($returnid = $DB->insert_record("assignment", $assignment)) {
$assignment->id = $returnid;
$returnid = $DB->insert_record("assignment", $assignment);
$assignment->id = $returnid;

if ($assignment->timedue) {
$event = new object();
$event->name = $assignment->name;
$event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
$event->courseid = $assignment->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'assignment';
$event->instance = $returnid;
$event->eventtype = 'due';
$event->timestart = $assignment->timedue;
$event->timeduration = 0;

calendar_event::create($event);
}

assignment_grade_item_update($assignment);
if ($assignment->timedue) {
$event = new object();
$event->name = $assignment->name;
$event->description = format_module_intro('assignment', $assignment, $assignment->coursemodule);
$event->courseid = $assignment->course;
$event->groupid = 0;
$event->userid = 0;
$event->modulename = 'assignment';
$event->instance = $returnid;
$event->eventtype = 'due';
$event->timestart = $assignment->timedue;
$event->timeduration = 0;

calendar_event::create($event);
}

assignment_grade_item_update($assignment);

return $returnid;
}
Expand Down
24 changes: 12 additions & 12 deletions mod/choice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ function choice_add_instance($choice) {
}

//insert answers
if ($choice->id = $DB->insert_record("choice", $choice)) {
foreach ($choice->option as $key => $value) {
$value = trim($value);
if (isset($value) && $value <> '') {
$option = new object();
$option->text = $value;
$option->choiceid = $choice->id;
if (isset($choice->limit[$key])) {
$option->maxanswers = $choice->limit[$key];
}
$option->timemodified = time();
$DB->insert_record("choice_options", $option);
$choice->id = $DB->insert_record("choice", $choice);
foreach ($choice->option as $key => $value) {
$value = trim($value);
if (isset($value) && $value <> '') {
$option = new object();
$option->text = $value;
$option->choiceid = $choice->id;
if (isset($choice->limit[$key])) {
$option->maxanswers = $choice->limit[$key];
}
$option->timemodified = time();
$DB->insert_record("choice_options", $option);
}
}

return $choice->id;
}

Expand Down

0 comments on commit 9d97f08

Please sign in to comment.