This patch adds two features and fixes one bug that widen the range of ways third party modules can integrate with Scheduler;

  • Implementations of hook_scheduler_api() can now receive $node by reference.
  • hook_scheduler_api() is now also invoked before publishing and unpublishing with "pre_publish" and "pre_unpublish" actions respectively.
  • BUG: The $node object still has publish_on and unpublish_on properties when actions_do() is called. This causes the value to be saved to the database again if any module that does an asynchronous node_save() with the $node object.

These API features are useful and/or required by Scheduler Workbench Integration module to effectively integrate Scheduler with Workbench Moderation module. Specifically;

  • scheduler_workbench_scheduler_api() can trigger moderation-state changes via the $node->workbench_moderation_state_new property, which is more reliable, thorough and efficient than calling workbench_moderation_moderate() after the node is already published by scheduler. It also means that the node only passes through one moderation state transition instead of two.
  • Workbench Moderation has a drupal_register_shutdown_function()-callback which node_save()s as drupal shuts down, restoring publish_on and unpublish_on dates to the scheduler table.

Related patch for Scheduler Workbench Integration module; #1660252: Publishing transitions twice through draft

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Bevan’s picture

Bevan’s picture

This patch does not fix the bug in the case where both the publish and unpublish events for a node happen on the same cron run. I can not think of a fix for that scenario that is sufficiently unhacky to be worth contributing, without overhauling scheduler_cron().

acbramley’s picture

This patch fixed an issue for me where the workbench state wasn't being set correctly on with scheduler_workbench

rv0’s picture

+1 for getting this committed.

one comment:

function _scheduler_scheduler_api(&$node, $action) {

objects are always passed by reference so the "&" is not needed

repost with those lines removed:

xtfer’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.57 KB

The patch in #4 wouldn't apply for me. Kept telling me it was corrupt.

I've just rerolled it as is to try to fix that.

pfrenssen’s picture

Rerolled patch to latest dev and improved documentation.

rickmanelius’s picture

I'm slightly confused by the comment in #4. It was stated that & is not needed and then it's still in the patch.

Otherwise it looks good and will be committed once we can get clarification on this point.

pfrenssen’s picture

@rickmanelius, that comment was about this hunk in the patch in #1. It was removed in #4 and subsequent patches:

@@ -901,7 +909,7 @@ function _scheduler_lightweight_cron() {
  * @param $action
  *  The action being performed, either "publish" or "unpublish"
  */
-function _scheduler_scheduler_api($node, $action) {
+function _scheduler_scheduler_api(&$node, $action) {
   foreach (module_implements('scheduler_api') as $module) {
     $function = $module . '_scheduler_api';
     $function($node, $action);
rickmanelius’s picture

@pfrenssen Dreditor must have been playing tricks on me because I can see the difference now. I'll get this applied tonight.

rickmanelius’s picture

Status: Reviewed & tested by the community » Fixed

Just committed #6. Thanks to everyone for their help in creating/reviewing this patch.
http://drupalcode.org/project/scheduler.git/commit/0212013

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Adding reference to the patch that requires this