You are here

public function FeedsNodeProcessor::clear in Feeds 7

Same name and namespace in other branches
  1. 6 plugins/FeedsNodeProcessor.inc \FeedsNodeProcessor::clear()

Implements FeedsProcessor::clear().

Overrides FeedsProcessor::clear

File

plugins/FeedsNodeProcessor.inc, line 89
Class definition of FeedsNodeProcessor.

Class

FeedsNodeProcessor
Creates nodes from feed items.

Code

public function clear(FeedsBatch $batch, FeedsSource $source) {
  if (!$batch
    ->getTotal(FEEDS_CLEARING)) {
    $total = db_query("SELECT COUNT(n.nid) FROM {node} n JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE fn.id = :id AND fn.feed_nid = :nid", array(
      ':id' => $source->id,
      ':nid' => $source->feed_nid,
    ))
      ->fetchField();
    $batch
      ->setTotal(FEEDS_CLEARING, $total);
  }
  $count = variable_get('feeds_node_batch_size', FEEDS_NODE_BATCH_SIZE);
  $nids = array();
  $nodes = db_query_range("SELECT n.nid FROM {node} n JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE fn.id = :id AND fn.feed_nid = :nid", 0, $count, array(
    ':id' => $source->id,
    ':nid' => $source->feed_nid,
  ));
  foreach ($nodes as $node) {
    $nids[$node->nid] = $node->nid;
    $batch->deleted++;
  }
  node_delete_multiple($nids);
  if (db_query_range("SELECT 1 FROM {node} n JOIN {feeds_node_item} fn ON n.nid = fn.nid WHERE fn.id = :id AND fn.feed_nid = :nid", 0, 1, array(
    ':id' => $source->id,
    ':nid' => $source->feed_nid,
  ))
    ->fetchField()) {
    $batch
      ->setProgress(FEEDS_CLEARING, $batch->deleted);
    return;
  }

  // Set message.
  drupal_get_messages('status');
  if ($batch->deleted) {
    drupal_set_message(format_plural($batch->deleted, 'Deleted @number node.', 'Deleted @number nodes.', array(
      '@number' => $batch->deleted,
    )));
  }
  else {
    drupal_set_message(t('There is no content to be deleted.'));
  }
  $batch
    ->setProgress(FEEDS_CLEARING, FEEDS_BATCH_COMPLETE);
}