Pdf: Restore previous state after rendering content

In case an exception occurs its output was previously merged
with the rendered content or even PDF..
This commit is contained in:
Johannes Meyer 2020-01-10 14:08:21 +01:00
parent c12da7b7ac
commit 5943e6bde9
2 changed files with 12 additions and 7 deletions

View File

@ -51,14 +51,19 @@ class Pdf
Environment::raiseExecutionTime(300);
$viewRenderer = $controller->getHelper('viewRenderer');
$controller->render(
$viewRenderer->getScriptAction(),
$viewRenderer->getResponseSegment(),
$viewRenderer->getNoController()
);
$layout = $controller->getHelper('layout')->setLayout('pdf');
$viewRenderer->postDispatch();
$layoutHelper = $controller->getHelper('layout');
$oldLayout = $layoutHelper->getLayout();
$layout = $layoutHelper->setLayout('pdf');
$layout->content = $controller->getResponse();
$html = $layout->render();
// Restore previous layout and reset content, to properly show errors
$controller->getResponse()->clearBody($viewRenderer->getResponseSegment());
$layoutHelper->setLayout($oldLayout);
$imgDir = Url::fromPath('img');
$html = preg_replace(
'~src="' . $imgDir . '/~',

View File

@ -484,8 +484,8 @@ class ActionController extends Zend_Controller_Action
}
if ($req->getParam('format') === 'pdf') {
$this->shutdownSession();
$this->sendAsPdf();
$this->shutdownSession();
exit;
}