You are here

function scheduler_update_7101 in Scheduler 7

Delete obsolete Scheduler rows for nodes already unpublished.

File

./scheduler.install, line 132
Installation file for Scheduler module.

Code

function scheduler_update_7101() {

  // Retrieve all unpublished nodes which have a row in the Scheduler with an
  // unpublish-on date in the past and no publish-on date.
  // @see http://www.drupal.org/node/2355129
  $query = db_select('scheduler', 's');
  $query
    ->addField('s', 'nid');
  $query
    ->addJoin('INNER', 'node', 'n', 's.nid = n.nid');
  $query
    ->condition('n.status', NODE_NOT_PUBLISHED, '=');
  $query
    ->condition('s.publish_on', 0, '=');
  $query
    ->condition('s.unpublish_on', 0, '>');
  $query
    ->condition('s.unpublish_on', REQUEST_TIME, '<');

  // Delete these rows from the Scheduler table.
  if ($nids_to_delete = $query
    ->execute()
    ->fetchCol()) {
    db_delete('scheduler')
      ->condition('nid', $nids_to_delete, 'IN')
      ->execute();
  }
  return format_plural(count($nids_to_delete), '1 obsolete row deleted from scheduler table.', '@count obsolete rows deleted from scheduler table.');
}