@@ -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 | |
@@ -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(), |
@@ -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 |
@@ -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 | ) { |
@@ -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 | } |
@@ -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); |