2015-10-23 12:45:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\ImportBundle\Controller;
|
|
|
|
|
2022-08-28 00:01:46 +00:00
|
|
|
use Craue\ConfigBundle\Util\Config;
|
2022-04-24 16:20:46 +00:00
|
|
|
use Predis\Client;
|
2018-10-04 12:07:20 +00:00
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
2022-08-28 00:01:46 +00:00
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
2023-12-31 09:03:14 +00:00
|
|
|
use Wallabag\CoreBundle\Consumer\RabbitMQConsumerTotalProxy;
|
2024-01-01 18:51:22 +00:00
|
|
|
use Wallabag\CoreBundle\Controller\AbstractController;
|
2022-04-24 15:24:24 +00:00
|
|
|
use Wallabag\ImportBundle\Import\ImportChain;
|
2015-10-23 12:45:50 +00:00
|
|
|
|
2023-08-07 21:04:13 +00:00
|
|
|
class ImportController extends AbstractController
|
2015-10-23 12:45:50 +00:00
|
|
|
{
|
2022-12-19 12:23:56 +00:00
|
|
|
private RabbitMQConsumerTotalProxy $rabbitMQConsumerTotalProxy;
|
|
|
|
|
|
|
|
public function __construct(RabbitMQConsumerTotalProxy $rabbitMQConsumerTotalProxy)
|
|
|
|
{
|
|
|
|
$this->rabbitMQConsumerTotalProxy = $rabbitMQConsumerTotalProxy;
|
|
|
|
}
|
|
|
|
|
2015-10-23 12:45:50 +00:00
|
|
|
/**
|
2015-12-31 10:24:46 +00:00
|
|
|
* @Route("/", name="import")
|
2015-10-23 12:45:50 +00:00
|
|
|
*/
|
2022-12-19 12:23:56 +00:00
|
|
|
public function importAction(ImportChain $importChain)
|
2015-10-23 12:45:50 +00:00
|
|
|
{
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagImport/Import/index.html.twig', [
|
2022-12-19 12:23:56 +00:00
|
|
|
'imports' => $importChain->getAll(),
|
2015-12-31 10:24:46 +00:00
|
|
|
]);
|
2015-10-23 12:45:50 +00:00
|
|
|
}
|
2016-09-13 18:31:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display how many messages are queue (both in Redis and RabbitMQ).
|
2016-09-16 18:08:07 +00:00
|
|
|
* Only for admins.
|
2016-09-13 18:31:32 +00:00
|
|
|
*/
|
2022-12-19 12:23:56 +00:00
|
|
|
public function checkQueueAction(AuthorizationCheckerInterface $authorizationChecker, Config $craueConfig)
|
2016-09-13 18:31:32 +00:00
|
|
|
{
|
|
|
|
$nbRedisMessages = null;
|
|
|
|
$nbRabbitMessages = null;
|
2016-09-24 17:56:15 +00:00
|
|
|
$redisNotInstalled = false;
|
|
|
|
$rabbitNotInstalled = false;
|
2016-09-13 18:31:32 +00:00
|
|
|
|
2022-12-19 12:23:56 +00:00
|
|
|
if (!$authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagImport/Import/check_queue.html.twig');
|
2016-09-16 18:08:07 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 12:23:56 +00:00
|
|
|
if ($craueConfig->get('import_with_rabbitmq')) {
|
2016-09-24 17:56:15 +00:00
|
|
|
// in case rabbit is activated but not installed
|
|
|
|
try {
|
2022-12-19 12:23:56 +00:00
|
|
|
$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')
|
2023-07-26 10:49:30 +00:00
|
|
|
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('shaarli')
|
|
|
|
+ $this->rabbitMQConsumerTotalProxy->getTotalMessage('pocket_html')
|
2016-09-27 05:57:53 +00:00
|
|
|
;
|
2016-09-24 17:56:15 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$rabbitNotInstalled = true;
|
|
|
|
}
|
2022-12-19 12:23:56 +00:00
|
|
|
} elseif ($craueConfig->get('import_with_redis')) {
|
2022-04-24 16:20:46 +00:00
|
|
|
$redis = $this->get(Client::class);
|
2016-09-13 18:31:32 +00:00
|
|
|
|
2016-09-24 17:56:15 +00:00
|
|
|
try {
|
|
|
|
$nbRedisMessages = $redis->llen('wallabag.import.pocket')
|
|
|
|
+ $redis->llen('wallabag.import.readability')
|
|
|
|
+ $redis->llen('wallabag.import.wallabag_v1')
|
2016-09-27 05:57:53 +00:00
|
|
|
+ $redis->llen('wallabag.import.wallabag_v2')
|
|
|
|
+ $redis->llen('wallabag.import.firefox')
|
|
|
|
+ $redis->llen('wallabag.import.chrome')
|
|
|
|
+ $redis->llen('wallabag.import.instapaper')
|
2016-11-04 21:44:31 +00:00
|
|
|
+ $redis->llen('wallabag.import.pinboard')
|
2021-02-08 08:08:12 +00:00
|
|
|
+ $redis->llen('wallabag.import.delicious')
|
2019-12-02 11:36:05 +00:00
|
|
|
+ $redis->llen('wallabag.import.elcurator')
|
2023-07-26 10:49:30 +00:00
|
|
|
+ $redis->llen('wallabag.import.shaarli')
|
|
|
|
+ $redis->llen('wallabag.import.pocket_html')
|
2016-09-27 05:57:53 +00:00
|
|
|
;
|
2016-09-24 17:56:15 +00:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
$redisNotInstalled = true;
|
|
|
|
}
|
2016-09-13 18:31:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 22:47:22 +00:00
|
|
|
return $this->render('@WallabagImport/Import/check_queue.html.twig', [
|
2016-09-13 18:31:32 +00:00
|
|
|
'nbRedisMessages' => $nbRedisMessages,
|
|
|
|
'nbRabbitMessages' => $nbRabbitMessages,
|
2016-09-24 17:56:15 +00:00
|
|
|
'redisNotInstalled' => $redisNotInstalled,
|
|
|
|
'rabbitNotInstalled' => $rabbitNotInstalled,
|
2016-09-13 18:31:32 +00:00
|
|
|
]);
|
|
|
|
}
|
2015-10-23 12:45:50 +00:00
|
|
|
}
|