Commit e79ac4ff authored by Nigel McNie's avatar Nigel McNie
Browse files

[sfd08] Add 'lastaccess' field to users.

There is a configuration parameter that sets how often this field is updated. This prevents DB writes every page load, though this behaviour can be achieved by setting the parameter to 0 if necessary.
parent dfe7170d
......@@ -63,6 +63,7 @@ class User {
'expirymailsent' => 0,
'lastlogin' => null,
'lastlastlogin' => null,
'lastaccess' => null, /* Is not necessarily updated every request, see accesstimeupdatefrequency config variable */
'lastauthinstance' => null,
'inactivemailsent' => 0,
'staff' => 0,
......@@ -109,6 +110,7 @@ class User {
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
{usr}
......@@ -145,6 +147,7 @@ class User {
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
{usr}
......@@ -209,6 +212,7 @@ class User {
' . db_format_tsfield('u.expiry', 'expiry') . ',
' . db_format_tsfield('u.lastlogin', 'lastlogin') . ',
' . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ',
' . db_format_tsfield('u.lastaccess', 'lastaccess') . ',
' . db_format_tsfield('u.suspendedctime', 'suspendedctime') . '
FROM {usr} u
LEFT JOIN {auth_remote_user} r ON u.id = r.localusr
......@@ -229,6 +233,7 @@ class User {
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
{usr}
......@@ -399,7 +404,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 == 'suspendedctime') {
if ($k == 'expiry' || $k == 'lastlogin' || $k == 'lastlastlogin' || $k == 'lastaccess' || $k == 'suspendedctime') {
$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));
......@@ -666,6 +671,7 @@ class LiveUser extends User {
' . db_format_tsfield('expiry') . ',
' . db_format_tsfield('lastlogin') . ',
' . db_format_tsfield('lastlastlogin') . ',
' . db_format_tsfield('lastaccess') . ',
' . db_format_tsfield('suspendedctime') . '
FROM
{usr}
......@@ -726,14 +732,25 @@ class LiveUser extends User {
}
/**
* Assuming that a session is already active for a user, this method
* retrieves the information from the session and creates a user object
* that the script can use
*
* @return object
* Updates information in a users' session once we know their session is
* continuing
*/
public function renew() {
$this->set('logout_time', time() + get_config('session_timeout'));
$time = time();
$this->set('logout_time', $time + get_config('session_timeout'));
$oldlastaccess = $this->get('lastaccess');
// If there is an access time update frequency, we use a cookie to
// prevent updating before this time has expired.
// If it is set to zero, we always update the accesstime.
$accesstimeupdatefrequency = get_config('accesstimeupdatefrequency');
if ($accesstimeupdatefrequency == 0) {
$this->set('lastaccess', $time);
$this->commit();
}
else if ($oldlastaccess + $accesstimeupdatefrequency < $time) {
$this->set('lastaccess', $time);
$this->commit();
}
}
/**
......@@ -761,6 +778,7 @@ class LiveUser extends User {
session_regenerate_id(true);
$this->lastlastlogin = $this->lastlogin;
$this->lastlogin = time();
$this->lastaccess = time();
$this->sessionid = session_id();
$this->logout_time = time() + get_config('session_timeout');
$this->sesskey = get_random_key();
......
......@@ -138,4 +138,11 @@ $cfg->imagemaxheight = 1024;
// paths and arguments for various system commands
$cfg->pathtounzip = '/usr/bin/unzip';
$cfg->unzipdirarg = '-d';
// How often Mahara should update the last access time for users. Setting this
// lower means the field will be updated more regularly, but means a database
// write will be required for more requests.
// Setting it to zero means the access time will be updated every request
$cfg->accesstimeupdatefrequency = 300;
?>
......@@ -82,6 +82,7 @@
<FIELD NAME="expirymailsent" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="lastlogin" TYPE="datetime" NOTNULL="false"/>
<FIELD NAME="lastlastlogin" TYPE="datetime" NOTNULL="false"/>
<FIELD NAME="lastaccess" TYPE="datetime" NOTNULL="false"/>
<FIELD NAME="inactivemailsent" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="staff" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
<FIELD NAME="admin" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0"/>
......
......@@ -1408,6 +1408,13 @@ function xmldb_core_upgrade($oldversion=0) {
add_field($table, $field);
}
if ($oldversion < 2008092000) {
$table = new XMLDBTable('usr');
$field = new XMLDBField('lastaccess');
$field->setAttributes(XMLDB_TYPE_DATETIME, null, null);
add_field($table, $field);
}
return $status;
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008091604;
$config->version = 2008092000;
$config->release = '1.1.0alpha2dev';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
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