Skip to content
Snippets Groups Projects
Commit 0ba4a84a authored by klausi's avatar klausi Committed by Chris Leppanen
Browse files

Issue #2192851 by klausi: Hook_feeds_after_import() should have access to exceptions.

parent be0b65cd
No related branches found
No related tags found
No related merge requests found
...@@ -188,6 +188,13 @@ function hook_feeds_after_save(FeedsSource $source, $entity, $item, $entity_id) ...@@ -188,6 +188,13 @@ function hook_feeds_after_save(FeedsSource $source, $entity, $item, $entity_id)
*/ */
function hook_feeds_after_import(FeedsSource $source) { function hook_feeds_after_import(FeedsSource $source) {
// See geotaxonomy module's implementation for an example. // See geotaxonomy module's implementation for an example.
// We can also check for an exception in this hook. The exception should not
// be thrown here, Feeds will handle it.
if (isset($source->exception)) {
watchdog('mymodule', 'An exception occurred during importing!', array(), WATCHDOG_ERROR);
mymodule_panic_reaction($source);
}
} }
/** /**
......
...@@ -179,6 +179,9 @@ class FeedsSource extends FeedsConfigurable { ...@@ -179,6 +179,9 @@ class FeedsSource extends FeedsConfigurable {
// Timestamp when this source was imported the last time. // Timestamp when this source was imported the last time.
protected $imported; protected $imported;
// Holds an exception object in case an exception occurs during importing.
protected $exception;
/** /**
* Instantiate a unique object per class/id/feed_nid. Don't use * Instantiate a unique object per class/id/feed_nid. Don't use
* directly, use feeds_source() instead. * directly, use feeds_source() instead.
...@@ -379,9 +382,16 @@ class FeedsSource extends FeedsConfigurable { ...@@ -379,9 +382,16 @@ class FeedsSource extends FeedsConfigurable {
// Process. // Process.
$this->importer->processor->process($this, $parser_result); $this->importer->processor->process($this, $parser_result);
// Import finished without exceptions, so unset any potentially previously
// recorded exceptions.
unset($this->exception);
} }
catch (Exception $e) { catch (Exception $e) {
// $e is stored and re-thrown once we've had a chance to log our progress. // $e is stored and re-thrown once we've had a chance to log our progress.
// Set the exception so that other modules can check if an exception
// occurred in hook_feeds_after_import().
$this->exception = $e;
} }
$this->releaseLock(); $this->releaseLock();
......
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