Commit 026508fb authored by catch's avatar catch

Issue #1831522 by miro_dietiker, pdrake, Berdir: Convert statistics variables to config/state.

parent 23ab7488
......@@ -172,7 +172,7 @@ function testExpiredLogs() {
->set('count_content_views', 1)
->set('access_log.max_lifetime', 1)
->save();
variable_set('statistics_day_timestamp', 8640000);
state()->set('statistics.day_timestamp', 8640000);
$this->drupalGet('node/' . $this->test_node->nid);
// Manually calling statistics.php, simulating ajax behavior.
......
......@@ -5,6 +5,15 @@
* Install and update functions for the Statistics module.
*/
/**
* Implements hook_uninstall().
*/
function statistics_uninstall() {
// Remove states.
state()->delete('statistics.node_counter_scale');
state()->delete('statistics.day_timestamp');
}
/**
* Implements hook_schema().
*/
......@@ -154,3 +163,13 @@ function statistics_update_8001() {
array('primary key' => array('nid'))
);
}
/**
* Convert variables to state.
*/
function statistics_update_8002() {
update_variables_to_state(array(
'node_cron_views_scale' => 'statistics.node_counter_scale',
'statistics_day_timestamp' => 'statistics.day_timestamp',
));
}
......@@ -226,14 +226,14 @@ function statistics_user_predelete($account) {
* Implements hook_cron().
*/
function statistics_cron() {
$statistics_timestamp = variable_get('statistics_day_timestamp', '');
$statistics_timestamp = state()->get('statistics.day_timestamp') ?: 0;
if ((REQUEST_TIME - $statistics_timestamp) >= 86400) {
// Reset day counts.
db_update('node_counter')
->fields(array('daycount' => 0))
->execute();
variable_set('statistics_day_timestamp', REQUEST_TIME);
state()->set('statistics.day_timestamp', REQUEST_TIME);
}
// Delete access logs (if applicable).
......@@ -437,7 +437,7 @@ function statistics_ranking() {
),
// Inverse law that maps the highest view count on the site to 1 and 0 to 0.
'score' => '2.0 - 2.0 / (1.0 + node_counter.totalcount * CAST(:scale AS DECIMAL))',
'arguments' => array(':scale' => variable_get('node_cron_views_scale', 0)),
'arguments' => array(':scale' => state()->get('statistics.node_counter_scale') ?: 0),
),
);
}
......@@ -447,7 +447,7 @@ function statistics_ranking() {
* Implements hook_update_index().
*/
function statistics_update_index() {
variable_set('node_cron_views_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
state()->set('statistics.node_counter_scale', 1.0 / max(1, db_query('SELECT MAX(totalcount) FROM {node_counter}')->fetchField()));
}
/**
......
......@@ -43,6 +43,14 @@ public function testSystemVariableUpgrade() {
'value' => 1304208001,
'variable_name' => 'node_cron_last',
);
$expected_state['statistics.day_timestamp'] = array(
'value' => 1352070595,
'variable_name' => 'statistics_day_timestamp',
);
$expected_state['statistics.node_counter_scale'] = array(
'value' => 1.0 / 2000,
'variable_name' => 'node_cron_views_scale',
);
$expected_state['system.cron_last'] = array(
'value' => 1304208002,
'variable_name' => 'cron_last',
......
......@@ -11,6 +11,14 @@
*/
// Update system settings to known values.
db_merge('variable')
->key(array('name' => 'node_cron_views_scale'))
->fields(array('value' => serialize(1.0 / 2000)))
->execute();
db_merge('variable')
->key(array('name' => 'statistics_day_timestamp'))
->fields(array('value' => serialize(1352070595)))
->execute();
db_merge('variable')
->key(array('name' => 'update_last_check'))
->fields(array('value' => serialize(1304208000)))
......
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