From: Thomas Citharel Date: Sun, 25 Sep 2016 09:36:59 +0000 (+0200) Subject: Merge pull request #2306 from wallabag/redis-rabbit-check X-Git-Tag: 2.1.0~28 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=9d7dd6b0d2480d3efff5b0ab1461f2ef99bfd57a;hp=637aa17e6b52dd8021854a809053560a27caca72;p=github%2Fwallabag%2Fwallabag.git Merge pull request #2306 from wallabag/redis-rabbit-check Some checks about Redis & RabbitMQ --- diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 38880908..3216b6ff 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,6 +16,7 @@ + diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index 9f051edb..c6fcb355 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -432,6 +432,9 @@ flashes: # failed_on_file: 'Error while processing import. Please verify your import file.' # summary: 'Import summary: %imported% imported, %skipped% already saved.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: # client_created: 'New client created.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index cbfacd55..c0e82b59 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -432,6 +432,9 @@ flashes: failed_on_file: 'Fehler während des Imports. Bitte überprüfe deine Import-Datei.' summary: 'Import-Zusammenfassung: %imported% importiert, %skipped% bereits gespeichert.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: client_created: 'Neuer Client erstellt.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 21e2405c..6f262209 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -434,6 +434,9 @@ flashes: failed_on_file: 'Error while processing import. Please verify your import file.' summary: 'Import summary: %imported% imported, %skipped% already saved.' summary_with_queue: 'Import summary: %queued% queued.' + error: + redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: client_created: 'New client %name% created.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 43f376d4..7b981069 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -432,6 +432,9 @@ flashes: failed_on_file: 'Se ocurre un error por procesar importación. Por favor verifique su archivo importado.' summary: 'Resúmen importado: %importado% importado, %saltados% ya guardado.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: client_created: 'Nuevo cliente creado.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index 56418ef9..99fcc378 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -432,6 +432,9 @@ flashes: failed_on_file: 'خطا هنگام پردازش پروندهٔ ورودی. آیا پروندهٔ درون‌ریزی شده سالم است؟' summary: 'گزارش درون‌ریزی: %imported% وارد شد, %skipped% از قبل ذخیره شده بود.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: # client_created: 'New client created.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index bde21866..dd82e7f5 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -434,6 +434,9 @@ flashes: failed_on_file: "Erreur lors du traitement de l'import. Vérifier votre fichier." summary: "Rapport d'import: %imported% importés, %skipped% déjà présent." summary_with_queue: "Rapport d'import: %queued% en cours de traitement." + error: + redis_enabled_not_installed: Redis est activé pour les imports asynchrones mais impossible de s'y connecter. Vérifier la configuration de Redis. + rabbit_enabled_not_installed: RabbitMQ est activé pour les imports asynchrones mais impossible de s'y connecter. Vérifier la configuration de RabbitMQ. developer: notice: client_created: 'Nouveau client %name% créé' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 26bb31ba..d3ce30c9 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -431,6 +431,9 @@ flashes: failed_on_file: 'Errore durante la processazione dei dati da importare. Verifica il tuo file di import.' summary: 'Sommario di importazione: %imported% importati, %skipped% già salvati.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: client_created: 'Nuovo client creato.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index c6818449..d040daea 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -432,6 +432,9 @@ flashes: failed_on_file: "Errorr pendent du tractament de l'import. Mercés de verificar vòstre fichièr." summary: "Rapòrt d'import: %imported% importats, %skipped% ja presents." # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: client_created: 'Novèl client creat' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index 84f68138..a51ed1f2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -432,6 +432,9 @@ flashes: failed_on_file: 'Błąd podczas ptrzetwarzania pliku. Sprawdż swój importowany plik.' summary: 'Podsumowanie importu: %imported% zaimportowane, %skipped% już zapisane.' summary_with_queue: 'Podsumowanie importu: %queued% zakolejkowane.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: client_created: 'Nowy klient utworzony.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 3d22e29d..de21f0b3 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -432,6 +432,9 @@ flashes: # failed_on_file: 'Error while processing import. Please verify your import file.' # summary: 'Import summary: %imported% imported, %skipped% already saved.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: # client_created: 'New client created.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 5099b002..d4b7a7a2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -432,6 +432,9 @@ flashes: # failed_on_file: 'Error while processing import. Please verify your import file.' # summary: 'Import summary: %imported% imported, %skipped% already saved.' # summary_with_queue: 'Import summary: %queued% queued.' + error: + # redis_enabled_not_installed: Redis is enabled for handle asynchronous import but it looks like we can't connect to it. Please check Redis configuration. + # rabbit_enabled_not_installed: RabbitMQ is enabled for handle asynchronous import but it looks like we can't connect to it. Please check RabbitMQ configuration. developer: notice: # client_created: 'New client created.' diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php index ea4f7d7b..36a2a399 100644 --- a/src/Wallabag/ImportBundle/Controller/ImportController.php +++ b/src/Wallabag/ImportBundle/Controller/ImportController.php @@ -25,33 +25,41 @@ class ImportController extends Controller { $nbRedisMessages = null; $nbRabbitMessages = null; + $redisNotInstalled = false; + $rabbitNotInstalled = false; if (!$this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { - return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [ - 'nbRedisMessages' => $nbRedisMessages, - 'nbRabbitMessages' => $nbRabbitMessages, - ]); + return $this->render('WallabagImportBundle:Import:check_queue.html.twig'); } if ($this->get('craue_config')->get('import_with_rabbitmq')) { - $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket') - + $this->getTotalMessageInRabbitQueue('readability') - + $this->getTotalMessageInRabbitQueue('wallabag_v1') - + $this->getTotalMessageInRabbitQueue('wallabag_v2') - ; + // in case rabbit is activated but not installed + try { + $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket') + + $this->getTotalMessageInRabbitQueue('readability') + + $this->getTotalMessageInRabbitQueue('wallabag_v1') + + $this->getTotalMessageInRabbitQueue('wallabag_v2'); + } catch (\Exception $e) { + $rabbitNotInstalled = true; + } } elseif ($this->get('craue_config')->get('import_with_redis')) { $redis = $this->get('wallabag_core.redis.client'); - $nbRedisMessages = $redis->llen('wallabag.import.pocket') - + $redis->llen('wallabag.import.readability') - + $redis->llen('wallabag.import.wallabag_v1') - + $redis->llen('wallabag.import.wallabag_v2') - ; + try { + $nbRedisMessages = $redis->llen('wallabag.import.pocket') + + $redis->llen('wallabag.import.readability') + + $redis->llen('wallabag.import.wallabag_v1') + + $redis->llen('wallabag.import.wallabag_v2'); + } catch (\Exception $e) { + $redisNotInstalled = true; + } } return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [ 'nbRedisMessages' => $nbRedisMessages, 'nbRabbitMessages' => $nbRabbitMessages, + 'redisNotInstalled' => $redisNotInstalled, + 'rabbitNotInstalled' => $rabbitNotInstalled, ]); } diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig index 7168ea35..a2633698 100644 --- a/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig +++ b/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig @@ -1,11 +1,23 @@ -{% if nbRedisMessages > 0 %} +{% if nbRedisMessages is defined and nbRedisMessages > 0 %} {% endif %} -{% if nbRabbitMessages > 0 %} +{% if nbRabbitMessages is defined and nbRabbitMessages > 0 %} {% endif %} + +{% if redisNotInstalled is defined and redisNotInstalled %} +
+ {{ 'flashes.import.error.redis_enabled_not_installed'|trans|raw }} +
+{% endif %} + +{% if rabbitNotInstalled is defined and rabbitNotInstalled %} +
+ {{ 'flashes.import.error.rabbit_enabled_not_installed'|trans|raw }} +
+{% endif %} diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index c0055888..75b7ee0b 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -80,4 +80,19 @@ abstract class WallabagCoreTestCase extends WebTestCase throw new \RuntimeException('No logged in User.'); } + + /** + * Check if Redis is installed. + * If not, mark test as skip + */ + protected function checkRedis() + { + try { + $this->client->getContainer()->get('wallabag_core.redis.client')->connect(); + } catch (\Exception $e) { + $this->markTestSkipped( + 'Redis is not installed/activated' + ); + } + } } diff --git a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php index 35673261..7d6a300f 100644 --- a/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/PocketControllerTest.php @@ -34,6 +34,7 @@ class PocketControllerTest extends WallabagCoreTestCase public function testImportPocketWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php index 7b88d891..87ecb9d3 100644 --- a/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/ReadabilityControllerTest.php @@ -54,6 +54,7 @@ class ReadabilityControllerTest extends WallabagCoreTestCase public function testImportReadabilityWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php index 98e85d45..3497c4b8 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV1ControllerTest.php @@ -54,6 +54,7 @@ class WallabagV1ControllerTest extends WallabagCoreTestCase public function testImportWallabagWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient(); diff --git a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php index 74d61f9a..27d2d52b 100644 --- a/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php +++ b/tests/Wallabag/ImportBundle/Controller/WallabagV2ControllerTest.php @@ -54,6 +54,7 @@ class WallabagV2ControllerTest extends WallabagCoreTestCase public function testImportWallabagWithRedisEnabled() { + $this->checkRedis(); $this->logInAs('admin'); $client = $this->getClient();