I created rules to auto-generate the node title and path after the node was created (because Automatic Nodetitles wasn't doing this properly - the fix was suggested here and worked a treat). I also have User Points installed which gives a user 10 points for creating a new node and 5 for editing a node. Now when creating nodes I am being given 10 points, 5 points and another 5 points, all at the same time. I am not editing the nodes after creating them. If I turn off the rule which generates the node title after saving new content the problem goes away and I get just 10 points for creating the node, suggesting that the rule is generating two node revisions after a save. (Turning off the rules for generating the path after saving new content and updating node titles after editing doesn't make any difference.)

Comments

mitchell’s picture

Component: Miscellaneous » Rules Core
Status: Active » Postponed (maintainer needs more info)

Could you upload exports of your rules and the debug logs too?

thoughtcat’s picture

I've just added a new node (content type "track") and got the extra "userpoints". I've since added further rules to send me an email when new content has been added or edited, and I've got one email to say "new content created" and another two both saying the node has been updated.

Not sure where I can find the debug logs you ask for? /admin/reports/dblog though only shows "track: added", not "track: updated", if that helps?

I edited the track manually a few minutes later and got 2 x 5 userpoints and two "help" messages saying the track had been edited and again two more "update" emails. dblog has recorded one "update" of the track. So that would suggest the "update" rule fires twice of its own accord, but doesn't explain why creating the node fires the update rule at all.

Here's the export of the rule that fires "after saving new content":

{ "rules_fix_title_on_create" : {
    "LABEL" : "Fix track title on create",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_insert" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "track" : "track" } } } }
    ],
    "DO" : [
      { "data_set" : {
          "data" : [ "node:title" ],
          "value" : "[node:field-song] ([node:field-artist], [node:field-album], [node:field-year])"
        }
      }
    ]
  }
}
mitchell’s picture

Turn on Rule's debug log in the configuration options. See https://drupal.org/node/1538864

thoughtcat’s picture

OK thanks, done that. I added another node and the debug log shows (in order) the three emails firing off, then "node added", then the Rules debug info which is:

Rules debug information:
" Reacting on event After saving new content.

0 ms Reacting on event After saving new content.
8.482 ms Evaluating conditions of rule Fix track URL on create. [edit]
8.912 ms The condition node_is_of_type evaluated to TRUE [edit]
8.925 ms AND evaluated to TRUE.
" Rule Fix track URL on create fires. [edit]
0 ms Rule Fix track URL on create fires.
7.901 ms Evaluating the action node_path_alias. [edit]
8.512 ms Rule Fix track URL on create has fired.
17.503 ms Evaluating conditions of rule Fix track title on create. [edit]
17.72 ms The condition node_is_of_type evaluated to TRUE [edit]
17.732 ms AND evaluated to TRUE.
" Rule Fix track title on create fires. [edit]
0 ms Rule Fix track title on create fires.
4.703 ms Evaluating the action data_set. [edit]
4.86 ms Rule Fix track title on create has fired.
22.651 ms Evaluating conditions of rule Fix perf URL on create. [edit]
22.859 ms The condition node_is_of_type evaluated to FALSE [edit]
22.87 ms AND evaluated to FALSE.
22.906 ms Evaluating conditions of rule Fix perf title on create. [edit]
23.111 ms The condition node_is_of_type evaluated to FALSE [edit]
23.122 ms AND evaluated to FALSE.
23.16 ms Evaluating conditions of rule RC new content alert. [edit]
23.304 ms The condition node_is_published evaluated to TRUE [edit]
23.317 ms AND evaluated to TRUE.
" Rule RC new content alert fires. [edit]
0 ms Rule RC new content alert fires.
4.606 ms Evaluating the action mail. [edit]
19.967 ms Rule RC new content alert has fired.
43.385 ms Saved node of type node.
" Reacting on event After updating existing content. [edit]
0 ms Reacting on event After updating existing content.
0.273 ms Evaluating conditions of rule Fix title on edit. [edit]
0.533 ms The condition node_is_of_type evaluated to TRUE [edit]
0.545 ms AND evaluated to TRUE.
" Rule Fix title on edit fires. [edit]
0 ms Rule Fix title on edit fires.
3.342 ms Evaluating the action data_set. [edit]
3.506 ms Rule Fix title on edit has fired.
4.118 ms Evaluating conditions of rule Fix perf title on edit. [edit]
4.324 ms The condition node_is_of_type evaluated to FALSE [edit]
4.335 ms AND evaluated to FALSE.
4.371 ms Evaluating conditions of rule RC content updated alert. [edit]
4.497 ms The condition node_is_published evaluated to TRUE [edit]
4.508 ms AND evaluated to TRUE.
" Rule RC content updated alert fires. [edit]
0 ms Rule RC content updated alert fires.
3.588 ms Evaluating the action mail. [edit]
16.407 ms Rule RC content updated alert has fired.
21.005 ms Saved node of type node.
" Reacting on event After updating existing content. [edit]
0 ms Reacting on event After updating existing content.
0.268 ms Not evaluating reaction rule Fix title on edit to prevent recursion. [edit]
0.304 ms Evaluating conditions of rule Fix perf title on edit. [edit]
0.548 ms The condition node_is_of_type evaluated to FALSE [edit]
0.56 ms AND evaluated to FALSE.
0.597 ms Evaluating conditions of rule RC content updated alert. [edit]
0.697 ms The condition node_is_published evaluated to TRUE [edit]
0.708 ms AND evaluated to TRUE.
" Rule RC content updated alert fires. [edit]
0 ms Rule RC content updated alert fires.
3.302 ms Evaluating the action mail. [edit]
15.863 ms Rule RC content updated alert has fired.
16.639 ms Finished reacting on event After updating existing content.
76.424 ms Finished reacting on event After updating existing content.
181.518 ms Finished reacting on event After saving new content.

mitchell’s picture

Have you reviewed this output? What are your thoughts?

Please upload long text in a separate file instead of using blockquote.

thoughtcat’s picture

Sorry, will remember that next time.

I have reviewed it now and can see the "fix title on edit" and "fix perf title on edit" rules are also firing on "after updating existing content", which would account for the extra revisions. I see at 43.385 ms "Saved node of type node", so if that means that the content now "exists" I guess that might be why "after updating existing content" rules are running afterwards, but I still can't see why they should be triggered?

I've tried changing the weights of the rules to put the "after updating existing content" rules before the "after new content is saved" ones to see if this would stop the former running after the latter, but it hasn't worked.

Do I need to add another condition to the two unnecessary "after updating existing content" rules to stop them firing?

acbramley’s picture

I'm getting this problem too, I have a similar Rule with emails being sent using the After saving new content event, and 3 conditions being ANDed together. When I have the rule enabled and save a piece of content, 2 revisions are created, therefore the rule is run twice and duplicate emails are sent. Disabling the rule stops the double revisions being generated.

nicodv’s picture

Same here, I just used the event "After saving new content" and reduced my rule to almost nothing: "Show a message on the site" saying 'hola', but the rule is not being fired. (no conditions... nothing)

Am I missing something?

nicodv’s picture

CWSmith1701’s picture

Version: 7.x-2.1 » 7.x-2.2

I have two rules in version 2.2 that redirect upon saving a specific node to different parts of my site. But the redirect drops you back at a blank add node page for the types, and results in 24 copies of the node. I'm not sure why that is.

TR’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (duplicate)