Rebuild node permissions table on large sites with many nodes

Every now and again the node permissions table on a Drupal site can go out of whack. The result is that some users may get an accessed denied message when trying to access pages.

This is fairly easy to fix on a "normal size" website. You simply go to admin -> content -> post settings and click "Rebuild permissions".

However, this does not always work on a partcularly large Drupal based website. I have tried this on a site with around 11,000 nodes and it times out, giving me a page not found error.

One solution is to use a custom script to rebuild the node permissions one node at a time. I found this script on drupal.org:

http://drupal.org/node/158043#comment-881058

Thanks to enboig for the script.

I have used it on the site with 11,000 nodes and it works like a treat. Although it does take a long time to run. In this case, it took several hours. But at least it worked!

If you liked this, you'll love my book, Master Drupal Module Development.

"..the must have drupal developers book"


Feeling stuck with Drupal 8 module dev?

Get the free 7 lesson course that will help you get started today without feeling overwhelmed.

  • Create Drupal modules with just a few commands using the Drupal Console
  • Create custom pages
  • Create custom blocks
  • Create admin forms
  • Demystify routers and controllers
  • Bonus material

Find out more


Comments

Hi,

I want to run the script on my site. Could you help me where shall I keep the script in drupal?

Thnaks in advance.

Regards,
Sagar

Blair Wadman's picture

Hi Sagar,

You need to put the script in your Drupal root directory (the same directory that has the main index.php page).

I have noticed that the link that I posted no longer takes you direct to the comment with the code for the script. It has moved into the body of the post. It is now under "Node Access" under "WSODs Due to Specific Modules".

When I get a chance I'll post the script here as well to make it easier to find.

Run this code with firebug(remove php tags) or put it in node and click preview(choose php as input format):

<?php
set_time_limit(0);
db_query("DELETE FROM {node_access}");
node_access_rebuild();
?>

This has solved me many problems when the rebuilding gets
stuck etc.

This script saved my tail... Thank you Thank you

Note that there is still a hardcoded time limit in node.module :

See:

http://drupal.org/node/399572#comment-1347380

You can also work around this if you have a newer drush version with the following:
PHP_OPTIONS='-d disable_functions=set_time_limit -d max_execution_time=0 -d memory_limit=1024M' drush php-eval 'node_access_rebuild();'

Add new comment