public static function Nodes::rebuildNodeAccess in Hook Update Deploy Tools 7
Rebuild the node access table and report its success.
Parameters
array $sandbox: The sandbox variable passed into a hook_update_N(&$sandbox);
File
- src/
Nodes.php, line 573
Class
- Nodes
- Public method for changing nodes programatically.
Namespace
HookUpdateDeployToolsCode
public static function rebuildNodeAccess(&$sandbox) {
// Is this the first run?
if (empty($sandbox['sandbox']['progress'])) {
// This is the first run. So start by whiping out the old.
db_delete('node_access')
->execute();
$sandbox['messages'] = array();
$sandbox['messages'][] = Message::make('Deleted table node_access. Rebuilding the node access table.', array(), WATCHDOG_INFO);
$sandbox['iteration'] = 0;
$sandbox['progress'] = 1;
}
_node_access_rebuild_batch_operation($sandbox);
$sandbox['iteration']++;
$sandbox['#finished'] = $sandbox['sandbox']['progress'] >= $sandbox['sandbox']['max'];
if ($sandbox['#finished']) {
// The batch is done so this was the last iteration.
node_access_needs_rebuild(FALSE);
// Count the number of rows now in the access table.
$num_rows = db_select('node_access')
->countQuery()
->execute()
->fetchField();
$variables = array(
'!rows' => $num_rows,
'!iterations' => $sandbox['iteration'],
);
$messages = implode(' ', $sandbox['messages']);
$messages .= Message::make('node_access table rebuilt !rows rows in !iterations batches.', $variables, WATCHDOG_INFO);
return $messages;
}
else {
// This is just one of the iterations, so give some progress feedback.
$variables = array(
'!percent' => round($sandbox['sandbox']['progress'] / $sandbox['sandbox']['max'] * 100, 1),
'!iteration' => $sandbox['iteration'],
'!progress' => $sandbox['sandbox']['progress'],
'!max' => $sandbox['sandbox']['max'],
);
return t("#!iteration Rebuilding node_access_table (!progress/!max) -> !percent%", $variables);
}
}