Parcourir la source

#31 - Simultaneous downloading in Store.

AntonLV il y a 12 ans
Parent
commit
745dca367d

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

@@ -525,7 +525,7 @@
 	<string name="_adm_btn_installed_submit"><![CDATA[Installed]]></string>
 	<string name="_adm_btn_login_submit"><![CDATA[Enter Studio]]></string>
 	<string name="_adm_btn_purchase_submit"><![CDATA[Purchase]]></string>
-	<string name="_adm_btn_queued"><![CDATA[Queued]]></string>
+	<string name="_adm_btn_queued_submit"><![CDATA[Queued]]></string>
 	<string name="_adm_btn_settings_save"><![CDATA[Save]]></string>
 	<string name="_adm_dbd_btn_update"><![CDATA[Update]]></string>
 	<string name="_adm_dbd_txt_dolphin_n_available"><![CDATA[Dolphin {0} is available!]]></string>

+ 10 - 6
studio/classes/BxDolStudioInstallerUtils.php

@@ -13,6 +13,10 @@ bx_import('BxDolInstallerUtils');
 define('BX_DOL_UNITY_URL_ROOT', 'http://www.boonex.com/');
 define('BX_DOL_UNITY_URL_MARKET', BX_DOL_UNITY_URL_ROOT . 'market/');
 
+define('BX_DOL_STUDIO_IU_RC_SUCCESS', 0);
+define('BX_DOL_STUDIO_IU_RC_FAILED', 1);
+define('BX_DOL_STUDIO_IU_RC_SCHEDULED', 2);
+
 class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSingleton
 {
 	protected $bUseFtp;
@@ -202,10 +206,10 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     	}
 
     	if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner() && !in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) {
-    		if($this->addTransientJob(self::getNamePerformAction($sDirectory . '_' . $sOperation), 'perform_action', array($sDirectory, $sOperation, $aParams)))
-    			return array('code' => 1, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
+    		if($this->addTransientJob(self::getNamePerformAction($sDirectory), 'perform_action', array($sDirectory, $sOperation, $aParams)))
+    			return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
     		else 
-    			return array('code' => 2, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
+    			return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
     	}
 
     	$sConfigFile = 'install/config.php';
@@ -220,7 +224,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         	if($bTransient)
         		$this->emailNotify($sMessage);
 
-        	return array('code' => 2, 'message' => $sMessage);
+        	return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $sMessage);
         } 
 
 		require_once($sPathInstaller);
@@ -232,7 +236,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 		if(!$aResult['result'] && $bTransient)
 			$this->emailNotify($aResult['message']);
 
-        return array('code' => $aResult['result'] ? 0 : 2, 'message' => $aResult['message']);
+        return array('code' => $aResult['result'] ? BX_DOL_STUDIO_IU_RC_SUCCESS : BX_DOL_STUDIO_IU_RC_FAILED, 'message' => $aResult['message']);
     }
 
     public function checkModules($bAuthorizedAccess = false)
@@ -334,7 +338,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 			if(!$this->addTransientJob(self::getNameDownloadFile($aParams['module_name']), 'download_file_complete', array($sFilePath, $aParams)))
 				return _t('_adm_str_err_download_failed');
 
-			return array('code' => '2', 'message' => _t('_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled'));
+			return array('code' => BX_DOL_STUDIO_IU_RC_SCHEDULED, 'message' => _t('_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled'));
 		}
 
         //--- Unarchive package.

+ 11 - 19
studio/classes/BxDolStudioStore.php

@@ -49,7 +49,7 @@ class BxDolStudioStore extends BxTemplStudioPage
         if(($sAction = bx_get('str_action')) !== false) {
             $sAction = bx_process_input($sAction);
 
-            $aResult = array('code' => 1, 'message' => _t('_adm_mod_err_cannot_process_action'));
+            $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_mod_err_cannot_process_action'));
             switch($sAction) {
                 case 'get-file':
                     $iFileId = (int)bx_get('str_id');
@@ -76,9 +76,9 @@ class BxDolStudioStore extends BxTemplStudioPage
 
                     $sContent = $this->getPageCode();
                     if(!empty($sContent))
-                        $aResult = array('code' => 0, 'content' => $sContent);
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'content' => $sContent);
                     else
-                        $aResult = array('code' => 1, 'message' => _t('_adm_act_err_failed_page_loading'));
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_act_err_failed_page_loading'));
                     break;
 
                 case 'get-products-by-page':
@@ -86,9 +86,9 @@ class BxDolStudioStore extends BxTemplStudioPage
 
                     $sContent = $this->getPageContent();
                     if(!empty($sContent))
-                        $aResult = array('code' => 0, 'content' => $sContent);
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'content' => $sContent);
                     else
-                        $aResult = array('code' => 1, 'message' => _t('_adm_act_err_failed_page_loading'));
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_act_err_failed_page_loading'));
                     break;
 
                 case 'add-to-cart':
@@ -97,13 +97,13 @@ class BxDolStudioStore extends BxTemplStudioPage
                     $iItemCount = 1;
 
                     if(empty($sVendor) || empty($iItem)) {
-                        $aResult = array('code' => 1, 'message' => _t('_adm_err_modules_cannot_add_to_cart'));
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_add_to_cart'));
                         break;
                     }
 
                     bx_import('BxDolStudioCart');
                     BxDolStudioCart::getInstance()->add($sVendor, $iItem, $iItemCount);
-                    $aResult = array('code' => 0, 'message' => _t('_adm_msg_modules_success_added_to_cart'));
+                    $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_msg_modules_success_added_to_cart'));
                     break;
 
                 case 'delete-from-cart':
@@ -111,24 +111,24 @@ class BxDolStudioStore extends BxTemplStudioPage
                     $iItem = (int)bx_get('str_item');
 
                     if(empty($sVendor)) {
-                        $aResult = array('code' => 1, 'message' => _t('_adm_err_modules_cannot_delete_from_cart'));
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_delete_from_cart'));
                         break;
                     }
 
                     bx_import('BxDolStudioCart');
                     BxDolStudioCart::getInstance()->delete($sVendor, $iItem);
-                    $aResult = array('code' => 0, 'message' => '');
+                    $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '');
                     break;
 
                 case 'checkout-cart':
                     $sVendor = bx_process_input(bx_get('str_vendor'));
                     if(empty($sVendor)) {
-                        $aResult = array('code' => 1, 'message' => _t('_adm_err_modules_cannot_checkout_empty_vendor'));
+                        $aResult = array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_err_modules_cannot_checkout_empty_vendor'));
                         break;
                     }
 
                     $sLocation = $this->checkoutCart($sVendor);
-                    $aResult = array('code' => 0, 'message' => '', 'redirect' => $sLocation);
+                    $aResult = array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '', 'redirect' => $sLocation);
                     break;
 
                 case 'install':
@@ -136,7 +136,6 @@ class BxDolStudioStore extends BxTemplStudioPage
                     if(empty($sValue))
                         break;
 
-                    bx_import('BxDolStudioInstallerUtils');
                     $aResult = BxDolStudioInstallerUtils::getInstance()->perform($sValue, 'install', array('auto_enable' => true, 'html_response' => true));
                     break;
 
@@ -145,7 +144,6 @@ class BxDolStudioStore extends BxTemplStudioPage
                     if(empty($sValue))
                         break;
 
-                    bx_import('BxDolStudioInstallerUtils');
                     $aResult = BxDolStudioInstallerUtils::getInstance()->perform($sValue, 'update', array('html_response' => true));
                     break;
 
@@ -154,7 +152,6 @@ class BxDolStudioStore extends BxTemplStudioPage
                     if(empty($sValue))
                         break;
 
-                    bx_import('BxDolStudioInstallerUtils');
                     $aResult = BxDolStudioInstallerUtils::getInstance()->perform($sValue, 'delete', array('html_response' => true));
                     break;
             }
@@ -235,13 +232,11 @@ class BxDolStudioStore extends BxTemplStudioPage
 
     protected function loadPurchases()
     {
-		bx_import('BxDolStudioInstallerUtils');
         return BxDolStudioInstallerUtils::getInstance()->checkModules(true);
     }
 
     protected function loadUpdates()
     {
-    	bx_import('BxDolStudioInstallerUtils');
         return BxDolStudioInstallerUtils::getInstance()->checkUpdates($this->bAuthAccessUpdates);
     }
 
@@ -275,7 +270,6 @@ class BxDolStudioStore extends BxTemplStudioPage
 
     protected function loadDownloaded()
     {
-        bx_import('BxDolStudioInstallerUtils');
         $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
 
         return array(
@@ -297,7 +291,6 @@ class BxDolStudioStore extends BxTemplStudioPage
      */
     protected function loadFile($iFileId)
     {
-        bx_import('BxDolStudioInstallerUtils');
         return BxDolStudioInstallerUtils::getInstance()->downloadFileAuthorized($iFileId);
     }
 
@@ -306,7 +299,6 @@ class BxDolStudioStore extends BxTemplStudioPage
      */
 	protected function loadUpdate($sModuleName, $bAutoUpdate = false)
     {
-        bx_import('BxDolStudioInstallerUtils');
         return BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($sModuleName, $bAutoUpdate);
     }
 

+ 12 - 2
studio/classes/BxDolStudioStoreQuery.php

@@ -16,10 +16,20 @@ class BxDolStudioStoreQuery extends BxDolStudioModulesQuery
         parent::__construct();
     }
 
-    public function isDownloadQueued($sName)
+    public function isQueued($sAction, $sName)
     {
     	bx_import('BxDolStudioInstallerUtils');
-    	$sJobName = BxDolStudioInstallerUtils::getNameDownloadFile($sName);
+
+    	$sJobName = '';
+    	switch($sAction) {
+    		case 'download':
+    			$sJobName = BxDolStudioInstallerUtils::getNameDownloadFile($sName);
+    			break;
+
+    		case 'action':
+    			$sJobName = BxDolStudioInstallerUtils::getNamePerformAction($sName);
+    			break;
+    	}
 
     	$sSql = $this->prepare("SELECT `id` FROM `sys_cron_jobs` WHERE name=? LIMIT 1", $sJobName);
     	return (int)$this->getOne($sSql) > 0;

+ 23 - 9
studio/js/store.js

@@ -183,7 +183,7 @@ BxDolStudioStore.prototype._onGetFile = function(oData, oButton) {
 			$(oButton).removeClass('bx-btn-disabled');
 			break;
 		case 2:
-			$(oButton).val(_t('_adm_btn_queued'));
+			$(oButton).val(_t('_adm_btn_queued_submit'));
 			break;
 	}
 
@@ -266,9 +266,9 @@ BxDolStudioStore.prototype.initScreenshots = function(iCount) {
 
 BxDolStudioStore.prototype.install = function(sValue, oInput) {
 	var $this = this;
-	var onSuccess = function() {
-		$(oInput).parent('.bx-std-pc-buttons').hide(0, function() {
-			$(this).siblings(':hidden').show(0);
+	var onSuccess = function(oData) {
+		$(oInput).parent('.bx-std-pc-buttons:first').hide(0, function() {
+			$(this).siblings('.bx-std-pcb-installed:hidden').show(0);
 		});
 	};
 
@@ -277,7 +277,7 @@ BxDolStudioStore.prototype.install = function(sValue, oInput) {
 
 BxDolStudioStore.prototype.update = function(sValue, oInput) {
 	var $this = this;
-	var onSuccess = function() {
+	var onSuccess = function(oData) {
 		$(oInput).parents('.bx-std-product:first').hide();
 	};
 
@@ -285,8 +285,17 @@ BxDolStudioStore.prototype.update = function(sValue, oInput) {
 };
 
 BxDolStudioStore.prototype.remove = function(sValue, oInput) {
-	var onSuccess = function() {
-		$(oInput).parents('.bx-std-product:first').hide();
+	var onSuccess = function(oData) {
+		switch(parseInt(oData.code)) {
+			case 0:
+				$(oInput).parents('.bx-std-product:first').hide();
+				break;
+			case 2:
+				$(oInput).parent('.bx-std-pc-buttons:first').hide(0, function() {
+					$(this).siblings('.bx-std-pcb-queued:hidden').show(0);
+				});
+				break;
+		}
 	};
 
     return this.perform('delete', sValue, onSuccess);
@@ -314,8 +323,13 @@ BxDolStudioStore.prototype.perform = function(sType, sValue, onSuccess) {
     		if(oData.message.length > 0)
     			$this.showPopup('bx-std-str-popup-' + sType, oData.message);
 
-    		if(oData.code == 0 && typeof onSuccess == 'function')
-    			onSuccess();
+    		switch(parseInt(oData.code)) {
+	    		case 0:
+	    		case 2:
+	    			if(typeof onSuccess == 'function')
+	    				onSuccess(oData);
+	    			break;
+    		}
     	},
     	'json'
     );

+ 24 - 12
studio/template/scripts/BxBaseStudioStore.php

@@ -27,7 +27,7 @@ class BxBaseStudioStore extends BxDolStudioStore
 
     function getPageJs()
     {
-    	BxDolStudioTemplate::getInstance()->addJsTranslation(array('_adm_btn_queued'));
+    	BxDolStudioTemplate::getInstance()->addJsTranslation(array('_adm_btn_queued_submit'));
         return array_merge(parent::getPageJs(), array('jquery.fancybox.pack.js', 'store.js'));
     }
 
@@ -347,6 +347,10 @@ class BxBaseStudioStore extends BxDolStudioStore
         	$sIcon = BxDolStudioUtils::getModuleIcon($aModule, 'store');
         	$bIcon = strpos($sIcon, '.') === false;
 
+        	$bInstalled = $aModule['installed'];
+        	$bQueued = !$bInstalled && $this->oDb->isQueued('action', $aModule['dir']);
+        	
+
             $sModules .= $oTemplate->parseHtmlByName('str_product_v1.html', array(
                 'js_object' => $sJsObject,
              	'name' => $aModule['name'],
@@ -363,11 +367,15 @@ class BxBaseStudioStore extends BxDolStudioStore
                 'version' => $aModule['version'],
                 'dir' => $aModule['dir'],
                 'bx_if:hide_install' => array(
-                    'condition' => $aModule['installed'],
+                    'condition' => $bInstalled || $bQueued,
+                    'content' => array()
+                ),
+                'bx_if:hide_queued' => array(
+                    'condition' => !$bQueued,
                     'content' => array()
                 ),
                 'bx_if:hide_installed' => array(
-                    'condition' => !$aModule['installed'],
+                    'condition' => !$bInstalled || $bQueued,
                     'content' => array()
                 )
             ));
@@ -444,7 +452,7 @@ class BxBaseStudioStore extends BxDolStudioStore
 
         $aProduct = $this->loadProduct($sModuleName);
         if(empty($aProduct) || !is_array($aProduct))
-            return array('code' => 1, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info')));
+            return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($aProduct) ? $aProduct : _t('_adm_str_err_no_product_info')));
 
 		$aDownloaded = $this->getDownloadedModules(false);
 
@@ -522,29 +530,33 @@ class BxBaseStudioStore extends BxDolStudioStore
 			),
         ));
 
-        return array('code' => 0, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
+        return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => '', 'popup' => PopupBox('bx-std-str-popup-product', $aProduct['title'], $sContent, true), 'screenshots' => $iScreenshots);
     }
 
     protected function getFile($iFileId)
     {
         $mixedResult = $this->loadFile($iFileId);
         if($mixedResult === true)
-        	return array('code' => 0, 'message' => _t('_adm_str_msg_download_successfully'));
+        	return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download_successfully'));
 
         if(is_string($mixedResult))
-			return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
+			return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
 
 		if(is_array($mixedResult))
-			return array_merge(array('code' => 1, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
+			return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
     }
 
 	protected function getUpdate($sModuleName, $bAutoUpdate = false)
     {
         $mixedResult = $this->loadUpdate($sModuleName, $bAutoUpdate);
-        if($mixedResult !== true)
-            return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
+        if($mixedResult === true)
+        	return array('code' => BX_DOL_STUDIO_IU_RC_SUCCESS, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
+
+		if(is_string($mixedResult))
+			return array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
 
-        return array('code' => 0, 'message' => _t('_adm_str_msg_download' . ($bAutoUpdate ? '_and_install' : '') . '_successfully'));
+		if(is_array($mixedResult))
+        	return array_merge(array('code' => BX_DOL_STUDIO_IU_RC_FAILED, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
     }
 
     protected function displayProducts($aItems, $aParams = array())
@@ -566,7 +578,7 @@ class BxBaseStudioStore extends BxDolStudioStore
             $bDownloadable = (int)$aItem['is_file'] == 1;
             $bDownloaded = in_array($aItem['name'], $aDownloaded);
             $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
-            $bQueued = $this->oDb->isDownloadQueued($aItem['name']);
+            $bQueued = $this->oDb->isQueued('download', $aItem['name']);
 
             $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free');
             $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : '';

+ 5 - 2
studio/template/str_product_v1.html

@@ -14,11 +14,14 @@
         </div>
         <div class="bx-std-pc-vendor bx-def-margin-thd-top bx-def-font-small">__vendor__ &bull; <span class="bx-std-pc-version">__version__</span></div>
         <div class="bx-std-pc-action bx-def-margin-thd-top">
-        	<div class="bx-std-pc-buttons bx-clearfix" <bx_if:hide_install>style="display:none"</bx_if:hide_install>>
+        	<div class="bx-std-pc-buttons bx-std-pcb-install bx-clearfix" <bx_if:hide_install>style="display:none"</bx_if:hide_install>>
         		<input class="bx-btn bx-btn-small bx-def-margin-sec-left-auto" type="button" value="<bx_text:_adm_btn_install_submit />" onclick="javascript:__js_object__.install('__dir__', this)" />
         		<input class="bx-btn bx-btn-small bx-def-margin-sec-left-auto" type="button" value="<bx_text:_adm_btn_delete_submit />" onclick="javascript:__js_object__.remove('__dir__', this)" />
         	</div>
-        	<div class="bx-std-pc-buttons bx-clearfix" <bx_if:hide_installed>style="display:none"</bx_if:hide_installed>>
+        	<div class="bx-std-pc-buttons bx-std-pcb-queued bx-clearfix" <bx_if:hide_queued>style="display:none"</bx_if:hide_queued>>
+            	<input class="bx-btn bx-btn-small bx-btn-disabled" type="button" value="<bx_text:_adm_btn_queued_submit />" />
+            </div>
+            <div class="bx-std-pc-buttons bx-std-pcb-installed bx-clearfix" <bx_if:hide_installed>style="display:none"</bx_if:hide_installed>>
             	<input class="bx-btn bx-btn-small bx-btn-disabled" type="button" value="<bx_text:_adm_btn_installed_submit />" />
             </div>
         </div>