On a fresh drupal installation I put node clone module and rules module and simply tried to show a message on site when a node is cloned. For this I used rule event "After cloning a node" the rule export is as following

{ "rules_test_cloning" : {
    "LABEL" : "Test Cloning",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "clone" ],
    "ON" : { "clone_node" : [] },
    "DO" : [ { "drupal_message" : { "message" : "Test" } } ]
  }
}

It seems event "After cloning a node" is not firing

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

noopal’s picture

Hi

Im trying to use rules with latest release of this module but having the same problem.

I have set rules to perform an action when a node is clones but the action isnt being performed.

NWOM’s picture

I'm sadly experiencing the same issue.

NWOM’s picture

Version: 7.x-1.0-rc2 » 7.x-1.x-dev
tripodcreative’s picture

I can confirm that the rules event "After cloning a node" is not firing. I made multiple simple test rules and none have been evaluated on this event. I am using the latest stable version.

tripodcreative’s picture

After going through the code a bit and adding in some watchdog() function calls, as well as calls to undefined functions to see if the site would break (and thus read the code), I'm getting nothing. However, when I add the invoke event on _clone_node_prepare(), it fires. That's not the right function since we want to fire it on submit or save, but we know it works in that context. I'm going to keep digging and see if I can get it to fire under the correct circumstances.

TC

tripodcreative’s picture

It seems that the rule fails when the option "Pre-populate the node form fields" is set, as opposed to "Save as a new node then edit."

If you set it to "Save as a new node then edit," the rule fires. This seems to be because clone_node_save is only invoked by functions that are called if the save as new node is set. There's gotta be another function that handles submit if you set to the first option to pre-populate. I don't have time to look into that tonight, but if you select "Save as a new node then edit," you should be good to go w/ rules for the time being.

TC

noopal’s picture

There's already an action to run a rule when a node gets edited.

This will work when the clone option is set to "Save as a new node then edit".

Isn't the clone_node_save function kinda redundant in this situation?

pwolanin’s picture

Status: Active » Needs review
FileSize
1.22 KB

Not sure about the use case, but something like this?

At least would be more consistent.

thekevinday’s picture

Switching to "Save as a new node then edit" is not acceptable for me as I do not want rules to fire that react on new or updated nodes until after any modifications to the clone have been made.

The issue seems to be that there is no presave rule for node_clone.
After looking at the code I found that this can be best implemented as a node_clone_prepare rule.
This happens at the prepare step because a save may not have yet happened.

I have attached a patch that adds the "Preparing a node clone" rule.

You will have to clear the site cache after applying this patch to see the new rule.

pwolanin’s picture

I'm not sure what the use case is for such a rule. It seems like you'd use the alter hook instead?

myDrupal2014_846824658246’s picture

Is it possible that this is still not working after 2 years?

myDrupal2014_846824658246’s picture

Trying to apply the patch #9 but getting a error on version = "7.x-1.0";
The command I use is:

$ patch -p0 --dry-run < node_clone-7.x-1.x-add_preparing_clone_rule-2212039-9.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/clone.module b/clone.module
|index 7b84031..f8e36a8 100644
|--- a/clone.module
|+++ b/clone.module
--------------------------
File to patch:

What to do?

pinueve’s picture