forked from wallabag/wallabag
Validate imported entry to avoid error on import
We got some imports with a missing `url` field generating some errors while trying to retrieve an existing entry with that url. Introducing the `validateEntry` allow us to dismiss a message when it doesn't have an url (or other missing stuff in the future)
This commit is contained in:
@ -118,6 +118,15 @@ abstract class AbstractImport implements ImportInterface
|
||||
*/
|
||||
abstract public function parseEntry(array $importedEntry);
|
||||
|
||||
/**
|
||||
* Validate that an entry is valid (like has some required keys, etc.).
|
||||
*
|
||||
* @param array $importedEntry
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function validateEntry(array $importedEntry);
|
||||
|
||||
/**
|
||||
* 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).
|
||||
@ -141,9 +150,9 @@ abstract class AbstractImport implements ImportInterface
|
||||
/**
|
||||
* Parse and insert all given entries.
|
||||
*
|
||||
* @param $entries
|
||||
* @param array $entries
|
||||
*/
|
||||
protected function parseEntries($entries)
|
||||
protected function parseEntries(array $entries)
|
||||
{
|
||||
$i = 1;
|
||||
$entryToBeFlushed = [];
|
||||
@ -153,6 +162,10 @@ abstract class AbstractImport implements ImportInterface
|
||||
$importedEntry = $this->setEntryAsRead($importedEntry);
|
||||
}
|
||||
|
||||
if (false === $this->validateEntry($importedEntry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entry = $this->parseEntry($importedEntry);
|
||||
|
||||
if (null === $entry) {
|
||||
|
||||
Reference in New Issue
Block a user