diff --git a/Classes/CheckLinks/CheckLinksStatistics.php b/Classes/CheckLinks/CheckLinksStatistics.php index 7615f0ec4..f147b388e 100644 --- a/Classes/CheckLinks/CheckLinksStatistics.php +++ b/Classes/CheckLinks/CheckLinksStatistics.php @@ -16,6 +16,8 @@ * The TYPO3 project - inspiring people to share! */ +use Sypets\Brofix\CheckLinks\CheckedLinksInfo\CheckedLinkInfoModel; + class CheckLinksStatistics { /** @@ -66,6 +68,11 @@ class CheckLinksStatistics */ protected $percentBrokenLinks; + /** + * @var array CheckedLinkInfoModel + */ + protected $checkedLinksInfoList = []; + public function __construct() { } @@ -132,6 +139,14 @@ public function setPageTitle(string $pageTitle): void $this->pageTitle = $pageTitle; } + public function addCheckedLinkInfo(CheckedLinkInfoModel $checkedLinkInfo): void + { + // limit the display checked links details + if (count($this->checkedLinksInfoList) < 10) { + array_push($this->checkedLinksInfoList, $checkedLinkInfo); + } + } + public function getPageTitle(): string { return $this->pageTitle; @@ -196,4 +211,12 @@ public function getPercentBrokenLinks(): float { return $this->percentBrokenLinks; } + + /** + * @return array + */ + public function getCheckedLinksInfoList(): array + { + return $this->checkedLinksInfoList; + } } diff --git a/Classes/CheckLinks/CheckedLinksInfo/CheckedLinkInfoModel.php b/Classes/CheckLinks/CheckedLinksInfo/CheckedLinkInfoModel.php new file mode 100644 index 000000000..15664486d --- /dev/null +++ b/Classes/CheckLinks/CheckedLinksInfo/CheckedLinkInfoModel.php @@ -0,0 +1,67 @@ +pageTitle; + } + public function getUrl(): string + { + return $this->url; + } + + public function getUid(): int + { + return $this->uid; + } + + public function getPid(): int + { + return $this->pid; + } + + // Setters + public function setPageTitle(string $pageTitle): void + { + $this->pageTitle = $pageTitle; + } + public function setUrl(string $url): void + { + $this->url = $url; + } + + public function setUid(int $uid): void + { + $this->uid = $uid; + } + + public function setPid(int $pid): void + { + $this->pid = $pid; + } +} diff --git a/Classes/Configuration/Configuration.php b/Classes/Configuration/Configuration.php index fd5b6336a..ce39b93d8 100644 --- a/Classes/Configuration/Configuration.php +++ b/Classes/Configuration/Configuration.php @@ -416,6 +416,11 @@ public function getMailLanguage(): string return $this->tsConfig['mail.']['language'] ?? 'en'; } + public function getMailAddLinks(): string + { + return $this->tsConfig['mail.']['addLinks'] ?? '0'; + } + /** * @return mixed[] */ diff --git a/Classes/LinkAnalyzer.php b/Classes/LinkAnalyzer.php index 6e2ed989a..ae3ece187 100644 --- a/Classes/LinkAnalyzer.php +++ b/Classes/LinkAnalyzer.php @@ -20,6 +20,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; +use Sypets\Brofix\CheckLinks\CheckedLinksInfo\CheckedLinkInfoModel; use Sypets\Brofix\CheckLinks\CheckLinksStatistics; use Sypets\Brofix\CheckLinks\ExcludeLinkTarget; use Sypets\Brofix\Configuration\Configuration; @@ -236,9 +237,9 @@ public function recheckUrl(string &$message, array $record): int // URL is not ok, update records (error type may have changed) $response = [ - 'valid' => false, - 'errorParams' => $hookObj->getErrorParams()->toArray() - ]; + 'valid' => false, + 'errorParams' => $hookObj->getErrorParams()->toArray() + ]; $brokenLinkRecord = []; $brokenLinkRecord['url'] = $url; $brokenLinkRecord['url_response'] = json_encode($response) ?: ''; @@ -246,9 +247,9 @@ public function recheckUrl(string &$message, array $record): int $brokenLinkRecord['last_check_url'] = \time(); $brokenLinkRecord['last_check'] = \time(); $identifier = [ - 'url' => $url, - 'link_type' => $linkType - ]; + 'url' => $url, + 'link_type' => $linkType + ]; $count = $this->brokenLinkRepository->updateBrokenLink($brokenLinkRecord, $identifier); $message = sprintf( $this->getLanguageService()->getLL('list.recheck.url.notok.updated'), @@ -408,6 +409,31 @@ protected function checkLinks(array $links, array $linkTypes, int $mode = 0): vo $record['last_check'] = \time(); $this->brokenLinkRepository->insertOrUpdateBrokenLink($record); $this->statistics->incrementCountBrokenLinks(); + + // test if the links list is enable + if ($this->configuration->getMailAddLinks() == '1') { + // Get The Page Title + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); + $queryBuilder = $connectionPool->getQueryBuilderForTable('pages'); + $queryBuilder->select('title') + ->from('pages') + ->where( + $queryBuilder->expr()->eq('pages' . '.uid', $record['record_pid']) + ); + + $result = $queryBuilder + ->execute(); + // Generate CheckedLinkInfoModel + $checkedLinkInfo = new CheckedLinkInfoModel(); + $checkedLinkInfo->setUid($row['uid']); + $checkedLinkInfo->setPid($record['record_pid']); + $checkedLinkInfo->setUrl($url); + while ($row = $result->fetch()) { + $checkedLinkInfo->setPageTitle($row['title']); + } + // add the records to the check links info array + $this->statistics->addCheckedLinkInfo($checkedLinkInfo); + } } elseif (GeneralUtility::_GP('showalllinks')) { $response = ['valid' => true]; $record['url_response'] = json_encode($response) ?: ''; @@ -424,8 +450,9 @@ protected function checkLinks(array $links, array $linkTypes, int $mode = 0): vo * * @param array $linkTypes List of link types to check (corresponds to hook object) * @param bool $considerHidden Defines whether to look into hidden fields + * @param string $searchFilter */ - public function generateBrokenLinkRecords(array $linkTypes = [], $considerHidden = false): void + public function generateBrokenLinkRecords(array $linkTypes = [], $considerHidden = false, $searchFilter = ''): void { if (empty($linkTypes) || empty($this->pids)) { return; @@ -479,6 +506,8 @@ public function generateBrokenLinkRecords(array $linkTypes = [], $considerHidden 'p', $queryBuilder->expr()->eq('p.uid', $queryBuilder->quoteIdentifier($table . '.pid')) ); + // order by the link creation + $queryBuilder->orderBy($table.'.crdate', 'DESC'); $constraints[] = $queryBuilder->expr()->neq('p.doktype', $queryBuilder->createNamedParameter(3, \PDO::PARAM_INT)); $constraints[] =$queryBuilder->expr()->neq('p.doktype', $queryBuilder->createNamedParameter(4, \PDO::PARAM_INT)); diff --git a/Configuration/TsConfig/Page/pagetsconfig.tsconfig b/Configuration/TsConfig/Page/pagetsconfig.tsconfig index d0fe48a2c..6934e7718 100644 --- a/Configuration/TsConfig/Page/pagetsconfig.tsconfig +++ b/Configuration/TsConfig/Page/pagetsconfig.tsconfig @@ -63,6 +63,7 @@ mod.brofix { subject = template = CheckLinksResults language = en + addLinks = 0 } custom { diff --git a/Documentation/Setup/Reference.rst b/Documentation/Setup/Reference.rst index ac552378e..9f9027b3b 100644 --- a/Documentation/Setup/Reference.rst +++ b/Documentation/Setup/Reference.rst @@ -826,3 +826,23 @@ mail.language Default en + +mail.addLinks +============ + +*optional* + +.. container:: table-row + + Property + mod.brofix.addLinks + + Data type + int + + Description + Get Broken links list int the e-mail report. ‘0’ is not displayed by default. + ‘1’ will send in the e-email report 10 broken links found recently created, with the UID, page Title, and the link. + + Default + 0 diff --git a/Resources/Private/Language/locallang.xlf b/Resources/Private/Language/locallang.xlf index e114a5ccd..ed5e2de31 100644 --- a/Resources/Private/Language/locallang.xlf +++ b/Resources/Private/Language/locallang.xlf @@ -106,6 +106,15 @@ and check links + + Visit the backend page + + + Page Title + + + Link + diff --git a/Resources/Private/Partials/BrokenLinksStatsTable.html b/Resources/Private/Partials/BrokenLinksStatsTable.html index b99bdd1ea..45732f936 100644 --- a/Resources/Private/Partials/BrokenLinksStatsTable.html +++ b/Resources/Private/Partials/BrokenLinksStatsTable.html @@ -13,20 +13,40 @@ } table.BrokenLinkStats td { - text-align: right; + text-align : right; } table.BrokenLinkStats tr.tableHeader { background-color: darkgrey; color: white; } + + + table.BrokenLinks, + table.BrokenLinks th, + table.BrokenLinks td { + padding: 10px; + border: 1px solid black; + border-collapse: collapse; + } + + table.BrokenLinks th { + text-align: left; + } + + table.BrokenLinks tr.tableHeader { + background-color: darkgrey; + color: white; + } - + @@ -83,4 +103,31 @@ +
Broken links + Broken links +
Percent broken linksCheck done {stats.checkEndTime} {stats.checkEndTime}
+
+ + + +
+
+ + + + + + + + + + + + + + + +