diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsAdminTest.php index a7487f7f4d1f48871b3a71b28724d2570d1512fa..528611e95486d31f335e1272e49faf47b30755f8 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 @@ 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. diff --git a/core/modules/statistics/statistics.install b/core/modules/statistics/statistics.install index c0d0a6fe80d3196d74e6c14466ef38a84b392fa1..5f2b7dda83113841db0c44f51ce33971713c4229 100644 --- a/core/modules/statistics/statistics.install +++ b/core/modules/statistics/statistics.install @@ -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', + )); +} diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index f11f3ed5fe0e7b5205f51ea1c9b9b5521efc8fc7..db45bee615383b46a25457ec97d91e462468e013 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 5f1ffc7214ba5d90ac93c01e0c445e3a250b9821..9c99f0098cc5d35733192d7fb5dae3301b9e4030 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 @@ 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', 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 aaacc5b8caf0a93a3ad6b294eae2d66777d4aa27..96e18b739536cfeb8feb040f7ff90201c58c09ae 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 @@ -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)))