summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcatch2012-11-09 22:30:28 (GMT)
committercatch2012-11-09 22:30:28 (GMT)
commit026508fb21fb29c0aeb734f1a3f1774bf38cd6db (patch)
treecb978c317cfc80550f42ed5a3740f497677485b5
parent23ab748832b6fec8e81c8552a44ef9f0ad0e232b (diff)
Issue #1831522 by miro_dietiker, pdrake, Berdir: Convert statistics variables to config/state.
-rw-r--r--core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php2
-rw-r--r--core/modules/statistics/statistics.install19
-rw-r--r--core/modules/statistics/statistics.module8
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php8
-rw-r--r--core/modules/system/tests/upgrade/drupal-7.state.system.database.php8
5 files changed, 40 insertions, 5 deletions
diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php
index a7487f7..528611e 100644
--- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php
+++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php
@@ -172,7 +172,7 @@ class StatisticsAdminTest extends WebTestBase {
->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.
diff --git a/core/modules/statistics/statistics.install b/core/modules/statistics/statistics.install
index c0d0a6f..5f2b7dd 100644
--- a/core/modules/statistics/statistics.install
+++ b/core/modules/statistics/statistics.install
@@ -6,6 +6,15 @@
*/
/**
+ * Implements hook_uninstall().
+ */
+function statistics_uninstall() {
+ // Remove states.
+ state()->delete('statistics.node_counter_scale');
+ state()->delete('statistics.day_timestamp');
+}
+
+/**
* Implements hook_schema().
*/
function statistics_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',
+ ));
+}
diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module
index f11f3ed..db45bee 100644
--- a/core/modules/statistics/statistics.module
+++ b/core/modules/statistics/statistics.module
@@ -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()));
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php
index 5f1ffc7..9c99f00 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php
@@ -43,6 +43,14 @@ class StateSystemUpgradePathTest extends UpgradePathTestBase {
'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',
diff --git a/core/modules/system/tests/upgrade/drupal-7.state.system.database.php b/core/modules/system/tests/upgrade/drupal-7.state.system.database.php
index aaacc5b..96e18b7 100644
--- a/core/modules/system/tests/upgrade/drupal-7.state.system.database.php
+++ b/core/modules/system/tests/upgrade/drupal-7.state.system.database.php
@@ -12,6 +12,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)))
->execute();