Project

General

Profile

Feature #24572 ยป 17033.diff

Administrator Admin, 2011-01-17 11:55

View differences:

typo3/sysext/reports/reports/status/class.tx_reports_reports_status_status.php (working copy)
public function getSeverity() {
return $this->severity;
}
/**
* Creates a string representation of a status.
*
* @return string String representation of this status.
*/
public function __toString() {
$severity = array(
self::NOTICE => 'NOTE',
self::INFO => 'INFO',
self::OK => 'OK',
self::WARNING => 'WARN',
self::ERROR => 'ERR',
);
// max length 80 characters
$stringRepresentation =
str_pad('[' . $severity[$this->severity] . ']', 7) .
str_pad($this->title, 40) . ' - ' .
substr($this->value, 0, 30);
return $stringRepresentation;
}
}
typo3/sysext/reports/reports/locallang.xml (working copy)
<label index="status_configuration_DeprecationLogSize">Your deprecation log file currently takes up %s.</label>
<label index="status_updateTaskTitle">System Status Update</label>
<label index="status_updateTaskDescription">Runs a system status check and sends notifications if problems have been found.</label>
<label index="status_updateTaskField_notificationEmail">Notification Email Address</label>
<label index="status_updateTaskField_notificationEmail_invlaid">Empty or invalid notification email address.</label>
<label index="status_updateTask_email_subject">System Status Notification for site %s</label>
<label index="status_updateTask_email_site">Site</label>
<label index="status_updateTask_email_issues">Issues</label>
</languageKey>
</data>
</T3locallang>
typo3/sysext/reports/ext_autoload.php (working copy)
'tx_reports_reports_status_configurationstatus' => $extensionPath . 'reports/status/class.tx_reports_reports_status_configurationstatus.php',
'tx_reports_reports_status_status' => $extensionPath . 'reports/status/class.tx_reports_reports_status_status.php',
'tx_reports_tasks_systemstatusupdatetask' => $extensionPath . 'tasks/class.tx_reports_tasks_systemstatusupdatetask.php',
'tx_reports_tasks_systemstatusupdatetasknotificationemailfield' => $extensionPath . 'tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php',
);
?>
typo3/sysext/reports/ext_localconf.php (working copy)
}
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['scheduler']['tasks']['tx_reports_tasks_SystemStatusUpdateTask'] = array(
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskTitle',
'description' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskDescription'
'extension' => $_EXTKEY,
'title' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskTitle',
'description' => 'LLL:EXT:' . $_EXTKEY . '/reports/locallang.xml:status_updateTaskDescription',
'additionalFields' => 'tx_reports_tasks_SystemStatusUpdateTaskNotificationEmailField'
);
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_befunc.php']['displayWarningMessages']['tx_reports_WarningMessagePostProcessor'] = 'EXT:reports/reports/status/class.tx_reports_reports_status_warningmessagepostprocessor.php:tx_reports_reports_status_WarningMessagePostProcessor';
typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php (revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 2010 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Additional field to set the notification email address(es) for system health
* issue notifications.
*
* @author Ingo Renner <ingo@typo3.org>
* @package TYPO3
* @subpackage reports
*/
class tx_reports_tasks_SystemStatusUpdateTaskNotificationEmailField implements tx_scheduler_AdditionalFieldProvider {
/**
* Additional fields
*
* @var array
*/
protected $fields = array('notificationEmail');
/**
* Field prefix.
*
* @var string
*/
protected $fieldPrefix = 'SystemStatusUpdate';
/**
* Gets additional fields to render in the form to add/edit a task
*
* @param array $taskInfo Values of the fields from the add/edit task form
* @param tx_scheduler_Task $task The task object being eddited. Null when adding a task!
* @param tx_scheduler_Module $schedulerModule Reference to the scheduler backend module
* @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
*/
public function getAdditionalFields(array &$taskInfo, $task, tx_scheduler_Module $schedulerModule) {
$fields = array('notificationEmail');
if ($schedulerModule->CMD == 'edit') {
$taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
}
$additionalFields = array();
foreach ($fields as $field) {
$fieldName = $this->getFullFieldName($field);
$fieldId = 'task_' . $fieldName;
$fieldHtml = '<input type="text" '
. 'name="tx_scheduler[' . $fieldName . ']" '
. 'id="' . $fieldId . '" '
. 'value="' . $taskInfo[$fieldName] . '" />';
$additionalFields[$fieldId] = array(
'code' => $fieldHtml,
'label' => 'LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_' . $field,
'cshKey' => '',
'cshLabel' => $fieldId
);
}
return $additionalFields;
}
/**
* Validates the additional fields' values
*
* @param array $submittedData An array containing the data submitted by the add/edit task form
* @param tx_scheduler_Module $schedulerModule Reference to the scheduler backend module
* @return boolean True if validation was ok (or selected class is not relevant), false otherwise
*/
public function validateAdditionalFields(array &$submittedData, tx_scheduler_Module $schedulerModule) {
$validInput = TRUE;
$submittedData[$this->fieldPrefix . 'NotificationEmail'] = trim($submittedData[$this->fieldPrefix . 'NotificationEmail']);
if (
empty($submittedData[$this->fieldPrefix . 'NotificationEmail'])
|| !filter_var($submittedData[$this->fieldPrefix . 'NotificationEmail'], FILTER_VALIDATE_EMAIL)
) {
$schedulerModule->addMessage(
$GLOBALS['LANG']->sL('LLL:EXT:reports/reports/locallang.xml:status_updateTaskField_notificationEmail_invalid'),
t3lib_FlashMessage::ERROR
);
$validInput = FALSE;
}
return $validInput;
}
/**
* Takes care of saving the additional fields' values in the task's object
*
* @param array $submittedData An array containing the data submitted by the add/edit task form
* @param tx_scheduler_Task $task Reference to the scheduler backend module
* @return void
*/
public function saveAdditionalFields(array $submittedData, tx_scheduler_Task $task) {
if (!($task instanceof tx_reports_tasks_SystemStatusUpdateTask)) {
throw new InvalidArgumentException(
'Expected a task of type tx_reports_tasks_SystemStatusUpdateTask, but got ' . get_class($task),
1295012802
);
}
$task->setNotificationEmail($submittedData[$this->fieldPrefix . 'NotificationEmail']);
}
/**
* Constructs the full field name which can be used in HTML markup.
*
* @param string $fieldName A raw field name
* @return string Field name ready to use in HTML markup
*/
protected function getFullFieldName($fieldName) {
return $this->fieldPrefix . ucfirst($fieldName);
}
}
if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php'])) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetasknotificationemailfield.php']);
}
?>
typo3/sysext/reports/tasks/class.tx_reports_tasks_systemstatusupdatetask.php (working copy)
class tx_reports_tasks_SystemStatusUpdateTask extends tx_scheduler_Task {
/**
* Email address to send email notification to in case we find problems with
* the system.
*
* @var string
*/
protected $notificationEmail = NULL;
/**
* Executes the System Status Update task, determing the highest severity of
* status reports and saving that to the registry to be displayed at login
* if necessary.
......
$registry->set('tx_reports', 'status.highestSeverity', $highestSeverity);
if ($highestSeverity > tx_reports_reports_status_Status::OK) {
$this->sendNotificationEmail($systemStatus);
}
return true;
}
/**
* Gets the notification email address.
*
* @return string Notification email address.
*/
public function getNotificationEmail() {
return $this->notificationEmail;
}
/**
* Sets the notification email address.
*
* @param string $notificationEmail Notification email address.
*/
public function setNotificationEmail($notificationEmail) {
$this->notificationEmail = $notificationEmail;
}
/**
* Sends a notification email, reporting system issues.
*
* @param array $systemStatus Array of statuses
*/
protected function sendNotificationEmail(array $systemStatus) {
$systemIssues = array();
foreach ($systemStatus as $statusProvider) {
foreach ($statusProvider as $status) {
if ($status->getSeverity() > tx_reports_reports_status_Status::OK) {
$systemIssues[] = (string) $status;
}
}
}
$fromEmail = $this->getFromAddress();
$subject = sprintf(
$GLOBALS['LANG']->getLL('status_updateTask_email_subject'),
$GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']
);
$message = sprintf(
$GLOBALS['LANG']->getLL('status_problemNotification'),
'',
''
);
$message .= CRLF . CRLF;
$message .= $GLOBALS['LANG']->getLL('status_updateTask_email_site')
. ': ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
$message .= CRLF . CRLF;
$message .= $GLOBALS['LANG']->getLL('status_updateTask_email_issues')
. ': ' .CRLF;
$message .= implode(CRLF, $systemIssues);
$message .= CRLF . CRLF;
$mail = t3lib_div::makeInstance('t3lib_mail_Message');
$mail->setFrom(array($fromEmail => 'TYPO3 CMS'));
$mail->setTo($this->notificationEmail);
$mail->setSubject($subject);
$mail->setBody($message);
$mail->send();
}
/**
* Tries to generate an email address to use for the From field.
*
* @return string email address
*/
protected function getFromAddress() {
$user = 'no-reply';
$host = php_uname('n');
// just get us a domain record we can use
$domainRecord = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow(
'domainName',
'sys_domain',
'hidden = 0',
'',
'pid ASC, sorting ASC'
);
if (!empty($domainRecord['domainName'])) {
$tempUrl = $domainRecord['domainName'];
if (!t3lib_div::isFirstPartOfStr($tempUrl, 'http')) {
// shouldn't be the case anyways, but you never know
// ... there're crazy people out there
$tempUrl = 'http://' .$tempUrl;
}
$host = parse_url($tempUrl, PHP_URL_HOST);
}
return $user . '@' . $host;
}
}
    (1-1/1)