Skip to content
Snippets Groups Projects
Commit b1eac923 authored by gordon's avatar gordon Committed by Chris Leppanen
Browse files

Issue #1961998 by gordon: Added new hook hook_feeds_before_update().

parent 80db3a55
No related branches found
No related tags found
No related merge requests found
......@@ -87,9 +87,9 @@ function hook_feeds_plugins() {
/**
* Invoked after a feed source has been parsed, before it will be processed.
*
* @param $source
* @param FeedsSource $source
* FeedsSource object that describes the source that has been imported.
* @param $result
* @param FeedsParserResult $result
* FeedsParserResult object that has been parsed from the source.
*/
function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
......@@ -97,15 +97,53 @@ function hook_feeds_after_parse(FeedsSource $source, FeedsParserResult $result)
$result->title = 'Import number ' . my_module_import_id();
}
/**
* Invoked before a feed source import starts.
*
* @param FeedsSource $source
* FeedsSource object that describes the source that is going to be imported.
*/
function hook_feeds_before_import(FeedsSource $source) {
// See feeds_rules module's implementation for an example.
}
/**
* Invoked before a feed item is updated/created/replaced.
*
* This is called every time a feed item is processed no matter if the item gets
* updated or not.
*
* @param FeedsSource $source
* The source for the current feed.
* @param array $item
* All the current item from the feed.
* @param int|null $entity_id
* The id of the current item which is going to be updated. If this is a new
* item, then NULL is passed.
*/
function hook_feeds_before_update(FeedsSource $source, $item, $entity_id) {
if ($entity_id) {
$processor = $source->importer->processor;
db_update('foo_bar')
->fields(array('entity_type' => $processor->entityType(), 'entity_id' => $entity_id, 'last_seen' => REQUEST_TIME))
->condition('entity_type', $processor->entityType())
->condition('entity_id', $entity_id)
->execute();
}
}
/**
* Invoked before a feed item is saved.
*
* @param $source
* @param FeedsSource $source
* FeedsSource object that describes the source that is being imported.
* @param $entity
* The entity object.
* @param $item
* @param array $item
* The parser result for this entity.
* @param int|null $entity_id
* The id of the current item which is going to be updated. If this is a new
* item, then NULL is passed.
*/
function hook_feeds_presave(FeedsSource $source, $entity, $item) {
if ($entity->feeds_item->entity_type == 'node') {
......@@ -114,32 +152,25 @@ function hook_feeds_presave(FeedsSource $source, $entity, $item) {
}
}
/**
* Invoked before a feed source import starts.
*
* @param $source
* FeedsSource object that describes the source that is going to be imported.
*/
function hook_feeds_before_import(FeedsSource $source) {
// See feeds_rules module's implementation for an example.
}
/**
* Invoked after a feed item has been saved.
*
* @param $source
* @param FeedsSource $source
* FeedsSource object that describes the source that is being imported.
* @param $entity
* The entity object that has just been saved.
* @param $item
* @param array $item
* The parser result for this entity.
* @param int|null $entity_id
* The id of the current item which is going to be updated. If this is a new
* item, then NULL is passed.
*/
function hook_feeds_after_save(FeedsSource $source, $entity, $item) {
function hook_feeds_after_save(FeedsSource $source, $entity, $item, $entity_id) {
// Use $entity->nid of the saved node.
// Although the $entity object is passed by reference, any changes made in
// this function will be ignored by the FeedsProcessor.
$config = $source->importer()->getConfig();
$config = $source->importer->getConfig();
if ($config['processor']['config']['purge_unseen_items'] && isset($entity->feeds_item)) {
$feeds_item = $entity->feeds_item;
......@@ -152,7 +183,7 @@ function hook_feeds_after_save(FeedsSource $source, $entity, $item) {
/**
* Invoked after a feed source has been imported.
*
* @param $source
* @param FeedsSource $source
* FeedsSource object that describes the source that has been imported.
*/
function hook_feeds_after_import(FeedsSource $source) {
......@@ -162,7 +193,7 @@ function hook_feeds_after_import(FeedsSource $source) {
/**
* Invoked after a feed source has been cleared of its items.
*
* @param $source
* @param FeedsSource $source
* FeedsSource object that describes the source that has been cleared.
*/
function hook_feeds_after_clear(FeedsSource $source) {
......
......@@ -27,7 +27,12 @@ define('FEEDS_BATCH_ACTIVE', 0.0);
*/
function feeds_hook_info() {
$hooks = array(
'feeds_plugins',
'feeds_after_parse',
'feeds_before_import',
'feeds_before_update',
'feeds_presave',
'feeds_after_save'
'feeds_after_import',
'feeds_after_clear',
'feeds_processor_targets_alter',
......
......@@ -183,6 +183,8 @@ abstract class FeedsProcessor extends FeedsPlugin {
$entity_id = $this->existingEntityId($source, $parser_result);
$skip_existing = $this->config['update_existing'] == FEEDS_SKIP_EXISTING;
module_invoke_all('feeds_before_update', $source, $item, $entity_id);
// If it exists, and we are not updating, pass onto the next item.
if ($entity_id && $skip_existing) {
continue;
......@@ -221,7 +223,7 @@ abstract class FeedsProcessor extends FeedsPlugin {
$this->entityValidate($entity);
// Allow modules to alter the entity before saving.
module_invoke_all('feeds_presave', $source, $entity, $item);
module_invoke_all('feeds_presave', $source, $entity, $item, $entity_id);
if (module_exists('rules')) {
rules_invoke_event('feeds_import_'. $source->importer()->id, $entity);
}
......@@ -237,7 +239,7 @@ abstract class FeedsProcessor extends FeedsPlugin {
// Allow modules to perform operations using the saved entity data.
// $entity contains the updated entity after saving.
module_invoke_all('feeds_after_save', $source, $entity, $item);
module_invoke_all('feeds_after_save', $source, $entity, $item, $entity_id);
// Track progress.
if (empty($entity_id)) {
......
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