Skip to content

Commit 190d0ae

Browse files
author
Stanislav Idolov
authored
ENGCOM-2240: Remove PDF files after generation #16401
2 parents 480b3a1 + 014cb45 commit 190d0ae

File tree

13 files changed

+119
-15
lines changed

13 files changed

+119
-15
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/Pdfcreditmemos.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ public function __construct(
7474
*/
7575
public function massAction(AbstractCollection $collection)
7676
{
77+
$pdf = $this->pdfCreditmemo->getPdf($collection);
78+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
79+
7780
return $this->fileFactory->create(
7881
sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
79-
$this->pdfCreditmemo->getPdf($collection)->render(),
82+
$fileContent,
8083
DirectoryList::VAR_DIR,
8184
'application/pdf'
8285
);

app/code/Magento/Sales/Controller/Adminhtml/Creditmemo/AbstractCreditmemo/PrintAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct(
5353

5454
/**
5555
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
56+
* @throws \Exception
5657
*/
5758
public function execute()
5859
{
@@ -69,9 +70,11 @@ public function execute()
6970
$date = $this->_objectManager->get(
7071
\Magento\Framework\Stdlib\DateTime\DateTime::class
7172
)->date('Y-m-d_H-i-s');
73+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
74+
7275
return $this->_fileFactory->create(
7376
\creditmemo::class . $date . '.pdf',
74-
$pdf->render(),
77+
$fileContent,
7578
DirectoryList::VAR_DIR,
7679
'application/pdf'
7780
);

app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/Pdfinvoices.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ public function __construct(
7575
*/
7676
public function massAction(AbstractCollection $collection)
7777
{
78+
$pdf = $this->pdfInvoice->getPdf($collection);
79+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
80+
7881
return $this->fileFactory->create(
7982
sprintf('invoice%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
80-
$this->pdfInvoice->getPdf($collection)->render(),
83+
$fileContent,
8184
DirectoryList::VAR_DIR,
8285
'application/pdf'
8386
);

app/code/Magento/Sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function __construct(
4545

4646
/**
4747
* @return ResponseInterface|void
48+
* @throws \Exception
4849
*/
4950
public function execute()
5051
{
@@ -58,9 +59,11 @@ public function execute()
5859
$date = $this->_objectManager->get(
5960
\Magento\Framework\Stdlib\DateTime\DateTime::class
6061
)->date('Y-m-d_H-i-s');
62+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
63+
6164
return $this->_fileFactory->create(
6265
'invoice' . $date . '.pdf',
63-
$pdf->render(),
66+
$fileContent,
6467
DirectoryList::VAR_DIR,
6568
'application/pdf'
6669
);

app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function __construct(
7676
*
7777
* @param AbstractCollection $collection
7878
* @return ResponseInterface|ResultInterface
79+
* @throws \Exception
7980
*/
8081
protected function massAction(AbstractCollection $collection)
8182
{
@@ -85,9 +86,12 @@ protected function massAction(AbstractCollection $collection)
8586
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
8687
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
8788
}
89+
$pdf = $this->pdfCreditmemo->getPdf($creditmemoCollection->getItems());
90+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
91+
8892
return $this->fileFactory->create(
8993
sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
90-
$this->pdfCreditmemo->getPdf($creditmemoCollection->getItems())->render(),
94+
$fileContent,
9195
DirectoryList::VAR_DIR,
9296
'application/pdf'
9397
);

app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfdocs.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public function __construct(
113113
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
114114
*
115115
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
116+
* @throws \Exception
116117
*/
117118
protected function massAction(AbstractCollection $collection)
118119
{
@@ -142,10 +143,11 @@ protected function massAction(AbstractCollection $collection)
142143
foreach ($documents as $document) {
143144
$pdf->pages = array_merge($pdf->pages, $document->pages);
144145
}
146+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
145147

146148
return $this->fileFactory->create(
147149
sprintf('docs%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
148-
$pdf->render(),
150+
$fileContent,
149151
DirectoryList::VAR_DIR,
150152
'application/pdf'
151153
);

app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function __construct(
7575
*
7676
* @param AbstractCollection $collection
7777
* @return ResponseInterface|ResultInterface
78+
* @throws \Exception
7879
*/
7980
protected function massAction(AbstractCollection $collection)
8081
{
@@ -83,9 +84,12 @@ protected function massAction(AbstractCollection $collection)
8384
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
8485
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
8586
}
87+
$pdf = $this->pdfInvoice->getPdf($invoicesCollection->getItems());
88+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
89+
8690
return $this->fileFactory->create(
8791
sprintf('invoice%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
88-
$this->pdfInvoice->getPdf($invoicesCollection->getItems())->render(),
92+
$fileContent,
8993
DirectoryList::VAR_DIR,
9094
'application/pdf'
9195
);

app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfshipments.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function __construct(
7777
*
7878
* @param AbstractCollection $collection
7979
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
80+
* @throws \Exception
8081
*/
8182
protected function massAction(AbstractCollection $collection)
8283
{
@@ -87,9 +88,13 @@ protected function massAction(AbstractCollection $collection)
8788
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
8889
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
8990
}
91+
92+
$pdf = $this->pdfShipment->getPdf($shipmentsCollection->getItems());
93+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
94+
9095
return $this->fileFactory->create(
9196
sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
92-
$this->pdfShipment->getPdf($shipmentsCollection->getItems())->render(),
97+
$fileContent,
9398
DirectoryList::VAR_DIR,
9499
'application/pdf'
95100
);

app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/Pdfshipments.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,12 @@ public function __construct(
7070
*/
7171
public function massAction(AbstractCollection $collection)
7272
{
73+
$pdf = $this->pdfShipment->getPdf($collection);
74+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
75+
7376
return $this->fileFactory->create(
7477
sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
75-
$this->pdfShipment->getPdf($collection)->render(),
78+
$fileContent,
7679
DirectoryList::VAR_DIR,
7780
'application/pdf'
7881
);

app/code/Magento/Sales/Controller/Adminhtml/Shipment/AbstractShipment/PrintAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function __construct(
4848

4949
/**
5050
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Forward
51+
* @throws \Exception
5152
*/
5253
public function execute()
5354
{
@@ -63,9 +64,11 @@ public function execute()
6364
$date = $this->_objectManager->get(
6465
\Magento\Framework\Stdlib\DateTime\DateTime::class
6566
)->date('Y-m-d_H-i-s');
67+
$fileContent = ['type' => 'string', 'value' => $pdf->render(), 'rm' => true];
68+
6669
return $this->_fileFactory->create(
6770
'packingslip' . $date . '.pdf',
68-
$pdf->render(),
71+
$fileContent,
6972
DirectoryList::VAR_DIR,
7073
'application/pdf'
7174
);

0 commit comments

Comments
 (0)