Bläddra i källkod

Ticket #323: Update Relations during Installation.

AntonLV 10 år sedan
förälder
incheckning
7e1e175643

+ 0 - 26
modules/base/notifications/classes/BxBaseModNotificationsInstaller.php

@@ -15,32 +15,6 @@ class BxBaseModNotificationsInstaller extends BxBaseModGeneralInstaller
     {
         parent::__construct($aConfig);
     }
-
-	public function enable($aParams)
-    {
-    	$aResult = parent::enable($aParams);
-        if($aResult['result'])
-        	$this->_processHandlers('add_handlers');
-
-        return $aResult;
-    }
-
-    public function disable($aParams)
-    {
-    	$this->_processHandlers('delete_handlers');
-
-        return parent::disable($aParams);
-    }
-
-    protected function _processHandlers($sAction)
-    {
-    	$aModules = $this->oDb->getModulesBy(array('type' => 'all', 'active' => 1));
-	    foreach($aModules as $aModule) {
-	    	$aConfig = self::getModuleConfig($aModule);
-			if(!empty($aConfig['relations']) && is_array($aConfig['relations']) && in_array($this->_aConfig['name'], $aConfig['relations']))
-				BxDolService::call($this->_aConfig['name'], $sAction, array($aModule['uri']));
-		}
-    }
 }
 
 /** @} */

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1314,6 +1314,7 @@
 	<string name="_adm_txt_modules_show_introduction"><![CDATA[Introduction from vendor:]]></string>
 	<string name="_adm_txt_modules_update_files"><![CDATA[Update files:]]></string>
 	<string name="_adm_txt_modules_update_relations"><![CDATA[Update relations:]]></string>
+	<string name="_adm_txt_modules_update_relations_for_all"><![CDATA[Update relations for all dependent modules:]]></string>
 	<string name="_adm_txt_modules_update_languages"><![CDATA[Update languages:]]></string>
 	<string name="_adm_txt_modules_update_latest"><![CDATA[You have the most current version.]]></string>
 	<string name="_adm_txt_modules_update_text"><![CDATA[New version {0} is available.]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1314,6 +1314,7 @@
 	<string name="_adm_txt_modules_show_introduction"><![CDATA[Введение от продавца:]]></string>
 	<string name="_adm_txt_modules_update_files"><![CDATA[Обновить файлы:]]></string>
 	<string name="_adm_txt_modules_update_relations"><![CDATA[Обновить связи:]]></string>
+	<string name="_adm_txt_modules_update_relations_for_all"><![CDATA[Обновить связи для всех зависимых модулей:]]></string>
 	<string name="_adm_txt_modules_update_languages"><![CDATA[Обновить языки:]]></string>
 	<string name="_adm_txt_modules_update_latest"><![CDATA[У Вас самая свежая версия.]]></string>
 	<string name="_adm_txt_modules_update_text"><![CDATA[Доступна новая версия {0}.]]></string>

+ 53 - 1
studio/classes/BxDolStudioInstaller.php

@@ -45,7 +45,7 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
     protected $_bShowOnSuccess = false;
 
-    function __construct($aConfig)
+    public function __construct($aConfig)
     {
         parent::__construct();
 
@@ -102,6 +102,9 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
             ),
             'update_relations' => array(
                 'title' => _t('_adm_txt_modules_update_relations'),
+            ),
+            'update_relations_for_all' => array(
+                'title' => _t('_adm_txt_modules_update_relations_for_all'),
             ),
 			'process_connections' => array(
                 'title' => _t('_adm_txt_modules_process_connections'),
@@ -364,6 +367,13 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
                 'result' => false
             );
 
+		$aResult = array();
+		if(!empty($this->_aConfig['before_enable'])) {
+        	$aResult = $this->_perform('before_enable', $aParams);
+        	if($aResult && !$aResult['result'])
+        		return $aResult;
+		}
+
 		$aResult = array();
         bx_alert('system', 'before_enable', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
         if ($aResult && !$aResult['result'])
@@ -407,6 +417,13 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
                 'result' => false
             );
 
+		$aResult = array();
+		if(!empty($this->_aConfig['before_disable'])) {
+        	$aResult = $this->_perform('before_disable', $aParams);
+        	if($aResult && !$aResult['result'])
+        		return $aResult;
+		}
+
 		$aResult = array();
         bx_alert('system', 'before_disable', 0, false, array ('config' => $this->_aConfig, 'result' => &$aResult));
         if ($aResult && !$aResult['result'])
@@ -600,6 +617,12 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
         return $bResult && $oLanguages->compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
     }
+
+    /**
+     * NOTE. The action is ONLY needed for dependent module to let 
+     * Notifications based module(s) know that he(they) should 
+     * update (request and save) handlers from this dependent module.
+     */
 	protected function actionUpdateRelations($sOperation)
     {
         if(!in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) 
@@ -622,6 +645,35 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
         return BX_DOL_STUDIO_INSTALLER_SUCCESS;
     }
 
+    /**
+     * NOTE. The action is ONLY needed for Notifications based modules 
+     * to update (request and save) handlers from all dependent modules.
+     */
+    protected function actionUpdateRelationsForAll($sOperation)
+    {
+    	if(!in_array($sOperation, array('enable', 'disable'))) 
+        	return BX_DOL_STUDIO_INSTALLER_FAILED;
+
+        if($sOperation == 'enable')
+        	$this->oDb->insertRelation($this->_aConfig['name'], $this->_aConfig['relation_handlers']);
+
+		$aRelation = $this->oDb->getRelationsBy(array('type' => 'module', 'value' => $this->_aConfig['name']));
+		if(empty($aRelation) || empty($aRelation['on_' . $sOperation]))
+			return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+
+    	$aModules = $this->oDb->getModulesBy(array('type' => 'all', 'active' => 1));
+	    foreach($aModules as $aModule) {
+	    	$aConfig = self::getModuleConfig($aModule);
+			if(!empty($aConfig['relations']) && is_array($aConfig['relations']) && in_array($this->_aConfig['name'], $aConfig['relations']))
+				BxDolService::call($this->_aConfig['name'], $aRelation['on_' . $sOperation], array($aModule['uri']));
+		}
+
+		if($sOperation == 'disable')
+        	$this->oDb->deleteRelation($this->_aConfig['name']);
+
+		return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+    }
+
 	/**
      * 
      * Connections objects associated with module data. It must be defined which content is associated with the connection.

+ 12 - 0
studio/classes/BxDolStudioInstallerQuery.php

@@ -14,6 +14,18 @@ class BxDolStudioInstallerQuery extends BxDolModuleQuery
         parent::__construct();
     }
 
+    function insertRelation($sModule, $aRelation)
+    {
+    	$aRelation['module'] = $sModule;
+        return (int)$this->query("INSERT INTO `sys_modules_relations` SET `module`=:module, `on_install`=:on_install, `on_uninstall`=:on_uninstall, `on_enable`=:on_enable, `on_disable`=:on_disable", $aRelation) > 0;
+    }
+
+	function deleteRelation($sModule)
+    {
+    	$sQuery = $this->prepare("DELETE FROM `sys_modules_relations` WHERE `module`=? LIMIT 1", $sModule);
+        return (int)$this->query($sQuery) > 0;
+    }
+
     function getRelationsBy($aParams = array())
     {
     	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));