1

I created a rule for scheduling a action component after 48h. The rule gets triggered correctly and the task shows up at the "Workflow" tab in rules.

The problem is that the scheduled component gets an empty parameter and so can execute the actions. Drupal log shows an "The variable or parameter node is empty." warning.

Here is the rule:

{ "rules_set_submission_status_to_archived" : {
    "LABEL" : "SUBMISSION: Set submission status to archived",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "archived", "submission" ],
    "REQUIRES" : [ "rules", "rules_scheduler" ],
    "ON" : { "node_insert--submission" : { "bundle" : "submission" } },
    "IF" : [ { "entity_is_of_type" : { "entity" : [ "node" ], "type" : "node" } } ],
    "DO" : [
      { "schedule" : {
          "component" : "rules_times_up_for_submission",
          "date" : "+2 days",
          "identifier" : "Archive submission [node:nid] \u0022[node:title]\u0022 after 48h.",
          "param_node" : [ "node" ]
        }
      }
    ]
  }
}

Here is the scheduled component:

{ "rules_times_up_for_submission" : {
    "LABEL" : "Times up for submission, archive and pay back credits",
    "PLUGIN" : "rule",
    "OWNER" : "rules",
    "TAGS" : [ "archived", "submission" ],
    "REQUIRES" : [ "rules", "commerce_credits", "php" ],
    "USES VARIABLES" : { "node_to_archive" : { "label" : "Node", "type" : "node" } },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node-to-archive" ],
          "type" : { "value" : { "submission" : "submission" } }
        }
      },
      { "entity_has_field" : { "entity" : [ "node-to-archive" ], "field" : "field_status" } },
      { "data_is" : { "data" : [ "node-to-archive:field-status" ], "value" : "submitted" } },
      { "entity_has_field" : { "entity" : [ "node-to-archive" ], "field" : "field_use_free_credits" } },
      { "data_is" : { "data" : [ "node-to-archive:field-use-free-credits" ], "value" : "0" } }
    ],
    "DO" : [
      { "commerce_credits_add" : {
          "entity" : [ "node-to-archive:author" ],
          "credit_type" : "credit",
          "number" : [ "node-to-archive:field-submission-price" ]
        }
      },
      { "data_set" : { "data" : [ "node-to-archive:field-status" ], "value" : "archived" } },
      { "entity_save" : { "data" : [ "node-to-archive" ], "immediate" : "1" } },
      { "php_eval" : { "code" : "watchdog(\u0027schedule\u0027, $node_to_archive);" } }
    ]
  }
}

So basically, the node is not passed to the scheduler component. Is there something broken in my system or do I miss something?

5
  • 1. The component performs the desired actions when executing it manually but shows this error: "Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2227 of database.in‌​c)." The log has a "page not found" warning from /admin/config/workflow/rules/components/manage/autocomplete/node_to_archive/form-xxx.../ 2. I don't know where to check which user executes it. It's triggered by cron with Anonymous user. 3. Functionally I try to check if content has been reviewed in 48h. If not, after 48h the postet content gets archived.
    – geraldo
    Commented Aug 15, 2017 at 12:26
  • Great! Deactivating the last rule (PHP) made it execute (almost) correctly. As I see in the log, all the actions get performed - but the "data set" action has no effect. Executing it manually it performs the "data set" action correctly.
    – geraldo
    Commented Aug 15, 2017 at 13:04
  • Merci for the "accept", but I might ALSO have an explanation (and work around) for that remaining *** ... "data set" action has no effect ...*** in your prior comment. Give me a few mins to quickly go check something and I'll add another small improvement to my answer ... ok? Commented Aug 15, 2017 at 13:16
  • THANKS! Just in case to avoid permissions issues I gave Anonymous users rights to the component (even if it doesn't look like that as the node gets saved but the field doesn't get edited), but without effect.
    – geraldo
    Commented Aug 15, 2017 at 13:28
  • Well, I'm not surprised about that "but without effect", because more and more I'm convinced that the real reason for your original problem is what I just added to my answer (within "last but not least"). Curious to ever hear how close I am ... the bets are open ... (Rules is great, but sometimes it has some bizarre behavours ...). Ps: sorry I had not yet upvoted your question (I think it'd be a great question for a Rules Certification program) ... so +1 "now". Commented Aug 15, 2017 at 13:40

1 Answer 1

1

Some tips to help you find out what's happening / going wrong (based on revision 2 of your question):

  • Try to execute your Rules Component "manually" (just to test), to unit-test if it works as desired. To do so, use the "execute" link to the right of the Rules Component (in the Rules UI).
  • It could be a permission issue, i.e. think about which "user" (authority) the scheduled component executes with.

Some more tips to help you find out what's happening / going wrong (based on revision 3 of your question), and your extra comment which includes "... shows this error: "Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2227 of database.in‌​c)." The log has a "page not found" warning from /admin/config/workflow/rules/components/manage/autocomplete/‌​node_to_archive/form‌​-xxx.../ ...":

  • Try to temporary remove that very last rules action (to execute that PHP code), and see what happens.
  • If the error still doesn't go away, it seems the time is right to start Rules debugging, as explained in my answer to "Where is the Rules Evaluation Log?".

Last but not least ...

About this part of your question:

The problem is that the scheduled component gets an empty parameter and so can execute the actions. Drupal log shows an "The variable or parameter node is empty." warning.

Please have a look at what's described in my answer to "Why can my view not access the data of a new node when using Rules event After saving new content?". It explains that "after saving something" actually happens ... "before saving something" (which is not a bug, simply how the Rules module works ...). I wouldn't be surprised that this is also what explains your problem. Here is why I think so:

  • Your (main) rule uses the event "after saving something".
  • Assume that the rules action (to schedule your component) actually happens (also) "before saving something"; In that scenario the part of your message that says "The variable or parameter node is empty." makes sense ... (get it?).

So it would be interesting to see what would happen if (even only to test), you'd replace the (single) Rules Action (to schedule your Rules Component) by the execution of an additional Rules Component (let's call it "Test_tip_from_Pierre") which is scheduled to execute after X secs or mins, and with a single Rules Action (equal to your Rules Action you now have in your main rule). Using that approach, for sure the node will have been saved before you actually schedule your original Rules Component. And that is what might resolve (eliminate / prevent) your warning like "The variable or parameter node is empty."

1
  • Sorry, I don't get it. First of all the "The variable or parameter node is empty." warning from Drupal log disappeared. Rules log shows this messages regarding data set and save node: 11.838 ms Evaluating the action data_set. edit 11.956 ms Evaluating the action entity_save. edit 11.976 ms Saved node_to_archive of type node. My problem is that entity_save is done but data_set isn't. So the original rule doesn't influence, the problem must be in the component. So should I try that even the node is empty warning disappeared?
    – geraldo
    Commented Aug 15, 2017 at 14:03

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.