add configurable debug mode, exports do execute SELECT queries only

This commit is contained in:
Daniel Seifert 2021-04-18 23:17:48 +02:00
parent c7bf1017d4
commit 602cdf43ee
Signed by: DanielS
GPG Key ID: 6A513E13AEE66170
4 changed files with 66 additions and 19 deletions

View File

@ -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()

View File

@ -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());
}

View File

@ -26,6 +26,9 @@ $aLang = array(
'd3mxDataWizard' => '<i class="fa fa-fw fas-hat-wizard"></i> 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'

View File

@ -17,12 +17,15 @@
*/
$sMetadataVersion = '2.1';
$sModuleId = 'd3datawizard';
$logo = '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em">';
/**
* Module information
*/
$aModule = [
'id' => 'd3datawizard',
'title' => '<img src="https://logos.oxidmodule.com/d3logo.svg" alt="(D3)" style="height:1em;width:1em"> 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' => []
];