MDL-14679 fixed multiple old style insert_record calls, we throw exceptions now from DML
authorPetr Skoda <skodak@moodle.org>
Fri, 3 Sep 2010 16:26:04 +0000 (16:26 +0000)
committerPetr Skoda <skodak@moodle.org>
Fri, 3 Sep 2010 16:26:04 +0000 (16:26 +0000)
admin/generator.php
blog/locallib.php
enrol/imsenterprise/lib.php
lib/messagelib.php
message/discussion.php
message/lib.php
mod/assignment/lib.php
mod/choice/lib.php

index eb08e4d..43a5084 100755 (executable)
@@ -896,9 +896,8 @@ class generator {
                     $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')) {
index e1cfc68..f09c3bf 100644 (file)
@@ -340,18 +340,17 @@ class blog_entry {
         $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);
     }
 
     /**
index 3d4271f..4ee19ce 100644 (file)
@@ -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.');
@@ -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
@@ -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.
 
@@ -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).");
index 4c5ebd5..47b06b9 100644 (file)
@@ -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));
             }
     }
 
index ff1d21a..00d3c0b 100644 (file)
             $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
             }
index 7806a6e..c23088c 100644 (file)
@@ -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;
@@ -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));
             }
         }
     }
@@ -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));
         }
     }
 }
index b50b4f8..99edfd2 100644 (file)
@@ -441,29 +441,26 @@ class assignment_base {
         $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;
     }
index 55c0442..e711a44 100644 (file)
@@ -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;
 }