Просмотр исходного кода

Ticket #3691 - Alerts: Add possibility to disable handler via database.

AntonLV 4 лет назад
Родитель
Сommit
ebf5b73975
2 измененных файлов с 15 добавлено и 4 удалено
  1. 14 4
      inc/classes/BxDolAlerts.php
  2. 1 0
      install/sql/system.sql

+ 14 - 4
inc/classes/BxDolAlerts.php

@@ -102,8 +102,11 @@ class BxDolAlerts extends BxDol
         if (isset($this->_aAlerts[$this->sUnit]) && isset($this->_aAlerts[$this->sUnit][$this->sAction]))
             foreach($this->_aAlerts[$this->sUnit][$this->sAction] as $iHandlerId) {
                 $aHandler = $this->_aHandlers[$iHandlerId];
+                if(!$aHandler['active'])
+                    continue;
 
-                if (isset($GLOBALS['bx_profiler']) && 'bx_profiler' != $aHandler['name']) $GLOBALS['bx_profiler']->beginAlert($this->sUnit, $this->sAction, $aHandler['name']);
+                if (isset($GLOBALS['bx_profiler']) && 'bx_profiler' != $aHandler['name']) 
+                    $GLOBALS['bx_profiler']->beginAlert($this->sUnit, $this->sAction, $aHandler['name']);
 
                 if (!empty($aHandler['file']) && !empty($aHandler['class']) && file_exists(BX_DIRECTORY_PATH_ROOT . $aHandler['file'])) {
                     if(!class_exists($aHandler['class'], false))
@@ -121,7 +124,8 @@ class BxDolAlerts extends BxDol
                     BxDolService::call($aService['module'], $aService['method'], $aParams, isset($aService['class']) ? $aService['class'] : 'Module');
                 }
 
-                if (isset($GLOBALS['bx_profiler']) && 'bx_profiler' != $aHandler['name']) $GLOBALS['bx_profiler']->endAlert($this->sUnit, $this->sAction, $aHandler['name']);
+                if (isset($GLOBALS['bx_profiler']) && 'bx_profiler' != $aHandler['name']) 
+                    $GLOBALS['bx_profiler']->endAlert($this->sUnit, $this->sAction, $aHandler['name']);
             }
     }
 
@@ -139,9 +143,15 @@ class BxDolAlerts extends BxDol
         foreach ($aAlerts as $aAlert)
             $aResult['alerts'][$aAlert['unit']][$aAlert['action']][] = $aAlert['handler_id'];
 
-        $aHandlers = $oDb->getAll("SELECT `id`, `class`, `file`, `service_call`, `name` FROM `sys_alerts_handlers` ORDER BY `id` ASC");
+        $aHandlers = $oDb->getAll("SELECT * FROM `sys_alerts_handlers` ORDER BY `id` ASC");
         foreach ($aHandlers as $aHandler)
-            $aResult['handlers'][$aHandler['id']] = array('class' => $aHandler['class'], 'file' => $aHandler['file'], 'service_call' => $aHandler['service_call'], 'name' => $aHandler['name']);
+            $aResult['handlers'][$aHandler['id']] = [
+                'name' => $aHandler['name'],
+                'class' => $aHandler['class'], 
+                'file' => $aHandler['file'], 
+                'service_call' => $aHandler['service_call'],
+                'active' => (int)$aHandler['active']
+            ];
 
         return $aResult;
     }

+ 1 - 0
install/sql/system.sql

@@ -1824,6 +1824,7 @@ CREATE TABLE `sys_alerts_handlers` (
   `class` varchar(128) NOT NULL default '',
   `file` varchar(255) NOT NULL default '',
   `service_call` text NOT NULL default '', 
+  `active` tinyint(4) NOT NULL default '1',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`)
 );