TYPO3 CMS  TYPO3_7-6
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 
21 
26 {
33  protected $notificationEmail = null;
34 
42  public function execute()
43  {
45  $registry = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Registry::class);
47  $statusReport = GeneralUtility::makeInstance(\TYPO3\CMS\Reports\Report\Status\Status::class);
48  $systemStatus = $statusReport->getDetailedSystemStatus();
49  $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
50  $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
51  if ($highestSeverity > Status::OK) {
52  $this->sendNotificationEmail($systemStatus);
53  }
54  return true;
55  }
56 
62  public function getNotificationEmail()
63  {
65  }
66 
74  {
75  $this->notificationEmail = $notificationEmail;
76  }
77 
84  protected function sendNotificationEmail(array $systemStatus)
85  {
86  $systemIssues = [];
87  foreach ($systemStatus as $statusProvider) {
89  foreach ($statusProvider as $status) {
90  if ($status->getSeverity() > Status::OK) {
91  $systemIssues[] = (string)$status . CRLF . $status->getMessage() . CRLF . CRLF;
92  }
93  }
94  }
95  $notificationEmails = GeneralUtility::trimExplode(LF, $this->notificationEmail, true);
96  $sendEmailsTo = [];
97  foreach ($notificationEmails as $notificationEmail) {
98  $sendEmailsTo[] = $notificationEmail;
99  }
100  $subject = sprintf($GLOBALS['LANG']->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
101  $message = sprintf($GLOBALS['LANG']->getLL('status_problemNotification'), '', '');
102  $message .= CRLF . CRLF;
103  $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site') . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
104  $message .= CRLF . CRLF;
105  $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues') . ': ' . CRLF;
106  $message .= implode(CRLF, $systemIssues);
107  $message .= CRLF . CRLF;
108  $from = MailUtility::getSystemFrom();
110  $mail = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
111  $mail->setFrom($from);
112  $mail->setTo($sendEmailsTo);
113  $mail->setSubject($subject);
114  $mail->setBody($message);
115  $mail->send();
116  }
117 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']