|
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 = [ |
|
|
|
|
|
|
26
|
|
|
"StaticSiteURL" => DBVarchar::class, |
|
27
|
|
|
"StaticSiteImportID" => DBInt::class, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
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
|
|
|
|