Skip to content

Commit

Permalink
[TASK] Simplify API for checking link target
Browse files Browse the repository at this point in the history
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: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
sypets authored and georgringer committed Feb 21, 2020
1 parent 7091f48 commit 41d7cee
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public function checkExternalLink(BrokenLinkAnalysisEvent $event): void
}
$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');
}
}
Expand Down Expand Up @@ -88,8 +87,7 @@ public function checkFileLink(BrokenLinkAnalysisEvent $event): void
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');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -46,10 +52,36 @@ public function getNumberOfBrokenLinks(string $linkTarget): int
$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;
}
}

Expand Down

0 comments on commit 41d7cee

Please sign in to comment.