StaticPublishingTriggerPage::generatePublishable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace SilverStripe\StaticPublishQueue\Test\SiteTreePublishingEngineTest\Model;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Dev\TestOnly;
7
use SilverStripe\ORM\ArrayList;
8
use SilverStripe\StaticPublishQueue\Contract\StaticPublishingTrigger;
9
10
class StaticPublishingTriggerPage extends SiteTree implements TestOnly, StaticPublishingTrigger
11
{
12
    private static $table_name = 'SPQ_StaticPublishingTriggerPage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
13
14
    public function generatePublishable($url, $prio)
15
    {
16
        $obj = StaticallyPublishablePage::create();
17
        $obj->url = $url;
18
        $obj->prio = $prio;
19
20
        return $obj;
21
    }
22
23
    public function objectsToUpdate($context)
24
    {
25
        switch ($context['action']) {
26
            case 'publish':
27
                return new ArrayList([$this->generatePublishable('/updateOnPublish', 10)]);
28
            case 'unpublish':
29
                return new ArrayList([$this->generatePublishable('/updateOnUnpublish', 10)]);
30
        }
31
    }
32
33
    /**
34
     * Remove the object on unpublishing (the parent will get updated via objectsToUpdate).
35
     */
36
    public function objectsToDelete($context)
37
    {
38
        switch ($context['action']) {
39
            case 'publish':
40
                return new ArrayList([$this->generatePublishable('/deleteOnPublish', 10)]);
41
            case 'unpublish':
42
                return new ArrayList([$this->generatePublishable('/deleteOnUnpublish', 10)]);
43
        }
44
    }
45
}
46