Convert to new cache layer, clean up other overlooked points in the ss4 upgrade
This commit is contained in:
parent
77eaa62efc
commit
0374d66b32
|
@ -1 +0,0 @@
|
||||||
.DS_Store
|
|
|
@ -29,7 +29,7 @@ before_script:
|
||||||
script:
|
script:
|
||||||
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
|
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
|
||||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
|
||||||
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --ignore=install.php src/ tests/ *.php; fi
|
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
---
|
---
|
||||||
Name: externallinksdependencies
|
Name: externallinksdependencies
|
||||||
---
|
---
|
||||||
Injector:
|
SilverStripe\Core\Injector\Injector:
|
||||||
LinkChecker: CurlLinkChecker
|
LinkChecker: SilverStripe\ExternalLinks\Tasks\CurlLinkChecker
|
||||||
|
Psr\SimpleCache\CacheInterface.CurlLinkChecker:
|
||||||
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
|
constructor:
|
||||||
|
namespace: 'curllinkchecker'
|
||||||
|
|
|
@ -7,13 +7,14 @@ use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
|
||||||
use SilverStripe\ExternalLinks\Jobs\CheckExternalLinksJob;
|
use SilverStripe\ExternalLinks\Jobs\CheckExternalLinksJob;
|
||||||
use SilverStripe\ExternalLinks\Tasks\CheckExternalLinksTask;
|
use SilverStripe\ExternalLinks\Tasks\CheckExternalLinksTask;
|
||||||
use SilverStripe\Control\Controller;
|
use SilverStripe\Control\Controller;
|
||||||
|
use Symbiote\QueuedJobs\Services\QueuedJobService;
|
||||||
|
|
||||||
class CMSExternalLinksController extends Controller
|
class CMSExternalLinksController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
private static $allowed_actions = array('getJobStatus', 'start');
|
private static $allowed_actions = array('getJobStatus', 'start');
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Respond to Ajax requests for info on a running job
|
* Respond to Ajax requests for info on a running job
|
||||||
*
|
*
|
||||||
* @return string JSON string detailing status of the job
|
* @return string JSON string detailing status of the job
|
||||||
|
@ -41,7 +42,7 @@ class CMSExternalLinksController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Starts a broken external link check
|
* Starts a broken external link check
|
||||||
*/
|
*/
|
||||||
public function start()
|
public function start()
|
||||||
|
@ -53,11 +54,11 @@ class CMSExternalLinksController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new job
|
// Create a new job
|
||||||
if (class_exists('QueuedJobService')) {
|
if (class_exists(QueuedJobService::class)) {
|
||||||
// Force the creation of a new run
|
// Force the creation of a new run
|
||||||
BrokenExternalPageTrackStatus::create_status();
|
BrokenExternalPageTrackStatus::create_status();
|
||||||
$checkLinks = new CheckExternalLinksJob();
|
$checkLinks = new CheckExternalLinksJob();
|
||||||
singleton('QueuedJobService')->queueJob($checkLinks);
|
singleton(QueuedJobService::class)->queueJob($checkLinks);
|
||||||
} else {
|
} else {
|
||||||
//TODO this hangs as it waits for the connection to be released
|
//TODO this hangs as it waits for the connection to be released
|
||||||
// should return back and continue processing
|
// should return back and continue processing
|
||||||
|
|
|
@ -19,7 +19,7 @@ class CheckExternalLinksJob extends AbstractQueuedJob implements QueuedJob
|
||||||
|
|
||||||
public function getTitle()
|
public function getTitle()
|
||||||
{
|
{
|
||||||
return _t('CheckExternalLiksJob.TITLE', 'Checking for external broken links');
|
return _t(__CLASS__ . '.TITLE', 'Checking for external broken links');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getJobType()
|
public function getJobType()
|
||||||
|
|
|
@ -71,13 +71,13 @@ class BrokenExternalLink extends DataObject
|
||||||
$code = $this->HTTPCode;
|
$code = $this->HTTPCode;
|
||||||
if (empty($code)) {
|
if (empty($code)) {
|
||||||
// Assume that $code = 0 means there was no response
|
// Assume that $code = 0 means there was no response
|
||||||
$description = _t('BrokenExternalLink.NOTAVAILABLE', 'Server Not Available');
|
$description = _t(__CLASS__ . '.NOTAVAILABLE', 'Server Not Available');
|
||||||
} elseif (($descriptions = Config::inst()->get(HTTPResponse::class, 'status_codes'))
|
} elseif (($descriptions = Config::inst()->get(HTTPResponse::class, 'status_codes'))
|
||||||
&& isset($descriptions[$code])
|
&& isset($descriptions[$code])
|
||||||
) {
|
) {
|
||||||
$description = $descriptions[$code];
|
$description = $descriptions[$code];
|
||||||
} else {
|
} else {
|
||||||
$description = _t('BrokenExternalLink.UNKNOWNRESPONSE', 'Unknown Response Code');
|
$description = _t(__CLASS__ . '.UNKNOWNRESPONSE', 'Unknown Response Code');
|
||||||
}
|
}
|
||||||
return sprintf("%d (%s)", $code, $description);
|
return sprintf("%d (%s)", $code, $description);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class BrokenExternalPageTrackStatus extends DataObject
|
||||||
/**
|
/**
|
||||||
* Get the latest track status
|
* Get the latest track status
|
||||||
*
|
*
|
||||||
* @return self
|
* @return BrokenExternalPageTrackStatus
|
||||||
*/
|
*/
|
||||||
public static function get_latest()
|
public static function get_latest()
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,8 @@ class BrokenExternalPageTrackStatus extends DataObject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get total pages count
|
* Get total pages count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getTotalPages()
|
public function getTotalPages()
|
||||||
{
|
{
|
||||||
|
@ -80,6 +82,8 @@ class BrokenExternalPageTrackStatus extends DataObject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get completed pages count
|
* Get completed pages count
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getCompletedPages()
|
public function getCompletedPages()
|
||||||
{
|
{
|
||||||
|
@ -92,7 +96,7 @@ class BrokenExternalPageTrackStatus extends DataObject
|
||||||
/**
|
/**
|
||||||
* Returns the latest run, or otherwise creates a new one
|
* Returns the latest run, or otherwise creates a new one
|
||||||
*
|
*
|
||||||
* @return self
|
* @return BrokenExternalPageTrackStatus
|
||||||
*/
|
*/
|
||||||
public static function get_or_create()
|
public static function get_or_create()
|
||||||
{
|
{
|
||||||
|
@ -106,10 +110,10 @@ class BrokenExternalPageTrackStatus extends DataObject
|
||||||
return self::create_status();
|
return self::create_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Create and prepare a new status
|
* Create and prepare a new status
|
||||||
*
|
*
|
||||||
* @return self
|
* @return BrokenExternalPageTrackStatus
|
||||||
*/
|
*/
|
||||||
public static function create_status()
|
public static function create_status()
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,6 @@ use SilverStripe\Reports\Report;
|
||||||
/**
|
/**
|
||||||
* Content side-report listing pages with external broken links
|
* Content side-report listing pages with external broken links
|
||||||
* @package externallinks
|
* @package externallinks
|
||||||
* @subpackage content
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class BrokenExternalLinksReport extends Report
|
class BrokenExternalLinksReport extends Report
|
||||||
|
@ -25,7 +24,7 @@ class BrokenExternalLinksReport extends Report
|
||||||
*/
|
*/
|
||||||
public function title()
|
public function title()
|
||||||
{
|
{
|
||||||
return _t('ExternalBrokenLinksReport.EXTERNALBROKENLINKS', "External broken links report");
|
return _t(__CLASS__ . '.EXTERNALBROKENLINKS', "External broken links report");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function columns()
|
public function columns()
|
||||||
|
@ -78,7 +77,7 @@ class BrokenExternalLinksReport extends Report
|
||||||
|
|
||||||
public function getCMSFields()
|
public function getCMSFields()
|
||||||
{
|
{
|
||||||
Requirements::javascript('externallinks/javascript/BrokenExternalLinksReport.js');
|
Requirements::javascript('silverstripe/externallinks: javascript/BrokenExternalLinksReport.js');
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
$reportResultSpan = '</ br></ br><h3 id="ReportHolder"></h3>';
|
$reportResultSpan = '</ br></ br><h3 id="ReportHolder"></h3>';
|
||||||
|
@ -90,7 +89,7 @@ class BrokenExternalLinksReport extends Report
|
||||||
'runReport',
|
'runReport',
|
||||||
sprintf(
|
sprintf(
|
||||||
$button,
|
$button,
|
||||||
_t('ExternalBrokenLinksReport.RUNREPORT', 'Create new report')
|
_t(__CLASS__ . '.RUNREPORT', 'Create new report')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$fields->push($runReportButton);
|
$fields->push($runReportButton);
|
||||||
|
|
|
@ -137,7 +137,7 @@ class CheckExternalLinksTask extends BuildTask
|
||||||
}
|
}
|
||||||
|
|
||||||
// do we have any whitelisted codes
|
// do we have any whitelisted codes
|
||||||
$ignoreCodes = Config::inst()->get('CheckExternalLinks', 'IgnoreCodes');
|
$ignoreCodes = $this->config()->get('IgnoreCodes');
|
||||||
if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) {
|
if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace SilverStripe\ExternalLinks\Tasks;
|
namespace SilverStripe\ExternalLinks\Tasks;
|
||||||
|
|
||||||
use SS_Cache;
|
use Psr\SimpleCache\CacheInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check links using curl
|
* Check links using curl
|
||||||
|
@ -17,11 +17,7 @@ class CurlLinkChecker implements LinkChecker
|
||||||
*/
|
*/
|
||||||
protected function getCache()
|
protected function getCache()
|
||||||
{
|
{
|
||||||
return SS_Cache::factory(
|
return Injector::inst()->get(CacheInterface::class . '.CurlLinkChecker');
|
||||||
__CLASS__,
|
|
||||||
'Output',
|
|
||||||
array('automatic_serialization' => true)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,7 +35,7 @@ class CurlLinkChecker implements LinkChecker
|
||||||
|
|
||||||
// Check if we have a cached result
|
// Check if we have a cached result
|
||||||
$cacheKey = md5($href);
|
$cacheKey = md5($href);
|
||||||
$result = $this->getCache()->load($cacheKey);
|
$result = $this->getCache()->get($cacheKey);
|
||||||
if ($result !== false) {
|
if ($result !== false) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +50,7 @@ class CurlLinkChecker implements LinkChecker
|
||||||
curl_close($handle);
|
curl_close($handle);
|
||||||
|
|
||||||
// Cache result
|
// Cache result
|
||||||
$this->getCache()->save($httpCode, $cacheKey);
|
$this->getCache()->set($httpCode, $cacheKey);
|
||||||
return $httpCode;
|
return $httpCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ class ExternalLinksTest extends SapphireTest
|
||||||
parent::setUpOnce();
|
parent::setUpOnce();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class ExternalLinksTest extends SapphireTest
|
||||||
|
|
||||||
// Check all pages have had the correct HTML adjusted
|
// Check all pages have had the correct HTML adjusted
|
||||||
for ($i = 1; $i <= 5; $i++) {
|
for ($i = 1; $i <= 5; $i++) {
|
||||||
$page = $this->objFromFixture('ExternalLinksTestPage', 'page'.$i);
|
$page = $this->objFromFixture(ExternalLinksTestPage::class, 'page'.$i);
|
||||||
$this->assertNotEmpty($page->Content);
|
$this->assertNotEmpty($page->Content);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$page->ExpectedContent,
|
$page->ExpectedContent,
|
||||||
|
@ -154,7 +154,7 @@ class ExternalLinksTest extends SapphireTest
|
||||||
$reports = Report::get_reports();
|
$reports = Report::get_reports();
|
||||||
$reportNames = array();
|
$reportNames = array();
|
||||||
foreach ($reports as $report) {
|
foreach ($reports as $report) {
|
||||||
$reportNames[] = $report->class;
|
$reportNames[] = get_class($report);
|
||||||
}
|
}
|
||||||
$this->assertContains(
|
$this->assertContains(
|
||||||
BrokenExternalLinksReport::class,
|
BrokenExternalLinksReport::class,
|
||||||
|
|
Loading…
Reference in New Issue