Skip to content
Snippets Groups Projects
Commit f56b7ee8 authored by Kevin King's avatar Kevin King
Browse files

Merge branch '7.x-2.x' of git.drupal.org:project/feeds into 7.x-2.x

parents 2694fcac b2b2a941
No related branches found
No related tags found
No related merge requests found
...@@ -97,6 +97,21 @@ function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) ...@@ -97,6 +97,21 @@ function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result)
$result->title = 'Import number ' . my_module_import_id(); $result->title = 'Import number ' . my_module_import_id();
} }
/**
* Invoked before a feed item is saved.
*
* @param $source
* FeedsSource object that describes the source that is being imported.
* @param $entity
* The entity object.
*/
function hook_feeds_presave(FeedsSource $source, $entity) {
if ($entity->feeds_item->entity_type == 'node') {
// Skip saving this entity.
$entity->feeds_item->skip = TRUE;
}
}
/** /**
* Invoked after a feed source has been imported. * Invoked after a feed source has been imported.
* *
......
<?php
/**
* @file
* Rules integration.
*/
/**
* Implements hook_rules_event_info().
*/
function feeds_rules_event_info() {
$info = array();
$entity_info = entity_get_info();
foreach (feeds_importer_load_all() as $importer) {
$config = $importer->getConfig();
$processor = feeds_plugin($config['processor']['plugin_key'], $importer->id);
$entity_type = $processor->entityType();
$info['feeds_import_'. $importer->id] = array(
'label' => t('Before saving an item imported via @name.', array('@name' => $importer->config['name'])),
'group' => t('Feeds'),
'variables' => array(
$entity_type => array(
'label' => t('Imported @label', array('@label' => $entity_info[$entity_type]['label'])),
'type' => $entity_type,
// Saving is handled by feeds anyway (unless the skip action is used).
'skip save' => TRUE,
),
),
'access callback' => 'feeds_rules_access_callback',
);
// Add bundle information if the node processor is used.
if ($processor instanceof FeedsNodeProcessor) {
$config = $processor->getConfig();
$info['feeds_import_'. $importer->id]['variables'][$entity_type]['bundle'] = $config['content_type'];
}
}
return $info;
}
/**
* Implements of hook_rules_action_info().
*/
function feeds_rules_action_info() {
return array(
'feeds_skip_item' => array(
'base' => 'feeds_action_skip_item',
'label' => t('Skip import of feeds item'),
'group' => t('Feeds'),
'parameter' => array(
'entity' => array('type' => 'entity', 'label' => t('The feeds import item to be marked as skipped')),
),
'access callback' => 'feeds_rules_access_callback',
),
);
}
/**
* Mark feeds import item as skipped.
*/
function feeds_action_skip_item($entity_wrapper) {
$entity = $entity_wrapper->value();
if(isset($entity->feeds_item)) {
$entity->feeds_item->skip = TRUE;
}
}
/**
* Help callback for the skip action.
*/
function feeds_action_skip_item_help() {
return t("This action allows skipping certain feed items during feeds processing, i.e. before an imported item is saved. Once this action is used on a item, the changes to the entity of the feed item are not saved.");
}
/**
* Access callback for the feeds rules integration.
*/
function feeds_rules_access_callback() {
return user_access('administer feeds');
}
...@@ -201,6 +201,13 @@ class FeedsSource extends FeedsConfigurable { ...@@ -201,6 +201,13 @@ class FeedsSource extends FeedsConfigurable {
$this->load(); $this->load();
} }
/**
* Returns the FeedsImporter object that this source is expected to be used with.
*/
public function importer() {
return $this->importer;
}
/** /**
* Preview = fetch and parse a feed. * Preview = fetch and parse a feed.
* *
......
...@@ -126,14 +126,23 @@ abstract class FeedsProcessor extends FeedsPlugin { ...@@ -126,14 +126,23 @@ abstract class FeedsProcessor extends FeedsPlugin {
} }
$this->map($source, $parser_result, $entity); $this->map($source, $parser_result, $entity);
$this->entityValidate($entity); $this->entityValidate($entity);
$this->entitySave($entity);
// Track progress. // Allow modules to alter the entity before saving.
if (empty($entity_id)) { module_invoke_all('feeds_presave', $source, $entity);
$state->created++; if (module_exists('rules')) {
rules_invoke_event('feeds_import_'. $source->importer()->id, $entity);
} }
else {
$state->updated++; // Enable modules to skip saving at all.
if (empty($entity->feeds_item->skip)) {
$this->entitySave($entity);
// Track progress.
if (empty($entity_id)) {
$state->created++;
}
else {
$state->updated++;
}
} }
} }
catch (Exception $e) { catch (Exception $e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment