[TASK] Change "false" into "FALSE"
[Packages/TYPO3.CMS.git] / typo3 / sysext / reports / tasks / class.tx_reports_tasks_systemstatusupdatetask.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25
26 /**
27 * A task that should be run regularly to determine the system's status.
28 *
29 * @author Ingo Renner <ingo@typo3.org>
30 * @package TYPO3
31 * @subpackage reports
32 */
33 class tx_reports_tasks_SystemStatusUpdateTask extends tx_scheduler_Task {
34
35 /**
36 * Email address to send email notification to in case we find problems with
37 * the system.
38 *
39 * @var string
40 */
41 protected $notificationEmail = NULL;
42
43 /**
44 * Executes the System Status Update task, determing the highest severity of
45 * status reports and saving that to the registry to be displayed at login
46 * if necessary.
47 *
48 * @see typo3/sysext/scheduler/tx_scheduler_Task::execute()
49 */
50 public function execute() {
51 $registry = t3lib_div::makeInstance('t3lib_Registry');
52 $statusReport = t3lib_div::makeInstance('tx_reports_reports_Status');
53
54 $systemStatus = $statusReport->getSystemStatus();
55 $highestSeverity = $statusReport->getHighestSeverity($systemStatus);
56
57 $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
58
59 if ($highestSeverity > tx_reports_reports_status_Status::OK) {
60 $this->sendNotificationEmail($systemStatus);
61 }
62
63 return TRUE;
64 }
65
66 /**
67 * Gets the notification email address.
68 *
69 * @return string Notification email address.
70 */
71 public function getNotificationEmail() {
72 return $this->notificationEmail;
73 }
74
75 /**
76 * Sets the notification email address.
77 *
78 * @param string $notificationEmail Notification email address.
79 */
80 public function setNotificationEmail($notificationEmail) {
81 $this->notificationEmail = $notificationEmail;
82 }
83
84 /**
85 * Sends a notification email, reporting system issues.
86 *
87 * @param array $systemStatus Array of statuses
88 */
89 protected function sendNotificationEmail(array $systemStatus) {
90 $systemIssues = array();
91
92 foreach ($systemStatus as $statusProvider) {
93 foreach ($statusProvider as $status) {
94 if ($status->getSeverity() > tx_reports_reports_status_Status::OK) {
95 $systemIssues[] = (string) $status;
96 }
97 }
98 }
99
100 $subject = sprintf(
101 $GLOBALS['LANG']->getLL('status_updateTask_email_subject'),
102 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
103 );
104
105 $message = sprintf(
106 $GLOBALS['LANG']->getLL('status_problemNotification'),
107 '',
108 ''
109 );
110 $message .= CRLF . CRLF;
111 $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site')
112 . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
113 $message .= CRLF . CRLF;
114 $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues')
115 . ': ' .CRLF;
116 $message .= implode(CRLF, $systemIssues);
117 $message .= CRLF . CRLF;
118
119 $from = t3lib_utility_Mail::getSystemFrom();
120
121 $mail = t3lib_div::makeInstance('t3lib_mail_Message');
122 $mail->setFrom($from);
123 $mail->setTo($this->notificationEmail);
124 $mail->setSubject($subject);
125 $mail->setBody($message);
126
127 $mail->send();
128 }
129 }
130
131
132 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php'])) {
133 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php']);
134 }
135
136 ?>