]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/ImportBundle/Import/AbstractImport.php
Replace continue; with break; to avoid PHP 7.3 warnings
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Import / AbstractImport.php
index 167853aaef541b8955c8cd6ab0a63e2198f81159..ea86c52862c3b94f6cb1bc5fe8a88606ebc66f32 100644 (file)
@@ -2,17 +2,17 @@
 
 namespace Wallabag\ImportBundle\Import;
 
+use Doctrine\ORM\EntityManager;
+use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
-use Doctrine\ORM\EntityManager;
-use Wallabag\CoreBundle\Helper\ContentProxy;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Wallabag\CoreBundle\Entity\Entry;
 use Wallabag\CoreBundle\Entity\Tag;
+use Wallabag\CoreBundle\Event\EntrySavedEvent;
+use Wallabag\CoreBundle\Helper\ContentProxy;
 use Wallabag\CoreBundle\Helper\TagsAssigner;
 use Wallabag\UserBundle\Entity\User;
-use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Wallabag\CoreBundle\Event\EntrySavedEvent;
 
 abstract class AbstractImport implements ImportInterface
 {
@@ -24,7 +24,7 @@ abstract class AbstractImport implements ImportInterface
     protected $producer;
     protected $user;
     protected $markAsRead;
-    protected $disableContentUpdate;
+    protected $disableContentUpdate = false;
     protected $skippedEntries = 0;
     protected $importedEntries = 0;
     protected $queuedEntries = 0;
@@ -88,7 +88,7 @@ abstract class AbstractImport implements ImportInterface
     /**
      * Set whether articles should be fetched for updated content.
      *
-     * @param bool $markAsRead
+     * @param bool $disableContentUpdate
      */
     public function setDisableContentUpdate($disableContentUpdate)
     {
@@ -98,13 +98,25 @@ abstract class AbstractImport implements ImportInterface
     }
 
     /**
-     * Get whether articles should be fetched for updated content.
+     * {@inheritdoc}
      */
-    public function getDisableContentUpdate()
+    public function getSummary()
     {
-        return $this->disableContentUpdate;
+        return [
+            'skipped' => $this->skippedEntries,
+            'imported' => $this->importedEntries,
+            'queued' => $this->queuedEntries,
+        ];
     }
 
+    /**
+     * Parse one entry.
+     *
+     * @param array $importedEntry
+     *
+     * @return Entry
+     */
+    abstract public function parseEntry(array $importedEntry);
 
     /**
      * Fetch content from the ContentProxy (using graby).
@@ -117,10 +129,10 @@ abstract class AbstractImport implements ImportInterface
     protected function fetchContent(Entry $entry, $url, array $content = [])
     {
         try {
-            $this->contentProxy->importEntry($entry, $content, $this->disableContentUpdate);
+            $this->contentProxy->updateEntry($entry, $url, $content, $this->disableContentUpdate);
         } catch (\Exception $e) {
             $this->logger->error('Error trying to import an entry.', [
-                'entry_url' => $content['url'],
+                'entry_url' => $url,
                 'error_msg' => $e->getMessage(),
             ]);
         }
@@ -144,7 +156,7 @@ abstract class AbstractImport implements ImportInterface
             $entry = $this->parseEntry($importedEntry);
 
             if (null === $entry) {
-                continue;
+                break;
             }
 
             // store each entry to be flushed so we can trigger the entry.saved event for each of them
@@ -153,7 +165,7 @@ abstract class AbstractImport implements ImportInterface
             $entryToBeFlushed[] = $entry;
 
             // flush every 20 entries
-            if (($i % 20) === 0) {
+            if (0 === ($i % 20)) {
                 $this->em->flush();
 
                 foreach ($entryToBeFlushed as $entry) {
@@ -204,27 +216,6 @@ abstract class AbstractImport implements ImportInterface
         }
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    public function getSummary()
-    {
-        return [
-            'skipped' => $this->skippedEntries,
-            'imported' => $this->importedEntries,
-            'queued' => $this->queuedEntries,
-        ];
-    }
-
-    /**
-     * Parse one entry.
-     *
-     * @param array $importedEntry
-     *
-     * @return Entry
-     */
-    abstract public function parseEntry(array $importedEntry);
-
     /**
      * Set current imported entry to archived / read.
      * Implementation is different accross all imports.