Skip to content

Commit

Permalink
Add oc version to app store requests in stable8
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed Jun 29, 2015
1 parent 8a1cfa4 commit 57789e1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
10 changes: 5 additions & 5 deletions lib/private/app.php
Expand Up @@ -294,8 +294,8 @@ public static function enable($app, $groups = null) {
* @return int
*/
public static function downloadApp($app) {
$appData=OC_OCSClient::getApplication($app);
$download=OC_OCSClient::getApplicationDownload($app, 1);
$appData=OC_OCSClient::getApplication($app, \OC_Util::getVersion());
$download=OC_OCSClient::getApplicationDownload($app, 1, \OC_Util::getVersion());
if(isset($download['downloadlink']) and $download['downloadlink']!='') {
// Replace spaces in download link without encoding entire URL
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
Expand Down Expand Up @@ -926,7 +926,7 @@ protected static function getInternalAppIdByOcs($ocsID) {
public static function getAppstoreApps($filter = 'approved', $category = null) {
$categories = array($category);
if (is_null($category)) {
$categoryNames = OC_OCSClient::getCategories();
$categoryNames = OC_OCSClient::getCategories(\OC_Util::getVersion());
if (is_array($categoryNames)) {
// Check that categories of apps were retrieved correctly
if (!$categories = array_keys($categoryNames)) {
Expand All @@ -938,7 +938,7 @@ public static function getAppstoreApps($filter = 'approved', $category = null) {
}

$page = 0;
$remoteApps = OC_OCSClient::getApplications($categories, $page, $filter);
$remoteApps = OC_OCSClient::getApplications($categories, $page, $filter, \OC_Util::getVersion());
$app1 = array();
$i = 0;
$l = \OC::$server->getL10N('core');
Expand Down Expand Up @@ -1088,7 +1088,7 @@ public static function getAppVersions() {
public static function installApp($app) {
$l = \OC::$server->getL10N('core');
$config = \OC::$server->getConfig();
$appData=OC_OCSClient::getApplication($app);
$appData=OC_OCSClient::getApplication($app, \OC_Util::getVersion());

// check if app is a shipped app or not. OCS apps have an integer as id, shipped apps use a string
if(!is_numeric($app)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/private/installer.php
Expand Up @@ -205,8 +205,8 @@ public static function updateApp( $info=array(), $isShipped=false) {
* @throws Exception
*/
public static function updateAppByOCSId($ocsid) {
$appdata = OC_OCSClient::getApplication($ocsid);
$download = OC_OCSClient::getApplicationDownload($ocsid, 1);
$appdata = OC_OCSClient::getApplication($ocsid, \OC_Util::getVersion());
$download = OC_OCSClient::getApplicationDownload($ocsid, 1, \OC_Util::getVersion());

if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') {
$download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']);
Expand Down Expand Up @@ -368,7 +368,7 @@ public static function isUpdateAvailable( $app ) {

if($ocsid<>'') {

$ocsdata=OC_OCSClient::getApplication($ocsid);
$ocsdata=OC_OCSClient::getApplication($ocsid, \OC_Util::getVersion());
$ocsversion= (string) $ocsdata['version'];
$currentversion=OC_App::getAppVersion($app);
if (version_compare($ocsversion, $currentversion, '>')) {
Expand Down
18 changes: 13 additions & 5 deletions lib/private/ocsclient.php
Expand Up @@ -67,12 +67,15 @@ private static function getOCSresponse($url) {
* @return array|null an array of category ids or null
* @note returns NULL if config value appstoreenabled is set to false
* This function returns a list of all the application categories on the OCS server
*
* @param array $targetVersion The target ownCloud version
*/
public static function getCategories() {
public static function getCategories(array $targetVersion) {
if(!self::isAppstoreEnabled()) {
return null;
}
$url=OC_OCSClient::getAppStoreURL().'/content/categories';
$url .= '?version='.implode('x', $targetVersion);
$xml=OC_OCSClient::getOCSresponse($url);
if($xml==false) {
return null;
Expand Down Expand Up @@ -103,8 +106,9 @@ public static function getCategories() {
* @param array|string $categories
* @param int $page
* @param string $filter
* @param array $targetVersion The target ownCloud version
*/
public static function getApplications($categories, $page, $filter) {
public static function getApplications($categories, $page, $filter, array $targetVersion) {
if(!self::isAppstoreEnabled()) {
return(array());
}
Expand All @@ -115,7 +119,7 @@ public static function getApplications($categories, $page, $filter) {
$categoriesstring=$categories;
}

$version='&version='.implode('x', \OC_Util::getVersion());
$version='&version='.implode('x', $targetVersion);
$filterurl='&filter='.urlencode($filter);
$url=OC_OCSClient::getAppStoreURL().'/content/data?categories='.urlencode($categoriesstring)
.'&sortmode=new&page='.urlencode($page).'&pagesize=100'.$filterurl.$version;
Expand Down Expand Up @@ -158,15 +162,17 @@ public static function getApplications($categories, $page, $filter) {
/**
* Get an the applications from the OCS server
* @param string $id
* @param array $targetVersion The target ownCloud version
* @return array|null an array of application data or null
*
* This function returns an applications from the OCS server
*/
public static function getApplication($id) {
public static function getApplication($id, array $targetVersion) {
if(!self::isAppstoreEnabled()) {
return null;
}
$url=OC_OCSClient::getAppStoreURL().'/content/data/'.urlencode($id);
$url .= '?version='.implode('x', $targetVersion);
$xml=OC_OCSClient::getOCSresponse($url);

if($xml==false) {
Expand Down Expand Up @@ -209,12 +215,14 @@ public static function getApplication($id) {
* This function returns an download url for an applications from the OCS server
* @param string $id
* @param integer $item
* @param array $targetVersion The target ownCloud version
*/
public static function getApplicationDownload($id, $item) {
public static function getApplicationDownload($id, $item, array $targetVersion) {
if(!self::isAppstoreEnabled()) {
return null;
}
$url=OC_OCSClient::getAppStoreURL().'/content/download/'.urlencode($id).'/'.urlencode($item);
$url .= '?version='.implode('x', $targetVersion);
$xml=OC_OCSClient::getOCSresponse($url);

if($xml==false) {
Expand Down
2 changes: 1 addition & 1 deletion settings/controller/appsettingscontroller.php
Expand Up @@ -66,7 +66,7 @@ public function listCategories() {
if($this->config->getSystemValue('appstoreenabled', true)) {
$categories[] = ['id' => 2, 'displayName' => (string)$this->l10n->t('Recommended')];
// apps from external repo via OCS
$ocs = \OC_OCSClient::getCategories();
$ocs = \OC_OCSClient::getCategories(\OC_Util::getVersion());
if ($ocs) {
foreach($ocs as $k => $v) {
$categories[] = array(
Expand Down

0 comments on commit 57789e1

Please sign in to comment.