‪TYPO3CMS  10.4
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;
27 
33 {
40  protected ‪$notificationEmail;
41 
47  protected ‪$notificationAll = false;
48 
56  public function ‪execute()
57  {
59  $registry = GeneralUtility::makeInstance(Registry::class);
61  $statusReport = GeneralUtility::makeInstance(\‪TYPO3\CMS\Reports\Report\‪Status\Status::class);
62  $systemStatus = $statusReport->getDetailedSystemStatus();
63  $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
64  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
65  if (($highestSeverity > ‪Status::OK) || $this->‪getNotificationAll()) {
66  $this->‪sendNotificationEmail($systemStatus);
67  }
68  return true;
69  }
70 
76  public function ‪getNotificationEmail()
77  {
79  }
80 
87  {
88  $this->notificationEmail = ‪$notificationEmail;
89  }
90 
96  protected function ‪sendNotificationEmail(array $systemStatus)
97  {
98  $systemIssues = [];
99  foreach ($systemStatus as $statusProvider) {
101  foreach ($statusProvider as $status) {
102  if ($this->‪getNotificationAll() || ($status->getSeverity() > ‪Status::OK)) {
103  $systemIssues[] = (string)$status . CRLF . $status->getMessage() . CRLF . CRLF;
104  }
105  }
106  }
107  $notificationEmails = ‪GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
108  $sendEmailsTo = [];
109  foreach ($notificationEmails as ‪$notificationEmail) {
110  $sendEmailsTo[] = new Address(‪$notificationEmail);
111  }
112  $subject = sprintf($this->‪getLanguageService()->getLL('status_updateTask_email_subject'), ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
113  $message = $this->‪getNotificationAll() ? $this->‪getLanguageService()->‪getLL('status_allNotification') : $this->‪getLanguageService()->‪getLL('status_problemNotification');
114  $message .= CRLF . CRLF;
115  $message .= $this->‪getLanguageService()->‪getLL('status_updateTask_email_site') . ': ' . ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
116  $message .= CRLF . CRLF;
117  $message .= $this->‪getLanguageService()->‪getLL('status_updateTask_email_issues') . ': ' . CRLF;
118  $message .= implode(CRLF, $systemIssues);
119  $message .= CRLF . CRLF;
120 
121  $templateConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
122  $templateConfiguration['templateRootPaths'][20] = 'EXT:reports/Resources/Private/Templates/Email/';
123 
124  $email = GeneralUtility::makeInstance(FluidEmail::class, new ‪TemplatePaths($templateConfiguration));
125  $email
126  ->to(...$sendEmailsTo)
127  ->format('plain')
128  ->subject($subject)
129  ->setTemplate('Report')
130  ->assign('message', $message);
131  if ((‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface) {
132  $email->setRequest(‪$GLOBALS['TYPO3_REQUEST']);
133  }
134 
135  GeneralUtility::makeInstance(Mailer::class)->send($email);
136  }
137 
141  public function ‪getNotificationAll(): bool
142  {
144  }
145 
149  public function ‪setNotificationAll(bool ‪$notificationAll)
150  {
151  $this->notificationAll = ‪$notificationAll;
152  }
153 }
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationAll
‪setNotificationAll(bool $notificationAll)
Definition: SystemStatusUpdateTask.php:147
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:35
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask
Definition: SystemStatusUpdateTask.php:33
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\$notificationAll
‪bool $notificationAll
Definition: SystemStatusUpdateTask.php:45
‪TYPO3
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:33
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\$notificationEmail
‪string $notificationEmail
Definition: SystemStatusUpdateTask.php:39
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getNotificationEmail
‪string getNotificationEmail()
Definition: SystemStatusUpdateTask.php:74
‪TYPO3\CMS\Reports\Status\OK
‪const OK
Definition: Status.php:27
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Scheduler\Task\AbstractTask\getLanguageService
‪LanguageService null getLanguageService()
Definition: AbstractTask.php:605
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:35
‪TYPO3\CMS\Core\Mail\FluidEmail
Definition: FluidEmail.php:35
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getNotificationAll
‪bool getNotificationAll()
Definition: SystemStatusUpdateTask.php:139
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:38
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\execute
‪execute()
Definition: SystemStatusUpdateTask.php:54
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationEmail
‪setNotificationEmail($notificationEmail)
Definition: SystemStatusUpdateTask.php:84
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:16
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:154
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\sendNotificationEmail
‪sendNotificationEmail(array $systemStatus)
Definition: SystemStatusUpdateTask.php:94