Add a real configuration for CS-Fixer

This commit is contained in:
Jeremy Benoist
2017-07-01 09:52:38 +02:00
parent 822c877949
commit f808b01692
170 changed files with 3147 additions and 3120 deletions

View File

@ -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('<info>'.$summary['imported'].' imported</info>');
$output->writeln('<comment>'.$summary['skipped'].' already saved</comment>');
$output->writeln('<info>' . $summary['imported'] . ' imported</info>');
$output->writeln('<comment>' . $summary['skipped'] . ' already saved</comment>');
}
$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') . ' ---');
}
}

View File

@ -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')
);

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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', [

View File

@ -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', [

View File

@ -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;
}
}

View File

@ -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', [

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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');
}

View File

@ -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
{

View File

@ -2,17 +2,17 @@
namespace Wallabag\ImportBundle\Import;
use Doctrine\ORM\EntityManager;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Doctrine\ORM\EntityManager;
use Wallabag\CoreBundle\Helper\ContentProxy;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Wallabag\CoreBundle\Entity\Entry;
use Wallabag\CoreBundle\Entity\Tag;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
use Wallabag\CoreBundle\Helper\ContentProxy;
use Wallabag\CoreBundle\Helper\TagsAssigner;
use Wallabag\UserBundle\Entity\User;
use OldSound\RabbitMqBundle\RabbitMq\ProducerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Wallabag\CoreBundle\Event\EntrySavedEvent;
abstract class AbstractImport implements ImportInterface
{
@ -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.

View File

@ -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}
*/

View File

@ -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'];
}

View File

@ -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'];
}

View File

@ -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

View File

@ -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]];
}

View File

@ -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'];
}

View File

@ -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'];
}

View File

@ -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);
}

View File

@ -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