Overview
The enhancements developed in this issue integrate the Scheduler functionality with Rules and Views Bulk Operations in both directions. Scheduler provides events which Rules can react to, and it provides actions and components to allow other rules to set or remove scheduled dates.
Changes to scheduler.module
When Scheduler publishes or unpublishes a node, or a new or existing node is scheduled for future publishing or unpublishing, an event is triggered which can be reacted on in Rules.
New file scheduler.rules.inc
scheduler_rules_event_info() - Defines six events which are triggered by Scheduler activity (as described above)
scheduler_rules_action_info() - Defines four actions which can be added to Rules built by others, to allow other modules to interact with Scheduler by adding or removing publish and unpublish dates.
scheduler_rules_condition_info() - Defines four conditions to determine the scheduled properties of a node. For use when building reaction rules.
New file scheduler.rules_defaults.inc
scheduler_default_rules_configuration()
Defines two reaction rules as examples for the user to modify
Defines four components for use in Views Bulk Operation, to allow bulk setting and removing of publishing and unpublishing dates.
Jonathan
original request
I would like to set up nodes that have a Date CCK field so that they automatically are unpublished based on that date. If the date is modified before the node is unpublished, this should modify the unpublish date. And if the date is a repeating schedule, then the "until" date should be used. There should also be an offset of a number of days (+/-) from the effective date.
I realize this is not possible, but I am thinking that I could get a great deal of this accomplished if this module had integration with Rules http://www.drupal.org/project/rules.
If anyone has any ideas about other approaches to this problem please let me know. Thanks!
Comment | File | Size | Author |
---|---|---|---|
#45 | 773510.39_to_45.interdiff.txt | 2.98 KB | jonathan1055 |
#45 | 773510_45.rules_integration.patch | 19.71 KB | jonathan1055 |
#40 | 773510-40-scheduler-rules-tests.patch | 15.63 KB | pfrenssen |
Comments
Comment #1
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedAny new ideas on this issue? I can't help with this myself, because I do not know and use the rules module.
Comment #2
anonymous07 CreditAttribution: anonymous07 commentedI had this working in D5 with Workflow-ng, Rules, Scheduler, and Node Import and have not been able to get it going in D6 (with Rules, Scheduler, Node Import). (I am just migrating to D6 after hoping that most kinks would be resolved by now :-)
When I try to assign the date values (Publish/Unpublish) to the CCK field, it keeps throwing a:
"The 'publish on' value does not match the expected format of 2010-07-20 22:46:09"
"The 'unpublish on' value does not match the expected format of 2010-07-20 22:46:09"
You can see the issue and code snippet here: http://groups.drupal.org/node/81904
Comment #3
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedComment #5
1kenthomas CreditAttribution: 1kenthomas commentedDoes scheduler integrate with Rules? It's not immediately clear from the project ...
At this point AFAIK, there is no general-purpose mechanism for scheduling 'actions' at a particular time. Allowing Scheduler to 'trigger' Rules would make it much more general purpose modules, without much code or loss of simplicity.
Comment #6
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedI cannot answer this question because I do not really know what rules is doing and I have never used it. Could you explain what it would mean to "integrate with rules".
Comment #7
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedFrom http://www.drupal.org/project/rules (features section):
This does not sound like
Comment #8
aharown07 CreditAttribution: aharown07 commentedThis would be really, useful I think.
There's a Rules API and some documentation for integrating other modules with it: http://drupal.org/node/298486
From what I've seen in other modules, what they apparently do is expose some of the modules functionality in some way to Rules in the form of triggers, conditions or actions.
Comment #9
ben.bunk CreditAttribution: ben.bunk commentedRules integration could be achieved very easily. It would simply be an event that is triggered when something is added to the scheduler table.
There might be a fringe case for wanting to know if something is removed from the table but I can't think of it now. The removal event might be redundant because you can watch for the publish and unpublish events that are already built-in.
Comment #10
tguidon CreditAttribution: tguidon commentedComment #11
tguidon CreditAttribution: tguidon commentedAdds rules integration to the scheduler module.
Comment #12
Eric-Alexander Schaefer CreditAttribution: Eric-Alexander Schaefer commentedLooks good so far.
What happens if rules is not installed/activated?
Comment #13
Ken Hawkins CreditAttribution: Ken Hawkins commentedDid this ever go anywhere — is it still a viable option? If so, am happy to do some testing.
Comment #14
jonathan1055 CreditAttribution: jonathan1055 commentedHi Ken,
The version at the top of the issue says 1.6 so I'm not sure what the patch in #11 was created against, but probably it was -dev as 15th May 2011. I've not used rules but it has been asked for several times so maybe it should be progressed. Also I suppose the D7 version should really be implemented first, then ported to 6.
Have you tried implementing the patch and giving it a go?
Jonathan
Comment #15
ben.bunk CreditAttribution: ben.bunk commentedThe patch didn't work for me.
Comment #16
jonathan1055 CreditAttribution: jonathan1055 commentedI've created a new version, updated for 7.x, and defined four rules which can be used to trigger events by Rules.
The $node and the two dates are passed as parameters to be available in Rules when creating the actions to perform.
The implementation of hook_rules_event_info is defined in a new file scheduler.rules.inc which is automatically included when needed. This is the preferred way as suggested in the Rules documentation. The other functions changed are scheduler_node_insert(), scheduler_node_update(), _scheduler_publish() and _scheduler_unpublish(). The patch is against the dev 1.1+7 of 25th May
There is more integration that might be needed for processing the other way round, ie exposing some of scheduler's functionality so that it can be executed by rules actions. When I've learnt more about Rules and Actions I will have a better idea on how to do that.
Jonathan
Comment #17
jonathan1055 CreditAttribution: jonathan1055 commentedFor those users (like me) who are new to Rules https://drupal.org/project/rules, here is what the above patch provides. When defining a rule, there are four new events which can be reacted on.
You have the two dates to use as replacement patterns in e-mails
(I'm sure there is a way to set the label and description, I will find out how to do that)
and the two dates can be used in conditions to further filter on whether to react to the event
Comment #18
jonathan1055 CreditAttribution: jonathan1055 commentedHere is an improved version, with more features. In addition to the four events listed above I have created two default 'reaction rules', to send an email to the owner of the content when it is published and unpublished by scheduler. The rules can be modified by admins, and tailored to your requirements. This is part of the 'rules reacting to scheduler' side of integration.
I have also worked on the other side, opening up schedulers functionality to be incorporated in custom rules. For this, I have created two components 'set publishing date for Scheduler module' and 'set unpublishing date for Scheduler module'.
This allows site admins to create their own reaction rules and have scheduler set the dates for publishing/unpublishing as actions which can be triggered. The $node and $date are passed as parameters, and the date can be set using any other field in the $node object.
There are now two new files - scheduler.rules.inc and scheduler.rules_defaults.inc, both of which are automatically included as and when Rules needs them.
Jonathan
Comment #19
jonathan1055 CreditAttribution: jonathan1055 commentedFurther things to consider for Rules Integration:
Comment #20
jonathan1055 CreditAttribution: jonathan1055 commentedHere is an updated patch, against the new dev 1.1+10 dated 28th July.
Regarding (1) above I have removed the unnecessary calls to user_load() and passing $user to the rules because node:author is available by default. I have not addressed 2-4 yet, but these are relatively minor points.
Comment #21
pauldawg CreditAttribution: pauldawg commentedHey there Jonathan! As it turns out I found another use for Drupal in my new position, setting up a development wiki for a healthcare IT organization. So I am back in the Drupal game after a hiaitus, and glad to see this integration is happening. Looking forward to giving it a dry run soon, as it will definitely come in handy for my project. Thanks again!
Comment #22
jonathan1055 CreditAttribution: jonathan1055 commentedHere is a re-rolled patch, against the new dev 1.1+15 of 25th Sept.
I've also removed a couple of changes from here which are repeated in #1566024: Coding Standards and Coder Review. This avoids a clash and allows both .module patches to be applied.
Comment #23
pfrenssenThis is some great work and would be a fantastic addition to Scheduler. I'm sure it would come in very handy for a lot of people.
I do not have much experience with the Rules module myself, but will start by reviewing the code and write down any remarks I might have. I will test it later on.
Comment exceeds 80 characters.
I'm not familiar with how Rules operates, but this seems to notify a listener, and passing some parameters to it. Isn't it redundant to include both the node ($n) and a property that is part of the same node object ($n->unpublish_on)? Is this perhaps necessary to display this parameter in the user interface?edit: this is explained where this event is defined.
Comment exceeds 80 characters.
Same question as above.edit: this is explained where this event is defined.
This lining up of array keys is very pretty, but alas not conforming to coding standards :)
This is occurring several times in the patch.
This is a very good question :)
Same as above. This needs to be figured out before we can commit the patch.
This should use the machine name of the permission 'schedule (un)publishing of nodes' instead of the human readable string.
Display comments above the affected code instead of inline. It is also more common to do typecasting by using (int).
@param documentation should be indented with 2 spaces. This is occurring throughout the code.
I looked for some examples, and it is implemented in the same way in commerce_checkout_default_rules_configuration() so it seems fine. Wouldn't hurt to try translating it though.
Comment #24
jonathan1055 CreditAttribution: jonathan1055 commentedHi Pieter, thanks for the review. Here's what I've done:
See http://drupalcontrib.org/api/drupal/contributions%21rules%21rules.api.ph... for more on both of these optional items
However the php manual http://www.php.net/manual/en/language.types.integer.php#language.types.i... does not recommend using (int) for any input other than strings or booleans. So I have changed it to explicitly check is_numeric() and set to 0 if not.
I have not added the two new files to the files[] array in .info as it seems Rules automatically detects and uses the files. Do you think that is ok?
Here's a new patch against 1.1+20 and an interdiff file for you to see the changes.
Jonathan
Comment #25
pfrenssenIt's looking very good now. Using +0 to cast is fine for me, it works :) If the rules integration works without announcing the files in the info file then that is good too.
Are you sure about this? It seems like a privilege separation violation. It is not necessarily always the case that people that have rights to create rules automatically have the right to schedule nodes for publication. For example if an organisation has a "webmaster" role that can do regular maintenance tasks including making rules, but the publication of nodes is strictly reserved to the "chief editor" role.
I suppose we don't need tests for this? At least I don't feel comfortable writing them as I have very little experience with Rules ;)
Comment #26
jonathan1055 CreditAttribution: jonathan1055 commentedThanks for the review. Yes I am pleased with this work.
I agree with you. However, my understanding of the access callbacks in hook_rules_event_info() and hook_rules_action_info() are to allow contrib modules to make even tighter restrictions on who can create and configure rules using the components and default rules that the contrib module provides. I was saying that if a user has enough admin permission to get to the admin/config/workflow/rules page which configures rules, then we do not additionally need to restrict them. Specifically we are not checking if the 'webmaster' has the authority to schedule nodes, because as you say, those roles may be separate.
Comment #27
jonathan1055 CreditAttribution: jonathan1055 commentedIf you want to test this with Rules be aware that a bug was introduced in Rules 2.5 #1568134: Enabling or disabling a contrib rule makes it disappear which makes using the contrib rules rather difficult! The dev version 2.5+2 dated 7th October was when this bug was fixed.
Jonathan
Comment #28
jonathan1055 CreditAttribution: jonathan1055 commentedNeeded re-roll after 1.1+30, to make it easier if anyone else comes along to patch and test this enhancement.
@Pieter, to answer your question about tests, no I do not think we could write any meaningful tests for Rules Integration. I think good old fashioned manual testing is all we can do with this.
Comment #28.0
jonathan1055 CreditAttribution: jonathan1055 commentedAdded link to Rules module http://www.drupal.org/project/rules
Comment #29
jonathan1055 CreditAttribution: jonathan1055 commentedComment #30
jonathan1055 CreditAttribution: jonathan1055 commentedThe changes in patch 29 are:
There are no changes to the .module code - all the above are in the two new files.
Comment #31
jonathan1055 CreditAttribution: jonathan1055 commentedIn scheduler.rules.inc, fix typos where the item keys did not match the changes in scheduler.rules_default.inc. I also improved the text labels.
In scheduler.rules_default.inc, in "1. Component to set the publishing date on a node", I have now removed the action to unpublish the node as this caused an unwanted node_save (along with all the associated hooks). The unpublishing can be achieved by using the core component instead.
No changes to scheduler.module
Patch against 1.1+39
[drupal failed to add the new comment first time, although I did get the e-mail notification, and patch 31 did get attached. Trying again. The patch does not seem to be showing here. See the issue summary to get the patch.]
Comment #32
jonathan1055 CreditAttribution: jonathan1055 commentedThe patch file, although attached, is not queued for testing. Something obviously did go wrong with the node save. Cannot find how to request it to be sent for testing, so uploading a new file.
Comment #33
pfrenssenRerolled against latest HEAD.
Comment #34
pfrenssenGoing to test the functionality manually. It's quite a lot to go through, so I am going to have to keep track of what I've already done. I will edit this post as I make progress.
Events
Actions
Conditions
Default rules
Default components
Questions / remarks
This would be similar to the node events "After saving new content" and "After updating existing content".
Comment #35
jonathan1055 CreditAttribution: jonathan1055 commentedThanks for doing this testing. I will address the problems, but not post a new patch until you have tested all the items listed.
Comment #36
pfrenssenIs there any way I can test the components through the Rules interface? I tried executing them but can't figure out how to choose a node to perform the action on. "node:nid:2" doesn't work :)
Comment #37
jonathan1055 CreditAttribution: jonathan1055 commentedYes, even though the components were built so that the the power of VBO could be utilised, they can be tested solely through rules without installing VBO. To act on the node being edited just select 'node' from the drop-down list, as in:
Or using your question, if you want to test a specific node id, switch to 'direct input mode' and enter the nid:
The components check that the requested node can be scheduled (or is scheduled, if using the 'remove' versions) so you do not need to add those conditions in the rules if using components rather than actions. But if your rule also shows a message giving details of the new date or whatever, then you may want the conditions added to the rules as well, so that the message is not shown when the action cannot actually be performed.
Jonathan
Comment #38
pfrenssenThanks! I finished the manual testing, so setting this to Needs work as per #34. Very nice work overall, I'm very excited about this addition to Scheduler!
Comment #39
jonathan1055 CreditAttribution: jonathan1055 commentedYes, this is going to be a very powerful addition to Scheduler.
Here is a patch addressing both of the issues you found. Good testing, thanks. I have added a message when attempting to set a scheduled date on a node that is not enabled. Also the message explains what to do to remedy the problem.
I have not done the same message when removing a date, we just avoid running the code but do it quietly.
Jonathan
Comment #40
pfrenssenI was playing around with the Rules integration some more yesterday evening. Creating and exporting rules turns out to be very easy, so I created a test rule for each component and exported them into our test module. Started poking around a bit to see how much work it would be to write tests. I'm not sure yet if I will finish this but am attaching my work in progress anyway, we can maybe use it for a followup issue.
@Jonathan, thanks for the update, will review the patch immediately, I have some free time now.
Comment #42
pfrenssenTypo: "enabeld".
Don't bother rolling a new patch for this, I will fix it before committing.
Code looks good. I'm going to do a quick functional test now.
Comment #43
pfrenssenTested manually and everything works as expected.
However, I think that it would maybe be better to use the watchdog to log events in which scheduling is applied to nodes that do not support it. The messages might be shown to regular visitors if an action they took created or updated a node in the background. They will not understand it, and might think something went wrong.
Comment #44
jonathan1055 CreditAttribution: jonathan1055 commentedYes, ok I was in two minds whether to show the message. A watchdog row is better, so I will make that change and re-patch.
The tests look interesting, but I think we should get the main code in and committed without extra delays. Then as you say, the tests can be added in a separate issue.
Jonathan
Comment #45
jonathan1055 CreditAttribution: jonathan1055 commentedChanged the drupal_set_message to watchdog call, added for all four of the events. Now that we have more space for the text I expanded the message and provided a link to the appropriate content type settings page. Also fixed the typo.
Did not include any changes to .test as I think that should be in a separate issue. Patch against 1.1+49.
Comment #46
pfrenssenGreat! It's all good now. Committed to 7.x-1.x: commit e2dcf53e5.
Very nice to finally have this in, more than 3 years after it was originally requested, excellent work!!
Comment #47
jonathan1055 CreditAttribution: jonathan1055 commentedFabulous.
Yes, but only five months since I started working on it, and only two months since the first of your excellent reviews, so thank you to us! ;-)
Comment #49
Yuri CreditAttribution: Yuri commentedIt appears not to be included in the latest dev?
Comment #50
jonathan1055 CreditAttribution: jonathan1055 commentedHi Yuri,
The latest dev release from the project main page is stuck at 19th December due to Drupal.org release problems
#2132327: Can't create release: git repository tag appears in repo browser, but not vcs tables
#2125405: Not all commits showing up
If you want the actual latest dev you can get it from the git repository http://drupalcode.org/project/scheduler.git
Hope that helps. I might ask Pieter to put a notice to this effect on the front page.
Jonathan