From d3d393ab3770cb037a29d2e14ff8b5ed0fb31fe0 Mon Sep 17 00:00:00 2001 From: Rossiani Wijaya Date: Wed, 3 Feb 2010 04:25:20 +0000 Subject: [PATCH] MDL-21226 - add 'timecreated' column to user table. During an update, the column will copy the value from 'firstaccess' column. if the account never been access, it will be set to current time of the update. also, modified the files for signup, add new user, and upload user to initialize the value of timecreated field. --- admin/uploaduser.php | 1 + lib/db/install.xml | 7 ++++--- lib/db/upgrade.php | 17 +++++++++++++++++ login/signup.php | 5 +++-- user/editadvanced.php | 3 ++- version.php | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 54073eb3612..9d2bff16323 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -205,6 +205,7 @@ if ($formdata = $mform->is_cancelled()) { foreach ($line as $key => $value) { if ($value !== '') { $key = $columns[$key]; + $user->timecreated = time(); // password is special field if ($key == 'password') { if ($value !== '') { diff --git a/lib/db/install.xml b/lib/db/install.xml index 87cbd4756c7..38443985436 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -600,8 +600,9 @@ - - + + + @@ -2391,4 +2392,4 @@ - \ No newline at end of file + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 9305bdc23df..ddf745e98b4 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3012,6 +3012,23 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint($result, 2010020100); } + if ($result && $oldversion < 2010020300) { + + /// Define field timecreated to be added to user + $table = new xmldb_table('user'); + $field = new xmldb_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'trackforums'); + + if (!$dbman->field_exists($table, $field)) { + /// Launch add field timecreated + $dbman->add_field($table, $field); + + $DB->execute("UPDATE {user} SET timecreated = firstaccess"); + + $sql = "UPDATE {user} SET timecreated = " . time() ." where timecreated = 0"; + $DB->execute($sql); + } + upgrade_main_savepoint($result, 2010020300); + } return $result; } diff --git a/login/signup.php b/login/signup.php index bea4e322a70..e1f3fd40a21 100644 --- a/login/signup.php +++ b/login/signup.php @@ -58,11 +58,12 @@ if ($mform_signup->is_cancelled()) { $user->confirmed = 0; $user->lang = current_language(); $user->firstaccess = time(); + $user->timecreated = time(); $user->mnethostid = $CFG->mnet_localhost_id; $user->secret = random_string(15); $user->auth = $CFG->registerauth; - - $authplugin->user_signup($user, true); // prints notice and link to login/index.php + + $authplugin->user_signup($user, true); // prints notice and link to login/index.php exit; //never reached } diff --git a/user/editadvanced.php b/user/editadvanced.php index 80efa61ea85..57a7ef03774 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -144,7 +144,8 @@ if ($usernew = $userform->get_data()) { unset($usernew->id); $usernew = file_postupdate_standard_editor($usernew, 'description', $editoroptions, null, 'user_profile', null); $usernew->mnethostid = $CFG->mnet_localhost_id; // always local user - $usernew->confirmed = 1; + $usernew->confirmed = 1; + $usernew->timecreated = time(); $usernew->password = hash_internal_user_password($usernew->newpassword); $usernew->id = $DB->insert_record('user', $usernew); $usercreated = true; diff --git a/version.php b/version.php index 21bfe2bff94..f3cf32ee247 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // whether upgrades should be performed (see lib/db/*.php) - $version = 2010020100; // YYYYMMDD = date of the last version bump + $version = 2010020300; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0 dev (Build: 20100203)'; // Human-friendly version name