Attached Files |
email_log_writing_changes_447.patch [^] (3,715 bytes) 2011-12-12 09:18
[Show Content]
Index: install/install_schema.sql
===================================================================
--- install/install_schema.sql (revision 14860)
+++ install/install_schema.sql (working copy)
@@ -76,6 +76,7 @@
SendRetries int(10) unsigned NOT NULL DEFAULT '0',
LastSendRetry int(10) unsigned DEFAULT NULL,
MailingId int(10) unsigned NOT NULL DEFAULT '0',
+ LogData text,
PRIMARY KEY (EmailQueueId),
KEY LastSendRetry (LastSendRetry),
KEY SendRetries (SendRetries),
Index: install/upgrades.sql
===================================================================
--- install/upgrades.sql (revision 14860)
+++ install/upgrades.sql (working copy)
@@ -2377,4 +2377,6 @@
INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.ADD', 11, 1, 0, 1);
INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.HISTORY.VIEW', 11, 1, 0, 1);
-INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.HISTORY.RESTORE', 11, 1, 0, 1);
\ No newline at end of file
+INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.HISTORY.RESTORE', 11, 1, 0, 1);
+
+ALTER TABLE EmailQueue ADD `LogData` TEXT;
\ No newline at end of file
Index: kernel/utility/email_send.php
===================================================================
--- kernel/utility/email_send.php (revision 14860)
+++ kernel/utility/email_send.php (working copy)
@@ -118,7 +118,14 @@
*/
var $smtpFeatures = Array();
+ /**
+ * Stores log data.
+ * @var array
+ * @access private
+ */
+ var $_logData = Array();
+
public function __construct()
{
parent::__construct();
@@ -1132,6 +1139,7 @@
);
$this->SetCharset(null, true);
+ $this->_logData = Array();
}
/**
@@ -2002,6 +2010,7 @@
'SendRetries' => 0,
'LastSendRetry' => 0,
'MailingId' => (int)$immediate_send,
+ 'LogData' => serialize($this->_logData),
);
$fields_hash['MessageHeaders'] = serialize($message_headers);
$fields_hash['MessageBody'] =& $message_body;
@@ -2017,4 +2026,13 @@
return $immediate_send !== true ? true : false;
}
+ /**
+ * Sets log data
+ *
+ * @param string $log_data
+ */
+ function setLogData($log_data)
+ {
+ $this->_logData = $log_data;
+ }
}
\ No newline at end of file
Index: units/helpers/mailing_list_helper.php
===================================================================
--- units/helpers/mailing_list_helper.php (revision 14860)
+++ units/helpers/mailing_list_helper.php (working copy)
@@ -55,7 +55,6 @@
// 3. set recipient specific fields
$esender->SetTo($email, $email);
- $esender->Deliver(null, $mailing_id, false);
// 4. write to log
$log_fields_hash = Array (
@@ -65,8 +64,9 @@
'timestamp' => adodb_mktime(),
'EventParams' => serialize( Array ('MailingId' => $mailing_id) ),
);
+ $esender->setLogData($log_fields_hash);
- $this->Conn->doInsert($log_fields_hash, TABLE_PREFIX . 'EmailLog');
+ $esender->Deliver(null, $mailing_id, false);
}
/**
@@ -80,7 +80,7 @@
{
$is_root = true;
$email_address = $name = '';
-
+
if ( $mailing_data['PortalUserId'] > 0 ) {
$sender =& $this->Application->recallObject('u.-item', null, Array ('skip_autoload' => true));
/* @var $sender UsersItem */
@@ -271,6 +271,9 @@
WHERE EmailQueueId = ' . $messages[$i]['EmailQueueId'];
$this->Conn->Query($sql);
+ // add emal log record
+ $this->Conn->doInsert(unserialize($messages[$i]['LogData']), TABLE_PREFIX . 'EmailLog');
+
$mailing_id = $messages[$i]['MailingId'];
if (!array_key_exists($mailing_id, $mailing_totals)) {
$mailing_totals[$mailing_id] = 0;
log_email_only_after_sending_v2.patch [^] (7,178 bytes) 2011-12-13 03:37
[Show Content]
Index: install/install_schema.sql
===================================================================
--- install/install_schema.sql (revision 14858)
+++ install/install_schema.sql (working copy)
@@ -76,6 +76,7 @@
SendRetries int(10) unsigned NOT NULL DEFAULT '0',
LastSendRetry int(10) unsigned DEFAULT NULL,
MailingId int(10) unsigned NOT NULL DEFAULT '0',
+ LogData text,
PRIMARY KEY (EmailQueueId),
KEY LastSendRetry (LastSendRetry),
KEY SendRetries (SendRetries),
Index: install/upgrades.sql
===================================================================
--- install/upgrades.sql (revision 14858)
+++ install/upgrades.sql (working copy)
@@ -2377,4 +2377,6 @@
INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.ADD', 11, 1, 0, 1);
INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.HISTORY.VIEW', 11, 1, 0, 1);
-INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.HISTORY.RESTORE', 11, 1, 0, 1);
\ No newline at end of file
+INSERT INTO Permissions VALUES(DEFAULT, 'CATEGORY.REVISION.HISTORY.RESTORE', 11, 1, 0, 1);
+
+ALTER TABLE EmailQueue ADD `LogData` TEXT;
\ No newline at end of file
Index: kernel/utility/email_send.php
===================================================================
--- kernel/utility/email_send.php (revision 14858)
+++ kernel/utility/email_send.php (working copy)
@@ -118,6 +118,13 @@
*/
var $smtpFeatures = Array();
+ /**
+ * Stores log data
+ *
+ * @var Array
+ * @access protected
+ */
+ protected $_logData = Array ();
public function __construct()
{
@@ -1123,15 +1130,16 @@
{
$this->headers = Array ();
$this->bodyPartNumber = false;
- $this->parts = Array();
+ $this->parts = Array ();
$this->guessOptions = Array (
- 'attachments' => Array(),
+ 'attachments' => Array (),
'inline_attachments' => Array (),
'text_part' => false,
'html_part' => false,
);
$this->SetCharset(null, true);
+ $this->_logData = Array ();
}
/**
@@ -1984,14 +1992,20 @@
$composed = $this->GetHeadersAndBody($message_headers, $message_body);
}
- if ($composed) {
- if ($immediate_send === true) {
- $send_method = 'Send'.$this->sendMethod;
+ if ( $composed ) {
+ if ( $immediate_send === true ) {
+ $send_method = 'Send' . $this->sendMethod;
$result = $this->$send_method($message_headers, $message_body);
- if ($immediate_clear) {
+ if ( $result && $this->_logData ) {
+ // add e-mail log record
+ $this->Conn->doInsert($this->_logData, TABLE_PREFIX . 'EmailLog');
+ }
+
+ if ( $immediate_clear ) {
$this->Clear();
}
+
return $result;
}
else {
@@ -2002,12 +2016,14 @@
'SendRetries' => 0,
'LastSendRetry' => 0,
'MailingId' => (int)$immediate_send,
+ 'LogData' => serialize($this->_logData), // remember e-mail log record
);
+
$fields_hash['MessageHeaders'] = serialize($message_headers);
$fields_hash['MessageBody'] =& $message_body;
- $this->Conn->doInsert($fields_hash, TABLE_PREFIX.'EmailQueue');
+ $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'EmailQueue');
- if ($immediate_clear) {
+ if ( $immediate_clear ) {
$this->Clear();
}
}
@@ -2017,4 +2033,15 @@
return $immediate_send !== true ? true : false;
}
+ /**
+ * Sets log data
+ *
+ * @param string $log_data
+ * @return void
+ * @access public
+ */
+ public function setLogData($log_data)
+ {
+ $this->_logData = $log_data;
+ }
}
\ No newline at end of file
Index: units/email_events/email_events_event_handler.php
===================================================================
--- units/email_events/email_events_event_handler.php (revision 14858)
+++ units/email_events/email_events_event_handler.php (working copy)
@@ -713,26 +713,35 @@
$esender->CreateTextHtmlPart($message_body, $object->GetDBField('MessageType') == 'html');
+ $log_fields_hash = Array (
+ 'fromuser' => $from_name . ' (' . $from_email . ')',
+ 'addressto' => $to_name . ' (' . $to_email . ')',
+ 'subject' => $message_subject,
+ 'timestamp' => adodb_mktime(),
+ 'event' => $email_event_name,
+ 'EventParams' => serialize( $this->removeSendingParams($send_params) ),
+ );
+
+ $esender->setLogData($log_fields_hash);
$event->status = $esender->Deliver() ? kEvent::erSUCCESS : kEvent::erFAIL;
+ }
- if ( $event->status == kEvent::erSUCCESS ) {
- // all keys, that are not used in email sending are written to log record
- $send_keys = Array ('from_email', 'from_name', 'to_email', 'to_name', 'message');
- foreach ($send_keys as $send_key) {
- unset($send_params[$send_key]);
- }
+ /**
+ * Removes parameters, used during e-mail sending
+ *
+ * @param Array $params
+ * @return Array
+ * @access protected
+ */
+ protected function removeSendingParams($params)
+ {
+ $send_keys = Array ('from_email', 'from_name', 'to_email', 'to_name', 'message');
- $fields_hash = Array (
- 'fromuser' => $from_name . ' (' . $from_email . ')',
- 'addressto' => $to_name . ' (' . $to_email . ')',
- 'subject' => $message_subject,
- 'timestamp' => adodb_mktime(),
- 'event' => $email_event_name,
- 'EventParams' => serialize($send_params),
- );
+ foreach ($send_keys as $send_key) {
+ unset($params[$send_key]);
+ }
- $this->Conn->doInsert($fields_hash, TABLE_PREFIX . 'EmailLog');
- }
+ return $params;
}
function _getSendLanguage($send_params)
Index: units/helpers/mailing_list_helper.php
===================================================================
--- units/helpers/mailing_list_helper.php (revision 14858)
+++ units/helpers/mailing_list_helper.php (working copy)
@@ -55,7 +55,6 @@
// 3. set recipient specific fields
$esender->SetTo($email, $email);
- $esender->Deliver(null, $mailing_id, false);
// 4. write to log
$log_fields_hash = Array (
@@ -66,7 +65,8 @@
'EventParams' => serialize( Array ('MailingId' => $mailing_id) ),
);
- $this->Conn->doInsert($log_fields_hash, TABLE_PREFIX . 'EmailLog');
+ $esender->setLogData($log_fields_hash);
+ $esender->Deliver(null, $mailing_id, false);
}
/**
@@ -80,7 +80,7 @@
{
$is_root = true;
$email_address = $name = '';
-
+
if ( $mailing_data['PortalUserId'] > 0 ) {
$sender =& $this->Application->recallObject('u.-item', null, Array ('skip_autoload' => true));
/* @var $sender UsersItem */
@@ -263,10 +263,12 @@
while ($i < $message_count) {
$message[0] = unserialize($messages[$i]['MessageHeaders']);
$message[1] =& $messages[$i]['MessageBody'];
+
+ $esender->setLogData( unserialize($messages[$i]['LogData']) );
$delivered = $esender->Deliver($message, true); // immediate send!
if ($delivered) {
- // send succseeded, delete from queue
+ // send succeeded, delete from queue
$sql = 'DELETE FROM ' . $queue_table . '
WHERE EmailQueueId = ' . $messages[$i]['EmailQueueId'];
$this->Conn->Query($sql);
|