]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Controller/ImportController.php
Disable deprecation that fail test
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / ImportController.php
CommitLineData
d51b38ed
NL
1<?php
2
3namespace Wallabag\ImportBundle\Controller;
4
5use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
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;
28
4fc99824
JB
29 if (!$this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
30 return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [
31 'nbRedisMessages' => $nbRedisMessages,
32 'nbRabbitMessages' => $nbRabbitMessages,
33 ]);
34 }
35
e01a3c98
JB
36 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
37 $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket')
38 + $this->getTotalMessageInRabbitQueue('readability')
39 + $this->getTotalMessageInRabbitQueue('wallabag_v1')
40 + $this->getTotalMessageInRabbitQueue('wallabag_v2')
41 ;
42 } elseif ($this->get('craue_config')->get('import_with_redis')) {
43 $redis = $this->get('wallabag_core.redis.client');
44
45 $nbRedisMessages = $redis->llen('wallabag.import.pocket')
46 + $redis->llen('wallabag.import.readability')
47 + $redis->llen('wallabag.import.wallabag_v1')
48 + $redis->llen('wallabag.import.wallabag_v2')
49 ;
50 }
51
52 return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [
53 'nbRedisMessages' => $nbRedisMessages,
54 'nbRabbitMessages' => $nbRabbitMessages,
55 ]);
56 }
57
58 /**
59 * Count message in RabbitMQ queue.
60 * It get one message without acking it (so it'll stay in the queue)
61 * which will include the total of *other* messages in the queue.
62 * Adding one to that messages will result in the full total message.
63 *
64 * @param string $importService The import service related: pocket, readability, wallabag_v1 or wallabag_v2
65 *
66 * @return int
67 */
68 private function getTotalMessageInRabbitQueue($importService)
69 {
70 $message = $this
71 ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer')
72 ->getChannel()
73 ->basic_get('wallabag.import.'.$importService);
74
75 if (null === $message) {
76 return 0;
77 }
78
79 return $message->delivery_info['message_count'] + 1;
80 }
d51b38ed 81}