1
0
Эх сурвалжийг харах

Ticket #5497 - Notifications: add setting for getEventsToProcess function.

AntonLV 4 сар өмнө
parent
commit
fdce24b716

+ 2 - 1
modules/boonex/notifications/classes/BxNtfsConfig.php

@@ -50,7 +50,8 @@ class BxNtfsConfig extends BxBaseModNotificationsConfig
             'URL_HOME' => 'page.php?i=notifications-view',
 
             // some params
-            'PARAM_QUEUE_ADD_THRESHOLD' => 0,
+            'PARAM_QUEUE_ADD_THRESHOLD' => 'bx_notifications_queue_add_threshold',
+            'PARAM_QUEUE_ADD_LIMIT' => 'bx_notifications_queue_add_limit',
             'PARAM_COMMENT_POST_EXT' => 'bx_notifications_enable_comment_post_ext',
             'PARAM_REPLY_AS_COMMENT' => 'bx_notifications_enable_reply_as_comment',
             'PARAM_PROCESSED_EVENT' => 'bx_notifications_processed_event',

+ 15 - 8
modules/boonex/notifications/classes/BxNtfsCronNotify.php

@@ -9,12 +9,17 @@
  * @{
  */
 
+/**
+ * Get notifications list and retrieve recipients for each notification. Put emails in:
+ * a) internal queue, if Delivery Timeout is set,
+ * b) system queue otherwise
+ */
 class BxNtfsCronNotify extends BxDolCron
 {
     protected $_sModule;
     protected $_oModule;
 
-    protected $_iAddThreshold;
+    protected $_bDeliveryTimeout;
 
     public function __construct()
     {
@@ -22,17 +27,21 @@ class BxNtfsCronNotify extends BxDolCron
     	$this->_oModule = BxDolModule::getInstance($this->_sModule);
 
         parent::__construct();
+
+        $this->_bDeliveryTimeout = $this->_oModule->_oConfig->getDeliveryTimeout() > 0;
     }
 
     public function processing()
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
 
-        $iCount = (int)$this->_oModule->_oDb->queueGet(array('type' => 'count'));
-        if($iCount > $CNF['PARAM_QUEUE_ADD_THRESHOLD'])
-            return;
+        if($this->_bDeliveryTimeout) {
+            $iCount = (int)$this->_oModule->_oDb->queueGet(['type' => 'count']);
+            if($iCount > (int)getParam($CNF['PARAM_QUEUE_ADD_THRESHOLD']))
+                return;
+        }
 
-        $aEvents = $this->_oModule->_oDb->getEventsToProcess();
+        $aEvents = $this->_oModule->_oDb->getEventsToProcess((int)getParam($CNF['PARAM_QUEUE_ADD_LIMIT']));
 
         foreach($aEvents as $aEvent) {
             if(!empty($aEvent['content']) && is_string($aEvent['content']))
@@ -112,8 +121,6 @@ class BxNtfsCronNotify extends BxDolCron
         if($iOwner != $iObjectOwner)
             $this->_addRecipient($iObjectOwner, BX_NTFS_STYPE_PERSONAL, $aRecipients);
 
-        $bDeliveryTimeout = $this->_oModule->_oConfig->getDeliveryTimeout() > 0;
-
         //--- Check recipients and send notifications.
         list($aModulesProfiles) = $this->_oModule->_oConfig->getProfileBasedModules();
         $aRecipientsId = $this->_oModule->_oDb->filterProfileIdsByModule(array_keys($aRecipients), $aModulesProfiles);
@@ -149,7 +156,7 @@ class BxNtfsCronNotify extends BxDolCron
                      * 'break' is essential in the next two conditions to avoid 
                      * duplicate sending to the same recipient.
                      */
-                    if($bDeliveryTimeout && $this->_oModule->_oDb->queueAdd(array(
+                    if($this->_bDeliveryTimeout && $this->_oModule->_oDb->queueAdd(array(
                         'profile_id' => $iRecipient, 
                         'event_id' => $aEvent['id'], 
                         'delivery' => $sDeliveryType,

+ 4 - 0
modules/boonex/notifications/classes/BxNtfsCronQueue.php

@@ -9,6 +9,10 @@
  * @{
  */
 
+/**
+ * Send notifications from internal queue by moving them to system one.
+ * Is working if Delivery Timeout is set.
+ */
 class BxNtfsCronQueue extends BxDolCron
 {
     protected $_sModule;

+ 5 - 0
modules/boonex/notifications/install/langs/en.xml

@@ -67,6 +67,11 @@
     <string name="_bx_ntfs_option_enable_group_events"><![CDATA[Group notifications by event]]></string>
     <string name="_bx_ntfs_option_enable_clicked_indicator"><![CDATA[Enable 'clicked' indicator]]></string>
     <string name="_bx_ntfs_option_delivery_timeout"><![CDATA[Delay before sending Email and/or Push notifications (in seconds)]]></string>
+    <string name="_bx_ntfs_option_delivery_timeout_inf"><![CDATA[Positive value other than '0' means that notifications will be send via Internal queue.]]></string>
+    <string name="_bx_ntfs_option_queue_add_threshold"><![CDATA[Threshold to add to Internal queue]]></string>
+    <string name="_bx_ntfs_option_queue_add_threshold_inf"><![CDATA['0' means that adding in the queue will be performed only when the queue is empty.]]></string>
+    <string name="_bx_ntfs_option_queue_add_limit"><![CDATA[Number of notifications to process and add to queue (Internal or System) per execution]]></string>
+    <string name="_bx_ntfs_option_queue_add_limit_inf"><![CDATA['0' means that all available notifications will be processed at once.]]></string>
     <string name="_bx_ntfs_option_processed_event"><![CDATA[The last processed event upon notifications sending]]></string>
     <string name="_bx_ntfs_option_clear_interval"><![CDATA[Notification lifetime, in days (0 - no limit)]]></string>
     <string name="_bx_ntfs_option_enable_comment_post_ext"><![CDATA[Notify a user about new comments for a content he's previously commented]]></string>

+ 17 - 15
modules/boonex/notifications/install/sql/enable.sql

@@ -93,21 +93,23 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 INSERT INTO `sys_options_categories` (`type_id`, `name`, `caption`, `hidden`, `order`) VALUES (@iTypeId, @sName, '_bx_ntfs', 0, 1);
 SET @iCategId = LAST_INSERT_ID();
 
-INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `check`, `check_params`, `check_error`, `extra`, `order`) VALUES
-('bx_notifications_events_per_page', '24', @iCategId, '_bx_ntfs_option_events_per_page', 'digit', '', '', '', '', 1),
-('bx_notifications_events_per_preview', '5', @iCategId, '_bx_ntfs_option_events_per_preview', 'digit', '', '', '', '', 5),
-('bx_notifications_enable_group_settings', 'on', @iCategId, '_bx_ntfs_option_enable_group_settings', 'checkbox', '', '', '', '', 10), 
-('bx_notifications_enable_group_events', 'on', @iCategId, '_bx_ntfs_option_enable_group_events', 'checkbox', '', '', '', '', 11), 
-('bx_notifications_enable_clicked_indicator', '', @iCategId, '_bx_ntfs_option_enable_clicked_indicator', 'checkbox', '', '', '', '', 15),
-('bx_notifications_delivery_timeout', '120', @iCategId, '_bx_ntfs_option_delivery_timeout', 'digit', '', '', '', '', 20),
-('bx_notifications_clear_interval', '90', @iCategId, '_bx_ntfs_option_clear_interval', 'digit', '', '', '', '', 30),
-('bx_notifications_enable_comment_post_ext', '', @iCategId, '_bx_ntfs_option_enable_comment_post_ext', 'checkbox', '', '', '', '', 40),
-('bx_notifications_enable_reply_as_comment', 'on', @iCategId, '_bx_ntfs_option_enable_reply_as_comment', 'checkbox', '', '', '', '', 42),
-('bx_notifications_summary_chars', '200', @iCategId, '_bx_ntfs_option_summary_chars', 'digit', '', '', '', '', 50),
-('bx_notifications_owner_name_chars', '21', @iCategId, '_bx_ntfs_option_owner_name_chars', 'digit', '', '', '', '', 51),
-('bx_notifications_content_chars', '32', @iCategId, '_bx_ntfs_option_content_chars', 'digit', '', '', '', '', 52),
-('bx_notifications_email_subject_chars', '30', @iCategId, '_bx_ntfs_option_email_subject_chars', 'digit', '', '', '', '', 53),
-('bx_notifications_push_message_chars', '190', @iCategId, '_bx_ntfs_option_push_message_chars', 'digit', '', '', '', '', 54);
+INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `info`, `type`, `check`, `check_params`, `check_error`, `extra`, `order`) VALUES
+('bx_notifications_events_per_page', '24', @iCategId, '_bx_ntfs_option_events_per_page', '', 'digit', '', '', '', '', 1),
+('bx_notifications_events_per_preview', '5', @iCategId, '_bx_ntfs_option_events_per_preview', '', 'digit', '', '', '', '', 5),
+('bx_notifications_enable_group_settings', 'on', @iCategId, '_bx_ntfs_option_enable_group_settings', '', 'checkbox', '', '', '', '', 10), 
+('bx_notifications_enable_group_events', 'on', @iCategId, '_bx_ntfs_option_enable_group_events', '', 'checkbox', '', '', '', '', 11), 
+('bx_notifications_enable_clicked_indicator', '', @iCategId, '_bx_ntfs_option_enable_clicked_indicator', '', 'checkbox', '', '', '', '', 15),
+('bx_notifications_delivery_timeout', '120', @iCategId, '_bx_ntfs_option_delivery_timeout', '_bx_ntfs_option_delivery_timeout_inf', 'digit', '', '', '', '', 20),
+('bx_notifications_queue_add_threshold', '0', @iCategId, '_bx_ntfs_option_queue_add_threshold', '_bx_ntfs_option_queue_add_threshold_inf', 'digit', '', '', '', '', 21),
+('bx_notifications_queue_add_limit', '200', @iCategId, '_bx_ntfs_option_queue_add_limit', '_bx_ntfs_option_queue_add_limit_inf', 'digit', '', '', '', '', 22),
+('bx_notifications_clear_interval', '90', @iCategId, '_bx_ntfs_option_clear_interval', '', 'digit', '', '', '', '', 30),
+('bx_notifications_enable_comment_post_ext', '', @iCategId, '_bx_ntfs_option_enable_comment_post_ext', '', 'checkbox', '', '', '', '', 40),
+('bx_notifications_enable_reply_as_comment', 'on', @iCategId, '_bx_ntfs_option_enable_reply_as_comment', '', 'checkbox', '', '', '', '', 42),
+('bx_notifications_summary_chars', '200', @iCategId, '_bx_ntfs_option_summary_chars', '', 'digit', '', '', '', '', 50),
+('bx_notifications_owner_name_chars', '21', @iCategId, '_bx_ntfs_option_owner_name_chars', '', 'digit', '', '', '', '', 51),
+('bx_notifications_content_chars', '32', @iCategId, '_bx_ntfs_option_content_chars', '', 'digit', '', '', '', '', 52),
+('bx_notifications_email_subject_chars', '30', @iCategId, '_bx_ntfs_option_email_subject_chars', '', 'digit', '', '', '', '', 53),
+('bx_notifications_push_message_chars', '190', @iCategId, '_bx_ntfs_option_push_message_chars', '', 'digit', '', '', '', '', 54);
 
 
 -- PRIVACY 

+ 5 - 0
modules/boonex/russian/data/langs/bx_notifications/ru.xml

@@ -67,6 +67,11 @@
     <string name="_bx_ntfs_option_enable_group_events"><![CDATA[Сгруппировать оповещения по принадлежности к событию]]></string>
     <string name="_bx_ntfs_option_enable_clicked_indicator"><![CDATA[Включить индикатор перехода по ссылке уведомления]]></string>
     <string name="_bx_ntfs_option_delivery_timeout"><![CDATA[Задержка перед отправкой Email и/или Push уведомлений (в секундах)]]></string>
+    <string name="_bx_ntfs_option_delivery_timeout_inf"><![CDATA[Положительное значение, отличное от '0', означает, что уведомления будут отправляться через Внутреннюю очередь.]]></string>
+    <string name="_bx_ntfs_option_queue_add_threshold"><![CDATA[Пороговое значение для добавления во Внутреннюю очередь]]></string>
+    <string name="_bx_ntfs_option_queue_add_threshold_inf"><![CDATA['0' означает, что добавление в очередь будет выполняться только тогда, когда очередь пуста.]]></string>
+    <string name="_bx_ntfs_option_queue_add_limit"><![CDATA[Количество уведомлений для обработки и добавления в очередь (Внутреннюю или Системную) за одно выполнение]]></string>
+    <string name="_bx_ntfs_option_queue_add_limit_inf"><![CDATA['0' означает, что все доступные уведомления будут обработаны одновременно.]]></string>
     <string name="_bx_ntfs_option_clear_interval"><![CDATA[Срок жизни уведомления, в днях (0 - без ограничений)]]></string>
     <string name="_bx_ntfs_option_processed_event"><![CDATA[Последнее событие, обработанное в процессе отправки оповещений]]></string>
     <string name="_bx_ntfs_option_enable_comment_post_ext"><![CDATA[Оповещать пользователя о новых комментариях к контенту, котороый он комментировал ранее]]></string>