Skip to content

Commit

Permalink
FIX Ensure everything gets flushed when flushing from sake
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Oct 21, 2024
1 parent ba97de9 commit 7251090
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 38 deletions.
11 changes: 1 addition & 10 deletions src/Control/Middleware/FlushMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
}
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
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()
{
TestFlushable::$flushed = false;

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

// reset the kernel Flush flag
Injector::inst()->get(Kernel::class)->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

0 comments on commit 7251090

Please sign in to comment.