129 protected $languageFile =
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf';
260 $this->templateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
261 $successfullyExecuted =
true;
262 if (!file_exists($file = GeneralUtility::getFileAbsFileName($this->emailTemplateFile))
263 && !empty($this->email)
265 if ($this->emailTemplateFile ===
'EXT:linkvalidator/res/mailtemplate.html') {
267 $this->emailTemplateFile =
'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html';
271 throw new \InvalidArgumentException(
272 $lang->sL($this->languageFile .
':tasks.error.invalidEmailTemplateFile'),
277 $htmlFile = file_get_contents($file);
278 $this->templateMail = $this->templateService->getSubpart($htmlFile,
'###REPORT_TEMPLATE###');
281 $this->isDifferentToLastRun =
false;
282 $pageList = GeneralUtility::trimExplode(
',', $this->page,
true);
284 if (is_array($pageList)) {
286 $this->oldTotalBrokenLink = 0;
287 $this->totalBrokenLink = 0;
288 foreach ($pageList as
$page) {
292 if ($this->totalBrokenLink != $this->oldTotalBrokenLink) {
293 $this->isDifferentToLastRun =
true;
295 if ($this->totalBrokenLink > 0
296 && (!$this->emailOnBrokenLinkOnly || $this->isDifferentToLastRun)
297 && !empty($this->email)
299 $successfullyExecuted = $this->
reportEmail($pageSections, $modTs);
301 return $successfullyExecuted;
321 $processor = GeneralUtility::makeInstance(LinkAnalyzer::class);
323 $rootLineHidden =
false;
326 if ($pageRow ===
null) {
327 throw new \InvalidArgumentException(
332 $rootLineHidden = $processor->getRootLineIsHidden($pageRow);
334 if (!$rootLineHidden || $modTs[
'checkhidden'] == 1) {
335 $pageIds = $processor->extGetTreeList(
$page, $this->depth, 0,
'1=1', $modTs[
'checkhidden']);
336 if (isset($pageRow) && $pageRow[
'hidden'] == 0 || $modTs[
'checkhidden'] == 1) {
341 if (!empty($pageIds)) {
342 $processor->init($searchFields, $pageIds, $modTs);
343 if (!empty($this->email)) {
344 $oldLinkCounts = $processor->getLinkCounts(
$page);
345 $this->oldTotalBrokenLink += $oldLinkCounts[
'brokenlinkCount'];
347 $processor->getLinkStatistics($linkTypes, $modTs[
'checkhidden']);
348 if (!empty($this->email)) {
349 $linkCounts = $processor->getLinkCounts(
$page);
350 $this->totalBrokenLink += $linkCounts[
'brokenlinkCount'];
351 $pageSections = $this->
buildMail(
$page, $pageIds, $linkCounts, $oldLinkCounts);
354 return $pageSections;
366 $parseObj = GeneralUtility::makeInstance(TypoScriptParser::class);
367 $parseObj->parse($this->configuration);
368 if (!empty($parseObj->errors)) {
370 $parseErrorMessage = $languageService->sL($this->languageFile .
':tasks.error.invalidTSconfig')
372 foreach ($parseObj->errors as $errorInfo) {
373 $parseErrorMessage .= $errorInfo[0] .
'<br />';
375 throw new \Exception($parseErrorMessage,
'1295476989');
378 $tsConfig = $parseObj->setup;
379 $overrideTs = $tsConfig[
'mod.'][
'linkvalidator.'];
380 if (is_array($overrideTs)) {
395 foreach ($modTS[
'searchFields.'] as $table => $fieldList) {
396 $fields = GeneralUtility::trimExplode(
',', $fieldList);
398 $searchFields[$table][] = $field;
401 return $searchFields ?? [];
413 $typesTmp = GeneralUtility::trimExplode(
',', $modTS[
'linktypes'],
true);
414 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'] ?? [] as $type => $value) {
415 if (in_array($type, $typesTmp)) {
416 $linkTypes[$type] = 1;
430 protected function reportEmail($pageSections, array $modTsConfig)
433 $content = $this->templateService->substituteSubpart($this->templateMail,
'###PAGE_SECTION###', $pageSections);
437 $validEmailList = [];
443 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'reportEmailMarkers'] ?? [] as $userFunc) {
446 'markerArray' => $markerArray
448 $newMarkers = GeneralUtility::callUserFunction($userFunc, $params, $this);
449 if (is_array($newMarkers)) {
450 $markerArray = $newMarkers + $markerArray;
454 $content = $this->templateService->substituteMarkerArray($content, $markerArray,
'###|###',
true,
true);
456 $mail = GeneralUtility::makeInstance(MailMessage::class);
457 if (empty($modTsConfig[
'mail.'][
'fromemail'])) {
460 if (empty($modTsConfig[
'mail.'][
'fromname'])) {
463 if (GeneralUtility::validEmail($modTsConfig[
'mail.'][
'fromemail'])) {
464 $mail->setFrom([$modTsConfig[
'mail.'][
'fromemail'] => $modTsConfig[
'mail.'][
'fromname']]);
466 throw new \Exception(
467 $lang->sL($this->languageFile .
':tasks.error.invalidFromEmail'),
471 if (GeneralUtility::validEmail($modTsConfig[
'mail.'][
'replytoemail'])) {
472 $mail->setReplyTo([$modTsConfig[
'mail.'][
'replytoemail'] => $modTsConfig[
'mail.'][
'replytoname']]);
474 if (!empty($modTsConfig[
'mail.'][
'subject'])) {
475 $mail->setSubject($modTsConfig[
'mail.'][
'subject']);
477 throw new \Exception(
478 $lang->sL($this->languageFile .
':tasks.error.noSubject'),
482 if (!empty($this->email)) {
484 if (strpos($this->email,
',') !==
false) {
485 $emailList = GeneralUtility::trimExplode(
',', $this->email,
true);
486 $this->email = implode(LF, $emailList);
489 $emailList = GeneralUtility::trimExplode(LF, $this->email,
true);
492 foreach ($emailList as $emailAdd) {
493 if (!GeneralUtility::validEmail($emailAdd)) {
494 throw new \Exception(
495 $lang->sL($this->languageFile .
':tasks.error.invalidToEmail'),
499 $validEmailList[] = $emailAdd;
502 if (is_array($validEmailList) && !empty($validEmailList)) {
503 $mail->setTo($validEmailList);
508 $mail->setBody($content,
'text/html');
523 protected function buildMail($curPage, $pageList, array $markerArray, array $oldBrokenLink)
525 $pageSectionHtml = $this->templateService->getSubpart($this->templateMail,
'###PAGE_SECTION###');
526 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'buildMailMarkers'] ?? [] as $userFunc) {
528 'curPage' => $curPage,
529 'pageList' => $pageList,
530 'markerArray' => $markerArray,
531 'oldBrokenLink' => $oldBrokenLink,
534 $newMarkers = GeneralUtility::callUserFunction($userFunc, $params, $this);
535 if (is_array($newMarkers)) {
536 $markerArray = $newMarkers + $markerArray;
540 foreach ($markerArray as $markerKey => $markerValue) {
541 if (empty($oldBrokenLink[$markerKey])) {
542 $oldBrokenLink[$markerKey] = 0;
544 if ($markerValue != $oldBrokenLink[$markerKey]) {
545 $this->isDifferentToLastRun =
true;
547 $markerArray[$markerKey .
'_old'] = $oldBrokenLink[$markerKey];
554 if ($markerArray[
'brokenlinkCount'] > 0) {
555 $content = $this->templateService->substituteMarkerArray(
574 $additionalInformation = [];
580 if (!empty($pageData)) {
582 $pageLabel = $pageTitle .
' (' .
$page .
')';
587 $additionalInformation[] = $lang->sL($this->languageFile .
':tasks.validate.page') .
': ' . $pageLabel;
588 $additionalInformation[] = $lang->sL($this->languageFile .
':tasks.validate.depth') .
': '
589 . $lang->sL(
'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_' . (
$depth === 999 ?
'infi' :
$depth));
590 $additionalInformation[] = $lang->sL($this->languageFile .
':tasks.validate.email') .
': '
593 return implode(
', ', $additionalInformation);
603 'tx_link_scheduler_link',
608 '--sleepAfterFinish',