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->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);
if (null === $entry) {
*/
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).
/**
* Parse and insert all given entries.
*
- * @param $entries
+ * @param array $entries
*/
- protected function parseEntries($entries)
+ protected function parseEntries(array $entries)
{
$i = 1;
$entryToBeFlushed = [];
$importedEntry = $this->setEntryAsRead($importedEntry);
}
+ if (false === $this->validateEntry($importedEntry)) {
+ continue;
+ }
+
$entry = $this->parseEntry($importedEntry);
if (null === $entry) {
/**
* Parse and insert all given entries.
*
- * @param $entries
+ * @param array $entries
*/
- protected function parseEntries($entries)
+ protected function parseEntries(array $entries)
{
$i = 1;
$entryToBeFlushed = [];
return 'import.chrome.description';
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['url'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*/
return 'import.firefox.description';
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['uri'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*/
return true;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['url'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*/
return true;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['href'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*/
$this->client = $client;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['resolved_url']) && empty($importedEntry['given_url'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*
return true;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['article__url'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*/
return $this;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateEntry(array $importedEntry)
+ {
+ if (empty($importedEntry['url'])) {
+ return false;
+ }
+
+ return true;
+ }
+
/**
* {@inheritdoc}
*/