Commit 41d7cee8 authored by Sybille Peters's avatar Sybille Peters 🙋 Committed by Georg Ringer
Browse files

[TASK] Simplify API for checking link target

Previously, the function BrokenLinkRepository::getNumberOfBrokenLinks()
was used in the event listener. It is not necessary to return the count.
We now only check if the link target is in the list of broken links.

This makes the API easier to read and reduces the number of methods
with similar and misleading names.

Resolves: #90390
Releases: master
Change-Id: Ia94a7a0bd44bbc827864371f7c6694b4b8f8f52a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/63267


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
parent 7091f482
.. 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
......@@ -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');
}
}
......
......@@ -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;
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment