Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Classes/CheckLinks/CheckLinksStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* The TYPO3 project - inspiring people to share!
*/

use Sypets\Brofix\CheckLinks\CheckedLinksInfo\CheckedLinkInfoModel;

class CheckLinksStatistics
{
/**
Expand Down Expand Up @@ -66,6 +68,11 @@ class CheckLinksStatistics
*/
protected $percentBrokenLinks;

/**
* @var array<CheckedLinkInfoModel> CheckedLinkInfoModel
*/
protected $checkedLinksInfoList = [];

public function __construct()
{
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -196,4 +211,12 @@ public function getPercentBrokenLinks(): float
{
return $this->percentBrokenLinks;
}

/**
* @return array<CheckedLinkInfoModel>
*/
public function getCheckedLinksInfoList(): array
{
return $this->checkedLinksInfoList;
}
}
67 changes: 67 additions & 0 deletions Classes/CheckLinks/CheckedLinksInfo/CheckedLinkInfoModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Sypets\Brofix\CheckLinks\CheckedLinksInfo;

class CheckedLinkInfoModel
{
// UID, Title, URL
/**
* @var string
*/
protected $pageTitle = '';

/**
* @var string
*/
protected $url = '';

/**
* @var int
*/
protected $uid;

/**
* @var int
*/
protected $pid;

// getters
public function getPageTitle(): string
{
return $this->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;
}
}
5 changes: 5 additions & 0 deletions Classes/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
*/
Expand Down
43 changes: 36 additions & 7 deletions Classes/LinkAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -236,19 +237,19 @@ 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) ?: '';
// last_check reflects time of last check (is now because URL not fetched from cache)
$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'),
Expand Down Expand Up @@ -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) ?: '';
Expand All @@ -424,8 +450,9 @@ protected function checkLinks(array $links, array $linkTypes, int $mode = 0): vo
*
* @param array<int,string> $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;
Expand Down Expand Up @@ -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));

Expand Down
1 change: 1 addition & 0 deletions Configuration/TsConfig/Page/pagetsconfig.tsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ mod.brofix {
subject =
template = CheckLinksResults
language = en
addLinks = 0
}

custom {
Expand Down
20 changes: 20 additions & 0 deletions Documentation/Setup/Reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@
<trans-unit id="and_check_links" resname="and_check_links">
<source>and check links</source>
</trans-unit>
<trans-unit id="visitBackendPage">
<source>Visit the backend page</source>
</trans-unit>
<trans-unit id="pageTitle">
<source>Page Title</source>
</trans-unit>
<trans-unit id="link">
<source>Link</source>
</trans-unit>
</body>
</file>
</xliff>
51 changes: 49 additions & 2 deletions Resources/Private/Partials/BrokenLinksStatsTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
</style>

<table class="BrokenLinkStats">


<tr class="tableHeader">
<th colspan="2"><f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:email.brokenlinksreport.header.broken_links" languageKey="{language}">Broken links</f:translate></th>
<th colspan="2">
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:email.brokenlinksreport.header.broken_links" languageKey="{language}">Broken links</f:translate>
</th>
</tr>
<tr>
<th><f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:email.brokenlinksreport.percent_broken_links" languageKey="{language}">Percent broken links</f:translate></th>
Expand Down Expand Up @@ -83,4 +103,31 @@
<th><f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:email.brokenlinksreport.check.done" languageKey="{language}">Check done</f:translate></th>
<td><f:format.date>{stats.checkEndTime}</f:format.date> <f:format.date format="H:i">{stats.checkEndTime}</f:format.date></td>
</tr>

</table>
<br>
<a href="http://mce.local.vici.io/typo3">
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:visitBackendPage"/>
</a>
<br>
<br>
<f:if condition="{stats.checkedLinksInfoList}">
<table class="BrokenLinks">
<tr class="tableHeader">
<th>UID</th>
<th>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:pageTitle"/>
</th>
<th>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/locallang.xlf:link"/>
</th>
</tr>
<f:for each="{stats.checkedLinksInfoList}" as="item">
<tr>
<td>{item.uid}</td>
<td>{item.pageTitle}</td>
<td>{item.url}</td>
</tr>
</f:for>
</table>
</f:if>