@@ -111,6 +111,9 @@ |
||
111 | 111 | return $status; |
112 | 112 | } |
113 | 113 | |
114 | + /** |
|
115 | + * @param string $message |
|
116 | + */ |
|
114 | 117 | public function updateJobInfo($message) { |
115 | 118 | $this->JobInfo = $message; |
116 | 119 | $this->write(); |
@@ -40,7 +40,7 @@ |
||
40 | 40 | $pageIDs = $this |
41 | 41 | ->getIncompleteTracks() |
42 | 42 | ->column('PageID'); |
43 | - if($pageIDs) return Versioned::get_by_stage('SiteTree', 'Stage') |
|
43 | + if ($pageIDs) return Versioned::get_by_stage('SiteTree', 'Stage') |
|
44 | 44 | ->byIDs($pageIDs); |
45 | 45 | } |
46 | 46 |
@@ -40,8 +40,10 @@ |
||
40 | 40 | $pageIDs = $this |
41 | 41 | ->getIncompleteTracks() |
42 | 42 | ->column('PageID'); |
43 | - if($pageIDs) return Versioned::get_by_stage('SiteTree', 'Stage') |
|
43 | + if($pageIDs) { |
|
44 | + return Versioned::get_by_stage('SiteTree', 'Stage') |
|
44 | 45 | ->byIDs($pageIDs); |
46 | + } |
|
45 | 47 | } |
46 | 48 | |
47 | 49 | /** |
@@ -20,7 +20,7 @@ |
||
20 | 20 | |
21 | 21 | // Format status |
22 | 22 | $track = BrokenExternalPageTrackStatus::get_latest(); |
23 | - if($track) return json_encode(array( |
|
23 | + if ($track) return json_encode(array( |
|
24 | 24 | 'TrackID' => $track->ID, |
25 | 25 | 'Status' => $track->Status, |
26 | 26 | 'Completed' => $track->getCompletedPages(), |
@@ -20,12 +20,14 @@ discard block |
||
20 | 20 | |
21 | 21 | // Format status |
22 | 22 | $track = BrokenExternalPageTrackStatus::get_latest(); |
23 | - if($track) return json_encode(array( |
|
23 | + if($track) { |
|
24 | + return json_encode(array( |
|
24 | 25 | 'TrackID' => $track->ID, |
25 | 26 | 'Status' => $track->Status, |
26 | 27 | 'Completed' => $track->getCompletedPages(), |
27 | 28 | 'Total' => $track->getTotalPages() |
28 | 29 | )); |
30 | + } |
|
29 | 31 | } |
30 | 32 | |
31 | 33 | |
@@ -35,7 +37,9 @@ discard block |
||
35 | 37 | public function start() { |
36 | 38 | // return if the a job is already running |
37 | 39 | $status = BrokenExternalPageTrackStatus::get_latest(); |
38 | - if ($status && $status->Status == 'Running') return; |
|
40 | + if ($status && $status->Status == 'Running') { |
|
41 | + return; |
|
42 | + } |
|
39 | 43 | |
40 | 44 | // Create a new job |
41 | 45 | if (class_exists('QueuedJobService')) { |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!class_exists('AbstractQueuedJob')) return; |
|
3 | +if (!class_exists('AbstractQueuedJob')) return; |
|
4 | 4 | |
5 | 5 | /** |
6 | 6 | * A Job for running a external link check for published pages |
@@ -1,6 +1,8 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if(!class_exists('AbstractQueuedJob')) return; |
|
3 | +if(!class_exists('AbstractQueuedJob')) { |
|
4 | + return; |
|
5 | +} |
|
4 | 6 | |
5 | 7 | /** |
6 | 8 | * A Job for running a external link check for published pages |
@@ -53,10 +53,10 @@ |
||
53 | 53 | */ |
54 | 54 | public function getHTTPCodeDescription() { |
55 | 55 | $code = $this->HTTPCode; |
56 | - if(empty($code)) { |
|
56 | + if (empty($code)) { |
|
57 | 57 | // Assume that $code = 0 means there was no response |
58 | 58 | $description = _t('BrokenExternalLink.NOTAVAILABLE', 'Server Not Available'); |
59 | - } elseif( |
|
59 | + } elseif ( |
|
60 | 60 | ($descriptions = Config::inst()->get('SS_HTTPResponse', 'status_codes')) |
61 | 61 | && isset($descriptions[$code]) |
62 | 62 | ) { |
@@ -56,7 +56,9 @@ |
||
56 | 56 | |
57 | 57 | public function sourceRecords() { |
58 | 58 | $track = BrokenExternalPageTrackStatus::get_latest(); |
59 | - if ($track) return $track->BrokenLinks(); |
|
59 | + if ($track) { |
|
60 | + return $track->BrokenLinks(); |
|
61 | + } |
|
60 | 62 | return new ArrayList(); |
61 | 63 | } |
62 | 64 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param string $message |
29 | 29 | */ |
30 | 30 | protected function log($message) { |
31 | - if(!$this->silent) Debug::message($message); |
|
31 | + if (!$this->silent) Debug::message($message); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function run($request) { |
@@ -70,10 +70,10 @@ discard block |
||
70 | 70 | |
71 | 71 | // Check link |
72 | 72 | $httpCode = $this->linkChecker->checkLink($href); |
73 | - if($httpCode === null) return; // Null link means uncheckable, such as an internal link |
|
73 | + if ($httpCode === null) return; // Null link means uncheckable, such as an internal link |
|
74 | 74 | |
75 | 75 | // If this code is broken then mark as such |
76 | - if($foundBroken = $this->isCodeBroken($httpCode)) { |
|
76 | + if ($foundBroken = $this->isCodeBroken($httpCode)) { |
|
77 | 77 | // Create broken record |
78 | 78 | $brokenLink = new BrokenExternalLink(); |
79 | 79 | $brokenLink->Link = $href; |
@@ -84,8 +84,8 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | // Check if we need to update CSS class, otherwise return |
87 | - if($markedBroken == $foundBroken) return; |
|
88 | - if($foundBroken) { |
|
87 | + if ($markedBroken == $foundBroken) return; |
|
88 | + if ($foundBroken) { |
|
89 | 89 | $class .= ' ss-broken'; |
90 | 90 | } else { |
91 | 91 | $class = preg_replace('/\s*\b(ss-broken)\b\s*/', ' ', $class); |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | */ |
102 | 102 | protected function isCodeBroken($httpCode) { |
103 | 103 | // Null represents no request attempted |
104 | - if($httpCode === null) return false; |
|
104 | + if ($httpCode === null) return false; |
|
105 | 105 | |
106 | 106 | // do we have any whitelisted codes |
107 | 107 | $ignoreCodes = Config::inst()->get('CheckExternalLinks', 'IgnoreCodes'); |
108 | - if(is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) return false; |
|
108 | + if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) return false; |
|
109 | 109 | |
110 | 110 | // Check if code is outside valid range |
111 | 111 | return $httpCode < 200 || $httpCode > 302; |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | |
124 | 124 | // Calculate pages to run |
125 | 125 | $pageTracks = $status->getIncompleteTracks(); |
126 | - if($limit) $pageTracks = $pageTracks->limit($limit); |
|
126 | + if ($limit) $pageTracks = $pageTracks->limit($limit); |
|
127 | 127 | |
128 | 128 | // Check each page |
129 | 129 | foreach ($pageTracks as $pageTrack) { |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | // Check each link |
141 | 141 | $links = $htmlValue->getElementsByTagName('a'); |
142 | - foreach($links as $link) { |
|
142 | + foreach ($links as $link) { |
|
143 | 143 | $this->checkPageLink($pageTrack, $link); |
144 | 144 | } |
145 | 145 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | // Once all links have been created for this page update HasBrokenLinks |
152 | 152 | $count = $pageTrack->BrokenLinks()->count(); |
153 | 153 | $this->log("Found {$count} broken links"); |
154 | - if($count) { |
|
154 | + if ($count) { |
|
155 | 155 | // Bypass the ORM as syncLinkTracking does not allow you to update HasBrokenLink to true |
156 | 156 | DB::query(sprintf( |
157 | 157 | 'UPDATE "SiteTree" SET "HasBrokenLink" = 1 WHERE "ID" = \'%d\'', |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | private function updateJobInfo($message) { |
182 | 182 | $track = BrokenExternalPageTrackStatus::get_latest(); |
183 | - if($track) { |
|
183 | + if ($track) { |
|
184 | 184 | $track->JobInfo = $message; |
185 | 185 | $track->write(); |
186 | 186 | } |
@@ -28,7 +28,9 @@ discard block |
||
28 | 28 | * @param string $message |
29 | 29 | */ |
30 | 30 | protected function log($message) { |
31 | - if(!$this->silent) Debug::message($message); |
|
31 | + if(!$this->silent) { |
|
32 | + Debug::message($message); |
|
33 | + } |
|
32 | 34 | } |
33 | 35 | |
34 | 36 | public function run($request) { |
@@ -70,7 +72,10 @@ discard block |
||
70 | 72 | |
71 | 73 | // Check link |
72 | 74 | $httpCode = $this->linkChecker->checkLink($href); |
73 | - if($httpCode === null) return; // Null link means uncheckable, such as an internal link |
|
75 | + if($httpCode === null) { |
|
76 | + return; |
|
77 | + } |
|
78 | + // Null link means uncheckable, such as an internal link |
|
74 | 79 | |
75 | 80 | // If this code is broken then mark as such |
76 | 81 | if($foundBroken = $this->isCodeBroken($httpCode)) { |
@@ -84,7 +89,9 @@ discard block |
||
84 | 89 | } |
85 | 90 | |
86 | 91 | // Check if we need to update CSS class, otherwise return |
87 | - if($markedBroken == $foundBroken) return; |
|
92 | + if($markedBroken == $foundBroken) { |
|
93 | + return; |
|
94 | + } |
|
88 | 95 | if($foundBroken) { |
89 | 96 | $class .= ' ss-broken'; |
90 | 97 | } else { |
@@ -101,11 +108,15 @@ discard block |
||
101 | 108 | */ |
102 | 109 | protected function isCodeBroken($httpCode) { |
103 | 110 | // Null represents no request attempted |
104 | - if($httpCode === null) return false; |
|
111 | + if($httpCode === null) { |
|
112 | + return false; |
|
113 | + } |
|
105 | 114 | |
106 | 115 | // do we have any whitelisted codes |
107 | 116 | $ignoreCodes = Config::inst()->get('CheckExternalLinks', 'IgnoreCodes'); |
108 | - if(is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) return false; |
|
117 | + if(is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) { |
|
118 | + return false; |
|
119 | + } |
|
109 | 120 | |
110 | 121 | // Check if code is outside valid range |
111 | 122 | return $httpCode < 200 || $httpCode > 302; |
@@ -123,7 +134,9 @@ discard block |
||
123 | 134 | |
124 | 135 | // Calculate pages to run |
125 | 136 | $pageTracks = $status->getIncompleteTracks(); |
126 | - if($limit) $pageTracks = $pageTracks->limit($limit); |
|
137 | + if($limit) { |
|
138 | + $pageTracks = $pageTracks->limit($limit); |
|
139 | + } |
|
127 | 140 | |
128 | 141 | // Check each page |
129 | 142 | foreach ($pageTracks as $pageTrack) { |
@@ -135,7 +148,9 @@ discard block |
||
135 | 148 | $page = $pageTrack->Page(); |
136 | 149 | $this->log("Checking {$page->Title}"); |
137 | 150 | $htmlValue = Injector::inst()->create('HTMLValue', $page->Content); |
138 | - if (!$htmlValue->isValid()) continue; |
|
151 | + if (!$htmlValue->isValid()) { |
|
152 | + continue; |
|
153 | + } |
|
139 | 154 | |
140 | 155 | // Check each link |
141 | 156 | $links = $htmlValue->getElementsByTagName('a'); |
@@ -26,12 +26,12 @@ |
||
26 | 26 | */ |
27 | 27 | public function checkLink($href) { |
28 | 28 | // Skip non-external links |
29 | - if(!preg_match('/^https?[^:]*:\/\//', $href)) return null; |
|
29 | + if (!preg_match('/^https?[^:]*:\/\//', $href)) return null; |
|
30 | 30 | |
31 | 31 | // Check if we have a cached result |
32 | 32 | $cacheKey = md5($href); |
33 | 33 | $result = $this->getCache()->load($cacheKey); |
34 | - if($result !== false) return $result; |
|
34 | + if ($result !== false) return $result; |
|
35 | 35 | |
36 | 36 | // No cached result so just request |
37 | 37 | $handle = curl_init($href); |
@@ -26,12 +26,16 @@ |
||
26 | 26 | */ |
27 | 27 | public function checkLink($href) { |
28 | 28 | // Skip non-external links |
29 | - if(!preg_match('/^https?[^:]*:\/\//', $href)) return null; |
|
29 | + if(!preg_match('/^https?[^:]*:\/\//', $href)) { |
|
30 | + return null; |
|
31 | + } |
|
30 | 32 | |
31 | 33 | // Check if we have a cached result |
32 | 34 | $cacheKey = md5($href); |
33 | 35 | $result = $this->getCache()->load($cacheKey); |
34 | - if($result !== false) return $result; |
|
36 | + if($result !== false) { |
|
37 | + return $result; |
|
38 | + } |
|
35 | 39 | |
36 | 40 | // No cached result so just request |
37 | 41 | $handle = curl_init($href); |