From 175c75419a8504dc4453b2a28a01c88c220f4479 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Fri, 13 Sep 2024 17:18:27 +1200 Subject: [PATCH] API Deprecate API that will be removed (#147) --- src/Tasks/CheckExternalLinksTask.php | 14 +++++++++++--- tests/php/ExternalLinksTest.php | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Tasks/CheckExternalLinksTask.php b/src/Tasks/CheckExternalLinksTask.php index 2203396..9dbb851 100644 --- a/src/Tasks/CheckExternalLinksTask.php +++ b/src/Tasks/CheckExternalLinksTask.php @@ -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; @@ -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; @@ -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); } @@ -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; } @@ -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; @@ -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 diff --git a/tests/php/ExternalLinksTest.php b/tests/php/ExternalLinksTest.php index edbdd2d..c6dd4a6 100644 --- a/tests/php/ExternalLinksTest.php +++ b/tests/php/ExternalLinksTest.php @@ -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; @@ -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 @@ -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