Bladeren bron

#35 - optional install of additional modules

Alex Trofimov 12 jaren geleden
bovenliggende
commit
b40d69622a

+ 40 - 19
install/classes/BxDolInstallSiteConfig.php

@@ -357,27 +357,13 @@ EOF;
 
 
     public function processModules ($a)
     public function processModules ($a)
     {
     {
-        require_once(BX_INSTALL_PATH_HEADER);
-        bx_import('BxDolStudioInstallerUtils');
-        bx_import('BxDolLanguages');
-        BxDolLanguages::getInstance();        
-        $oModulesTools = new BxDolInstallModulesTools();
-
-        $aActions = array ('install', 'enable');
         $aTypes = array (BX_DOL_MODULE_TYPE_LANGUAGE, BX_DOL_MODULE_TYPE_TEMPLATE);
         $aTypes = array (BX_DOL_MODULE_TYPE_LANGUAGE, BX_DOL_MODULE_TYPE_TEMPLATE);
         foreach ($aTypes as $sModuleType) {
         foreach ($aTypes as $sModuleType) {
-            $aModules = $oModulesTools->getModules($sModuleType);
-            foreach ($aModules as $aConfig) {
-                $sUri = $aConfig['home_uri'];
-                if (empty($a[$sModuleType]) || $a[$sModuleType] != $sUri)
-                    continue;
-
-                foreach ($aActions as $sAction) {
-                    $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aConfig['home_dir'], $sAction);
-                    if ((!isset($aResult['result']) || !$aResult['result']) && !empty($aResult['message']))
-                        return array(BX_INSTALL_ERR_GENERAL => $aResult['message']);
-                }
-            }            
+            if (empty($a[$sModuleType]))
+                continue;
+            $sErrorMessage = $this->processModuleByUri ($a[$sModuleType], array ('install', 'enable'), $sModuleType);
+            if ($sErrorMessage)
+                return array(BX_INSTALL_ERR_GENERAL => $sErrorMessage);
         } 
         } 
 
 
         bx_import('BxDolAccount');
         bx_import('BxDolAccount');
@@ -391,6 +377,41 @@ EOF;
         return array();
         return array();
     }
     }
 
 
+    public function processModuleByUri ($sModuleUri, $aActions = array ('install', 'enable'), $sModuleType = null)
+    {
+        return $this->processModuleByField('home_uri', $sModuleUri, $aActions, $sModuleType);
+    }
+
+    public function processModuleByName ($sModuleName, $aActions = array ('install', 'enable'), $sModuleType = null)
+    {
+        return $this->processModuleByField('name', $sModuleName, $aActions, $sModuleType);
+    }
+
+    protected function processModuleByField ($sField, $sModuleUri, $aActions = array ('install', 'enable'), $sModuleType = null)
+    {
+        if (!file_exists(BX_INSTALL_PATH_HEADER))
+            return _t('_sys_inst_msg_script_isnt_installed');
+        require_once(BX_INSTALL_PATH_HEADER);
+        bx_import('BxDolStudioInstallerUtils');
+        bx_import('BxDolLanguages');
+        BxDolLanguages::getInstance();        
+        $oModulesTools = new BxDolInstallModulesTools();
+
+        $aModules = $oModulesTools->getModules($sModuleType);
+        foreach ($aModules as $aConfig) {
+            if ($sModuleUri != $aConfig[$sField])
+                continue;
+
+            foreach ($aActions as $sAction) {
+                $aResult = BxDolStudioInstallerUtils::getInstance()->perform($aConfig['home_dir'], $sAction);
+                if ((!isset($aResult['result']) || !$aResult['result']) && !empty($aResult['message']))
+                    return $aResult['message'];
+            }
+        }
+
+        return '';
+    }
+
     protected function dbErrors2ErrorFields ($a) 
     protected function dbErrors2ErrorFields ($a) 
     {
     {
         $s = '';
         $s = '';

+ 25 - 3
install/cmd.php

@@ -15,12 +15,14 @@ class BxDolInstallCmd
     protected $_sHeaderPath;
     protected $_sHeaderPath;
     protected $_aSiteConfig;
     protected $_aSiteConfig;
     protected $_isQuiet = false;
     protected $_isQuiet = false;
+    protected $_aAdditionalModules = array();
     protected $_aReturnCodes = array(
     protected $_aReturnCodes = array(
         'success' => array ('code' => 0, 'msg' => 'Success.'),
         'success' => array ('code' => 0, 'msg' => 'Success.'),
         'already installed' => array ('code' => 0, 'msg' => 'Script is already installed. Can\'t perform install.'),
         'already installed' => array ('code' => 0, 'msg' => 'Script is already installed. Can\'t perform install.'),
         'requirements failed' => array ('code' => 2, 'msg' => 'Requirements aren\'t met.'),
         'requirements failed' => array ('code' => 2, 'msg' => 'Requirements aren\'t met.'),
         'permissions failed' => array ('code' => 3, 'msg' => 'Folders and/or files permissions aren\'t correct.'),
         'permissions failed' => array ('code' => 3, 'msg' => 'Folders and/or files permissions aren\'t correct.'),
         'create config failed' => array ('code' => 4, 'msg' => 'Form data was not submitted.'),
         'create config failed' => array ('code' => 4, 'msg' => 'Form data was not submitted.'),
+        'module failed' => array ('code' => 5, 'msg' => 'Additional module install failed.'),
     );
     );
 
 
     public function __construct() 
     public function __construct() 
@@ -52,7 +54,7 @@ class BxDolInstallCmd
     {
     {
         // set neccessary options
         // set neccessary options
 
 
-        $a = getopt('hq', $this->getOptions());
+        $a = getopt('hqm:', $this->getOptions());
 
 
         if (isset($a['h']))
         if (isset($a['h']))
             $this->finish($this->_aReturnCodes['success']['code'], $this->getHelp());
             $this->finish($this->_aReturnCodes['success']['code'], $this->getHelp());
@@ -60,6 +62,9 @@ class BxDolInstallCmd
         if (isset($a['q']))
         if (isset($a['q']))
             $this->_isQuiet = true;
             $this->_isQuiet = true;
 
 
+        if (isset($a['m']))
+            $this->_aAdditionalModules = explode(',', $a['m']);
+
         $this->_aSiteConfig = array_merge($this->_aSiteConfig, $a);
         $this->_aSiteConfig = array_merge($this->_aSiteConfig, $a);
 
 
         // initialize environment
         // initialize environment
@@ -86,13 +91,21 @@ class BxDolInstallCmd
 
 
     protected function getHelp() 
     protected function getHelp() 
     {
     {
-        $s = '';
-        $s .= "Usage: php cmd.php [options]\n";
+        $s = "Usage: php cmd.php [options]\n";
+
         $s .= str_pad("\t -h", 35) . "Print this help\n";
         $s .= str_pad("\t -h", 35) . "Print this help\n";
         $s .= str_pad("\t -q", 35) . "Quiet\n";
         $s .= str_pad("\t -q", 35) . "Quiet\n";
+        $s .= str_pad("\t -m <module1,module2,...,moduleN>", 35) . "Install additional modules, by module name (ex:bx_notes)\n";
+
         foreach ($this->_aSiteConfig as $sKey => $sVal)
         foreach ($this->_aSiteConfig as $sKey => $sVal)
             if ('site_config' != $sKey)
             if ('site_config' != $sKey)
                 $s .= str_pad("\t --{$sKey}=<value>", 35) . "Default value: {$sVal}\n";
                 $s .= str_pad("\t --{$sKey}=<value>", 35) . "Default value: {$sVal}\n";
+
+        $s .= "\n";
+        $s .= "Return codes:\n";
+        foreach ($this->_aReturnCodes as $r)
+            $s .= str_pad("\t {$r['code']}", 5) . "{$r['msg']}\n";
+
         return $s;
         return $s;
     }
     }
 
 
@@ -148,6 +161,15 @@ class BxDolInstallCmd
 
 
         if (true !== $mixedResult)
         if (true !== $mixedResult)
             $this->finish($this->_aReturnCodes['create config failed']['code'], $sErrorMessage ? $sErrorMessage : $this->_aReturnCodes['create config failed']['msg']);
             $this->finish($this->_aReturnCodes['create config failed']['code'], $sErrorMessage ? $sErrorMessage : $this->_aReturnCodes['create config failed']['msg']);
+
+        // install custom additional modules
+        if (!empty($this->_aAdditionalModules)) {
+            foreach ($this->_aAdditionalModules as $sModuleName) {
+                $sErrorMessage = $oSiteConfig->processModuleByName($sModuleName);
+                if ($sErrorMessage)
+                    $this->finish($this->_aReturnCodes['module failed']['code'], $this->_aReturnCodes['module failed']['msg']);
+            }
+        }
     }
     }
 }
 }
 
 

+ 4 - 2
install/sql/system.sql

@@ -2,6 +2,8 @@
 -- Database: v 8.0
 -- Database: v 8.0
 --
 --
 
 
+SET @sSysVersion = '8.0.0';
+
 -- --------------------------------------------------------
 -- --------------------------------------------------------
 
 
 SET NAMES 'utf8';
 SET NAMES 'utf8';
@@ -244,7 +246,7 @@ SET @iCategoryId = LAST_INSERT_ID();
 
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'cmdDay', '', '10', 'digit', '', '', '', 1),
 (@iCategoryId, 'cmdDay', '', '10', 'digit', '', '', '', 1),
-(@iCategoryId, 'sys_version', '', '8.0.0', 'digit', '', '', '', 2),
+(@iCategoryId, 'sys_version', '', @sSysVersion, 'digit', '', '', '', 2),
 (@iCategoryId, 'sys_install_time', '', '0', 'digit', '', '', '', 3),
 (@iCategoryId, 'sys_install_time', '', '0', 'digit', '', '', '', 3),
 
 
 (@iCategoryId, 'sys_html_fields', '', 'a:1:{s:6:"system";a:4:{i:0;s:12:"POST.message";i:1;s:15:"REQUEST.message";i:2;s:12:"POST.CmtText";i:3;s:15:"REQUEST.CmtText";}}', 'text', '', '', '', 10),
 (@iCategoryId, 'sys_html_fields', '', 'a:1:{s:6:"system";a:4:{i:0;s:12:"POST.message";i:1;s:15:"REQUEST.message";i:2;s:12:"POST.CmtText";i:3;s:15:"REQUEST.CmtText";}}', 'text', '', '', '', 10),
@@ -944,7 +946,7 @@ CREATE TABLE `sys_modules` (
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8;
 
 
 INSERT INTO `sys_modules` (`type`, `name`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `dependencies`, `date`, `enabled`) VALUES
 INSERT INTO `sys_modules` (`type`, `name`, `title`, `vendor`, `version`, `product_url`, `update_url`, `path`, `uri`, `class_prefix`, `db_prefix`, `lang_category`, `dependencies`, `date`, `enabled`) VALUES
-('module', 'system', 'System', 'BoonEx', '8.0.0', '', '', '', 'system', 'Bx', 'sys_', 'System', '', 0, 1);
+('module', 'system', 'System', 'BoonEx', @sSysVersion, '', '', '', 'system', 'Bx', 'sys_', 'System', '', 0, 1);
 
 
 
 
 CREATE TABLE `sys_modules_file_tracks` (
 CREATE TABLE `sys_modules_file_tracks` (

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

@@ -3840,6 +3840,7 @@ If you don't know how to do it by yourself you can submit <a target="_blank" hre
     <string name="_sys_inst_msg_finish_goto_studio"><![CDATA[<a href="{0}studio/">Go to Studio</a> to add additional modules and customize the site.]]></string>
     <string name="_sys_inst_msg_finish_goto_studio"><![CDATA[<a href="{0}studio/">Go to Studio</a> to add additional modules and customize the site.]]></string>
     <string name="_sys_inst_msg_remove_install"><![CDATA[Please, remove INSTALL directory from your server and reload this page to activate your site.<br />After deletion you can safely go <a href="../studio/">to the site Studio</a> to add additional modules and customize the site.]]></string>
     <string name="_sys_inst_msg_remove_install"><![CDATA[Please, remove INSTALL directory from your server and reload this page to activate your site.<br />After deletion you can safely go <a href="../studio/">to the site Studio</a> to add additional modules and customize the site.]]></string>
     <string name="_sys_inst_msg_admin_account_not_found"><![CDATA[Admin account wasn't found by email - {0}]]></string>
     <string name="_sys_inst_msg_admin_account_not_found"><![CDATA[Admin account wasn't found by email - {0}]]></string>
+    <string name="_sys_inst_msg_script_isnt_installed"><![CDATA[Script isn't installed]]></string>
 
 
 	<string name="_sys_inst_finish"><![CDATA[Installation has been successfully completed]]></string>
 	<string name="_sys_inst_finish"><![CDATA[Installation has been successfully completed]]></string>
 	<string name="_sys_inst_site_config"><![CDATA[Site configuration]]></string>
 	<string name="_sys_inst_site_config"><![CDATA[Site configuration]]></string>