‪TYPO3CMS  9.5
SystemStatusUpdateTask.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
29 {
36  protected ‪$notificationEmail;
37 
43  protected ‪$notificationAll = false;
44 
52  public function ‪execute()
53  {
55  $registry = GeneralUtility::makeInstance(Registry::class);
57  $statusReport = GeneralUtility::makeInstance(\‪TYPO3\CMS\Reports\Report\‪Status\Status::class);
58  $systemStatus = $statusReport->getDetailedSystemStatus();
59  $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
60  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
61  if (($highestSeverity > ‪Status::OK) || $this->‪getNotificationAll()) {
62  $this->‪sendNotificationEmail($systemStatus);
63  }
64  return true;
65  }
66 
72  public function ‪getNotificationEmail()
73  {
75  }
76 
83  {
84  $this->notificationEmail = ‪$notificationEmail;
85  }
86 
92  protected function ‪sendNotificationEmail(array $systemStatus)
93  {
94  $systemIssues = [];
95  foreach ($systemStatus as $statusProvider) {
97  foreach ($statusProvider as $status) {
98  if ($this->‪getNotificationAll() || ($status->getSeverity() > ‪Status::OK)) {
99  $systemIssues[] = (string)$status . CRLF . $status->getMessage() . CRLF . CRLF;
100  }
101  }
102  }
103  $notificationEmails = GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
104  $sendEmailsTo = [];
105  foreach ($notificationEmails as ‪$notificationEmail) {
106  $sendEmailsTo[] = ‪$notificationEmail;
107  }
108  $subject = sprintf($this->‪getLanguageService()->getLL('status_updateTask_email_subject'), ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
109  $message = $this->‪getNotificationAll() ? $this->‪getLanguageService()->‪getLL('status_allNotification') : $this->‪getLanguageService()->‪getLL('status_problemNotification');
110  $message .= CRLF . CRLF;
111  $message .= $this->‪getLanguageService()->‪getLL('status_updateTask_email_site') . ': ' . ‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
112  $message .= CRLF . CRLF;
113  $message .= $this->‪getLanguageService()->‪getLL('status_updateTask_email_issues') . ': ' . CRLF;
114  $message .= implode(CRLF, $systemIssues);
115  $message .= CRLF . CRLF;
117  $mail = GeneralUtility::makeInstance(MailMessage::class);
118  $mail->setTo($sendEmailsTo);
119  $mail->setSubject($subject);
120  $mail->setBody($message);
121  $mail->send();
122  }
123 
127  public function ‪getNotificationAll(): bool
128  {
130  }
131 
135  public function ‪setNotificationAll(bool ‪$notificationAll)
136  {
137  $this->notificationAll = ‪$notificationAll;
138  }
139 
143  protected function ‪getLanguageService()
144  {
145  return ‪$GLOBALS['LANG'];
146  }
147 }
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationAll
‪setNotificationAll(bool $notificationAll)
Definition: SystemStatusUpdateTask.php:133
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask
Definition: SystemStatusUpdateTask.php:29
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\$notificationAll
‪bool $notificationAll
Definition: SystemStatusUpdateTask.php:41
‪TYPO3
‪TYPO3\CMS\Core\Registry
Definition: Registry.php:32
‪TYPO3\CMS\Core\Mail\MailMessage
Definition: MailMessage.php:23
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\$notificationEmail
‪string $notificationEmail
Definition: SystemStatusUpdateTask.php:35
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getNotificationEmail
‪string getNotificationEmail()
Definition: SystemStatusUpdateTask.php:70
‪TYPO3\CMS\Reports\Status\OK
‪const OK
Definition: Status.php:25
‪TYPO3\CMS\Reports\Status
Definition: Status.php:22
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:32
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getLanguageService
‪LanguageService getLanguageService()
Definition: SystemStatusUpdateTask.php:141
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\getNotificationAll
‪bool getNotificationAll()
Definition: SystemStatusUpdateTask.php:125
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\execute
‪execute()
Definition: SystemStatusUpdateTask.php:50
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\setNotificationEmail
‪setNotificationEmail($notificationEmail)
Definition: SystemStatusUpdateTask.php:80
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Reports\Task
Definition: SystemStatusUpdateTask.php:2
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:29
‪TYPO3\CMS\Core\Localization\LanguageService\getLL
‪string getLL($index)
Definition: LanguageService.php:118
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Reports\Task\SystemStatusUpdateTask\sendNotificationEmail
‪sendNotificationEmail(array $systemStatus)
Definition: SystemStatusUpdateTask.php:90