MDL-14679 fixed a lot more old style uses of insert_record()
authorPetr Skoda <skodak@moodle.org>
Fri, 3 Sep 2010 17:47:41 +0000 (17:47 +0000)
committerPetr Skoda <skodak@moodle.org>
Fri, 3 Sep 2010 17:47:41 +0000 (17:47 +0000)
15 files changed:
admin/xmldb/actions/test/test.class.php
auth/db/auth.php
auth/email/auth.php
auth/ldap/auth.php
blog/external_blog_edit.php
enrol/mnet/enrol.php
lib/datalib.php
lib/simpletest/fixtures/gradetest.php
mnet/lib.php
mod/chat/chat_ajax.php
mod/chat/lib.php
mod/glossary/import.php
mod/wiki/locallib.php
my/lib.php
notes/lib.php

index c507c69..ba7590f 100644 (file)
@@ -968,23 +968,20 @@ class test extends XMLDBAction {
             $rec->name = 'texttest';
         /// Calculate its length
             $textlen = $textlib->strlen($fulltext);
-            if ($rec->id = $DB->insert_record('newnameforthetable', $rec)) {
-                if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
-                    $DB->delete_records('newnameforthetable', array('id'=>$new->id));
-                    $newtextlen = $textlib->strlen($new->intro);
-                    if ($fulltext === $new->intro) {
-                        $test->sql = array($newtextlen . ' cc. (text) sent and received ok');
-                        $test->status = true;
-                    } else {
-                        $test->error = $DB->get_last_error();
-                        $test->sql = array($newtextlen . ' cc. (text) transfer failed. Data changed!');
-                        $test->status = false;
-                    }
+            $rec->id = $DB->insert_record('newnameforthetable', $rec);
+            if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
+                $DB->delete_records('newnameforthetable', array('id'=>$new->id));
+                $newtextlen = $textlib->strlen($new->intro);
+                if ($fulltext === $new->intro) {
+                    $test->sql = array($newtextlen . ' cc. (text) sent and received ok');
+                    $test->status = true;
                 } else {
-                    $test->error = $DB->get_last_error().'xx';
+                    $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().'yy'.var_export($rec->id, true);
+                $test->error = $DB->get_last_error().'xx';
             }
             $tests['insert record '. $textlen . ' cc. (text)'] = $test;
         }
@@ -998,19 +995,16 @@ class test extends XMLDBAction {
             $rec->name = 'binarytest';
         /// Calculate its length
             $textlen = strlen($rec->avatar);
-            if ($rec->id = $DB->insert_record('newnameforthetable', $rec)) {
-                if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
-                    $newtextlen = strlen($new->avatar);
-                    if ($rec->avatar === $new->avatar) {
-                        $test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
-                        $test->status = true;
-                    } else {
-                        $test->error = $DB->get_last_error();
-                        $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
-                        $test->status = false;
-                    }
+            $rec->id = $DB->insert_record('newnameforthetable', $rec);
+            if ($new = $DB->get_record('newnameforthetable', array('id'=>$rec->id))) {
+                $newtextlen = strlen($new->avatar);
+                if ($rec->avatar === $new->avatar) {
+                    $test->sql = array($newtextlen . ' bytes (binary) sent and received ok');
+                    $test->status = true;
                 } else {
                     $test->error = $DB->get_last_error();
+                    $test->sql = array($newtextlen . ' bytes (binary) transfer failed. Data changed!');
+                    $test->status = false;
                 }
             } else {
                 $test->error = $DB->get_last_error();
index 7682da1..ada6406 100644 (file)
@@ -365,15 +365,14 @@ class auth_plugin_db extends auth_plugin_base {
                     $DB->set_field('user', 'deleted', 0, array('username'=>$user->username));
                     echo "\t"; print_string('auth_dbreviveduser', 'auth_db', array('name'=>$user->username, 'id'=>$user->id)); echo "\n";
 
-                } elseif ($id = $DB->insert_record ('user',$user)) { // it is truly a new user
+                } else {
+                    $id = $DB->insert_record ('user',$user); // it is truly a new user
                     echo "\t"; print_string('auth_dbinsertuser','auth_db',array('name'=>$user->username, 'id'=>$id)); echo "\n";
                     // if relevant, tag for password generation
                     if ($this->config->passtype === 'internal') {
                         set_user_preference('auth_forcepasswordchange', 1, $id);
                         set_user_preference('create_password',          1, $id);
                     }
-                } else {
-                    echo "\t"; print_string('auth_dbinsertusererror', 'auth_db', $user->username); echo "\n";
                 }
             }
             $transaction->allow_commit();
index d57f11e..01612b6 100644 (file)
@@ -79,9 +79,7 @@ class auth_plugin_email extends auth_plugin_base {
 
         $user->password = hash_internal_user_password($user->password);
 
-        if (! ($user->id = $DB->insert_record('user', $user)) ) {
-            print_error('auth_emailnoinsert','auth_email');
-        }
+        $user->id = $DB->insert_record('user', $user);
 
         /// Save any custom profile field information
         profile_save_data($user);
index f114d1d..ce5ca11 100644 (file)
@@ -490,9 +490,7 @@ class auth_plugin_ldap extends auth_plugin_base {
             print_error('auth_ldap_create_error', 'auth_ldap');
         }
 
-        if (! ($user->id = $DB->insert_record('user', $user)) ) {
-            print_error('auth_emailnoinsert', 'auth_email');
-        }
+        $user->id = $DB->insert_record('user', $user);
 
         // Save any custom profile field information
         profile_save_data($user);
@@ -861,18 +859,15 @@ class auth_plugin_ldap extends auth_plugin_base {
                     $user->lang = $CFG->lang;
                 }
 
-                if ($id = $DB->insert_record('user', $user)) {
-                    echo "\t"; print_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)); echo "\n";
-                    if (!empty($this->config->forcechangepassword)) {
-                        set_user_preference('auth_forcepasswordchange', 1, $id);
-                    }
+                $id = $DB->insert_record('user', $user);
+                echo "\t"; print_string('auth_dbinsertuser', 'auth_db', array('name'=>$user->username, 'id'=>$id)); echo "\n";
+                if (!empty($this->config->forcechangepassword)) {
+                    set_user_preference('auth_forcepasswordchange', 1, $id);
+                }
 
-                    // Add course creators if needed
-                    if ($creatorrole !== false and $this->iscreator($user->username)) {
-                        role_assign($creatorrole->id, $id, $sitecontext->id, $this->roleauth);
-                    }
-                } else {
-                    echo "\t"; print_string('auth_dbinsertusererror', 'auth_db', $user->username); echo "\n";
+                // Add course creators if needed
+                if ($creatorrole !== false and $this->iscreator($user->username)) {
+                    role_assign($creatorrole->id, $id, $sitecontext->id, $this->roleauth);
                 }
 
             }
index 517dde2..42cb3ed 100644 (file)
@@ -82,10 +82,9 @@ if ($externalblogform->is_cancelled()){
             $newexternal->filtertags = $data->filtertags;
             $newexternal->timemodified = mktime();
 
-            if ($newexternal->id = $DB->insert_record('blog_external', $newexternal)) {
-                blog_sync_external_entries($newexternal);
-                tag_set('blog_external', $newexternal->id, $data->autotags);
-            }
+            $newexternal->id = $DB->insert_record('blog_external', $newexternal);
+            blog_sync_external_entries($newexternal);
+            tag_set('blog_external', $newexternal->id, $data->autotags);
 
             break;
 
index 4efcf95..230aee1 100644 (file)
@@ -145,7 +145,9 @@ class enrol_mnet_mnetservice_enrol {
             // users {@link http://tracker.moodle.org/browse/MDL-21327}
             $user = mnet_strip_user((object)$userdata, mnet_fields_to_import($client));
             $user->mnethostid = $client->id;
-            if (!$user->id = $DB->insert_record('user', $user)) {
+            try {
+                $user->id = $DB->insert_record('user', $user);
+            } catch (Exception $e) {
                 throw new mnet_server_exception(5011, 'couldnotcreateuser', 'enrol_mnet');
             }
         }
index 48bb742..7ebb845 100644 (file)
@@ -1234,9 +1234,8 @@ function make_default_scale() {
                            get_string('postrating3', 'forum');
     $defaultscale->timemodified = time();
 
-    if ($defaultscale->id = $DB->insert_record('scale', $defaultscale)) {
-        $DB->execute("UPDATE {forum} SET scale = ?", array($defaultscale->id));
-    }
+    $defaultscale->id = $DB->insert_record('scale', $defaultscale);
+    $DB->execute("UPDATE {forum} SET scale = ?", array($defaultscale->id));
 }
 
 
index fc7d9ef..f7748ac 100644 (file)
@@ -106,11 +106,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $scale->description = 'This scale defines some of qualities that make posts helpful within the Moodle help forums.\n Your feedback will help others see how their posts are being received.';
         $scale->timemodified = mktime();
 
-        if ($scale->id = $DB->insert_record('scale', $scale)) {
-            $this->scale[0] = $scale;
-            $temp = explode(',', $scale->scale);
-            $this->scalemax[0] = count($temp) -1;
-        }
+        $scale->id = $DB->insert_record('scale', $scale);
+        $this->scale[0] = $scale;
+        $temp = explode(',', $scale->scale);
+        $this->scalemax[0] = count($temp) -1;
 
         $scale = new stdClass();
 
@@ -121,11 +120,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $scale->description = 'This scale is used to mark standard assignments.';
         $scale->timemodified = mktime();
 
-        if ($scale->id = $DB->insert_record('scale', $scale)) {
-            $this->scale[1] = $scale;
-            $temp = explode(',', $scale->scale);
-            $this->scalemax[1] = count($temp) -1;
-        }
+        $scale->id = $DB->insert_record('scale', $scale);
+        $this->scale[1] = $scale;
+        $temp = explode(',', $scale->scale);
+        $this->scalemax[1] = count($temp) -1;
 
         $scale = new stdClass();
 
@@ -138,11 +136,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $temp  = explode(',', $scale->scale);
         $scale->max         = count($temp) -1;
 
-        if ($scale->id = $DB->insert_record('scale', $scale)) {
-            $this->scale[2] = $scale;
-            $temp = explode(',', $scale->scale);
-            $this->scalemax[2] = count($temp) -1;
-        }
+        $scale->id = $DB->insert_record('scale', $scale);
+        $this->scale[2] = $scale;
+        $temp = explode(',', $scale->scale);
+        $this->scalemax[2] = count($temp) -1;
 
         $scale->name        = 'unittestscale4';
         $scale->courseid    = $this->courseid;
@@ -153,11 +150,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $temp  = explode(',', $scale->scale);
         $scale->max         = count($temp) -1;
 
-        if ($scale->id = $DB->insert_record('scale', $scale)) {
-            $this->scale[3] = $scale;
-            $temp = explode(',', $scale->scale);
-            $this->scalemax[3] = count($temp) -1;
-        }
+        $scale->id = $DB->insert_record('scale', $scale);
+        $this->scale[3] = $scale;
+        $temp = explode(',', $scale->scale);
+        $this->scalemax[3] = count($temp) -1;
 
         $scale->name        = 'unittestscale5';
         $scale->courseid    = $this->courseid;
@@ -168,11 +164,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $temp  = explode(',', $scale->scale);
         $scale->max         = count($temp) -1;
 
-        if ($scale->id = $DB->insert_record('scale', $scale)) {
-            $this->scale[4] = $scale;
-            $temp = explode(',', $scale->scale);
-            $this->scalemax[4] = count($temp) -1;
-        }
+        $scale->id = $DB->insert_record('scale', $scale);
+        $this->scale[4] = $scale;
+        $temp = explode(',', $scale->scale);
+        $this->scalemax[4] = count($temp) -1;
     }
 
     /**
@@ -196,11 +191,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_category->timemodified = mktime();
         $grade_category->depth = 2;
 
-        if ($grade_category->id = $DB->insert_record('grade_categories', $grade_category)) {
-            $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
-            $DB->update_record('grade_categories', $grade_category);
-            $this->grade_categories[0] = $grade_category;
-        }
+        $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
+        $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
+        $DB->update_record('grade_categories', $grade_category);
+        $this->grade_categories[0] = $grade_category;
 
         $grade_category = new stdClass();
 
@@ -215,11 +209,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_category->timemodified = mktime();
         $grade_category->depth = 3;
 
-        if ($grade_category->id = $DB->insert_record('grade_categories', $grade_category)) {
-            $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
-            $DB->update_record('grade_categories', $grade_category);
-            $this->grade_categories[1] = $grade_category;
-        }
+        $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
+        $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
+        $DB->update_record('grade_categories', $grade_category);
+        $this->grade_categories[1] = $grade_category;
 
         $grade_category = new stdClass();
 
@@ -234,11 +227,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_category->timemodified = mktime();
         $grade_category->depth = 3;
 
-        if ($grade_category->id = $DB->insert_record('grade_categories', $grade_category)) {
-            $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
-            $DB->update_record('grade_categories', $grade_category);
-            $this->grade_categories[2] = $grade_category;
-        }
+        $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
+        $grade_category->path = $this->grade_categories[0]->path.$grade_category->id.'/';
+        $DB->update_record('grade_categories', $grade_category);
+        $this->grade_categories[2] = $grade_category;
 
         // A category with no parent, but grade_items as children
 
@@ -255,11 +247,10 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_category->timemodified = mktime();
         $grade_category->depth = 2;
 
-        if ($grade_category->id = $DB->insert_record('grade_categories', $grade_category)) {
-            $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
-            $DB->update_record('grade_categories', $grade_category);
-            $this->grade_categories[3] = $grade_category;
-        }
+        $grade_category->id = $DB->insert_record('grade_categories', $grade_category);
+        $grade_category->path = '/'.$course_category->id.'/'.$grade_category->id.'/';
+        $DB->update_record('grade_categories', $grade_category);
+        $this->grade_categories[3] = $grade_category;
     }
 
     /**
@@ -269,21 +260,18 @@ class grade_test extends UnitTestCaseUsingDatabase {
         global $DB;
         $module = new stdClass();
         $module->name = 'assignment';
-        if ($module->id = $DB->insert_record('modules', $module)) {
-            $this->modules[0] = $module;
-        }
+        $module->id = $DB->insert_record('modules', $module);
+        $this->modules[0] = $module;
 
         $module = new stdClass();
         $module->name = 'quiz';
-        if ($module->id = $DB->insert_record('modules', $module)) {
-            $this->modules[1] = $module;
-        }
+        $module->id = $DB->insert_record('modules', $module);
+        $this->modules[1] = $module;
 
         $module = new stdClass();
         $module->name = 'forum';
-        if ($module->id = $DB->insert_record('modules', $module)) {
-            $this->modules[2] = $module;
-        }
+        $module->id = $DB->insert_record('modules', $module);
+        $this->modules[2] = $module;
     }
 
     /**
@@ -295,49 +283,43 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $course_module->course = $this->courseid;
         $quiz->module = 1;
         $quiz->instance = 2;
-        if ($course_module->id = $DB->insert_record('course_modules', $course_module)) {
-            $this->course_module[0] = $course_module;
-        }
+        $course_module->id = $DB->insert_record('course_modules', $course_module);
+        $this->course_module[0] = $course_module;
 
         $course_module = new stdClass();
         $course_module->course = $this->courseid;
         $quiz->module = 2;
         $quiz->instance = 1;
-        if ($course_module->id = $DB->insert_record('course_modules', $course_module)) {
-            $this->course_module[0] = $course_module;
-        }
+        $course_module->id = $DB->insert_record('course_modules', $course_module);
+        $this->course_module[0] = $course_module;
 
         $course_module = new stdClass();
         $course_module->course = $this->courseid;
         $quiz->module = 2;
         $quiz->instance = 5;
-        if ($course_module->id = $DB->insert_record('course_modules', $course_module)) {
-            $this->course_module[0] = $course_module;
-        }
+        $course_module->id = $DB->insert_record('course_modules', $course_module);
+        $this->course_module[0] = $course_module;
 
         $course_module = new stdClass();
         $course_module->course = $this->courseid;
         $quiz->module = 3;
         $quiz->instance = 3;
-        if ($course_module->id = $DB->insert_record('course_modules', $course_module)) {
-            $this->course_module[0] = $course_module;
-        }
+        $course_module->id = $DB->insert_record('course_modules', $course_module);
+        $this->course_module[0] = $course_module;
 
         $course_module = new stdClass();
         $course_module->course = $this->courseid;
         $quiz->module = 3;
         $quiz->instance = 7;
-        if ($course_module->id = $DB->insert_record('course_modules', $course_module)) {
-            $this->course_module[0] = $course_module;
-        }
+        $course_module->id = $DB->insert_record('course_modules', $course_module);
+        $this->course_module[0] = $course_module;
 
         $course_module = new stdClass();
         $course_module->course = $this->courseid;
         $quiz->module = 3;
         $quiz->instance = 9;
-        if ($course_module->id = $DB->insert_record('course_modules', $course_module)) {
-            $this->course_module[0] = $course_module;
-        }
+        $course_module->id = $DB->insert_record('course_modules', $course_module);
+        $this->course_module[0] = $course_module;
     }
 
     /**
@@ -350,19 +332,16 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $quiz->name = 'test quiz';
         $quiz->intro = 'let us quiz you!';
         $quiz->questions = '1,2';
-        if ($quiz->id = $DB->insert_record('quiz', $quiz)) {
-            $this->activities[0] = $quiz;
-        }
+        $quiz->id = $DB->insert_record('quiz', $quiz);
+        $this->activities[0] = $quiz;
 
         $quiz = new stdClass();
         $quiz->course = $this->courseid;
         $quiz->name = 'test quiz 2';
         $quiz->intro = 'let us quiz you again!';
         $quiz->questions = '1,3';
-        if ($quiz->id = $DB->insert_record('quiz', $quiz)) {
-            $this->activities[1] = $quiz;
-        }
-
+        $quiz->id = $DB->insert_record('quiz', $quiz);
+        $this->activities[1] = $quiz;
     }
 
     /**
@@ -392,9 +371,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 3;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[0] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[0] = $grade_item;
 
         // id = 1
         $grade_item = new stdClass();
@@ -415,9 +393,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 4;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[1] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[1] = $grade_item;
 
         // id = 2
         $grade_item = new stdClass();
@@ -437,9 +414,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 6;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[2] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[2] = $grade_item;
 
         // Load grade_items associated with the 3 categories
         // id = 3
@@ -458,9 +434,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 1;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[3] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[3] = $grade_item;
 
         // id = 4
         $grade_item = new stdClass();
@@ -478,9 +453,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 2;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[4] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[4] = $grade_item;
 
         // id = 5
         $grade_item = new stdClass();
@@ -498,9 +472,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 5;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[5] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[5] = $grade_item;
 
         // Orphan grade_item
         // id = 6
@@ -522,9 +495,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 7;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[6] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[6] = $grade_item;
 
         // 2 grade items under level1category
         // id = 7
@@ -545,9 +517,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 9;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[7] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[7] = $grade_item;
 
         // id = 8
         $grade_item = new stdClass();
@@ -566,9 +537,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 10;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[8] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[8] = $grade_item;
 
         // Grade_item for level1category
         // id = 9
@@ -588,9 +558,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timemodified = mktime();
         $grade_item->sortorder = 8;
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[9] = $grade_item;
-        }
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[9] = $grade_item;
 
         // Manual grade_item
         // id = 10
@@ -609,10 +578,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_item->timecreated = mktime();
         $grade_item->timemodified = mktime();
 
-        if ($grade_item->id = $DB->insert_record('grade_items', $grade_item)) {
-            $this->grade_items[10] = $grade_item;
-        }
-
+        $grade_item->id = $DB->insert_record('grade_items', $grade_item);
+        $this->grade_items[10] = $grade_item;
     }
 
     /**
@@ -623,7 +590,7 @@ class grade_test extends UnitTestCaseUsingDatabase {
 
         //this method is called once for each test method. Avoid adding things to $this->grade_grades multiple times
         $this->grade_grades = array();
-        
+
         // Grades for grade_item 1
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[0]->id;
@@ -637,9 +604,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->feedback = 'Good, but not good enough..';
         $grade->feedbackformat = FORMAT_PLAIN;
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[0] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[0] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[0]->id;
@@ -650,9 +616,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '2 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[1] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[1] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[0]->id;
@@ -663,9 +628,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '3 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[2] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[2] = $grade;
 
 
         // No raw grades for grade_item 2 - it is calculated
@@ -678,9 +642,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '4 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[3] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[3] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[1]->id;
@@ -690,9 +653,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '5 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[4] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[4] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[1]->id;
@@ -702,9 +664,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '6 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[5] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[5] = $grade;
 
 
         // Grades for grade_item 3
@@ -719,9 +680,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '7 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[6] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[6] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[2]->id;
@@ -733,9 +693,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '8 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[2]->id;
@@ -747,9 +706,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '9 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         // Grades for grade_item 7
 
@@ -762,9 +720,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '10 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[6]->id;
@@ -775,9 +732,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '11 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[6]->id;
@@ -788,9 +744,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '12 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         // Grades for grade_item 8
 
@@ -803,9 +758,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '13 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[7]->id;
@@ -816,9 +770,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '14 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         // Grades for grade_item 9
 
@@ -831,9 +784,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '15 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[8]->id;
@@ -844,9 +796,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '16 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
 
         $grade = new stdClass();
         $grade->itemid = $this->grade_items[8]->id;
@@ -857,9 +808,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade->timemodified = mktime();
         $grade->information = '17 of 17 grade_grades';
 
-        if ($grade->id = $DB->insert_record('grade_grades', $grade)) {
-            $this->grade_grades[] = $grade;
-        }
+        $grade->id = $DB->insert_record('grade_grades', $grade);
+        $this->grade_grades[] = $grade;
     }
 
     /**
@@ -880,9 +830,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_outcome->timemodified = mktime();
         $grade_outcome->scaleid = $this->scale[2]->id;
 
-        if ($grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome)) {
-            $this->grade_outcomes[] = $grade_outcome;
-        }
+        $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
+        $this->grade_outcomes[] = $grade_outcome;
 
         // Calculation for grade_item 2
         $grade_outcome = new stdClass();
@@ -893,9 +842,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_outcome->timemodified = mktime();
         $grade_outcome->scaleid = $this->scale[3]->id;
 
-        if ($grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome)) {
-            $this->grade_outcomes[] = $grade_outcome;
-        }
+        $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
+        $this->grade_outcomes[] = $grade_outcome;
 
         // Calculation for grade_item 3
         $grade_outcome = new stdClass();
@@ -906,9 +854,8 @@ class grade_test extends UnitTestCaseUsingDatabase {
         $grade_outcome->timemodified = mktime();
         $grade_outcome->scaleid = $this->scale[4]->id;
 
-        if ($grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome)) {
-            $this->grade_outcomes[] = $grade_outcome;
-        }
+        $grade_outcome->id = $DB->insert_record('grade_outcomes', $grade_outcome);
+        $this->grade_outcomes[] = $grade_outcome;
     }
 
 /**
index a18f72c..8905ac6 100644 (file)
@@ -442,25 +442,17 @@ function mnet_update_sso_access_control($username, $mnet_host_id, $accessctrl) {
     if ($aclrecord = $DB->get_record('mnet_sso_access_control', array('username'=>$username, 'mnet_host_id'=>$mnet_host_id))) {
         // update
         $aclrecord->accessctrl = $accessctrl;
-        if ($DB->update_record('mnet_sso_access_control', $aclrecord)) {
-            add_to_log(SITEID, 'admin/mnet', 'update', 'admin/mnet/access_control.php',
-                    "SSO ACL: $accessctrl user '$username' from {$mnethost->name}");
-        } else {
-            print_error('failedaclwrite', 'mnet', '', $username);
-            return false;
-        }
+        $DB->update_record('mnet_sso_access_control', $aclrecord);
+        add_to_log(SITEID, 'admin/mnet', 'update', 'admin/mnet/access_control.php',
+                "SSO ACL: $accessctrl user '$username' from {$mnethost->name}");
     } else {
         // insert
         $aclrecord->username = $username;
         $aclrecord->accessctrl = $accessctrl;
         $aclrecord->mnet_host_id = $mnet_host_id;
-        if ($id = $DB->insert_record('mnet_sso_access_control', $aclrecord)) {
-            add_to_log(SITEID, 'admin/mnet', 'add', 'admin/mnet/access_control.php',
-                    "SSO ACL: $accessctrl user '$username' from {$mnethost->name}");
-        } else {
-            print_error('failedaclwrite', 'mnet', '', $username);
-            return false;
-        }
+        $id = $DB->insert_record('mnet_sso_access_control', $aclrecord);
+        add_to_log(SITEID, 'admin/mnet', 'add', 'admin/mnet/access_control.php',
+                "SSO ACL: $accessctrl user '$username' from {$mnethost->name}");
     }
     return true;
 }
index 1a8ea66..ad91a1b 100644 (file)
@@ -14,6 +14,8 @@
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
+//TODO: use standard CLI_SCRIPT support here (skodak)
+
 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
 require_once(dirname(__FILE__) . '/lib.php');
 
@@ -81,11 +83,8 @@ case 'chat':
         $chatuser->lastmessageping = time() - 2;
         $DB->update_record('chat_users', $chatuser);
 
-        if (!($DB->insert_record('chat_messages', $message) && $DB->insert_record('chat_messages_current', $message))) {
-            chat_print_error('ERROR', get_string('cantlogin','chat'));
-        } else {
-            echo 200;
-        }
+        $DB->insert_record('chat_messages', $message);
+        $DB->insert_record('chat_messages_current', $message);
         add_to_log($course->id, 'chat', 'talk', "view.php?id=$cm->id", $chat->id, $cm->id);
 
         ob_end_flush();
index 443e138..a11938d 100644 (file)
@@ -110,22 +110,21 @@ function chat_add_instance($chat) {
 
     $chat->timemodified = time();
 
-    if ($returnid = $DB->insert_record("chat", $chat)) {
-
-        $event = NULL;
-        $event->name        = $chat->name;
-        $event->description = format_module_intro('chat', $chat, $chat->coursemodule);
-        $event->courseid    = $chat->course;
-        $event->groupid     = 0;
-        $event->userid      = 0;
-        $event->modulename  = 'chat';
-        $event->instance    = $returnid;
-        $event->eventtype   = 'chattime';
-        $event->timestart   = $chat->chattime;
-        $event->timeduration = 0;
-
-        calendar_event::create($event);
-    }
+    $returnid = $DB->insert_record("chat", $chat);
+
+    $event = NULL;
+    $event->name        = $chat->name;
+    $event->description = format_module_intro('chat', $chat, $chat->coursemodule);
+    $event->courseid    = $chat->course;
+    $event->groupid     = 0;
+    $event->userid      = 0;
+    $event->modulename  = 'chat';
+    $event->instance    = $returnid;
+    $event->eventtype   = 'chattime';
+    $event->timestart   = $chat->chattime;
+    $event->timeduration = 0;
+
+    calendar_event::create($event);
 
     return $returnid;
 }
index 9d6b1b1..52d8cee 100644 (file)
@@ -237,54 +237,48 @@ if ($xml = glossary_read_imported_file($result)) {
                 $newentry->fullmatch      = $CFG->glossary_fullmatch;
             }
 
-            if ( $newentry->id = $DB->insert_record("glossary_entries",$newentry) )  {
-                $importedentries++;
-
-                $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES
-                for($k = 0; $k < sizeof($xmlaliases); $k++) {
-                /// Importing aliases
-                    $xmlalias = $xmlaliases[$k];
-                    $aliasname = $xmlalias['#']['NAME'][0]['#'];
-
-                    if (!empty($aliasname)) {
-                        $newalias = new object();
-                        $newalias->entryid = $newentry->id;
-                        $newalias->alias = trim($aliasname);
-                        $newalias->id = $DB->insert_record("glossary_alias",$newalias);
-                    }
+            $newentry->id = $DB->insert_record("glossary_entries",$newentry);
+            $importedentries++;
+
+            $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES
+            for($k = 0; $k < sizeof($xmlaliases); $k++) {
+            /// Importing aliases
+                $xmlalias = $xmlaliases[$k];
+                $aliasname = $xmlalias['#']['NAME'][0]['#'];
+
+                if (!empty($aliasname)) {
+                    $newalias = new object();
+                    $newalias->entryid = $newentry->id;
+                    $newalias->alias = trim($aliasname);
+                    $newalias->id = $DB->insert_record("glossary_alias",$newalias);
                 }
+            }
 
-                if (!empty($data->catsincl)) {
-                    // If the categories must be imported...
-                    $xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES
-                    for($k = 0; $k < sizeof($xmlcats); $k++) {
-                        $xmlcat = $xmlcats[$k];
-
-                        $newcat = new object();
-                        $newcat->name = $xmlcat['#']['NAME'][0]['#'];
-                        $newcat->usedynalink = $xmlcat['#']['USEDYNALINK'][0]['#'];
-                        if ( !$category = $DB->get_record("glossary_categories", array("glossaryid"=>$glossary->id,"name"=>$newcat->name))) {
-                            // Create the category if it does not exist
-                            $category = new object();
-                            $category->name = $newcat->name;
-                            $category->glossaryid = $glossary->id;
-                            $category->id = $DB->insert_record("glossary_categories",$category);
-                            $importedcats++;
-                        }
-                        if ( $category ) {
-                            // inserting the new relation
-                            $entrycat = new object();
-                            $entrycat->entryid    = $newentry->id;
-                            $entrycat->categoryid = $category->id;
-                            $DB->insert_record("glossary_entries_categories",$entrycat);
-                        }
+            if (!empty($data->catsincl)) {
+                // If the categories must be imported...
+                $xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES
+                for($k = 0; $k < sizeof($xmlcats); $k++) {
+                    $xmlcat = $xmlcats[$k];
+
+                    $newcat = new object();
+                    $newcat->name = $xmlcat['#']['NAME'][0]['#'];
+                    $newcat->usedynalink = $xmlcat['#']['USEDYNALINK'][0]['#'];
+                    if ( !$category = $DB->get_record("glossary_categories", array("glossaryid"=>$glossary->id,"name"=>$newcat->name))) {
+                        // Create the category if it does not exist
+                        $category = new object();
+                        $category->name = $newcat->name;
+                        $category->glossaryid = $glossary->id;
+                        $category->id = $DB->insert_record("glossary_categories",$category);
+                        $importedcats++;
+                    }
+                    if ( $category ) {
+                        // inserting the new relation
+                        $entrycat = new object();
+                        $entrycat->entryid    = $newentry->id;
+                        $entrycat->categoryid = $category->id;
+                        $DB->insert_record("glossary_entries_categories",$entrycat);
                     }
                 }
-            } else {
-                $entriesrejected++;
-                // add to exception report (can't insert new record)
-                $rejections .= "<tr><td>$newentry->concept</td>" .
-                               "<td>" . get_string("cantinsertrec","glossary"). "</td></tr>";
             }
         } else {
             $entriesrejected++;
index c02ed09..deb8d84 100644 (file)
@@ -246,9 +246,7 @@ function wiki_save_page($wikipage, $newcontent, $userid) {
         $version->userid = $userid;
         $version->version++;
         $version->timecreated = time();
-        if (!$versionid = $DB->insert_record('wiki_versions', $version)) {
-            return false;
-        }
+        $versionid = $DB->insert_record('wiki_versions', $version);
 
         $wikipage->timemodified = $version->timecreated;
         $wikipage->userid = $userid;
@@ -334,9 +332,7 @@ function wiki_create_page($swid, $title, $format, $userid) {
     $version->userid = $userid;
 
     $versionid = null;
-    if (!$versionid = $DB->insert_record('wiki_versions', $version)) {
-        return false;
-    }
+    $versionid = $DB->insert_record('wiki_versions', $version);
 
     // Createing a new empty page
     $page = new stdClass();
index 0c713a4..080332f 100644 (file)
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
-define('MY_PAGE_PUBLIC', 0); 
+define('MY_PAGE_PUBLIC', 0);
 define('MY_PAGE_PRIVATE', 1);
 
 require_once("$CFG->libdir/blocklib.php");
 
-/* 
+/*
  * For a given user, this returns the $page information for their My Moodle page
  *
  */
@@ -71,10 +71,8 @@ function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
     $page = clone($systempage);
     unset($page->id);
     $page->userid = $userid;
-    if (!$page->id = $DB->insert_record('my_pages', $page)) {
-        return false;
-    }
-    
+    $page->id = $DB->insert_record('my_pages', $page);
+
     // Clone ALL the associated blocks as well
     $systemcontext = get_context_instance(CONTEXT_SYSTEM);
     $usercontext = get_context_instance(CONTEXT_USER, $userid);
@@ -86,9 +84,8 @@ function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
         unset($instance->id);
         $instance->parentcontextid = $usercontext->id;
         $instance->subpagepattern = $page->id;
-        if ($instance->id = $DB->insert_record('block_instances', $instance)) {
-            $blockcontext = get_context_instance(CONTEXT_BLOCK, $instance->id);  // Just creates the context record
-        }
+        $instance->id = $DB->insert_record('block_instances', $instance);
+        $blockcontext = get_context_instance(CONTEXT_BLOCK, $instance->id);  // Just creates the context record
     }
 
     // FIXME: block position overrides should be merged in with block instance
index f5a9784..5fd84d3 100644 (file)
@@ -99,18 +99,14 @@ function note_save(&$note) {
     if (empty($note->id)) {
         // insert new note
         $note->created = $note->lastmodified;
-        if ($id = $DB->insert_record('post', $note)) {
-            $note = $DB->get_record('post', array('id'=>$id));
-            $result = true;
-        } else {
-            $result = false;
-        }
+        $id = $DB->insert_record('post', $note);
+        $note = $DB->get_record('post', array('id'=>$id));
     } else {
         // update old note
-        $result = $DB->update_record('post', $note);
+        $DB->update_record('post', $note);
     }
     unset($note->module);
-    return $result;
+    return true;
 }
 
 /**