Index: branches/5.3.x/core/admin_templates/mailing_lists/send_queue.tpl =================================================================== diff -u -N -r15677 -r15916 --- branches/5.3.x/core/admin_templates/mailing_lists/send_queue.tpl (.../send_queue.tpl) (revision 15677) +++ branches/5.3.x/core/admin_templates/mailing_lists/send_queue.tpl (.../send_queue.tpl) (revision 15916) @@ -1,15 +1,15 @@ - + \ No newline at end of file Index: branches/5.3.x/core/install/english.lang =================================================================== diff -u -N -r15913 -r15916 --- branches/5.3.x/core/install/english.lang (.../english.lang) (revision 15913) +++ branches/5.3.x/core/install/english.lang (.../english.lang) (revision 15916) @@ -165,6 +165,7 @@ RGVmYXVsdCAiUGVyIFBhZ2UiIHNldHRpbmcgaW4gR3JpZHM= RGVmYXVsdCBSZWdpc3RyYXRpb24gQ291bnRyeQ== RGVmYXVsdCBBbmFseXRpY3MgVHJhY2tpbmcgQ29kZQ== + RW1haWwgRGVsaXZlcnk= S2VlcCAiRS1tYWlsIExvZyIgZm9y RW5hYmxlICJFLW1haWwgTG9nIg== RW5hYmxlIFJldmlzaW9uIENvbnRyb2wgZm9yIFNlY3Rpb24gQ29udGVudA== @@ -899,6 +900,8 @@ RWRpdG9yJ3MgUGljaw== RS1tYWls RS1tYWlsIEJvZHk= + SW1tZWRpYXRl + RW1haWwgUXVldWU= Rm9yZXZlciAobmV2ZXIgZGVsZXRlZCBhdXRvbWF0aWNhbGx5KQ== RS1tYWlsIFN1YmplY3Q= RS1tYWlsIFRlbXBsYXRlcw== Index: branches/5.3.x/core/kernel/utility/email.php =================================================================== diff -u -N -r15677 -r15916 --- branches/5.3.x/core/kernel/utility/email.php (.../email.php) (revision 15677) +++ branches/5.3.x/core/kernel/utility/email.php (.../email.php) (revision 15916) @@ -1,6 +1,6 @@ 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: branches/5.3.x/core/install/install_data.sql =================================================================== diff -u -N -r15902 -r15916 --- branches/5.3.x/core/install/install_data.sql (.../install_data.sql) (revision 15902) +++ branches/5.3.x/core/install/install_data.sql (.../install_data.sql) (revision 15916) @@ -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: branches/5.3.x/core/units/email_templates/email_template_eh.php =================================================================== diff -u -N -r15902 -r15916 --- branches/5.3.x/core/units/email_templates/email_template_eh.php (.../email_template_eh.php) (revision 15902) +++ branches/5.3.x/core/units/email_templates/email_template_eh.php (.../email_template_eh.php) (revision 15916) @@ -1,6 +1,6 @@ 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: branches/5.3.x/core/kernel/constants.php =================================================================== diff -u -N -r15677 -r15916 --- branches/5.3.x/core/kernel/constants.php (.../constants.php) (revision 15677) +++ branches/5.3.x/core/kernel/constants.php (.../constants.php) (revision 15916) @@ -1,6 +1,6 @@ Array ( 'generate_mailing_queue' => Array ('EventName' => 'OnGenerateEmailQueue', 'RunSchedule' => '*/30 * * * *'), - 'process_mailing_queue' => Array ('EventName' => 'OnProcessEmailQueue', 'RunSchedule' => '*/30 * * * *'), ), 'IDField' => 'MailingId', Index: branches/5.3.x/core/units/helpers/mailing_list_helper.php =================================================================== diff -u -N -r15698 -r15916 --- branches/5.3.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 15698) +++ branches/5.3.x/core/units/helpers/mailing_list_helper.php (.../mailing_list_helper.php) (revision 15916) @@ -1,6 +1,6 @@ getTableName(); // update sent email count for each processed mailing - foreach ($mailing_totals as $mailing_id => $mailing_total) { + foreach ( $mailing_totals as $mailing_id => $mailing_total ) { $sql = 'UPDATE ' . $table_name . ' SET EmailsSent = EmailsSent + ' . $mailing_total . ' WHERE ' . $config->getIDField() . ' = ' . $mailing_id; @@ -266,37 +268,42 @@ } /** - * Sent given messages from email queue + * Sent given messages from email queue. * - * @param Array $messages + * @return integer */ - 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); + $message = Array(); + $mailing_totals = Array(); + $queue_table = $this->Application->getUnitConfig('email-queue')->getTableName(); - while ($i < $message_count) { + 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]++; @@ -312,5 +319,68 @@ } $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: branches/5.3.x/core/install/upgrades.sql =================================================================== diff -u -N -r15913 -r15916 --- branches/5.3.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15913) +++ branches/5.3.x/core/install/upgrades.sql (.../upgrades.sql) (revision 15916) @@ -2944,3 +2944,5 @@ UPDATE LanguageLabels SET l1_HintTranslation = '
    \r\n
  • This deploy script will apply all Database Changes stored in [module]/project_upgrades.sql to the current website and save applied Revisions in AppliedDBRevisions.
  • \r\n
  • This deploy script will create all new language phrases by re-importing [module]/install/english.lang file.
  • \r\n
  • This deploy script will reset all caches at once.
  • \r\n
' WHERE Phrase = 'la_title_SystemToolsDeploy'; + +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: branches/5.3.x/core/units/mailing_lists/mailing_list_eh.php =================================================================== diff -u -N -r15698 -r15916 --- branches/5.3.x/core/units/mailing_lists/mailing_list_eh.php (.../mailing_list_eh.php) (revision 15698) +++ branches/5.3.x/core/units/mailing_lists/mailing_list_eh.php (.../mailing_list_eh.php) (revision 15916) @@ -1,6 +1,6 @@ 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: branches/5.3.x/core/admin_templates/mailing_lists/send_complete.tpl =================================================================== diff -u -N -r15677 -r15916 --- branches/5.3.x/core/admin_templates/mailing_lists/send_complete.tpl (.../send_complete.tpl) (revision 15677) +++ branches/5.3.x/core/admin_templates/mailing_lists/send_complete.tpl (.../send_complete.tpl) (revision 15916) @@ -1,7 +1,7 @@ - +