]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Controller/ImportController.php
Merge pull request #4438 from wallabag/dependabot/composer/scheb/two-factor-bundle...
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / ImportController.php
CommitLineData
d51b38ed
NL
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
f808b016 5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
115de64e 6use Symfony\Component\Routing\Annotation\Route;
d51b38ed
NL
7
8class ImportController extends Controller
9{
10 /**
7019c7cf 11 * @Route("/", name="import")
d51b38ed 12 */
252ebd60 13 public function importAction()
d51b38ed 14 {
7019c7cf
JB
15 return $this->render('WallabagImportBundle:Import:index.html.twig', [
16 'imports' => $this->get('wallabag_import.chain')->getAll(),
17 ]);
d51b38ed 18 }
e01a3c98
JB
19
20 /**
21 * Display how many messages are queue (both in Redis and RabbitMQ).
4fc99824 22 * Only for admins.
e01a3c98
JB
23 */
24 public function checkQueueAction()
25 {
26 $nbRedisMessages = null;
27 $nbRabbitMessages = null;
13a522df
JB
28 $redisNotInstalled = false;
29 $rabbitNotInstalled = false;
e01a3c98 30
4fc99824 31 if (!$this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
13a522df 32 return $this->render('WallabagImportBundle:Import:check_queue.html.twig');
4fc99824
JB
33 }
34
e01a3c98 35 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
13a522df
JB
36 // in case rabbit is activated but not installed
37 try {
38 $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket')
39 + $this->getTotalMessageInRabbitQueue('readability')
40 + $this->getTotalMessageInRabbitQueue('wallabag_v1')
ff1a5362
JB
41 + $this->getTotalMessageInRabbitQueue('wallabag_v2')
42 + $this->getTotalMessageInRabbitQueue('firefox')
43 + $this->getTotalMessageInRabbitQueue('chrome')
44 + $this->getTotalMessageInRabbitQueue('instapaper')
9ab024b4 45 + $this->getTotalMessageInRabbitQueue('pinboard')
f3d20097 46 + $this->getTotalMessageInRabbitQueue('elcurator')
ff1a5362 47 ;
13a522df
JB
48 } catch (\Exception $e) {
49 $rabbitNotInstalled = true;
50 }
e01a3c98
JB
51 } elseif ($this->get('craue_config')->get('import_with_redis')) {
52 $redis = $this->get('wallabag_core.redis.client');
53
13a522df
JB
54 try {
55 $nbRedisMessages = $redis->llen('wallabag.import.pocket')
56 + $redis->llen('wallabag.import.readability')
57 + $redis->llen('wallabag.import.wallabag_v1')
ff1a5362
JB
58 + $redis->llen('wallabag.import.wallabag_v2')
59 + $redis->llen('wallabag.import.firefox')
60 + $redis->llen('wallabag.import.chrome')
61 + $redis->llen('wallabag.import.instapaper')
9ab024b4 62 + $redis->llen('wallabag.import.pinboard')
f3d20097 63 + $redis->llen('wallabag.import.elcurator')
ff1a5362 64 ;
13a522df
JB
65 } catch (\Exception $e) {
66 $redisNotInstalled = true;
67 }
e01a3c98
JB
68 }
69
70 return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [
71 'nbRedisMessages' => $nbRedisMessages,
72 'nbRabbitMessages' => $nbRabbitMessages,
13a522df
JB
73 'redisNotInstalled' => $redisNotInstalled,
74 'rabbitNotInstalled' => $rabbitNotInstalled,
e01a3c98
JB
75 ]);
76 }
77
78 /**
79 * Count message in RabbitMQ queue.
80 * It get one message without acking it (so it'll stay in the queue)
81 * which will include the total of *other* messages in the queue.
82 * Adding one to that messages will result in the full total message.
83 *
84 * @param string $importService The import service related: pocket, readability, wallabag_v1 or wallabag_v2
85 *
86 * @return int
87 */
88 private function getTotalMessageInRabbitQueue($importService)
89 {
90 $message = $this
f808b016 91 ->get('old_sound_rabbit_mq.import_' . $importService . '_consumer')
e01a3c98 92 ->getChannel()
f808b016 93 ->basic_get('wallabag.import.' . $importService);
e01a3c98
JB
94
95 if (null === $message) {
96 return 0;
97 }
98
99 return $message->delivery_info['message_count'] + 1;
100 }
d51b38ed 101}