Forráskód Böngészése

#73 - Modules autoupdate.

AntonLV 12 éve
szülő
commit
0a6878b5d6

+ 2 - 0
install/sql/system.sql

@@ -216,6 +216,7 @@ SET @iCategoryId = LAST_INSERT_ID();
 
 INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `extra`, `check`, `check_error`, `order`) VALUES
 (@iCategoryId, 'sys_install_time', '', '0', 'digit', '', '', '', 3),
+(@iCategoryId, 'sys_oauth_user', '', '0', 'digit', '', '', '', 4),
 
 (@iCategoryId, 'sys_site_logo', '', '0', 'digit', '', '', '', 20),
 (@iCategoryId, 'sys_site_logo_alt', '_adm_dsg_txt_alt_text', '0', 'text', '', '', '', 21),
@@ -748,6 +749,7 @@ CREATE TABLE `sys_modules` (
   `date` int(11) unsigned NOT NULL default '0',
   `enabled` tinyint(1) NOT NULL default '0',
   `pending_uninstall` tinyint(4) NOT NULL,
+  `hash` varchar(32) NOT NULL default '',
   PRIMARY KEY  (`id`),
   UNIQUE KEY `name` (`name`),
   UNIQUE KEY `path` (`path`),

+ 1 - 2
studio/classes/BxDolStudioJson.php

@@ -38,8 +38,7 @@ class BxDolStudioJson extends BxDol implements iBxDolSingleton
         if(empty($sContent))
             return false;
 
-        //--- Uncomment to debug
-        //echo $sContent; exit;
+        //echo $sContent; exit;		//--- Uncomment to debug
         $mixedResult = json_decode($sContent, true);
         if(is_null($mixedResult))
             return false;

+ 9 - 0
studio/classes/BxDolStudioModulesQuery.php

@@ -15,6 +15,15 @@ class BxDolStudioModulesQuery extends BxDolModuleQuery
     {
         parent::__construct();
     }
+
+	public function updateModule($aParamsSet, $aParamsWhere)
+    {
+        if(empty($aParamsSet) || empty($aParamsWhere))
+            return false;
+
+        $sSql = "UPDATE `sys_modules` SET " . $this->arrayToSQL($aParamsSet) . " WHERE " . $this->arrayToSQL($aParamsWhere, " AND ");
+        return $this->query($sSql);
+    }
 }
 
 /** @} */

+ 6 - 3
studio/classes/BxDolStudioOAuth.php

@@ -144,10 +144,13 @@ class BxDolStudioOAuth extends BxDol implements iBxDolSingleton
                 if($this->isServerError($aAccessToken))
                     return $this->processServerError($aAccessToken);
 
+				$iUser = (int)bx_get('oauth_user');
+				setParam('sys_oauth_user', $iUser);
+
                 $this->oSession->setValue('sys_oauth_token', $aAccessToken['oauth_token']);
                 $this->oSession->setValue('sys_oauth_secret', $aAccessToken['oauth_token_secret']);
                 $this->oSession->setValue('sys_oauth_authorized', 1);
-                $this->oSession->setValue('sys_oauth_authorized_user', (int)bx_get('oauth_user'));
+                $this->oSession->setValue('sys_oauth_authorized_user', $iUser);
 
                 return true;
             }
@@ -169,8 +172,8 @@ class BxDolStudioOAuth extends BxDol implements iBxDolSingleton
             $oConsumer->setToken($this->oSession->getValue('sys_oauth_token'), $this->oSession->getValue('sys_oauth_secret'));
             $oConsumer->fetch(BX_DOL_OAUTH_URL_FETCH_DATA, $aParams, OAUTH_HTTP_METHOD_POST);
 
-            //--- Uncomment to debug
-            //echo $oConsumer->getLastResponse(); exit;
+            
+            //echo $oConsumer->getLastResponse(); exit;	//--- Uncomment to debug
             return json_decode($oConsumer->getLastResponse(), true);
         } catch(OAuthException $e) {
             return array();

+ 24 - 7
studio/classes/BxDolStudioStore.php

@@ -232,28 +232,45 @@ class BxDolStudioStore extends BxTemplStudioPage
     protected function loadPurchases()
     {
         bx_import('BxDolStudioOAuth');
-        return BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'purchased_products'));
+        $aProducts = BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'purchased_products', 'dol_domain' => BX_DOL_URL_ROOT));
+
+        if(!empty($aProducts) && is_array($aProducts))
+	        foreach ($aProducts as $aProduct)
+	        	$this->oDb->updateModule(array('hash' => $aProduct['hash']), array('name' => $aProduct['name']));
+
+        return $aProducts;
     }
 
-    protected function loadUpdates()
+    protected function loadUpdates($bAuthorizedLoading = false)
     {
         bx_import('BxDolModuleQuery');
         $oModules = BxDolModuleQuery::getInstance();
         $aModules = $oModules->getModules();
 
-        $aParams = array();
+        $aProducts = array();
         foreach($aModules as $aModule) {
-            if(!isset($aModule['name']) || empty($aModule['name']))
+            if(empty($aModule['name']) || empty($aModule['hash']))
                 continue;
 
-            $aParams[] = array(
+            $aProducts[] = array(
                 'name' => $aModule['name'],
                 'version' => $aModule['version'],
+            	'hash' => $aModule['hash'],
             );
         }
+        $sProducts = base64_encode(serialize($aProducts));
 
-        bx_import('BxDolStudioOAuth');
-        return BxDolStudioOAuth::getInstance()->loadItems(array('dol_type' => 'available_updates', 'dol_products' => base64_encode(serialize($aParams))));
+        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') 
+		));
     }
 
     protected function loadCheckout()