node.api.php documents hook_delete and hook_node_delete.

The documentation for hook_delete says

This hook is invoked from node_delete_multiple() after the node has been removed from the node table in the database, before hook_node_delete() is invoked, and before field_attach_delete() is called.

The documentation for hook_node_delete says

This hook is invoked from node_delete_multiple() after the type-specific hook_delete() has been invoked, but before hook_entity_delete and field_attach_delete() are called, and before the node is removed from the node table in the database.

So one claims the sequence

  1. Remove from node table in database
  2. hook_delete
  3. hook_node_delete

and the other claims the sequence

  1. hook_delete
  2. hook_node_delete
  3. Remove from node table in database

They can't both be correct unless some of those events happen twice.

Comments

jhodgdon’s picture

Issue tags: +Novice

Thanks for the report! I think this page has the correct sequence (and I verified by looking at node_delete_multiple()):
https://api.drupal.org/api/drupal/modules!node!node.api.php/group/node_a...

This is a Drupal 7 issue only.

valderama’s picture

As far as I understand the db transaction is committed when the scope leaves node_delete_multiple(). Which means that the node is deleted from the database at the end, after all hook calls.

Also, the page referenced by jhodgdon documents it that way.

I'll prepare a patch which reflects this behavior.

valderama’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.6 KB

I have updated the documentation and added an additional paragraph with further clarification about the db_transaction. I took this paragraph from this issue, which was about node_save:
https://drupal.org/node/1677830

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! The documentation looks good, but the patch needs some work -- there are a lot of spaces at the ends of lines that need to be removed.

You should be able to set up your programming editor to remove and/or highlight end-of-line spaces.

valderama’s picture

Status: Needs work » Needs review
StatusFileSize
new1.59 KB

Alright, found the setting in netbeans which removes trailing whitespace on save :)

Here is a new patch...

jhodgdon’s picture

Status: Needs review » Needs work

That's better! Now just take the changes to .gitignore out of the patch. :)

valderama’s picture

Status: Needs work » Needs review
StatusFileSize
new1.33 KB

Oh, I did not realize that these changes came into the patch too. Sorry.

How does this patch look now?

jhodgdon’s picture

Status: Needs review » Fixed

Great, thanks!

My suggestion: Always do "git status" to see what you've changed before doing "git diff". Then if you want to get only some of the changes into the diff/patch, you can do something like "git diff modules" to get, for instance, just the changes in the modules directory and its subdirectories.

I was just getting set up to make some commits, so I committed this to 7.x.

The last submitted patch, 5: clarify_hook_order-2107231-5.patch, failed testing.

jhodgdon’s picture

Ignore the test failures. The patches won't apply because they've been committed. I should have waited to commit until the tests ran, but since it was a docs-only patch, I didn't. My bad...

Status: Fixed » Needs work

The last submitted patch, 7: clarify_hook_order-2107231-7.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.