From d1e5059ea0ccfbf8e224e71f8d233b01ddfbc92d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Thu, 4 May 2017 11:53:44 +0200 Subject: Use username to import Signed-off-by: Thomas Citharel add docs Signed-off-by: Thomas Citharel use username as default Signed-off-by: Thomas Citharel rename user to username typo Signed-off-by: Thomas Citharel --- src/Wallabag/ImportBundle/Command/ImportCommand.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index 28d01715..ce72837a 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -15,10 +15,11 @@ class ImportCommand extends ContainerAwareCommand $this ->setName('wallabag:import') ->setDescription('Import entries from a JSON export') - ->addArgument('userId', InputArgument::REQUIRED, 'User ID to populate') + ->addArgument('username', InputArgument::REQUIRED, 'User to populate') ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) + ->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false) ; } @@ -34,10 +35,14 @@ class ImportCommand extends ContainerAwareCommand // Turning off doctrine default logs queries for saving memory $em->getConnection()->getConfiguration()->setSQLLogger(null); - $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('userId')); + if ($input->getOption('useUserId')) { + $user = $em->getRepository('WallabagUserBundle:User')->findOneById($input->getArgument('username')); + } else { + $user = $em->getRepository('WallabagUserBundle:User')->findOneByUsername($input->getArgument('username')); + } if (!is_object($user)) { - throw new Exception(sprintf('User with id "%s" not found', $input->getArgument('userId'))); + throw new Exception(sprintf('User "%s" not found', $input->getArgument('username'))); } switch ($input->getOption('importer')) { -- cgit v1.2.3 From 4c707d087b9989d6cd2f21d3141eca1fe9c3f969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 23 May 2017 17:07:26 +0200 Subject: Fixed is_starred for wallabag v2 import --- src/Wallabag/ImportBundle/Import/WallabagV2Import.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php index d2a89d79..2603503c 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php @@ -37,7 +37,7 @@ class WallabagV2Import extends WallabagImport 'html' => $entry['content'], 'content_type' => $entry['mimetype'], 'is_archived' => (int) ($entry['is_archived'] || $this->markAsRead), - 'is_starred' => false, + 'is_starred' => (int) $entry['is_starred'], ] + $entry; } -- cgit v1.2.3 From 6bc6fb1f60e7b81a21f844dca025671a2f4a4564 Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sat, 27 May 2017 22:08:14 +0200 Subject: Move Tags assigner to a separate file Signed-off-by: Thomas Citharel --- src/Wallabag/ImportBundle/Import/AbstractImport.php | 5 ++++- src/Wallabag/ImportBundle/Import/BrowserImport.php | 2 +- src/Wallabag/ImportBundle/Import/PinboardImport.php | 2 +- src/Wallabag/ImportBundle/Import/PocketImport.php | 2 +- src/Wallabag/ImportBundle/Import/WallabagImport.php | 2 +- src/Wallabag/ImportBundle/Resources/config/services.yml | 8 ++++++++ 6 files changed, 16 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 1d4a6e27..a61388c0 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManager; use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Tag; +use Wallabag\CoreBundle\Helper\TagsAssigner; use Wallabag\UserBundle\Entity\User; use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -18,6 +19,7 @@ abstract class AbstractImport implements ImportInterface protected $em; protected $logger; protected $contentProxy; + protected $tagsAssigner; protected $eventDispatcher; protected $producer; protected $user; @@ -26,11 +28,12 @@ abstract class AbstractImport implements ImportInterface protected $importedEntries = 0; protected $queuedEntries = 0; - public function __construct(EntityManager $em, ContentProxy $contentProxy, EventDispatcherInterface $eventDispatcher) + public function __construct(EntityManager $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher) { $this->em = $em; $this->logger = new NullLogger(); $this->contentProxy = $contentProxy; + $this->tagsAssigner = $tagsAssigner; $this->eventDispatcher = $eventDispatcher; } diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 8bf7d92e..c8a9b4e6 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -205,7 +205,7 @@ abstract class BrowserImport extends AbstractImport $entry = $this->fetchContent($entry, $data['url'], $data); if (array_key_exists('tags', $data)) { - $this->contentProxy->assignTagsToEntry( + $this->tagsAssigner->assignTagsToEntry( $entry, $data['tags'] ); diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php index d9865534..489b9257 100644 --- a/src/Wallabag/ImportBundle/Import/PinboardImport.php +++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php @@ -112,7 +112,7 @@ class PinboardImport extends AbstractImport $entry = $this->fetchContent($entry, $data['url'], $data); if (!empty($data['tags'])) { - $this->contentProxy->assignTagsToEntry( + $this->tagsAssigner->assignTagsToEntry( $entry, $data['tags'], $this->em->getUnitOfWork()->getScheduledEntityInsertions() diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 33093480..1171d452 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -216,7 +216,7 @@ class PocketImport extends AbstractImport } if (isset($importedEntry['tags']) && !empty($importedEntry['tags'])) { - $this->contentProxy->assignTagsToEntry( + $this->tagsAssigner->assignTagsToEntry( $entry, array_keys($importedEntry['tags']), $this->em->getUnitOfWork()->getScheduledEntityInsertions() diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php index 702da057..0e5382cf 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagImport.php +++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php @@ -111,7 +111,7 @@ abstract class WallabagImport extends AbstractImport $entry = $this->fetchContent($entry, $data['url'], $data); if (array_key_exists('tags', $data)) { - $this->contentProxy->assignTagsToEntry( + $this->tagsAssigner->assignTagsToEntry( $entry, $data['tags'], $this->em->getUnitOfWork()->getScheduledEntityInsertions() diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index c4fe3f92..661dc7e1 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml @@ -20,6 +20,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setClient, [ "@wallabag_import.pocket.client" ] ] @@ -32,6 +33,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] @@ -43,6 +45,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] @@ -54,6 +57,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] @@ -65,6 +69,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] @@ -76,6 +81,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] @@ -87,6 +93,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] @@ -97,6 +104,7 @@ services: arguments: - "@doctrine.orm.entity_manager" - "@wallabag_core.content_proxy" + - "@wallabag_core.tags_assigner" - "@event_dispatcher" calls: - [ setLogger, [ "@logger" ]] -- cgit v1.2.3 From 5d3deafd3efc04df53fc24ee82a49988f72756dd Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Sun, 28 May 2017 01:16:01 +0200 Subject: CS Signed-off-by: Thomas Citharel --- src/Wallabag/ImportBundle/Import/BrowserImport.php | 1 - src/Wallabag/ImportBundle/Import/PocketImport.php | 1 - 2 files changed, 2 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index c8a9b4e6..ef0eeb7e 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -4,7 +4,6 @@ namespace Wallabag\ImportBundle\Import; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\UserBundle\Entity\User; -use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Event\EntrySavedEvent; abstract class BrowserImport extends AbstractImport diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 1171d452..8835161b 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -5,7 +5,6 @@ namespace Wallabag\ImportBundle\Import; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Helper\ContentProxy; class PocketImport extends AbstractImport { -- cgit v1.2.3 From 047fdc767aed03a92f37273eae2206f3d61fedc5 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 20:15:41 +0200 Subject: Add tests --- src/Wallabag/ImportBundle/Import/WallabagV2Import.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php index 2603503c..3e085ecf 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV2Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV2Import.php @@ -36,8 +36,8 @@ class WallabagV2Import extends WallabagImport return [ 'html' => $entry['content'], 'content_type' => $entry['mimetype'], - 'is_archived' => (int) ($entry['is_archived'] || $this->markAsRead), - 'is_starred' => (int) $entry['is_starred'], + 'is_archived' => (bool) ($entry['is_archived'] || $this->markAsRead), + 'is_starred' => (bool) $entry['is_starred'], ] + $entry; } -- cgit v1.2.3 From 7a8ed3cee1003aae56400e18509980e2695ea622 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Wed, 31 May 2017 10:38:00 +0200 Subject: Add support for tag in Instapaper import --- src/Wallabag/ImportBundle/Import/InstapaperImport.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index 70a53f1a..c8e0cd5b 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php @@ -68,6 +68,14 @@ class InstapaperImport extends AbstractImport continue; } + // last element in the csv is the folder where the content belong + // BUT it can also be the status (since status = folder in Instapaper) + // and we don't want archive, unread & starred to become a tag + $tags = null; + if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'])) { + $tags = [$data[3]]; + } + $entries[] = [ 'url' => $data[0], 'title' => $data[1], @@ -75,6 +83,7 @@ class InstapaperImport extends AbstractImport 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred', 'is_starred' => $data[3] === 'Starred', 'html' => false, + 'tags' => $tags, ]; } fclose($handle); @@ -118,6 +127,14 @@ class InstapaperImport extends AbstractImport // update entry with content (in case fetching failed, the given entry will be return) $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry); + if (!empty($importedEntry['tags'])) { + $this->tagsAssigner->assignTagsToEntry( + $entry, + $importedEntry['tags'], + $this->em->getUnitOfWork()->getScheduledEntityInsertions() + ); + } + $entry->setArchived($importedEntry['is_archived']); $entry->setStarred($importedEntry['is_starred']); -- cgit v1.2.3 From 7aba665e484c5c36ee029219a999a427d864ff22 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Tue, 6 Dec 2016 22:17:44 -0500 Subject: Avoid returning objects passed by reference. Objects are always passed by reference, so it doesn't make sense to return an object which is passed by reference as it will always be the same object. This change makes the code a bit more readable. --- src/Wallabag/ImportBundle/Import/AbstractImport.php | 4 +--- src/Wallabag/ImportBundle/Import/BrowserImport.php | 2 +- src/Wallabag/ImportBundle/Import/InstapaperImport.php | 2 +- src/Wallabag/ImportBundle/Import/PinboardImport.php | 2 +- src/Wallabag/ImportBundle/Import/PocketImport.php | 2 +- src/Wallabag/ImportBundle/Import/ReadabilityImport.php | 2 +- src/Wallabag/ImportBundle/Import/WallabagImport.php | 2 +- 7 files changed, 7 insertions(+), 9 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index a61388c0..fc462c4c 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -91,13 +91,11 @@ abstract class AbstractImport implements ImportInterface * @param Entry $entry Entry to update * @param string $url Url to grab content for * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url - * - * @return Entry */ protected function fetchContent(Entry $entry, $url, array $content = []) { try { - return $this->contentProxy->updateEntry($entry, $url, $content); + $this->contentProxy->updateEntry($entry, $url, $content); } catch (\Exception $e) { return $entry; } diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index ef0eeb7e..71e65e59 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -201,7 +201,7 @@ abstract class BrowserImport extends AbstractImport $entry->setTitle($data['title']); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $data['url'], $data); + $this->fetchContent($entry, $data['url'], $data); if (array_key_exists('tags', $data)) { $this->tagsAssigner->assignTagsToEntry( diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index c8e0cd5b..3aa12f6f 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php @@ -125,7 +125,7 @@ class InstapaperImport extends AbstractImport $entry->setTitle($importedEntry['title']); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $importedEntry['url'], $importedEntry); + $this->fetchContent($entry, $importedEntry['url'], $importedEntry); if (!empty($importedEntry['tags'])) { $this->tagsAssigner->assignTagsToEntry( diff --git a/src/Wallabag/ImportBundle/Import/PinboardImport.php b/src/Wallabag/ImportBundle/Import/PinboardImport.php index 489b9257..110b0464 100644 --- a/src/Wallabag/ImportBundle/Import/PinboardImport.php +++ b/src/Wallabag/ImportBundle/Import/PinboardImport.php @@ -109,7 +109,7 @@ class PinboardImport extends AbstractImport $entry->setTitle($data['title']); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $data['url'], $data); + $this->fetchContent($entry, $data['url'], $data); if (!empty($data['tags'])) { $this->tagsAssigner->assignTagsToEntry( diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 8835161b..c1d5b6da 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -192,7 +192,7 @@ class PocketImport extends AbstractImport $entry->setUrl($url); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $url); + $this->fetchContent($entry, $url); // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); diff --git a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php index de320d23..002b27f4 100644 --- a/src/Wallabag/ImportBundle/Import/ReadabilityImport.php +++ b/src/Wallabag/ImportBundle/Import/ReadabilityImport.php @@ -109,7 +109,7 @@ class ReadabilityImport extends AbstractImport $entry->setTitle($data['title']); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $data['url'], $data); + $this->fetchContent($entry, $data['url'], $data); $entry->setArchived($data['is_archived']); $entry->setStarred($data['is_starred']); diff --git a/src/Wallabag/ImportBundle/Import/WallabagImport.php b/src/Wallabag/ImportBundle/Import/WallabagImport.php index 0e5382cf..c64ccd64 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagImport.php +++ b/src/Wallabag/ImportBundle/Import/WallabagImport.php @@ -108,7 +108,7 @@ abstract class WallabagImport extends AbstractImport $entry->setTitle($data['title']); // update entry with content (in case fetching failed, the given entry will be return) - $entry = $this->fetchContent($entry, $data['url'], $data); + $this->fetchContent($entry, $data['url'], $data); if (array_key_exists('tags', $data)) { $this->tagsAssigner->assignTagsToEntry( -- cgit v1.2.3 From d0e9b3d640acce49068d1a2c5603b92c1bda363e Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Wed, 7 Dec 2016 15:16:49 -0500 Subject: 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. --- .../ImportBundle/Command/ImportCommand.php | 4 ++- .../ImportBundle/Import/AbstractImport.php | 29 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index ce72837a..bca800e6 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -5,6 +5,7 @@ namespace Wallabag\ImportBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -19,7 +20,7 @@ class ImportCommand extends ContainerAwareCommand ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) - ->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false) + ->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL') ; } @@ -69,6 +70,7 @@ class ImportCommand extends ContainerAwareCommand } $import->setMarkAsRead($input->getOption('markAsRead')); + $import->setDisableContentUpdate($input->getOption('disableContentUpdate')); $import->setUser($user); $res = $import diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index fc462c4c..167853aa 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -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(), + ]); } } -- cgit v1.2.3 From 704803e182068923eba16f3dc451e9231f15ecb5 Mon Sep 17 00:00:00 2001 From: Jerome Charaoui Date: Fri, 16 Dec 2016 09:46:21 -0500 Subject: Replace Wallabag v1 error strings with v2 strings --- src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 18 +++++++++++++++--- .../ImportBundle/Resources/config/services.yml | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 59e3ce02..872fd642 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -4,6 +4,17 @@ namespace Wallabag\ImportBundle\Import; class WallabagV1Import extends WallabagImport { + protected $fetchingErrorMessage; + protected $fetchingErrorMessageTitle; + + public function __construct($em, $contentProxy, $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage) + { + $this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle; + $this->fetchingErrorMessage = $fetchingErrorMessage; + + parent::__construct($em, $contentProxy, $eventDispatcher); + } + /** * {@inheritdoc} */ @@ -43,10 +54,11 @@ class WallabagV1Import extends WallabagImport 'created_at' => '', ]; - // force content to be refreshed in case on bad fetch in the v1 installation + // In case of a bad fetch in v1, replace title and content with v2 error strings + // If fetching fails again, they will get this instead of the v1 strings if (in_array($entry['title'], $this->untitled)) { - $data['title'] = ''; - $data['html'] = ''; + $data['title'] = $this->fetchingErrorMessageTitle; + $data['html'] = $this->fetchingErrorMessage; } if (array_key_exists('tags', $entry) && $entry['tags'] != '') { diff --git a/src/Wallabag/ImportBundle/Resources/config/services.yml b/src/Wallabag/ImportBundle/Resources/config/services.yml index 661dc7e1..b224a6a2 100644 --- a/src/Wallabag/ImportBundle/Resources/config/services.yml +++ b/src/Wallabag/ImportBundle/Resources/config/services.yml @@ -35,6 +35,8 @@ services: - "@wallabag_core.content_proxy" - "@wallabag_core.tags_assigner" - "@event_dispatcher" + - "%wallabag_core.fetching_error_message_title%" + - "%wallabag_core.fetching_error_message%" calls: - [ setLogger, [ "@logger" ]] tags: -- cgit v1.2.3 From 432a24f5028446f1bc5c184905f8406bbef8bf05 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 16:21:25 +0200 Subject: CS --- src/Wallabag/ImportBundle/Import/AbstractImport.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 167853aa..1f904292 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -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) { @@ -105,7 +105,6 @@ abstract class AbstractImport implements ImportInterface 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). -- cgit v1.2.3 From d5c2cc54b5490b0bec46f39d7706d5d46869e872 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Tue, 30 May 2017 17:48:24 +0200 Subject: Fix tests --- src/Wallabag/ImportBundle/Command/ImportCommand.php | 1 + src/Wallabag/ImportBundle/Import/AbstractImport.php | 5 ++++- src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index bca800e6..0829a1da 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -20,6 +20,7 @@ class ImportCommand extends ContainerAwareCommand ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) + ->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false) ->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL') ; } diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 1f904292..bf568a1a 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -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; @@ -115,6 +115,9 @@ abstract class AbstractImport implements ImportInterface */ protected function fetchContent(Entry $entry, $url, array $content = []) { + // be sure to set at least the given url + $content['url'] = isset($content['url']) ? $content['url'] : $url; + try { $this->contentProxy->importEntry($entry, $content, $this->disableContentUpdate); } catch (\Exception $e) { diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 872fd642..1f0df646 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -7,12 +7,12 @@ class WallabagV1Import extends WallabagImport protected $fetchingErrorMessage; protected $fetchingErrorMessageTitle; - public function __construct($em, $contentProxy, $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage) + public function __construct($em, $contentProxy, $tagsAssigner, $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage) { $this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle; $this->fetchingErrorMessage = $fetchingErrorMessage; - parent::__construct($em, $contentProxy, $eventDispatcher); + parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher); } /** -- cgit v1.2.3 From 6acadf8e98cf6021a9019773df75bdb151865687 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 11:31:45 +0200 Subject: Rewrote code & fix tests --- src/Wallabag/ImportBundle/Import/AbstractImport.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index bf568a1a..9f3d822a 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -115,14 +115,11 @@ abstract class AbstractImport implements ImportInterface */ protected function fetchContent(Entry $entry, $url, array $content = []) { - // be sure to set at least the given url - $content['url'] = isset($content['url']) ? $content['url'] : $url; - 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(), ]); } -- cgit v1.2.3 From 701d3066fbac504beb25ab7a13546ad155e65488 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 12:46:07 +0200 Subject: We don't need that getter --- src/Wallabag/ImportBundle/Import/AbstractImport.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 9f3d822a..9b624296 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -97,14 +97,6 @@ abstract class AbstractImport implements ImportInterface 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). -- cgit v1.2.3 From f5924e954730efdb7b9fadf23c0b73b3f5a0a434 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 1 Jun 2017 15:44:36 +0200 Subject: Fix option attributes --- src/Wallabag/ImportBundle/Command/ImportCommand.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index 0829a1da..5f1ab0af 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -18,9 +18,9 @@ class ImportCommand extends ContainerAwareCommand ->setDescription('Import entries from a JSON export') ->addArgument('username', InputArgument::REQUIRED, 'User to populate') ->addArgument('filepath', InputArgument::REQUIRED, 'Path to the JSON file') - ->addOption('importer', null, InputArgument::OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') - ->addOption('markAsRead', null, InputArgument::OPTIONAL, 'Mark all entries as read', false) - ->addOption('useUserId', null, InputArgument::OPTIONAL, 'Use user id instead of username to find account', false) + ->addOption('importer', null, InputOption::VALUE_OPTIONAL, 'The importer to use: v1, v2, instapaper, pinboard, readability, firefox or chrome', 'v1') + ->addOption('markAsRead', null, InputOption::VALUE_OPTIONAL, 'Mark all entries as read', false) + ->addOption('useUserId', null, InputOption::VALUE_NONE, 'Use user id instead of username to find account') ->addOption('disableContentUpdate', null, InputOption::VALUE_NONE, 'Disable fetching updated content from URL') ; } -- cgit v1.2.3 From f808b01692a835673f328d7221ba8c212caa9b61 Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Sat, 1 Jul 2017 09:52:38 +0200 Subject: Add a real configuration for CS-Fixer --- .../ImportBundle/Command/ImportCommand.php | 10 +- .../ImportBundle/Command/RedisWorkerCommand.php | 12 +- .../ImportBundle/Consumer/AbstractConsumer.php | 10 +- .../ImportBundle/Controller/BrowserController.php | 43 +++--- .../ImportBundle/Controller/ChromeController.php | 16 +-- .../ImportBundle/Controller/FirefoxController.php | 16 +-- .../ImportBundle/Controller/ImportController.php | 6 +- .../Controller/InstapaperController.php | 20 +-- .../ImportBundle/Controller/PinboardController.php | 20 +-- .../ImportBundle/Controller/PocketController.php | 46 +++---- .../Controller/ReadabilityController.php | 20 +-- .../ImportBundle/Controller/WallabagController.php | 46 +++---- .../Controller/WallabagV1Controller.php | 16 +-- .../Controller/WallabagV2Controller.php | 16 +-- .../WallabagImportExtension.php | 6 +- .../ImportBundle/Form/Type/UploadImportType.php | 6 +- .../ImportBundle/Import/AbstractImport.php | 52 +++---- src/Wallabag/ImportBundle/Import/BrowserImport.php | 150 ++++++++++----------- src/Wallabag/ImportBundle/Import/ChromeImport.php | 2 +- src/Wallabag/ImportBundle/Import/FirefoxImport.php | 2 +- .../ImportBundle/Import/ImportCompilerPass.php | 2 +- .../ImportBundle/Import/InstapaperImport.php | 2 +- src/Wallabag/ImportBundle/Import/PocketImport.php | 13 +- .../ImportBundle/Import/WallabagV1Import.php | 4 +- src/Wallabag/ImportBundle/Redis/Producer.php | 2 +- src/Wallabag/ImportBundle/WallabagImportBundle.php | 2 +- 26 files changed, 269 insertions(+), 271 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index 5f1ab0af..99056c2c 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php @@ -5,8 +5,8 @@ namespace Wallabag\ImportBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ImportCommand extends ContainerAwareCommand @@ -27,7 +27,7 @@ class ImportCommand extends ContainerAwareCommand protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); + $output->writeln('Start : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---'); if (!file_exists($input->getArgument('filepath'))) { throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath'))); @@ -80,12 +80,12 @@ class ImportCommand extends ContainerAwareCommand if (true === $res) { $summary = $import->getSummary(); - $output->writeln(''.$summary['imported'].' imported'); - $output->writeln(''.$summary['skipped'].' already saved'); + $output->writeln('' . $summary['imported'] . ' imported'); + $output->writeln('' . $summary['skipped'] . ' already saved'); } $em->clear(); - $output->writeln('End : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); + $output->writeln('End : ' . (new \DateTime())->format('d-m-Y G:i:s') . ' ---'); } } diff --git a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php index 2d06af44..d94900ad 100644 --- a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php +++ b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php @@ -2,13 +2,13 @@ namespace Wallabag\ImportBundle\Command; +use Simpleue\Worker\QueueWorker; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Config\Definition\Exception\Exception; use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Simpleue\Worker\QueueWorker; class RedisWorkerCommand extends ContainerAwareCommand { @@ -24,18 +24,18 @@ class RedisWorkerCommand extends ContainerAwareCommand protected function execute(InputInterface $input, OutputInterface $output) { - $output->writeln('Worker started at: '.(new \DateTime())->format('d-m-Y G:i:s')); + $output->writeln('Worker started at: ' . (new \DateTime())->format('d-m-Y G:i:s')); $output->writeln('Waiting for message ...'); $serviceName = $input->getArgument('serviceName'); - if (!$this->getContainer()->has('wallabag_import.queue.redis.'.$serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.'.$serviceName)) { + if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) { throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName'))); } $worker = new QueueWorker( - $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName), - $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName), + $this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName), + $this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName), (int) $input->getOption('maxIterations') ); diff --git a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php index 992ce1ad..b035f5cc 100644 --- a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php +++ b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php @@ -3,14 +3,14 @@ namespace Wallabag\ImportBundle\Consumer; use Doctrine\ORM\EntityManager; -use Wallabag\ImportBundle\Import\AbstractImport; -use Wallabag\UserBundle\Repository\UserRepository; -use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\CoreBundle\Entity\Tag; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\ImportBundle\Import\AbstractImport; +use Wallabag\UserBundle\Repository\UserRepository; abstract class AbstractConsumer { @@ -76,7 +76,7 @@ abstract class AbstractConsumer return false; } - $this->logger->info('Content with url imported! ('.$entry->getUrl().')'); + $this->logger->info('Content with url imported! (' . $entry->getUrl() . ')'); return true; } diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php index e119098f..0753e318 100644 --- a/src/Wallabag/ImportBundle/Controller/BrowserController.php +++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php @@ -2,28 +2,14 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Wallabag\ImportBundle\Form\Type\UploadImportType; abstract class BrowserController extends Controller { - /** - * Return the service to handle the import. - * - * @return \Wallabag\ImportBundle\Import\ImportInterface - */ - abstract protected function getImportService(); - - /** - * Return the template used for the form. - * - * @return string - */ - abstract protected function getImportTemplate(); - /** * @Route("/browser", name="import_browser") * @@ -42,11 +28,11 @@ abstract class BrowserController extends Controller if ($form->isSubmitted() && $form->isValid()) { $file = $form->get('file')->getData(); $markAsRead = $form->get('mark_as_read')->getData(); - $name = $this->getUser()->getId().'.json'; + $name = $this->getUser()->getId() . '.json'; - if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { + if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { $res = $wallabag - ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) + ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name) ->setMarkAsRead($markAsRead) ->import(); @@ -65,7 +51,7 @@ abstract class BrowserController extends Controller ]); } - unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name); } $this->get('session')->getFlashBag()->add( @@ -74,12 +60,11 @@ abstract class BrowserController extends Controller ); return $this->redirect($this->generateUrl('homepage')); - } else { - $this->get('session')->getFlashBag()->add( + } + $this->get('session')->getFlashBag()->add( 'notice', 'flashes.import.notice.failed_on_file' ); - } } return $this->render($this->getImportTemplate(), [ @@ -87,4 +72,18 @@ abstract class BrowserController extends Controller 'import' => $wallabag, ]); } + + /** + * Return the service to handle the import. + * + * @return \Wallabag\ImportBundle\Import\ImportInterface + */ + abstract protected function getImportService(); + + /** + * Return the template used for the form. + * + * @return string + */ + abstract protected function getImportTemplate(); } diff --git a/src/Wallabag/ImportBundle/Controller/ChromeController.php b/src/Wallabag/ImportBundle/Controller/ChromeController.php index 454f3347..0cb418a1 100644 --- a/src/Wallabag/ImportBundle/Controller/ChromeController.php +++ b/src/Wallabag/ImportBundle/Controller/ChromeController.php @@ -7,6 +7,14 @@ use Symfony\Component\HttpFoundation\Request; class ChromeController extends BrowserController { + /** + * @Route("/chrome", name="import_chrome") + */ + public function indexAction(Request $request) + { + return parent::indexAction($request); + } + /** * {@inheritdoc} */ @@ -30,12 +38,4 @@ class ChromeController extends BrowserController { return 'WallabagImportBundle:Chrome:index.html.twig'; } - - /** - * @Route("/chrome", name="import_chrome") - */ - public function indexAction(Request $request) - { - return parent::indexAction($request); - } } diff --git a/src/Wallabag/ImportBundle/Controller/FirefoxController.php b/src/Wallabag/ImportBundle/Controller/FirefoxController.php index c329b9c4..88697f9d 100644 --- a/src/Wallabag/ImportBundle/Controller/FirefoxController.php +++ b/src/Wallabag/ImportBundle/Controller/FirefoxController.php @@ -7,6 +7,14 @@ use Symfony\Component\HttpFoundation\Request; class FirefoxController extends BrowserController { + /** + * @Route("/firefox", name="import_firefox") + */ + public function indexAction(Request $request) + { + return parent::indexAction($request); + } + /** * {@inheritdoc} */ @@ -30,12 +38,4 @@ class FirefoxController extends BrowserController { return 'WallabagImportBundle:Firefox:index.html.twig'; } - - /** - * @Route("/firefox", name="import_firefox") - */ - public function indexAction(Request $request) - { - return parent::indexAction($request); - } } diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php index 237c748e..7e4fd174 100644 --- a/src/Wallabag/ImportBundle/Controller/ImportController.php +++ b/src/Wallabag/ImportBundle/Controller/ImportController.php @@ -2,8 +2,8 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; class ImportController extends Controller { @@ -86,9 +86,9 @@ class ImportController extends Controller private function getTotalMessageInRabbitQueue($importService) { $message = $this - ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer') + ->get('old_sound_rabbit_mq.import_' . $importService . '_consumer') ->getChannel() - ->basic_get('wallabag.import.'.$importService); + ->basic_get('wallabag.import.' . $importService); if (null === $message) { return 0; diff --git a/src/Wallabag/ImportBundle/Controller/InstapaperController.php b/src/Wallabag/ImportBundle/Controller/InstapaperController.php index 0251acb9..550679c3 100644 --- a/src/Wallabag/ImportBundle/Controller/InstapaperController.php +++ b/src/Wallabag/ImportBundle/Controller/InstapaperController.php @@ -2,8 +2,8 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\ImportBundle\Form\Type\UploadImportType; @@ -29,11 +29,11 @@ class InstapaperController extends Controller if ($form->isSubmitted() && $form->isValid()) { $file = $form->get('file')->getData(); $markAsRead = $form->get('mark_as_read')->getData(); - $name = 'instapaper_'.$this->getUser()->getId().'.csv'; + $name = 'instapaper_' . $this->getUser()->getId() . '.csv'; - if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { + if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { $res = $instapaper - ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) + ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name) ->setMarkAsRead($markAsRead) ->import(); @@ -52,7 +52,7 @@ class InstapaperController extends Controller ]); } - unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name); } $this->get('session')->getFlashBag()->add( @@ -61,12 +61,12 @@ class InstapaperController extends Controller ); return $this->redirect($this->generateUrl('homepage')); - } else { - $this->get('session')->getFlashBag()->add( - 'notice', - 'flashes.import.notice.failed_on_file' - ); } + + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.import.notice.failed_on_file' + ); } return $this->render('WallabagImportBundle:Instapaper:index.html.twig', [ diff --git a/src/Wallabag/ImportBundle/Controller/PinboardController.php b/src/Wallabag/ImportBundle/Controller/PinboardController.php index d0ad8aa8..0e57fd41 100644 --- a/src/Wallabag/ImportBundle/Controller/PinboardController.php +++ b/src/Wallabag/ImportBundle/Controller/PinboardController.php @@ -2,8 +2,8 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\ImportBundle\Form\Type\UploadImportType; @@ -29,11 +29,11 @@ class PinboardController extends Controller if ($form->isSubmitted() && $form->isValid()) { $file = $form->get('file')->getData(); $markAsRead = $form->get('mark_as_read')->getData(); - $name = 'pinboard_'.$this->getUser()->getId().'.json'; + $name = 'pinboard_' . $this->getUser()->getId() . '.json'; - if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { + if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { $res = $pinboard - ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) + ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name) ->setMarkAsRead($markAsRead) ->import(); @@ -52,7 +52,7 @@ class PinboardController extends Controller ]); } - unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name); } $this->get('session')->getFlashBag()->add( @@ -61,12 +61,12 @@ class PinboardController extends Controller ); return $this->redirect($this->generateUrl('homepage')); - } else { - $this->get('session')->getFlashBag()->add( - 'notice', - 'flashes.import.notice.failed_on_file' - ); } + + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.import.notice.failed_on_file' + ); } return $this->render('WallabagImportBundle:Pinboard:index.html.twig', [ diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index 56be5cbf..9f28819a 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -2,33 +2,14 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; -use Symfony\Component\HttpFoundation\Request; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class PocketController extends Controller { - /** - * Return Pocket Import Service with or without RabbitMQ enabled. - * - * @return \Wallabag\ImportBundle\Import\PocketImport - */ - private function getPocketImportService() - { - $pocket = $this->get('wallabag_import.pocket.import'); - $pocket->setUser($this->getUser()); - - if ($this->get('craue_config')->get('import_with_rabbitmq')) { - $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer')); - } elseif ($this->get('craue_config')->get('import_with_redis')) { - $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket')); - } - - return $pocket; - } - /** * @Route("/pocket", name="import_pocket") */ @@ -70,7 +51,7 @@ class PocketController extends Controller $this->get('session')->set('mark_as_read', $request->request->get('form')['mark_as_read']); return $this->redirect( - 'https://getpocket.com/auth/authorize?request_token='.$requestToken.'&redirect_uri='.$this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL), + 'https://getpocket.com/auth/authorize?request_token=' . $requestToken . '&redirect_uri=' . $this->generateUrl('import_pocket_callback', [], UrlGeneratorInterface::ABSOLUTE_URL), 301 ); } @@ -117,4 +98,23 @@ class PocketController extends Controller return $this->redirect($this->generateUrl('homepage')); } + + /** + * Return Pocket Import Service with or without RabbitMQ enabled. + * + * @return \Wallabag\ImportBundle\Import\PocketImport + */ + private function getPocketImportService() + { + $pocket = $this->get('wallabag_import.pocket.import'); + $pocket->setUser($this->getUser()); + + if ($this->get('craue_config')->get('import_with_rabbitmq')) { + $pocket->setProducer($this->get('old_sound_rabbit_mq.import_pocket_producer')); + } elseif ($this->get('craue_config')->get('import_with_redis')) { + $pocket->setProducer($this->get('wallabag_import.producer.redis.pocket')); + } + + return $pocket; + } } diff --git a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php index aa732ddd..59de24cb 100644 --- a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php +++ b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php @@ -2,8 +2,8 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Wallabag\ImportBundle\Form\Type\UploadImportType; @@ -29,11 +29,11 @@ class ReadabilityController extends Controller if ($form->isSubmitted() && $form->isValid()) { $file = $form->get('file')->getData(); $markAsRead = $form->get('mark_as_read')->getData(); - $name = 'readability_'.$this->getUser()->getId().'.json'; + $name = 'readability_' . $this->getUser()->getId() . '.json'; - if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { + if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { $res = $readability - ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) + ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name) ->setMarkAsRead($markAsRead) ->import(); @@ -52,7 +52,7 @@ class ReadabilityController extends Controller ]); } - unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name); } $this->get('session')->getFlashBag()->add( @@ -61,12 +61,12 @@ class ReadabilityController extends Controller ); return $this->redirect($this->generateUrl('homepage')); - } else { - $this->get('session')->getFlashBag()->add( - 'notice', - 'flashes.import.notice.failed_on_file' - ); } + + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.import.notice.failed_on_file' + ); } return $this->render('WallabagImportBundle:Readability:index.html.twig', [ diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php index e81c1ca9..7b61805b 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagController.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php @@ -11,20 +11,6 @@ use Wallabag\ImportBundle\Form\Type\UploadImportType; */ abstract class WallabagController extends Controller { - /** - * Return the service to handle the import. - * - * @return \Wallabag\ImportBundle\Import\ImportInterface - */ - abstract protected function getImportService(); - - /** - * Return the template used for the form. - * - * @return string - */ - abstract protected function getImportTemplate(); - /** * Handle import request. * @@ -43,11 +29,11 @@ abstract class WallabagController extends Controller if ($form->isSubmitted() && $form->isValid()) { $file = $form->get('file')->getData(); $markAsRead = $form->get('mark_as_read')->getData(); - $name = $this->getUser()->getId().'.json'; + $name = $this->getUser()->getId() . '.json'; - if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes')) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { + if (null !== $file && in_array($file->getClientMimeType(), $this->getParameter('wallabag_import.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_import.resource_dir'), $name)) { $res = $wallabag - ->setFilepath($this->getParameter('wallabag_import.resource_dir').'/'.$name) + ->setFilepath($this->getParameter('wallabag_import.resource_dir') . '/' . $name) ->setMarkAsRead($markAsRead) ->import(); @@ -66,7 +52,7 @@ abstract class WallabagController extends Controller ]); } - unlink($this->getParameter('wallabag_import.resource_dir').'/'.$name); + unlink($this->getParameter('wallabag_import.resource_dir') . '/' . $name); } $this->get('session')->getFlashBag()->add( @@ -75,12 +61,12 @@ abstract class WallabagController extends Controller ); return $this->redirect($this->generateUrl('homepage')); - } else { - $this->get('session')->getFlashBag()->add( - 'notice', - 'flashes.import.notice.failed_on_file' - ); } + + $this->get('session')->getFlashBag()->add( + 'notice', + 'flashes.import.notice.failed_on_file' + ); } return $this->render($this->getImportTemplate(), [ @@ -88,4 +74,18 @@ abstract class WallabagController extends Controller 'import' => $wallabag, ]); } + + /** + * Return the service to handle the import. + * + * @return \Wallabag\ImportBundle\Import\ImportInterface + */ + abstract protected function getImportService(); + + /** + * Return the template used for the form. + * + * @return string + */ + abstract protected function getImportTemplate(); } diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php index 312c7a35..d700d8a8 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV1Controller.php @@ -7,6 +7,14 @@ use Symfony\Component\HttpFoundation\Request; class WallabagV1Controller extends WallabagController { + /** + * @Route("/wallabag-v1", name="import_wallabag_v1") + */ + public function indexAction(Request $request) + { + return parent::indexAction($request); + } + /** * {@inheritdoc} */ @@ -30,12 +38,4 @@ class WallabagV1Controller extends WallabagController { return 'WallabagImportBundle:WallabagV1:index.html.twig'; } - - /** - * @Route("/wallabag-v1", name="import_wallabag_v1") - */ - public function indexAction(Request $request) - { - return parent::indexAction($request); - } } diff --git a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php index 45211fe6..ab26400c 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagV2Controller.php @@ -7,6 +7,14 @@ use Symfony\Component\HttpFoundation\Request; class WallabagV2Controller extends WallabagController { + /** + * @Route("/wallabag-v2", name="import_wallabag_v2") + */ + public function indexAction(Request $request) + { + return parent::indexAction($request); + } + /** * {@inheritdoc} */ @@ -30,12 +38,4 @@ class WallabagV2Controller extends WallabagController { return 'WallabagImportBundle:WallabagV2:index.html.twig'; } - - /** - * @Route("/wallabag-v2", name="import_wallabag_v2") - */ - public function indexAction(Request $request) - { - return parent::indexAction($request); - } } diff --git a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php index 3f23c36b..cab70297 100644 --- a/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php +++ b/src/Wallabag/ImportBundle/DependencyInjection/WallabagImportExtension.php @@ -2,10 +2,10 @@ namespace Wallabag\ImportBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; class WallabagImportExtension extends Extension { @@ -16,7 +16,7 @@ class WallabagImportExtension extends Extension $container->setParameter('wallabag_import.allow_mimetypes', $config['allow_mimetypes']); $container->setParameter('wallabag_import.resource_dir', $config['resource_dir']); - $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yml'); } diff --git a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php index f50424c1..c50ef8c9 100644 --- a/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php +++ b/src/Wallabag/ImportBundle/Form/Type/UploadImportType.php @@ -3,10 +3,10 @@ namespace Wallabag\ImportBundle\Form\Type; use Symfony\Component\Form\AbstractType; -use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Form\Extension\Core\Type\SubmitType; -use Symfony\Component\Form\Extension\Core\Type\FileType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; +use Symfony\Component\Form\Extension\Core\Type\FileType; +use Symfony\Component\Form\Extension\Core\Type\SubmitType; +use Symfony\Component\Form\FormBuilderInterface; class UploadImportType extends AbstractType { diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index 9b624296..cb46db09 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -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 { @@ -97,6 +97,27 @@ abstract class AbstractImport implements ImportInterface return $this; } + /** + * {@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); + /** * 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). @@ -195,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. diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 71e65e59..f1195824 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -3,8 +3,8 @@ namespace Wallabag\ImportBundle\Import; use Wallabag\CoreBundle\Entity\Entry; -use Wallabag\UserBundle\Entity\User; use Wallabag\CoreBundle\Event\EntrySavedEvent; +use Wallabag\UserBundle\Entity\User; abstract class BrowserImport extends AbstractImport { @@ -73,6 +73,80 @@ abstract class BrowserImport extends AbstractImport return $this; } + /** + * {@inheritdoc} + */ + public function parseEntry(array $importedEntry) + { + if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { + if ($this->producer) { + $this->parseEntriesForProducer($importedEntry); + + return; + } + + $this->parseEntries($importedEntry); + + return; + } + + if (array_key_exists('children', $importedEntry)) { + if ($this->producer) { + $this->parseEntriesForProducer($importedEntry['children']); + + return; + } + + $this->parseEntries($importedEntry['children']); + + return; + } + + if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { + return; + } + + $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; + + $existingEntry = $this->em + ->getRepository('WallabagCoreBundle:Entry') + ->findByUrlAndUserId($url, $this->user->getId()); + + if (false !== $existingEntry) { + ++$this->skippedEntries; + + return; + } + + $data = $this->prepareEntry($importedEntry); + + $entry = new Entry($this->user); + $entry->setUrl($data['url']); + $entry->setTitle($data['title']); + + // update entry with content (in case fetching failed, the given entry will be return) + $this->fetchContent($entry, $data['url'], $data); + + if (array_key_exists('tags', $data)) { + $this->tagsAssigner->assignTagsToEntry( + $entry, + $data['tags'] + ); + } + + $entry->setArchived($data['is_archived']); + + if (!empty($data['created_at'])) { + $dt = new \DateTime(); + $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); + } + + $this->em->persist($entry); + ++$this->importedEntries; + + return $entry; + } + /** * Parse and insert all given entries. * @@ -149,80 +223,6 @@ abstract class BrowserImport extends AbstractImport } } - /** - * {@inheritdoc} - */ - public function parseEntry(array $importedEntry) - { - if ((!array_key_exists('guid', $importedEntry) || (!array_key_exists('id', $importedEntry))) && is_array(reset($importedEntry))) { - if ($this->producer) { - $this->parseEntriesForProducer($importedEntry); - - return; - } - - $this->parseEntries($importedEntry); - - return; - } - - if (array_key_exists('children', $importedEntry)) { - if ($this->producer) { - $this->parseEntriesForProducer($importedEntry['children']); - - return; - } - - $this->parseEntries($importedEntry['children']); - - return; - } - - if (!array_key_exists('uri', $importedEntry) && !array_key_exists('url', $importedEntry)) { - return; - } - - $url = array_key_exists('uri', $importedEntry) ? $importedEntry['uri'] : $importedEntry['url']; - - $existingEntry = $this->em - ->getRepository('WallabagCoreBundle:Entry') - ->findByUrlAndUserId($url, $this->user->getId()); - - if (false !== $existingEntry) { - ++$this->skippedEntries; - - return; - } - - $data = $this->prepareEntry($importedEntry); - - $entry = new Entry($this->user); - $entry->setUrl($data['url']); - $entry->setTitle($data['title']); - - // update entry with content (in case fetching failed, the given entry will be return) - $this->fetchContent($entry, $data['url'], $data); - - if (array_key_exists('tags', $data)) { - $this->tagsAssigner->assignTagsToEntry( - $entry, - $data['tags'] - ); - } - - $entry->setArchived($data['is_archived']); - - if (!empty($data['created_at'])) { - $dt = new \DateTime(); - $entry->setCreatedAt($dt->setTimestamp($data['created_at'])); - } - - $this->em->persist($entry); - ++$this->importedEntries; - - return $entry; - } - /** * {@inheritdoc} */ diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index 2667890f..e3ba636a 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -45,7 +45,7 @@ class ChromeImport extends BrowserImport 'created_at' => substr($entry['date_added'], 0, 10), ]; - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { $data['tags'] = $entry['tags']; } diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index c50c69b3..c18e7e93 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -45,7 +45,7 @@ class FirefoxImport extends BrowserImport 'created_at' => substr($entry['dateAdded'], 0, 10), ]; - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { $data['tags'] = $entry['tags']; } diff --git a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php index a363a566..d7df0a83 100644 --- a/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php +++ b/src/Wallabag/ImportBundle/Import/ImportCompilerPass.php @@ -2,8 +2,8 @@ namespace Wallabag\ImportBundle\Import; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; class ImportCompilerPass implements CompilerPassInterface diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index 3aa12f6f..7d70154a 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php @@ -72,7 +72,7 @@ class InstapaperImport extends AbstractImport // BUT it can also be the status (since status = folder in Instapaper) // and we don't want archive, unread & starred to become a tag $tags = null; - if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'])) { + if (false === in_array($data[3], ['Archive', 'Unread', 'Starred'], true)) { $tags = [$data[3]]; } diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index c1d5b6da..7d38826b 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -8,11 +8,10 @@ use Wallabag\CoreBundle\Entity\Entry; class PocketImport extends AbstractImport { + const NB_ELEMENTS = 5000; private $client; private $accessToken; - const NB_ELEMENTS = 5000; - /** * Only used for test purpose. * @@ -176,7 +175,7 @@ class PocketImport extends AbstractImport */ public function parseEntry(array $importedEntry) { - $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] != '' ? $importedEntry['resolved_url'] : $importedEntry['given_url']; + $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] !== '' ? $importedEntry['resolved_url'] : $importedEntry['given_url']; $existingEntry = $this->em ->getRepository('WallabagCoreBundle:Entry') @@ -195,15 +194,15 @@ class PocketImport extends AbstractImport $this->fetchContent($entry, $url); // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted - $entry->setArchived($importedEntry['status'] == 1 || $this->markAsRead); + $entry->setArchived($importedEntry['status'] === 1 || $this->markAsRead); // 0 or 1 - 1 If the item is starred - $entry->setStarred($importedEntry['favorite'] == 1); + $entry->setStarred($importedEntry['favorite'] === 1); $title = 'Untitled'; - if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] != '') { + if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] !== '') { $title = $importedEntry['resolved_title']; - } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] != '') { + } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] !== '') { $title = $importedEntry['given_title']; } diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index 1f0df646..d585d44d 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -56,12 +56,12 @@ class WallabagV1Import extends WallabagImport // In case of a bad fetch in v1, replace title and content with v2 error strings // If fetching fails again, they will get this instead of the v1 strings - if (in_array($entry['title'], $this->untitled)) { + if (in_array($entry['title'], $this->untitled, true)) { $data['title'] = $this->fetchingErrorMessageTitle; $data['html'] = $this->fetchingErrorMessage; } - if (array_key_exists('tags', $entry) && $entry['tags'] != '') { + if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { $data['tags'] = $entry['tags']; } diff --git a/src/Wallabag/ImportBundle/Redis/Producer.php b/src/Wallabag/ImportBundle/Redis/Producer.php index fedc3e57..c77b5174 100644 --- a/src/Wallabag/ImportBundle/Redis/Producer.php +++ b/src/Wallabag/ImportBundle/Redis/Producer.php @@ -29,7 +29,7 @@ class Producer implements ProducerInterface * @param string $routingKey NOT USED * @param array $additionalProperties NOT USED */ - public function publish($msgBody, $routingKey = '', $additionalProperties = array()) + public function publish($msgBody, $routingKey = '', $additionalProperties = []) { $this->queue->sendJob($msgBody); } diff --git a/src/Wallabag/ImportBundle/WallabagImportBundle.php b/src/Wallabag/ImportBundle/WallabagImportBundle.php index a5ddc1b4..98c2f97b 100644 --- a/src/Wallabag/ImportBundle/WallabagImportBundle.php +++ b/src/Wallabag/ImportBundle/WallabagImportBundle.php @@ -2,8 +2,8 @@ namespace Wallabag\ImportBundle; -use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\HttpKernel\Bundle\Bundle; use Wallabag\ImportBundle\Import\ImportCompilerPass; class WallabagImportBundle extends Bundle -- cgit v1.2.3 From 459374022f39977656cc393e6313b85e3e60cfbb Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 24 Jul 2017 11:52:43 +0200 Subject: CS --- src/Wallabag/ImportBundle/Controller/BrowserController.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php index 0753e318..77a7a904 100644 --- a/src/Wallabag/ImportBundle/Controller/BrowserController.php +++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php @@ -80,10 +80,10 @@ abstract class BrowserController extends Controller */ abstract protected function getImportService(); - /** - * Return the template used for the form. - * - * @return string - */ - abstract protected function getImportTemplate(); + /** + * Return the template used for the form. + * + * @return string + */ + abstract protected function getImportTemplate(); } -- cgit v1.2.3 From 52b84c11a5b5474cd45271d937a46c6adfdf2749 Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sat, 29 Jul 2017 22:51:50 +0200 Subject: Fix some namespaces and phpdoc --- src/Wallabag/ImportBundle/Controller/WallabagController.php | 2 ++ src/Wallabag/ImportBundle/Import/BrowserImport.php | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php index 7b61805b..6e6524b4 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagController.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php @@ -3,7 +3,9 @@ namespace Wallabag\ImportBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Wallabag\ImportBundle\Form\Type\UploadImportType; /** diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index f1195824..1628cb47 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -4,7 +4,6 @@ namespace Wallabag\ImportBundle\Import; use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Event\EntrySavedEvent; -use Wallabag\UserBundle\Entity\User; abstract class BrowserImport extends AbstractImport { -- cgit v1.2.3 From fe312015d2902dcc2e08b02ab4307da5c206217a Mon Sep 17 00:00:00 2001 From: Nicolas Hart Date: Sat, 29 Jul 2017 22:59:11 +0200 Subject: Add missing abstract method prepareEntry in BrowserImport --- src/Wallabag/ImportBundle/Import/BrowserImport.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index f1195824..4d3073b7 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -232,4 +232,6 @@ abstract class BrowserImport extends AbstractImport return $importedEntry; } + + abstract protected function prepareEntry(array $entry = []); } -- cgit v1.2.3 From 3ef055ced3d6ea0d2f15ba660602545f477e9c3c Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 9 Oct 2017 16:47:15 +0200 Subject: CS --- src/Wallabag/ImportBundle/Import/AbstractImport.php | 2 +- src/Wallabag/ImportBundle/Import/BrowserImport.php | 2 +- src/Wallabag/ImportBundle/Import/ChromeImport.php | 2 +- src/Wallabag/ImportBundle/Import/FirefoxImport.php | 2 +- src/Wallabag/ImportBundle/Import/InstapaperImport.php | 6 +++--- src/Wallabag/ImportBundle/Import/PocketImport.php | 12 ++++++------ src/Wallabag/ImportBundle/Import/WallabagV1Import.php | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/Wallabag/ImportBundle') diff --git a/src/Wallabag/ImportBundle/Import/AbstractImport.php b/src/Wallabag/ImportBundle/Import/AbstractImport.php index cb46db09..58a234f4 100644 --- a/src/Wallabag/ImportBundle/Import/AbstractImport.php +++ b/src/Wallabag/ImportBundle/Import/AbstractImport.php @@ -165,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) { diff --git a/src/Wallabag/ImportBundle/Import/BrowserImport.php b/src/Wallabag/ImportBundle/Import/BrowserImport.php index 78077324..b5593180 100644 --- a/src/Wallabag/ImportBundle/Import/BrowserImport.php +++ b/src/Wallabag/ImportBundle/Import/BrowserImport.php @@ -171,7 +171,7 @@ abstract class BrowserImport extends AbstractImport $entryToBeFlushed[] = $entry; // flush every 20 entries - if (($i % 20) === 0) { + if (0 === ($i % 20)) { $this->em->flush(); foreach ($entryToBeFlushed as $entry) { diff --git a/src/Wallabag/ImportBundle/Import/ChromeImport.php b/src/Wallabag/ImportBundle/Import/ChromeImport.php index e3ba636a..09183abe 100644 --- a/src/Wallabag/ImportBundle/Import/ChromeImport.php +++ b/src/Wallabag/ImportBundle/Import/ChromeImport.php @@ -45,7 +45,7 @@ class ChromeImport extends BrowserImport 'created_at' => substr($entry['date_added'], 0, 10), ]; - if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { + if (array_key_exists('tags', $entry) && '' !== $entry['tags']) { $data['tags'] = $entry['tags']; } diff --git a/src/Wallabag/ImportBundle/Import/FirefoxImport.php b/src/Wallabag/ImportBundle/Import/FirefoxImport.php index c18e7e93..73269fe1 100644 --- a/src/Wallabag/ImportBundle/Import/FirefoxImport.php +++ b/src/Wallabag/ImportBundle/Import/FirefoxImport.php @@ -45,7 +45,7 @@ class FirefoxImport extends BrowserImport 'created_at' => substr($entry['dateAdded'], 0, 10), ]; - if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { + if (array_key_exists('tags', $entry) && '' !== $entry['tags']) { $data['tags'] = $entry['tags']; } diff --git a/src/Wallabag/ImportBundle/Import/InstapaperImport.php b/src/Wallabag/ImportBundle/Import/InstapaperImport.php index 7d70154a..7ab69e7a 100644 --- a/src/Wallabag/ImportBundle/Import/InstapaperImport.php +++ b/src/Wallabag/ImportBundle/Import/InstapaperImport.php @@ -63,7 +63,7 @@ class InstapaperImport extends AbstractImport $entries = []; $handle = fopen($this->filepath, 'r'); - while (($data = fgetcsv($handle, 10240)) !== false) { + while (false !== ($data = fgetcsv($handle, 10240))) { if ('URL' === $data[0]) { continue; } @@ -80,8 +80,8 @@ class InstapaperImport extends AbstractImport 'url' => $data[0], 'title' => $data[1], 'status' => $data[3], - 'is_archived' => $data[3] === 'Archive' || $data[3] === 'Starred', - 'is_starred' => $data[3] === 'Starred', + 'is_archived' => 'Archive' === $data[3] || 'Starred' === $data[3], + 'is_starred' => 'Starred' === $data[3], 'html' => false, 'tags' => $tags, ]; diff --git a/src/Wallabag/ImportBundle/Import/PocketImport.php b/src/Wallabag/ImportBundle/Import/PocketImport.php index 7d38826b..dddb87f4 100644 --- a/src/Wallabag/ImportBundle/Import/PocketImport.php +++ b/src/Wallabag/ImportBundle/Import/PocketImport.php @@ -149,7 +149,7 @@ class PocketImport extends AbstractImport // - first call get 5k offset 0 // - second call get 5k offset 5k // - and so on - if (count($entries['list']) === self::NB_ELEMENTS) { + if (self::NB_ELEMENTS === count($entries['list'])) { ++$run; return $this->import(self::NB_ELEMENTS * $run); @@ -175,7 +175,7 @@ class PocketImport extends AbstractImport */ public function parseEntry(array $importedEntry) { - $url = isset($importedEntry['resolved_url']) && $importedEntry['resolved_url'] !== '' ? $importedEntry['resolved_url'] : $importedEntry['given_url']; + $url = isset($importedEntry['resolved_url']) && '' !== $importedEntry['resolved_url'] ? $importedEntry['resolved_url'] : $importedEntry['given_url']; $existingEntry = $this->em ->getRepository('WallabagCoreBundle:Entry') @@ -194,15 +194,15 @@ class PocketImport extends AbstractImport $this->fetchContent($entry, $url); // 0, 1, 2 - 1 if the item is archived - 2 if the item should be deleted - $entry->setArchived($importedEntry['status'] === 1 || $this->markAsRead); + $entry->setArchived(1 === $importedEntry['status'] || $this->markAsRead); // 0 or 1 - 1 If the item is starred - $entry->setStarred($importedEntry['favorite'] === 1); + $entry->setStarred(1 === $importedEntry['favorite']); $title = 'Untitled'; - if (isset($importedEntry['resolved_title']) && $importedEntry['resolved_title'] !== '') { + if (isset($importedEntry['resolved_title']) && '' !== $importedEntry['resolved_title']) { $title = $importedEntry['resolved_title']; - } elseif (isset($importedEntry['given_title']) && $importedEntry['given_title'] !== '') { + } elseif (isset($importedEntry['given_title']) && '' !== $importedEntry['given_title']) { $title = $importedEntry['given_title']; } diff --git a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php index d585d44d..a35c411e 100644 --- a/src/Wallabag/ImportBundle/Import/WallabagV1Import.php +++ b/src/Wallabag/ImportBundle/Import/WallabagV1Import.php @@ -61,7 +61,7 @@ class WallabagV1Import extends WallabagImport $data['html'] = $this->fetchingErrorMessage; } - if (array_key_exists('tags', $entry) && $entry['tags'] !== '') { + if (array_key_exists('tags', $entry) && '' !== $entry['tags']) { $data['tags'] = $entry['tags']; } -- cgit v1.2.3