]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/ImportBundle/Controller/ImportController.php
And of course it doesn't work for SQLite
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / ImportController.php
1 <?php
2
3 namespace Wallabag\ImportBundle\Controller;
4
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
8 class ImportController extends Controller
9 {
10 /**
11 * @Route("/", name="import")
12 */
13 public function importAction()
14 {
15 return $this->render('WallabagImportBundle:Import:index.html.twig', [
16 'imports' => $this->get('wallabag_import.chain')->getAll(),
17 ]);
18 }
19
20 /**
21 * Display how many messages are queue (both in Redis and RabbitMQ).
22 * Only for admins.
23 */
24 public function checkQueueAction()
25 {
26 $nbRedisMessages = null;
27 $nbRabbitMessages = null;
28 $redisNotInstalled = false;
29 $rabbitNotInstalled = false;
30
31 if (!$this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
32 return $this->render('WallabagImportBundle:Import:check_queue.html.twig');
33 }
34
35 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
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')
41 + $this->getTotalMessageInRabbitQueue('wallabag_v2')
42 + $this->getTotalMessageInRabbitQueue('firefox')
43 + $this->getTotalMessageInRabbitQueue('chrome')
44 + $this->getTotalMessageInRabbitQueue('instapaper')
45 + $this->getTotalMessageInRabbitQueue('pinboard')
46 ;
47 } catch (\Exception $e) {
48 $rabbitNotInstalled = true;
49 }
50 } elseif ($this->get('craue_config')->get('import_with_redis')) {
51 $redis = $this->get('wallabag_core.redis.client');
52
53 try {
54 $nbRedisMessages = $redis->llen('wallabag.import.pocket')
55 + $redis->llen('wallabag.import.readability')
56 + $redis->llen('wallabag.import.wallabag_v1')
57 + $redis->llen('wallabag.import.wallabag_v2')
58 + $redis->llen('wallabag.import.firefox')
59 + $redis->llen('wallabag.import.chrome')
60 + $redis->llen('wallabag.import.instapaper')
61 + $redis->llen('wallabag.import.pinboard')
62 ;
63 } catch (\Exception $e) {
64 $redisNotInstalled = true;
65 }
66 }
67
68 return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [
69 'nbRedisMessages' => $nbRedisMessages,
70 'nbRabbitMessages' => $nbRabbitMessages,
71 'redisNotInstalled' => $redisNotInstalled,
72 'rabbitNotInstalled' => $rabbitNotInstalled,
73 ]);
74 }
75
76 /**
77 * Count message in RabbitMQ queue.
78 * It get one message without acking it (so it'll stay in the queue)
79 * which will include the total of *other* messages in the queue.
80 * Adding one to that messages will result in the full total message.
81 *
82 * @param string $importService The import service related: pocket, readability, wallabag_v1 or wallabag_v2
83 *
84 * @return int
85 */
86 private function getTotalMessageInRabbitQueue($importService)
87 {
88 $message = $this
89 ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer')
90 ->getChannel()
91 ->basic_get('wallabag.import.'.$importService);
92
93 if (null === $message) {
94 return 0;
95 }
96
97 return $message->delivery_info['message_count'] + 1;
98 }
99 }