AntonLV před 5 roky
rodič
revize
9d009d2f70

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

@@ -115,6 +115,10 @@ class BxNtfsCronNotify extends BxDolCron
         $bDeliveryTimeout = $this->_oModule->_oConfig->getDeliveryTimeout() > 0;
         $bDeliveryTimeout = $this->_oModule->_oConfig->getDeliveryTimeout() > 0;
 
 
         //--- Check recipients and send notifications.
         //--- Check recipients and send notifications.
+        list($aModulesProfiles) = $this->_oModule->_oConfig->getProfileBasedModules();
+        $aRecipientsId = $this->_oModule->_oDb->filterProfileIdsByModule(array_keys($aRecipients), $aModulesProfiles);
+        $aRecipients = array_intersect_key($aRecipients, array_flip($aRecipientsId));
+
         $oPrivacyInt = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->getObject('privacy_view'));
         $oPrivacyInt = BxDolPrivacy::getObjectInstance($this->_oModule->_oConfig->getObject('privacy_view'));
         $oPrivacyExt = $this->_oModule->_oConfig->getPrivacyObject($aEvent['type'] . '_' . $aEvent['action']);
         $oPrivacyExt = $this->_oModule->_oConfig->getPrivacyObject($aEvent['type'] . '_' . $aEvent['action']);
         foreach($aRecipients as $iRecipient => $aSettingTypes) {
         foreach($aRecipients as $iRecipient => $aSettingTypes) {
@@ -122,13 +126,6 @@ class BxNtfsCronNotify extends BxDolCron
             if($iIdRead >= $iId)
             if($iIdRead >= $iId)
                 continue;
                 continue;
 
 
-            $oProfile = BxDolProfile::getInstance($iRecipient);
-            if(!$oProfile)
-                continue;
-
-            if(!bx_srv($oProfile->getModule(), 'act_as_profile'))
-                continue;
-
             if($oPrivacyExt !== false && !$oPrivacyExt->check($aEvent['id'], $iRecipient)) 
             if($oPrivacyExt !== false && !$oPrivacyExt->check($aEvent['id'], $iRecipient)) 
                 continue;
                 continue;
 
 
@@ -161,7 +158,7 @@ class BxNtfsCronNotify extends BxDolCron
                     )) !== false)
                     )) !== false)
                         break;
                         break;
 
 
-                    if($this->_oModule->{$aDeliveryType['method_send']}($oProfile, $mixedNotification) !== false)
+                    if($this->_oModule->{$aDeliveryType['method_send']}($iRecipient, $mixedNotification) !== false)
                         break;
                         break;
                 }
                 }
         }
         }

+ 12 - 2
modules/boonex/notifications/classes/BxNtfsDb.php

@@ -235,9 +235,11 @@ class BxNtfsDb extends BxBaseModNotificationsDb
         return array($sJoinClause, $sWhereClause);
         return array($sJoinClause, $sWhereClause);
     }
     }
 
 
-    public function getEventsToProcess()
+    public function getEventsToProcess($iLimit = 0)
     {
     {
-        $aEvents = $this->getAll("SELECT * FROM `" . $this->_sTable . "` WHERE `id`>:id ORDER BY `id` ASC", array('id' => $this->_oConfig->getProcessedEvent()));
+        $aEvents = $this->getAll("SELECT * FROM `" . $this->_sTable . "` WHERE `id`>:id ORDER BY `id` ASC" . ($iLimit != 0 ? ' LIMIT ' . $iLimit : ''), array(
+            'id' => $this->_oConfig->getProcessedEvent()
+        ));
 
 
         if(!empty($aEvents) && is_array($aEvents)) {
         if(!empty($aEvents) && is_array($aEvents)) {
             $aEventEnd = end($aEvents);
             $aEventEnd = end($aEvents);
@@ -336,6 +338,14 @@ class BxNtfsDb extends BxBaseModNotificationsDb
         $this->query("DELETE FROM `{$this->_sTable}` WHERE `date` < :date", array('date' => time() - $iClearIntervalInDays * 86400));
         $this->query("DELETE FROM `{$this->_sTable}` WHERE `date` < :date", array('date' => time() - $iClearIntervalInDays * 86400));
         $this->query("DELETE FROM `{$this->_sTableEvt2Usr}` WHERE `event_id` NOT IN (SELECT `id` FROM `{$this->_sTable}`)");
         $this->query("DELETE FROM `{$this->_sTableEvt2Usr}` WHERE `event_id` NOT IN (SELECT `id` FROM `{$this->_sTable}`)");
     }   
     }   
+
+    public function filterProfileIdsByModule($aIds, $mixedModule)
+    {
+        if(!is_array($mixedModule))
+            $mixedModule = array($mixedModule);
+
+        return $this->getColumn("SELECT `id` FROM `sys_profiles` WHERE `id` IN (" . $this->implode_escape($aIds) . ") AND `type` IN (" . $this->implode_escape($mixedModule) . ")");
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 9 - 17
modules/boonex/notifications/classes/BxNtfsModule.php

@@ -442,13 +442,9 @@ class BxNtfsModule extends BxBaseModNotificationsModule
         return $mixedResult;
         return $mixedResult;
     }
     }
 
 
-    public function sendNotificationEmail($oProfile, $aNotification)
+    public function sendNotificationEmail($iProfile, $aNotification)
     {
     {
-        if(!$oProfile)
-            return false;
-
-        $oAccount = $oProfile->getAccountObject();
-        if(!$oAccount)
+        if(!$iProfile)
             return false;
             return false;
 
 
         $aSettings = &$aNotification['settings'];
         $aSettings = &$aNotification['settings'];
@@ -459,9 +455,9 @@ class BxNtfsModule extends BxBaseModNotificationsModule
             $aTemplateMarkers = array_merge($aTemplateMarkers, $aSettings['markers']);              
             $aTemplateMarkers = array_merge($aTemplateMarkers, $aSettings['markers']);              
 
 
         $aTemplate = null;
         $aTemplate = null;
-        bx_alert($this->_aModule['name'], 'before_parse_email_template', 0, 0, array('profile_id' => $oProfile->id(), 'account_id' => $oAccount->id(), 'template' => $sTemplate, 'markers' => $aTemplateMarkers, 'notification' => $aNotification, 'override_result' => &$aTemplate));
-        if (is_null($aTemplate))
-            $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($sTemplate, $aTemplateMarkers, $oAccount->id(), $oProfile->id());
+        bx_alert($this->_aModule['name'], 'before_parse_email_template', 0, 0, array('profile_id' => $iProfile, 'template' => $sTemplate, 'markers' => $aTemplateMarkers, 'notification' => $aNotification, 'override_result' => &$aTemplate));
+        if(is_null($aTemplate))
+            $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate($sTemplate, $aTemplateMarkers, 0, $iProfile);
         if(!$aTemplate)
         if(!$aTemplate)
             return false;
             return false;
 
 
@@ -469,13 +465,9 @@ class BxNtfsModule extends BxBaseModNotificationsModule
         return sendMail($oAccount->getEmail(), $sSubject, $aTemplate['Body'], 0, array(), BX_EMAIL_NOTIFY, 'html', false, array(), true);
         return sendMail($oAccount->getEmail(), $sSubject, $aTemplate['Body'], 0, array(), BX_EMAIL_NOTIFY, 'html', false, array(), true);
     }
     }
 
 
-    public function sendNotificationPush($oProfile, $aNotification)
+    public function sendNotificationPush($iProfile, $aNotification)
     {
     {
-        if(!$oProfile)
-            return false;
-
-        $oAccount = $oProfile->getAccountObject();
-        if(!$oAccount)
+        if(!$iProfile)
             return false;
             return false;
 
 
         $aContent = &$aNotification['content'];
         $aContent = &$aNotification['content'];
@@ -483,9 +475,9 @@ class BxNtfsModule extends BxBaseModNotificationsModule
 
 
         $sSubject = !empty($aSettings['subject']) ? $aSettings['subject'] : _t('_bx_ntfs_push_new_event_subject', getParam('site_title'));
         $sSubject = !empty($aSettings['subject']) ? $aSettings['subject'] : _t('_bx_ntfs_push_new_event_subject', getParam('site_title'));
         
         
-        bx_alert($this->_aModule['name'], 'before_send_notification_push', 0, 0, array('profile_id' => $oProfile->id(), 'account_id' => $oAccount->id(), 'content' => &$aContent, 'setting' => &$aSettings, 'subject' => &$sSubject));
+        bx_alert($this->_aModule['name'], 'before_send_notification_push', 0, 0, array('profile_id' => $iProfile, 'content' => &$aContent, 'setting' => &$aSettings, 'subject' => &$sSubject));
    
    
-        return BxDolPush::getInstance()->send($oProfile->id(), array(
+        return BxDolPush::getInstance()->send($iProfile, array(
             'contents' => array(
             'contents' => array(
                 'en' => $aContent['message']
                 'en' => $aContent['message']
             ),
             ),