From 85c21eb7821c5b05bf9efae7babcdd6a45fbf66d Mon Sep 17 00:00:00 2001 From: pbarroca <pbarroca@git-test.afi-sa.fr> Date: Mon, 21 May 2012 10:45:25 +0000 Subject: [PATCH] Nouvelle gestion d'erreur sans redirection pouvant induire une boucle de redirection --- .gitattributes | 2 + .../admin/controllers/ErrorController.php | 52 +++---------------- .../admin/views/scripts/error/error.phtml | 14 ++++- .../opac/controllers/ErrorController.php | 27 ++++++++++ .../opac/views/scripts/error/error.phtml | 0 index.php.default | 16 ++---- startup.php | 6 ++- tests/bootstrap_frontcontroller.php | 1 - 8 files changed, 55 insertions(+), 63 deletions(-) create mode 100644 application/modules/opac/controllers/ErrorController.php create mode 100644 application/modules/opac/views/scripts/error/error.phtml diff --git a/.gitattributes b/.gitattributes index 5865e8111c5..abd0abff6dc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -515,6 +515,7 @@ application/modules/opac/controllers/BibNumeriqueController.php -text application/modules/opac/controllers/BlogController.php -text application/modules/opac/controllers/CatalogueController.php -text application/modules/opac/controllers/CmsController.php -text +application/modules/opac/controllers/ErrorController.php -text application/modules/opac/controllers/EtagereController.php -text application/modules/opac/controllers/IndexController.php -text application/modules/opac/controllers/JavaController.php -text @@ -573,6 +574,7 @@ application/modules/opac/views/scripts/cms/articleviewbydate.phtml -text application/modules/opac/views/scripts/cms/error.phtml -text application/modules/opac/views/scripts/cms/reseau.phtml -text application/modules/opac/views/scripts/empty.phtml -text +application/modules/opac/views/scripts/error/error.phtml -text application/modules/opac/views/scripts/etagere/appelmenu.phtml -text application/modules/opac/views/scripts/footer.phtml -text application/modules/opac/views/scripts/head.phtml -text diff --git a/application/modules/admin/controllers/ErrorController.php b/application/modules/admin/controllers/ErrorController.php index 80132cc94fd..24450e518d8 100644 --- a/application/modules/admin/controllers/ErrorController.php +++ b/application/modules/admin/controllers/ErrorController.php @@ -18,50 +18,10 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ - -class Admin_ErrorController extends Zend_Controller_Action -{ - - function indexAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Erreur"; - - } - - function privilegesAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Vous n'avez pas les privilèges appropriés"; - } - - function databaseAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Problème d'accès à la base de données"; - } - - function bibAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Il y a encore des utilisateurs attachés à cette bibliothèque, suppression interdite"; - } - - function zoneAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Il y a encore des bibliothèques attachées à ce territoire , suppression interdite"; - } - - function cmsAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Il y a encore des objets attachées à cette catégorie , opération interdite"; - } - - function rssAction() - { - $this->view->title = "Erreur"; - $this->view->message = "Il y a encore des objets attachées à cette catégorie , opération interdite"; - } +class Admin_ErrorController extends Zend_Controller_Action { + public function errorAction() { + $this->view->titre = 'Une erreur est survenue'; + $this->view->errors = $this->_getParam('error_handler'); + $this->view->database = Zend_Registry::get('cfg')->sgbd->config->dbname; + } } \ No newline at end of file diff --git a/application/modules/admin/views/scripts/error/error.phtml b/application/modules/admin/views/scripts/error/error.phtml index d089e227c31..bcb9b85dc2e 100644 --- a/application/modules/admin/views/scripts/error/error.phtml +++ b/application/modules/admin/views/scripts/error/error.phtml @@ -1,2 +1,12 @@ -<br/> -<center><div class="error"><?php echo $this->traduire($this->message) ?></div></center> \ No newline at end of file +<h2>N'hésitez pas à contacter notre support</h2> +<div class="panel"> +Par courriel (de préférence) : <a href="mailto:hotline@afi-sa.fr">hotline@afi-sa.fr</a><br> +Par téléphone : 01.60.17.12.34</div> +<a href="javascript:$('#error_tech').toggle();">Voir le détail technique de l'erreur >></a> +<div class="panel" id="error_tech" style="display:none;overflow:auto;"> + <strong>Erreur :</strong> <?php echo $this->escape($this->errors->exception->getMessage()); ?><br> + <strong>Date :</strong> <?php echo date('c');?><br> + <strong>Pile d'appel :</strong> <pre><code><?php echo $this->escape($this->errors->exception->getTraceAsString()); ?></code></pre><br> + <strong>Base de données : </strong> <?php echo $this->escape($this->database);?><br> + <strong>Version : </strong> <?php echo $this->escape(VERSION_PERGAME);?><br> +</div> \ No newline at end of file diff --git a/application/modules/opac/controllers/ErrorController.php b/application/modules/opac/controllers/ErrorController.php new file mode 100644 index 00000000000..76bbf8f916b --- /dev/null +++ b/application/modules/opac/controllers/ErrorController.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class ErrorController extends Zend_Controller_Action { + public function errorAction() { + $this->_response->setHttpResponseCode(500); + $this->_response->clearBody(); + $this->_helper->getHelper('viewRenderer')->setLayoutScript('empty.phtml'); + } +} \ No newline at end of file diff --git a/application/modules/opac/views/scripts/error/error.phtml b/application/modules/opac/views/scripts/error/error.phtml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/index.php.default b/index.php.default index 4c69107b2ab..2ba5944591e 100644 --- a/index.php.default +++ b/index.php.default @@ -24,8 +24,8 @@ if (!function_exists('xdebug_break')) { } set_include_path('.' . PATH_SEPARATOR . './library' -. PATH_SEPARATOR . '../ZendFramework-1.6.2/library' -. PATH_SEPARATOR . get_include_path()); + . PATH_SEPARATOR . '../ZendFramework-1.6.2/library' + . PATH_SEPARATOR . get_include_path()); // Includes de base include_once "local.php"; @@ -46,15 +46,7 @@ $frontController = setupOpac(); try { $frontController->dispatch(); -} catch(Zend_Controller_Action_Exception $e) { - $url='' ; - $request= $frontController->getRequest() ; - $module= $request->getModuleName() ; - $controller= $request->getControllerName() ; - if($module != 'default') $url= '/' . $module ; - if($controller != 'default') $url= $url . '/' . $controller ; - header("Location: " . BASE_URL . $url) ; +} catch(Exception $e) { + echo $e->getMessage(); } - - ?> \ No newline at end of file diff --git a/startup.php b/startup.php index a605dcb04be..00aa62c2113 100644 --- a/startup.php +++ b/startup.php @@ -171,13 +171,17 @@ function setupLanguage() { function setupDatabase($cfg) { // setup database $sql = Zend_Db::factory($cfg->sgbd->adapter, $cfg->sgbd->config->toArray()); + Zend_Db_Table::setDefaultAdapter($sql); + $afi_sql = new Class_Systeme_Sql( $cfg->sgbd->config->host, $cfg->sgbd->config->username, $cfg->sgbd->config->password, $cfg->sgbd->config->dbname); Zend_Registry::set('sql', $afi_sql); + + Zend_Db_Table::getDefaultAdapter()->query('set names "UTF8"'); } @@ -239,7 +243,6 @@ function setupMail($cfg) { function setupFrontController() { $front_controller = Zend_Controller_Front::getInstance() - ->throwExceptions(true) ->addModuleDirectory(MODULEDIRECTORY) ->addControllerDirectory(ROOT_PATH.'afi/application/modules/opacpriv/controllers','opacpriv') ->setDefaultModule('opac') @@ -251,7 +254,6 @@ function setupFrontController() { ->registerPlugin(new ZendAfi_Controller_Plugin_SelectionBib()) ->setParam('useDefaultControllerAlways', true); - return setupRoutes($front_controller); } diff --git a/tests/bootstrap_frontcontroller.php b/tests/bootstrap_frontcontroller.php index 60d8e5b408f..0a5a9c1a859 100644 --- a/tests/bootstrap_frontcontroller.php +++ b/tests/bootstrap_frontcontroller.php @@ -29,7 +29,6 @@ $_REQUEST["id_profil"] = $_SESSION["id_profil"] = 2; $_SERVER['HTTP_HOST'] = 'localhost'; $controller = Zend_Controller_Front::getInstance() - ->setParam('noErrorHandler', true) ->throwExceptions(true) ->addModuleDirectory('application/modules') ->setDefaultModule('opac') -- GitLab