TYPO3 CMS  TYPO3_8-7
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 
28 {
35  protected $notificationEmail = null;
36 
42  protected $notificationAll = false;
43 
51  public function execute()
52  {
54  $registry = GeneralUtility::makeInstance(Registry::class);
56  $statusReport = GeneralUtility::makeInstance(\TYPO3\CMS\Reports\Report\Status\Status::class);
57  $systemStatus = $statusReport->getDetailedSystemStatus();
58  $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
59  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
60  if (($highestSeverity > Status::OK) || $this->getNotificationAll()) {
61  $this->sendNotificationEmail($systemStatus);
62  }
63  return true;
64  }
65 
71  public function getNotificationEmail()
72  {
74  }
75 
82  {
83  $this->notificationEmail = $notificationEmail;
84  }
85 
91  protected function sendNotificationEmail(array $systemStatus)
92  {
93  $systemIssues = [];
94  foreach ($systemStatus as $statusProvider) {
96  foreach ($statusProvider as $status) {
97  if ($this->getNotificationAll() || ($status->getSeverity() > Status::OK)) {
98  $systemIssues[] = (string)$status . CRLF . $status->getMessage() . CRLF . CRLF;
99  }
100  }
101  }
102  $notificationEmails = GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
103  $sendEmailsTo = [];
104  foreach ($notificationEmails as $notificationEmail) {
105  $sendEmailsTo[] = $notificationEmail;
106  }
107  $subject = sprintf($this->getLanguageService()->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
108  $message = $this->getNotificationAll() ? $this->getLanguageService()->getLL('status_allNotification') : $this->getLanguageService()->getLL('status_problemNotification');
109  $message .= CRLF . CRLF;
110  $message .= $this->getLanguageService()->getLL('status_updateTask_email_site') . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
111  $message .= CRLF . CRLF;
112  $message .= $this->getLanguageService()->getLL('status_updateTask_email_issues') . ': ' . CRLF;
113  $message .= implode(CRLF, $systemIssues);
114  $message .= CRLF . CRLF;
116  $mail = GeneralUtility::makeInstance(MailMessage::class);
117  $mail->setTo($sendEmailsTo);
118  $mail->setSubject($subject);
119  $mail->setBody($message);
120  $mail->send();
121  }
122 
126  public function getNotificationAll(): bool
127  {
128  return $this->notificationAll;
129  }
130 
134  public function setNotificationAll(bool $notificationAll)
135  {
136  $this->notificationAll = $notificationAll;
137  }
138 
142  protected function getLanguageService()
143  {
144  return $GLOBALS['LANG'];
145  }
146 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']