mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Ensure everything gets flushed when flushing from sake
This commit is contained in:
parent
ba97de9458
commit
eefd0437fe
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Control\Tests;
|
||||
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Core\Kernel;
|
||||
use SilverStripe\Control\Tests\FlushMiddlewareTest\TestFlushable;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
|
||||
class FlushMiddlewareTest extends FunctionalTest
|
||||
{
|
||||
/**
|
||||
* Assert that classes that implement flushable are called
|
||||
*/
|
||||
public function testImplementorsAreCalled()
|
||||
{
|
||||
TestFlushable::$flushed = false;
|
||||
|
||||
Injector::inst()->get(Kernel::class)->boot(true);
|
||||
$this->get('/');
|
||||
$this->assertTrue(TestFlushable::$flushed);
|
||||
|
||||
// reset the kernel Flush flag
|
||||
Injector::inst()->get(Kernel::class)->boot();
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Control\Tests\FlushMiddlewareTest;
|
||||
namespace SilverStripe\Core\Tests\KernelTest;
|
||||
|
||||
use SilverStripe\Core\Flushable;
|
||||
use SilverStripe\Dev\TestOnly;
|
Loading…
Reference in New Issue
Block a user