Index: admin_templates/mailing_lists/send_complete.tpl
===================================================================
--- admin_templates/mailing_lists/send_complete.tpl (revision 15907)
+++ admin_templates/mailing_lists/send_complete.tpl (working copy)
@@ -1,7 +1,7 @@
-
+
\ No newline at end of file
Index: install/english.lang
===================================================================
--- install/english.lang (revision 15907)
+++ install/english.lang (working copy)
@@ -165,7 +165,7 @@
RGVmYXVsdCAiUGVyIFBhZ2UiIHNldHRpbmcgaW4gR3JpZHM=
RGVmYXVsdCBSZWdpc3RyYXRpb24gQ291bnRyeQ==
RGVmYXVsdCBBbmFseXRpY3MgVHJhY2tpbmcgQ29kZQ==
- S2VlcCAiRS1tYWlsIExvZyIgZm9y
+ RW1haWwgRGVsaXZlcnk= S2VlcCAiRS1tYWlsIExvZyIgZm9y
RW5hYmxlICJFLW1haWwgTG9nIg==
RW5hYmxlIFJldmlzaW9uIENvbnRyb2wgZm9yIFNlY3Rpb24gQ29udGVudA==
VGVtcGxhdGUgZm9yICJGaWxlIG5vdCBmb3VuZCAoNDA0KSIgRXJyb3I=
@@ -899,6 +899,8 @@
RWRpdG9yJ3MgUGljaw==
RS1tYWls
RS1tYWlsIEJvZHk=
+ SW1tZWRpYXRl
+ RW1haWwgUXVldWU=
Rm9yZXZlciAobmV2ZXIgZGVsZXRlZCBhdXRvbWF0aWNhbGx5KQ==
RS1tYWlsIFN1YmplY3Q=
RS1tYWlsIFRlbXBsYXRlcw==
Index: install/install_data.sql
===================================================================
--- install/install_data.sql (revision 15907)
+++ install/install_data.sql (working copy)
@@ -91,6 +91,7 @@
INSERT INTO SystemSettings VALUES(DEFAULT, 'MailingListQueuePerStep', '10', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_MailingListQueuePerStep', 'text', NULL, NULL, 50.08, 0, 0, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'MailingListSendPerStep', '10', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_MailingListSendPerStep', 'text', NULL, NULL, 50.09, 0, 0, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'DefaultEmailRecipients', '', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_DefaultEmailRecipients', 'text', NULL, NULL, 50.10, 0, 0, NULL);
+INSERT INTO SystemSettings VALUES(DEFAULT, 'EmailDelivery', '1', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_EmailDelivery', 'radio', NULL, '1=la_opt_EmailDeliveryQueue||2=la_opt_EmailDeliveryImmediate', 50.11, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'UseOutputCompression', '1', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_UseOutputCompression', 'checkbox', '', '', 60.01, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'OutputCompressionLevel', '7', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_OutputCompressionLevel', 'text', '', '', 60.02, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'TrimRequiredFields', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_TrimRequiredFields', 'checkbox', '', '', 60.03, 0, 0, NULL);
Index: install/upgrades.sql
===================================================================
--- install/upgrades.sql (revision 15907)
+++ install/upgrades.sql (working copy)
@@ -2940,3 +2940,5 @@
INSERT INTO SystemSettings VALUES(DEFAULT, 'PlainTextCookies', '', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsSystem', 'la_config_PlainTextCookies', 'text', '', '', 60.10, 0, 1, NULL);
INSERT INTO SystemSettings VALUES(DEFAULT, 'ForceCanonicalUrls', '0', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsWebsite', 'la_config_ForceCanonicalUrls', 'checkbox', '', '', 10.0125, 0, 0, NULL);
+
+INSERT INTO SystemSettings VALUES(DEFAULT, 'EmailDelivery', '2', 'In-Portal', 'in-portal:configure_advanced', 'la_section_SettingsMailling', 'la_config_EmailDelivery', 'radio', NULL, '1=la_opt_EmailDeliveryQueue||2=la_opt_EmailDeliveryImmediate', 50.11, 0, 1, NULL);
Index: kernel/constants.php
===================================================================
--- kernel/constants.php (revision 15907)
+++ kernel/constants.php (working copy)
@@ -199,13 +199,18 @@
const PS_USER = 'USER';
}
-class CategoryPermissionRebuild {
- const MANUAL = 1;
- const SILENT = 2;
- const AUTOMATIC = 3;
-}
+ class CategoryPermissionRebuild {
+ const MANUAL = 1;
+ const SILENT = 2;
+ const AUTOMATIC = 3;
+ }
-class TranslationSaveMode {
- const SYNC_WITH_PRIMARY = 1;
- const MAKE_PRIMARY = 2;
-}
\ No newline at end of file
+ class EmailDelivery {
+ const QUEUE = 1;
+ const IMMEDIATE = 2;
+ }
+
+ class TranslationSaveMode {
+ const SYNC_WITH_PRIMARY = 1;
+ const MAKE_PRIMARY = 2;
+ }
\ No newline at end of file
Index: kernel/utility/email.php
===================================================================
--- kernel/utility/email.php (revision 15907)
+++ kernel/utility/email.php (working copy)
@@ -204,7 +204,7 @@
protected function _getCustomParams()
{
$ret = $this->params;
- $send_keys = Array ('from_email', 'from_name', 'to_email', 'to_name', 'overwrite_to_email', 'language_id', 'use_custom_design');
+ $send_keys = Array ('from_email', 'from_name', 'to_email', 'to_name', 'overwrite_to_email', 'language_id', 'use_custom_design', 'delivery');
foreach ($send_keys as $send_key) {
unset($ret[$send_key]);
@@ -217,11 +217,10 @@
* Sends e-mail now or puts it in queue
*
* @param int $recipient_user_id
- * @param bool $immediate_send
* @return bool
* @access public
*/
- public function send($recipient_user_id = null, $immediate_send = true)
+ public function send($recipient_user_id = null)
{
$this->recipientUserId = $recipient_user_id;
@@ -283,7 +282,9 @@
$this->sender->setLogData($log_fields_hash);
}
- return $this->sender->Deliver(null, $immediate_send);
+ $delivery = isset($this->params['delivery']) ? $this->params['delivery'] : $this->Application->ConfigValue('EmailDelivery');
+
+ return $this->sender->Deliver(null, $delivery == EmailDelivery::IMMEDIATE);
}
/**
Index: units/email_queue/email_queue_config.php
===================================================================
--- units/email_queue/email_queue_config.php (revision 15907)
+++ units/email_queue/email_queue_config.php (working copy)
@@ -18,7 +18,7 @@
'Prefix' => 'email-queue',
'ItemClass' => Array ('class' => 'kDBItem', 'file' => '', 'build_event' => 'OnItemBuild'),
'ListClass' => Array ('class' => 'kDBList', 'file' => '', 'build_event' => 'OnListBuild'),
- 'EventHandlerClass' => Array ('class' => 'kDBEventHandler', 'file' => '', 'build_event' => 'OnBuild'),
+ 'EventHandlerClass' => Array ('class' => 'EmailQueueEventHandler', 'file' => 'email_queue_eh.php', 'build_event' => 'OnBuild'),
'TagProcessorClass' => Array ('class' => 'EmailQueueTagProcessor', 'file' => 'email_queue_tp.php', 'build_event' => 'OnBuild'),
'AutoLoad' => true,
@@ -31,12 +31,18 @@
5 => 'mode',
),
+ 'ScheduledTasks' => Array (
+ 'process_email_queue' => Array ('EventName' => 'OnProcess', 'RunSchedule' => '* * * * *'),
+ ),
+
'IDField' => 'EmailQueueId',
'TableName' => TABLE_PREFIX . 'EmailQueue',
'TitlePresets' => Array (
'email_queue_list' => Array ('prefixes' => Array ('email-queue_List'), 'format' => '!la_tab_EmailQueue!',),
+ 'email_send' => Array ('prefixes' => Array (), 'format' => '!la_title_SendingPreparedEmails!. !la_title_PleaseWait!'),
+ 'email_send_complete' => Array ('prefixes' => Array (), 'format' => '!la_title_SendMailComplete!'),
),
'PermSection' => Array ('main' => 'in-portal:email_queue'),
Index: units/email_queue/email_queue_eh.php
===================================================================
--- units/email_queue/email_queue_eh.php (revision 0)
+++ units/email_queue/email_queue_eh.php (revision 0)
@@ -0,0 +1,97 @@
+ Array ('self' => 'view'),
+ 'OnProcess' => Array ('self' => true),
+ );
+
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
+
+ /**
+ * Process emails from queue
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnProcessAjax(kEvent $event)
+ {
+ $mailing_list_helper = $this->Application->recallObject('MailingListHelper');
+ /* @var $mailing_list_helper MailingListHelper */
+
+ $emails_sent = 0;
+ $email_queue_progress = $this->Application->RecallVar('email_queue_progress');
+
+ if ( $email_queue_progress === false ) {
+ $total_emails = $mailing_list_helper->getMessages(true);
+
+ $this->Application->StoreVar('email_queue_progress', $emails_sent . ':' . $total_emails);
+ }
+ else {
+ list ($emails_sent, $total_emails) = explode(':', $email_queue_progress);
+ }
+
+ $message_count = $mailing_list_helper->processQueue();
+
+ if ( !$message_count ) {
+ // no messages left to send in queue
+ $this->Application->RemoveVar('email_queue_progress');
+ $this->Application->Redirect($this->Application->GetVar('finish_template'));
+
+ return;
+ }
+
+ $emails_sent += $message_count;
+
+ if ( $emails_sent >= $total_emails ) {
+ $this->Application->RemoveVar('email_queue_progress');
+ $this->Application->Redirect($this->Application->GetVar('finish_template'));
+ }
+
+ $this->Application->StoreVar('email_queue_progress', $emails_sent . ':' . $total_emails);
+ $event->status = kEvent::erSTOP;
+
+ echo ($emails_sent / $total_emails) * 100;
+ }
+
+ /**
+ * [SCHEDULED TASK] Process email queue from cron
+ *
+ * @param kEvent $event
+ */
+ function OnProcess($event)
+ {
+ $mailing_list_helper = $this->Application->recallObject('MailingListHelper');
+ /* @var $mailing_list_helper MailingListHelper */
+
+ $mailing_list_helper->processQueue();
+ }
+}
Property changes on: units\email_queue\email_queue_eh.php
___________________________________________________________________
Added: svn:keywords
+ Id
Added: svn:eol-style
+ LF
Index: units/email_templates/email_template_eh.php
===================================================================
--- units/email_templates/email_template_eh.php (revision 15907)
+++ units/email_templates/email_template_eh.php (working copy)
@@ -30,7 +30,6 @@
$permissions = Array (
'OnFrontOnly' => Array ('self' => 'edit'),
'OnSaveSelected' => Array ('self' => 'view'),
- 'OnProcessEmailQueue' => Array ('self' => 'add|edit'),
'OnExportEmailTemplates' => Array ('self' => 'view'),
'OnSuggestAddress' => Array ('self' => 'add|edit'),
@@ -218,72 +217,6 @@
}
/**
- * Process emails from queue
- *
- * @param kEvent $event
- * @todo Move to MailingList
- */
- function OnProcessEmailQueue($event)
- {
- $deliver_count = $event->getEventParam('deliver_count');
- if ( $deliver_count === false ) {
- $deliver_count = $this->Application->ConfigValue('MailingListSendPerStep');
- if ( $deliver_count === false ) {
- $deliver_count = 10; // 10 emails per script run (if not specified directly)
- }
- }
-
- $processing_type = $this->Application->GetVar('type');
- if ( $processing_type = 'return_progress' ) {
- $email_queue_progress = $this->Application->RecallVar('email_queue_progress');
- if ( $email_queue_progress === false ) {
- $emails_sent = 0;
- $sql = 'SELECT COUNT(*)
- FROM ' . TABLE_PREFIX . 'EmailQueue
- WHERE (SendRetries < 5) AND (LastSendRetry < ' . strtotime('-2 hours') . ')';
- $total_emails = $this->Conn->GetOne($sql);
- $this->Application->StoreVar('email_queue_progress', $emails_sent . ':' . $total_emails);
- }
- else {
- list ($emails_sent, $total_emails) = explode(':', $email_queue_progress);
- }
- }
-
- $sql = 'SELECT *
- FROM ' . TABLE_PREFIX . 'EmailQueue
- WHERE (SendRetries < 5) AND (LastSendRetry < ' . strtotime('-2 hours') . ')
- LIMIT 0,' . $deliver_count;
- $messages = $this->Conn->Query($sql);
-
- $message_count = count($messages);
- if ( !$message_count ) {
- // no messages left to send in queue
- if ( $processing_type = 'return_progress' ) {
- $this->Application->RemoveVar('email_queue_progress');
- $this->Application->Redirect($this->Application->GetVar('finish_template'));
- }
- return;
- }
-
- $mailing_list_helper = $this->Application->recallObject('MailingListHelper');
- /* @var $mailing_list_helper MailingListHelper */
-
- $mailing_list_helper->processQueue($messages);
-
- if ( $processing_type = 'return_progress' ) {
- $emails_sent += $message_count;
- if ( $emails_sent >= $total_emails ) {
- $this->Application->RemoveVar('email_queue_progress');
- $this->Application->Redirect($this->Application->GetVar('finish_template'));
- }
-
- $this->Application->StoreVar('email_queue_progress', $emails_sent . ':' . $total_emails);
- $event->status = kEvent::erSTOP;
- echo ($emails_sent / $total_emails) * 100;
- }
- }
-
- /**
* Prefills module dropdown
*
* @param kEvent $event
Index: units/email_templates/email_templates_config.php
===================================================================
--- units/email_templates/email_templates_config.php (revision 15907)
+++ units/email_templates/email_templates_config.php (working copy)
@@ -62,8 +62,6 @@
// for mass mailing
'email_send_form' => Array ('prefixes' => Array (), 'format' => '!la_title_SendEmail!'),
- 'email_send' => Array ('prefixes' => Array (), 'format' => '!la_title_SendingPreparedEmails!. !la_title_PleaseWait!'),
- 'email_send_complete' => Array ('prefixes' => Array (), 'format' => '!la_title_SendMailComplete!'),
),
'EditTabPresets' => Array (
Index: units/helpers/mailing_list_helper.php
===================================================================
--- units/helpers/mailing_list_helper.php (revision 15907)
+++ units/helpers/mailing_list_helper.php (working copy)
@@ -242,7 +242,7 @@
*/
function _updateSentTotals($mailing_totals)
{
- if (array_key_exists(0, $mailing_totals)) {
+ if ( array_key_exists(0, $mailing_totals) ) {
// don't update sent email count for mails queued directly (not via mailing lists)
unset($mailing_totals[0]);
}
@@ -268,37 +268,45 @@
/**
* Sent given messages from email queue
*
- * @param Array $messages
+ * @return int
+ * @access public
*/
- function processQueue(&$messages)
+ function processQueue()
{
$esender = $this->Application->recallObject('EmailSender');
/* @var $esender kEmailSendingHelper */
- $queue_table = $this->Application->getUnitConfig('email-queue')->getTableName();
+ $messages = $this->getMessages();
+ $message_count = count($messages);
+ if ( !$message_count ) {
+ return 0;
+ }
+
$i = 0;
$message = Array ();
$mailing_totals = Array ();
- $message_count = count($messages);
+ $queue_table = $this->Application->getUnitConfig('email-queue')->getTableName();
while ($i < $message_count) {
$message[0] = unserialize($messages[$i]['MessageHeaders']);
$message[1] =& $messages[$i]['MessageBody'];
- $esender->setLogData( unserialize($messages[$i]['LogData']) );
+ $esender->setLogData(unserialize($messages[$i]['LogData']));
$delivered = $esender->Deliver($message, true); // immediate send!
- if ($delivered) {
+ if ( $delivered ) {
// send succeeded, delete from queue
$sql = 'DELETE FROM ' . $queue_table . '
WHERE EmailQueueId = ' . $messages[$i]['EmailQueueId'];
$this->Conn->Query($sql);
$mailing_id = $messages[$i]['MailingId'];
- if (!array_key_exists($mailing_id, $mailing_totals)) {
+
+ if ( !array_key_exists($mailing_id, $mailing_totals) ) {
$mailing_totals[$mailing_id] = 0;
}
+
$mailing_totals[$mailing_id]++;
}
else {
@@ -312,5 +320,66 @@
}
$this->_updateSentTotals($mailing_totals);
+
+ return $message_count;
}
+
+ /**
+ * Returns queued messages (or their count), that can be sent
+ *
+ * @param bool $count_only
+ * @return Array|int
+ * @access public
+ */
+ public function getMessages($count_only = false)
+ {
+ $deliver_count = $this->getSetting('MailingListSendPerStep');
+
+ if ( !is_numeric($deliver_count) ) {
+ return $count_only ? 0 : Array ();
+ }
+
+ $queue_table = $this->Application->getUnitConfig('email-queue')->getTableName();
+
+ if ( $count_only ) {
+ $sql = 'SELECT COUNT(*)
+ FROM ' . $queue_table . '
+ WHERE (SendRetries < 5) AND (LastSendRetry < ' . strtotime('-2 hours') . ')';
+
+ return $this->Conn->GetOne($sql);
+ }
+
+ // regular e-mails are pressed before mailing generated ones !
+ $sql = 'SELECT *
+ FROM ' . $queue_table . '
+ WHERE (SendRetries < 5) AND (LastSendRetry < ' . strtotime('-2 hours') . ')
+ ORDER BY MailingId ASC
+ LIMIT 0,' . $deliver_count;
+
+ return $this->Conn->Query($sql);
+ }
+
+ /**
+ * Allows to safely get mailing configuration variable
+ *
+ * @param string $variable_name
+ * @return int
+ * @access public
+ */
+ public function getSetting($variable_name)
+ {
+ $value = $this->Application->ConfigValue($variable_name);
+
+ if ( $value === false ) {
+ // ensure default value, when configuration variable is missing
+ return 10;
+ }
+
+ if ( !$value ) {
+ // configuration variable found, but it's value is empty or zero
+ return false;
+ }
+
+ return $value;
+ }
}
\ No newline at end of file
Index: units/mailing_lists/mailing_list_eh.php
===================================================================
--- units/mailing_lists/mailing_list_eh.php (revision 15907)
+++ units/mailing_lists/mailing_list_eh.php (working copy)
@@ -30,7 +30,6 @@
$permissions = Array (
'OnCancelMailing' => Array ('self' => 'edit'),
'OnGenerateEmailQueue' => Array ('self' => true),
- 'OnProcessEmailQueue' => Array ('self' => true),
'OnGetHtmlBody' => Array ('self' => 'edit'),
);
@@ -255,28 +254,6 @@
}
/**
- * Allows to safely get mailing configuration variables
- *
- * @param string $variable_name
- * @return int
- */
- function _ensureDefault($variable_name)
- {
- $value = $this->Application->ConfigValue($variable_name);
- if ( $value === false ) {
- // ensure default value, when configuration variable is missing
- return 10;
- }
-
- if ( !$value ) {
- // configuration variable found, but it's value is empty or zero
- return false;
- }
-
- return $value;
- }
-
- /**
* Generates email queue for active mailing lists
*
* @param kEvent $event
@@ -303,16 +280,15 @@
return;
}
- // queue 10 emails per step summary from all mailing lists (FIFO logic)
- $to_queue = $this->_ensureDefault('MailingListQueuePerStep');
+ $mailing_list_helper = $this->Application->recallObject('MailingListHelper');
+ /* @var $mailing_list_helper MailingListHelper */
- if ( $to_queue === false ) {
+ $to_queue = $mailing_list_helper->getSetting('MailingListQueuePerStep');
+
+ if ( !is_numeric($to_queue) ) {
return;
}
- $mailing_list_helper = $this->Application->recallObject('MailingListHelper');
- /* @var $mailing_list_helper MailingListHelper */
-
foreach ($mailing_lists as $mailing_id => $mailing_data) {
if ( $mailing_data['EmailsTotal'] == 0 ) {
// no work performed on this mailing list -> calculate totals
@@ -357,38 +333,6 @@
}
/**
- * Process email queue from cron
- *
- * @param kEvent $event
- */
- function OnProcessEmailQueue($event)
- {
- $deliver_count = $this->_ensureDefault('MailingListSendPerStep');
- if ($deliver_count === false) {
- return ;
- }
-
- $queue_table = $this->Application->getUnitConfig('email-queue')->getTableName();
-
- // get queue part to send
- $sql = 'SELECT *
- FROM ' . $queue_table . '
- WHERE (SendRetries < 5) AND (LastSendRetry < ' . strtotime('-2 hours') . ')
- LIMIT 0,' . $deliver_count;
- $messages = $this->Conn->Query($sql);
-
- if (!$messages) {
- // no more messages left in queue
- return ;
- }
-
- $mailing_list_helper = $this->Application->recallObject('MailingListHelper');
- /* @var $mailing_list_helper MailingListHelper */
-
- $mailing_list_helper->processQueue($messages);
- }
-
- /**
* Returns HTML of sent e-mail for iframe
*
* @param kEvent $event
Index: units/mailing_lists/mailing_lists_config.php
===================================================================
--- units/mailing_lists/mailing_lists_config.php (revision 15907)
+++ units/mailing_lists/mailing_lists_config.php (working copy)
@@ -33,7 +33,6 @@
'ScheduledTasks' => Array (
'generate_mailing_queue' => Array ('EventName' => 'OnGenerateEmailQueue', 'RunSchedule' => '*/30 * * * *'),
- 'process_mailing_queue' => Array ('EventName' => 'OnProcessEmailQueue', 'RunSchedule' => '*/30 * * * *'),
),
'IDField' => 'MailingId',