StaticSiteDataExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
c 0
b 0
f 0
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 6 3
A onAfterDelete() 0 6 2
1
<?php
2
3
namespace PhpTek\Exodus\Extension;
4
5
use PhpTek\Exodus\Model\FailedURLRewriteObject;
6
use PhpTek\Exodus\Model\StaticSiteContentSource;
7
use SilverStripe\ORM\DataExtension;
8
use SilverStripe\Forms\ReadonlyField;
9
use SilverStripe\ORM\DataObject;
10
use SilverStripe\Forms\FieldList;
11
use SilverStripe\ORM\FieldType\DBInt;
12
use SilverStripe\ORM\FieldType\DBVarchar;
13
14
/**
15
 * @package phptek/silverstripe-exodus
16
 * @author Sam Minee <[email protected]>
17
 * @author Russell Michell <[email protected]>
18
 */
19
class StaticSiteDataExtension extends DataExtension
20
{
21
    /**
22
     *
23
     * @var array
24
     */
25
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
26
        "StaticSiteURL" => DBVarchar::class,
27
        "StaticSiteImportID" => DBInt::class,
28
    ];
29
30
    /**
31
     *
32
     * @var array
33
     */
34
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
35
        'StaticSiteContentSource' => StaticSiteContentSource::class,
36
    ];
37
38
    /**
39
     * Show readonly fields of Import "Meta data"
40
     *
41
     * @param FieldList $fields
42
     * @return void
43
     */
44
    public function updateCMSFields(FieldList $fields)
45
    {
46
        if ($this->owner->StaticSiteContentSourceID && $this->owner->StaticSiteURL) {
47
            $fields->addFieldToTab('Root.Main', ReadonlyField::create('StaticSiteURL', 'Imported URL'), 'MenuTitle');
48
            $fields->addFieldToTab('Root.Main', $importField = ReadonlyField::create('StaticSiteImportID', 'Import ID'), 'MenuTitle');
49
            $importField->setDescription('Use this number to pass as the \'ImportID\' parameter to the StaticSiteRewriteLinksTask.');
50
        }
51
    }
52
53
    /**
54
     * Ensure related FailedURLRewriteObjects are also removed, when the related SiteTree
55
     * object is deleted in the CMS.
56
     *
57
     * @return void
58
     */
59
    public function onAfterDelete()
60
    {
61
        parent::onAfterDelete();
62
        if ($failedRewriteObjects = DataObject::get(FailedURLRewriteObject::class)->filter('ContainedInID', $this->owner->ID)) {
63
            $failedRewriteObjects->each(function ($item) {
64
                $item->delete();
65
            });
66
        }
67
    }
68
}
69