fetchField(); // A place to store messages during the run. $sandbox['messages'] = array(); // Last node read via the query. $sandbox['current_node'] = -1; } // Process nodes by groups of 10 (arbitrary value). // When a group is processed, the batch update engine determines // whether it should continue processing in the same request or provide // progress feedback to the user and wait for the next request. $limit = 10; // Retrieve the next group of nids. $result = db_select('node', 'n') ->fields('n', array('nid')) ->orderBy('n.nid', 'ASC') ->where('n.nid > :nid', array(':nid' => $sandbox['current_node'])) ->extend('PagerDefault') ->limit($limit) ->execute(); foreach ($result as $row) { // Here we actually perform a dummy 'update' on the current node. $node = db_query('SELECT nid FROM {node} WHERE nid = :nid', array(':nid' => $row->nid))->fetchField(); // Update our progress information. $sandbox['progress']++; $sandbox['current_node'] = $row->nid; } // Set the "finished" status, to tell batch engine whether this function // needs to run again. If you set a float, this will indicate the progress // of the batch so the progress bar will update. $sandbox['#finished'] = ($sandbox['progress'] >= $sandbox['max']) ? TRUE : ($sandbox['progress'] / $sandbox['max']); // Set up a per-run message; Make a copy of $sandbox so we can change it. // This is simply a debugging stanza to illustrate how to capture status // from each pass through hook_update_N(). $sandbox_status = $sandbox; // Don't want them in the output. unset($sandbox_status['messages']); $sandbox['messages'][] = t('$sandbox=') . print_r($sandbox_status, TRUE); if ($sandbox['#finished']) { // hook_update_N() may optionally return a string which will be displayed // to the user. $final_message = '