1

Is it possible/expected that node_save() does not create a new record until the current php session is complete?

In other words, if i have a set of nodes to create and i need to check something that is based on the entire list of nodes prior to creating each one; the ones i am creating in my script will not yet be included in the full list?

1 Answer 1

0

Is it possible/expected that node_save() does not create a new record until the current php session is complete?

I'm not sure 'session' is the right word there, I'm assuming you mean 'current request' (queuing actions to be run when the session has expired would be an odd thing, and not something PHP/Drupal would do without you telling it to).

Either way, before node_save() completes it commits the database transaction and flushes relevant caches. So no, it doesn't wait for the current request to complete.

So to address

the ones i am creating in my script will not yet be included in the full list?

No, once you've saved the node, and assuming it completed without error, it will be in the database and available immediately via node_load().

Of course you don't actually need to load it, as your $node object will be in an identical state to the loaded node when node_save() has completed anyway.

Ignoring all that, if you actually mean "does running node_save() automatically update an array of nodes I've previously loaded into a variable earlier in the script", then also no. That would be magic :)

2
  • Yes, you understand what i am doing.. and no, it does not appear to work that way from what i see.. i stop execution AFTER the node_save() call has completed and the record has not been added to my db (even though i have a nid assigned. later in the code i do a entityfieldquery to pull a list of nodes and this "new" node is not in my list (which makes sense as it is still not in the db).
    – liquidcms
    Aug 29, 2014 at 18:13
  • If it has a nid but isn't in the database then you've got bigger problems. The db engine provides Drupal with that nid, so if it's giving you an id, but not storing the data, there's something wrong with it
    – Clive
    Aug 29, 2014 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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