Skip to content

Commit 547d3a5

Browse files
ACPT-1742
* Error\ProcessorFactory now uses existing ObjectManager when it exists This is required for compatiblity with ApplicationServer * Adding metadata to HTTP Response in Error Processor. * This new metadata is checked in Magento/PageCache/Model/App/Response/HttpPlugin to avoid caching errors, and avoid race condition * Changed usage of "require_once" to "require" in several places to make compatible with ApplicationServer
1 parent 34a21e8 commit 547d3a5

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

app/code/Magento/PageCache/Model/App/Response/HttpPlugin.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ class HttpPlugin
2222
*/
2323
public function beforeSendResponse(HttpResponse $subject)
2424
{
25-
if ($subject instanceof NotCacheableInterface || $subject->headersSent()) {
25+
if (
26+
$subject instanceof NotCacheableInterface
27+
|| $subject->headersSent()
28+
|| $subject->setMetadata("NotCacheable")
29+
) {
2630
return;
2731
}
28-
2932
$subject->sendVary();
3033
}
3134
}

pub/errors/default/page.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</head>
2020
<body>
2121
<main class="page-main">
22-
<?php require_once $contentTemplate; ?>
22+
<?php require $contentTemplate; ?>
2323
</main>
2424
</body>
2525
</html>

pub/errors/processor.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,25 +188,23 @@ public function __construct(
188188
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
189189
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
190190
$this->documentRoot = $documentRoot ?? ObjectManager::getInstance()->get(DocumentRoot::class);
191-
192191
if (!empty($_SERVER['SCRIPT_NAME'])) {
193192
if (in_array(basename($_SERVER['SCRIPT_NAME'], '.php'), ['404', '503', 'report'])) {
194193
$this->_scriptName = dirname($_SERVER['SCRIPT_NAME']);
195194
} else {
196195
$this->_scriptName = $_SERVER['SCRIPT_NAME'];
197196
}
198197
}
199-
200198
$this->_indexDir = $this->_getIndexDir();
201199
$this->_root = is_dir($this->_indexDir . 'app');
202-
203200
$this->_prepareConfig();
204201
if (isset($_GET['skin'])) {
205202
$this->_setSkin($_GET['skin']);
206203
}
207204
if (isset($_GET['id'])) {
208205
$this->loadReport($_GET['id']);
209206
}
207+
$this->response->setMetadata("NotCacheable", true);
210208
}
211209

212210
/**
@@ -449,7 +447,7 @@ protected function _renderPage($template)
449447
$html = '';
450448
if ($baseTemplate && $contentTemplate) {
451449
ob_start();
452-
require_once $baseTemplate;
450+
require $baseTemplate;
453451
$html = ob_get_clean();
454452
}
455453
return $html;

pub/errors/processorFactory.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ class ProcessorFactory
2020
*/
2121
public function createProcessor()
2222
{
23-
$objectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER);
24-
$objectManager = $objectManagerFactory->create($_SERVER);
25-
$response = $objectManager->create(\Magento\Framework\App\Response\Http::class);
26-
return new Processor($response);
23+
try {
24+
$objectManager = AppObjectManager::getInstance();
25+
return $objectManager->create(Processor::class);
26+
} catch (\RuntimeException $exception) {
27+
$objectManagerFactory = \Magento\Framework\App\Bootstrap::createObjectManagerFactory(BP, $_SERVER);
28+
$objectManager = $objectManagerFactory->create($_SERVER);
29+
$response = $objectManager->create(\Magento\Framework\App\Response\Http::class);
30+
return new Processor($response);
31+
}
2732
}
2833
}

pub/get.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@
6262
$fileRelativePath = str_replace(rtrim($mediaDirectory, '/') . '/', '', $fileAbsolutePath);
6363

6464
if (!$isAllowed($fileRelativePath, $allowedResources)) {
65-
require_once 'errors/404.php';
65+
require 'errors/404.php';
6666
exit;
6767
}
6868

6969
if (is_readable($fileAbsolutePath)) {
7070
if (is_dir($fileAbsolutePath)) {
71-
require_once 'errors/404.php';
71+
require 'errors/404.php';
7272
exit;
7373
}
7474

0 commit comments

Comments
 (0)