Last active
December 30, 2015 04:19
-
-
Save shrop/67720ffece47c18575ef to your computer and use it in GitHub Desktop.
Rebuild permissions for running via Drush (no batch process)
This file contains 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
<?php | |
/** | |
* @file | |
* Rebuild the node access database with no php time limits. | |
*/ | |
/** | |
* Rebuilds the node access database (for use with drush php-script). | |
* | |
* This is code borrowed from Drupal core and slightly modified to run with | |
* drush. | |
* | |
* @see node_access_rebuild() | |
*/ | |
function node_access_rebuild_drush() { | |
db_delete('node_access')->execute(); | |
// Only recalculate if the site is using a node_access module. | |
if (count(module_implements('node_grants'))) { | |
// Try to allocate enough time to rebuild node grants. | |
drupal_set_time_limit(0); | |
$nids = db_query("SELECT nid FROM {node}")->fetchCol(); | |
foreach ($nids as $nid) { | |
$node = node_load($nid, NULL, TRUE); | |
// To preserve database integrity, only acquire grants if the node | |
// loads successfully. | |
if (!empty($node)) { | |
node_access_acquire_grants($node); | |
} | |
} | |
} | |
else { | |
// Not using any node_access modules. Add the default grant. | |
db_insert('node_access') | |
->fields(array( | |
'nid' => 0, | |
'realm' => 'all', | |
'gid' => 0, | |
'grant_view' => 1, | |
'grant_update' => 0, | |
'grant_delete' => 0, | |
)) | |
->execute(); | |
} | |
drupal_set_message(t('Content permissions have been rebuilt.')); | |
node_access_needs_rebuild(FALSE); | |
cache_clear_all(); | |
} | |
// Start node access rebuild process. | |
node_access_rebuild_drush(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
shrop said to run it like this: