You are here

public function FeedsFeedNodeProcessor::process in Feeds 7

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

Implements FeedsProcessor::process().

Overrides FeedsProcessor::process

File

plugins/FeedsFeedNodeProcessor.inc, line 17
Class definition of FeedsFeedNodeProcessor.

Class

FeedsFeedNodeProcessor
Creates *feed* nodes from feed items. The difference to FeedsNodeProcessor is that this plugin only creates nodes that are feed nodes themselves.

Code

public function process(FeedsImportBatch $batch, FeedsSource $source) {
  while ($item = $batch
    ->shiftItem()) {

    // If the target item does not exist OR if update_existing is enabled,
    // map and save.
    if (!($nid = $this
      ->existingItemId($batch, $source) || $this->config['update_existing'])) {

      // Map item to a node.
      $node = $this
        ->map($batch);

      // If updating populate nid and vid avoiding an expensive node_load().
      if (!empty($nid)) {
        $node->nid = $nid;
        $node->vid = db_query("SELECT vid FROM {node} WHERE nid = :nid", array(
          ':nid' => $nid,
        ))
          ->fetchField();
      }

      // Save the node.
      node_save($node);
      if ($nid) {
        $batch->updated++;
      }
      else {
        $batch->created++;
      }
    }
  }

  // Set messages.
  if ($batch->created) {
    drupal_set_message(format_plural($batch->created, 'Created @number @type node.', 'Created @number @type nodes.', array(
      '@number' => $batch->created,
      '@type' => $this->config['content_type'],
    )));
  }
  elseif ($batch->updated) {
    drupal_set_message(format_plural($batch->updated, 'Updated @number @type node.', 'Updated @number @type nodes.', array(
      '@number' => $batch->updated,
      '@type' => $this->config['content_type'],
    )));
  }
  else {
    drupal_set_message(t('There is no new content.'));
  }
}