From ae3d402dbc3c9620cea5b32bedc7f00874b12dd0 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 29 Jun 2015 11:15:56 +0200 Subject: [PATCH] Send OC version to appstore so it can reply with the right links --- lib/private/app.php | 10 ++-- lib/private/installer.php | 6 +-- lib/private/ocsclient.php | 25 +++++++--- settings/controller/appsettingscontroller.php | 2 +- tests/lib/ocsclienttest.php | 50 +++++++++++-------- 5 files changed, 58 insertions(+), 35 deletions(-) diff --git a/lib/private/app.php b/lib/private/app.php index 4814561bae..c506be1799 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -312,8 +312,8 @@ class OC_App { \OC::$server->getConfig(), \OC::$server->getLogger() ); - $appData = $ocsClient->getApplication($app); - $download= $ocsClient->getApplicationDownload($app); + $appData = $ocsClient->getApplication($app, \OC_Util::getVersion()); + $download= $ocsClient->getApplicationDownload($app, \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']); @@ -918,7 +918,7 @@ class OC_App { if (is_null($category)) { - $categoryNames = $ocsClient->getCategories(); + $categoryNames = $ocsClient->getCategories(\OC_Util::getVersion()); if (is_array($categoryNames)) { // Check that categories of apps were retrieved correctly if (!$categories = array_keys($categoryNames)) { @@ -930,7 +930,7 @@ class OC_App { } $page = 0; - $remoteApps = $ocsClient->getApplications($categories, $page, $filter); + $remoteApps = $ocsClient->getApplications($categories, $page, $filter, \OC_Util::getVersion()); $apps = []; $i = 0; $l = \OC::$server->getL10N('core'); @@ -1088,7 +1088,7 @@ class OC_App { $config, \OC::$server->getLogger() ); - $appData = $ocsClient->getApplication($app); + $appData = $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)) { diff --git a/lib/private/installer.php b/lib/private/installer.php index 41f13f0f5f..bd214be566 100644 --- a/lib/private/installer.php +++ b/lib/private/installer.php @@ -227,8 +227,8 @@ class OC_Installer{ \OC::$server->getConfig(), \OC::$server->getLogger() ); - $appData = $ocsClient->getApplication($ocsId); - $download = $ocsClient->getApplicationDownload($ocsId); + $appData = $ocsClient->getApplication($ocsId, \OC_Util::getVersion()); + $download = $ocsClient->getApplicationDownload($ocsId, \OC_Util::getVersion()); if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') { $download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']); @@ -395,7 +395,7 @@ class OC_Installer{ \OC::$server->getConfig(), \OC::$server->getLogger() ); - $ocsdata = $ocsClient->getApplication($ocsid); + $ocsdata = $ocsClient->getApplication($ocsid, \OC_Util::getVersion()); $ocsversion= (string) $ocsdata['version']; $currentversion=OC_App::getAppVersion($app); if (version_compare($ocsversion, $currentversion, '>')) { diff --git a/lib/private/ocsclient.php b/lib/private/ocsclient.php index 2868b40700..9fa4aebb5e 100644 --- a/lib/private/ocsclient.php +++ b/lib/private/ocsclient.php @@ -106,11 +106,12 @@ class OCSClient { /** * Get all the categories from the OCS server * + * @param array $targetVersion The target ownCloud version * @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 */ - public function getCategories() { + public function getCategories($targetVersion) { if (!$this->isAppStoreEnabled()) { return null; } @@ -121,6 +122,9 @@ class OCSClient { $this->getAppStoreUrl() . '/content/categories', [ 'timeout' => 5, + 'query' => [ + 'version' => implode('x', $targetVersion), + ], ] ); } catch(\Exception $e) { @@ -155,9 +159,10 @@ class OCSClient { * @param array $categories * @param int $page * @param string $filter + * @param array $targetVersion The target ownCloud version * @return array An array of application data */ - public function getApplications(array $categories, $page, $filter) { + public function getApplications(array $categories, $page, $filter, $targetVersion) { if (!$this->isAppStoreEnabled()) { return []; } @@ -169,7 +174,7 @@ class OCSClient { [ 'timeout' => 5, 'query' => [ - 'version' => implode('x', \OC_Util::getVersion()), + 'version' => implode('x', $targetVersion), 'filter' => $filter, 'categories' => implode('x', $categories), 'sortmode' => 'new', @@ -229,11 +234,12 @@ class OCSClient { * 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 function getApplication($id) { + public function getApplication($id, $targetVersion) { if (!$this->isAppStoreEnabled()) { return null; } @@ -244,6 +250,9 @@ class OCSClient { $this->getAppStoreUrl() . '/content/data/' . urlencode($id), [ 'timeout' => 5, + 'query' => [ + 'version' => implode('x', $targetVersion), + ], ] ); } catch(\Exception $e) { @@ -290,10 +299,11 @@ class OCSClient { /** * Get the download url for an application from the OCS server - * @param $id + * @param string $id + * @param array $targetVersion The target ownCloud version * @return array|null an array of application data or null */ - public function getApplicationDownload($id) { + public function getApplicationDownload($id, $targetVersion) { if (!$this->isAppStoreEnabled()) { return null; } @@ -304,6 +314,9 @@ class OCSClient { $url, [ 'timeout' => 5, + 'query' => [ + 'version' => implode('x', $targetVersion), + ], ] ); } catch(\Exception $e) { diff --git a/settings/controller/appsettingscontroller.php b/settings/controller/appsettingscontroller.php index d64c945c02..53570a2a35 100644 --- a/settings/controller/appsettingscontroller.php +++ b/settings/controller/appsettingscontroller.php @@ -127,7 +127,7 @@ class AppSettingsController extends Controller { if($this->ocsClient->isAppStoreEnabled()) { // apps from external repo via OCS - $ocs = $this->ocsClient->getCategories(); + $ocs = $this->ocsClient->getCategories(\OC_Util::getVersion()); if ($ocs) { foreach($ocs as $k => $v) { $categories[] = [ diff --git a/tests/lib/ocsclienttest.php b/tests/lib/ocsclienttest.php index ca8a2a2a2e..b8c4ed2f7f 100644 --- a/tests/lib/ocsclienttest.php +++ b/tests/lib/ocsclienttest.php @@ -85,7 +85,7 @@ class OCSClientTest extends \Test\TestCase { ->method('getSystemValue') ->with('appstoreenabled', true) ->will($this->returnValue(false)); - $this->assertNull($this->ocsClient->getCategories()); + $this->assertNull($this->ocsClient->getCategories([8, 1, 0, 7])); } public function testGetCategoriesExceptionClient() { @@ -108,6 +108,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/categories', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->throwException(new \Exception('TheErrorMessage'))); @@ -127,7 +128,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertNull($this->ocsClient->getCategories()); + $this->assertNull($this->ocsClient->getCategories([8, 1, 0, 7])); } public function testGetCategoriesParseError() { @@ -156,6 +157,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/categories', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -175,7 +177,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertNull($this->ocsClient->getCategories()); + $this->assertNull($this->ocsClient->getCategories([8, 1, 0, 7])); } public function testGetCategoriesSuccessful() { @@ -239,6 +241,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/categories', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -256,7 +259,7 @@ class OCSClientTest extends \Test\TestCase { 924 => 'ownCloud Tool', 925 => 'ownCloud other', ]; - $this->assertSame($expected, $this->ocsClient->getCategories()); + $this->assertSame($expected, $this->ocsClient->getCategories([8, 1, 0, 7])); } public function testGetApplicationsDisabledAppStore() { @@ -265,7 +268,7 @@ class OCSClientTest extends \Test\TestCase { ->method('getSystemValue') ->with('appstoreenabled', true) ->will($this->returnValue(false)); - $this->assertSame([], $this->ocsClient->getApplications([], 1, 'approved')); + $this->assertSame([], $this->ocsClient->getApplications([], 1, 'approved', [8, 1, 0, 7])); } public function testGetApplicationsExceptionClient() { @@ -289,7 +292,7 @@ class OCSClientTest extends \Test\TestCase { [ 'timeout' => 5, 'query' => [ - 'version' => implode('x', \OC_Util::getVersion()), + 'version' => implode('x', [8, 1, 0, 7]), 'filter' => 'approved', 'categories' => '815x1337', 'sortmode' => 'new', @@ -316,7 +319,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved')); + $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7])); } public function testGetApplicationsParseError() { @@ -346,7 +349,7 @@ class OCSClientTest extends \Test\TestCase { [ 'timeout' => 5, 'query' => [ - 'version' => implode('x', \OC_Util::getVersion()), + 'version' => implode('x', [8, 1, 0, 7]), 'filter' => 'approved', 'categories' => '815x1337', 'sortmode' => 'new', @@ -373,7 +376,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved')); + $this->assertSame([], $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7])); } public function testGetApplicationsSuccessful() { @@ -482,7 +485,7 @@ class OCSClientTest extends \Test\TestCase { [ 'timeout' => 5, 'query' => [ - 'version' => implode('x', \OC_Util::getVersion()), + 'version' => implode('x', [8, 1, 0, 7]), 'filter' => 'approved', 'categories' => '815x1337', 'sortmode' => 'new', @@ -539,7 +542,7 @@ class OCSClientTest extends \Test\TestCase { 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud', ], ]; - $this->assertEquals($expected, $this->ocsClient->getApplications([815, 1337], 1, 'approved')); + $this->assertEquals($expected, $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7])); } public function tesGetApplicationDisabledAppStore() { @@ -548,7 +551,7 @@ class OCSClientTest extends \Test\TestCase { ->method('getSystemValue') ->with('appstoreenabled', true) ->will($this->returnValue(false)); - $this->assertNull($this->ocsClient->getApplication('MyId')); + $this->assertNull($this->ocsClient->getApplication('MyId', [8, 1, 0, 7])); } public function testGetApplicationExceptionClient() { @@ -571,6 +574,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/data/MyId', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->throwException(new \Exception('TheErrorMessage'))); @@ -590,7 +594,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertNull($this->ocsClient->getApplication('MyId')); + $this->assertNull($this->ocsClient->getApplication('MyId', [8, 1, 0, 7])); } public function testGetApplicationParseError() { @@ -619,6 +623,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/data/MyId', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -638,7 +643,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertNull($this->ocsClient->getApplication('MyId')); + $this->assertNull($this->ocsClient->getApplication('MyId', [8, 1, 0, 7])); } public function testGetApplicationSuccessful() { @@ -745,6 +750,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/data/MyId', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -771,7 +777,7 @@ class OCSClientTest extends \Test\TestCase { 'description' => 'Placeholder for future updates', 'score' => 50, ]; - $this->assertSame($expected, $this->ocsClient->getApplication('MyId')); + $this->assertSame($expected, $this->ocsClient->getApplication('MyId', [8, 1, 0, 7])); } public function testGetApplicationEmptyXml() { $this->config @@ -807,6 +813,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/data/MyId', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -816,7 +823,7 @@ class OCSClientTest extends \Test\TestCase { ->method('newClient') ->will($this->returnValue($client)); - $this->assertSame(null, $this->ocsClient->getApplication('MyId')); + $this->assertSame(null, $this->ocsClient->getApplication('MyId', [8, 1, 0, 7])); } public function testGetApplicationDownloadDisabledAppStore() { @@ -825,7 +832,7 @@ class OCSClientTest extends \Test\TestCase { ->method('getSystemValue') ->with('appstoreenabled', true) ->will($this->returnValue(false)); - $this->assertNull($this->ocsClient->getApplicationDownload('MyId')); + $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7])); } public function testGetApplicationDownloadExceptionClient() { @@ -848,6 +855,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/download/MyId/1', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->throwException(new \Exception('TheErrorMessage'))); @@ -867,7 +875,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertNull($this->ocsClient->getApplicationDownload('MyId')); + $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7])); } public function testGetApplicationDownloadParseError() { @@ -896,6 +904,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/download/MyId/1', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -915,7 +924,7 @@ class OCSClientTest extends \Test\TestCase { ] ); - $this->assertNull($this->ocsClient->getApplicationDownload('MyId')); + $this->assertNull($this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7])); } public function testGetApplicationDownloadUrlSuccessful() { @@ -962,6 +971,7 @@ class OCSClientTest extends \Test\TestCase { 'https://api.owncloud.com/v1/content/download/MyId/1', [ 'timeout' => 5, + 'query' => ['version' => '8x1x0x7'], ] ) ->will($this->returnValue($response)); @@ -974,6 +984,6 @@ class OCSClientTest extends \Test\TestCase { $expected = [ 'downloadlink' => 'https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip', ]; - $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId')); + $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7])); } }