diff --git a/src/Control/Middleware/FlushMiddleware.php b/src/Control/Middleware/FlushMiddleware.php index 374063eec..64cd4279a 100644 --- a/src/Control/Middleware/FlushMiddleware.php +++ b/src/Control/Middleware/FlushMiddleware.php @@ -3,9 +3,6 @@ namespace SilverStripe\Control\Middleware; use SilverStripe\Control\HTTPRequest; -use SilverStripe\Core\BaseKernel; -use SilverStripe\Core\ClassInfo; -use SilverStripe\Core\Flushable; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Kernel; @@ -17,16 +14,10 @@ class FlushMiddleware implements HTTPMiddleware public function process(HTTPRequest $request, callable $delegate) { $kernel = Injector::inst()->get(Kernel::class); - if ((method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) { + if ($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/Core/CoreKernel.php b/src/Core/CoreKernel.php index ca9946f68..5626fd080 100644 --- a/src/Core/CoreKernel.php +++ b/src/Core/CoreKernel.php @@ -52,6 +52,14 @@ class CoreKernel extends BaseKernel $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/tests/php/Control/FlushMiddlewareTest.php b/tests/php/Control/FlushMiddlewareTest.php deleted file mode 100644 index a553d14ba..000000000 --- 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 c779f3495..afb5b37a7 100644 --- a/tests/php/Core/KernelTest.php +++ b/tests/php/Core/KernelTest.php @@ -15,6 +15,7 @@ use SilverStripe\Core\Environment; use ReflectionClass; use SilverStripe\ORM\DB; use ReflectionObject; +use SilverStripe\Core\Tests\KernelTest\TestFlushable; class KernelTest extends SapphireTest { @@ -85,7 +86,7 @@ class KernelTest extends SapphireTest $kernel->getConfigLoader()->getManifest(); } - + public function testReplicaDatabaseVarsLoaded() { // Set environment variables for a fake replica database @@ -113,4 +114,16 @@ class KernelTest extends SapphireTest '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 f1c290e16..8b1f2d87a 100644 --- a/tests/php/Control/FlushMiddlewareTest/TestFlushable.php +++ b/tests/php/Core/KernelTest/TestFlushable.php @@ -1,6 +1,6 @@