Issue #1813184 by brandenlhamilton, Lars Toomre, ACF, Berdir: Convert variable 'tracker_index_nid()' to state system.
parent
c4fec19a1e
commit
3fd80ed2b9
|
@ -59,6 +59,10 @@ class StateSystemUpgradePathTest extends UpgradePathTestBase {
|
|||
'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',
|
||||
|
|
|
@ -19,6 +19,10 @@ db_merge('variable')
|
|||
->key(array('name' => 'statistics_day_timestamp'))
|
||||
->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)))
|
||||
|
|
|
@ -221,7 +221,7 @@ class TrackerTest extends WebTestBase {
|
|||
$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')
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue