Passed
Pull Request — master (#70)
by Daniel
02:11
created

DeleteStaticCacheJob   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 15 4
A getTitle() 0 3 1
1
<?php
2
3
namespace SilverStripe\StaticPublishQueue\Job;
4
5
use SilverStripe\StaticPublishQueue\Job;
6
use SilverStripe\StaticPublishQueue\Publisher;
7
8
class DeleteStaticCacheJob extends Job
9
{
10
    /**
11
     * @var int
12
     * @config
13
     */
14
    private static $chunk_size = 2000;
0 ignored issues
show
introduced by
The private property $chunk_size is not used, and could be removed.
Loading history...
15
16
    /**
17
     * @return string
18
     */
19
    public function getTitle()
20
    {
21
        return 'Remove a set of static pages from the cache';
22
    }
23
24
    /**
25
     * Do some processing yourself!
26
     */
27
    public function process()
28
    {
29
        $chunkSize = self::config()->get('chunk_size');
30
        $count = 0;
31
        foreach ($this->jobData->URLsToProcess as $url => $priority) {
32
            if (++$count > $chunkSize) {
33
                break;
34
            }
35
            $meta = Publisher::singleton()->purgeURL($url);
36
            if (!empty($meta['success'])) {
37
                $this->jobData->ProcessedURLs[$url] = $url;
38
                unset($this->jobData->URLsToProcess[$url]);
39
            }
40
        }
41
        $this->isComplete = empty($this->jobData->URLsToProcess);
42
    }
43
}
44