Commit 42da6080 authored by Hugh Davenport's avatar Hugh Davenport
Browse files

Store weekly registration data in local table



Copied from the mahara.org registration table. It stores each registration field
in a local database with a timestamp of when the data was obtained.

This storage is done whether or not the data is actually sent to mahara.org.

Change-Id: Ib8478b0caa97c5cc5f04a7d5b44f2a9ac11f9ce8
Signed-off-by: default avatarHugh Davenport <hugh@catalyst.net.nz>
parent f9e5f92b
......@@ -954,5 +954,25 @@
<KEY NAME="namefk" TYPE="foreign" FIELDS="name" REFTABLE="iframe_source_icon" REFFIELDS="name" />
</KEYS>
</TABLE>
<TABLE NAME="site_registration">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="time" TYPE="datetime" NOTNULL="true"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
</KEYS>
</TABLE>
<TABLE NAME="site_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="site_registration" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
......@@ -2948,5 +2948,22 @@ function xmldb_core_upgrade($oldversion=0) {
add_key($table, $key);
}
if ($oldversion < 2012062900) {
// Add site registration data tables
$table = new XMLDBTable('site_registration');
$table->addFieldInfo('id', XMLDB_TYPE_INTEGER, 10, null, XMLDB_NOTNULL, XMLDB_SEQUENCE);
$table->addFieldInfo('time', XMLDB_TYPE_DATETIME, null, null, XMLDB_NOTNULL);
$table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
create_table($table);
$table = new XMLDBTable('site_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'), 'site_registration', array('id'));
create_table($table);
}
return $status;
}
......@@ -2740,11 +2740,12 @@ function cron_check_for_updates() {
* Cronjob to send an update of site statistics to mahara.org
*/
function cron_send_registration_data() {
require_once(get_config('libroot') . 'registration.php');
registration_store_data();
if (!get_config('registration_sendweeklyupdates')) {
return;
}
require_once(get_config('libroot') . 'registration.php');
$result = registration_send_data();
$data = json_decode($result->data);
......
......@@ -119,6 +119,21 @@ function registration_send_data() {
return mahara_http_request($request);
}
function registration_store_data() {
$data = registration_data();
db_begin();
$registration_id = insert_record('site_registration', (object)array(
'time' => db_format_timestamp(time()),
), 'id', true);
foreach ($data as $key => $value) {
insert_record('site_registration_data', (object)array(
'registration_id' => $registration_id,
'field' => $key,
'value' => ($value == null ? '' : $value)
));
}
db_commit();
}
/**
* Builds the data that will be sent by the "register your site" feature
......
......@@ -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 = 2012060100;
$config->version = 2012062900;
$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