|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2010-2011 Ingo Renner <ingo@typo3.org> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 00026 /** 00027 * A task that should be run regularly to determine the system's status. 00028 * 00029 * @author Ingo Renner <ingo@typo3.org> 00030 * @package TYPO3 00031 * @subpackage reports 00032 */ 00033 class tx_reports_tasks_SystemStatusUpdateTask extends tx_scheduler_Task { 00034 00035 /** 00036 * Email address to send email notification to in case we find problems with 00037 * the system. 00038 * 00039 * @var string 00040 */ 00041 protected $notificationEmail = NULL; 00042 00043 /** 00044 * Executes the System Status Update task, determing the highest severity of 00045 * status reports and saving that to the registry to be displayed at login 00046 * if necessary. 00047 * 00048 * @see typo3/sysext/scheduler/tx_scheduler_Task::execute() 00049 */ 00050 public function execute() { 00051 $registry = t3lib_div::makeInstance('t3lib_Registry'); 00052 $statusReport = t3lib_div::makeInstance('tx_reports_reports_Status'); 00053 00054 $systemStatus = $statusReport->getSystemStatus(); 00055 $highestSeverity = $statusReport->getHighestSeverity($systemStatus); 00056 00057 $registry->set('tx_reports', 'status.highestSeverity', $highestSeverity); 00058 00059 if ($highestSeverity > tx_reports_reports_status_Status::OK) { 00060 $this->sendNotificationEmail($systemStatus); 00061 } 00062 00063 return true; 00064 } 00065 00066 /** 00067 * Gets the notification email address. 00068 * 00069 * @return string Notification email address. 00070 */ 00071 public function getNotificationEmail() { 00072 return $this->notificationEmail; 00073 } 00074 00075 /** 00076 * Sets the notification email address. 00077 * 00078 * @param string $notificationEmail Notification email address. 00079 */ 00080 public function setNotificationEmail($notificationEmail) { 00081 $this->notificationEmail = $notificationEmail; 00082 } 00083 00084 /** 00085 * Sends a notification email, reporting system issues. 00086 * 00087 * @param array $systemStatus Array of statuses 00088 */ 00089 protected function sendNotificationEmail(array $systemStatus) { 00090 $systemIssues = array(); 00091 00092 foreach ($systemStatus as $statusProvider) { 00093 foreach ($statusProvider as $status) { 00094 if ($status->getSeverity() > tx_reports_reports_status_Status::OK) { 00095 $systemIssues[] = (string) $status; 00096 } 00097 } 00098 } 00099 00100 $subject = sprintf( 00101 $GLOBALS['LANG']->getLL('status_updateTask_email_subject'), 00102 $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'] 00103 ); 00104 00105 $message = sprintf( 00106 $GLOBALS['LANG']->getLL('status_problemNotification'), 00107 '', 00108 '' 00109 ); 00110 $message .= CRLF . CRLF; 00111 $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site') 00112 . ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']; 00113 $message .= CRLF . CRLF; 00114 $message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues') 00115 . ': ' .CRLF; 00116 $message .= implode(CRLF, $systemIssues); 00117 $message .= CRLF . CRLF; 00118 00119 $from = t3lib_utility_Mail::getSystemFrom(); 00120 00121 $mail = t3lib_div::makeInstance('t3lib_mail_Message'); 00122 $mail->setFrom($from); 00123 $mail->setTo($this->notificationEmail); 00124 $mail->setSubject($subject); 00125 $mail->setBody($message); 00126 00127 $mail->send(); 00128 } 00129 } 00130 00131 00132 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php'])) { 00133 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php']); 00134 } 00135 00136 ?>
1.8.0