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 {
'parentuser' => null,
'loginanyway' => false,
'sesskey' => '',
'ctime' => null,
);
$this->attributes = array();
......@@ -111,7 +112,8 @@ class User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......@@ -148,7 +150,8 @@ class User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......@@ -214,6 +217,7 @@ class User {
' . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ',
' . db_format_tsfield('u.lastaccess', 'lastaccess') . ',
' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . '
' . db_format_tsfield('u.ctime', 'ctime') . '
FROM {usr} u
LEFT JOIN {auth_remote_user} r ON u.id = r.localusr
WHERE
......@@ -234,7 +238,8 @@ class User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......@@ -251,6 +256,14 @@ class User {
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
* values
......@@ -473,7 +486,7 @@ class User {
$this->stdclass = new StdClass;
reset($this->defaults);
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));
} else {
$this->stdclass->{$k} = $this->get($k);//(is_null($this->get($k))? 'NULL' : $this->get($k));
......@@ -803,7 +816,8 @@ class LiveUser extends User {
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
' . db_format_tsfield('suspendedctime') . ',
' . db_format_tsfield('ctime') . '
FROM
{usr}
WHERE
......
......@@ -104,6 +104,7 @@
<FIELD NAME="quota" TYPE="int" LENGTH="10" NOTNULL="false"/>
<FIELD NAME="quotaused" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="authinstance" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="1" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="false" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -1322,7 +1322,6 @@ function xmldb_core_upgrade($oldversion=0) {
// @TODO: Stats upgrade:
// 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
if ($oldversion < 2009122200) {
......@@ -1355,6 +1354,12 @@ function xmldb_core_upgrade($oldversion=0) {
// Put best guess at installation time into config table.
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;
......
......@@ -1528,10 +1528,12 @@ function create_user($user, $profile=array(), $institution=null, $remoteauth=nul
db_begin();
if ($user instanceof User) {
$user->create();
$user->commit();
$user = $user->to_stdclass();
}
else {
$user->ctime = db_format_timestamp(time());
$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
......
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