6

How can I rebuild the node access permissions?

drupal node:access:rebuild returns the following error message.

[Symfony\Component\Console\Exception\CommandNotFoundException] There are no commands defined in the "node:access" namespace.

I am using Drupal Console 0.11.3 and Drupal 8.2.0-rc2.

3 Answers 3

6

If you're having issues with Drupal Console, you don't have access to it, or you're not using Drush, you can also do it via the UI.

  • Login as an administrator
  • Visit /admin/reports/status (also located via the menu at Reports->Status report
  • Find the Node access permissions section
  • Click on the Rebuild Permissions link (which is also located on /admin/reports/status/rebuild)
1
  • 1
    Worth mentioning that when doing this from the UI it can get quite a lengthy process when having a huge amount of nodes. PHP settings may need to be adjusted accordingly.
    – leymannx
    Dec 27, 2018 at 23:55
13

With Drush:

drush php-eval 'node_access_rebuild();'

With Drupal Console:

drupal node:access:rebuild

3
  • +1 for Drush, -1 for posting the exact command OP posted in their question.
    – leymannx
    Dec 27, 2018 at 23:37
  • 3
    Worth mentioning that when you have quite lots of nodes you better batch the process like so: drush php-eval 'node_access_rebuild($batch_mode = TRUE)'.
    – leymannx
    Dec 27, 2018 at 23:46
  • 1
    Would be useful you'd link the docs as well: node_access_rebuild()
    – leymannx
    Dec 28, 2018 at 0:00
1

For those people for whom running node_access_rebuild function using drush is not working.

I'm not very familiar with drush internals, but the code drush php-eval 'node_access_rebuild();' won't trigger batch processing. At least on the next drush/drupal versions (9.2.8, 10.6.1).

The thing is node_access_rebuild function do not call batch processing immediaetly.

What worked for me is writing drush script to call batch processing explicitly:

<?php
// filename: rebuildPermissions.drush.php
// based on topic https://www.drupal.org/node/873132
node_access_rebuild($batch_mode = TRUE);

$batch =& batch_get();
$batch['progressive'] = FALSE;
drush_backend_batch_process();

and then just run it: drush scr rebuildPermissions.drush.php

But in the end of the day I've used node_access_rebuild_progressive module for my needs and rebuilt 12K rules and 92K nodes in 5 minutes using drush.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.