Przeglądaj źródła

#73 - Modules autoupdate

AntonLV 12 lat temu
rodzic
commit
ed76c6e8b3

+ 1 - 3
inc/classes/BxDolInstallerHasher.php

@@ -79,9 +79,7 @@ class BxDolInstallerHasher extends BxDolInstallerUtils
     public function checkSystemFilesHash (&$fChangedFilesPercent) 
     {
         $aFiles = $this->getSystemFilesHash ();
-        $aFilesChanged = $this->hashCheck($aFiles, BX_SYSTEM_MODULE_ID);
-        if (null !== $fChangedFilesPercent && 0 != count($aFiles))
-            $fChangedFilesPercent = count($aFilesChanged) / count($aFiles);
+        list($aFilesChanged, $fChangedFilesPercent) = $this->hashCheck($aFiles, BX_SYSTEM_MODULE_ID);
         return $aFilesChanged;
     }
 }

+ 13 - 12
inc/classes/BxDolInstallerUtils.php

@@ -6,9 +6,10 @@
  * @defgroup    DolphinCore Dolphin Core
  * @{
  */
-
 bx_import('BxDolIO');
 
+define('BX_FORCE_AUTOUPDATE_MAX_CHANGED_FILES_PERCENT', 0.05);
+
 class BxDolInstallerUtils extends BxDolIO
 {
     protected $_aNonHashableFiles = array();
@@ -154,23 +155,23 @@ class BxDolInstallerUtils extends BxDolIO
      * @param $iModuleId module id
      * @return empty array on success, or array of files which checksum was changed 
      */
-    public function hashCheck($aFiles, $iModuleId, $bBreakOnFirstError = false)
+    public function hashCheck($aFiles, $iModuleId)
     {
         $oDb = bx_instance('BxDolStudioInstallerQuery');
 
         $aFilesOrig = $oDb->getModuleTrackFiles($iModuleId);
-        $aFailedFailes = array();
-        foreach ($aFiles as $aFile) {
-            if (!isset($aFilesOrig[$aFile['file']]) || $aFilesOrig[$aFile['file']]['hash'] != $aFile['hash']) {
-                $aFailedFailes[] = $aFile['file'];
-                if ($bBreakOnFirstError)
-                    return $aFailedFailes;
-            }
-        }
+        $aFailesChanged = array();
+        foreach ($aFiles as $aFile)
+            if(!isset($aFilesOrig[$aFile['file']]) || $aFilesOrig[$aFile['file']]['hash'] != $aFile['hash'])
+                $aFailesChanged[] = $aFile['file'];
 
-        return $aFailedFailes;
-    }
+		$fChangedPercent = 0;
+        if(count($aFilesOrig) != 0)
+            $fChangedPercent = count($aFailesChanged) / count($aFilesOrig);
 
+        return array($aFailesChanged, $fChangedPercent);
+    }
+    
     protected function hashInfo($sPath)
     {
         return array(

+ 0 - 2
inc/classes/BxDolUpgrader.php

@@ -7,8 +7,6 @@
  * @{
  */
 
-define('BX_FORCE_AUTOUPDATE_MAX_CHANGED_FILES_PERCENT', 0.05);
-
 class BxDolUpgrader extends BxDol
 {
     protected $_sUrlVersionCheck = 'http://rss.boonex.com/u/';

+ 1 - 0
install/sql/system.sql

@@ -1008,6 +1008,7 @@ CREATE TABLE `sys_cron_jobs` (
 INSERT INTO `sys_cron_jobs` (`name`, `time`, `class`, `file`, `service_call`) VALUES
 ('pruning', '0 0 * * *', 'BxDolCronPruning', 'inc/classes/BxDolCronPruning.php', ''),
 ('sys_upgrade', '0 3 * * *', 'BxDolCronUpgradeCheck', 'inc/classes/BxDolCronUpgradeCheck.php', ''),
+('sys_upgrade_modules', '0 6 * * *', 'BxDolCronUpgradeModulesCheck', 'inc/classes/BxDolCronUpgradeModulesCheck.php', ''),
 ('sys_storage', '* * * * *', 'BxDolCronStorage', 'inc/classes/BxDolCronStorage.php', '');
 
 -- --------------------------------------------------------

+ 2 - 2
studio/classes/BxDolStudioInstaller.php

@@ -488,8 +488,8 @@ class BxDolStudioInstaller extends BxDolInstallerUtils
     function _displayResult($sAction, $bResult, $sResult = '')
     {
         $sMessage = $this->_aActions[$sAction]['title'] . ' ';
-        if(!empty($sResult) && substr($sResult, 0, 1) == '_')
-            $sResult = _t($sResult) . '<br />';
+        if(!empty($sResult))
+            $sResult = (substr($sResult, 0, 1) == '_' ? _t($sResult) : $sResult) . '<br />';
 
         if(!$bResult)
             return $sMessage . '<span style="color:red;">' . $sResult . '</span>';

+ 129 - 6
studio/classes/BxDolStudioInstallerUtils.php

@@ -9,6 +9,9 @@
 
 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/');
+
 class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSingleton
 {
     public function __construct()
@@ -59,7 +62,8 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
                 'code' => $aResult['result'] ? 0 : 1,
                 'message' => $aResult['message'],
             );
-        } else
+        } 
+        else
             $aResult = array(
                 'code' => 2,
                 'message' => _t('_adm_mod_err_process_operation_failed', $sOperation, $sDirectory),
@@ -68,7 +72,7 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $aResult;
     }
 
-    public function loadModules()
+    public function getModules()
     {
         $aModules = array();
         $oTemplate = BxDolStudioTemplate::getInstance();
@@ -104,26 +108,28 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $aModules;
     }
 
-    public function loadUpdates()
+    public function getUpdates()
     {
         $aUpdates = array();
+
+        bx_import('BxDolStudioTemplate');
         $oTemplate = BxDolStudioTemplate::getInstance();
 
         $aInstalledPathes = $aInstalledInfo = array();
         $this->getInstalledInfo($aInstalledPathes, $aInstalledInfo);
 
         $sPath = BX_DIRECTORY_PATH_MODULES;
-        if($rHandleVendor = opendir($sPath)) {
+        if(($rHandleVendor = opendir($sPath)) !== false) {
             while(($sVendor = readdir($rHandleVendor)) !== false) {
                 if(substr($sVendor, 0, 1) == '.' || !is_dir($sPath . $sVendor))
                     continue;
 
-                if($rHandleModule = opendir($sPath . $sVendor . '/')) {
+                if(($rHandleModule = opendir($sPath . $sVendor . '/')) !== false) {
                     while(($sModule = readdir($rHandleModule)) !== false) {
                         if(!is_dir($sPath . $sVendor . '/' . $sModule) || substr($sModule, 0, 1) == '.')
                             continue;
 
-                        if($rHandleUpdate = @opendir($sPath . $sVendor . '/' . $sModule . '/updates/')) {
+                        if(($rHandleUpdate = @opendir($sPath . $sVendor . '/' . $sModule . '/updates/')) !== false) {
                             while(($sUpdate = readdir($rHandleUpdate)) !== false) {
                                 if(!is_dir($sPath . $sVendor . '/' . $sModule . '/updates/' . $sUpdate) || substr($sUpdate, 0, 1) == '.')
                                     continue;
@@ -149,6 +155,123 @@ class BxDolStudioInstallerUtils extends BxDolInstallerUtils implements iBxDolSin
         return $aUpdates;
     }
 
+    public function checkUpdates($bAuthorizedAccess = false)
+    {
+		bx_import('BxDolModuleQuery');
+        $aModules = BxDolModuleQuery::getInstance()->getModules();
+
+        $aProducts = array();
+        foreach($aModules as $aModule) {
+            if(empty($aModule['name']) || empty($aModule['hash']))
+                continue;
+
+            $aProducts[] = array(
+                'name' => $aModule['name'],
+                'version' => $aModule['version'],
+            	'hash' => $aModule['hash'],
+            );
+        }
+        $sProducts = base64_encode(serialize($aProducts));
+
+        if($bAuthorizedAccess) {
+	        bx_import('BxDolStudioOAuth');
+	        return BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'available_updates', 'dol_products' => $sProducts));
+        }
+
+		bx_import('BxDolStudioJson');
+		return BxDolStudioJson::getInstance()->load(BX_DOL_UNITY_URL_MARKET . 'json_browse_updates', array(
+			'products' => $sProducts,
+			'domain' => BX_DOL_URL_ROOT,
+			'user' => (int)getParam('sys_oauth_user') 
+		));
+    }
+
+    public function downloadFileAuthorized($iFileId)
+    {
+    	bx_import('BxDolStudioOAuth');
+		$aItem = BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'product_file', 'dol_file_id' => $iFileId));
+
+		return $this->downloadFile($aItem);
+    }
+
+    public function downloadUpdatePublic($sModuleName)
+    {
+    	bx_import('BxDolModuleQuery');
+		$aModule = BxDolModuleQuery::getInstance()->getModuleByName($sModuleName);
+
+		bx_import('BxDolStudioJson');
+		$aItem = BxDolStudioJson::getInstance()->load(BX_DOL_UNITY_URL_MARKET . 'json_download_update', array(
+			'product' => base64_encode(serialize(array(
+				'name' => $aModule['name'],
+	            'version' => $aModule['version'],
+	            'hash' => $aModule['hash'],
+			))),
+			'domain' => BX_DOL_URL_ROOT,
+			'user' => (int)getParam('sys_oauth_user') 
+		));
+
+		return $this->downloadFile($aItem);
+    }
+
+    protected function downloadFile($aItem)
+    {
+        if(empty($aItem) || !is_array($aItem))
+            return $aItem;
+
+        //--- write ZIP archive.
+        $sFilePath = BX_DIRECTORY_PATH_TMP . $aItem['name'];
+        if (!$rHandler = fopen($sFilePath, 'w'))
+            return _t('_adm_str_err_cannot_write');
+
+        if (!fwrite($rHandler, urldecode($aItem['content'])))
+            return _t('_adm_str_err_cannot_write');
+
+        fclose($rHandler);
+
+        //--- Unarchive package.
+        if(!class_exists('ZipArchive'))
+            return _t('_adm_str_err_zip_not_available');
+
+        $oZip = new ZipArchive();
+        if($oZip->open($sFilePath) !== true)
+            return _t('_adm_str_err_cannot_unzip_package');
+
+        $sPackageRootFolder = $oZip->numFiles > 0 ? $oZip->getNameIndex(0) : false;
+        if($sPackageRootFolder && file_exists(BX_DIRECTORY_PATH_TMP . $sPackageRootFolder)) // remove existing tmp folder with the same name
+            bx_rrmdir(BX_DIRECTORY_PATH_TMP . $sPackageRootFolder);
+
+        if($sPackageRootFolder && !$oZip->extractTo(BX_DIRECTORY_PATH_TMP))
+            return _t('_adm_str_err_cannot_unzip_package');
+
+        $oZip->close();
+
+        //--- Move unarchived package.
+        $sLogin = getParam('sys_ftp_login');
+        $sPassword = getParam('sys_ftp_password');
+        $sPath = getParam('sys_ftp_dir');
+        if(empty($sLogin) || empty($sPassword) || empty($sPath))
+            return _t('_adm_str_err_no_ftp_info');
+
+        bx_import('BxDolFtp');
+        $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
+
+        if(!$oFtp->connect())
+            return _t('_adm_str_err_cannot_connect_to_ftp');
+
+        if(!$oFtp->isDolphin())
+            return _t('_adm_str_err_destination_not_valid');
+
+        $sConfigPath = BX_DIRECTORY_PATH_TMP . $sPackageRootFolder . '/install/config.php';
+        if(!file_exists($sConfigPath))
+            return _t('_adm_str_err_wrong_package_format');
+
+		$aConfig = self::getModuleConfig($sConfigPath);
+        if(empty($aConfig) || empty($aConfig['home_dir']) || !$oFtp->copy(BX_DIRECTORY_PATH_TMP . $sPackageRootFolder . '/', 'modules/' . $aConfig['home_dir']))
+            return _t('_adm_str_err_ftp_copy_failed');
+
+        return true;
+    }
+
     protected function getConfigModule($sConfigPath, $aInstalledPathes = array(), $aInstalledInfo = array())
     {
     	$aConfig = self::getModuleConfig($sConfigPath);

+ 1 - 2
studio/classes/BxDolStudioOAuth.php

@@ -7,8 +7,7 @@
  * @{
  */
 
-define('BX_DOL_UNITY_URL_ROOT', 'http://www.boonex.com/');
-define('BX_DOL_UNITY_URL_MARKET', BX_DOL_UNITY_URL_ROOT . 'market/');
+bx_import('BxDolStudioInstallerUtils');
 
 define('BX_DOL_OAUTH_URL_REQUEST_TOKEN', BX_DOL_UNITY_URL_ROOT . 'scripts_public/oauth_request_token.php5');
 define('BX_DOL_OAUTH_URL_AUTHORIZE', BX_DOL_UNITY_URL_ROOT . 'scripts_public/oauth_authorize.php5');

+ 30 - 91
studio/classes/BxDolStudioStore.php

@@ -8,8 +8,8 @@
  */
 
 bx_import('BxTemplStudioPage');
-bx_import('BxDolStudioOAuth');
 bx_import('BxDolStudioStoreQuery');
+bx_import('BxDolStudioInstallerUtils');
 
 define('BX_DOL_STUDIO_STR_TYPE_DEFAULT', 'downloaded');
 
@@ -21,6 +21,7 @@ class BxDolStudioStore extends BxTemplStudioPage
     protected $iClient;
 
     protected $aAlias;
+    protected $bAuthAccessUpdates;
 
     function __construct($sPage = "")
     {
@@ -35,11 +36,13 @@ class BxDolStudioStore extends BxTemplStudioPage
             ),
             'category' => array()
         );
+        $this->bAuthAccessUpdates = false;
 
         $this->sPage = BX_DOL_STUDIO_STR_TYPE_DEFAULT;
         if(is_string($sPage) && !empty($sPage))
             $this->sPage = $sPage;
 
+		bx_import('BxDolStudioOAuth');
         $this->iClient = BxDolStudioOAuth::getAuthorizedClient();
 
         //--- Check actions ---//
@@ -58,8 +61,8 @@ class BxDolStudioStore extends BxTemplStudioPage
                     break;
 
                 case 'get-file':
-                    $iId = (int)bx_get('str_id');
-                    $aResult = $this->getFile($iId);
+                    $iFileId = (int)bx_get('str_id');
+                    $aResult = $this->getFile($iFileId);
                     break;
 
                 case 'get-product':
@@ -67,6 +70,11 @@ class BxDolStudioStore extends BxTemplStudioPage
                     $aResult = $this->getProduct($iId);
                     break;
 
+                case 'get-update':
+                    $sModuleName = bx_process_input(bx_get('str_id'));
+                    $aResult = $this->getUpdate($sModuleName);
+                    break;
+
                 case 'get-products-by-type':
                     $this->sPage = bx_process_input(bx_get('str_value'));
 
@@ -241,36 +249,10 @@ class BxDolStudioStore extends BxTemplStudioPage
         return $aProducts;
     }
 
-    protected function loadUpdates($bAuthorizedLoading = false)
+    protected function loadUpdates()
     {
-        bx_import('BxDolModuleQuery');
-        $oModules = BxDolModuleQuery::getInstance();
-        $aModules = $oModules->getModules();
-
-        $aProducts = array();
-        foreach($aModules as $aModule) {
-            if(empty($aModule['name']) || empty($aModule['hash']))
-                continue;
-
-            $aProducts[] = array(
-                'name' => $aModule['name'],
-                'version' => $aModule['version'],
-            	'hash' => $aModule['hash'],
-            );
-        }
-        $sProducts = base64_encode(serialize($aProducts));
-
-        if($bAuthorizedLoading) {
-	        bx_import('BxDolStudioOAuth');
-	        return BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'available_updates', 'dol_products' => $sProducts));
-        }
-
-		bx_import('BxDolStudioJson');
-		return BxDolStudioJson::getInstance()->load(BX_DOL_UNITY_URL_MARKET . 'json_browse_updates', array(
-			'products' => $sProducts,
-			'domain' => BX_DOL_URL_ROOT,
-			'user' => (int)$this->oDb->getParam('sys_oauth_user') 
-		));
+    	bx_import('BxDolStudioInstallerUtils');
+        return BxDolStudioInstallerUtils::getInstance()->checkUpdates($this->bAuthAccessUpdates);
     }
 
     protected function loadCheckout()
@@ -307,8 +289,8 @@ class BxDolStudioStore extends BxTemplStudioPage
         $oInstallerUtils = BxDolStudioInstallerUtils::getInstance();
 
         return array(
-            'modules' => $oInstallerUtils->loadModules(),
-            'updates' => $oInstallerUtils->loadUpdates()
+            'modules' => $oInstallerUtils->getModules(),
+            'updates' => $oInstallerUtils->getUpdates()
         );
     }
 
@@ -329,65 +311,22 @@ class BxDolStudioStore extends BxTemplStudioPage
         return BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'product_files', 'dol_product_id' => $iId, 'dol_file_type' => $sType));
     }
 
-    protected function loadFile($iId)
+    /*
+     * Load package (module, update) using OAuth authorization.
+     */
+    protected function loadFile($iFileId)
     {
-        bx_import('BxDolStudioOAuth');
-        $aItem = BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'product_file', 'dol_file_id' => $iId));
-        if(empty($aItem) || !is_array($aItem))
-            return $aItem;
-
-        //--- write ZIP archive.
-        $sFilePath = BX_DIRECTORY_PATH_TMP . $aItem['name'];
-        if (!$rHandler = fopen($sFilePath, 'w'))
-            return _t('_adm_str_err_cannot_write');
-
-        if (!fwrite($rHandler, urldecode($aItem['content'])))
-            return _t('_adm_str_err_cannot_write');
-
-        fclose($rHandler);
-
-        //--- Unarchive package.
-        if(!class_exists('ZipArchive'))
-            return _t('_adm_str_err_zip_not_available');
-
-        $oZip = new ZipArchive();
-        if($oZip->open($sFilePath) !== true)
-            return _t('_adm_str_err_cannot_unzip_package');
-
-        $sPackageRootFolder = $oZip->numFiles > 0 ? $oZip->getNameIndex(0) : false;
-        if($sPackageRootFolder && file_exists(BX_DIRECTORY_PATH_TMP . $sPackageRootFolder)) // remove existing tmp folder with the same name
-            bx_rrmdir(BX_DIRECTORY_PATH_TMP . $sPackageRootFolder);
-
-        if($sPackageRootFolder && !$oZip->extractTo(BX_DIRECTORY_PATH_TMP))
-            return _t('_adm_str_err_cannot_unzip_package');
-
-        $oZip->close();
-
-        //--- Move unarchived package.
-        $sLogin = getParam('sys_ftp_login');
-        $sPassword = getParam('sys_ftp_password');
-        $sPath = getParam('sys_ftp_dir');
-        if(empty($sLogin) || empty($sPassword) || empty($sPath))
-            return _t('_adm_str_err_no_ftp_info');
-
-        bx_import('BxDolFtp');
-        $oFtp = new BxDolFtp($_SERVER['HTTP_HOST'], $sLogin, $sPassword, $sPath);
-
-        if(!$oFtp->connect())
-            return _t('_adm_str_err_cannot_connect_to_ftp');
-
-        if(!$oFtp->isDolphin())
-            return _t('_adm_str_err_destination_not_valid');
-
-        $sConfigPath = BX_DIRECTORY_PATH_TMP . $sPackageRootFolder . '/install/config.php';
-        if(!file_exists($sConfigPath))
-            return _t('_adm_str_err_wrong_package_format');
-
-        include($sConfigPath);
-        if(empty($aConfig) || empty($aConfig['home_dir']) || !$oFtp->copy(BX_DIRECTORY_PATH_TMP . $sPackageRootFolder . '/', 'modules/' . $aConfig['home_dir']))
-            return _t('_adm_str_err_ftp_copy_failed');
+        bx_import('BxDolStudioInstallerUtils');
+        return BxDolStudioInstallerUtils::getInstance()->downloadFileAuthorized($iFileId);
+    }
 
-        return true;
+    /*
+     * Load update's package publicly.
+     */
+	protected function loadUpdate($sModuleName)
+    {
+        bx_import('BxDolStudioInstallerUtils');
+        return BxDolStudioInstallerUtils::getInstance()->downloadUpdatePublic($sModuleName);
     }
 
     private function checkoutCart($sVendor)

+ 13 - 5
studio/classes/BxDolStudioUpdater.php

@@ -59,11 +59,20 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
         //--- Check hash ---//
         $aFiles = array();
         $this->hashFiles(BX_DIRECTORY_PATH_ROOT . 'modules/' . $this->_aConfig['module_dir'], $aFiles);
-        if (!empty($this->hashCheck($aFiles, $aModuleInfo['id'], true))
-            return array_merge($aResult, array(
+
+        list($aFilesChanged, $fChangedPercent) = $this->hashCheck($aFiles, $aModuleInfo['id']);
+        $bAutoupdateForceModifiedFiles = getParam('sys_autoupdate_force_modified_files') == 'on';
+
+    	if(!empty($aFilesChanged) && !$bAutoupdateForceModifiedFiles) 
+    		return array_merge($aResult, array(
                 'message' => $this->_displayResult('check_module_hash', false, '_adm_err_modules_module_was_modified'),
                 'result' => false
             ));
+		else if($fChangedPercent > BX_FORCE_AUTOUPDATE_MAX_CHANGED_FILES_PERCENT && $bAutoupdateForceModifiedFiles) 
+			return array_merge($aResult, array(
+                'message' => $this->_displayResult('check_module_hash', false, _t('_sys_upgrade_files_checksum_failed_too_many', round($fChangedPercent * 100))),
+                'result' => false
+            ));
 
         //--- Perform action and check results ---//
         $aResult = array_merge($aResult, $this->_perform('install', 'Update'));
@@ -109,11 +118,10 @@ class BxDolStudioUpdater extends BxDolStudioInstaller
         $aLanguages = $oLanguages->getLanguages();
 
         //--- Process languages' key=>value pears ---//
-        $sModuleConfig = $this->_sHomePath . 'install/config.php';
-        if(!file_exists($sModuleConfig))
+        $aConfig = self::getModuleConfig($this->_sHomePath . 'install/config.php');
+        if(empty($aConfig) || !is_array($aConfig))
             return BX_DOL_STUDIO_INSTALLER_FAILED;
 
-        include($sModuleConfig);
         $iCategoryId = $oLanguages->getLanguageCategory($aConfig['language_category']);
 
         foreach($aLanguages as $sName => $sTitle)

+ 11 - 3
studio/js/store.js

@@ -126,7 +126,15 @@ BxDolStudioStore.prototype.checkoutCart = function(sVendor, oButton) {
 	);
 };
 
-BxDolStudioStore.prototype.getFile = function(iProductId, iFileId, oButton) {
+BxDolStudioStore.prototype.getFile = function(iFileId, oButton) {
+	this._getFile('get-file', iFileId, oButton);
+};
+
+BxDolStudioStore.prototype.getUpdate = function(sModuleName, oButton) {
+	this._getFile('get-update', sModuleName, oButton);
+};
+
+BxDolStudioStore.prototype._getFile = function(sAction, mixedId, oButton) {
 	var oDate = new Date();
 	var $this = this;
 	bx_loading(this.sIdPageContent, true);
@@ -134,8 +142,8 @@ BxDolStudioStore.prototype.getFile = function(iProductId, iFileId, oButton) {
 	$.get(
 		this.sActionsUrl,
 		{
-			str_action: 'get-file',
-			str_id: iFileId,
+			str_action: sAction,
+			str_id: mixedId,
 			_t:oDate.getTime()
 		},
 		function(oData) {

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

@@ -490,7 +490,6 @@ class BxBaseStudioStore extends BxDolStudioStore
                 'condition' => ($bFree || $bPurchased) && $bDownloadable,
                 'content' => array(
                     'js_object' => $sJsObject,
-                    'id' => $aProduct['id'],
                     'file_id' => $aProduct['file_id'],
                 )
             )
@@ -515,7 +514,6 @@ class BxBaseStudioStore extends BxDolStudioStore
         foreach($aFiles as $aFile)
             $aTmplVarsFiles[] = array(
                 'js_object' => $sJsObject,
-                'product_id' => $iId,
                 'id' => $aFile['id'],
                 'title' => $aFile['name'],
                 'version' => empty($aFile['version_to']) ? $aFile['version'] : _t('_adm_str_txt_update_from_to', $aFile['version'], $aFile['version_to']),
@@ -528,9 +526,18 @@ class BxBaseStudioStore extends BxDolStudioStore
         return array('code' => 0, 'message' => $sContent);
     }
 
-    protected function getFile($iId)
+    protected function getFile($iFileId)
+    {
+        $mixedResult = $this->loadFile($iFileId);
+        if($mixedResult !== true)
+            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'));
+    }
+
+	protected function getUpdate($sModuleName)
     {
-        $mixedResult = $this->loadFile($iId);
+        $mixedResult = $this->loadUpdate($sModuleName);
         if($mixedResult !== true)
             return array('code' => 1, 'message' => (!empty($mixedResult) ? $mixedResult : _t('_adm_str_err_download_failed')));
 
@@ -599,7 +606,6 @@ class BxBaseStudioStore extends BxDolStudioStore
                     'condition' => !$bShoppingCart && ($bFree || $bPurchased) && $bDownloadable,
                     'content' => array(
                         'js_object' => $sJsObject,
-                        'id' => $aItem['id'],
                         'file_id' => $aItem['file_id'],
                     )
                 ),
@@ -650,9 +656,7 @@ class BxBaseStudioStore extends BxDolStudioStore
                 'bx_if:show_download' => array(
                     'condition' => $bDownloadable,
                     'content' => array(
-                        'js_object' => $sJsObject,
-                        'id' => $aItem['id'],
-                        'file_id' => $aItem['file_id'],
+	            		'on_click' => $sJsObject . "." . ($this->bAuthAccessUpdates ? "getFile(" . $aItem['file_id'] . ", this)" : "getUpdate('" . $aItem['name'] . "', this)")
                     )
                 )
             ));

+ 1 - 1
studio/template/str_files.html

@@ -10,7 +10,7 @@
 				<td class="bx-std-ftitle">__title__</td>
 				<td class="bx-std-fversion">__version__</td>
 				<td>
-					<input class="bx-btn bx-btn-small" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__product_id__, __id__, this)" />
+					<input class="bx-btn bx-btn-small" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__id__, this)" />
 				</td>
 			</tr>
 	    </bx_repeat:files>

+ 1 - 1
studio/template/str_product_v2.html

@@ -23,7 +23,7 @@
             	<input class="bx-btn bx-btn-small bx-std-pc-purchase" type="button" value="<bx_text:_adm_btn_purchase_submit />" onclick="javascript:__js_object__.addToCart('__vendor__', __id__, this)" />
             </bx_if:show_purchase>
         	<bx_if:show_download>
-            	<input class="bx-btn bx-btn-small bx-std-pc-download" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__id__, '__file_id__', this)" />
+            	<input class="bx-btn bx-btn-small bx-std-pc-download" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__file_id__, this)" />
             </bx_if:show_download>
             <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)" />

+ 1 - 1
studio/template/str_product_view.html

@@ -81,7 +81,7 @@
 			<input class="bx-btn bx-def-margin-right" type="button" value="<bx_text:_adm_btn_purchase_submit />" onclick="javascript:__js_object__.addToCart('__vendor__', __id__, this)" />
 		</bx_if:show_purchase>
 		<bx_if:show_download>
-			<input class="bx-btn bx-def-margin-right" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__id__, '__file_id__', this)" />
+			<input class="bx-btn bx-def-margin-right" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__file_id__, this)" />
 		</bx_if:show_download>
 		<input class="bx-btn bx-def-margin-right" type="button" value="<bx_text:_adm_btn_cancel_submit />" onclick="javascript:$('.bx-popup-applied:visible').dolPopupHide();" />
 		<div class="bx-std-cb"></div>

+ 1 - 1
studio/template/str_update_v2.html

@@ -15,7 +15,7 @@
         <div class="bx-std-pc-vendor bx-def-margin-thd-top bx-def-font-small">__vendor__ &bull; <span class="bx-std-pc-versions">__versions__</span></div>
         <div class="bx-std-pc-action bx-def-margin-thd-top bx-clearfix">
         	<bx_if:show_download>
-            	<input class="bx-btn bx-btn-small bx-std-pc-download" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__js_object__.getFile(__id__, '__file_id__', this)" />
+            	<input class="bx-btn bx-btn-small bx-std-pc-download" type="button" value="<bx_text:_adm_btn_download_submit />" onclick="javascript:__on_click__" />
             </bx_if:show_download>
         </div>
     </div>