‪TYPO3CMS  ‪main
SystemStatusUpdateTask.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ServerRequestInterface;
19 use Symfony\Component\Mime\Address;
28 
34 {
41  protected ‪$notificationEmail;
42 
48  protected ‪$notificationAll = false;
49 
57  public function ‪execute()
58  {
59  $registry = GeneralUtility::makeInstance(Registry::class);
60  $statusReport = GeneralUtility::makeInstance(\‪TYPO3\CMS\Reports\Report\‪Status\Status::class);
61  $systemStatus = $statusReport->getDetailedSystemStatus();
62  $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
63  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
64  if (($highestSeverity > ContextualFeedbackSeverity::OK->value) || $this->‪getNotificationAll()) {
65  $this->‪sendNotificationEmail($systemStatus);
66  }
67  return true;
68  }
69 
75  public function ‪getNotificationEmail()
76  {
78  }
79 
86  {
87  $this->notificationEmail = ‪$notificationEmail;
88  }
89 
95  protected function ‪sendNotificationEmail(array $systemStatus)
96  {
97  $systemIssues = [];
98  foreach ($systemStatus as $statusProvider) {
99  foreach ($statusProvider as $status) {
100  if ($this->‪getNotificationAll() || ($status->getSeverity()->value > ContextualFeedbackSeverity::OK->value)) {
101  $systemIssues[] = (string)$status . CRLF . $status->getMessage() . CRLF . CRLF;
102  }
103  }
104  }
105  $notificationEmails = ‪GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
106  $sendEmailsTo = [];
107  foreach ($notificationEmails as ‪$notificationEmail) {
108  $sendEmailsTo[] = new Address(‪$notificationEmail);
109  }
110  $subject = sprintf($this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTask_email_subject'), ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
111  $message = sprintf($this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:' . ($this->‪getNotificationAll() ? 'status_allNotification' : 'status_problemNotification')), '', '');
112  $message .= CRLF . CRLF;
113  $message .= $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTask_email_site') . ': ' . ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
114  $message .= CRLF . CRLF;
115  $message .= $this->‪getLanguageService()->sL('LLL:EXT:reports/Resources/Private/Language/locallang_reports.xlf:status_updateTask_email_issues') . ': ' . CRLF;
116  $message .= implode(CRLF, $systemIssues);
117  $message .= CRLF . CRLF;
118 
119  $templateConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
120  $templateConfiguration['templateRootPaths'][20] = 'EXT:reports/Resources/Private/Templates/Email/';
121 
122  $email = GeneralUtility::makeInstance(FluidEmail::class, new ‪TemplatePaths($templateConfiguration));
123  $email
124  ->to(...$sendEmailsTo)
125  ->format('plain')
126  ->subject($subject)
127  ->setTemplate('Report')
128  ->assign('message', $message);
129  if ((‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface) {
130  $email->setRequest(‪$GLOBALS['TYPO3_REQUEST']);
131  }
132 
133  // TODO: DI should be used to inject the MailerInterface
134  GeneralUtility::makeInstance(MailerInterface::class)->send($email);
135  }
136 
137  public function ‪getNotificationAll(): bool
138  {
140  }
141 
142  public function ‪setNotificationAll(bool ‪$notificationAll)
143  {
144  $this->notificationAll = ‪$notificationAll;
145  }
146 }
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationAll
‪setNotificationAll(bool $notificationAll)
Definition: SystemStatusUpdateTask.php:140
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getNotificationAll
‪getNotificationAll()
Definition: SystemStatusUpdateTask.php:135
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:39
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask
Definition: SystemStatusUpdateTask.php:34
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\$notificationAll
‪bool $notificationAll
Definition: SystemStatusUpdateTask.php:46
‪TYPO3
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Core\Mail\MailerInterface
Definition: MailerInterface.php:28
‪TYPO3\CMS\Scheduler\Task\AbstractTask\getLanguageService
‪getLanguageService()
Definition: AbstractTask.php:431
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\$notificationEmail
‪string $notificationEmail
Definition: SystemStatusUpdateTask.php:40
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getNotificationEmail
‪string getNotificationEmail()
Definition: SystemStatusUpdateTask.php:73
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:33
‪TYPO3\CMS\Core\Mail\FluidEmail
Definition: FluidEmail.php:35
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\execute
‪execute()
Definition: SystemStatusUpdateTask.php:55
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationEmail
‪setNotificationEmail($notificationEmail)
Definition: SystemStatusUpdateTask.php:83
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\sendNotificationEmail
‪sendNotificationEmail(array $systemStatus)
Definition: SystemStatusUpdateTask.php:93
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode(string $delim, string $string, bool $removeEmptyValues=false, int $limit=0)
Definition: GeneralUtility.php:822