1

I currently have a project where I am inserting mulitple records into Drupal using node_save. Its usually a couple of hundred at a time. For some reason, sometimes the node_access table ends up empty, resulting in the data "appearing" deleted to the users.

Does anyone know what could possible be happening?

I have reviewed the node_save code and notice is does run a call to rebuild the node_access table via node_access_acquire_grants($node). Currently I have no modules implementing node_access hooks.

My one thought was to just call node_access_rebuild() once I've finished inserting. I also run the process a few times every hour.

Side Note: Drupal may not be the right system for the bulk inserts and volume, but that is not the discussion I wish to have on this question.

  • What do you mean with "sometimes the node_access table ends up empty?" Do you mean that sometimes the table contains data, and sometimes doesn't? It would help to know which code you use to save multiple nodes, and if the code is only invoking node_save() – kiamlaluno Mar 16 '11 at 19:15
  • the node_access table will get a default entry of "grant all" if no modules implement node_access hooks. However, the table somehow ends up empty randomly. I suspect during its reset in node_access_write_grants(). – lordg Mar 16 '11 at 19:33
1

The only moment where the node access table could be empty is when node_access_write_grants() (or node_access_rebuild()) deletes the content of the table before to repopulate it.
In the case of node_access_write_grants(), the table could become empty only if the table contained the access data for a node; in the case of node_access_rebuild(), the table becomes empty in any cases.

Sometimes the all entry can vanish, as node_access_acquire_grants() adds that entry only if no modules returned access records for the node passed as argument to the function, and node_access_rebuild() adds that entry if no module returned access records.

To notice also that, in the case the $realm passed to node_access_write_grants() doesn't match with the value contained in $grant['realm'] (for all the grants passed to the function), then node_access_write_grants() will delete the access records for the node passed as argument, but it will not save any access records.

// Only perform work when node_access modules are active.
if (count(module_implements('node_grants'))) {
  foreach ($grants as $grant) {
    if ($realm && $realm != $grant['realm']) {
      continue;
    }
    // Only write grants; denies are implicit.
    if ($grant['grant_view'] || $grant['grant_update'] || $grant['grant_delete']) {
      db_query("INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (%d, '%s', %d, %d, %d, %d)", $node->nid, $grant['realm'], $grant['gid'], $grant['grant_view'], $grant['grant_update'], $grant['grant_delete']);
    }
  }
}

The same can happen if a module calls node_access_write_grants() using the default value for $delete, and there aren't modules implementing hook_node_grants().
In these cases, the node access table can become empty if the table contained data only for the node passed as argument to node_access_write_grants().

  • thanks for this post. the odd thing is I have no modules implementing hooks for the node_access functions. And it only happens occasionally. – lordg Mar 17 '11 at 20:40
  • @lordg: Even without any modules that implement access permissions, node_access_write_records() still deletes the content of the table, and writes the single row. – kiamlaluno Mar 18 '11 at 0:00
  • if node_access_rebuild times out, will the table remain empty? – awm Jun 25 '13 at 22:27
-1

The node_access table is only populated if you use a node access module.

Some examples are Content Access, Taxonomy Access Control Lite, or Node Access.

  • This is incorrect. The following process happens if no modules implement the node access hooks: node_save calls node_access_acquire_grants($node), which calls node_access_write_grants($node, $grants). node_access_acquire_grants will build a default grant of all. – lordg Mar 16 '11 at 19:28
  • I had a looser definition of populated. I meant other than the global grant. – tim.plunkett Mar 16 '11 at 20:19

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.