Created
July 6, 2017 17:06
-
-
Save JeffTomlinson/d686ae552a78eb52bc7a0e5d46b8e487 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Explanation of what this update does. | |
*/ | |
function example_update_7100(&$sandbox) { | |
$limit = 1; | |
if (!isset($sandbox['processed'])) { | |
$nids = db_select('node', 'n') | |
->fields('n', array('nid')) | |
->condition('type', 'page', '=') | |
->execute() | |
->fetchCol(); | |
if (empty($nids)) { | |
watchdog('example', 'There are no items to process.', array(), WATCHDOG_NOTICE); | |
return; | |
} | |
$sandbox['processed'] = 0; | |
$sandbox['total'] = count($nids); | |
$sandbox['nids'] = $nids; | |
} | |
for ($i = 0; $i < $limit; $i++) { | |
if ($nid = array_shift($sandbox['nids'])) { | |
// Do processing here. | |
} | |
$sandbox['processed']++; | |
} | |
$sandbox['#finished'] = ($sandbox['processed'] >= $sandbox['total']) ? 1 : ($sandbox['processed'] / $sandbox['total']); | |
$args = array( | |
'!processed' => $sandbox['processed'], | |
'!total' => $sandbox['total'], | |
'!pct' => round(($sandbox['processed'] / $sandbox['total']) * 100, 2), | |
); | |
return t('Completed !processed/!total (!pct%)', $args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment