Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Ensure everything gets flushed when flushing from sake #11436

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion _config/requestprocessors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SilverStripe\Core\Injector\Injector:
TrustedProxyMiddleware: '%$SilverStripe\Control\Middleware\TrustedProxyMiddleware'
AllowedHostsMiddleware: '%$SilverStripe\Control\Middleware\AllowedHostsMiddleware'
SessionMiddleware: '%$SilverStripe\Control\Middleware\SessionMiddleware'
FlushMiddleware: '%$SilverStripe\Control\Middleware\FlushMiddleware'
ChangeDetectionMiddleware: '%$SilverStripe\Control\Middleware\ChangeDetectionMiddleware'
HTTPCacheControleMiddleware: '%$SilverStripe\Control\Middleware\HTTPCacheControlMiddleware'
CanonicalURLMiddleware: '%$SilverStripe\Control\Middleware\CanonicalURLMiddleware'
Expand Down
38 changes: 0 additions & 38 deletions src/Control/Middleware/FlushMiddleware.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/Control/Middleware/HTTPCacheControlMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Resettable;
use SilverStripe\ORM\FieldType\DBDatetime;

Expand All @@ -35,6 +36,12 @@ class HTTPCacheControlMiddleware implements HTTPMiddleware, Resettable
*/
public function process(HTTPRequest $request, callable $delegate)
{
// Disable cache when flushing
$kernel = Injector::inst()->get(Kernel::class);
if ($kernel->isFlushed()) {
$this->disableCache(true);
}

try {
$response = $delegate($request);
} catch (HTTPResponse_Exception $ex) {
Expand Down
8 changes: 8 additions & 0 deletions src/Core/CoreKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function boot($flush = false)
$this->validateDatabase();

$this->setBooted(true);

// Flush everything else that can be flushed, now that we're booted.
if ($flush) {
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
/** @var Flushable|string $class */
$class::flush();
}
}
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/Core/Flushable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace SilverStripe\Core;

use SilverStripe\Control\Middleware\FlushMiddleware;

/**
* Provides an interface for classes to implement their own flushing functionality
* whenever flush=1 is requested.
Expand All @@ -12,11 +10,9 @@ interface Flushable
{

/**
* This function is triggered early in the request if the "flush" query
* parameter has been set. Each class that implements Flushable implements
* This function is triggered early in the request if the kernel gets flushed.
* Each class that implements Flushable implements
* this function which looks after it's own specific flushing functionality.
*
* @see FlushMiddleware
*/
public static function flush();
}
7 changes: 0 additions & 7 deletions src/Forms/HTMLEditor/TinyMCECombinedGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,6 @@ public function generateFilename(TinyMCEConfig $config)
return $url;
}

/**
* This function is triggered early in the request if the "flush" query
* parameter has been set. Each class that implements Flushable implements
* this function which looks after it's own specific flushing functionality.
*
* @see FlushMiddleware
*/
public static function flush()
{
$dir = dirname(static::config()->get('filename_base') ?? '');
Expand Down
26 changes: 0 additions & 26 deletions tests/php/Control/FlushMiddlewareTest.php

This file was deleted.

15 changes: 14 additions & 1 deletion tests/php/Core/KernelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use ReflectionClass;
use SilverStripe\ORM\DB;
use ReflectionObject;
use SilverStripe\Core\Tests\KernelTest\TestFlushable;

class KernelTest extends SapphireTest
{
Expand Down Expand Up @@ -85,7 +86,7 @@ public function testInvalidConfigDetection()

$kernel->getConfigLoader()->getManifest();
}

public function testReplicaDatabaseVarsLoaded()
{
// Set environment variables for a fake replica database
Expand Down Expand Up @@ -113,4 +114,16 @@ public function testReplicaDatabaseVarsLoaded()
'password' => 'hi_people',
], $configs['replica_01']);
}

public function testImplementorsAreCalled()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the exact test (with some code quality improvements) that used to live in FlushMiddlewareTest

{
TestFlushable::$flushed = false;

$kernel = Injector::inst()->get(Kernel::class);
$kernel->boot(true);
$this->assertTrue(TestFlushable::$flushed);

// reset the kernel Flush flag
$kernel->boot();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace SilverStripe\Control\Tests\FlushMiddlewareTest;
namespace SilverStripe\Core\Tests\KernelTest;

use SilverStripe\Core\Flushable;
use SilverStripe\Dev\TestOnly;
Expand Down