Created
September 2, 2015 10:21
-
-
Save johnennewdeeson/6d4a6d667538e6149f56 to your computer and use it in GitHub Desktop.
Rebuild all content node access permissions in an update hook
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
/** | |
* Rebuild node access permissions. | |
* node_access_rebuild(TRUE) claims to be able to do this in batch mode but all it does is set a | |
* batch. There is no way to process the batch from within an update hook. You could do it using | |
* a separate drush command but if you only have access to run updb on your production env | |
* then you need to do all the processing from within the update hook. This gem allows complete | |
* safe permission rebuild, batched, from within a single update hook. | |
*/ | |
function mymodule_update_7001(&$sandbox) { | |
_node_access_rebuild_batch_operation($sandbox); | |
$sandbox['#finished'] = $sandbox['sandbox']['progress'] >= $sandbox['sandbox']['max']; | |
if ($sandbox['#finished']) { | |
node_access_needs_rebuild(FALSE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a helpful example. I modified it a bit and used it in https://www.drupal.org/project/hook_update_deploy_tools#rebuild-node-access
When called in a hook_updated_N it runs the batch and reports on the progress as it goes.