Skip to content

Commit

Permalink
MDL-14679 fixed a lot more old style uses of insert_record()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 3, 2010
1 parent b44ff4e commit a9637e7
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 329 deletions.
44 changes: 19 additions & 25 deletions admin/xmldb/actions/test/test.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions auth/db/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 1 addition & 3 deletions auth/email/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 9 additions & 14 deletions auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

}
Expand Down
7 changes: 3 additions & 4 deletions blog/external_blog_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion enrol/mnet/enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}


Expand Down
Loading

0 comments on commit a9637e7

Please sign in to comment.