Merge pull request #3816 from wallabag/validate-import-entry
Validate imported entry to avoid error on import
This commit is contained in:
commit
8f5c4b083c
@ -52,6 +52,13 @@ abstract class AbstractConsumer
|
|||||||
|
|
||||||
$this->import->setUser($user);
|
$this->import->setUser($user);
|
||||||
|
|
||||||
|
if (false === $this->import->validateEntry($storedEntry)) {
|
||||||
|
$this->logger->warning('Entry is invalid', ['entry' => $storedEntry]);
|
||||||
|
|
||||||
|
// return true to skip message
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
$entry = $this->import->parseEntry($storedEntry);
|
$entry = $this->import->parseEntry($storedEntry);
|
||||||
|
|
||||||
if (null === $entry) {
|
if (null === $entry) {
|
||||||
|
@ -118,6 +118,15 @@ abstract class AbstractImport implements ImportInterface
|
|||||||
*/
|
*/
|
||||||
abstract public function parseEntry(array $importedEntry);
|
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).
|
* 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).
|
* 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.
|
* Parse and insert all given entries.
|
||||||
*
|
*
|
||||||
* @param $entries
|
* @param array $entries
|
||||||
*/
|
*/
|
||||||
protected function parseEntries($entries)
|
protected function parseEntries(array $entries)
|
||||||
{
|
{
|
||||||
$i = 1;
|
$i = 1;
|
||||||
$entryToBeFlushed = [];
|
$entryToBeFlushed = [];
|
||||||
@ -153,6 +162,10 @@ abstract class AbstractImport implements ImportInterface
|
|||||||
$importedEntry = $this->setEntryAsRead($importedEntry);
|
$importedEntry = $this->setEntryAsRead($importedEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (false === $this->validateEntry($importedEntry)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$entry = $this->parseEntry($importedEntry);
|
$entry = $this->parseEntry($importedEntry);
|
||||||
|
|
||||||
if (null === $entry) {
|
if (null === $entry) {
|
||||||
|
@ -149,9 +149,9 @@ abstract class BrowserImport extends AbstractImport
|
|||||||
/**
|
/**
|
||||||
* Parse and insert all given entries.
|
* Parse and insert all given entries.
|
||||||
*
|
*
|
||||||
* @param $entries
|
* @param array $entries
|
||||||
*/
|
*/
|
||||||
protected function parseEntries($entries)
|
protected function parseEntries(array $entries)
|
||||||
{
|
{
|
||||||
$i = 1;
|
$i = 1;
|
||||||
$entryToBeFlushed = [];
|
$entryToBeFlushed = [];
|
||||||
|
@ -30,6 +30,18 @@ class ChromeImport extends BrowserImport
|
|||||||
return 'import.chrome.description';
|
return 'import.chrome.description';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['url'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +30,18 @@ class FirefoxImport extends BrowserImport
|
|||||||
return 'import.firefox.description';
|
return 'import.firefox.description';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['uri'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -105,6 +105,18 @@ class InstapaperImport extends AbstractImport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['url'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -80,6 +80,18 @@ class PinboardImport extends AbstractImport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['href'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -168,6 +168,18 @@ class PocketImport extends AbstractImport
|
|||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['resolved_url']) && empty($importedEntry['given_url'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
|
@ -80,6 +80,18 @@ class ReadabilityImport extends AbstractImport
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['article__url'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
@ -86,6 +86,18 @@ abstract class WallabagImport extends AbstractImport
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validateEntry(array $importedEntry)
|
||||||
|
{
|
||||||
|
if (empty($importedEntry['url'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user