node_access_rebuild

  1. drupal
    1. 5
    2. 8
    3. 6
    4. 7
Versions
5 node_access_rebuild()
8 – 7 node_access_rebuild($batch_mode = FALSE)

Rebuild the node access database. This is occasionally needed by modules that make system-wide changes to access levels.

Related topics

Code

modules/node/node.module, line 3014

<?php
function node_access_rebuild() {
  db_query("DELETE FROM {node_access}");
  // only recalculate if site is using a node_access module
  if (count(module_implements('node_grants'))) {
    // If not in 'safe mode', increase the maximum execution time:
    if (!ini_get('safe_mode')) {
      set_time_limit(240);
    }
    $result = db_query("SELECT nid FROM {node}");
    while ($node = db_fetch_object($result)) {
      $loaded_node = node_load($node->nid, NULL, TRUE);
      // To preserve database integrity, only aquire grants if the node
      // loads successfully.
      if (!empty($loaded_node)) {
        node_access_acquire_grants($loaded_node);
      }
    }
  }
  else {
    // not using any node_access modules. add the default grant.
    db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
  }
  cache_clear_all();
}
?>