add preAction and postAction calls to prevent wrong filenames because unset values

This commit is contained in:
Daniel Seifert 2020-08-13 14:50:48 +02:00
parent f0eb1423ee
commit 7d27e27764
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
2 changed files with 19 additions and 13 deletions

View File

@ -50,6 +50,14 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
$this->oSmarty = Registry::getUtilsView()->getSmarty();
}
public function runPreAction()
{
}
public function runPostAction()
{
}
/**
* @param $sFilename
* @param int $iSelLang
@ -77,8 +85,10 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
public function downloadPdf($iLanguage = 0)
{
try {
$this->runPreAction();
$sFilename = $this->getFilename();
$this->genPdf($sFilename, $iLanguage, self::PDF_DESTINATION_DOWNLOAD);
$this->runPostAction();
Registry::getUtils()->showMessageAndExit('');
} catch (pdfGeneratorExceptionAbstract $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
@ -95,12 +105,14 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
public function savePdfFile($path, $iLanguage = 0)
{
try {
$this->runPreAction();
$sFilename = $this->getFilename();
$this->genPdf(
rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$sFilename,
$iLanguage,
self::PDF_DESTINATION_FILE
);
$this->runPostAction();
} catch (pdfGeneratorExceptionAbstract $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e);
@ -116,8 +128,11 @@ abstract class pdfdocumentsGeneric extends Base implements genericInterface
public function getPdfContent($iLanguage = 0)
{
try {
$this->runPreAction();
$sFilename = $this->getFilename();
return $this->genPdf( $sFilename, $iLanguage, self::PDF_DESTINATION_STRING );
$ret = $this->genPdf( $sFilename, $iLanguage, self::PDF_DESTINATION_STRING );
$this->runPostAction();
return $ret;
} catch (pdfGeneratorExceptionAbstract $e) {
Registry::get(UtilsView::class)->addErrorToDisplay($e);
Registry::getLogger()->error($e);

View File

@ -43,22 +43,13 @@ class invoicePdf extends pdfdocumentsOrder implements pdfdocumentsOrderinvoiceIn
return 'invoice';
}
/**
* @param $sFilename
* @param int $iSelLang
* @param string $target
*
* @return mixed|string|void
* @throws Html2PdfException
* @throws noBaseObjectSetException
*/
public function genPdf( $sFilename, $iSelLang = 0, $target = 'I' )
public function runPreAction()
{
parent::runPreAction();
$this->setInvoiceNumber();
$this->setInvoiceDate();
$this->saveOrderOnChanges();
return parent::genPdf( $sFilename, $iSelLang, $target );
}
public function setInvoiceNumber()