Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Do not rely on flush variable #11440

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/Control/Middleware/URLSpecialsMiddleware/FlushScheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've redone the logic on this one since it was already checked Injector::inst()->get(Kernel::class)->isFlushed() and returning false if isFlushed() was true.

$kernel = Injector::inst()->get(Kernel::class);
if (!$kernel->isFlushed()) {
ScheduledFlushDiscoverer::scheduleFlush($kernel);
return true;
}
}

ScheduledFlushDiscoverer::scheduleFlush($kernel);

return true;
return false;
}
}
1 change: 0 additions & 1 deletion src/Core/Startup/RequestFlushDiscoverer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function __construct(HTTPRequest $request, $env)
/**
* Checks whether the request contains any flush indicators
*
*
* @return null|bool flush or don't care
*/
protected function lookupRequest()
Expand Down
5 changes: 3 additions & 2 deletions src/Dev/Install/DatabaseAdapterRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
Expand Down Expand Up @@ -155,8 +156,8 @@ public static function autoconfigure(&$config = null)
*/
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 {
Expand Down
4 changes: 3 additions & 1 deletion src/View/SSViewer_FromString.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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.
Expand Down Expand Up @@ -60,7 +62,7 @@ public function process($item, $arguments = null, $scope = null)
$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 ?? '');
Expand Down