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