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;
|
namespace SilverStripe\Control\Middleware;
|
||||||
|
|
||||||
use SilverStripe\Control\HTTPRequest;
|
use SilverStripe\Control\HTTPRequest;
|
||||||
use SilverStripe\Core\BaseKernel;
|
|
||||||
use SilverStripe\Core\ClassInfo;
|
|
||||||
use SilverStripe\Core\Flushable;
|
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
use SilverStripe\Core\Kernel;
|
use SilverStripe\Core\Kernel;
|
||||||
|
|
||||||
@ -17,16 +14,10 @@ class FlushMiddleware implements HTTPMiddleware
|
|||||||
public function process(HTTPRequest $request, callable $delegate)
|
public function process(HTTPRequest $request, callable $delegate)
|
||||||
{
|
{
|
||||||
$kernel = Injector::inst()->get(Kernel::class);
|
$kernel = Injector::inst()->get(Kernel::class);
|
||||||
if ((method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) {
|
if ($kernel->isFlushed()) {
|
||||||
// Disable cache when flushing
|
// Disable cache when flushing
|
||||||
HTTPCacheControlMiddleware::singleton()->disableCache(true);
|
HTTPCacheControlMiddleware::singleton()->disableCache(true);
|
||||||
|
|
||||||
foreach (ClassInfo::implementorsOf(Flushable::class) as $class) {
|
|
||||||
/** @var Flushable|string $class */
|
|
||||||
$class::flush();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $delegate($request);
|
return $delegate($request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,14 @@ class CoreKernel extends BaseKernel
|
|||||||
$this->validateDatabase();
|
$this->validateDatabase();
|
||||||
|
|
||||||
$this->setBooted(true);
|
$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 ReflectionClass;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use ReflectionObject;
|
use ReflectionObject;
|
||||||
|
use SilverStripe\Core\Tests\KernelTest\TestFlushable;
|
||||||
|
|
||||||
class KernelTest extends SapphireTest
|
class KernelTest extends SapphireTest
|
||||||
{
|
{
|
||||||
@ -113,4 +114,16 @@ class KernelTest extends SapphireTest
|
|||||||
'password' => 'hi_people',
|
'password' => 'hi_people',
|
||||||
], $configs['replica_01']);
|
], $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
|
<?php
|
||||||
|
|
||||||
namespace SilverStripe\Control\Tests\FlushMiddlewareTest;
|
namespace SilverStripe\Core\Tests\KernelTest;
|
||||||
|
|
||||||
use SilverStripe\Core\Flushable;
|
use SilverStripe\Core\Flushable;
|
||||||
use SilverStripe\Dev\TestOnly;
|
use SilverStripe\Dev\TestOnly;
|
Loading…
Reference in New Issue
Block a user