diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-90390-DeprecateBrokenLinkRepositorygetNumberOfBrokenLinksInLinkvalidator.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-90390-DeprecateBrokenLinkRepositorygetNumberOfBrokenLinksInLinkvalidator.rst new file mode 100644 index 0000000000000000000000000000000000000000..29552b94d97ca223cd3577783c748d68b0e30910 --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-90390-DeprecateBrokenLinkRepositorygetNumberOfBrokenLinksInLinkvalidator.rst @@ -0,0 +1,34 @@ +.. include:: ../../Includes.txt + +=============================================================================================== +Deprecation: #90390 - Deprecate BrokenLinkRepository::getNumberOfBrokenLinks() in linkvalidator +=============================================================================================== + +See :issue:`90390` + +Description +=========== + +The method :php:`BrokenLinkRepository::getNumberOfBrokenLinks()` is deprecated. + + +Impact +====== + +If third party extensions use this function, a `E_USER_DEPRECATED` +is triggered. + + +Affected Installations +====================== + +This only affects third party extensions which use this function. The +deprecated function is no longer used in the core. + + +Migration +========= + +Use :php:`BrokenLinkRepository::getNumberOfBrokenLinks()` instead. + +.. index:: Backend, NotScanned, ext:linkvalidator diff --git a/typo3/sysext/linkvalidator/Classes/EventListener/CheckBrokenRteLinkEventListener.php b/typo3/sysext/linkvalidator/Classes/EventListener/CheckBrokenRteLinkEventListener.php index 2d296995219b6ce1720abeed57a497f2078d20c1..3075309466bd8b3d2939b5bfd38de05d8c58a42c 100644 --- a/typo3/sysext/linkvalidator/Classes/EventListener/CheckBrokenRteLinkEventListener.php +++ b/typo3/sysext/linkvalidator/Classes/EventListener/CheckBrokenRteLinkEventListener.php @@ -45,8 +45,7 @@ final class CheckBrokenRteLinkEventListener } $url = (string)$event->getLinkData()['url'] ?? ''; if (!empty($url)) { - $count = $this->brokenLinkRepository->getNumberOfBrokenLinks($url); - if ($count) { + if ($this->brokenLinkRepository->isLinkTargetBrokenLink($url)) { $event->markAsBrokenLink('External link is broken'); } } @@ -88,8 +87,7 @@ final class CheckBrokenRteLinkEventListener return; } - $count = $this->brokenLinkRepository->getNumberOfBrokenLinks('file:' . $file->getProperty('uid')); - if ($count) { + if ($this->brokenLinkRepository->isLinkTargetBrokenLink('file:' . $file->getProperty('uid'))) { $event->markAsBrokenLink('File with ID ' . $file->getProperty('uid') . ' not found'); } } diff --git a/typo3/sysext/linkvalidator/Classes/Repository/BrokenLinkRepository.php b/typo3/sysext/linkvalidator/Classes/Repository/BrokenLinkRepository.php index 8a322b087b618e94b7861686c6223e6801a0f74c..36bf60b38079a521a823aeef3e71f0a60dfc057b 100644 --- a/typo3/sysext/linkvalidator/Classes/Repository/BrokenLinkRepository.php +++ b/typo3/sysext/linkvalidator/Classes/Repository/BrokenLinkRepository.php @@ -33,9 +33,15 @@ class BrokenLinkRepository * @param string $linkTarget Url to check for. Can be a URL (for external links) * a page uid (for db links), a file reference (for file links), etc. * @return int the amount of usages this broken link is used in this installation + * @deprecated This method was deprecated in TYPO3 10.3 Use isLinkTargetBrokenLink() instead */ public function getNumberOfBrokenLinks(string $linkTarget): int { + trigger_error( + 'BrokenLinkRepository::getNumberOfBrokenLinks() was deprecated in TYPO3 10.3 Use BrokenLinkRepository::isLinkTargetBrokenLink() instead', + E_USER_DEPRECATED + ); + try { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable(static::TABLE); @@ -46,10 +52,36 @@ class BrokenLinkRepository $queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($linkTarget)) ); return (int)$queryBuilder + ->execute() + ->fetchColumn(0); + } catch (\Doctrine\DBAL\Exception\TableNotFoundException $e) { + return 0; + } + } + + /** + * Check if linkTarget is in list of broken links. + * + * @param string $linkTarget Url to check for. Can be a URL (for external links) + * a page uid (for db links), a file reference (for file links), etc. + * @return bool is the link target a broken link + */ + public function isLinkTargetBrokenLink(string $linkTarget): bool + { + try { + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable(static::TABLE); + $queryBuilder + ->count('uid') + ->from(static::TABLE) + ->where( + $queryBuilder->expr()->eq('url', $queryBuilder->createNamedParameter($linkTarget)) + ); + return (bool)$queryBuilder ->execute() ->fetchColumn(0); } catch (\Doctrine\DBAL\Exception\TableNotFoundException $e) { - return 0; + return false; } }