From a3c693189bc396094f9c94ad62548161e05b2c4d Mon Sep 17 00:00:00 2001 From: Kirk Mayo Date: Thu, 24 Jul 2014 14:50:14 +1200 Subject: [PATCH] NEW: Adding back in the Broken links model no model admin this time though --- code/model/BrokenExternalLinks.php | 28 ++++++++++++++++++++++++++++ code/tasks/CheckExternalLinks.php | 6 ++++++ 2 files changed, 34 insertions(+) create mode 100644 code/model/BrokenExternalLinks.php diff --git a/code/model/BrokenExternalLinks.php b/code/model/BrokenExternalLinks.php new file mode 100644 index 0000000..e002405 --- /dev/null +++ b/code/model/BrokenExternalLinks.php @@ -0,0 +1,28 @@ + 'Varchar(2083)', // 2083 is the maximum length of a URL in Internet Explorer. + 'HTTPCode' =>'Int' + ); + + private static $has_one = array( + 'Page' => 'Page' + ); + + public static $summary_fields = array( + 'Page.Title' => 'Page', + 'HTTPCode' => 'HTTP Code', + 'Created' => 'Created' + ); + + public static $searchable_fields = array( + 'HTTPCode' => array('title' => 'HTTP Code') + ); + + function canEdit($member = false) { + return false; + } + +} diff --git a/code/tasks/CheckExternalLinks.php b/code/tasks/CheckExternalLinks.php index 3a61fb4..ba2f148 100644 --- a/code/tasks/CheckExternalLinks.php +++ b/code/tasks/CheckExternalLinks.php @@ -60,6 +60,12 @@ function run($request) { if (($httpCode < 200 || $httpCode > 302) || ($href == '' || $href[0] == '/')) { + $brokenLink = new BrokenExternalLinks(); + $brokenLink->PageID = $page->ID; + $brokenLink->Link = $href; + $brokenLink->HTTPCode = $httpCode; + $brokenLink->write(); + // set the broken link class $class = ($class && stripos($class, 'ss-broken')) ? $class . ' ss-broken' : 'ss-broken';