Ver código fonte

#24 - activate/deactivate events when dependent module enabled/disabled accordingly.

AntonLV 12 anos atrás
pai
commit
6d6712f9ce

+ 6 - 6
modules/base/general/classes/BxBaseModGeneralInstaller.php

@@ -40,8 +40,8 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
 
         BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
 
-        if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'add_handlers'))
-            BxDolService::call('timeline', 'add_handlers', array($this->_aConfig['home_uri']));
+        if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('bx_timeline', 'add_handlers'))
+            BxDolService::call('bx_timeline', 'add_handlers', array($this->_aConfig['home_uri']));
 
         if ($this->_aMenuTriggers) {
             bx_import('BxDolMenu');
@@ -54,8 +54,8 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
 
     function disable($aParams)
     {
-        if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'delete_handlers'))
-            BxDolService::call('timeline', 'delete_handlers', array($this->_aConfig['home_uri']));
+        if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('bx_timeline', 'delete_handlers'))
+            BxDolService::call('bx_timeline', 'delete_handlers', array($this->_aConfig['home_uri']));
 
         BxDolImageTranscoder::unregisterHandlersArray($this->_aTranscoders);
         BxDolImageTranscoder::cleanupObjectsArray($this->_aTranscoders);
@@ -131,8 +131,8 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
         }
 
         //request Timeline cleaning
-        if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('timeline', 'delete_module_events'))
-            BxDolService::call('timeline', 'delete_module_events', array($this->_aConfig['home_uri']));
+        if ($this->_bUpdateTimeline && BxDolRequest::serviceExists('bx_timeline', 'delete_module_events'))
+            BxDolService::call('bx_timeline', 'delete_module_events', array($this->_aConfig['home_uri']));
 
         return parent::uninstall($aParams, $bDisable);
     }

+ 11 - 0
modules/boonex/timeline/classes/BxTimelineDb.php

@@ -113,6 +113,14 @@ class BxTimelineDb extends BxDolModuleDb
             $this->deleteEvent(array('type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
     }
 
+	public function activateModuleEvents($aData, $bActivate = true)
+    {
+    	$iActivate = $bActivate ? 1 : 0;
+
+    	foreach($aData['handlers'] as $aHandler)
+            $this->updateEvent(array('active' => $iActivate), array('type' => $aHandler['alert_unit'], 'action' => $aHandler['alert_action']));
+    }
+
     public function getHandlers($aParams = array())
     {
         $sMethod = 'getAll';
@@ -180,6 +188,9 @@ class BxTimelineDb extends BxDolModuleDb
         $sMethod = 'getAll';
         $sJoinClause = $sWhereClause = $sOrderClause = $sLimitClause = "";
 
+        if(isset($aParams['active']))
+        	$sWhereClause .= $this->prepare("AND `{$this->_sTable}`.`active`=? ", (int)$aParams['active']);
+
         switch($aParams['browse']) {
             case 'id':
                 $sMethod = 'getRow';

+ 5 - 0
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -864,6 +864,7 @@ class BxTimelineModule extends BxDolModule
         $aParams['filter'] = !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL;
         $aParams['modules'] = is_array($aModules) && !empty($aModules) ? $aModules : array();
         $aParams['timeline'] = (int)$iTimeline > 0 ? $iTimeline : 0;
+        $aParams['active'] = 1;
 
         return $aParams;
     }
@@ -917,11 +918,15 @@ class BxTimelineModule extends BxDolModule
 				case 'add_handlers':
 					$this->_oDb->insertData($aData);
 					BxDolAlerts::cacheInvalidate();
+
+					$this->_oDb->activateModuleEvents($aData, true);
 					break;
 
 				case 'delete_handlers':
 					$this->_oDb->deleteData($aData);
 					BxDolAlerts::cacheInvalidate();
+
+					$this->_oDb->activateModuleEvents($aData, false);
 					break;
 
 				case 'delete_module_events':

+ 1 - 0
modules/boonex/timeline/install/sql/install.sql

@@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS `bx_timeline_events` (
   `comments` int(11) unsigned NOT NULL default '0',
   `shares` int(11) unsigned NOT NULL default '0',
   `date` int(11) NOT NULL default '0',
+  `active` tinyint(4) NOT NULL default '1',
   PRIMARY KEY  (`id`),
   KEY `owner_id` (`owner_id`)
 );