From a9637e7df484bccf08bc56ceef7412aa4fa5dc73 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Fri, 3 Sep 2010 17:47:41 +0000 Subject: [PATCH] MDL-14679 fixed a lot more old style uses of insert_record() --- admin/xmldb/actions/test/test.class.php | 44 ++-- auth/db/auth.php | 5 +- auth/email/auth.php | 4 +- auth/ldap/auth.php | 23 +- blog/external_blog_edit.php | 7 +- enrol/mnet/enrol.php | 4 +- lib/datalib.php | 5 +- lib/simpletest/fixtures/gradetest.php | 295 ++++++++++-------------- mnet/lib.php | 20 +- mod/chat/chat_ajax.php | 9 +- mod/chat/lib.php | 31 ++- mod/glossary/import.php | 82 +++---- mod/wiki/locallib.php | 8 +- my/lib.php | 15 +- notes/lib.php | 12 +- 15 files changed, 235 insertions(+), 329 deletions(-) diff --git a/admin/xmldb/actions/test/test.class.php b/admin/xmldb/actions/test/test.class.php index c507c695c2c7c..ba7590f32f432 100644 --- a/admin/xmldb/actions/test/test.class.php +++ b/admin/xmldb/actions/test/test.class.php @@ -968,23 +968,20 @@ function invoke() { $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 @@ function invoke() { $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(); diff --git a/auth/db/auth.php b/auth/db/auth.php index 7682da1ebb158..ada6406411632 100644 --- a/auth/db/auth.php +++ b/auth/db/auth.php @@ -365,15 +365,14 @@ function sync_users($do_updates=false) { $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(); diff --git a/auth/email/auth.php b/auth/email/auth.php index d57f11e602e9f..01612b6d3c57a 100644 --- a/auth/email/auth.php +++ b/auth/email/auth.php @@ -79,9 +79,7 @@ function user_signup($user, $notify=true) { $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); diff --git a/auth/ldap/auth.php b/auth/ldap/auth.php index f114d1dcafa83..ce5ca113c1f8a 100644 --- a/auth/ldap/auth.php +++ b/auth/ldap/auth.php @@ -490,9 +490,7 @@ function user_signup($user, $notify=true) { 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 @@ function sync_users($do_updates=true) { $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); } } diff --git a/blog/external_blog_edit.php b/blog/external_blog_edit.php index 517dde20815bf..42cb3ed246bd8 100644 --- a/blog/external_blog_edit.php +++ b/blog/external_blog_edit.php @@ -82,10 +82,9 @@ $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; diff --git a/enrol/mnet/enrol.php b/enrol/mnet/enrol.php index 4efcf95166b5f..230aee1eb1e15 100644 --- a/enrol/mnet/enrol.php +++ b/enrol/mnet/enrol.php @@ -145,7 +145,9 @@ public function enrol_user(array $userdata, $courseid) { // 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'); } } diff --git a/lib/datalib.php b/lib/datalib.php index 48bb742b1851c..7ebb845de6cb7 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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)); } diff --git a/lib/simpletest/fixtures/gradetest.php b/lib/simpletest/fixtures/gradetest.php index fc7d9ef0ca3f3..f7748ac50400c 100644 --- a/lib/simpletest/fixtures/gradetest.php +++ b/lib/simpletest/fixtures/gradetest.php @@ -106,11 +106,10 @@ function load_scale() { $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 @@ function load_scale() { $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 @@ function load_scale() { $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 @@ function load_scale() { $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 @@ function load_scale() { $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 @@ function load_grade_categories() { $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 @@ function load_grade_categories() { $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 @@ function load_grade_categories() { $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 @@ function load_grade_categories() { $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 @@ function load_modules() { 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 @@ function load_course_modules() { $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 @@ function load_quiz_activities() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_items() { $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 @@ function load_grade_grades() { //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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_grades() { $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 @@ function load_grade_outcomes() { $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 @@ function load_grade_outcomes() { $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 @@ function load_grade_outcomes() { $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; } /** diff --git a/mnet/lib.php b/mnet/lib.php index a18f72c4ecec6..8905ac65057c1 100644 --- a/mnet/lib.php +++ b/mnet/lib.php @@ -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; } diff --git a/mod/chat/chat_ajax.php b/mod/chat/chat_ajax.php index 1a8ea6629ecc3..ad91a1bad1f5a 100644 --- a/mod/chat/chat_ajax.php +++ b/mod/chat/chat_ajax.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +//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 @@ $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(); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 443e138c3878f..a11938d409365 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -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; } diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 9d6b1b1a5f69e..52d8cee675ccc 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -237,54 +237,48 @@ $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 .= "$newentry->concept" . - "" . get_string("cantinsertrec","glossary"). ""; } } else { $entriesrejected++; diff --git a/mod/wiki/locallib.php b/mod/wiki/locallib.php index c02ed090c38ba..deb8d84c37c4e 100644 --- a/mod/wiki/locallib.php +++ b/mod/wiki/locallib.php @@ -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(); diff --git a/my/lib.php b/my/lib.php index 0c713a4bc5d26..080332f1d9dae 100644 --- a/my/lib.php +++ b/my/lib.php @@ -27,12 +27,12 @@ * @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 diff --git a/notes/lib.php b/notes/lib.php index f5a97841ec448..5fd84d38d2204 100644 --- a/notes/lib.php +++ b/notes/lib.php @@ -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; } /**