Pass logger in constructor for importers

This commit is contained in:
Yassine Guedidi 2022-08-27 20:57:18 +02:00
parent 96c8cc25af
commit 51884911f5
10 changed files with 22 additions and 47 deletions

View file

@ -236,7 +236,6 @@ services:
Wallabag\ImportBundle\Import\PocketImport: Wallabag\ImportBundle\Import\PocketImport:
calls: calls:
- [ setClient, [ "@wallabag_import.pocket.client" ] ] - [ setClient, [ "@wallabag_import.pocket.client" ] ]
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: pocket } - { name: wallabag_import.import, alias: pocket }
@ -244,56 +243,38 @@ services:
arguments: arguments:
$fetchingErrorMessageTitle: "%wallabag_core.fetching_error_message_title%" $fetchingErrorMessageTitle: "%wallabag_core.fetching_error_message_title%"
$fetchingErrorMessage: "%wallabag_core.fetching_error_message%" $fetchingErrorMessage: "%wallabag_core.fetching_error_message%"
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: wallabag_v1 } - { name: wallabag_import.import, alias: wallabag_v1 }
Wallabag\ImportBundle\Import\WallabagV2Import: Wallabag\ImportBundle\Import\WallabagV2Import:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: wallabag_v2 } - { name: wallabag_import.import, alias: wallabag_v2 }
Wallabag\ImportBundle\Import\ElcuratorImport: Wallabag\ImportBundle\Import\ElcuratorImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: elcurator } - { name: wallabag_import.import, alias: elcurator }
Wallabag\ImportBundle\Import\ReadabilityImport: Wallabag\ImportBundle\Import\ReadabilityImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: readability } - { name: wallabag_import.import, alias: readability }
Wallabag\ImportBundle\Import\InstapaperImport: Wallabag\ImportBundle\Import\InstapaperImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: instapaper } - { name: wallabag_import.import, alias: instapaper }
Wallabag\ImportBundle\Import\PinboardImport: Wallabag\ImportBundle\Import\PinboardImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: pinboard } - { name: wallabag_import.import, alias: pinboard }
Wallabag\ImportBundle\Import\DeliciousImport: Wallabag\ImportBundle\Import\DeliciousImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: delicious } - { name: wallabag_import.import, alias: delicious }
Wallabag\ImportBundle\Import\FirefoxImport: Wallabag\ImportBundle\Import\FirefoxImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: firefox } - { name: wallabag_import.import, alias: firefox }
Wallabag\ImportBundle\Import\ChromeImport: Wallabag\ImportBundle\Import\ChromeImport:
calls:
- [ setLogger, [ "@logger" ]]
tags: tags:
- { name: wallabag_import.import, alias: chrome } - { name: wallabag_import.import, alias: chrome }

View file

@ -5,7 +5,6 @@ namespace Wallabag\ImportBundle\Import;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface; use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Wallabag\CoreBundle\Entity\Entry; use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag; use Wallabag\CoreBundle\Entity\Tag;
@ -29,10 +28,10 @@ abstract class AbstractImport implements ImportInterface
protected $importedEntries = 0; protected $importedEntries = 0;
protected $queuedEntries = 0; protected $queuedEntries = 0;
public function __construct(EntityManagerInterface $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher) public function __construct(EntityManagerInterface $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger)
{ {
$this->em = $em; $this->em = $em;
$this->logger = new NullLogger(); $this->logger = $logger;
$this->contentProxy = $contentProxy; $this->contentProxy = $contentProxy;
$this->tagsAssigner = $tagsAssigner; $this->tagsAssigner = $tagsAssigner;
$this->eventDispatcher = $eventDispatcher; $this->eventDispatcher = $eventDispatcher;

View file

@ -3,6 +3,7 @@
namespace Wallabag\ImportBundle\Import; namespace Wallabag\ImportBundle\Import;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Wallabag\CoreBundle\Helper\ContentProxy; use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Helper\TagsAssigner; use Wallabag\CoreBundle\Helper\TagsAssigner;
@ -12,12 +13,12 @@ class WallabagV1Import extends WallabagImport
protected $fetchingErrorMessage; protected $fetchingErrorMessage;
protected $fetchingErrorMessageTitle; protected $fetchingErrorMessageTitle;
public function __construct(EntityManagerInterface $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher, $fetchingErrorMessageTitle, $fetchingErrorMessage) public function __construct(EntityManagerInterface $em, ContentProxy $contentProxy, TagsAssigner $tagsAssigner, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger, $fetchingErrorMessageTitle, $fetchingErrorMessage)
{ {
$this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle; $this->fetchingErrorMessageTitle = $fetchingErrorMessageTitle;
$this->fetchingErrorMessage = $fetchingErrorMessage; $this->fetchingErrorMessage = $fetchingErrorMessage;
parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher); parent::__construct($em, $contentProxy, $tagsAssigner, $eventDispatcher, $logger);
} }
/** /**

View file

@ -232,11 +232,10 @@ class ChromeImportTest extends TestCase
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
$wallabag->setLogger($logger);
$wallabag = new ChromeImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
if (false === $unsetUser) { if (false === $unsetUser) {
$wallabag->setUser($this->user); $wallabag->setUser($this->user);

View file

@ -232,11 +232,10 @@ class FirefoxImportTest extends TestCase
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
$wallabag->setLogger($logger);
$wallabag = new FirefoxImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
if (false === $unsetUser) { if (false === $unsetUser) {
$wallabag->setUser($this->user); $wallabag->setUser($this->user);

View file

@ -247,11 +247,10 @@ class InstapaperImportTest extends TestCase
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
$import->setLogger($logger);
$import = new InstapaperImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
if (false === $unsetUser) { if (false === $unsetUser) {
$import->setUser($this->user); $import->setUser($this->user);

View file

@ -589,12 +589,11 @@ JSON
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$pocket->setUser($this->user);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
$pocket->setLogger($logger);
$pocket = new PocketImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
$pocket->setUser($this->user);
return $pocket; return $pocket;
} }

View file

@ -232,11 +232,10 @@ class ReadabilityImportTest extends TestCase
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
$wallabag->setLogger($logger);
$wallabag = new ReadabilityImport($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
if (false === $unsetUser) { if (false === $unsetUser) {
$wallabag->setUser($this->user); $wallabag->setUser($this->user);

View file

@ -249,19 +249,19 @@ class WallabagV1ImportTest extends TestCase
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]);
$wallabag = new WallabagV1Import( $wallabag = new WallabagV1Import(
$this->em, $this->em,
$this->contentProxy, $this->contentProxy,
$this->tagsAssigner, $this->tagsAssigner,
$dispatcher, $dispatcher,
$logger,
$this->fetchingErrorMessageTitle, $this->fetchingErrorMessageTitle,
$this->fetchingErrorMessage $this->fetchingErrorMessage
); );
$this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]);
$wallabag->setLogger($logger);
if (false === $unsetUser) { if (false === $unsetUser) {
$wallabag->setUser($this->user); $wallabag->setUser($this->user);
} }

View file

@ -275,11 +275,10 @@ class WallabagV2ImportTest extends TestCase
->expects($this->exactly($dispatched)) ->expects($this->exactly($dispatched))
->method('dispatch'); ->method('dispatch');
$wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher);
$this->logHandler = new TestHandler(); $this->logHandler = new TestHandler();
$logger = new Logger('test', [$this->logHandler]); $logger = new Logger('test', [$this->logHandler]);
$wallabag->setLogger($logger);
$wallabag = new WallabagV2Import($this->em, $this->contentProxy, $this->tagsAssigner, $dispatcher, $logger);
if (false === $unsetUser) { if (false === $unsetUser) {
$wallabag->setUser($this->user); $wallabag->setUser($this->user);