Commit e5367399 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Save user creation times


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 3246beeb
...@@ -91,6 +91,7 @@ class User { ...@@ -91,6 +91,7 @@ class User {
'parentuser' => null, 'parentuser' => null,
'loginanyway' => false, 'loginanyway' => false,
'sesskey' => '', 'sesskey' => '',
'ctime' => null,
); );
$this->attributes = array(); $this->attributes = array();
...@@ -111,7 +112,8 @@ class User { ...@@ -111,7 +112,8 @@ class User {
' . db_format_tsfield('lastlogin') . ', ' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ', ' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ', ' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . ' ' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM FROM
{usr} {usr}
WHERE WHERE
...@@ -148,7 +150,8 @@ class User { ...@@ -148,7 +150,8 @@ class User {
' . db_format_tsfield('lastlogin') . ', ' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ', ' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ', ' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . ' ' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM FROM
{usr} {usr}
WHERE WHERE
...@@ -214,6 +217,7 @@ class User { ...@@ -214,6 +217,7 @@ class User {
' . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ', ' . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ',
' . db_format_tsfield('u.lastaccess', 'lastaccess') . ', ' . db_format_tsfield('u.lastaccess', 'lastaccess') . ',
' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . ' ' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . '
' . db_format_tsfield('u.ctime', 'ctime') . '
FROM {usr} u FROM {usr} u
LEFT JOIN {auth_remote_user} r ON u.id = r.localusr LEFT JOIN {auth_remote_user} r ON u.id = r.localusr
WHERE WHERE
...@@ -234,7 +238,8 @@ class User { ...@@ -234,7 +238,8 @@ class User {
' . db_format_tsfield('lastlogin') . ', ' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ', ' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ', ' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . ' ' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM FROM
{usr} {usr}
WHERE WHERE
...@@ -251,6 +256,14 @@ class User { ...@@ -251,6 +256,14 @@ class User {
return $this; return $this;
} }
/**
* Set stuff that needs to be initialised once before a user record is created.
*/
public function create() {
$this->set('ctime', time());
}
/** /**
* Take a row object from the usr table and populate this object with the * Take a row object from the usr table and populate this object with the
* values * values
...@@ -473,7 +486,7 @@ class User { ...@@ -473,7 +486,7 @@ class User {
$this->stdclass = new StdClass; $this->stdclass = new StdClass;
reset($this->defaults); reset($this->defaults);
foreach (array_keys($this->defaults) as $k) { foreach (array_keys($this->defaults) as $k) {
if ($k == 'expiry' || $k == 'lastlogin' || $k == 'lastlastlogin' || $k == 'lastaccess' || $k == 'suspendedctime') { if ($k == 'expiry' || $k == 'lastlogin' || $k == 'lastlastlogin' || $k == 'lastaccess' || $k == 'suspendedctime' || $k == 'ctime') {
$this->stdclass->{$k} = db_format_timestamp($this->get($k)); $this->stdclass->{$k} = db_format_timestamp($this->get($k));
} else { } else {
$this->stdclass->{$k} = $this->get($k);//(is_null($this->get($k))? 'NULL' : $this->get($k)); $this->stdclass->{$k} = $this->get($k);//(is_null($this->get($k))? 'NULL' : $this->get($k));
...@@ -803,7 +816,8 @@ class LiveUser extends User { ...@@ -803,7 +816,8 @@ class LiveUser extends User {
' . db_format_tsfield('lastlogin') . ', ' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ', ' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ', ' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . ' ' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM FROM
{usr} {usr}
WHERE WHERE
......
...@@ -104,6 +104,7 @@ ...@@ -104,6 +104,7 @@
<FIELD NAME="quota" TYPE="int" LENGTH="10" NOTNULL="false"/> <FIELD NAME="quota" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="quotaused" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" /> <FIELD NAME="quotaused" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="authinstance" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" /> <FIELD NAME="authinstance" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="false" />
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" /> <KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
...@@ -1322,7 +1322,6 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -1322,7 +1322,6 @@ function xmldb_core_upgrade($oldversion=0) {
// @TODO: Stats upgrade: // @TODO: Stats upgrade:
// Daily data: count of logged-in users // Daily data: count of logged-in users
// Add ctime to usr table for count of users created
// Add visits column to view table, updated daily from log on filesystem // Add visits column to view table, updated daily from log on filesystem
if ($oldversion < 2009122200) { if ($oldversion < 2009122200) {
...@@ -1355,6 +1354,12 @@ function xmldb_core_upgrade($oldversion=0) { ...@@ -1355,6 +1354,12 @@ function xmldb_core_upgrade($oldversion=0) {
// Put best guess at installation time into config table. // Put best guess at installation time into config table.
set_config('installation_time', get_field_sql("SELECT MIN(ctime) FROM {site_content}")); set_config('installation_time', get_field_sql("SELECT MIN(ctime) FROM {site_content}"));
// Add ctime to usr table for daily count of users created
$table = new XMLDBTable('usr');
$field = new XMLDBField('ctime');
$field->setAttributes(XMLDB_TYPE_DATETIME, null, null);
add_field($table, $field);
} }
return $status; return $status;
......
...@@ -1528,10 +1528,12 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul ...@@ -1528,10 +1528,12 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
db_begin(); db_begin();
if ($user instanceof User) { if ($user instanceof User) {
$user->create();
$user->commit(); $user->commit();
$user = $user->to_stdclass(); $user = $user->to_stdclass();
} }
else { else {
$user->ctime = db_format_timestamp(time());
$user->id = insert_record('usr', $user, 'id', true); $user->id = insert_record('usr', $user, 'id', true);
} }
// Bypass access check for 'copynewuser' institution/site views, because this user may not be logged in yet // Bypass access check for 'copynewuser' institution/site views, because this user may not be logged in yet
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment