@@ -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,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 |
@@ -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 | /** |
@@ -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,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,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); |