From faaebaeffb62fcdd1c4203299afd5b8c84eb466d Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 24 Jul 2023 13:46:50 +0200 Subject: [PATCH] Forward failed requests for routes with pending migrations --- application/controllers/ErrorController.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/application/controllers/ErrorController.php b/application/controllers/ErrorController.php index 580015b25..a22b040b7 100644 --- a/application/controllers/ErrorController.php +++ b/application/controllers/ErrorController.php @@ -3,6 +3,8 @@ namespace Icinga\Controllers; +use Icinga\Application\Hook\MigrationHook; +use Icinga\Application\MigrationManager; use Icinga\Exception\IcingaException; use Zend_Controller_Plugin_ErrorHandler; use Icinga\Application\Icinga; @@ -91,6 +93,22 @@ class ErrorController extends ActionController $this->getResponse()->setHttpResponseCode(403); break; default: + $mm = MigrationManager::instance(); + $action = $this->getRequest()->getActionName(); + $controller = $this->getRequest()->getControllerName(); + if ($action !== 'hint' && $controller !== 'migrations' && $mm->hasMigrations($moduleName)) { + // The view renderer from IPL web doesn't render the HTML content set in the respective + // controller if the error_handler request param is set, as it doesn't support error + // rendering. Since this error handler isn't caused by the migrations controller, we can + // safely unset this. + $this->setParam('error_handler', null); + $this->forward('hint', 'migrations', 'default', [ + MigrationHook::MIGRATION_PARAM => $moduleName + ]); + + return; + } + $this->getResponse()->setHttpResponseCode(500); $module = $modules->hasLoaded($moduleName) ? $modules->getModule($moduleName) : null; Logger::error("%s\n%s", $exception, IcingaException::getConfidentialTraceAsString($exception));