Index: core/units/logs/email_logs/email_logs_config.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/units/logs/email_logs/email_logs_config.php (revision 15938) +++ core/units/logs/email_logs/email_logs_config.php (revision ) @@ -89,6 +89,14 @@ 'Subject' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), 'HtmlBody' => Array ('type' => 'string', 'default' => NULL), 'TextBody' => Array ('type' => 'string', 'default' => NULL), + 'Status' => Array ( + 'type' => 'int', + 'formatter' => 'kOptionsFormatter', 'options' => Array ( + EmailLogStatus::SENT => 'la_opt_Sent', + EmailLogStatus::ERROR => 'la_opt_Error' + ), 'use_phrases' => 1, 'not_null' => 1, 'default' => EmailLogStatus::SENT + ), + 'ErrorMessage' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), 'SentOn' => Array ('type' => 'int', 'formatter' => 'kDateFormatter', 'default' => '#NOW#'), 'TemplateName' => Array ('type' => 'string', 'max_len' => 255, 'not_null' => 1, 'default' => ''), 'EventType' => Array ( @@ -124,6 +132,8 @@ 'Subject' => Array ('filter_block' => 'grid_like_filter', 'width' => 200), 'TemplateName' => Array ('filter_block' => 'grid_like_filter', 'width' => 170), 'EventType' => Array ('title' => 'column:la_fld_Type', 'filter_block' => 'grid_options_filter', 'width' => 60), + 'Status' => Array ('filter_block' => 'grid_options_filter', 'width' => 100), + 'ErrorMessage' => Array ('filter_block' => 'grid_like_filter', 'width' => 200), 'SentOn' => Array ('title' => 'la_prompt_SentOn', 'filter_block' => 'grid_date_range_filter', 'width' => 145), // 'EventParams' => Array ('title' => 'la_col_EventParams', 'filter_block' => 'grid_like_filter'), 'ItemPrefix' => Array('filter_block' => 'grid_options_filter'), \ No newline at end of file Index: core/install/upgrades.sql IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/install/upgrades.sql (revision 15938) +++ core/install/upgrades.sql (revision ) @@ -2955,3 +2955,7 @@ ADD ItemId INT(11) DEFAULT NULL; DELETE FROM UserPersistentSessionData WHERE VariableName = 'email-log[Default]columns_.'; + +ALTER TABLE EmailLog + ADD Status TINYINT NOT NULL DEFAULT '1' AFTER TextBody, + ADD ErrorMessage VARCHAR(255) NOT NULL DEFAULT '' AFTER Status; Index: core/admin_templates/logs/email_logs/email_log_edit.tpl IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/admin_templates/logs/email_logs/email_log_edit.tpl (revision 15938) +++ core/admin_templates/logs/email_logs/email_log_edit.tpl (revision ) @@ -89,6 +89,12 @@ + + + + + + \ No newline at end of file Index: core/kernel/constants.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/constants.php (revision 15928) +++ core/kernel/constants.php (revision ) @@ -210,7 +210,13 @@ const IMMEDIATE = 2; } + class EmailLogStatus + { + const SENT = 1; + const ERROR = 2; + } + -class TranslationSaveMode { - const SYNC_WITH_PRIMARY = 1; - const MAKE_PRIMARY = 2; -} \ No newline at end of file + class TranslationSaveMode { + const SYNC_WITH_PRIMARY = 1; + const MAKE_PRIMARY = 2; + } \ No newline at end of file Index: core/install/install_schema.sql IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/install/install_schema.sql (revision 15938) +++ core/install/install_schema.sql (revision ) @@ -427,6 +427,8 @@ `Subject` varchar(255) NOT NULL DEFAULT '', HtmlBody longtext, TextBody longtext, + `Status` tinyint(4) NOT NULL DEFAULT '1', + ErrorMessage varchar(255) NOT NULL DEFAULT '', SentOn int(11) DEFAULT NULL, TemplateName varchar(255) NOT NULL DEFAULT '', EventType tinyint(4) DEFAULT NULL, \ No newline at end of file Index: core/kernel/utility/email.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/utility/email.php (revision 15938) +++ core/kernel/utility/email.php (revision ) @@ -92,6 +92,13 @@ ); /** + * Stores log data. + * + * @var array + */ + protected $logData = array(); + + /** * Creates e-mail instance */ public function __construct() @@ -109,6 +116,8 @@ */ protected function _resetState() { + $this->logData = array(); + $this->fromEmail = $this->fromName = ''; $this->Application->removeObject('u.email-from'); @@ -233,14 +242,32 @@ $this->_processRecipients(); $this->_changeLanguage(false); + if ( $this->_storeEmailLog() ) { + // 1. prepare log + $this->logData = Array ( + 'From' => $this->fromName . ' (' . $this->fromEmail . ')', + 'To' => $this->toName . ' (' . $this->toEmail . ')', + 'OtherRecipients' => serialize($this->recipients), + 'Status' => EmailLogStatus::SENT, + 'ErrorMessage' => '', + 'SentOn' => TIMENOW, + 'TemplateName' => $this->emailTemplate->GetDBField('TemplateName'), + 'EventType' => $this->emailTemplate->GetDBField('Type'), + 'EventParams' => serialize($this->_getCustomParams()), + 'ToUserId' => $this->recipientUserId, + 'ItemPrefix' => $this->getItemPrefix(), + 'ItemId' => isset($this->params['item_id']) ? $this->params['item_id'] : null, + ); + + $this->params['email_access_key'] = $this->_generateAccessKey(); + } + // 1. set headers try { $message_headers = $this->_getHeaders(); } catch ( Exception $e ) { - trigger_error('Error parsing e-mail message headers', E_USER_WARNING); - - return false; + return $this->setError('Error parsing e-mail message headers'); } $message_subject = isset($message_headers['Subject']) ? $message_headers['Subject'] : 'Mail message'; @@ -251,22 +278,7 @@ } if ( $this->_storeEmailLog() ) { - // 2. prepare log - $log_fields_hash = Array ( - 'From' => $this->fromName . ' (' . $this->fromEmail . ')', - 'To' => $this->toName . ' (' . $this->toEmail . ')', - 'OtherRecipients' => serialize($this->recipients), - 'Subject' => $message_subject, - 'SentOn' => TIMENOW, - 'TemplateName' => $this->emailTemplate->GetDBField('TemplateName'), - 'EventType' => $this->emailTemplate->GetDBField('Type'), - 'EventParams' => serialize($this->_getCustomParams()), - 'ToUserId' => $this->recipientUserId, - 'ItemPrefix' => $this->getItemPrefix(), - 'ItemId' => isset($this->params['item_id']) ? $this->params['item_id'] : null, - ); - - $this->params['email_access_key'] = $this->_generateAccessKey($log_fields_hash); + $this->logData['Subject'] = $message_subject; } // 3. set body @@ -275,15 +287,11 @@ $plain_message_body = $this->_getMessageBody(false); } catch ( Exception $e ) { - trigger_error('Error parsing e-mail message body', E_USER_WARNING); - - return false; + return $this->setError('Error parsing e-mail message body'); } if ( $html_message_body === false && $plain_message_body === false ) { - trigger_error('Message template is empty (maybe after parsing).', E_USER_WARNING); - - return false; + return $this->setError('Message template is empty (maybe after parsing).'); } if ( $html_message_body !== false ) { @@ -298,10 +306,10 @@ if ( $this->_storeEmailLog() ) { // 4. set log - $log_fields_hash['HtmlBody'] = $html_message_body; - $log_fields_hash['TextBody'] = $plain_message_body; - $log_fields_hash['AccessKey'] = $this->params['email_access_key']; - $this->sender->setLogData($log_fields_hash); + $this->logData['HtmlBody'] = $html_message_body; + $this->logData['TextBody'] = $plain_message_body; + $this->logData['AccessKey'] = $this->params['email_access_key']; + $this->sender->setLogData($this->logData); } $delivery = isset($this->params['delivery']) ? $this->params['delivery'] : $this->Application->ConfigValue('EmailDelivery'); @@ -339,19 +347,36 @@ } /** + * Marks e-mail sending as failed. + * + * @param string $error_message Error message. + * + * @return boolean + */ + protected function setError($error_message) + { + if ( $this->_storeEmailLog() ) { + $this->logData['Status'] = EmailLogStatus::ERROR; + $this->logData['ErrorMessage'] = $error_message; + $this->Conn->doInsert($this->logData, TABLE_PREFIX . 'EmailLog'); + } + + return false; + } + + /** * Generates access key for accessing e-mail later * - * @param Array $log_fields_hash * @return string * @access protected */ - protected function _generateAccessKey($log_fields_hash) + protected function _generateAccessKey() { $ret = ''; $use_fields = Array ('From', 'To', 'Subject'); foreach ($use_fields as $use_field) { - $ret .= $log_fields_hash[$use_field] . ':'; + $ret .= $this->logData[$use_field] . ':'; } return md5($ret . microtime(true)); Index: core/install/english.lang IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/install/english.lang (revision 15938) +++ core/install/english.lang (revision ) @@ -417,6 +417,7 @@ RW5hYmxl RW5hYmxlZA== RW5hYmxlIENhY2hpbmcgZm9yIHRoaXMgU2VjdGlvbg== + RXJyb3IgTWVzc2FnZQ== RXJyb3IgVGFn RXN0aW1hdGVkIFRpbWU= RXZlbnQ= @@ -906,6 +907,7 @@ Rm9yZXZlciAobmV2ZXIgZGVsZXRlZCBhdXRvbWF0aWNhbGx5KQ== RS1tYWlsIFN1YmplY3Q= RS1tYWlsIFRlbXBsYXRlcw== + RXJyb3I= RXZlcnlvbmU= RXhhY3Q= RXhwaXJlZA== @@ -969,6 +971,7 @@ U2F0dXJkYXk= c2Vjb25kKHMp U2VtaS1jb2xvbg== + U2VudA== U2VwdGVtYmVy U2lsZW50 U3BhY2U= Index: core/kernel/utility/email_send.php IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- core/kernel/utility/email_send.php (revision 15928) +++ core/kernel/utility/email_send.php (revision ) @@ -1127,15 +1127,22 @@ $error_msg = 'mail error: ' . vsprintf($error_msgs[$code], $params); + if ( $this->_logData ) { + $this->_logData['Status'] = EmailLogStatus::ERROR; + $this->_logData['ErrorMessage'] = $error_msg; + $this->Conn->doInsert($this->_logData, TABLE_PREFIX . 'EmailLog'); + } + else { - if ($fatal) { - throw new Exception($error_msg); - } - else { - if ( $this->Application->isDebugMode() ) { - $this->Application->Debugger->appendTrace(); - } + if ($fatal) { + throw new Exception($error_msg); + } + else { + if ( $this->Application->isDebugMode() ) { + $this->Application->Debugger->appendTrace(); + } - trigger_error($error_msg, E_USER_WARNING); + trigger_error($error_msg, E_USER_WARNING); + } } return false; \ No newline at end of file