Skip to content

Commit acd42b8

Browse files
committed
#24229: Don't disable FPC for maintenance, instead don't set public cache headers
- Removes the observer for disabling and re-enabling the FPC during maintenande mode switch - Disables setting public cache headers, if maintenance mode is enabled - phpcs:ignore entries were added in places where no actual code was changed by this commit, but static tests failed
1 parent c7ca62e commit acd42b8

File tree

6 files changed

+33
-285
lines changed

6 files changed

+33
-285
lines changed

app/code/Magento/PageCache/Model/Layout/LayoutPlugin.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,31 @@ class LayoutPlugin
2020
*/
2121
protected $response;
2222

23+
/**
24+
* @var \Magento\Framework\App\MaintenanceMode
25+
*/
26+
private $maintenanceMode;
27+
2328
/**
2429
* Constructor
2530
*
2631
* @param \Magento\Framework\App\ResponseInterface $response
27-
* @param \Magento\PageCache\Model\Config $config
32+
* @param \Magento\PageCache\Model\Config $config
33+
* @param \Magento\Framework\App\MaintenanceMode $maintenanceMode
2834
*/
2935
public function __construct(
3036
\Magento\Framework\App\ResponseInterface $response,
31-
\Magento\PageCache\Model\Config $config
37+
\Magento\PageCache\Model\Config $config,
38+
\Magento\Framework\App\MaintenanceMode $maintenanceMode
3239
) {
3340
$this->response = $response;
3441
$this->config = $config;
42+
$this->maintenanceMode = $maintenanceMode;
3543
}
3644

3745
/**
3846
* Set appropriate Cache-Control headers
47+
*
3948
* We have to set public headers in order to tell Varnish and Builtin app that page should be cached
4049
*
4150
* @param \Magento\Framework\View\Layout $subject
@@ -44,7 +53,7 @@ public function __construct(
4453
*/
4554
public function afterGenerateXml(\Magento\Framework\View\Layout $subject, $result)
4655
{
47-
if ($subject->isCacheable() && $this->config->isEnabled()) {
56+
if ($subject->isCacheable() && !$this->maintenanceMode->isOn() && $this->config->isEnabled()) {
4857
$this->response->setPublicHeaders($this->config->getTtl());
4958
}
5059
return $result;
@@ -68,6 +77,7 @@ public function afterGetOutput(\Magento\Framework\View\Layout $subject, $result)
6877
if ($isVarnish && $isEsiBlock) {
6978
continue;
7079
}
80+
// phpcs:ignore
7181
$tags = array_merge($tags, $block->getIdentities());
7282
}
7383
}

app/code/Magento/PageCache/Observer/SwitchPageCacheOnMaintenance.php

Lines changed: 0 additions & 108 deletions
This file was deleted.

app/code/Magento/PageCache/Observer/SwitchPageCacheOnMaintenance/PageCacheState.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
/**
1616
* Page Cache state.
17+
* @deprecated Originally used by now removed observer SwitchPageCacheOnMaintenance
1718
*/
1819
class PageCacheState
1920
{

app/code/Magento/PageCache/Test/Unit/Model/Layout/LayoutPluginTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class LayoutPluginTest extends \PHPUnit\Framework\TestCase
2727
*/
2828
protected $configMock;
2929

30+
/**
31+
* @var \Magento\Framework\App\MaintenanceMode|\PHPUnit\Framework\MockObject\MockObject
32+
*/
33+
private $maintenanceModeMock;
34+
3035
protected function setUp()
3136
{
3237
$this->layoutMock = $this->getMockForAbstractClass(
@@ -40,27 +45,33 @@ protected function setUp()
4045
);
4146
$this->responseMock = $this->createMock(\Magento\Framework\App\Response\Http::class);
4247
$this->configMock = $this->createMock(\Magento\PageCache\Model\Config::class);
48+
$this->maintenanceModeMock = $this->createMock(\Magento\Framework\App\MaintenanceMode::class);
4349

4450
$this->model = new \Magento\PageCache\Model\Layout\LayoutPlugin(
4551
$this->responseMock,
46-
$this->configMock
52+
$this->configMock,
53+
$this->maintenanceModeMock
4754
);
4855
}
4956

5057
/**
5158
* @param $cacheState
5259
* @param $layoutIsCacheable
60+
* @param $maintenanceModeIsEnabled
61+
*
5362
* @dataProvider afterGenerateXmlDataProvider
5463
*/
55-
public function testAfterGenerateXml($cacheState, $layoutIsCacheable)
64+
public function testAfterGenerateXml($cacheState, $layoutIsCacheable, $maintenanceModeIsEnabled)
5665
{
5766
$maxAge = 180;
5867
$result = 'test';
5968

6069
$this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue($layoutIsCacheable));
6170
$this->configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
71+
$this->maintenanceModeMock->expects($this->any())->method('isOn')
72+
->will($this->returnValue($maintenanceModeIsEnabled));
6273

63-
if ($layoutIsCacheable && $cacheState) {
74+
if ($layoutIsCacheable && $cacheState && !$maintenanceModeIsEnabled) {
6475
$this->configMock->expects($this->once())->method('getTtl')->will($this->returnValue($maxAge));
6576
$this->responseMock->expects($this->once())->method('setPublicHeaders')->with($maxAge);
6677
} else {
@@ -76,10 +87,11 @@ public function testAfterGenerateXml($cacheState, $layoutIsCacheable)
7687
public function afterGenerateXmlDataProvider()
7788
{
7889
return [
79-
'Full_cache state is true, Layout is cache-able' => [true, true],
80-
'Full_cache state is true, Layout is not cache-able' => [true, false],
81-
'Full_cache state is false, Layout is not cache-able' => [false, false],
82-
'Full_cache state is false, Layout is cache-able' => [false, true]
90+
'Full_cache state is true, Layout is cache-able' => [true, true, false],
91+
'Full_cache state is true, Layout is not cache-able' => [true, false, false],
92+
'Full_cache state is false, Layout is not cache-able' => [false, false, false],
93+
'Full_cache state is false, Layout is cache-able' => [false, true, false],
94+
'Full_cache state is true, Layout is cache-able, Maintenance mode is enabled' => [true, true, true],
8395
];
8496
}
8597

app/code/Magento/PageCache/Test/Unit/Observer/SwitchPageCacheOnMaintenanceTest.php

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)