public function FeedsNodeProcessor::process in Feeds 7
Same name and namespace in other branches
- 6 plugins/FeedsNodeProcessor.inc \FeedsNodeProcessor::process()
Implements FeedsProcessor::process().
Overrides FeedsProcessor::process
File
- plugins/
FeedsNodeProcessor.inc, line 28 - Class definition of FeedsNodeProcessor.
Class
- FeedsNodeProcessor
- Creates nodes from feed items.
Code
public function process(FeedsImportBatch $batch, FeedsSource $source) {
// Keep track of processed items in this pass, set total number of items.
$processed = 0;
if (!$batch
->getTotal(FEEDS_PROCESSING)) {
$batch
->setTotal(FEEDS_PROCESSING, $batch
->getItemCount());
}
while ($item = $batch
->shiftItem()) {
// Create/update if item does not exist or update existing is enabled.
if (!($nid = $this
->existingItemId($batch, $source)) || $this->config['update_existing'] != FEEDS_SKIP_EXISTING) {
// Only proceed if item has actually changed.
$hash = $this
->hash($item);
if (!empty($nid) && $hash == $this
->getHash($nid)) {
continue;
}
$node = $this
->buildNode($nid, $source->feed_nid);
$node->feeds_node_item->hash = $hash;
// Map and save node. If errors occur don't stop but report them.
try {
$this
->map($batch, $node);
node_save($node);
if (!empty($nid)) {
$batch->updated++;
}
else {
$batch->created++;
}
} catch (Exception $e) {
drupal_set_message($e
->getMessage(), 'warning');
watchdog('feeds', $e
->getMessage(), array(), WATCHDOG_WARNING);
}
}
$processed++;
if ($processed >= variable_get('feeds_node_batch_size', FEEDS_NODE_BATCH_SIZE)) {
$batch
->setProgress(FEEDS_PROCESSING, $batch->created + $batch->updated);
return;
}
}
// 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' => node_type_get_name($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' => node_type_get_name($this->config['content_type']),
)));
}
else {
drupal_set_message(t('There is no new content.'));
}
$batch
->setProgress(FEEDS_PROCESSING, FEEDS_BATCH_COMPLETE);
}