For a project I am working on I need to (un)publish nodes using a field different from {node}.status. I have been able to manage almost everything I need through hook_nodeapi(), but I can't make Scheduler work as the query performed in scheduler_cron() cannot be altered and the node having status 1 but "custom status" 0 are not selected.

It would be really useful if scheduler_cron() were refactored so that its code were reusable.

Comments

plach’s picture

Status: Active » Needs review
StatusFileSize
new4.46 KB

Here is a patch that performs the refactoring. The logic should be unaltered.

(FWIW the custom module I'm working on aims to fix Book's inability to handle unpublished nodes without patching D6 core.)

plach’s picture

StatusFileSize
new4.08 KB

This is a patch for Scheduler 6.x-1.7, the patch to review is #1.

eric-alexander schaefer’s picture

There are some problems with this approach: Although your module will call this functions there will be a log entry saying scheduler did that. There might even be a scheduler revision log. Also the hook_scheduler_api will be invoked which might not be what either your module or the modules implementing that hook want to happen. Why don't you just fire the 'node_publish_action' and 'node_save_action' for your nodes?

plach’s picture

@Eric Schaefer:

Well, the idea is to execute a cron job exactly as if Scheduler was performing it, so the watchdog entries and API hook invocations are what we want. Otherwise we'll be forced to copy the code in scheduler_cron() and just change the queries.

eric-alexander schaefer’s picture

OK. Could you please explain why you want to that? I am trying to understand your motivation.

plach’s picture

OK. Could you please explain why you want to that? I am trying to understand your motivation.

Sure, and thanks for your time :)

We are trying to build a module working around #26552: Allow users with access to unpublished nodes to create unpublished books. After trying various approaches requiring to patch D6 core, we decided to go for a full-contrib solution: basically the idea is making book nodes always have status 1 (in order to make core queries to work as intended) and instead granting access to them using a custom status field, which does not interfere with core queries. We managed to make almost everything work as intended, but we are lacking Scheduler integration: as I was writing previously, one option we have is copying scheduler_cron() code and changing its queries, the other one is what I proposed in #1.

eric-alexander schaefer’s picture

Wouldn't it be much more useful if scheduler provided a hook for custom queries. Something like hook_scheduler_publish_query() and hook_scheduler_unpublish_query() which either return a query string or a list of nodes to operate on? Or maybe something like hook_scheduler_cron_query($op='publish'), which would support future scheduler operations. scheduler_cron() would do it's own query and then call all implemented hooks and work those nodes.

How about that? I actually like that idea. I do not like the idea of exposing scheduler_publish() because then it becomes a liability. Whenever I would try to change it, it could break another module. With my approach above scheduler would ask your module which nodes it wants published, but keeps the function private. The inner workings of scheduler_publish() might change anytime, but a list of nodes always stays a list of nodes.

plach’s picture

Yes, this could be a viable solution either. Do you want me to write down a patch or do you prefer to do it yourself?

eric-alexander schaefer’s picture

I'll do it myself. Sounds like fun... :-)

plach’s picture

Thank you! Now I'm a little bit distracted, but I'll have a look to this ASAP.

eric-alexander schaefer’s picture

Status: Needs review » Fixed
plach’s picture

Yes, this is fixed. Sorry for the delay. If I'll find any drawback I'll open a new issue.

Thanks!

Status: Fixed » Closed (fixed)

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