Commit 4d0f782b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add cron job to save weekly view/user/group counts


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent b99fde67
......@@ -1321,19 +1321,30 @@ function xmldb_core_upgrade($oldversion=0) {
}
// @TODO: Stats upgrade:
// Need table for weekly stats: counts of users, groups, views, view visits
// Daily data: count of logged-in users
// Add ctime to usr table for count of users created
// Add site start time to config table; initialise with earliest ctime from view, artefact, site_content?
// Add visits column to view table, updated daily from log on filesystem
// Records in cron table
if ($oldversion < 2009122200) {
// Table for collection of historical stats
$table = new XMLDBTable('site_data');
$table->addFieldInfo('ctime', XMLDB_TYPE_DATETIME, null, XMLDB_NOTNULL);
$table->addFieldInfo('type', XMLDB_TYPE_CHAR, 255, null, XMLDB_NOTNULL);
$table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('ctime','type'));
create_table($table);
// Insert a cron job to save weekly site data
$cron = new StdClass;
$cron->callfunction = 'cron_site_data_weekly';
$cron->minute = 55;
$cron->hour = 23;
$cron->day = '*';
$cron->month = '*';
$cron->dayofweek = 6;
insert_record('cron', $cron);
}
return $status;
......
......@@ -2205,6 +2205,27 @@ function cron_send_registration_data() {
}
}
/**
* Cronjob to save weekly site data locally
*/
function cron_site_data_weekly() {
$time = db_format_timestamp(time());
insert_record('site_data', (object) array(
'ctime' => $time,
'type' => 'user-count',
'value' => count_records_select('usr', 'id > 0 AND deleted = 0'),
));
insert_record('site_data', (object) array(
'ctime' => $time,
'type' => 'group-count',
'value' => count_records('group', 'deleted', 0),
));
insert_record('site_data', (object) array(
'ctime' => $time,
'type' => 'view-count',
'value' => count_records_select('view', 'owner <> 0'),
));
}
function random_string($length=15) {
$pool = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
......
......@@ -771,6 +771,7 @@ function core_install_firstcoredata_defaults() {
'cron_send_registration_data' => array(rand(0, 59), rand(0, 23), '*', '*', rand(0, 6)),
'export_cleanup_old_exports' => array('0', '3,15', '*', '*', '*'),
'import_cleanup_old_imports' => array('0', '4,16', '*', '*', '*'),
'cron_site_data_weekly' => array('55', '23', '*', '*', '6'),
);
foreach ($cronjobs as $callfunction => $times) {
$cron = new StdClass;
......
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