From 602cdf43ee0fb860b031a4eed468d7192cc0659f Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Sun, 18 Apr 2021 23:17:48 +0200 Subject: [PATCH] add configurable debug mode, exports do execute SELECT queries only --- .../Controller/Admin/d3ExportWizard.php | 40 +++++++++++-------- src/Application/Model/ExportBase.php | 25 ++++++++++++ .../views/admin/de/d3DataWizard_lang.php | 5 +++ src/metadata.php | 15 ++++++- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/src/Application/Controller/Admin/d3ExportWizard.php b/src/Application/Controller/Admin/d3ExportWizard.php index 596939e..efb015f 100644 --- a/src/Application/Controller/Admin/d3ExportWizard.php +++ b/src/Application/Controller/Admin/d3ExportWizard.php @@ -16,19 +16,10 @@ namespace D3\DataWizard\Application\Controller\Admin; use D3\DataWizard\Application\Model\Configuration; -use D3\DataWizard\Application\Model\Exports\activeArticlesInactiveCategory; -use D3\DataWizard\Application\Model\Exports\articlesWithoutManufacturers; -use D3\DataWizard\Application\Model\Exports\emptyCategories; -use D3\DataWizard\Application\Model\Exports\gappedArticleImages; -use D3\DataWizard\Application\Model\Exports\inactiveCategories; -use D3\DataWizard\Application\Model\Exports\inactiveParentCategory; -use D3\DataWizard\Application\Model\Exports\noArticleTextSet; -use D3\DataWizard\Application\Model\Exports\unreleasedRatings; -use D3\DataWizard\Application\Model\Exports\wrongArticlePrice; +use Doctrine\DBAL\DBALException; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; use OxidEsales\Eshop\Core\Exception\StandardException; use OxidEsales\Eshop\Core\Registry; -use OxidEsales\Eshop\Core\UtilsView; class d3ExportWizard extends AdminDetailsController { @@ -54,16 +45,31 @@ class d3ExportWizard extends AdminDetailsController return $this->configuration->getExportsByGroup($group); } + /** + * @throws DBALException + */ public function doExport() { - $id = Registry::getRequest()->getRequestEscapedParameter('exportid'); - $this->configuration->getExportById($id)->run(); + try { + $id = Registry::getRequest()->getRequestEscapedParameter('exportid'); + $export = $this->configuration->getExportById($id); - $oEx = oxNew( - StandardException::class, - Registry::getLang()->translateString('D3_DATAWIZARD_ERR_NOEXPORTCONTENT') - ); - Registry::get(UtilsView::class)->addErrorToDisplay($oEx); + if (Registry::getConfig()->getConfigParam('d3datawizard_debug')) { + throw oxNew( + StandardException::class, + $export->getQuery() + ); + } + + $export->run(); + + throw oxNew( + StandardException::class, + Registry::getLang()->translateString('D3_DATAWIZARD_ERR_NOEXPORTCONTENT') + ); + } catch (StandardException $e) { + Registry::getUtilsView()->addErrorToDisplay($e); + } } public function getUserMessages() diff --git a/src/Application/Model/ExportBase.php b/src/Application/Model/ExportBase.php index da037c5..fb10aca 100644 --- a/src/Application/Model/ExportBase.php +++ b/src/Application/Model/ExportBase.php @@ -16,11 +16,36 @@ namespace D3\DataWizard\Application\Model; use D3\ModCfg\Application\Model\d3database; +use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception; +use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException; +use Doctrine\DBAL\DBALException; +use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; +use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; +use OxidEsales\Eshop\Core\Exception\StandardException; +use OxidEsales\Eshop\Core\Registry; abstract class ExportBase implements QueryBase { + /** + * @throws StandardException + * @throws d3ShopCompatibilityAdapterException + * @throws d3_cfg_mod_exception + * @throws DBALException + * @throws DatabaseConnectionException + * @throws DatabaseErrorException + */ public function run() { + $query = trim($this->getQuery()); + + if (strtolower(substr($query, 0, 6)) !== 'select') { + /** @var StandardException $e */ + throw oxNew( + StandardException::class, + $this->getTitle().' - '.Registry::getLang()->translateString('D3_DATAWIZARD_EXPORT_NOSELECT') + ); + } + d3database::getInstance()->downloadExportCsvByQuery($this->getExportFilename(), $this->getQuery()); } diff --git a/src/Application/views/admin/de/d3DataWizard_lang.php b/src/Application/views/admin/de/d3DataWizard_lang.php index 25e1d8f..02ca429 100644 --- a/src/Application/views/admin/de/d3DataWizard_lang.php +++ b/src/Application/views/admin/de/d3DataWizard_lang.php @@ -26,6 +26,9 @@ $aLang = array( 'd3mxDataWizard' => ' Data Wizard', 'd3mxDataWizard_Export' => 'Exporte', + 'SHOP_MODULE_GROUP_d3datawizard_general' => 'Grundeinstellungen', + 'SHOP_MODULE_d3datawizard_debug' => 'zeigt Abfragen anstatt diese auszuführen', + 'D3_DATAWIZARD_GROUP_ARTICLES' => 'Artikel', 'D3_DATAWIZARD_GROUP_CATEGORIES' => 'Kategorien', 'D3_DATAWIZARD_GROUP_REMARKS' => 'Bewertungen', @@ -34,6 +37,8 @@ $aLang = array( 'D3_DATAWIZARD_EXPORT_SUBMIT' => 'Export starten', + 'D3_DATAWIZARD_EXPORT_NOSELECT' => 'Export kann nicht ausgeführt werden. Exporte erfordern SELECT Query.', + 'D3_DATAWIZARD_ERR_NOEXPORT_INSTALLED' => 'Es sind keine Exporte installiert oder aktiviert.', 'D3_DATAWIZARD_ERR_NOEXPORTCONTENT' => 'Export ist leer, kein Inhalt zum Download verfügbar' diff --git a/src/metadata.php b/src/metadata.php index 04efeb7..9540f2b 100644 --- a/src/metadata.php +++ b/src/metadata.php @@ -17,12 +17,15 @@ */ $sMetadataVersion = '2.1'; +$sModuleId = 'd3datawizard'; +$logo = '(D3)'; + /** * Module information */ $aModule = [ - 'id' => 'd3datawizard', - 'title' => '(D3) Data Wizard framework', + 'id' => $sModuleId, + 'title' => $logo.' Data Wizard framework', 'description' => [ 'de' => '', 'en' => '', @@ -40,5 +43,13 @@ $aModule = [ 'templates' => [ 'd3ExportWizard.tpl' => 'd3/datawizard/Application/views/admin/tpl/d3ExportWizard.tpl', ], + 'settings' => [ + [ + 'group' => $sModuleId.'_general', + 'name' => $sModuleId.'_debug', + 'type' => 'bool', + 'value' => false + ], + ], 'blocks' => [] ];