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 @@ 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 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 @@ 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 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();