‪TYPO3CMS  11.5
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  {
58  $registry = GeneralUtility::makeInstance(Registry::class);
59  $statusReport = GeneralUtility::makeInstance(\‪TYPO3\CMS\Reports\Report\‪Status\Status::class);
60  $systemStatus = $statusReport->getDetailedSystemStatus();
61  $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
62  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
63  if (($highestSeverity > ‪Status::OK) || $this->‪getNotificationAll()) {
64  $this->‪sendNotificationEmail($systemStatus);
65  }
66  return true;
67  }
68 
74  public function ‪getNotificationEmail()
75  {
77  }
78 
85  {
86  $this->notificationEmail = ‪$notificationEmail;
87  }
88 
94  protected function ‪sendNotificationEmail(array $systemStatus)
95  {
96  $systemIssues = [];
97  foreach ($systemStatus as $statusProvider) {
98  foreach ($statusProvider as $status) {
99  if ($this->‪getNotificationAll() || ($status->getSeverity() > ‪Status::OK)) {
100  $systemIssues[] = (string)$status . CRLF . $status->getMessage() . CRLF . CRLF;
101  }
102  }
103  }
104  $notificationEmails = ‪GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
105  $sendEmailsTo = [];
106  foreach ($notificationEmails as ‪$notificationEmail) {
107  $sendEmailsTo[] = new Address(‪$notificationEmail);
108  }
109  $subject = sprintf($this->‪getLanguageService()->getLL('status_updateTask_email_subject'), ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
110  $message = sprintf($this->‪getLanguageService()->getLL($this->‪getNotificationAll() ? 'status_allNotification' : 'status_problemNotification'), '', '');
111  $message .= CRLF . CRLF;
112  $message .= $this->‪getLanguageService()->‪getLL('status_updateTask_email_site') . ': ' . ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
113  $message .= CRLF . CRLF;
114  $message .= $this->‪getLanguageService()->‪getLL('status_updateTask_email_issues') . ': ' . CRLF;
115  $message .= implode(CRLF, $systemIssues);
116  $message .= CRLF . CRLF;
117 
118  $templateConfiguration = ‪$GLOBALS['TYPO3_CONF_VARS']['MAIL'];
119  $templateConfiguration['templateRootPaths'][20] = 'EXT:reports/Resources/Private/Templates/Email/';
120 
121  $email = GeneralUtility::makeInstance(FluidEmail::class, new ‪TemplatePaths($templateConfiguration));
122  $email
123  ->to(...$sendEmailsTo)
124  ->format('plain')
125  ->subject($subject)
126  ->setTemplate('Report')
127  ->assign('message', $message);
128  if ((‪$GLOBALS['TYPO3_REQUEST'] ?? null) instanceof ServerRequestInterface) {
129  $email->setRequest(‪$GLOBALS['TYPO3_REQUEST']);
130  }
131 
132  GeneralUtility::makeInstance(Mailer::class)->send($email);
133  }
134 
138  public function ‪getNotificationAll(): bool
139  {
141  }
142 
146  public function ‪setNotificationAll(bool ‪$notificationAll)
147  {
148  $this->notificationAll = ‪$notificationAll;
149  }
150 }
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static list< string > trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:999
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationAll
‪setNotificationAll(bool $notificationAll)
Definition: SystemStatusUpdateTask.php:144
‪TYPO3\CMS\Fluid\View\TemplatePaths
Definition: TemplatePaths.php:37
‪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:72
‪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:136
‪TYPO3\CMS\Core\Mail\Mailer
Definition: Mailer.php:38
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\execute
‪execute()
Definition: SystemStatusUpdateTask.php:54
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationEmail
‪setNotificationEmail($notificationEmail)
Definition: SystemStatusUpdateTask.php:82
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:16
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:121
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\sendNotificationEmail
‪sendNotificationEmail(array $systemStatus)
Definition: SystemStatusUpdateTask.php:92