Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
feeds
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
feeds
Commits
b1eac923
Commit
b1eac923
authored
11 years ago
by
gordon
Committed by
Chris Leppanen
11 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue #1961998 by gordon: Added new hook hook_feeds_before_update().
parent
80db3a55
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
feeds.api.php
+51
-20
51 additions, 20 deletions
feeds.api.php
feeds.module
+5
-0
5 additions, 0 deletions
feeds.module
plugins/FeedsProcessor.inc
+4
-2
4 additions, 2 deletions
plugins/FeedsProcessor.inc
with
60 additions
and
22 deletions
feeds.api.php
+
51
−
20
View file @
b1eac923
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
feeds.module
+
5
−
0
View file @
b1eac923
...
...
@@ -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'
,
...
...
This diff is collapsed.
Click to expand it.
plugins/FeedsProcessor.inc
+
4
−
2
View file @
b1eac923
...
...
@@ -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
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment