From b1b469a8746df2cfc98596d146e4fef7c6b81828 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Tue, 22 Oct 2024 19:09:42 +1300 Subject: [PATCH] ENH Do not rely on flush variable --- .../URLSpecialsMiddleware/FlushScheduler.php | 17 +++++++---------- src/Core/Startup/RequestFlushDiscoverer.php | 1 - src/Dev/Install/DatabaseAdapterRegistry.php | 5 +++-- src/View/SSViewer_FromString.php | 4 +++- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Control/Middleware/URLSpecialsMiddleware/FlushScheduler.php b/src/Control/Middleware/URLSpecialsMiddleware/FlushScheduler.php index 809936b0d..ee8bba5f9 100644 --- a/src/Control/Middleware/URLSpecialsMiddleware/FlushScheduler.php +++ b/src/Control/Middleware/URLSpecialsMiddleware/FlushScheduler.php @@ -2,7 +2,6 @@ namespace SilverStripe\Control\Middleware\URLSpecialsMiddleware; -use SilverStripe\Core\BaseKernel; use SilverStripe\Core\Kernel; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Startup\ScheduledFlushDiscoverer; @@ -28,15 +27,13 @@ trait FlushScheduler */ public function scheduleFlush(HTTPRequest $request) { - $flush = array_key_exists('flush', $request->getVars() ?? []) || ($request->getURL() === 'dev/build'); - - $kernel = Injector::inst()->get(Kernel::class); - if (!$flush || (method_exists($kernel, 'isFlushed') && $kernel->isFlushed())) { - return false; + if ($request->getURL() === 'dev/build') { + $kernel = Injector::inst()->get(Kernel::class); + if (!$kernel->isFlushed()) { + ScheduledFlushDiscoverer::scheduleFlush($kernel); + return true; + } } - - ScheduledFlushDiscoverer::scheduleFlush($kernel); - - return true; + return false; } } diff --git a/src/Core/Startup/RequestFlushDiscoverer.php b/src/Core/Startup/RequestFlushDiscoverer.php index 97c54c913..a2f594e31 100644 --- a/src/Core/Startup/RequestFlushDiscoverer.php +++ b/src/Core/Startup/RequestFlushDiscoverer.php @@ -44,7 +44,6 @@ class RequestFlushDiscoverer implements FlushDiscoverer /** * Checks whether the request contains any flush indicators * - * * @return null|bool flush or don't care */ protected function lookupRequest() diff --git a/src/Dev/Install/DatabaseAdapterRegistry.php b/src/Dev/Install/DatabaseAdapterRegistry.php index 4607e4472..6895bd8c5 100644 --- a/src/Dev/Install/DatabaseAdapterRegistry.php +++ b/src/Dev/Install/DatabaseAdapterRegistry.php @@ -6,6 +6,7 @@ use InvalidArgumentException; use Psr\SimpleCache\CacheInterface; use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Flushable; +use SilverStripe\Core\Kernel; /** * This class keeps track of the available database adapters @@ -155,8 +156,8 @@ class DatabaseAdapterRegistry implements Flushable */ protected static function getConfigureDatabasePaths(): array { - // autoconfigure() will get called before flush() on ?flush, so manually flush just to ensure no weirdness - if (isset($_GET['flush'])) { + // autoconfigure() will get called before flush() on flush, so manually flush just to ensure no weirdness + if (Injector::inst()->get(Kernel::class)->isFlushed()) { static::flush(); } try { diff --git a/src/View/SSViewer_FromString.php b/src/View/SSViewer_FromString.php index 9ec84dd57..b9e421f9c 100644 --- a/src/View/SSViewer_FromString.php +++ b/src/View/SSViewer_FromString.php @@ -5,6 +5,8 @@ namespace SilverStripe\View; use SilverStripe\Core\Config\Config; use SilverStripe\ORM\FieldType\DBField; use SilverStripe\Dev\Deprecation; +use SilverStripe\Core\Injector\Injector; +use SilverStripe\Core\Kernel; /** * Special SSViewer that will process a template passed as a string, rather than a filename. @@ -60,7 +62,7 @@ class SSViewer_FromString extends SSViewer $hash = sha1($this->content ?? ''); $cacheFile = TEMP_PATH . DIRECTORY_SEPARATOR . ".cache.$hash"; - if (!file_exists($cacheFile ?? '') || isset($_GET['flush'])) { + if (!file_exists($cacheFile ?? '') || Injector::inst()->get(Kernel::class)->isFlushed()) { $content = $this->parseTemplateContent($this->content, "string sha1=$hash"); $fh = fopen($cacheFile ?? '', 'w'); fwrite($fh, $content ?? '');