Commit d2a1852c authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Add cron job to store institution stats



Change-Id: Ie0d96d6caa5b6aff66bdb49e14940ab349046147
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent 81128042
......@@ -974,5 +974,27 @@
<KEY NAME="regdatafk" TYPE="foreign" FIELDS="registration_id" REFTABLE="site_registration" REFFIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="institution_registration">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="time" TYPE="datetime" NOTNULL="true"/>
<FIELD NAME="institution" TYPE="char" LENGTH="255" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="institutionfk" TYPE="foreign" FIELDS="institution" REFTABLE="institution" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="institution_registration_data">
<FIELDS>
<FIELD NAME="registration_id" TYPE="int" LENGTH="10" NOTNULL="true"/>
<FIELD NAME="field" TYPE="char" LENGTH="100" NOTNULL="true"/>
<FIELD NAME="value" TYPE="text" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="registration_id,field"/>
<KEY NAME="regdatafk" TYPE="foreign" FIELDS="registration_id" REFTABLE="institution_registration" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -2965,5 +2965,34 @@ function xmldb_core_upgrade($oldversion=0) {
create_table($table);
}
if ($oldversion < 2012062901) {
// Add institution registration data tables
$table = new XMLDBTable('institution_registration');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('time', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addFieldInfo('institution', XMLDB_TYPE_CHAR, 255, null, null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->addKeyInfo('institutionfk', XMLDB_KEY_FOREIGN, array('institution'), 'institution', array('name'));
create_table($table);
$table = new XMLDBTable('institution_registration_data');
$table->addFieldInfo('registration_id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL);
$table->addFieldInfo('field', XMLDB_TYPE_CHAR, 100, XMLDB_UNSIGNED, XMLDB_NOTNULL);
$table->addFieldInfo('value', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('registration_id', 'field'));
$table->addKeyInfo('regdatafk', XMLDB_KEY_FOREIGN, array('registration_id'), 'institution_registration', array('id'));
create_table($table);
// Install a cron job to collection institution registration data
$cron = new StdClass;
$cron->callfunction = 'cron_institution_registration_data';
$cron->minute = rand(0,59);
$cron->hour = rand(0,23);
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = rand(0,6);
insert_record('cron', $cron);
}
return $status;
}
......@@ -2757,6 +2757,14 @@ function cron_send_registration_data() {
}
}
/**
* Cronjob to store the institution statistics
*/
function cron_institution_registration_data() {
require_once(get_config('libroot') . 'registration.php');
institution_registration_store_data();
}
/**
* Cronjob to save weekly site data locally
*/
......
......@@ -204,6 +204,25 @@ function registration_data() {
return $data_to_send;
}
function institution_registration_store_data() {
$data = institution_registration_data();
db_begin();
foreach ($data as $institution => $inst_data) {
$registration_id = insert_record('institution_registration', (object)array(
'time' => db_format_timestamp(time()),
'institution' => $institution,
), 'id', true);
foreach ($inst_data as $key => $value) {
insert_record('institution_registration_data', (object)array(
'registration_id' => $registration_id,
'field' => $key,
'value' => $value
));
}
}
db_commit();
}
function institution_registration_data() {
$data_to_store = array();
foreach (get_column('institution', 'name') as $institution) {
......@@ -293,7 +312,7 @@ function institution_registration_data() {
FROM {usr} u
WHERE u.id IN (' . join(',', array_fill(0, count($members), '?')) . ')',
$members)) {
$inst_data['usersloggedin'] = $data->sum;
$inst_data['usersloggedin'] = isset($data->sum) ? $data->sum : 0;
}
else {
$inst_data['usersloggedin'] = 0;
......
......@@ -873,6 +873,7 @@ function core_install_firstcoredata_defaults() {
'cron_sitemap_daily' => array(0, 1, '*', '*', '*'),
'file_cleanup_old_cached_files' => array(0, 1, '*', '*', '*'),
'user_login_tries_to_zero' => array('*/5', '*', '*', '*', '*'),
'cron_institution_registration_data' => array(rand(0, 59), rand(0, 23), '*', '*', rand(0, 6)),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new StdClass;
......
......@@ -30,7 +30,7 @@ defined('INTERNAL') || die();
$config = new StdClass;
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2012062900;
$config->version = 2012062901;
$config->release = '1.6.0dev';
$config->minupgradefrom = 2008040200;
$config->minupgraderelease = '1.0.0 (release tag 1.0.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