Merge pull request #17222 from owncloud/issue-17101-send-oc-version-to-app-store

Send OC version to appstore so it can reply with the right links
This commit is contained in:
Lukas Reschke 2015-06-29 15:07:00 +02:00
commit b56af26199
5 changed files with 58 additions and 35 deletions

View File

@ -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)) {

View File

@ -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, '>')) {

View File

@ -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) {
@ -291,10 +300,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;
}
@ -305,6 +315,9 @@ class OCSClient {
$url,
[
'timeout' => 5,
'query' => [
'version' => implode('x', $targetVersion),
],
]
);
} catch(\Exception $e) {

View File

@ -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[] = [

View File

@ -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() {
@ -746,6 +751,7 @@ class OCSClientTest extends \Test\TestCase {
'https://api.owncloud.com/v1/content/data/MyId',
[
'timeout' => 5,
'query' => ['version' => '8x1x0x7'],
]
)
->will($this->returnValue($response));
@ -773,7 +779,7 @@ class OCSClientTest extends \Test\TestCase {
'score' => 50,
'level' => 200,
];
$this->assertSame($expected, $this->ocsClient->getApplication('MyId'));
$this->assertSame($expected, $this->ocsClient->getApplication('MyId', [8, 1, 0, 7]));
}
public function testGetApplicationEmptyXml() {
$this->config
@ -809,6 +815,7 @@ class OCSClientTest extends \Test\TestCase {
'https://api.owncloud.com/v1/content/data/MyId',
[
'timeout' => 5,
'query' => ['version' => '8x1x0x7'],
]
)
->will($this->returnValue($response));
@ -818,7 +825,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() {
@ -827,7 +834,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() {
@ -850,6 +857,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')));
@ -869,7 +877,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() {
@ -898,6 +906,7 @@ class OCSClientTest extends \Test\TestCase {
'https://api.owncloud.com/v1/content/download/MyId/1',
[
'timeout' => 5,
'query' => ['version' => '8x1x0x7'],
]
)
->will($this->returnValue($response));
@ -917,7 +926,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() {
@ -964,6 +973,7 @@ class OCSClientTest extends \Test\TestCase {
'https://api.owncloud.com/v1/content/download/MyId/1',
[
'timeout' => 5,
'query' => ['version' => '8x1x0x7'],
]
)
->will($this->returnValue($response));
@ -976,6 +986,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]));
}
}