Add disableContentUpdate import option

This commit also decouples the "import" and "update" functions inside
ContentProxy. If a content array is available, it must be passed to the
new importEntry method.
This commit is contained in:
Jerome Charaoui
2016-12-07 15:16:49 -05:00
committed by Jeremy Benoist
parent 1c5da417e4
commit d0e9b3d640
11 changed files with 118 additions and 60 deletions

View File

@ -24,6 +24,7 @@ abstract class AbstractImport implements ImportInterface
protected $producer;
protected $user;
protected $markAsRead;
protected $disableContentUpdate;
protected $skippedEntries = 0;
protected $importedEntries = 0;
protected $queuedEntries = 0;
@ -84,6 +85,27 @@ abstract class AbstractImport implements ImportInterface
return $this->markAsRead;
}
/**
* Set whether articles should be fetched for updated content.
*
* @param bool $markAsRead
*/
public function setDisableContentUpdate($disableContentUpdate)
{
$this->disableContentUpdate = $disableContentUpdate;
return $this;
}
/**
* Get whether articles should be fetched for updated content.
*/
public function getDisableContentUpdate()
{
return $this->disableContentUpdate;
}
/**
* Fetch content from the ContentProxy (using graby).
* If it fails return the given entry to be saved in all case (to avoid user to loose the content).
@ -95,9 +117,12 @@ abstract class AbstractImport implements ImportInterface
protected function fetchContent(Entry $entry, $url, array $content = [])
{
try {
$this->contentProxy->updateEntry($entry, $url, $content);
$this->contentProxy->importEntry($entry, $content, $this->disableContentUpdate);
} catch (\Exception $e) {
return $entry;
$this->logger->error('Error trying to import an entry.', [
'entry_url' => $content['url'],
'error_msg' => $e->getMessage(),
]);
}
}