From b81f894d22140f9014c3bdbe911e387a964794ab Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Tue, 17 Sep 2013 11:26:39 +0200 Subject: [PATCH] Remove infinite redirection, add upgrade instructions --- lib/Alchemy/Phrasea/Application/Root.php | 8 +++- lib/Alchemy/Phrasea/Controller/Setup.php | 11 ++++++ .../web/setup/upgrade-instructions.html.twig | 38 +++++++++++++++++++ .../Tests/Phrasea/Controller/SetupTest.php | 19 ++++++++++ 4 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 templates/web/setup/upgrade-instructions.html.twig diff --git a/lib/Alchemy/Phrasea/Application/Root.php b/lib/Alchemy/Phrasea/Application/Root.php index 9d240a5045..35a10c21dd 100644 --- a/lib/Alchemy/Phrasea/Application/Root.php +++ b/lib/Alchemy/Phrasea/Application/Root.php @@ -31,7 +31,13 @@ return call_user_func(function($environment = PhraseaApplication::ENV_PROD) { $app->before(function (Request $request) use ($app) { if (0 === strpos($request->getPathInfo(), '/setup')) { - if (!$app['phraseanet.configuration-tester']->isBlank()) { + if (!$app['phraseanet.configuration-tester']->isInstalled()) { + if (!$app['phraseanet.configuration-tester']->isBlank()) { + if ('setup_upgrade_instructions' !== $app['request']->attributes->get('_route')) { + return $app->redirectPath('setup_upgrade_instructions'); + } + } + } elseif (!$app['phraseanet.configuration-tester']->isBlank()) { return $app->redirectPath('homepage'); } } else { diff --git a/lib/Alchemy/Phrasea/Controller/Setup.php b/lib/Alchemy/Phrasea/Controller/Setup.php index 896e7de61b..ff17e751f1 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup.php +++ b/lib/Alchemy/Phrasea/Controller/Setup.php @@ -37,6 +37,9 @@ class Setup implements ControllerProviderInterface $controllers->get('/installer/', 'controller.setup:rootInstaller') ->bind('install_root'); + $controllers->get('/upgrade-instructions/', 'controller.setup:displayUpgradeInstructions') + ->bind('setup_upgrade_instructions'); + $controllers->get('/installer/step2/', 'controller.setup:getInstallForm') ->bind('install_step2'); @@ -70,6 +73,14 @@ class Setup implements ControllerProviderInterface ); } + public function displayUpgradeInstructions(Application $app, Request $request) + { + return $app['twig']->render('/setup/upgrade-instructions.html.twig', array( + 'locale' => $app['locale'], + 'available_locales' => Application::getAvailableLanguages(), + )); + } + public function getInstallForm(Application $app, Request $request) { $warnings = array(); diff --git a/templates/web/setup/upgrade-instructions.html.twig b/templates/web/setup/upgrade-instructions.html.twig new file mode 100644 index 0000000000..ffd11658da --- /dev/null +++ b/templates/web/setup/upgrade-instructions.html.twig @@ -0,0 +1,38 @@ +{% extends '/setup/wrapper.html.twig' %} + +{% block content %} +
+ + + + +
+
+

+ Upgrade Instructions +

+

+ This Phraseanet install requires an upgrade. +

+ + + + +
+ Please run the following command at your application install root. + + bin/setup system:upgrade + +
+
+
+ + + + +
+
+
+
+
+{% endblock %} diff --git a/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php b/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php index 29979b8c29..b7872d3d81 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/SetupTest.php @@ -39,6 +39,9 @@ class SetupTest extends \Silex\WebTestCase public function testRouteSlashWhenInstalled() { + $this->app['phraseanet.configuration-tester']->expects($this->once()) + ->method('isInstalled') + ->will($this->returnValue(true)); $this->app['phraseanet.configuration-tester']->expects($this->once()) ->method('isBlank') ->will($this->returnValue(false)); @@ -50,6 +53,22 @@ class SetupTest extends \Silex\WebTestCase $this->assertEquals('/login/', $response->headers->get('location')); } + public function testRouteInstructionsWhenUpgradeRequired() + { + $this->app['phraseanet.configuration-tester']->expects($this->once()) + ->method('isInstalled') + ->will($this->returnValue(false)); + $this->app['phraseanet.configuration-tester']->expects($this->once()) + ->method('isBlank') + ->will($this->returnValue(false)); + + $client = $this->createClient(); + $crawler = $client->request('GET', '/setup/'); + $response = $client->getResponse(); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertEquals('/setup/upgrade-instructions/', $response->headers->get('location')); + } + public function testRouteSetupInstaller() { $client = $this->createClient();