I need to Unpublish the nodes which are all not Updated for more than some specified time.

I'm having the query to fetch nodes and by using a batch process I will Unpublish those nodes one by one.

Now I want to schedule this operation to be run every day. How can I achieve that? using drush or something.

I have cron running at regular intervals. I need to run these scripts apart from the cron job i.e as a separate one.

4 Answers 4


You can use cron to do this, set a cron time in admin/config/system/cron for your site.

there is a hook_cron() is available in your drupal . using that hook you can configure your batch process to invoke.

  • Cron is already running at regular intervals. I want to run this one apart from cron. Will update the question also. Oct 18, 2012 at 12:16
  • 2
    To schedule your task to run at particular intervals cron is the correct one. you can use drupal.org/project/elysia_cron to get a fine grain control over each task. You can do your particular batch operation alone. why you are trying to run these scripts apart from the cron job? Oct 18, 2012 at 12:24
  • But un-publishing 10K nodes using node_save in cron will not be good :) Oct 18, 2012 at 12:32
  • i mean use hook_cron to invoke your batch process Oct 18, 2012 at 12:36
  • you can write your batch process function in a menu call back, and add the particular path in cron job with help of elysya cron Oct 18, 2012 at 12:43

I can achieve it by using a Cron job and Batch/Queue as mentioned by Anoop Joseph with some changes

Method I - Using Cron and queue

  • Cron will run the query and push the list of nodes to the queue
  • queue will pick the items one by one and Unpublish them

Method - II Using Cron and batch

  • Cron will run the query and push the list of nodes to the Batch process
  • Batch process will be launched programmatically using background_process module

In both methods Cron can be configured in such way that It runs the query once for every day by storing the last run time in a variable


The batch api is primary design to work with forms and it depends what is the purpose of your use, but you can create a function that mimic form submission, and then you can use batch together with cron, assume you have function that will be triggered by a rule on cron run, so this function is function1:

function function1 () {
    $form_state = array();
    $form_state['values']['hidden_value'] = 1;
    $form_state['values']['op'] = 'Test';
    $form_state['values']['submit'] = 'Test';
function function1_batch_form($form, &$form_state) {
  $form['hidden_value'] = array(
    '#type' => 'hidden',
    '#value' => 1,
  return $form;
function function1_batch_form_submit($form, &$form_state) {
  if ($form_state['values']['hidden_value'] == 1) {
    $batch = function1_batch_process($date);

I know this is an old thread, but if you really need things running at different times I might tackle it like this:

Start by setting up a rule with a custom rules action. You can use any logic you want here (because it's in a module using hook_action), I would check for a cache of nodes and process up-to X number of them if a cache is found or create a new cache and process up to X number of them if there is no cache.

The next part would be to set up the rule to happen on a specific page load and request that page with cron at whatever interval you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.