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 ec7a945..4fb1f68 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php @@ -59,6 +59,10 @@ public function testSystemVariableUpgrade() { 'value' => 'kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M', 'variable_name' => 'cron_key', ); + $expected_state['tracker.index_nid'] = array( + 'value' => 0, + 'variable_name' => 'tracker_index_nid', + ); $expected_state['update.last_check'] = array( 'value' => 1304208000, 'variable_name' => 'update_last_check', 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 062ee91..a6f47ef 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 @@ -20,6 +20,10 @@ ->fields(array('value' => serialize(1352070595))) ->execute(); db_merge('variable') + ->key(array('name' => 'tracker_index_nid')) + ->fields(array('value' => serialize(0))) + ->execute(); +db_merge('variable') ->key(array('name' => 'update_last_check')) ->fields(array('value' => serialize(1304208000))) ->execute(); diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php index 189b927..e858a04 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -221,7 +221,7 @@ function testTrackerCronIndexing() { $this->drupalPost('comment/reply/' . $nodes[3]->nid, $comment, t('Save')); // Start indexing backwards from node 3. - variable_set('tracker_index_nid', 3); + state()->set('tracker.index_nid', 3); // Clear the current tracker tables and rebuild them. db_delete('tracker_node') diff --git a/core/modules/tracker/tracker.install b/core/modules/tracker/tracker.install index e30da69..429b88e 100644 --- a/core/modules/tracker/tracker.install +++ b/core/modules/tracker/tracker.install @@ -9,7 +9,7 @@ * Implements hook_uninstall(). */ function tracker_uninstall() { - variable_del('tracker_index_nid'); + state()->delete('tracker.index_nid'); } /** @@ -18,7 +18,7 @@ function tracker_uninstall() { function tracker_enable() { $max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField(); if ($max_nid != 0) { - variable_set('tracker_index_nid', $max_nid); + state()->set('tracker.index_nid', $max_nid); // To avoid timing out while attempting to do a complete indexing, we // simply call our cron job to remove stale records and begin the process. tracker_cron(); @@ -152,6 +152,15 @@ function tracker_update_8001() { } /** - * @} End of "addtogroup updates-7.x-to-8.x". + * Convert tracker_index_nid variable to state system. + * + * @ingroup state_upgrade + */ +function tracker_update_8002() { + update_variables_to_state(array('tracker_index_nid' => 'tracker.index_nid')); +} + +/** + * @} End of "defgroup updates-7.x-to-8.x". * The next series of updates should start at 9000. */ diff --git a/core/modules/tracker/tracker.module b/core/modules/tracker/tracker.module index 92f5701..4f01724 100644 --- a/core/modules/tracker/tracker.module +++ b/core/modules/tracker/tracker.module @@ -73,15 +73,16 @@ function tracker_menu() { /** * Implements hook_cron(). * - * Updates tracking information for any items still to be tracked. The variable - * 'tracker_index_nid' is set to ((the last node ID that was indexed) - 1) and + * Updates tracking information for any items still to be tracked. The state + * 'tracker.index_nid' is set to ((the last node ID that was indexed) - 1) and * used to select the nodes to be processed. If there are no remaining nodes to - * process, 'tracker_index_nid' will be 0. + * process, 'tracker.index_nid' will be 0. */ function tracker_cron() { - $max_nid = variable_get('tracker_index_nid', 0); - $batch_size = config('tracker.settings')->get('cron_index_limit'); + $state = state(); + $max_nid = $state->get('tracker.index_nid') ?: 0; if ($max_nid > 0) { + $batch_size = config('tracker.settings')->get('cron_index_limit'); $last_nid = FALSE; $result = db_query_range('SELECT nid, uid, status FROM {node} WHERE nid <= :max_nid ORDER BY nid DESC', 0, $batch_size, array(':max_nid' => $max_nid), array('target' => 'slave')); @@ -143,13 +144,13 @@ function tracker_cron() { if ($last_nid !== FALSE) { // Prepare a starting point for the next run. - variable_set('tracker_index_nid', $last_nid - 1); + $state->set('tracker.index_nid', $last_nid - 1); watchdog('tracker', 'Indexed %count content items for tracking.', array('%count' => $count)); } else { // If all nodes have been indexed, set to zero to skip future cron runs. - variable_set('tracker_index_nid', 0); + $state->set('tracker.index_nid', 0); } } }