diff --git a/_config/requestprocessors.yml b/_config/requestprocessors.yml index abf0b6d5efa..e39b0e40db9 100644 --- a/_config/requestprocessors.yml +++ b/_config/requestprocessors.yml @@ -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' diff --git a/src/Control/Middleware/FlushMiddleware.php b/src/Control/Middleware/FlushMiddleware.php deleted file mode 100644 index c14fd319df6..00000000000 --- a/src/Control/Middleware/FlushMiddleware.php +++ /dev/null @@ -1,38 +0,0 @@ -get(Kernel::class); - if ((method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) { - // Disable cache when flushing - HTTPCacheControlMiddleware::singleton()->disableCache(true); - - foreach (ClassInfo::implementorsOf(Flushable::class) as $class) { - /** @var Flushable|string $class */ - $class::flush(); - } - } - - return $delegate($request); - } -} diff --git a/src/Control/Middleware/HTTPCacheControlMiddleware.php b/src/Control/Middleware/HTTPCacheControlMiddleware.php index c3da4f756c9..8f38305db07 100644 --- a/src/Control/Middleware/HTTPCacheControlMiddleware.php +++ b/src/Control/Middleware/HTTPCacheControlMiddleware.php @@ -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; @@ -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) { diff --git a/src/Core/CoreKernel.php b/src/Core/CoreKernel.php index ca9946f68a3..5626fd08082 100644 --- a/src/Core/CoreKernel.php +++ b/src/Core/CoreKernel.php @@ -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(); + } + } } /** diff --git a/src/Core/Flushable.php b/src/Core/Flushable.php index 7b30d3d3224..77f7992b1d4 100644 --- a/src/Core/Flushable.php +++ b/src/Core/Flushable.php @@ -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. @@ -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(); } diff --git a/src/Forms/HTMLEditor/TinyMCECombinedGenerator.php b/src/Forms/HTMLEditor/TinyMCECombinedGenerator.php index 0644c250eab..a9bbda3578c 100644 --- a/src/Forms/HTMLEditor/TinyMCECombinedGenerator.php +++ b/src/Forms/HTMLEditor/TinyMCECombinedGenerator.php @@ -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') ?? ''); diff --git a/tests/php/Control/FlushMiddlewareTest.php b/tests/php/Control/FlushMiddlewareTest.php deleted file mode 100644 index a553d14ba3f..00000000000 --- a/tests/php/Control/FlushMiddlewareTest.php +++ /dev/null @@ -1,26 +0,0 @@ -get(Kernel::class)->boot(true); - $this->get('/'); - $this->assertTrue(TestFlushable::$flushed); - - // reset the kernel Flush flag - Injector::inst()->get(Kernel::class)->boot(); - } -} diff --git a/tests/php/Core/KernelTest.php b/tests/php/Core/KernelTest.php index c779f349521..afb5b37a7a7 100644 --- a/tests/php/Core/KernelTest.php +++ b/tests/php/Core/KernelTest.php @@ -15,6 +15,7 @@ use ReflectionClass; use SilverStripe\ORM\DB; use ReflectionObject; +use SilverStripe\Core\Tests\KernelTest\TestFlushable; class KernelTest extends SapphireTest { @@ -85,7 +86,7 @@ public function testInvalidConfigDetection() $kernel->getConfigLoader()->getManifest(); } - + public function testReplicaDatabaseVarsLoaded() { // Set environment variables for a fake replica database @@ -113,4 +114,16 @@ public function testReplicaDatabaseVarsLoaded() 'password' => 'hi_people', ], $configs['replica_01']); } + + public function testImplementorsAreCalled() + { + TestFlushable::$flushed = false; + + $kernel = Injector::inst()->get(Kernel::class); + $kernel->boot(true); + $this->assertTrue(TestFlushable::$flushed); + + // reset the kernel Flush flag + $kernel->boot(); + } } diff --git a/tests/php/Control/FlushMiddlewareTest/TestFlushable.php b/tests/php/Core/KernelTest/TestFlushable.php similarity index 81% rename from tests/php/Control/FlushMiddlewareTest/TestFlushable.php rename to tests/php/Core/KernelTest/TestFlushable.php index f1c290e1651..8b1f2d87ae5 100644 --- a/tests/php/Control/FlushMiddlewareTest/TestFlushable.php +++ b/tests/php/Core/KernelTest/TestFlushable.php @@ -1,6 +1,6 @@