By no2e on
I have several (unpublished) nodes of the same content type. Each single day one of these nodes shall be published automatically.
But: I don't want to set a publish date for each node. They shall be published automatically one after one (sorted by node ID / creation date).
I will create new (unpublished) nodes constantly. But when the situation might occur, that there aren't any unpublished nodes anymore, the nodes I create after that shall be set to this past date (hard for me to explain ... I want one node for each day, and if there are no nodes for some time, there should be no gap after I created new nodes -> there publishing date should be set to the past automatically).
Comments
Non-Drupal approach
Write a php-script with SQL UPDATE function that changes status of one node in node table from unpublished to published.
Then run this php-script once a day with cron. (http://en.wikipedia.org/wiki/Cron)
This is a "non-Drupal" approach. But I bet you end up with a cron solution in there because you need to somehow trigger the update once a day.
Harjoituspäiväkirja - www.lenkkivihko.fi
Write a php-script with SQL
Hm, I don't 'speak' PHP :/ I'm no developer.
The "functionality" is already available in contributed modules like Scheduler, I think? But the problem is, that you have to enter a publishing date manually ...
This may work ...
There are a couple of modules that could play nicely together, helping you get a non-coded answer:
http://drupal.org/project/nodequeue
http://drupal.org/project/rules
Otherwise make a best guess coding solution via queues and see if you can get someone to help you through the process.
No matter what, you will need to a) enable cron OR b) enable poormanscron (http://drupal.org/project/poormanscron). Option a) is recommended.
Alan Davison
www.caignwebs.com.au
Alan Davison
rules and nodequeue?
Thanks Alan D.!
Could you explain how do you think nodequeue and rules could play together? I read into these modules and I don't understand, why I'd need nodequeue. Wouldn't it be possible to create a rule with rules only? (I don't know this module atm, just wondering)
Yes, I use cron. Just for my understanding: when my cronjob runs once a day at midnight ... and I'd set a publishing date of a node to one hour after midnight ... this node would be published after the next cronrun, correct?
Node queue allows you to
Node queue allows you to queue nodes for display. You can add as many as you like, thus no need to worry about dates, just make sure that the queue has some nodes in it.
Then with rules, you may be able to pop the oldest node from the queue once a day, showing the next node. I do not know if there is a rule action to do this, just that it could be an option worth looking into. Submit a feature request on the nodequeue issue queue if there isn't as it would be a very useful feature.
Using rules by itself may be harder to configure the Rules module to delete a node. (IE: The scheduler module would be easier if you need to start setting flags / unpublished dates)
Just go to the admin > logs > status reports to see if cron is active and working. We set cron to run every hour, but it depends on the site and it's requirements. If the only cron task is to unpublish a node once a day, then that will be all you need.
Alan Davison
www.caignwebs.com.au
Alan Davison
Any progress?
I need to do exactly this, as well.
Spent some time learning Rules and Triggered Rules, coupled with Nodequeue. Got as far as a Triggered Rule that successfully adds each new node of a specific content type to the queue.
What I need now is a Triggered Rules something like:
- When cron runs, remove oldest node from queue
If cron runs once a day, then this will take care of the scheduling. The problem is that the content arguments are not available with a Triggered Rule that fires on cron, so I don't have access to "Remove from queue".
The only solution I found to work around this is to fire on "When content is about to be viewed", but that doesn't work in this case.
I'm going to keep working at it and when I find the solution, I'll post it. In the meantime, anyone got ideas?
Solution
As usual, the solution is simple.
Modules: Nodequeue and Triggered Rules
1. Create an unlimited nodequeue
2. Create a triggered rule that fires on 'After saving new content'. Add a condition for 'Node has type' and specify the appropriate content type(s). Add an action 'Add to nodequeues' and specify the appropriate nodequeue.
3. Create a second triggered rule that fires on 'Cron maintenance tasks are performed'. Add an action 'Execute custom PHP code'. Your custom PHP code will be a query:
db_query("DELETE FROM `nodequeue_nodes` WHERE `nodequeue_nodes`.`qid` = 1 AND `nodequeue_nodes`.`position` = 1 LIMIT 1");
*obviously replace qid with the qid of your nodequeue.
4. Add a second action 'Execute custom PHP code' with another query:
$count = db_query("SELECT COUNT(*) FROM `nodequeue_nodes` WHERE `nodequeue_nodes`.`qid` = 4 AND `nodequeue_nodes`.`sqid` = 4");
for ($i = 2; $i <= $count; $i++) {
$position = $i - 1;
db_query("UPDATE `nodequeue_nodes` SET `position` = $position WHERE `nodequeue_nodes`.`qid` =1 AND `nodequeue_nodes`.`sqid` =1 AND `nodequeue_nodes`.`position` =$i LIMIT 1");
}
5. Set cron to run at midnight