Passed
Push — master ( ddbf8b...086098 )
by Robbie
11:17
created

FlushScheduler::scheduleFlush()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 4
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Control\Middleware\URLSpecialsMiddleware;
4
5
use SilverStripe\Core\Kernel;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\Core\Startup\ScheduledFlushDiscoverer;
8
use SilverStripe\Control\Director;
9
use SilverStripe\Control\HTTPRequest;
10
11
/**
12
 * Schedule flush operation for a following request
13
 *
14
 * The scheduler does not trigger a flush but rather puts a marker
15
 * into the manifest cache so that one of the next Requests can
16
 * find it and perform the actual manifest flush.
17
 */
18
trait FlushScheduler
19
{
20
    /**
21
     * Schedules the manifest flush operation for a following request
22
     *
23
     * WARNING! Does not perform flush, but schedules it for another request
24
     *
25
     * @param HTTPRequest $request
26
     *
27
     * @return bool true if flush has been scheduled, false otherwise
28
     */
29
    public function scheduleFlush(HTTPRequest $request)
30
    {
31
        $flush = array_key_exists('flush', $request->getVars()) || ($request->getURL() === 'dev/build');
32
33
        if (!$flush || Director::isManifestFlushed()) {
0 ignored issues
show
Deprecated Code introduced by
The function SilverStripe\Control\Director::isManifestFlushed() has been deprecated: 5.0 Kernel::isFlushed to be used instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

33
        if (!$flush || /** @scrutinizer ignore-deprecated */ Director::isManifestFlushed()) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
34
            return false;
35
        }
36
37
        $kernel = Injector::inst()->get(Kernel::class);
38
        ScheduledFlushDiscoverer::scheduleFlush($kernel);
39
40
        return true;
41
    }
42
}
43