diff --git a/local/languages/de.ini b/local/languages/de.ini index 336804999db2ea1751131028bddf2b6ce05e8452..a0df05da337b578678b3cd075ffd15e616097035 100644 --- a/local/languages/de.ini +++ b/local/languages/de.ini @@ -710,6 +710,8 @@ email_selected_favorites = "Ausgewählte Favoriten per E-Mail versenden" email_sending = "Nachricht wird gesendet..." email_success = "Nachricht versendet" error_inconsistent_parameters = "Leider ist ein Fehler aufgetreten. Es wurden widersprüchliche Angaben entdeckt." +error_timeout = "Ihre Abfrage dauerte zu lange und wurde abgebrochen. Bitte versuchen Sie, die Seite neu zu laden oder stellen Sie eine einfachere Abfrage. Falls Ihre Abfrage bereits einfach war, schicken Sie uns bitte eine Nachricht mit der Abfrage (und ggf. URL) an <a href="%s">%s</a>, damit wir das Problem lösen können." +error_service_unavailable = "Die Suche ist vorübergehend nicht verfügbar. Bitte versuchen Sie es später noch einmal." errorcode_error = "Es ist ein Fehler aufgetreten" errorcode_http_status_error = "Kein Netzwerk vorhanden" errorcode_empty_response_error = "Keine Nachricht vom Lokalsystem erhalten" diff --git a/local/languages/en.ini b/local/languages/en.ini index d8e6fdb85caf98a2cfb20db7bd4fd76352411418..a2e3967518e5cd8f88eeb7f965f47fe2c6497887 100644 --- a/local/languages/en.ini +++ b/local/languages/en.ini @@ -698,6 +698,8 @@ email_selected_favorites = "E-mail Selected Favorites" email_sending = "Sending Message..." email_success = "Message Sent" error_inconsistent_parameters = "Sorry, an error has occurred. Inconsistent parameters detected" +error_timeout = "Your query was taking too long and has been canceled. Please try to reload the page or make a simpler query. If your query was already simple, please send us a message with the query (if possible add URL) to <a href="mailto:%s">%s</a>, so that we can solve the problem." +error_service_unavailable = "Sorry, Service Is Temporarily Unavailable. Please retry again later." errorcode_error = "Sorry, an error has occurred. Please try it again" errorcode_http_status_error = "No network available for the Integrated Library System" errorcode_empty_response_error = "No response received from the Integrated Library System" diff --git a/module/finc/Module.php b/module/finc/Module.php index 9472cd3c7d109f5f4a666a2c4b92e765355370e9..f27fae056f99f9bf2f42bc48225ada4f43e094b7 100644 --- a/module/finc/Module.php +++ b/module/finc/Module.php @@ -85,9 +85,10 @@ class Module * @param MvcEvent $e Event * * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function onBootstrap(MvcEvent $e) { + $bootstrapper = new Bootstrapper($e); + $bootstrapper->bootstrap(); } } diff --git a/module/finc/src/finc/Bootstrapper.php b/module/finc/src/finc/Bootstrapper.php new file mode 100644 index 0000000000000000000000000000000000000000..fa81aac9a1b6b0597a4971ec3082052d51ef6a68 --- /dev/null +++ b/module/finc/src/finc/Bootstrapper.php @@ -0,0 +1,101 @@ +<?php +/** + * VuFind Bootstrapper + * + * PHP version 7 + * + * Copyright (C) Leipzig University Library 2020. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Bootstrap + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +namespace finc; + +use Zend\Console\Console; + +/** + * Finc Bootstrapper + * + * @category VuFind + * @package Bootstrap + * @author Robert Lange <lange@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org Main Site + */ +class Bootstrapper extends \VuFind\Bootstrapper +{ + /** + * Bootstrap finc resources. + * + * @return void + */ + public function bootstrap() + { + // automatically call all methods starting with "init": + $methods = get_class_methods($this); + foreach ($methods as $method) { + if (substr($method, 0, 8) == 'initFinc') { + $this->$method(); + } + } + } + + /** + * Set up custom error page based on exception information. + * + * @return void + */ + protected function initFincCustomErrorView() + { + //custom error page not needed in console mode: + if (\Zend\Console\Console::isConsole()) { + return; + } + + $callback = function ($e) { + $exception = $e->getParam('exception'); + if (!$exception) { + return; + } + + $exceptionName = end( + explode('\\', get_class($e->getParam('exception'))) + ); + + $resolver = $e->getApplication() + ->getServiceManager()->get('Zend\View\Resolver\TemplatePathStack'); + + if (false === $resolver->resolve($template = "error/$exceptionName")) { + // custom error template does not exist + return; + } + + $model = new \Zend\View\Model\ViewModel( + [ + 'display_exceptions' => APPLICATION_ENV == 'development', + 'exception' => $e->getParam('exception'), + ] + ); + $model->setTemplate($template); + $e->setResult($model); + }; + + $this->events->attach('dispatch.error', $callback); + } +} diff --git a/themes/finc/templates/error/RuntimeException.phtml b/themes/finc/templates/error/RuntimeException.phtml new file mode 100644 index 0000000000000000000000000000000000000000..0e8933ecf5a1fd6c08db0c8152ad4ae3d42b05dc --- /dev/null +++ b/themes/finc/templates/error/RuntimeException.phtml @@ -0,0 +1,56 @@ +<!-- finc: RuntimeException --> +<?/* largely copied from /bootstrap3/templates/error/index.phtml #17035 - RL */?> +<?php + // Set page title. + $this->headTitle($this->translate('An error has occurred')); + + $this->layout()->breadcrumbs = '<li class="active">Error</li>'; +?> +<div class="alert alert-danger"> + <p><?=$this->transEsc('An error has occurred')?></p> + <p> + <?php if (strpos($exception->getMessage(), "nable to connect to") !== false): ?> + <?=$this->translate('error_service_unavailable')?> + <?php else: ?> + <p><?=$this->transEsc($this->message)?></p> + <?=$this->transEsc('Please contact the Library Reference Department for assistance')?> + <?php $supportEmail = $this->escapeHtmlAttr($this->systememail()); ?> + <a href="mailto:<?=$supportEmail?>"><?=$supportEmail?></a> + <?php endif; ?> + <br/> + </p> +</div> + +<?php if ($this->showInstallLink): ?> + <h2><a href="<?=$this->url('install-home')?>"><?=$this->transEsc('auto_configure_title', [], 'Auto Configure')?></a></h2> + <?=$this->transEsc('auto_configure_description', [], 'If this is a new installation, you may be able to fix the error using VuFind\'s Auto Configure tool.')?> + <h2><a href="<?=$this->url('upgrade-home')?>"><?=$this->transEsc('Upgrade VuFind')?></a></h2> + <?=$this->transEsc('upgrade_description', [], 'If you are upgrading a previous VuFind version, you can load your old settings with this tool.')?> +<?php endif; ?> + +<?php if (isset($this->display_exceptions) && $this->display_exceptions): ?> + <h2><?=$this->transEsc('Exception')?>:</h2> + <p> + <b><?=$this->transEsc('Message')?>:</b> <?=$this->escapeHtml($this->exception->getMessage())?> + </p> + + <h2><?=$this->transEsc('Backtrace')?>:</h2> + <pre><?=$this->exception->getTraceAsString()?> + </pre> + + <?php if ($e = $this->exception->getPrevious()): ?> + <h3>Previous exceptions:</h3> + <?php while ($e): ?> + <h4><?php echo get_class($e); ?></h4> + <p><?=$e->getMessage()?></p> + <pre><?=$e->getTraceAsString()?></pre> + <?php $e = $e->getPrevious(); ?> + <?php endwhile; ?> + <?php endif; ?> + + <?php if (isset($this->request)): ?> + <h2><?=$this->transEsc('error_page_parameter_list_heading')?>:</h2> + <pre><?=$this->escapeHtml(var_export($this->request->getParams(), true))?></pre> + <?php endif; ?> +<?php endif ?> +<!-- finc: RuntimeException - END --> diff --git a/themes/finc/templates/error/TimeoutException.phtml b/themes/finc/templates/error/TimeoutException.phtml new file mode 100644 index 0000000000000000000000000000000000000000..825b115fa32be971509d5288848b43123d394367 --- /dev/null +++ b/themes/finc/templates/error/TimeoutException.phtml @@ -0,0 +1,48 @@ +<!-- finc: TimeoutException --> +<?/* largely copied from /bootstrap3/templates/error/index.phtml #17035 - RL */?> +<?php + // Set page title. + $this->headTitle($this->translate('An error has occurred')); + + $this->layout()->breadcrumbs = '<li class="active">Error</li>'; +?> +<div class="alert alert-danger"> + <p> + <?=sprintf($this->translate('error_timeout'), $this->systememail(), $this->systememail())?> + <br/> + </p> +</div> + +<?php if ($this->showInstallLink): ?> + <h2><a href="<?=$this->url('install-home')?>"><?=$this->transEsc('auto_configure_title', [], 'Auto Configure')?></a></h2> + <?=$this->transEsc('auto_configure_description', [], 'If this is a new installation, you may be able to fix the error using VuFind\'s Auto Configure tool.')?> + <h2><a href="<?=$this->url('upgrade-home')?>"><?=$this->transEsc('Upgrade VuFind')?></a></h2> + <?=$this->transEsc('upgrade_description', [], 'If you are upgrading a previous VuFind version, you can load your old settings with this tool.')?> +<?php endif; ?> + +<?php if (isset($this->display_exceptions) && $this->display_exceptions): ?> + <h2><?=$this->transEsc('Exception')?>:</h2> + <p> + <b><?=$this->transEsc('Message')?>:</b> <?=$this->escapeHtml($this->exception->getMessage())?> + </p> + + <h2><?=$this->transEsc('Backtrace')?>:</h2> + <pre><?=$this->exception->getTraceAsString()?> + </pre> + + <?php if ($e = $this->exception->getPrevious()): ?> + <h3>Previous exceptions:</h3> + <?php while ($e): ?> + <h4><?php echo get_class($e); ?></h4> + <p><?=$e->getMessage()?></p> + <pre><?= $e->getTraceAsString()?></pre> + <?php $e = $e->getPrevious(); ?> + <?php endwhile; ?> + <?php endif; ?> + + <?php if (isset($this->request)): ?> + <h2><?=$this->transEsc('error_page_parameter_list_heading')?>:</h2> + <pre><?=$this->escapeHtml(var_export($this->request->getParams(), true))?></pre> + <?php endif; ?> +<?php endif ?> +<!-- finc: TimeoutException - END --> \ No newline at end of file