From bc29344c97661d333339757cbcb7b2e6bb7e8e8d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Thu, 13 Jun 2013 15:53:00 +0200 Subject: [PATCH] Blocking installation if a configuration file exists. No twig cache during installation. --- main/install/index.php | 23 ++++++++++++++++++----- main/install/templates/error.tpl | 6 ++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 main/install/templates/error.tpl diff --git a/main/install/index.php b/main/install/index.php index 4f08f2d308..0a0fb3df2e 100644 --- a/main/install/index.php +++ b/main/install/index.php @@ -39,7 +39,7 @@ $app['root_sys'] = dirname(dirname(__DIR__)).'/'; // Registering services -$app['debug'] = true; +$app['debug'] = false; $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new Silex\Provider\FormServiceProvider()); $app->register(new Silex\Provider\SessionServiceProvider()); @@ -69,7 +69,8 @@ $app->register( 'charset' => 'utf-8', 'strict_variables' => false, 'autoescape' => true, - 'cache' => $app['debug'] ? false : $app['twig.cache.path'], + //'cache' => $app['debug'] ? false : $app['twig.cache.path'], + 'cache' => false, // no cache during installation sorry 'optimizations' => -1, // turn on optimizations with -1 ) ) @@ -426,17 +427,29 @@ $app->get('/finish', function() use($app) { return $app['twig']->render('finish.tpl', array('output' => $output)); })->bind('finish'); +// Middlewares. +$app->before( + function () use ($app) { + if (file_exists($app['root_sys'].'config/configuration.php') || file_exists($app['root_sys'].'config/configuration.yml')) { + return $app->abort(500, "A Chamilo installation was found. You can't reinstall."); + } + } +); -$app->error(function (\Exception $e, $code) { +// Errors +$app->error(function (\Exception $e, $code) use ($app) { switch ($code) { case 404: $message = 'The requested page could not be found.'; break; default: - $message = 'We are sorry, but something went terribly wrong.'; + // $message = 'We are sorry, but something went terribly wrong.'; + $message = $e->getMessage(); } + $app['twig']->addGlobal('code', $code); + $app['twig']->addGlobal('message', $message); - return new Response($message); + return $app['twig']->render('error.tpl'); }); if (PHP_SAPI == 'cli') { diff --git a/main/install/templates/error.tpl b/main/install/templates/error.tpl new file mode 100644 index 0000000000..aa11266700 --- /dev/null +++ b/main/install/templates/error.tpl @@ -0,0 +1,6 @@ +{% extends 'layout.tpl' %} + +{% block content %} + {{ code }} {{ message }} +{% endblock %} +