Skip to content

Commit

Permalink
API Deprecate API that will be removed (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Sep 13, 2024
1 parent 5ee28c0 commit 175c754
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/Tasks/CheckExternalLinksTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Dev\Debug;
use SilverStripe\Dev\Deprecation;
use SilverStripe\ExternalLinks\Model\BrokenExternalLink;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrack;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
Expand Down Expand Up @@ -36,6 +37,7 @@ class CheckExternalLinksTask extends BuildTask

/**
* @var bool
* @deprecated 3.4.0 Will be replaced with new $output parameter in the run() method
*/
protected $silent = false;

Expand All @@ -54,9 +56,11 @@ class CheckExternalLinksTask extends BuildTask
* Log a message
*
* @param string $message
* @deprecated 3.4.0 Will be replaced with new $output parameter in the run() method
*/
protected function log($message)
{
Deprecation::notice('3.4.0', 'Will be replaced with new $output parameter in the run() method');
if (!$this->silent) {
Debug::message($message);
}
Expand All @@ -70,9 +74,11 @@ public function run($request)
* Turn on or off message output
*
* @param bool $silent
* @deprecated 3.4.0 Will be replaced with new $output parameter in the run() method
*/
public function setSilent($silent)
{
Deprecation::notice('3.4.0', 'Will be replaced with new $output parameter in the run() method');
$this->silent = $silent;
}

Expand Down Expand Up @@ -181,7 +187,7 @@ public function runLinksCheck($limit = null)

// Check value of html area
$page = $pageTrack->Page();
$this->log("Checking {$page->Title}");
Deprecation::withNoReplacement(fn() => $this->log("Checking {$page->Title}"));
$htmlValue = Injector::inst()->create(HTMLValue::class, $page->Content);
if (!$htmlValue->isValid()) {
continue;
Expand All @@ -199,13 +205,15 @@ public function runLinksCheck($limit = null)
try {
$page->write();
} catch (ValidationException $ex) {
$this->log("Exception caught for {$page->Title}, skipping. Message: " . $ex->getMessage());
Deprecation::withNoReplacement(function () use ($page, $ex) {
$this->log("Exception caught for {$page->Title}, skipping. Message: " . $ex->getMessage());
});
continue;
}

// Once all links have been created for this page update HasBrokenLinks
$count = $pageTrack->BrokenLinks()->count();
$this->log("Found {$count} broken links");
Deprecation::withNoReplacement(fn() => $this->log("Found {$count} broken links"));
if ($count) {
$siteTreeTable = DataObject::getSchema()->tableName(SiteTree::class);
// Bypass the ORM as syncLinkTracking does not allow you to update HasBrokenLink to true
Expand Down
5 changes: 3 additions & 2 deletions tests/php/ExternalLinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SilverStripe\ExternalLinks\Tests;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
use SilverStripe\ExternalLinks\Reports\BrokenExternalLinksReport;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function testLinks()
{
// Run link checker
$task = CheckExternalLinksTask::create();
$task->setSilent(true); // Be quiet during the test!
Deprecation::withNoReplacement(fn() => $task->setSilent(true)); // Be quiet during the test!
$task->runLinksCheck();

// Get all links checked
Expand Down Expand Up @@ -112,7 +113,7 @@ public function testArchivedPagesAreHiddenFromReport()
{
// Run link checker
$task = CheckExternalLinksTask::create();
$task->setSilent(true); // Be quiet during the test!
Deprecation::withNoReplacement(fn() => $task->setSilent(true)); // Be quiet during the test!
$task->runLinksCheck();

// Ensure report lists all broken links
Expand Down

0 comments on commit 175c754

Please sign in to comment.