I've got a problem with a rule that fires when I think it shouldn't.
Background:
My Article content type uses the Node Expire and Node Expire Extras modules to control automatic Article expiration. I have the following “expiration” rule defined:
{ "rules_expired_content" : {
"LABEL" : "Expired Content",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "node_expire" ],
"ON" : { "node_expired" : [] },
"DO" : [ { "node_unpublish" : { "node" : [ "node" ] } } ]
}
}
The rule sets the Article to “unpublished”.
My users asked that I provide a way to selectively control if an email is sent when an article is updated. To that end, I added a field (radio button) to the Article content type called “Send email” (field_send_email). The field defaults to “Yes”. I wrote two rules: when content is saved and when content is updated. The rule for saving content seems to work flawlessly. Here's the rule for updating the content:
{ "rules_updated_article_email_notification_cloned_" : {
"LABEL" : "Updated Article Email Notification",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "Email" ],
"REQUIRES" : [ "rules", "node_expire", "php", "mimemail" ],
"ON" : { "node_update--article" : { "bundle" : "article" } },
"IF" : [
{ "data_is" : { "data" : [ "node:field-send-email" ], "value" : "1" } },
{ "AND" : [ { "NOT node_expire_rules_expired_check" : { "node" : [ "node" ] } } ] }
],
"DO" : [
{ "mimemail_to_users_of_role" : {
"key" : "xxxxxxxxxxxxxxxxxx",
"roles" : { "value" : { "4" : "4" } },
"active" : "1",
"from_mail" : [ "node:author:mail" ],
"subject" : "An article has been updated: [node:title]",
"body" : "[node:body]",
"attachments" : "\u003C?php\r\nforeach($node-\u003Efield_file_attachments[\u0027und\u0027] as $file) {\r\n echo drupal_realpath(file_load($file[\u0027fid\u0027])-\u003Euri);\r\necho (\u0022\\n\u0022);}\r\n?\u003E",
"language_user" : "1",
"language" : [ "" ]
}
}
]
}
}
Problem:
When cron runs, it fires the rule that detects that an Article has expired. That changes the state of the Article to “unpublished”. Changing the state forces the above updated Article rule to fire. Today, December 31st, a series of emails was sent out unexpectedly. I know it has something to do with the Updated Article rule, but, I am at a loss to pinpoint the cause. I checked the system log and noticed the following line that looked suspicious:
Notice: Undefined property: stdClass::$expired in node_expire_rules_expired_check() (line 98 of /XXXX/XXXX/public_html/XXXXX/sites/all/modules/node_expire/node_expire.rules.inc).
I did not find any reported problems with the Node expire module and the above message.
I also ran some localhost tests and the code appeared to run correctly although I'm not sure I'm simulating an expired node correctly by forcing it from Cron.
I've turned on Rules debug so that it will show in the system log for future issues with Articles. However, if anyone can shed some light on this, I'd greatly appreciate it.
UPDATE: I have since found that this bug is inconsistent. I had one article that was unpublished and had the problem, and, another that did not. The only difference seems to be that the one with the problem was also originally promoted to the front page.
UPDATE 2: I'm not getting any response on the Drupal Node Expire page. If anyone knows of an alternative mechanism to implement Node expiration without using the above mentioned modules, I'd love to hear.