1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpTek\Exodus\Model; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
6
|
|
|
use SilverStripe\Core\Injector\Injectable; |
7
|
|
|
use SilverStripe\ORM\DataObject; |
8
|
|
|
use SilverStripe\ORM\ArrayList; |
9
|
|
|
use SilverStripe\ORM\FieldType\DBVarchar; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A model object that represents a single failed link-rewrite during the |
13
|
|
|
* running of the StaticSiteRewriteLinksTask. This data is then used to power the |
14
|
|
|
* {@link FailedURLRewriteReport}. |
15
|
|
|
* |
16
|
|
|
* @author Russell Michell <[email protected]> |
17
|
|
|
* @package phptek/silverstripe-exodus |
18
|
|
|
* @see {@link StaticSiteLinkRewriteTask} |
19
|
|
|
*/ |
20
|
|
|
class FailedURLRewriteObject extends DataObject |
21
|
|
|
{ |
22
|
|
|
use Injectable; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
private static $table_name = 'FailedURLRewriteObject'; |
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private static $db = [ |
|
|
|
|
34
|
|
|
"BadLinkType" => "Enum('ThirdParty, BadScheme, NotImported, Junk, Unknown', 'Unknown')", |
35
|
|
|
"OrigUrl" => DBVarchar::class, |
36
|
|
|
]; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private static $has_one = [ |
|
|
|
|
43
|
|
|
'Import' => StaticSiteImportDataObject::class, |
44
|
|
|
'ContainedIn' => SiteTree::class, |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Customise the output of the FailedURLRewriteReport CSV export. |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public function summaryFields() |
53
|
|
|
{ |
54
|
|
|
return [ |
55
|
|
|
'ContainedIn.Title' => 'Imported page', |
56
|
|
|
'Import.Created' => 'Import date', |
57
|
|
|
'ThirdPartyTotal' => 'No. 3rd Party Urls', |
58
|
|
|
'BadSchemeTotal' => 'No. Urls with bad-scheme', |
59
|
|
|
'NotImportedTotal' => 'No. Unimported Urls', |
60
|
|
|
'JunkTotal' => 'No. Junk Urls', |
61
|
|
|
]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Fetch the related SiteTree object's Title property. |
66
|
|
|
* |
67
|
|
|
* @return string |
68
|
|
|
*/ |
69
|
|
|
public function Title() |
70
|
|
|
{ |
71
|
|
|
return $this->ContainedIn()->Title; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get totals for each type of failed URL. |
76
|
|
|
* |
77
|
|
|
* @param number $importID |
78
|
|
|
* @param string $badLinkType e.g. 'NotImported' |
79
|
|
|
* @return SS_List |
|
|
|
|
80
|
|
|
*/ |
81
|
|
|
public function getBadImportData($importID, $badLinkType = null) |
82
|
|
|
{ |
83
|
|
|
$default = ArrayList::create(); |
84
|
|
|
|
85
|
|
|
$badLinks = DataObject::get(__CLASS__) |
86
|
|
|
->filter('ImportID', $importID) |
87
|
|
|
->sort('Created'); |
88
|
|
|
|
89
|
|
|
if ($badLinks) { |
|
|
|
|
90
|
|
|
if ($badLinkType) { |
91
|
|
|
return $badLinks->filter('BadLinkType', $badLinkType); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
return $badLinks; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $default; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|