forked from wallabag/wallabag
Move source files directly under src/ directory
This commit is contained in:
83
src/Controller/Import/BrowserController.php
Normal file
83
src/Controller/Import/BrowserController.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\ImportInterface;
|
||||
|
||||
abstract class BrowserController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/import/browser", name="import_browser")
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$wallabag = $this->getImportService();
|
||||
$wallabag->setUser($this->getUser());
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = $this->getUser()->getId() . '.json';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $wallabag
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $wallabag->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render($this->getImportTemplate(), [
|
||||
'form' => $form->createView(),
|
||||
'import' => $wallabag,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service to handle the import.
|
||||
*
|
||||
* @return ImportInterface
|
||||
*/
|
||||
abstract protected function getImportService();
|
||||
|
||||
/**
|
||||
* Return the template used for the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getImportTemplate();
|
||||
}
|
||||
51
src/Controller/Import/ChromeController.php
Normal file
51
src/Controller/Import/ChromeController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\ChromeImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class ChromeController extends BrowserController
|
||||
{
|
||||
private ChromeImport $chromeImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(ChromeImport $chromeImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->chromeImport = $chromeImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/chrome", name="import_chrome")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->chromeImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->chromeImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->chromeImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/Chrome/index.html.twig';
|
||||
}
|
||||
}
|
||||
84
src/Controller/Import/DeliciousController.php
Normal file
84
src/Controller/Import/DeliciousController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\DeliciousImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class DeliciousController extends AbstractController
|
||||
{
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/delicious", name="import_delicious")
|
||||
*/
|
||||
public function indexAction(Request $request, DeliciousImport $delicious, Config $craueConfig, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$delicious->setUser($this->getUser());
|
||||
|
||||
if ($craueConfig->get('import_with_rabbitmq')) {
|
||||
$delicious->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($craueConfig->get('import_with_redis')) {
|
||||
$delicious->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = 'delicious_' . $this->getUser()->getId() . '.json';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $delicious
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $delicious->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render('Import/Delicious/index.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'import' => $delicious,
|
||||
]);
|
||||
}
|
||||
}
|
||||
51
src/Controller/Import/ElcuratorController.php
Normal file
51
src/Controller/Import/ElcuratorController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\ElcuratorImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class ElcuratorController extends WallabagController
|
||||
{
|
||||
private ElcuratorImport $elcuratorImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(ElcuratorImport $elcuratorImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->elcuratorImport = $elcuratorImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/elcurator", name="import_elcurator")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->elcuratorImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->elcuratorImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->elcuratorImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/Elcurator/index.html.twig';
|
||||
}
|
||||
}
|
||||
51
src/Controller/Import/FirefoxController.php
Normal file
51
src/Controller/Import/FirefoxController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\FirefoxImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class FirefoxController extends BrowserController
|
||||
{
|
||||
private FirefoxImport $firefoxImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(FirefoxImport $firefoxImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->firefoxImport = $firefoxImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/firefox", name="import_firefox")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->firefoxImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->firefoxImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->firefoxImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/Firefox/index.html.twig';
|
||||
}
|
||||
}
|
||||
83
src/Controller/Import/HtmlController.php
Normal file
83
src/Controller/Import/HtmlController.php
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\ImportInterface;
|
||||
|
||||
abstract class HtmlController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @Route("/import/html", name="import_html")
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$wallabag = $this->getImportService();
|
||||
$wallabag->setUser($this->getUser());
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = $this->getUser()->getId() . '.html';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $wallabag
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $wallabag->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render($this->getImportTemplate(), [
|
||||
'form' => $form->createView(),
|
||||
'import' => $wallabag,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service to handle the import.
|
||||
*
|
||||
* @return ImportInterface
|
||||
*/
|
||||
abstract protected function getImportService();
|
||||
|
||||
/**
|
||||
* Return the template used for the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getImportTemplate();
|
||||
}
|
||||
95
src/Controller/Import/ImportController.php
Normal file
95
src/Controller/Import/ImportController.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use Predis\Client;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
||||
use Wallabag\CoreBundle\Consumer\RabbitMQConsumerTotalProxy;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Import\ImportChain;
|
||||
|
||||
class ImportController extends AbstractController
|
||||
{
|
||||
private RabbitMQConsumerTotalProxy $rabbitMQConsumerTotalProxy;
|
||||
|
||||
public function __construct(RabbitMQConsumerTotalProxy $rabbitMQConsumerTotalProxy)
|
||||
{
|
||||
$this->rabbitMQConsumerTotalProxy = $rabbitMQConsumerTotalProxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/", name="import")
|
||||
*/
|
||||
public function importAction(ImportChain $importChain)
|
||||
{
|
||||
return $this->render('Import/index.html.twig', [
|
||||
'imports' => $importChain->getAll(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display how many messages are queue (both in Redis and RabbitMQ).
|
||||
* Only for admins.
|
||||
*/
|
||||
public function checkQueueAction(AuthorizationCheckerInterface $authorizationChecker, Config $craueConfig)
|
||||
{
|
||||
$nbRedisMessages = null;
|
||||
$nbRabbitMessages = null;
|
||||
$redisNotInstalled = false;
|
||||
$rabbitNotInstalled = false;
|
||||
|
||||
if (!$authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
|
||||
return $this->render('Import/check_queue.html.twig');
|
||||
}
|
||||
|
||||
if ($craueConfig->get('import_with_rabbitmq')) {
|
||||
// in case rabbit is activated but not installed
|
||||
try {
|
||||
$nbRabbitMessages = $this->rabbitMQConsumerTotalProxy->getTotalMessage('pocket')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('readability')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('wallabag_v1')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('wallabag_v2')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('firefox')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('chrome')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('instapaper')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('pinboard')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('delicious')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('elcurator')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('shaarli')
|
||||
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('pocket_html')
|
||||
;
|
||||
} catch (\Exception $e) {
|
||||
$rabbitNotInstalled = true;
|
||||
}
|
||||
} elseif ($craueConfig->get('import_with_redis')) {
|
||||
$redis = $this->get(Client::class);
|
||||
|
||||
try {
|
||||
$nbRedisMessages = $redis->llen('wallabag.import.pocket')
|
||||
+ $redis->llen('wallabag.import.readability')
|
||||
+ $redis->llen('wallabag.import.wallabag_v1')
|
||||
+ $redis->llen('wallabag.import.wallabag_v2')
|
||||
+ $redis->llen('wallabag.import.firefox')
|
||||
+ $redis->llen('wallabag.import.chrome')
|
||||
+ $redis->llen('wallabag.import.instapaper')
|
||||
+ $redis->llen('wallabag.import.pinboard')
|
||||
+ $redis->llen('wallabag.import.delicious')
|
||||
+ $redis->llen('wallabag.import.elcurator')
|
||||
+ $redis->llen('wallabag.import.shaarli')
|
||||
+ $redis->llen('wallabag.import.pocket_html')
|
||||
;
|
||||
} catch (\Exception $e) {
|
||||
$redisNotInstalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('Import/check_queue.html.twig', [
|
||||
'nbRedisMessages' => $nbRedisMessages,
|
||||
'nbRabbitMessages' => $nbRabbitMessages,
|
||||
'redisNotInstalled' => $redisNotInstalled,
|
||||
'rabbitNotInstalled' => $rabbitNotInstalled,
|
||||
]);
|
||||
}
|
||||
}
|
||||
84
src/Controller/Import/InstapaperController.php
Normal file
84
src/Controller/Import/InstapaperController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\InstapaperImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class InstapaperController extends AbstractController
|
||||
{
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/instapaper", name="import_instapaper")
|
||||
*/
|
||||
public function indexAction(Request $request, InstapaperImport $instapaper, Config $craueConfig, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$instapaper->setUser($this->getUser());
|
||||
|
||||
if ($craueConfig->get('import_with_rabbitmq')) {
|
||||
$instapaper->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($craueConfig->get('import_with_redis')) {
|
||||
$instapaper->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = 'instapaper_' . $this->getUser()->getId() . '.csv';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $instapaper
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $instapaper->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render('Import/Instapaper/index.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'import' => $instapaper,
|
||||
]);
|
||||
}
|
||||
}
|
||||
84
src/Controller/Import/PinboardController.php
Normal file
84
src/Controller/Import/PinboardController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\PinboardImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class PinboardController extends AbstractController
|
||||
{
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pinboard", name="import_pinboard")
|
||||
*/
|
||||
public function indexAction(Request $request, PinboardImport $pinboard, Config $craueConfig, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$pinboard->setUser($this->getUser());
|
||||
|
||||
if ($craueConfig->get('import_with_rabbitmq')) {
|
||||
$pinboard->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($craueConfig->get('import_with_redis')) {
|
||||
$pinboard->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = 'pinboard_' . $this->getUser()->getId() . '.json';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $pinboard
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $pinboard->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render('Import/Pinboard/index.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'import' => $pinboard,
|
||||
]);
|
||||
}
|
||||
}
|
||||
135
src/Controller/Import/PocketController.php
Normal file
135
src/Controller/Import/PocketController.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Import\PocketImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class PocketController extends AbstractController
|
||||
{
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
private SessionInterface $session;
|
||||
|
||||
public function __construct(Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer, SessionInterface $session)
|
||||
{
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pocket", name="import_pocket")
|
||||
*/
|
||||
public function indexAction(PocketImport $pocketImport)
|
||||
{
|
||||
$pocket = $this->getPocketImportService($pocketImport);
|
||||
|
||||
$form = $this->createFormBuilder($pocket)
|
||||
->add('mark_as_read', CheckboxType::class, [
|
||||
'label' => 'import.form.mark_as_read_label',
|
||||
'required' => false,
|
||||
])
|
||||
->getForm();
|
||||
|
||||
return $this->render('Import/Pocket/index.html.twig', [
|
||||
'import' => $pocket,
|
||||
'has_consumer_key' => '' === trim($this->getUser()->getConfig()->getPocketConsumerKey()) ? false : true,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pocket/auth", name="import_pocket_auth")
|
||||
*/
|
||||
public function authAction(Request $request, PocketImport $pocketImport)
|
||||
{
|
||||
$requestToken = $this->getPocketImportService($pocketImport)
|
||||
->getRequestToken($this->generateUrl('import', [], UrlGeneratorInterface::ABSOLUTE_URL));
|
||||
|
||||
if (false === $requestToken) {
|
||||
$this->addFlash(
|
||||
'notice',
|
||||
'flashes.import.notice.failed'
|
||||
);
|
||||
|
||||
return $this->redirect($this->generateUrl('import_pocket'));
|
||||
}
|
||||
|
||||
$form = $request->request->get('form');
|
||||
|
||||
$this->session->set('import.pocket.code', $requestToken);
|
||||
if (null !== $form && \array_key_exists('mark_as_read', $form)) {
|
||||
$this->session->set('mark_as_read', $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),
|
||||
301
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pocket/callback", name="import_pocket_callback")
|
||||
*/
|
||||
public function callbackAction(PocketImport $pocketImport, TranslatorInterface $translator)
|
||||
{
|
||||
$message = 'flashes.import.notice.failed';
|
||||
$pocket = $this->getPocketImportService($pocketImport);
|
||||
|
||||
$markAsRead = $this->session->get('mark_as_read');
|
||||
$this->session->remove('mark_as_read');
|
||||
|
||||
// something bad happend on pocket side
|
||||
if (false === $pocket->authorize($this->session->get('import.pocket.code'))) {
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('import_pocket'));
|
||||
}
|
||||
|
||||
if (true === $pocket->setMarkAsRead($markAsRead)->import()) {
|
||||
$summary = $pocket->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => null !== $summary && \array_key_exists('imported', $summary) ? $summary['imported'] : 0,
|
||||
'%skipped%' => null !== $summary && \array_key_exists('skipped', $summary) ? $summary['skipped'] : 0,
|
||||
]);
|
||||
|
||||
if (null !== $summary && \array_key_exists('queued', $summary) && 0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Pocket Import Service with or without RabbitMQ enabled.
|
||||
*/
|
||||
private function getPocketImportService(PocketImport $pocketImport): PocketImport
|
||||
{
|
||||
$pocketImport->setUser($this->getUser());
|
||||
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$pocketImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$pocketImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $pocketImport;
|
||||
}
|
||||
}
|
||||
51
src/Controller/Import/PocketHtmlController.php
Normal file
51
src/Controller/Import/PocketHtmlController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\PocketHtmlImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class PocketHtmlController extends HtmlController
|
||||
{
|
||||
private PocketHtmlImport $pocketHtmlImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(PocketHtmlImport $pocketHtmlImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->pocketHtmlImport = $pocketHtmlImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/pocket_html", name="import_pocket_html")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->pocketHtmlImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->pocketHtmlImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->pocketHtmlImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/PocketHtml/index.html.twig';
|
||||
}
|
||||
}
|
||||
84
src/Controller/Import/ReadabilityController.php
Normal file
84
src/Controller/Import/ReadabilityController.php
Normal file
@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\ReadabilityImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class ReadabilityController extends AbstractController
|
||||
{
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/readability", name="import_readability")
|
||||
*/
|
||||
public function indexAction(Request $request, ReadabilityImport $readability, Config $craueConfig, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$readability->setUser($this->getUser());
|
||||
|
||||
if ($craueConfig->get('import_with_rabbitmq')) {
|
||||
$readability->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($craueConfig->get('import_with_redis')) {
|
||||
$readability->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = 'readability_' . $this->getUser()->getId() . '.json';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $readability
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $readability->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render('Import/Readability/index.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
'import' => $readability,
|
||||
]);
|
||||
}
|
||||
}
|
||||
51
src/Controller/Import/ShaarliController.php
Normal file
51
src/Controller/Import/ShaarliController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\ShaarliImport;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class ShaarliController extends HtmlController
|
||||
{
|
||||
private ShaarliImport $shaarliImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(ShaarliImport $shaarliImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->shaarliImport = $shaarliImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/shaarli", name="import_shaarli")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->shaarliImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->shaarliImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->shaarliImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/Shaarli/index.html.twig';
|
||||
}
|
||||
}
|
||||
87
src/Controller/Import/WallabagController.php
Normal file
87
src/Controller/Import/WallabagController.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Controller\AbstractController;
|
||||
use Wallabag\CoreBundle\Form\Type\UploadImportType;
|
||||
use Wallabag\CoreBundle\Import\ImportInterface;
|
||||
|
||||
/**
|
||||
* Define Wallabag import for v1 and v2, since there are very similar.
|
||||
*/
|
||||
abstract class WallabagController extends AbstractController
|
||||
{
|
||||
/**
|
||||
* Handle import request.
|
||||
*
|
||||
* @return Response|RedirectResponse
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
$form = $this->createForm(UploadImportType::class);
|
||||
$form->handleRequest($request);
|
||||
|
||||
$wallabag = $this->getImportService();
|
||||
$wallabag->setUser($this->getUser());
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$file = $form->get('file')->getData();
|
||||
$markAsRead = $form->get('mark_as_read')->getData();
|
||||
$name = $this->getUser()->getId() . '.json';
|
||||
|
||||
if (null !== $file && \in_array($file->getClientMimeType(), $this->getParameter('wallabag_core.allow_mimetypes'), true) && $file->move($this->getParameter('wallabag_core.resource_dir'), $name)) {
|
||||
$res = $wallabag
|
||||
->setFilepath($this->getParameter('wallabag_core.resource_dir') . '/' . $name)
|
||||
->setMarkAsRead($markAsRead)
|
||||
->import();
|
||||
|
||||
$message = 'flashes.import.notice.failed';
|
||||
|
||||
if (true === $res) {
|
||||
$summary = $wallabag->getSummary();
|
||||
$message = $translator->trans('flashes.import.notice.summary', [
|
||||
'%imported%' => $summary['imported'],
|
||||
'%skipped%' => $summary['skipped'],
|
||||
]);
|
||||
|
||||
if (0 < $summary['queued']) {
|
||||
$message = $translator->trans('flashes.import.notice.summary_with_queue', [
|
||||
'%queued%' => $summary['queued'],
|
||||
]);
|
||||
}
|
||||
|
||||
unlink($this->getParameter('wallabag_core.resource_dir') . '/' . $name);
|
||||
}
|
||||
|
||||
$this->addFlash('notice', $message);
|
||||
|
||||
return $this->redirect($this->generateUrl('homepage'));
|
||||
}
|
||||
|
||||
$this->addFlash('notice', 'flashes.import.notice.failed_on_file');
|
||||
}
|
||||
|
||||
return $this->render($this->getImportTemplate(), [
|
||||
'form' => $form->createView(),
|
||||
'import' => $wallabag,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the service to handle the import.
|
||||
*
|
||||
* @return ImportInterface
|
||||
*/
|
||||
abstract protected function getImportService();
|
||||
|
||||
/**
|
||||
* Return the template used for the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getImportTemplate();
|
||||
}
|
||||
51
src/Controller/Import/WallabagV1Controller.php
Normal file
51
src/Controller/Import/WallabagV1Controller.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\WallabagV1Import;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class WallabagV1Controller extends WallabagController
|
||||
{
|
||||
private WallabagV1Import $wallabagImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(WallabagV1Import $wallabagImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->wallabagImport = $wallabagImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/wallabag-v1", name="import_wallabag_v1")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->wallabagImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->wallabagImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->wallabagImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/WallabagV1/index.html.twig';
|
||||
}
|
||||
}
|
||||
51
src/Controller/Import/WallabagV2Controller.php
Normal file
51
src/Controller/Import/WallabagV2Controller.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Controller\Import;
|
||||
|
||||
use Craue\ConfigBundle\Util\Config;
|
||||
use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Wallabag\CoreBundle\Import\WallabagV2Import;
|
||||
use Wallabag\CoreBundle\Redis\Producer as RedisProducer;
|
||||
|
||||
class WallabagV2Controller extends WallabagController
|
||||
{
|
||||
private WallabagV2Import $wallabagImport;
|
||||
private Config $craueConfig;
|
||||
private RabbitMqProducer $rabbitMqProducer;
|
||||
private RedisProducer $redisProducer;
|
||||
|
||||
public function __construct(WallabagV2Import $wallabagImport, Config $craueConfig, RabbitMqProducer $rabbitMqProducer, RedisProducer $redisProducer)
|
||||
{
|
||||
$this->wallabagImport = $wallabagImport;
|
||||
$this->craueConfig = $craueConfig;
|
||||
$this->rabbitMqProducer = $rabbitMqProducer;
|
||||
$this->redisProducer = $redisProducer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/import/wallabag-v2", name="import_wallabag_v2")
|
||||
*/
|
||||
public function indexAction(Request $request, TranslatorInterface $translator)
|
||||
{
|
||||
return parent::indexAction($request, $translator);
|
||||
}
|
||||
|
||||
protected function getImportService()
|
||||
{
|
||||
if ($this->craueConfig->get('import_with_rabbitmq')) {
|
||||
$this->wallabagImport->setProducer($this->rabbitMqProducer);
|
||||
} elseif ($this->craueConfig->get('import_with_redis')) {
|
||||
$this->wallabagImport->setProducer($this->redisProducer);
|
||||
}
|
||||
|
||||
return $this->wallabagImport;
|
||||
}
|
||||
|
||||
protected function getImportTemplate()
|
||||
{
|
||||
return 'Import/WallabagV2/index.html.twig';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user