2

I have got an issue unflagging a node with Rules scheduler when triggering it with cron. The node gets unflagged just fine if we execute the component manually, however, if I schedule it to unflag the node like 2 minutes after triggering the Rule, it doesn't unflag the node. I ran cron multiple times, refreshed the page, but nothing.

I have done some preliminary testing and found out that flag_rules_action_info() is just not being called at all when executing this through cron. I have checked permissions and every thing looks good there. Would appreciate it if you guys could give me some input as to what might be the problem when triggering it with cron. I have included the rules debug info below and an export of the rule and the component. Thanks.

Debug Info:

0 ms Scheduled evaluation of action set my component, task Unbookmark 10..
90.748 ms Evaluating the action component_rules_my_component. [edit]
0 ms Evaluating action set my component.
0.473 ms Evaluating the action component_rules_my_component. [edit]
0.528 ms Not evaluating action set my component to prevent recursion. [edit]
1.07 ms Evaluating the action flag_unflagnode. [edit]
5.439 ms Evaluating the action add_badge_by_name. [edit]
7.16 ms Finished evaluation of action set my component.
98.707 ms Evaluating the action flag_unflagnode. [edit]
98.982 ms Evaluating the action add_badge_by_name. [edit]
116.401 ms Finished evaluation of action set my component, task Unbookmark 10..

Component Export:

{ "rules_my_component" : {
"LABEL" : "my component",
"PLUGIN" : "action set",
"REQUIRES" : [ "rules", "flag", "user_badges" ],
"ACCESS_EXPOSED" : "1",
"USES VARIABLES" : { "node" : { "label" : "node", "type" : "node" } },
"ACTION SET" : [
{ "component_rules_my_component" : [ ] },
{ "flag_unflagnode" : {
"flag" : "bookmarks",
"node" : "10",
"flagging_user" : [ "site:current-user" ],
"permission_check" : 1
}
},
{ "add_badge_by_name" : { "badge" : "4", "user" : [ "node:author" ] } }
]
}
}

Rules Export:

{ "rules_test_scheduler" : {
"LABEL" : "test scheduler",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "rules_scheduler", "flag" ],
"ON" : [ "flag_flagged_bookmarks" ],
"IF" : [
{ "entity_is_of_type" : { "entity" : [ "flagged-node" ], "type" : "node" } },
{ "node_is_of_type" : {
"node" : [ "flagged-node" ],
"type" : { "value" : { "blog" : "blog" } }
}
}
],
"DO" : [
{ "drupal_message" : { "message" : "this works" } },
{ "schedule" : {
"component" : "rules_my_component",
"date" : "+2 minutes",
"identifier" : "Unbookmark [flagged-node:nid].",
"param_node" : [ "flagged-node" ]
}
}
]
}
}
1

I have figured this out myself. Please refer to Comment #5 in Issue 2094541 for the answer, located at the following link: https://drupal.org/node/2094541#comment-7955705

Here is what it says:

Finally, figured this out! The problem is, we're not supplying the required parameters to the Rules component. If you have given it only 'node' as the parameter, then, when you add the action to 'Unflag a Node', you must give the 'User on whose behalf to flag' a data selector such as 'node:author'. You can't do something like 'site:current-user' because that parameter is not available to the component when run through Cron.

Once you give it the required parameters, it should unflag the node through Cron.

|improve this answer|||||
  • I checked your link on drupal.org but even after doing the same it is not working in my case. As you want to unflag the node,I want it to be flagged after a fixed time. On admin/config/workflow/rules/schedule page I can see the content has been set for the flag to be done but it does not perform the flagging event. Could you let me know that should I change cron settings to achieve this?Or it should run automatically when the scheduled time occurs. – Aniruddhsinh Dec 12 '13 at 8:50
  • You've got to make sure you are supplying the needed parameters to the rules component. If you have given it only 'node' as the parameter, then, when you add the action to 'Unflag a Node', you must give the 'User on whose behalf to flag' a data selector such as 'node:author'. Basically, make sure you are feeding the component all the necessary parameters. We need to do this for cron because it is being run automatically. When done manually, it gets the parameters it needs. But when running with cron, it doesn't know on whose behalf it should perform the action. – SN_26 Dec 13 '13 at 6:09
  • 1
    Thanks for you comment Shabana but the real issue was that I was not waiting for Cron to run & was not even trying to run the cron manually. So even after doing the configuration I was just thinking of the node to be flagged within the given time which can be done only after the Cron run process. but when I ran the cron manually it started working. – Aniruddhsinh Dec 13 '13 at 6:17
  • Interesting stuff, +1 ! Hope it's OK I slightly enhanced your answer (the original link did not work ..) – Pierre.Vriens Sep 11 '15 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.