Closed (fixed)
Project:
Scheduler
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Apr 2010 at 06:37 UTC
Updated:
22 Oct 2013 at 06:56 UTC
Jump to comment: Most recent file
Comments
Comment #1
eric-alexander schaefer commentedI have no idea what you are talking about. Please explain what you want to do and where you see problems.
Comment #2
codycraven commentedEric,
prabhakarsun wants to display a calendar of nodes with publish on dates in the current, month, week, day, etc. The problem is that the calendar requires a date argument. This argument then forces the user to select a date field to filter on, which Publish on or Unpublish on are not one of.
The module already lays the groundwork for this with the Views integration. The only thing needed is to implement hook_date_api_fields() - patch attached.
This will add Publish on and Unpublish on as options for the argument to filter on.
Comment #3
codycraven commentedComment #4
codycraven commentedI just noticed an issue with Scheduler and Calendar integration, the issue does not impact the patch supplied in #2 in any way. It does however affect the usefulness of the patch.
Currently when scheduler is run in cron it removes scheduled events when it (un)publishes them. This causes an issue when attempting to use the (un)publish date for filtering in a calendar view because the calendar will only be able to show upcoming dates and not a historical reference.
I'm toying with the idea of creating an add-on module that would permanently store scheduled dates to circumvent this issue without requiring the user creating the nodes from entering identical data twice.
Comment #5
eric-alexander schaefer commentedHow about an option for keeping the schedule dates for this purpose?
Comment #6
codycraven commentedEric,
That's basically what I'm developing for use in my work. I'm creating a module scheduler_permanent which creates a separate table (identical to scheduler's table) but does not remove the dates upon cron running (and intercepts form errors for past dates). When done I will post the module to this thread so it can then be either dissected and integrated in Scheduler or added on as an additional module packaged with Scheduler (I'd prefer integrated myself).
Comment #7
eric-alexander schaefer commentedIn
scheduler_cron()there are two lines where entries in the scheduler table are deleted:All that is needed is a checkbox in the config area and two if's around the two DELETE queries.
Comment #8
codycraven commentedIt's slightly more complex than that. If we maintain dates then cron will need to know which (un)publish events have already been fired, so that not every (un)publish from the past is performed on every cron call.
The way I'm seeing it is that there are two options:
Aside from those two options, some additional work will need to be added to scheduler_nodeapi() to not flag errors when dates in the past are submitted - if the option is enabled.
If you can give me your preference on the two options quickly I can write a patch to address the functionality needed at work, as it is needed in a current task.
Comment #9
eric-alexander schaefer commentedI would prefer option 2.
Comment #10
codycraven commentedAttached is a patch against Scheduler which allows to users to specify dates in the past and keeps dates in the db after their scheduled operation has been performed, IF the new option Allow scheduled dates in the past is selected for the content-type under the Workflow menu.
I've tested the patch quite thoroughly and have only one remaining issue that I have discovered. When publish_on and unpublish_on have both passed without cron having been ran and the Allow scheduled dates in the past option is not enabled for a content-type, then the record is not removed form the scheduler table and the unpublish_on field is set for a new timestamp in the future, when cron is ran. However the node does correctly remain unpublished. This is an issue I am working to correct, but i wanted to post my efforts so far.
*Note this patch does not contain the patch posted in #2 that allows the calendar integration.
Comment #11
codycraven commentedPatch attached which fixes issue mentioned in #10. Also adds a warning instead of notice when the publishing period of a node is missed - occurs when a node is set with a publish and unpublish date but cron is not ran during the time between, causing the node to be unpubished the entire period.
[Edit]
Again this does not contain the patch from #2 above, which I believe should also be committed. This patch is ready for review, and if suitable, commit.
Comment #12
eric-alexander schaefer commentedWhoa. That's a lot of code. Could you please explain briefly what the patches are doing and why?
Comment #13
codycraven commentedCertainly,
First there are two patches. The first is the patch from #2 which is a brief patch to simply add Date API support to Views. This allows using Scheduler dates in certain places of Views that they were previously not available in, specifically added for within the Date argument that is required when using Calendar (it is a date selection that must be made in the View's argument).
Now on to the fun stuff.
The second patch is from #11. This patch adds support for storing past scheduled dates and setting dates in the past.
scheduler.install
This adds two fields that indicate whether the publish_on, unpublish_on fields need to be performed. For example if a user sets an unpublish date in the future when that future timestamp is inserted in to unpublish_on then perform_unpublish is set to 1. Once cron runs and performs the unpublish then perform_unpublish is set to 0.
This is the hook_update_N() which updates the schema to match the new hook_schema() for existing users of the module.
scheduler.module
This adds a checkbox to the content-type configuration under the workflow fieldset which allows keeping dates in the past and adding dates in the past to the content-type. This is the option you requested in #5 "How about an option for keeping the schedule dates for this purpose?".
This adds support for entering dates in the past, only if the history option is enabled for the content-type. The reason there is so much code to this is that dates in the past should only be accepted if the history option is enabled, otherwise we want past dates to be rejected. When history is enabled we need quite a bit of logic checking to ensure the perform_publish and perform_unpublish flags are appropriately set based on the dates selected.
To simplify the amount of code that would be needed and to better meet standards I replaced the UPDATE and INSERT SQL statements with drupal_write_record().
In hook_cron() the first major change is that I reversed the order of publish/unpublish. The reason being is that we want to check for scheduled dates that never occurred, ie the publish_on and unpublish_on values were both set to be performed but never did because Cron was not ran during any point in between them. This creates a WATCHDOG_WARNING to notify the admin that something may be wrong with their Cron or the frequency of their Cron. The reason I added this is to circumvent an issue with the added history support and because it provides better information to the administrator.
Other than that the only change hook_cron() makes is to add support for maintaining the unpublish_on and publish_on timestamps for content-types which have the history option enabled, instead of clearing them out. It also only queries dates that have perform_publish or perform_unpublish set to 1 to prevent Cron from re-running already processed Scheduler dates when history is enabled for a content-type.
Please let me know if you need any further clarification for any of the patches' code.
Comment #14
codycraven commentedThere is one error I found with the patch from #11. In hook_cron() there is a condition that is wrong, I used if ($scheduler->publish_on) { when I should have done if ($scheduler->perform_publish) {.
Fixed patch attached
Comment #15
codycraven commentedStill needing review
Comment #16
eric-alexander schaefer commentedCody, I have a problem with your patch. I do not even know how to setup a test environment for it since I do not know the calender module at all. I also do not have the time to do it. Sometimes I include posted patches for use cases that I have no use for myself, but those are usually one or two liners that I can understand. Your patch is far too large. It introduces changes all over the place. Thats why I am not able to include it. See, I know every line of scheduler. I know what it does and why it is there because almost every bit of it is used in my projects. But I don't even know where to start with your code. Also if I would include your patch and would need to change scheduler later I would have to know if I introduced bugs into your code. This is a real problem. Your patch is actually a module of its own. It's almost as long as scheduler itself. Maybe it would really be a good idea to create a add-on module if that is possible (I doubt it, actually).
I thought about keeping scheduler history myself, because it could be useful in many ways (e.g. recurring schedules). But it was just a thought. I do not currently have the time to implement something like that.
Maybe this would work: I will look at the original patch in #2, which would solve the original problem sans the history. Your other patches contain some changes that are not really related to the history problem (e.g. drupal_write_record), but are useful refactorings. Maybe you could find and extract those changes and post them as separate issues to improve the code quality of scheduler. I still want scheduler to become more generic (e.g. schedule all kinds of actions), but that will be a gradual process. In this process scheduler will get a (optional) history. But this history will have a use case I do understand and use. Thats why I do not reject this issue but postpone it.
Comment #17
codycraven commentedCertainly Eric I can appreciate and understand that, as I get time I'll post patches for the specific general modifications I made.
Comment #18
sirkitree commentedSubscribing. I have a use case with auto_nodetitle that would benefit from scheduler history. I should be able to review this soon. Changing title to be more accurate. I think this is a bit more general than just Views Calendar usage. I'll also try to rework the patch to only be pertinent to the issue at hand.
Comment #19
sirkitree commentedOk, sorry to be messing around like this, but I realize now that this issue is really two issues. The original issue for Views Calendar, and a secondary issue for Scheduler history.
So, I'm going to set this back to the original and note that the patch to review is #2, then I'm going to include the second patch for scheduler history into it's own issue #198137: Scheduler history: retaining un/publish_on data which is an older thread that talks about keeping scheduler history.
Again, sorry for any confusion I've caused :(
Comment #20
eric-alexander schaefer commentedPostponing this. We need to change the db schema for this feature (and other features). The will be a new task for changing the schema.
Comment #21
jonathan1055 commentedAll the discussions about storing the history of scheduler dates has clouded the original issue. Reading #19 from sirkitree, the original patch implemented hook_date_api_fields() to tell Views how to treat the two scheduler fields. This was written for Drupal 6 before we had any D7 views integration. This hook function does not exist in Date 7.x-2.6 but I am not sure we need it anyway in D7. I have just created a Views Calendar view from scratch for the publish_on field and it works fine, (once you have figured out the settings). All the scheduler fields are available for selection in the required places [fields, filter criteria, contextual filters].
So unless I am mistaken this patch is not required for scheduler in 7.x but I would like others to confirm this.
A related issue is #1926128: Improve support for calendar view templates which contains some screen shots and instructions on using the views calendar templates as a starter for Scheduler calendars.
I'll give the patch in #2 a test in D6 and see how it works.
Comment #22
jonathan1055 commentedTested the patch in #2 again 6.x-1.9+4, and it does exactly what is required. The scheduler dates can now be selected as date arguments.
Before:

After

I have used this to build a calendar view of nodes with the content placed by 'publish on' date. Unless we find any reason why the D7 code needs to be changed first, this is ready to be comitted.
Jonathan
Comment #23
pfrenssenThanks! Committed at c900aca.