-
Notifications
You must be signed in to change notification settings - Fork 821
/
FlushScheduler.php
42 lines (36 loc) · 1.24 KB
/
FlushScheduler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace SilverStripe\Control\Middleware\URLSpecialsMiddleware;
use SilverStripe\Core\BaseKernel;
use SilverStripe\Core\Kernel;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Startup\ScheduledFlushDiscoverer;
use SilverStripe\Control\HTTPRequest;
/**
* Schedule flush operation for a following request
*
* The scheduler does not trigger a flush but rather puts a marker
* into the manifest cache so that one of the next Requests can
* find it and perform the actual manifest flush.
*/
trait FlushScheduler
{
/**
* Schedules the manifest flush operation for a following request
*
* WARNING! Does not perform flush, but schedules it for another request
*
* @param HTTPRequest $request
*
* @return bool true if flush has been scheduled, false otherwise
*/
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;
}
ScheduledFlushDiscoverer::scheduleFlush($kernel);
return true;
}
}