|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Class AutomatedLinkPageResult |
|
5
|
|
|
* |
|
6
|
|
|
* This class is used to hold information about a page that has automated links. |
|
7
|
|
|
* It's only created if the controller AutomatedLinkReportTask is run |
|
8
|
|
|
* |
|
9
|
|
|
* @method SiteTree|null Page() |
|
10
|
|
|
* @property int OriginalLinkCount |
|
11
|
|
|
* @property int LinksCreatedCount |
|
12
|
|
|
* @property string Links |
|
13
|
|
|
*/ |
|
14
|
|
|
class AutomatedLinkPageResult extends DataObject { |
|
15
|
|
|
|
|
16
|
|
|
private static $db = array( |
|
17
|
|
|
'OriginalLinkCount' => 'INT', |
|
18
|
|
|
'LinksCreatedCount' => 'INT', |
|
19
|
|
|
'Links' => 'Text' |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
private static $has_one = array( |
|
23
|
|
|
'Page' => 'SiteTree' |
|
24
|
|
|
); |
|
25
|
|
|
|
|
26
|
|
|
private static $summary_fields = array( |
|
27
|
|
|
'Title' => 'Page Title', |
|
28
|
|
|
'URLSegment' => 'Page URLSegment', |
|
29
|
|
|
'OriginalLinkCount' => 'Amount of links originally', |
|
30
|
|
|
'Links' => 'List of automated links present', |
|
31
|
|
|
'LinkCount' => 'Amount of links created', |
|
32
|
|
|
'TotalLinks' => 'Total Amount of links' |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
|
|
// Disable all permissions to this object no one needs to touch it except the code itself |
|
36
|
|
|
public function canView($member = null) {return true; } |
|
37
|
|
|
public function canEdit($member = null) {return false; } |
|
38
|
|
|
public function canDelete($member = null) {return false; } |
|
39
|
|
|
public function canCreate($member = null) {return false; } |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Returns the URL of the page we're related to |
|
43
|
|
|
* |
|
44
|
|
|
* @return string |
|
45
|
|
|
*/ |
|
46
|
|
|
public function Title() { |
|
47
|
|
|
return $this->Page()->Title; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Returns the URL of the page we're related to |
|
52
|
|
|
* |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function URLSegment() { |
|
56
|
|
|
return $this->Page()->Link(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns the amount of links created on the page we're related to |
|
61
|
|
|
* |
|
62
|
|
|
* @return int |
|
63
|
|
|
*/ |
|
64
|
|
|
public function LinkCount() { |
|
65
|
|
|
return $this->LinksCreatedCount; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Returns the total amount of link the page we're related to has |
|
70
|
|
|
* |
|
71
|
|
|
* @return int |
|
72
|
|
|
*/ |
|
73
|
|
|
public function TotalLinks() { |
|
74
|
|
|
return $this->OriginalLinkCount+$this->LinksCreatedCount; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* If we already have an AutomatedLinkPageResult object for the |
|
79
|
|
|
* $page specified update it with the new data else create it |
|
80
|
|
|
* |
|
81
|
|
|
* @param SiteTree $page |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function add_or_update(SiteTree $page) { |
|
85
|
|
|
$obj = self::get()->find('PageID', $page->ID); |
|
86
|
|
|
if (!$obj) $obj = self::create(array('PageID' => $page->ID)); |
|
87
|
|
|
|
|
88
|
|
|
$obj->OriginalLinkCount = $page->OriginalLinkCount; |
|
89
|
|
|
$obj->LinksCreatedCount = $page->LinkCount; |
|
90
|
|
|
$obj->Links = $page->Links; |
|
91
|
|
|
|
|
92
|
|
|
$obj->write(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Delete the records we have that belong to pages that don't exist |
|
97
|
|
|
* anymore |
|
98
|
|
|
* |
|
99
|
|
|
* @return void |
|
100
|
|
|
*/ |
|
101
|
|
|
public static function remove_old_data() { |
|
102
|
|
|
foreach (self::get() as $obj) if (!SiteTree::get()->byID($obj->PageID)) $obj->delete(); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|