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

#31 - Modules' Connections and new action in Modules' Installer.

AntonLV 12 лет назад
Родитель
Сommit
1539f600f8

+ 18 - 0
inc/classes/BxDolInstallerUtils.php

@@ -39,6 +39,24 @@ class BxDolInstallerUtils extends BxDolIO
         return false;
     }
 
+    static public function getModuleConfig($mixed)
+    {
+    	$sConfig = '';
+    	if(is_array($mixed) && !empty($mixed['path']))
+			$sConfig = BX_DIRECTORY_PATH_MODULES . $mixed['path'] . 'install/config.php';
+		else if(is_string($mixed))
+			$sConfig = $mixed;
+		else 
+			return array();
+
+    	if(!file_exists($sConfig))
+            return array();
+
+        include($sConfig);
+
+        return $aConfig;
+    }
+
     static public function isModuleInstalled($sUri)
     {
         bx_import('BxDolModuleQuery');

+ 10 - 0
install/sql/system.sql

@@ -739,6 +739,16 @@ CREATE TABLE `sys_modules_file_tracks` (
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 
+CREATE TABLE `sys_modules_connections` (
+  `id` int(11) unsigned NOT NULL auto_increment,
+  `module` varchar(32) NOT NULL default '',
+  `on_install` varchar(255) NOT NULL default '',
+  `on_uninstall` varchar(255) NOT NULL default '',
+  `on_enable` varchar(255) NOT NULL default '',
+  `on_disable` varchar(255) NOT NULL default '',
+  PRIMARY KEY  (`id`)
+) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
+
 -- --------------------------------------------------------
 
 --

+ 0 - 12
modules/base/general/classes/BxBaseModGeneralInstaller.php

@@ -22,8 +22,6 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
 
     protected $_aConnections = array (); // connections objects associated with module data, it must be defined which content is associated with the connection, the key is connection object name and value is array (possible array values: type, conn, table, field_id), if 'type' == 'profiles', then it is considered profiles connection and other possible param is 'conn' ('initiator', 'content' or 'both') when 'type' == 'custom' (or ommited), then other possible params are 'conn', 'table' and 'field_id'
 
-    protected $_bUpdateTimeline = false; // set to true to automatically register handlers for timeline module
-
     protected $_aMenuTriggers = array(); // list of menu triggers, it must be specified in the module which adds menu item and in modules where menu items are added, @see BxDolMenu::processMenuTrigger
 
     function __construct($aConfig)
@@ -40,9 +38,6 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
 
         BxDolImageTranscoder::registerHandlersArray($this->_aTranscoders);
 
-        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');
             foreach ($this->_aMenuTriggers as $sMenuTriggerName)
@@ -54,9 +49,6 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
 
     function disable($aParams)
     {
-        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);
 
@@ -130,10 +122,6 @@ class BxBaseModGeneralInstaller extends BxDolStudioInstaller
             }
         }
 
-        //request Timeline cleaning
-        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);
     }
 }

+ 0 - 1
modules/base/text/classes/BxBaseModTextInstaller.php

@@ -16,7 +16,6 @@ class BxBaseModTextInstaller extends BxBaseModGeneralInstaller
     function __construct($aConfig)
     {
         parent::__construct($aConfig);
-        $this->_bUpdateTimeline = true;
     }
 }
 

+ 0 - 1
modules/boonex/convos/install/installer.php

@@ -18,7 +18,6 @@ class BxCnvInstaller extends BxBaseModTextInstaller
         parent::__construct($aConfig);
         $this->_aTranscoders = array ('bx_convos_preview');
         $this->_aStorages = array ('bx_convos_files');
-        $this->_bUpdateTimeline = false;
     }
 }
 

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

@@ -1237,6 +1237,7 @@
 	<string name="_adm_txt_modules_show_conclusion"><![CDATA[Conclusion from vendor:]]></string>
 	<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_connections"><![CDATA[Update connections:]]></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>

+ 11 - 0
modules/boonex/notes/install/config.php

@@ -52,10 +52,12 @@ $aConfig = array(
     'uninstall' => array (
         'execute_sql' => 1,
         'update_languages' => 1,
+    	'update_connections' => 1,
         'clear_db_cache' => 1,
     ),
     'enable' => array(
         'execute_sql' => 1,
+    	'update_connections' => 1,
         'recompile_menus' => 1,
         'recompile_permalinks' => 1,
         'recompile_alerts' => 1,
@@ -63,6 +65,7 @@ $aConfig = array(
     ),
     'disable' => array (
         'execute_sql' => 1,
+    	'update_connections' => 1,
         'recompile_menus' => 1,
         'recompile_permalinks' => 1,
         'recompile_alerts' => 1,
@@ -74,6 +77,14 @@ $aConfig = array(
      */
     'dependencies' => array(),
 
+    /**
+     * Connections Section
+     */
+    'connections' => array(
+    	'bx_timeline',
+    	'bx_notifications'
+    ),
+
 );
 
 /** @} */

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

@@ -2422,6 +2422,7 @@ Without doing that you won't be submitted to our database.</p>
 	<string name="_adm_txt_modules_move_sources"><![CDATA[Move source files:]]></string>
 	<string name="_adm_txt_modules_execute_sql"><![CDATA[Changing database:]]></string>
 	<string name="_adm_txt_modules_install_language"><![CDATA[Install language:]]></string>
+	<string name="_adm_txt_modules_update_connections"><![CDATA[Update connections:]]></string>
 	<string name="_adm_txt_modules_update_languages"><![CDATA[Update languages:]]></string>
 	<string name="_adm_txt_modules_recompile_global_paramaters"><![CDATA[Recompiling global paramaters:]]></string>
 	<string name="_adm_txt_modules_recompile_menus"><![CDATA[Recompiling menus:]]></string>

+ 4 - 0
modules/boonex/timeline/install/sql/disable.sql

@@ -33,3 +33,7 @@ DELETE FROM `sys_objects_cmts` WHERE `Name`='bx_timeline' LIMIT 1;
 
 -- VOTES
 DELETE FROM `sys_objects_vote` WHERE `Name`='bx_timeline' LIMIT 1;
+
+
+-- MODULES' CONNECTIONS
+DELETE FROM `sys_modules_connections` WHERE `module`='bx_timeline' LIMIT 1;

+ 5 - 0
modules/boonex/timeline/install/sql/enable.sql

@@ -129,3 +129,8 @@ INSERT INTO `sys_objects_cmts` (`Name`, `Table`, `CharsPostMin`, `CharsPostMax`,
 -- VOTES
 INSERT INTO `sys_objects_vote`(`Name`, `TableMain`, `TableTrack`, `PostTimeout`, `MinValue`, `MaxValue`, `IsUndo`, `IsOn`, `TriggerTable`, `TriggerFieldId`, `TriggerFieldRate`, `TriggerFieldRateCount`, `ClassName`, `ClassFile`) VALUES 
 ('bx_timeline', 'bx_timeline_votes', 'bx_timeline_votes_track', '604800', '1', '1', '1', '1', 'bx_timeline_events', 'id', 'rate', 'votes', 'BxTimelineVote', 'modules/boonex/timeline/classes/BxTimelineVote.php');
+
+
+-- MODULES' CONNECTIONS
+INSERT INTO `sys_modules_connections` (`module`, `on_install`, `on_uninstall`, `on_enable`, `on_disable`) VALUES
+('bx_timeline', '', 'delete_module_events', 'add_handlers', 'delete_handlers');

+ 24 - 0
studio/classes/BxDolStudioInstaller.php

@@ -106,6 +106,9 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
             'update_languages' => array(
                 'title' => _t('_adm_txt_modules_update_languages'),
             ),
+            'update_connections' => array(
+                'title' => _t('_adm_txt_modules_update_connections'),
+            ),
             'recompile_global_paramaters' => array(
                 'title' => _t('_adm_txt_modules_recompile_global_paramaters'),
             ),
@@ -698,6 +701,27 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
             $oLanguages->deleteLanguageCategory($this->_aConfig['language_category']);
 
         return $bResult && $oLanguages->compileLanguage(0, true) ? BX_DOL_STUDIO_INSTALLER_SUCCESS : BX_DOL_STUDIO_INSTALLER_FAILED;
+    }
+	function actionUpdateConnections($sOperation)
+    {
+        if(!in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) 
+        	return BX_DOL_STUDIO_INSTALLER_FAILED;
+
+		if(empty($this->_aConfig['connections']) || !is_array($this->_aConfig['connections']))
+            return BX_DOL_STUDIO_INSTALLER_SUCCESS;
+
+		foreach($this->_aConfig['connections'] as $sModule) {
+			if(!$this->oDb->isModuleByName($sModule))
+				continue;
+
+			$aConnection = $this->oDb->getConnectionsBy(array('type' => 'module', 'value' => $sModule));
+			if(empty($aConnection) || empty($aConnection['on_' . $sOperation]) || !BxDolRequest::serviceExists($aConnection['module'], $aConnection['on_' . $sOperation]))
+				continue;
+
+			BxDolService::call($aConnection['module'], $aConnection['on_' . $sOperation], array($this->_aConfig['home_uri']));
+		}
+
+        return BX_DOL_STUDIO_INSTALLER_SUCCESS;
     }
     function actionRecompileGlobalParamaters($sOperation)
     {

+ 25 - 0
studio/classes/BxDolStudioInstallerQuery.php

@@ -16,6 +16,31 @@ class BxDolStudioInstallerQuery extends BxDolModuleQuery
         parent::__construct();
     }
 
+    function getConnectionsBy($aParams = array())
+    {
+    	$sMethod = 'getAll';
+    	$sWhereClause = "";
+
+        switch($aParams['type']) {
+            case 'module':
+            	$sMethod = 'getRow';
+                $sWhereClause .= $this->prepare(" AND `module`=?", $aParams['value']);
+                break;
+        }
+
+        $sSql = "SELECT
+                `id`,
+                `module`,
+                `on_install`,
+                `on_uninstall`,
+                `on_enable`,
+                `on_disable`
+            FROM `sys_modules_connections`
+            WHERE 1" . $sWhereClause;
+
+        return $this->$sMethod($sSql);
+    }
+
     function insertModule(&$aConfig)
     {
         $sProductUrl = isset($aConfig['product_url']) ? $aConfig['product_url'] : '';

+ 6 - 9
studio/classes/BxDolStudioInstallerUtils.php

@@ -151,12 +151,11 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 
     protected function getConfigModule($sConfigPath, $aInstalledPathes = array(), $aInstalledInfo = array())
     {
-        if(!file_exists($sConfigPath))
+    	$aConfig = self::getModuleConfig($sConfigPath);
+        if(empty($aConfig) || !is_array($aConfig))
             return array();
 
-        include($sConfigPath);
         $sModulePath = $aConfig['home_dir'];
-        $sTitle = bx_process_output($aConfig['title']);
 
         $bInstalled = !empty($aInstalledPathes) && in_array($sModulePath, $aInstalledPathes);
         $bEnabled = $bInstalled && !empty($aInstalledInfo) && (int)$aInstalledInfo[$sModulePath]['enabled'] == 1;
@@ -176,7 +175,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return array(
         	'type' => $aConfig['type'],
             'name' => isset($aConfig['name']) ? $aConfig['name'] : $aConfig['home_uri'],
-            'title' => $sTitle,
+            'title' => bx_process_output($aConfig['title']),
             'vendor' => $aConfig['vendor'],
             'version' => $aConfig['version'],
             'uri' => $aConfig['home_uri'],
@@ -194,14 +193,12 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         if(empty($aModule) || !$aModule['installed'])
             return array();
 
-        if(!file_exists($sConfigPathUpdate))
+		$aConfig = self::getModuleConfig($sConfigPathUpdate);
+        if(empty($aConfig) || !is_array($aConfig))
             return array();
 
-        include($sConfigPathUpdate);
-        $sTitle = bx_process_output($aConfig['title']);
-
         return array(
-            'title' => $sTitle,
+            'title' => bx_process_output($aConfig['title']),
             'vendor' => $aConfig['vendor'],
             'version_from' => $aConfig['version_from'],
             'version_to' => $aConfig['version_to'],