diff --git a/Application/Model/Exceptions/ExportFileException.php b/Application/Model/Exceptions/ExportFileException.php new file mode 100644 index 0000000..dae1118 --- /dev/null +++ b/Application/Model/Exceptions/ExportFileException.php @@ -0,0 +1,31 @@ + + * @link https://www.oxidmodule.com + */ + +declare(strict_types=1); + +namespace D3\DataWizard\Application\Model\Exceptions; + +use OxidEsales\Eshop\Core\Registry; + +class ExportFileException extends DataWizardException +{ + public function __construct($sMessage = "not set", $iCode = 0, Exception $previous = null ) + { + $sMessage = sprintf( + Registry::getLang()->translateString('D3_DATAWIZARD_ERR_EXPORTFILEERROR'), + $sMessage + ); + + parent::__construct($sMessage, $iCode, $previous ); + } +} \ No newline at end of file diff --git a/Application/Model/ExportBase.php b/Application/Model/ExportBase.php index 4e18c0b..8b816bc 100644 --- a/Application/Model/ExportBase.php +++ b/Application/Model/ExportBase.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace D3\DataWizard\Application\Model; +use D3\DataWizard\Application\Model\Exceptions\ExportFileException; use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException; use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge; use D3\ModCfg\Application\Model\d3filesystem; @@ -44,6 +45,7 @@ abstract class ExportBase implements QueryBase /** * @param string $format + * @param $path * * @throws DBALException * @throws DatabaseConnectionException @@ -53,8 +55,9 @@ abstract class ExportBase implements QueryBase * @throws StandardException * @throws d3ShopCompatibilityAdapterException * @throws d3_cfg_mod_exception + * @return string */ - public function run($format = RendererBridge::FORMAT_CSV) + public function run( string $format = RendererBridge::FORMAT_CSV, $path = null): string { if ($this->hasFormElements()) { /** @var Input $element */ @@ -70,11 +73,18 @@ abstract class ExportBase implements QueryBase $content = $this->renderContent($rows, $fieldNames, $format); /** @var $oFS d3filesystem */ - $oFS = oxNew(d3filesystem::class); - $oFS->startDirectDownload( - $oFS->filterFilename($this->getExportFileName($format)), - $content - ); + $oFS = oxNew( d3filesystem::class ); + if (is_null($path)) { + $oFS->startDirectDownload( $oFS->filterFilename( $this->getExportFileName( $format ) ), $content ); + } else { + $filePath = $oFS->trailingslashit($path).$oFS->filterFilename( $this->getExportFileName( $format ) ); + if (false === $oFS->createFile($filePath, $content,true)) { + throw oxNew(ExportFileException::class, $filePath); + } + return $filePath; + } + + return ''; } /** diff --git a/Application/views/admin/de/d3DataWizard_lang.php b/Application/views/admin/de/d3DataWizard_lang.php index 22fb0f6..e9ba312 100644 --- a/Application/views/admin/de/d3DataWizard_lang.php +++ b/Application/views/admin/de/d3DataWizard_lang.php @@ -48,6 +48,7 @@ $aLang = array( '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', 'D3_DATAWIZARD_ERR_NOSUITABLERENDERER' => 'kein Renderer für Format "%1$s" registriert', + 'D3_DATAWIZARD_ERR_EXPORTFILEERROR' => 'Exportdatei "%1$s" kann nicht angelegt werden', 'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES' => 'deaktivierte Kategorien, mit aktiven Artikel', 'D3_DATAWIZARD_EXPORTS_INACTIVECATEGORIES_TREE' => 'Baum',