Procházet zdrojové kódy

#31 - Improvements in Module (Update) installation process.

AntonLV před 12 roky
rodič
revize
e9e32fa3e6

+ 13 - 5
inc/classes/BxDolModuleQuery.php

@@ -101,7 +101,8 @@ class BxDolModuleQuery extends BxDolDb implements iBxDolSingleton
     }
     function getModulesBy($aParams = array())
     {
-        $sPostfix = $sWhereClause = "";
+    	$aMethod = array('name' => 'getAll', 'params' => array(0 => 'query'));
+        $sPostfix = $sWhereClause = $sOrderByClause = "";
 
         switch($aParams['type']) {
             case 'modules':
@@ -116,6 +117,10 @@ class BxDolModuleQuery extends BxDolDb implements iBxDolSingleton
                 $sPostfix .= '_templates';
                 $sWhereClause .= $this->prepare(" AND `type`=?", BX_DOL_MODULE_TYPE_TEMPLATE);
                 break;
+            case 'path_and_uri':
+            	$aMethod['name'] = 'getRow';
+            	$sWhereClause .= $this->prepare(" AND `path`=? AND `uri`=?", $aParams['path'], $aParams['uri']);
+            	break;
         }
 
         if(isset($aParams['active'])) {
@@ -125,7 +130,7 @@ class BxDolModuleQuery extends BxDolDb implements iBxDolSingleton
 
         $sOrderByClause = " ORDER BY " . (isset($aParams['order_by']) ? $aParams['order_by'] : '`title`');
 
-        $sSql = "SELECT
+        $aMethod['params'][0] = "SELECT
                 `id`,
                 `type`,
                 `name`,
@@ -141,9 +146,12 @@ class BxDolModuleQuery extends BxDolDb implements iBxDolSingleton
                 `date`,
                 `enabled`
             FROM `sys_modules`
-            WHERE 1 " . $sWhereClause .
-            $sOrderByClause;
-        return $this->fromMemory('sys_modules' . $sPostfix, 'getAll', $sSql);
+            WHERE 1 " . $sWhereClause . $sOrderByClause;
+
+        if(empty($sPostfix))
+        	return call_user_func_array(array($this, $aMethod['name']), $aMethod['params']);
+
+        return call_user_func_array(array($this, 'fromMemory'), array_merge(array('sys_modules' . $sPostfix, $aMethod['name']), $aMethod['params']));
     }
 
     function getModulesUri()

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

@@ -593,6 +593,7 @@
 	<string name="_adm_err_modules_wrong_permissions_msg"><![CDATA[{0} - {1}]]></string>
 	<string name="_adm_err_modules_wrong_version"><![CDATA[The module has incompatible version]]></string>
 	<string name="_adm_err_modules_wrong_version_script"><![CDATA[The module is not compatible with your version of Dolphin script]]></string>
+	<string name="_adm_err_modules_wrong_version_script_update"><![CDATA[The new version of {0} module isn't compatible with your version of Dolphin. Please upgrade Dolphin first (Dashboard > Version) and then try to upgrade the module.]]></string>
 	<string name="_adm_err_oauth_cannot_get_token"><![CDATA[Cannot connect to <b>BoonEx</b>. Please try again later.]]></string>
 	<string name="_adm_err_oauth_cannot_read_answer"><![CDATA[Cannot get a valid answer from <b>BoonEx</b>. Please try again later.]]></string>
 	<string name="_adm_err_oauth_empty_key_secret"><![CDATA[You need to enter Key and Secret provided by <b>BoonEx</b> in Settings -> General.]]></string>

+ 25 - 9
studio/classes/BxDolStudioInstaller.php

@@ -176,13 +176,7 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
             );
 
         //--- Check version compatibility ---//
-        $bCompatible = false;
-        if(isset($this->_aConfig['compatible_with']) && is_array($this->_aConfig['compatible_with']))
-            foreach($this->_aConfig['compatible_with'] as $iKey => $sVersion) {
-                $sVersion = '/^' . str_replace(array('.', 'x'), array('\.', '[A-Za-z0-9-]+'), $sVersion) . '$/is';
-                $bCompatible = $bCompatible || (preg_match($sVersion, bx_get_ver()) > 0);
-            }
-        if(!$bCompatible)
+        if(!$this->_isCompatibleWith())
             return array(
                 'message' => $this->_displayResult('check_script_version', false, '_adm_err_modules_wrong_version_script'),
                 'result' => false
@@ -486,17 +480,27 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
     function _displayResult($sAction, $bResult, $sResult = '')
     {
+    	$oTemplate = BxDolStudioTemplate::getInstance();
+
         $sMessage = $this->_aActions[$sAction]['title'] . ' ';
         if(!empty($sResult))
             $sResult = (substr($sResult, 0, 1) == '_' ? _t($sResult) : $sResult) . '<br />';
 
         if(!$bResult)
-            return $sMessage . '<span style="color:red;">' . $sResult . '</span>';
+            return $oTemplate->parseHtmlByName('mod_action_result_step.html', array(
+            	'color' => 'red',
+            	'title' => $sMessage,
+            	'content' => $sResult
+            ));
 
         if($bResult && !in_array($sAction, array('show_introduction', 'show_conclusion')) && !$this->_bShowOnSuccess)
             return;
 
-        return $sMessage . '<span style="color:green;">' . (!empty($sResult) ? $sResult : _t('_adm_txt_modules_process_action_success') . '<br />') . '</span>';
+        return $oTemplate->parseHtmlByName('mod_action_result_step.html', array(
+        	'color' => 'green',
+            'title' => $sMessage,
+            'content' => !empty($sResult) ? $sResult : _t('_adm_txt_modules_process_action_success') . '<br />'
+        ));
     }
 
     //--- Action Methods ---//
@@ -766,6 +770,18 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
 
         return $oFile;
     }
+
+    protected function _isCompatibleWith()
+    {
+    	$bCompatible = false;
+        if(isset($this->_aConfig['compatible_with']) && is_array($this->_aConfig['compatible_with']))
+            foreach($this->_aConfig['compatible_with'] as $iKey => $sVersion) {
+                $sVersion = '/^' . str_replace(array('.', 'x'), array('\.', '[A-Za-z0-9-]+'), $sVersion) . '$/is';
+                $bCompatible = $bCompatible || (preg_match($sVersion, bx_get_ver()) > 0);
+            }
+
+		return $bCompatible;
+    }
 }
 
 /** @} */

+ 10 - 5
studio/classes/BxDolStudioUpdater.php

@@ -44,16 +44,22 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
         );
 
         //--- Check for module to update ---//
-        $sQuery = $oDb->prepare("SELECT `id`, `version` FROM `sys_modules` WHERE `path`=? AND `uri`=? LIMIT 1", $this->_aConfig['module_dir'], $this->_aConfig['module_uri']);
-        $aModuleInfo = $oDb->getRow($sQuery);
+        $aModuleInfo = $oDb->getModulesBy(array('type' => 'path_and_uri', 'path' => $this->_aConfig['module_dir'], 'uri' => $this->_aConfig['module_uri']));
         if(!$aModuleInfo)
             return array_merge($aResult, array(
                 'message' => $this->_displayResult('check_module_exists', false, '_adm_err_modules_module_not_found'),
                 'result' => false
             ));
 
+		//--- Check Dolphin version compatibility ---//
+        if(!$this->_isCompatibleWith())
+            return array(
+                'message' => $this->_displayResult('check_script_version', false, _t('_adm_err_modules_wrong_version_script_update', $aModuleInfo['title'])),
+                'result' => false
+            );
+
         //--- Check version ---//
-        if($aModuleInfo['version'] != $this->_aConfig['version_from'])
+        if(version_compare($aModuleInfo['version'], $this->_aConfig['version_from']) != 0)
             return array_merge($aResult, array(
                 'message' => $this->_displayResult('check_module_version', false, '_adm_err_modules_wrong_version'),
                 'result' => false
@@ -80,8 +86,7 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
         //--- Perform action and check results ---//
         $aResult = array_merge($aResult, $this->_perform('install', 'Update'));
         if($aResult['result']) {
-            $sQuery = $oDb->prepare("UPDATE `sys_modules` SET `version`=? WHERE `id`=?", $this->_aConfig['version_to'], $aModuleInfo['id']);
-            $oDb->query($sQuery);
+            $oDb->updateModule(array('version' => $this->_aConfig['version_to']), array('id' => $aModuleInfo['id']));
 
             $oDb->deleteModuleTrackFiles($aModuleInfo['id']);
 

+ 8 - 1
studio/template/css/modules.css

@@ -3,4 +3,11 @@ div.bx-mod-confirm {}
 div.bx-mod-confirm-cnt{}
 
 div.bx-mod-action-result {}
-div.bx-mod-action-result-cnt {}
+div.bx-mod-action-result-cnt {}
+
+div.bx-mod-action-result-step {
+	max-width: 480px;
+	max-width: 30rem;
+}
+div.bx-mod-ars-title,
+div.bx-mod-ars-content {}

+ 4 - 0
studio/template/mod_action_result_step.html

@@ -0,0 +1,4 @@
+<div class="bx-mod-action-result-step">
+	<div class="bx-mod-ars-title">__title__</div>
+	<div  class="bx-mod-ars-content bx-def-margin-thd-top" style="color:__color__;">__content__</div>
+</div>

+ 1 - 1
studio/template/scripts/BxBaseStudioStore.php

@@ -22,7 +22,7 @@ class BxBaseStudioStore extends BxDolStudioStore
 
     function getPageCss()
     {
-        return array_merge(parent::getPageCss(), array('store.css', 'store-media-tablet.css', 'store-media-desktop.css'));
+        return array_merge(parent::getPageCss(), array('modules.css', 'store.css', 'store-media-tablet.css', 'store-media-desktop.css'));
     }
 
     function getPageJs()