Node.module patch pre-save action causes Image_import problems and Pathauto to alias twice the URL

doc2@drupalfr.org - October 12, 2008 - 15:56
Project:Actions
Version:5.x-2.6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

Drupal 5.10
Image + Image Import 1.8
Actions 2.6 + Trigger Unlock 6.x-1.0
Workflow + Workflow access 2.3
Pathauto...

So, the new 2.x actions.module come with a patch for the node.module to pre-save a node so that it saves as well actions such as "publish/unpublish node" or "promote_to/remove_from front page".

My image_nodes belong to a workflow, therefore they get set from (creation) to my first workflow_state.

Each of my workflow_state transitions triggers an action such as publish/unpublish.

Since an action such as "publish/unpublish node" comes along with a by_default presave action which is necessary to make the first action effective, my image_nodes' get saved twice.

Here's the user message I get using the image_import.module :

  • The derivative images for TEST Papier rouge have been regenerated.
  • Created new alias doc/image-fixe/test-papier-rouge for node/10363
  • Created new alias doc/image-fixe/test-papier-rouge for node/10363
  • Successfully imported:
  • Papier pastel rouge brûlé.jpg as TEST Papier rouge [edit]
  • The selected file could not be copied, because no file by that name exists. Please check that you supplied the correct filename.

    Removing the node Save action from the Worflow transition "From (creation) To [My_First_W_State]" shortcuts the pre-save action therefore I get:

    • Created new alias doc/image-fixe/test-background for node/10361
    • Successfully imported:
    • background.jpg as TEST background [edit]

BUT
of course, the "publish/unpublish node" action is *not* saved.

So, what to do? Hack the image/image_import module? Or change something from the actions.module?

#1

doc2@drupalfr.org - October 12, 2008 - 16:10
Title:Node.module patch pre-save action causes Image_import problems» Node.module patch pre-save action causes Image_import problems and Pathauto to alias twice the URL

We'll notice up there that the Pathauto user message witnesses the two node saves... and creates twice the URL alias for my node, which is not desirable. This was my clue to explain the "no file by that name" error of the image_import.module.

This bug (as I guess it is) may affect other hooks from different module (than mine for example) invoked when saving a node.

BTW, the watchdog witnesses cron_runs when the pre-save action is enabled, but no cron when it's not. What's the real benefit of this? Is this a backport functionnality of d6 which can be avoided? If yes, Would Actions 2.x still work?

#2

jvandyk - October 25, 2008 - 20:16

Neither of the above makes much sense to me, but I can explain what the presave hook does. When node_save() runs, it

1. Takes a node object
2. Saves it
3. Calls hook_nodeapi(&$node, 'insert') if the node is new or hook_nodeapi(&$node, 'update') if the node is being updated.

The presave hook runs during (1), above. The node has not yet been saved. Thus, an action like "publish node" will just flip the bit on the node object before it gets saved. Very efficient.

Compare that with doing it during (3). Since the node has already been saved (in (2)) now if you want to change a node property you're going to have to save the node again.

You can see how the presave, insert and update hooks are presented by the trigger administration page in the attached screenshot.

That is why when you add an action that changes a node property to a hook other than the presave hook, a "Save post" action is automatically added as well, and you get the message "You have added an action that changes a the property of a post. A Save post action has been added so that the property change will be saved."

The fact that the workflow module does not use the presave op (since there was no such thing in Drupal 5) makes things a bit messy.

AttachmentSize
actionops.jpg 54.46 KB
 
 

Drupal is a registered trademark of Dries Buytaert.