Procházet zdrojové kódy

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

AntonLV před 12 roky
rodič
revize
e0e9b1e401

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

@@ -1176,8 +1176,10 @@
 	<string name="_adm_str_err_no_product_info"><![CDATA[Cannot load product info. Try again later.]]></string>
 	<string name="_adm_str_err_wrong_package_format"><![CDATA[Wrong package format.]]></string>
 	<string name="_adm_str_err_zip_not_available"><![CDATA[ZIP library is not available.]]></string>
-	<string name="_adm_str_msg_download_scheduled"><![CDATA[Download was scheduled. In a few minutes downloaded package will be available to install via Store -> Downloaded.]]></string>
-	<string name="_adm_str_msg_download_successfully"><![CDATA[Download was successfully finished. You may install it via Store -> Downloaded.]]></string>
+	<string name="_adm_str_msg_download_scheduled"><![CDATA[Download was scheduled. In a few minutes downloaded package will be available to install via Extensions -> Downloaded.]]></string>
+	<string name="_adm_str_msg_download_and_install_scheduled"><![CDATA[Download and subsequent installation were scheduled. It may take a few minutes.]]></string>
+	<string name="_adm_str_msg_download_successfully"><![CDATA[Download was successfully finished. You may install it via Extensions -> Downloaded.]]></string>
+	<string name="_adm_str_msg_download_and_install_successfully"><![CDATA[Download and subsequent installation were successfully finished.]]></string>
 	<string name="_adm_str_txt_discount_csign"><![CDATA[({0}{1} for Premium)]]></string>
 	<string name="_adm_str_txt_items_by"><![CDATA[item(s) by]]></string>
 	<string name="_adm_str_txt_price_csign"><![CDATA[{0}{1}]]></string>

+ 27 - 12
studio/classes/BxDolStudioInstallerUtils.php

@@ -15,12 +15,16 @@ define('BX_DOL_UNITY_URL_MARKET', BX_DOL_UNITY_URL_ROOT . 'market/');
 
 class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSingleton
 {
+	protected $bUseFtp;
+
     public function __construct()
     {
         if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
             trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
 
         parent::__construct();
+
+        $this->bUseFtp = BX_FORCE_USE_FTP_FILE_TRANSFER;
     }
 
     /**
@@ -43,9 +47,9 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $GLOBALS['bxDolClasses'][__CLASS__];
     }
 
-    public function serviceDownloadFileComplete($sFilePath)
+    public function serviceDownloadFileComplete($sFilePath, $sAutoAction = '')
     {
-    	return $this->downloadFileComplete($sFilePath);
+    	return $this->downloadFileComplete($sFilePath, $sAutoAction);
     }
 
 	public function servicePerformAction($sDirectory, $sOperation, $aParams)
@@ -254,7 +258,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 		return $this->downloadFileInit($aItem);
     }
 
-    public function downloadUpdatePublic($sModuleName)
+    public function downloadUpdatePublic($sModuleName, $bAutoUpdate = false)
     {
     	bx_import('BxDolModuleQuery');
 		$aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModuleName);
@@ -269,10 +273,10 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 			))),
 		));
 
-		return $this->downloadFileInit($aItem);
+		return $this->downloadFileInit($aItem, $bAutoUpdate ? 'update' : '');
     }
 
-    protected function downloadFileInit($aItem)
+    protected function downloadFileInit($aItem, $sAutoAction = '')
     {
     	if(empty($aItem) || !is_array($aItem))
 			return $aItem;
@@ -283,13 +287,14 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         if($mixedResult !== true)
         	return $mixedResult;
 
-		return $this->downloadFileComplete($sFilePath);
+		return $this->downloadFileComplete($sFilePath, $sAutoAction);
     }
 
-    protected function downloadFileComplete($sFilePath, $bUseFtp = BX_FORCE_USE_FTP_FILE_TRANSFER)
+    protected function downloadFileComplete($sFilePath, $sAutoAction = '')
     {
+    	$bAutoAction = !empty($sAutoAction);
 		if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner())
-			return _t($this->addTransientJob('download_file_complete', array($sFilePath)) ? '_adm_str_msg_download_scheduled' : '_adm_str_err_download_failed');
+			return _t($this->addTransientJob('download_file_complete', array($sFilePath, $sAutoAction)) ? '_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled' : '_adm_str_err_download_failed');
 
         //--- Unarchive package.
         $sPackagePath = '';
@@ -300,12 +305,21 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         	return $mixedResult;
 
         //--- Copy unarchived package.
-        $mixedResult = $this->performCopy($sPackagePath, $bUseFtp);
+        $sHomePath = '';
+        $mixedResult = $this->performCopy($sPackagePath, $sHomePath);
 
         @bx_rrmdir($sPackagePath);
         if($mixedResult !== true)
         	return $mixedResult;
 
+		if(!$bAutoAction)
+			 return true;
+
+		//--- Autoinstall the downloaded package if it's needed.
+		$aResult = $this->perform($sHomePath, $sAutoAction);
+		if((int)$aResult['code'] != 0)
+			return $aResult['message'];
+
         return true;
     }
 
@@ -361,9 +375,9 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return true;
     }
 
-    protected function performCopy($sPackagePath, $bUseFtp)
+    protected function performCopy($sPackagePath, &$sHomePath)
     {
-    	if($bUseFtp) {
+    	if($this->bUseFtp) {
 	        $sLogin = getParam('sys_ftp_login');
 	        $sPassword = getParam('sys_ftp_password');
 	        $sPath = getParam('sys_ftp_dir');
@@ -388,7 +402,8 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         if(empty($aConfig) || !is_array($aConfig) || empty($aConfig['home_dir']))
             return _t('_adm_str_err_wrong_package_format');
 
-        if(!$oFile->copy($sPackagePath, 'modules/' . $aConfig['home_dir']))
+		$sHomePath = $aConfig['home_dir'];
+        if(!$oFile->copy($sPackagePath, 'modules/' . $sHomePath))
             return _t('_adm_str_err_files_copy_failed');
 
 		return true;

+ 7 - 2
studio/classes/BxDolStudioStore.php

@@ -73,6 +73,11 @@ class BxDolStudioStore extends BxTemplStudioPage
                 case 'get-update':
                     $sModuleName = bx_process_input(bx_get('str_id'));
                     $aResult = $this->getUpdate($sModuleName);
+                    break;
+
+				case 'get-update-and-install':
+                    $sModuleName = bx_process_input(bx_get('str_id'));
+                    $aResult = $this->getUpdate($sModuleName, true);
                     break;
 
                 case 'get-products-by-type':
@@ -317,10 +322,10 @@ class BxDolStudioStore extends BxTemplStudioPage
     /*
      * Load update's package publicly.
      */
-	protected function loadUpdate($sModuleName)
+	protected function loadUpdate($sModuleName, $bAutoUpdate = false)
     {
         bx_import('BxDolStudioInstallerUtils');
-        return BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($sModuleName);
+        return BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($sModuleName, $bAutoUpdate);
     }
 
     private function checkoutCart($sVendor)

+ 5 - 3
studio/js/store.js

@@ -138,15 +138,17 @@ BxDolStudioStore.prototype.getUpdateAndInstall = function(sModuleName, oButton)
 	var $this = this;
 
 	var onResult = function(oData, oButton) {
-		if(oData.code != 0 || !oData.path) {
+		if(oData.code != 0) {
 			$this._onGetFile(oData, oButton);
 			return;
 		}
 
-		$this.update(oData.path, oButton);
+		bx_loading($this.sIdPageContent, false);
+
+		$(oButton).parents('.bx-std-product:first').hide();
 	};
 
-	this._getFile('get-update', sModuleName, onResult, oButton);
+	this._getFile('get-update-and-install', sModuleName, onResult, oButton);
 };
 
 BxDolStudioStore.prototype._getFile = function(sAction, mixedId, onResult, oButton) {

+ 3 - 6
studio/template/scripts/BxBaseStudioStore.php

@@ -546,16 +546,13 @@ class BxBaseStudioStore extends BxDolStudioStore
         return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully'));
     }
 
-	protected function getUpdate($sModuleName)
+	protected function getUpdate($sModuleName, $bAutoUpdate = false)
     {
-        $mixedResult = $this->loadUpdate($sModuleName);
+        $mixedResult = $this->loadUpdate($sModuleName, $bAutoUpdate);
         if($mixedResult !== true)
             return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
 
-		bx_import('BxDolStudioInstallerUtils');
-		$aUpdate = BxDolStudioInstallerUtils::getInstance()->getUpdate($sModuleName);
-
-        return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully'), 'path' => $aUpdate['dir']);
+        return array('code' => 0, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
     }
 
     protected function displayProducts($aItems, $aParams = array())