From ae09cf88a5e516c4a6656c56890659ec091d669a Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 3 Nov 2021 10:16:39 +0100 Subject: [PATCH] enable controller based exception handling --- .../Controller/Admin/d3ActionWizard.php | 36 +++++++++------ .../Controller/Admin/d3ExportWizard.php | 44 +++++++++++++------ 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/Application/Controller/Admin/d3ActionWizard.php b/Application/Controller/Admin/d3ActionWizard.php index fb2334b..3c4e5a4 100644 --- a/Application/Controller/Admin/d3ActionWizard.php +++ b/Application/Controller/Admin/d3ActionWizard.php @@ -61,24 +61,34 @@ class d3ActionWizard extends AdminDetailsController public function runTask() { try { - $id = Registry::getRequest()->getRequestEscapedParameter('taskid'); - $action = $this->configuration->getActionById($id); - - [ $queryString, $parameters ] = $action->getQuery(); - - if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) { - throw oxNew( - DebugException::class, - d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters) - ); - } - - $action->run(); + $this->execute(); } catch (DataWizardException|DBALException|DatabaseErrorException $e) { + Registry::getLogger()->error($e->getMessage()); Registry::getUtilsView()->addErrorToDisplay($e); } } + /** + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + */ + protected function execute() + { + $id = Registry::getRequest()->getRequestEscapedParameter('taskid'); + $action = $this->configuration->getActionById($id); + + [ $queryString, $parameters ] = $action->getQuery(); + + if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) { + throw oxNew( + DebugException::class, + d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters) + ); + } + + $action->run(); + } + public function getUserMessages() { return null; diff --git a/Application/Controller/Admin/d3ExportWizard.php b/Application/Controller/Admin/d3ExportWizard.php index eb76d2e..d38e678 100644 --- a/Application/Controller/Admin/d3ExportWizard.php +++ b/Application/Controller/Admin/d3ExportWizard.php @@ -18,6 +18,8 @@ namespace D3\DataWizard\Application\Controller\Admin; use D3\DataWizard\Application\Model\Configuration; use D3\DataWizard\Application\Model\Exceptions\DataWizardException; use D3\DataWizard\Application\Model\Exceptions\DebugException; +use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException; +use D3\DataWizard\Application\Model\Exceptions\TaskException; use D3\ModCfg\Application\Model\d3database; use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception; use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; @@ -61,24 +63,40 @@ class d3ExportWizard extends AdminDetailsController public function runTask() { try { - $id = Registry::getRequest()->getRequestEscapedParameter('taskid'); - $export = $this->configuration->getExportById($id); - - [ $queryString, $parameters ] = $export->getQuery(); - - if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) { - throw oxNew( - DebugException::class, - d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters) - ); - } - - $export->run(Registry::getRequest()->getRequestEscapedParameter('format')); + $this->execute(); } catch (DataWizardException|DBALException|DatabaseErrorException $e) { + Registry::getLogger()->error($e->getMessage()); Registry::getUtilsView()->addErrorToDisplay($e); } } + /** + * @throws DBALException + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + * @throws StandardException + * @throws NoSuitableRendererException + * @throws TaskException + * @throws d3ShopCompatibilityAdapterException + * @throws d3_cfg_mod_exception + */ + protected function execute() + { + $id = Registry::getRequest()->getRequestEscapedParameter('taskid'); + $export = $this->configuration->getExportById($id); + + [ $queryString, $parameters ] = $export->getQuery(); + + if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) { + throw oxNew( + DebugException::class, + d3database::getInstance()->getPreparedStatementQuery($queryString, $parameters) + ); + } + + $export->run(Registry::getRequest()->getRequestEscapedParameter('format')); + } + public function getUserMessages() { return null;