[TASK] Re-work/simplify copyright header in PHP files - Part 9
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / Classes / Task / SystemStatusUpdateTask.php
1 <?php
2 namespace TYPO3\CMS\Reports\Task;
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 /**
17 * A task that should be run regularly to determine the system's status.
18 *
19 * @author Ingo Renner <ingo@typo3.org>
20 */
21 class SystemStatusUpdateTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask {
22
23 /**
24 * Email addresses to send email notification to in case we find problems with
25 * the system.
26 *
27 * @var string
28 */
29 protected $notificationEmail = NULL;
30
31 /**
32 * Executes the System Status Update task, determining the highest severity of
33 * status reports and saving that to the registry to be displayed at login
34 * if necessary.
35 *
36 * @see \TYPO3\CMS\Scheduler\Task\AbstractTask::execute()
37 */
38 public function execute() {
39 /** @var $registry \TYPO3\CMS\Core\Registry */
40 $registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
41 /** @var $statusReport \TYPO3\CMS\Reports\Report\Status\Status */
42 $statusReport = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Reports\\Report\\Status\\Status');
43 $systemStatus = $statusReport->getSystemStatus();
44 $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
45 $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
46 if ($highestSeverity > \TYPO3\CMS\Reports\Status::OK) {
47 $this->sendNotificationEmail($systemStatus);
48 }
49 return TRUE;
50 }
51
52 /**
53 * Gets the notification email addresses.
54 *
55 * @return string Notification email addresses.
56 */
57 public function getNotificationEmail() {
58 return $this->notificationEmail;
59 }
60
61 /**
62 * Sets the notification email address.
63 *
64 * @param string $notificationEmail Notification email address.
65 * @return void
66 */
67 public function setNotificationEmail($notificationEmail) {
68 $this->notificationEmail = $notificationEmail;
69 }
70
71 /**
72 * Sends a notification email, reporting system issues.
73 *
74 * @param array $systemStatus Array of statuses
75 * @return void
76 */
77 protected function sendNotificationEmail(array $systemStatus) {
78 $systemIssues = array();
79 foreach ($systemStatus as $statusProvider) {
80 foreach ($statusProvider as $status) {
81 if ($status->getSeverity() > \TYPO3\CMS\Reports\Status::OK) {
82 $systemIssues[] = (string) $status;
83 }
84 }
85 }
86 $notificationEmails = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $this->notificationEmail, TRUE);
87 $sendEmailsTo = array();
88 foreach ($notificationEmails as $notificationEmail) {
89 $sendEmailsTo[] = $notificationEmail;
90 }
91 $subject = sprintf($GLOBALS['LANG']->getLL('status_updateTask_email_subject'), $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
92 $message = sprintf($GLOBALS['LANG']->getLL('status_problemNotification'), '', '');
93 $message .= CRLF . CRLF;
94 $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site') . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
95 $message .= CRLF . CRLF;
96 $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues') . ': ' . CRLF;
97 $message .= implode(CRLF, $systemIssues);
98 $message .= CRLF . CRLF;
99 $from = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFrom();
100 /** @var $mail \TYPO3\CMS\Core\Mail\MailMessage */
101 $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
102 $mail->setFrom($from);
103 $mail->setTo($sendEmailsTo);
104 $mail->setSubject($subject);
105 $mail->setBody($message);
106 $mail->send();
107 }
108
109 }