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

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

AntonLV 12 лет назад
Родитель
Сommit
733d3535f5

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

@@ -578,6 +578,7 @@
 	<string name="_adm_err_modules_cannot_delete_from_cart"><![CDATA[Cannot delete the product(s) from shopping cart.]]></string>
 	<string name="_adm_err_modules_cannot_remove_package"><![CDATA[Cannot remove package.]]></string>
 	<string name="_adm_err_modules_module_not_found"><![CDATA[Module not found]]></string>
+	<string name="_adm_err_modules_module_not_match"><![CDATA[Update is not suitable for this module.]]></string>
 	<string name="_adm_err_modules_module_not_installed"><![CDATA[Module not installed]]></string>
 	<string name="_adm_err_modules_module_was_modified"><![CDATA[Module was modified]]></string>
 	<string name="_adm_err_modules_pending_uninstall"><![CDATA[Module uninstall was postponed. Module will be uninstalled automatically after all its files are deleted.]]></string>
@@ -1221,6 +1222,7 @@
 	<string name="_adm_txt_module_system"><![CDATA[System]]></string>
 	<string name="_adm_txt_modules_check_dependencies"><![CDATA[Check module dependencies:]]></string>
 	<string name="_adm_txt_modules_check_module_exists"><![CDATA[Check module for existence:]]></string>
+	<string name="_adm_txt_modules_check_module_matches"><![CDATA[Check module to match:]]></string>
 	<string name="_adm_txt_modules_check_module_hash"><![CDATA[Check module hash:]]></string>
 	<string name="_adm_txt_modules_check_module_version"><![CDATA[Check module version:]]></string>
 	<string name="_adm_txt_modules_check_script_version"><![CDATA[Check the Dolphin version for compatibility:]]></string>

+ 28 - 10
studio/classes/BxDolStudioInstallerUtils.php

@@ -50,9 +50,9 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     /*
      * Is used to complete Downloading inside Transient Cron Job.
      */
-    public function serviceDownloadFileComplete($sFilePath, $sAutoAction = '')
+    public function serviceDownloadFileComplete($sFilePath, $aParams = array())
     {
-    	return $this->downloadFileComplete($sFilePath, $sAutoAction, true);
+    	return $this->downloadFileComplete($sFilePath, array_merge($aParams, array('transient' => true)));
     }
 
     /*
@@ -60,7 +60,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
      */
 	public function servicePerformAction($sDirectory, $sOperation, $aParams)
     {
-    	return $this->perform($sDirectory, $sOperation, $aParams, true);
+    	return $this->perform($sDirectory, $sOperation, array_merge($aParams, array('transient' => true)));
     }
 
     public function getModules($bTitleAsKey = true)
@@ -173,8 +173,14 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $aResult;
     }
 
-    public function perform($sDirectory, $sOperation, $aParams = array(), $bTransient = false)
+    public function perform($sDirectory, $sOperation, $aParams = array())
     {
+	    $bTransient = false;
+    	if(isset($aParams['transient']) && $aParams['transient'] === true) {
+    		$bTransient = true;
+    		unset($aParams['transient']);
+    	}
+
     	if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner() && !in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) {
     		if($this->addTransientJob('perform_action', array($sDirectory, $sOperation, $aParams)))
     			return array('code' => 1, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
@@ -287,10 +293,10 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 			))),
 		));
 
-		return $this->downloadFileInit($aItem, $bAutoUpdate ? 'update' : '');
+		return $this->downloadFileInit($aItem, array('updated_module_name' => $sModuleName, 'auto_action' => $bAutoUpdate ? 'update' : ''));
     }
 
-    protected function downloadFileInit($aItem, $sAutoAction = '')
+    protected function downloadFileInit($aItem, $aParams = array())
     {
     	if(empty($aItem) || !is_array($aItem))
 			return $aItem;
@@ -301,14 +307,26 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         if($mixedResult !== true)
         	return $mixedResult;
 
-		return $this->downloadFileComplete($sFilePath, $sAutoAction);
+		return $this->downloadFileComplete($sFilePath, $aParams);
     }
 
-    protected function downloadFileComplete($sFilePath, $sAutoAction = '', $bTransient = false)
+    protected function downloadFileComplete($sFilePath, $aParams = array())
     {
+    	$sAutoAction = '';
+    	if(isset($aParams['auto_action'])) {
+    		$sAutoAction = $aParams['auto_action'];
+    		unset($aParams['auto_action']);
+    	}
     	$bAutoAction = !empty($sAutoAction);
+
+    	$bTransient = false;
+    	if(isset($aParams['transient']) && $aParams['transient'] === true) {
+    		$bTransient = true;
+    		unset($aParams['transient']);
+    	}
+
 		if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner())
-			return _t($this->addTransientJob('download_file_complete', array($sFilePath, $sAutoAction)) ? '_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled' : '_adm_str_err_download_failed');
+			return _t($this->addTransientJob('download_file_complete', array($sFilePath, $aParams)) ? '_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled' : '_adm_str_err_download_failed');
 
         //--- Unarchive package.
         $sPackagePath = '';
@@ -338,7 +356,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 			 return true;
 
 		//--- Autoinstall the downloaded package if it's needed.
-		$aResult = $this->perform($sHomePath, $sAutoAction);
+		$aResult = $this->perform($sHomePath, $sAutoAction, $aParams);
 		if((int)$aResult['code'] != 0) {
 			if($bTransient)
         		$this->emailNotify($aResult['message']);

+ 9 - 0
studio/classes/BxDolStudioUpdater.php

@@ -20,6 +20,9 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
             'check_module_exists' => array(
                 'title' => _t('_adm_txt_modules_check_module_exists'),
             ),
+            'check_module_matches' => array(
+                'title' => _t('_adm_txt_modules_check_module_matches'),
+            ),
             'check_module_version' => array(
                 'title' => _t('_adm_txt_modules_check_module_version'),
             ),
@@ -51,6 +54,12 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
                 'result' => false
             ));
 
+		if(isset($aParams['updated_module_name']) && strcmp($aParams['updated_module_name'], $aModuleInfo['name']) != 0)
+			return array_merge($aResult, array(
+                'message' => $this->_displayResult('check_module_matches', false, '_adm_err_modules_module_not_match'),
+                'result' => false
+            ));
+
 		//--- Check Dolphin version compatibility ---//
         if(!$this->_isCompatibleWith())
             return array(