Kaynağa Gözat

#31 - Simultaneous downloading in Store.

AntonLV 12 yıl önce
ebeveyn
işleme
c75f9045c0

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

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

+ 21 - 7
studio/classes/BxDolStudioInstallerUtils.php

@@ -49,6 +49,16 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $GLOBALS['bxDolClasses'][__CLASS__];
         return $GLOBALS['bxDolClasses'][__CLASS__];
     }
     }
 
 
+    public static function getNamePerformAction($sParam)
+    {
+    	return 'sys_perform_action_' . md5($sParam);
+    }
+
+    public static function getNameDownloadFile($sParam)
+    {
+    	return 'sys_download_file_complete_' . $sParam;
+    }
+
     /*
     /*
      * Is used to complete Downloading inside Transient Cron Job.
      * Is used to complete Downloading inside Transient Cron Job.
      */
      */
@@ -192,7 +202,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     	}
     	}
 
 
     	if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner() && !in_array($sOperation, array('install', 'uninstall', 'enable', 'disable'))) {
     	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)))
+    		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'));
     			return array('code' => 1, 'message' => _t('_adm_mod_msg_process_operation_scheduled'));
     		else 
     		else 
     			return array('code' => 2, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
     			return array('code' => 2, 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory));
@@ -275,7 +285,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     {
     {
 		$aItem = $this->getAccessObject(true)->loadItems(array('dol_type' => 'product_file', 'dol_file_id' => $iFileId));
 		$aItem = $this->getAccessObject(true)->loadItems(array('dol_type' => 'product_file', 'dol_file_id' => $iFileId));
 
 
-		return $this->downloadFileInit($aItem);
+		return $this->downloadFileInit($aItem, array('module_name' => $aItem['module_name']));
     }
     }
 
 
     public function downloadUpdatePublic($sModuleName, $bAutoUpdate = false)
     public function downloadUpdatePublic($sModuleName, $bAutoUpdate = false)
@@ -292,7 +302,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
 			))),
 			))),
 		));
 		));
 
 
-		return $this->downloadFileInit($aItem, array('updated_module_name' => $sModuleName, 'auto_action' => $bAutoUpdate ? 'update' : ''));
+		return $this->downloadFileInit($aItem, array('module_name' => $sModuleName, 'auto_action' => $bAutoUpdate ? 'update' : ''));
     }
     }
 
 
     protected function downloadFileInit($aItem, $aParams = array())
     protected function downloadFileInit($aItem, $aParams = array())
@@ -320,8 +330,12 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
     	$sAutoAction = isset($aParams['auto_action']) ? $aParams['auto_action'] : '';
     	$sAutoAction = isset($aParams['auto_action']) ? $aParams['auto_action'] : '';
     	$bAutoAction = !empty($sAutoAction);
     	$bAutoAction = !empty($sAutoAction);
 
 
-		if(!defined('BX_DOL_CRON_EXECUTE') && !self::isRealOwner())
-			return _t($this->addTransientJob('download_file_complete', array($sFilePath, $aParams)) ? '_adm_str_msg_download' . ($bAutoAction ? '_and_install' : '') . '_scheduled' : '_adm_str_err_download_failed');
+		if(!defined('BX_DOL_CRON_EXECUTE') && self::isRealOwner()) {
+			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'));
+		}
 
 
         //--- Unarchive package.
         //--- Unarchive package.
         $sPackagePath = '';
         $sPackagePath = '';
@@ -507,10 +521,10 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $aInstalledInfo;
         return $aInstalledInfo;
     }
     }
 
 
-    private function addTransientJob($sAction, $aParams)
+    private function addTransientJob($sName, $sAction, $aParams)
     {
     {
 		bx_import('BxDolCronQuery');
 		bx_import('BxDolCronQuery');
-		if(BxDolCronQuery::getInstance()->addTransientJobService('sys_' . $sAction, array('system', $sAction, $aParams, 'DolStudioInstallerUtils')))
+		if(BxDolCronQuery::getInstance()->addTransientJobService($sName, array('system', $sAction, $aParams, 'DolStudioInstallerUtils')))
 			return true;
 			return true;
 
 
 		return false;
 		return false;

+ 9 - 0
studio/classes/BxDolStudioStoreQuery.php

@@ -15,6 +15,15 @@ class BxDolStudioStoreQuery extends BxDolStudioModulesQuery
     {
     {
         parent::__construct();
         parent::__construct();
     }
     }
+
+    public function isDownloadQueued($sName)
+    {
+    	bx_import('BxDolStudioInstallerUtils');
+    	$sJobName = BxDolStudioInstallerUtils::getNameDownloadFile($sName);
+
+    	$sSql = $this->prepare("SELECT `id` FROM `sys_cron_jobs` WHERE name=? LIMIT 1", $sJobName);
+    	return (int)$this->getOne($sSql) > 0;
+    }
 }
 }
 
 
 /** @} */
 /** @} */

+ 1 - 1
studio/classes/BxDolStudioUpdater.php

@@ -54,7 +54,7 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
                 'result' => false
                 'result' => false
             ));
             ));
 
 
-		if(isset($aParams['updated_module_name']) && strcmp($aParams['updated_module_name'], $aModuleInfo['name']) != 0)
+		if(isset($aParams['module_name']) && strcmp($aParams['module_name'], $aModuleInfo['name']) != 0)
 			return array_merge($aResult, array(
 			return array_merge($aResult, array(
                 'message' => $this->_displayResult('check_module_matches', false, '_adm_err_modules_module_not_match', $bHtmlResponce),
                 'message' => $this->_displayResult('check_module_matches', false, '_adm_err_modules_module_not_match', $bHtmlResponce),
                 'result' => false
                 'result' => false

+ 9 - 2
studio/js/store.js

@@ -177,8 +177,15 @@ BxDolStudioStore.prototype._getFile = function(sAction, mixedId, onResult, oButt
 
 
 BxDolStudioStore.prototype._onGetFile = function(oData, oButton) {
 BxDolStudioStore.prototype._onGetFile = function(oData, oButton) {
 	bx_loading(this.sIdPageContent, false);
 	bx_loading(this.sIdPageContent, false);
-	if(oData.code != 0)
-		$(oButton).removeClass('bx-btn-disabled');
+
+	switch(parseInt(oData.code)) {
+		case 1:
+			$(oButton).removeClass('bx-btn-disabled');
+			break;
+		case 2:
+			$(oButton).val(_t('_adm_btn_queued'));
+			break;
+	}
 
 
 	if(oData.message)
 	if(oData.message)
 		this.showPopup(this.sIdPopupFile, oData.message, oButton);
 		this.showPopup(this.sIdPopupFile, oData.message, oButton);

+ 15 - 5
studio/template/scripts/BxBaseStudioStore.php

@@ -27,6 +27,7 @@ class BxBaseStudioStore extends BxDolStudioStore
 
 
     function getPageJs()
     function getPageJs()
     {
     {
+    	BxDolStudioTemplate::getInstance()->addJsTranslation(array('_adm_btn_queued'));
         return array_merge(parent::getPageJs(), array('jquery.fancybox.pack.js', 'store.js'));
         return array_merge(parent::getPageJs(), array('jquery.fancybox.pack.js', 'store.js'));
     }
     }
 
 
@@ -527,10 +528,14 @@ class BxBaseStudioStore extends BxDolStudioStore
     protected function getFile($iFileId)
     protected function getFile($iFileId)
     {
     {
         $mixedResult = $this->loadFile($iFileId);
         $mixedResult = $this->loadFile($iFileId);
-        if($mixedResult !== true)
-            return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
+        if($mixedResult === true)
+        	return array('code' => 0, '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' => 0, 'message' => _t('_adm_str_msg_download_successfully'));
+		if(is_array($mixedResult))
+			return array_merge(array('code' => 1, 'message' => _t('_adm_str_err_download_failed')), $mixedResult);
     }
     }
 
 
 	protected function getUpdate($sModuleName, $bAutoUpdate = false)
 	protected function getUpdate($sModuleName, $bAutoUpdate = false)
@@ -561,6 +566,7 @@ class BxBaseStudioStore extends BxDolStudioStore
             $bDownloadable = (int)$aItem['is_file'] == 1;
             $bDownloadable = (int)$aItem['is_file'] == 1;
             $bDownloaded = in_array($aItem['name'], $aDownloaded);
             $bDownloaded = in_array($aItem['name'], $aDownloaded);
             $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
             $bDownload = !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable;
+            $bQueued = $this->oDb->isDownloadQueued($aItem['name']);
 
 
             $sPrice = !$bFree ? _t('_adm_str_txt_price_csign', $aItem['currency_sign'], $aItem['price']) : _t('_adm_str_txt_price_free');
             $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']) : '';
             $sDiscount = !$bFree && !empty($aItem['discount']) ? _t('_adm_str_txt_discount_csign', $aItem['currency_sign'], $aItem['discount']['price']) : '';
@@ -607,14 +613,18 @@ class BxBaseStudioStore extends BxDolStudioStore
                     )
                     )
                 ),
                 ),
                 'bx_if:show_download' => array(
                 'bx_if:show_download' => array(
-                    'condition' => $bDownload && !$bDownloaded,
+                    'condition' => $bDownload && !$bQueued && !$bDownloaded,
                     'content' => array(
                     'content' => array(
                         'js_object' => $sJsObject,
                         'js_object' => $sJsObject,
                         'file_id' => $aItem['file_id']
                         'file_id' => $aItem['file_id']
                     )
                     )
                 ),
                 ),
                 'bx_if:show_download_disabled' => array(
                 'bx_if:show_download_disabled' => array(
-					'condition' => $bDownload && $bDownloaded,
+					'condition' => $bDownload && !$bQueued && $bDownloaded,
+					'content' => array()
+				),
+				'bx_if:show_queued_disabled' => array(
+					'condition' => $bDownload && $bQueued && !$bDownloaded,
 					'content' => array()
 					'content' => array()
 				),
 				),
                 'bx_if:show_delete' => array(
                 'bx_if:show_delete' => array(

+ 3 - 0
studio/template/str_product_v2.html

@@ -28,6 +28,9 @@
             <bx_if:show_download_disabled>
             <bx_if:show_download_disabled>
             	<input class="bx-btn bx-btn-small bx-btn-disabled bx-std-pc-download" type="button" value="<bx_text:_adm_btn_download_submit />" disabled="disabled" />
             	<input class="bx-btn bx-btn-small bx-btn-disabled bx-std-pc-download" type="button" value="<bx_text:_adm_btn_download_submit />" disabled="disabled" />
             </bx_if:show_download_disabled>
             </bx_if:show_download_disabled>
+            <bx_if:show_queued_disabled>
+            	<input class="bx-btn bx-btn-small bx-btn-disabled bx-std-pc-queued" type="button" value="<bx_text:_adm_btn_queued />" disabled="disabled" />
+            </bx_if:show_queued_disabled>
             <bx_if:show_delete>
             <bx_if:show_delete>
             	<input class="bx-btn bx-btn-small bx-std-pc-delete" type="button" value="<bx_text:_adm_btn_delete_submit />" onclick="javascript:__js_object__.deleteFromCart('__vendor__', __id__, this)" />
             	<input class="bx-btn bx-btn-small bx-std-pc-delete" type="button" value="<bx_text:_adm_btn_delete_submit />" onclick="javascript:__js_object__.deleteFromCart('__vendor__', __id__, this)" />
             </bx_if:show_delete>
             </bx_if:show_delete>