Passed
Pull Request — master (#104)
by
unknown
02:45
created

GenerateStaticCacheJob   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 25
rs 10
c 3
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getTitle() 0 3 1
A processUrl() 0 11 4
1
<?php
2
3
namespace SilverStripe\StaticPublishQueue\Job;
4
5
use SilverStripe\StaticPublishQueue\Job;
6
use SilverStripe\StaticPublishQueue\Publisher;
7
8
/**
9
 * Class GenerateStaticCacheJob
10
 * add pages to static cache based on list of URLs
11
 *
12
 * @package SilverStripe\StaticPublishQueue\Job
13
 */
14
class GenerateStaticCacheJob extends Job
15
{
16
    /**
17
     * @return string
18
     */
19
    public function getTitle()
20
    {
21
        return 'Generate a set of static pages from URLs';
22
    }
23
24
    /**
25
     * @param string $url
26
     * @param int $priority
27
     */
28
    protected function processUrl($url, $priority)
29
    {
30
        $meta = Publisher::singleton()->publishURL($url, true);
31
        $meta = (is_array($meta)) ? $meta : [];
32
        if (array_key_exists('success', $meta) && $meta['success']) {
33
            $this->markUrlAsProcessed($url);
34
35
            return;
36
        }
37
38
        $this->handleFailedUrl($url, $meta);
39
    }
40
}
41