|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\Salsify\ORM; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\Admin\LeftAndMain; |
|
|
|
|
|
|
6
|
|
|
use SilverStripe\CMS\Forms\SiteTreeURLSegmentField; |
|
|
|
|
|
|
7
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
|
|
|
|
|
8
|
|
|
use SilverStripe\Control\Controller; |
|
9
|
|
|
use SilverStripe\Forms\DatetimeField; |
|
10
|
|
|
use SilverStripe\Forms\FieldList; |
|
11
|
|
|
use SilverStripe\Forms\FormAction; |
|
12
|
|
|
use SilverStripe\Forms\TextField; |
|
13
|
|
|
use SilverStripe\ORM\DataExtension; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class FileExtension |
|
17
|
|
|
* |
|
18
|
|
|
* @property string SalsifyID |
|
19
|
|
|
* @property string SalsifyUpdatedAt |
|
20
|
|
|
* |
|
21
|
|
|
* @property-read \SilverStripe\ORM\DataObject|\Dynamic\Salsify\ORM\SalsifyIDExtension $owner |
|
22
|
|
|
*/ |
|
23
|
|
|
class SalsifyIDExtension extends DataExtension |
|
24
|
|
|
{ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
private static $db = [ |
|
|
|
|
|
|
30
|
|
|
'SalsifyID' => 'Varchar(255)', |
|
31
|
|
|
'SalsifyUpdatedAt' => 'Varchar(255)' |
|
32
|
|
|
]; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param \SilverStripe\Forms\FieldList $fields |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function updateFields(FieldList $fields) |
|
38
|
|
|
{ |
|
39
|
|
|
$salsifyID = $fields->fieldByName('SalsifyID'); |
|
40
|
|
|
if (!$salsifyID) { |
|
|
|
|
|
|
41
|
|
|
$fields->push($salsifyID = TextField::create('SalsifyID')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$salsifyUpdatedAt = $fields->fieldByName('SalsifyUpdatedAt'); |
|
45
|
|
|
if (!$salsifyUpdatedAt) { |
|
|
|
|
|
|
46
|
|
|
$fields->push($salsifyUpdatedAt = DatetimeField::create('SalsifyUpdatedAt')); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($this->owner->SalsifyID) { |
|
50
|
|
|
$salsifyID->setTemplate(SiteTreeURLSegmentField::class)->addExtraClass('urlsegment'); |
|
51
|
|
|
} |
|
52
|
|
|
$salsifyUpdatedAt->setReadonly(true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param \SilverStripe\Forms\FieldList $fields |
|
57
|
|
|
*/ |
|
58
|
|
|
public function updateCMSFields(FieldList $fields) |
|
59
|
|
|
{ |
|
60
|
|
|
if ($this->owner instanceof SiteTree) { |
|
61
|
|
|
return parent::updateCMSFields($fields); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$this->updateFields($fields); |
|
65
|
|
|
return parent::updateCMSFields($fields); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param \SilverStripe\Forms\FieldList $fields |
|
70
|
|
|
*/ |
|
71
|
|
|
public function updateSettingsFields(FieldList $fields) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->updateFields($fields); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \SilverStripe\Forms\FieldList $actions |
|
78
|
|
|
*/ |
|
79
|
|
|
public function updateCMSActions(FieldList $actions) |
|
80
|
|
|
{ |
|
81
|
|
|
parent::updateCMSActions($actions); |
|
82
|
|
|
|
|
83
|
|
|
if (!$this->owner->SalsifyID) { |
|
84
|
|
|
return; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$controller = Controller::curr(); |
|
88
|
|
|
if ($controller instanceof LeftAndMain && $controller->canFetchSalsify()) { |
|
89
|
|
|
/** @var FormAction $action */ |
|
90
|
|
|
$action = FormAction::create('salsifyFetch', 'Re-fetch Salsify') |
|
91
|
|
|
->addExtraClass('btn-primary font-icon-sync') |
|
92
|
|
|
->setUseButtonTag(true); |
|
93
|
|
|
|
|
94
|
|
|
$actions->push($action); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* |
|
100
|
|
|
*/ |
|
101
|
|
|
public function onBeforeWrite() |
|
102
|
|
|
{ |
|
103
|
|
|
parent::onBeforeWrite(); |
|
104
|
|
|
|
|
105
|
|
|
$this->owner->SalsifyID = trim($this->owner->SalsifyID); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths