2 namespace TYPO3\CMS\Linkvalidator\Task;
258 $successfullyExecuted =
true;
261 && !empty($this->email)
263 if ($this->emailTemplateFile ===
'EXT:linkvalidator/res/mailtemplate.html') {
265 $this->emailTemplateFile =
'EXT:linkvalidator/Resources/Private/Templates/mailtemplate.html';
268 throw new \InvalidArgumentException(
269 $this->
getLanguageService()->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidEmailTemplateFile'),
274 $htmlFile = GeneralUtility::getURL($file);
275 $this->templateMail = $this->templateService->getSubpart($htmlFile,
'###REPORT_TEMPLATE###');
278 $this->isDifferentToLastRun =
false;
281 if (is_array($pageList)) {
282 foreach ($pageList as
$page) {
283 $pageSections .= $this->checkPageLinks($page);
286 if ($this->totalBrokenLink != $this->oldTotalBrokenLink) {
287 $this->isDifferentToLastRun =
true;
289 if ($this->totalBrokenLink > 0 && (!$this->emailOnBrokenLinkOnly || $this->isDifferentToLastRun) && !empty($this->email)) {
290 $successfullyExecuted = $this->reportEmail($pageSections, $modTs);
292 return $successfullyExecuted;
301 protected function checkPageLinks(
$page)
306 $oldLinkCounts = array();
313 $rootLineHidden =
false;
316 $rootLineHidden = $processor->getRootLineIsHidden($pageRow);
318 if (!$rootLineHidden || $modTs[
'checkhidden'] == 1) {
319 $pageIds = $processor->extGetTreeList(
$page, $this->depth, 0,
'1=1', $modTs[
'checkhidden']);
320 if (isset($pageRow) && $pageRow[
'hidden'] == 0 || $modTs[
'checkhidden'] == 1) {
325 if (!empty($pageIds)) {
326 $processor->init($searchFields, $pageIds, $modTs);
327 if (!empty($this->email)) {
328 $oldLinkCounts = $processor->getLinkCounts(
$page);
329 $this->oldTotalBrokenLink += $oldLinkCounts[
'brokenlinkCount'];
331 $processor->getLinkStatistics($linkTypes, $modTs[
'checkhidden']);
332 if (!empty($this->email)) {
333 $linkCounts = $processor->getLinkCounts(
$page);
334 $this->totalBrokenLink += $linkCounts[
'brokenlinkCount'];
335 $pageSections = $this->
buildMail(
$page, $pageIds, $linkCounts, $oldLinkCounts);
338 return $pageSections;
352 $parseObj->parse($this->configuration);
353 if (!empty($parseObj->errors)) {
354 $parseErrorMessage = $this->
getLanguageService()->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidTSconfig') .
'<br />';
355 foreach ($parseObj->errors as $errorInfo) {
356 $parseErrorMessage .= $errorInfo[0] .
'<br />';
358 throw new \Exception($parseErrorMessage,
'1295476989');
360 $tsConfig = $parseObj->setup;
361 $modTs = $modTs[
'properties'];
362 $overrideTs = $tsConfig[
'mod.'][
'linkvalidator.'];
363 if (is_array($overrideTs)) {
366 $deprecatedOverrideTs = $tsConfig[
'mod.'][
'tx_linkvalidator.'];
367 if (is_array($deprecatedOverrideTs)) {
368 GeneralUtility::deprecationLog(
'Using mod.tx_linkvalidator in the scheduler TSConfig setting is deprecated since TYPO3 CMS 7 and will be removed in TYPO3 CMS 8. Please use mod.linkvalidator instead.');
384 foreach ($modTS[
'searchFields.'] as $table => $fieldList) {
386 foreach ($fields as $field) {
387 $searchFields[$table][] = $field;
390 return isset($searchFields) ? $searchFields : array();
401 $linkTypes = array();
403 if (is_array($typesTmp)) {
404 if (!empty(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks']) && is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'])) {
405 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'checkLinks'] as $type => $value) {
406 if (in_array($type, $typesTmp)) {
407 $linkTypes[$type] = 1;
423 protected function reportEmail($pageSections, array $modTsConfig)
425 $content = $this->templateService->substituteSubpart($this->templateMail,
'###PAGE_SECTION###', $pageSections);
427 $markerArray = array();
429 $validEmailList = array();
435 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'reportEmailMarkers'])) {
436 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'reportEmailMarkers'] as $userFunc) {
439 'markerArray' => $markerArray
442 if (is_array($newMarkers)) {
443 $markerArray = $newMarkers + $markerArray;
448 $content = $this->templateService->substituteMarkerArray($content, $markerArray,
'###|###',
true,
true);
451 if (empty($modTsConfig[
'mail.'][
'fromemail'])) {
454 if (empty($modTsConfig[
'mail.'][
'fromname'])) {
458 $mail->setFrom(array($modTsConfig[
'mail.'][
'fromemail'] => $modTsConfig[
'mail.'][
'fromname']));
460 throw new \Exception($this->
getLanguageService()->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidFromEmail'),
'1295476760');
463 $mail->setReplyTo(array($modTsConfig[
'mail.'][
'replytoemail'] => $modTsConfig[
'mail.'][
'replytoname']));
465 if (!empty($modTsConfig[
'mail.'][
'subject'])) {
466 $mail->setSubject($modTsConfig[
'mail.'][
'subject']);
468 throw new \Exception($this->
getLanguageService()->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.noSubject'),
'1295476808');
470 if (!empty($this->email)) {
472 if (strpos($this->email,
',') !==
false) {
474 $this->email = implode(LF, $emailList);
480 foreach ($emailList as $emailAdd) {
482 throw new \Exception($this->
getLanguageService()->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.error.invalidToEmail'),
'1295476821');
484 $validEmailList[] = $emailAdd;
488 if (is_array($validEmailList) && !empty($validEmailList)) {
489 $mail->setTo($validEmailList);
494 $mail->setBody($content,
'text/html');
509 protected function buildMail($curPage, $pageList, array $markerArray, array $oldBrokenLink)
511 $pageSectionHtml = $this->templateService->getSubpart($this->templateMail,
'###PAGE_SECTION###');
513 if (is_array(
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'buildMailMarkers'])) {
514 foreach (
$GLOBALS[
'TYPO3_CONF_VARS'][
'EXTCONF'][
'linkvalidator'][
'buildMailMarkers'] as $userFunc) {
516 'curPage' => $curPage,
517 'pageList' => $pageList,
518 'markerArray' => $markerArray,
519 'oldBrokenLink' => $oldBrokenLink,
523 if (is_array($newMarkers)) {
524 $markerArray = $newMarkers + $markerArray;
529 if (is_array($markerArray)) {
530 foreach ($markerArray as $markerKey => $markerValue) {
531 if (empty($oldBrokenLink[$markerKey])) {
532 $oldBrokenLink[$markerKey] = 0;
534 if ($markerValue != $oldBrokenLink[$markerKey]) {
535 $this->isDifferentToLastRun =
true;
537 $markerArray[$markerKey .
'_old'] = $oldBrokenLink[$markerKey];
545 if ($markerArray[
'brokenlinkCount'] > 0) {
546 $content = $this->templateService->substituteMarkerArray($pageSectionHtml, $markerArray,
'###|###',
true,
true);
559 $additionalInformation = array();
565 if (!empty($pageData)) {
567 $pageLabel = $pageTitle .
' (' .
$page .
')';
571 $additionalInformation[] =
$lang->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.page') .
': ' . $pageLabel;
574 $additionalInformation[] =
$lang->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.depth') .
': ' .
$lang->sL(
'LLL:EXT:lang/locallang_core.xlf:labels.depth_' . (
$depth === 999 ?
'infi' :
$depth));
576 $additionalInformation[] =
$lang->sL(
'LLL:EXT:linkvalidator/Resources/Private/Language/locallang.xlf:tasks.validate.email') .
': ' . $this->
getEmail();
578 return implode(
', ', $additionalInformation);
588 $_SERVER[
'argv'] = array(
590 'tx_link_scheduler_link',
595 '--sleepAfterFinish',
596 $this->sleepAfterFinish,