我已经设置了规则,将节点保存上的发布推迟到指定的日期。规则组件在稍后的日期成功运行,并向节点作者发送电子邮件警报,让他们知道他们的节点已经发布。但是,规则组件在实际发布节点方面并不成功。
我很有信心该组件工作正常,因为如果我直接执行它,提供节点id作为内容标识符(使用直接输入模式),它将按预期的方式工作,即发送电子邮件警报并发布节点。
只有当组件由cron运行时,才会出现问题。我最好的猜测--基于这个stackoverflow问答 --它可能连接到D7上的cron,总是以匿名用户的身份运行。
不过,我很困惑。关于如何使用规则来推迟发布,有几个D7讨论,例如这个Drupal回答了问答或这个drupal.org评论 (关于在D7上使用这种方法--这是对D6页面的评论)。这些都没有提到匿名用户的任何问题,这让我想知道我是否犯了一些非常基本的错误和/或有一个不寻常的配置。似乎奇怪的是,调度程序无法或多或少地实现延迟发布。
我查看了组件的“配置访问权限以使用此组件”选项,并在没有解决问题的情况下尝试了该组件的各种设置。我不清楚我理解这个选项的功能,也没有找到任何文档/Q&到目前为止,这些都是有帮助的。
作为参考,规则组件(使用节点id手动执行时工作,但在cron触发时发送电子邮件而不发布节点)如下(导出时):
{ "rules_publish_content" : {
"LABEL" : "Delayed publish action",
"PLUGIN" : "rule set",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "delayed_node" : { "label" : "Delayed node", "type" : "node" } },
"RULES" : [
{ "RULE" : {
"IF" : [
{ "node_is_of_type" : {
"node" : [ "delayed-node" ],
"type" : { "value" : { "news" : "news" } }
}
},
{ "NOT node_is_published" : { "node" : [ "delayed-node" ] } }
],
"DO" : [
{ "mail" : {
"to" : [ "delayed-node:author:mail" ],
"subject" : "Your item, \u0022[delayed-node:title]\u0022, has been published.",
"message" : "Your item, \u0022[delayed-node:title]\u0022, has been published.\r\n\r\n[delayed-node:url]\r\n\r\nnode id: [delayed-node:nid]\r\n\r\nnode date: [delayed-node:field-date]\r\n\r\nnode status: [delayed-node:status]\r\n",
"language" : [ "" ]
}
},
{ "node_publish" : { "node" : [ "delayed-node" ] } }
],
"LABEL" : "Delayed publishing: publish and alert"
}
}
]
}
}发布于 2013-05-25 08:42:58
事实证明,人们对匿名用户下的cron的担忧是一种“红鲱鱼”。感谢@Patrick鼓励更持久的伐木。
诊断:调度组件的反应规则是由“在保存内容之前”事件触发的。在我的测试中--因为我关于问题原因的错误理论--我反复使用了一个已经创建的节点。因此,节点nid成功地传递给了组件,因此在日志记录(以及检查调度规则列表)中,一切看起来都正常。警报邮件甚至被正确生成。然而,事实证明,当组件是根据“在保存内容之前”事件触发的反应规则调度的,则在组件执行时不会保存对节点的更改。因此,有些东西可以使用从“在保存内容之前”传递的参数触发反应规则,但另一些则不行。对于不起作用的事情,在日志记录中没有错误或问题被标记。很高兴现在就知道了。
对于任何想要导入一些规则以延迟发布和运行的人,下面是导出的组件和两个导出的规则。
在我的用例中,我还检查了特定的节点类型。如果需要添加该条件,则在导入组件后添加一个附加条件。(将组件导入到: admin/config/workflow/rules/components)
{ "rules_publish_content" : {
"LABEL" : "Delayed publish action",
"PLUGIN" : "rule set",
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "delayed_node" : { "label" : "Delayed node", "type" : "node" } },
"RULES" : [
{ "RULE" : {
"IF" : [ { "NOT node_is_published" : { "node" : [ "delayed-node" ] } } ],
"DO" : [
{ "node_publish" : { "node" : [ "delayed-node" ] } },
{ "mail" : {
"to" : [ "delayed-node:author:mail" ],
"subject" : "Your item, \u0022[delayed-node:title]\u0022, has been published.",
"message" : "Your item, \u0022[delayed-node:title]\u0022, has been published.\r\n\r\n[delayed-node:url]\r\n",
"language" : [ "" ]
}
}
],
"LABEL" : "Delayed publishing: publish and alert"
}
}
]
}
}中触发在日期上创作时延迟发布
在我的用例中,我还检查了特定的节点类型。如果您需要添加该规则,则在导入规则后添加一个附加条件。(在以下位置导入组件:/admin/config/工作流/rules)。此外,在我的用例中,我查看了内容类型上的特定日期字段,而不是节点:created,即‘授权’,价值。如果要这样做,那么在导入之后,添加一个新的条件,检查添加的日期字段,并删除检查标准Drupal创建日期字段的条件。
{ "rules_publish_node_future" : {
"LABEL" : "Publish node (in the future)",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : [ "node_insert", "node_update" ],
"IF" : [
{ "data_is" : { "data" : [ "node:created" ], "op" : "\u003E", "value" : "now" } }
],
"DO" : [
{ "node_unpublish" : { "node" : [ "node" ] } },
{ "schedule" : {
"component" : "rules_publish_content",
"date" : [ "node:created" ],
"identifier" : "Delay publication of node: [node:nid]",
"param_delayed_node" : [ "node" ]
}
},
{ "drupal_message" : {
"message" : "\u003Cstrong\u003EPublishing will be delayed until (up to 3 hours) after: [node:created:long].\u003C\/strong\u003E This is because the \u0027Authored on\u0027 date you entered for your item is in the future. If you need to publish now then edit the item, change \u0027Authored on\u0027 date to now or earlier, set the item to be \u0027Published\u0027, and save.",
"type" : "warning"
}
},
{ "mail" : {
"to" : [ "node:author:mail" ],
"subject" : "\u0022[node:title]\u0022 publication will be delayed until [node:field-date]",
"message" : "\u0022[node:title]\u0022 publication will be delayed until (up to 3 hours) after: [node:created:long].\r\n\r\n[node:url]\r\n\r\nYou have received this message because the \u0027Authored on\u0027 date you entered for your item is in the future. If you need to publish now then edit the item, change \u0027Authored on\u0027 date to now or earlier, set the item to be \u0027Published\u0027, and save.",
"language" : [ "" ]
}
}
]
}
}如果节点保存在过去的
规则取消延迟发布
此规则取消节点的任何计划发布。它不设置要发布的节点。根据安装程序的不同,您可能希望向此规则添加一个操作来发布节点。
{ "rules_publish_node_future_cancel" : {
"LABEL" : "Publish node (in the future cancellation)",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "rules_scheduler" ],
"ON" : [ "node_update" ],
"IF" : [
{ "NOT data_is" : { "data" : [ "node:created" ], "op" : "\u003E", "value" : "now" } }
],
"DO" : [
{ "schedule_delete" : {
"component" : "rules_publish_content",
"task" : "Delay publication of node: [node:nid]"
}
}
]
}
}https://drupal.stackexchange.com/questions/74071
复制相似问题