/** * Get a list of all apps on the appstore * @param string $filter * @param string|null $category * @param OCSClient $ocsClient * @return array|bool multi-dimensional array of apps. * Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description */ public static function getAppstoreApps($filter = 'approved', $category = null, OCSClient $ocsClient) { $categories = [$category]; if (is_null($category)) { $categoryNames = $ocsClient->getCategories(\OCP\Util::getVersion()); if (is_array($categoryNames)) { // Check that categories of apps were retrieved correctly if (!($categories = array_keys($categoryNames))) { return false; } } else { return false; } } $page = 0; $remoteApps = $ocsClient->getApplications($categories, $page, $filter, \OCP\Util::getVersion()); $apps = []; $i = 0; $l = \OC::$server->getL10N('core'); foreach ($remoteApps as $app) { $potentialCleanId = self::getInternalAppIdByOcs($app['id']); // enhance app info (for example the description) $apps[$i] = OC_App::parseAppInfo($app); $apps[$i]['author'] = $app['personid']; $apps[$i]['ocs_id'] = $app['id']; $apps[$i]['internal'] = 0; $apps[$i]['active'] = $potentialCleanId !== false ? self::isEnabled($potentialCleanId) : false; $apps[$i]['update'] = false; $apps[$i]['groups'] = false; $apps[$i]['score'] = $app['score']; $apps[$i]['removable'] = false; if ($app['label'] == 'recommended') { $apps[$i]['internallabel'] = (string) $l->t('Recommended'); $apps[$i]['internalclass'] = 'recommendedapp'; } // Apps from the appstore are always assumed to be compatible with the // the current release as the initial filtering is done on the appstore $apps[$i]['dependencies']['owncloud']['@attributes']['min-version'] = implode('.', \OCP\Util::getVersion()); $apps[$i]['dependencies']['owncloud']['@attributes']['max-version'] = implode('.', \OCP\Util::getVersion()); $i++; } if (empty($apps)) { return false; } else { return $apps; } }
public function testGetApplicationsSuccessful() { $this->config->expects($this->at(0))->method('getSystemValue')->with('appstoreenabled', true)->will($this->returnValue(true)); $this->config->expects($this->at(1))->method('getSystemValue')->with('appstoreurl', 'https://api.owncloud.com/v1')->will($this->returnValue('https://api.owncloud.com/v1')); $response = $this->getMock('\\OCP\\Http\\Client\\IResponse'); $response->expects($this->once())->method('getBody')->will($this->returnValue('<?xml version="1.0"?> <ocs> <meta> <status>ok</status> <statuscode>100</statuscode> <message></message> <totalitems>2</totalitems> <itemsperpage>100</itemsperpage> </meta> <data> <content details="summary"> <id>168707</id> <name>Calendar 8.0</name> <version>0.6.4</version> <label>recommended</label> <changed>2015-02-09T15:23:56+01:00</changed> <created>2015-01-26T04:35:19+01:00</created> <typeid>921</typeid> <typename>ownCloud PIM</typename> <language></language> <personid>owncloud</personid> <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage> <downloads>5393</downloads> <score>60</score> <description>Calendar App for ownCloud</description> <comments>7</comments> <fans>10</fans> <licensetype>16</licensetype> <approved>0</approved> <category>1</category> <license>AGPL</license> <preview1></preview1> <detailpage>https://apps.owncloud.com/content/show.php?content=168707</detailpage> <downloadtype1></downloadtype1> <downloadway1>0</downloadway1> <downloadprice1>0</downloadprice1> <downloadlink1>http://apps.owncloud.com/content/download.php?content=168707&id=1</downloadlink1> <downloadgpgsignature1></downloadgpgsignature1> <downloadgpgfingerprint1></downloadgpgfingerprint1> <downloadpackagename1></downloadpackagename1> <downloadrepository1></downloadrepository1> <downloadname1></downloadname1> <downloadsize1>885</downloadsize1> </content> <content details="summary"> <id>168708</id> <name>Contacts 8.0</name> <version>0.3.0.18</version> <label>recommended</label> <changed>2015-02-09T15:18:58+01:00</changed> <created>2015-01-26T04:45:17+01:00</created> <typeid>921</typeid> <typename>ownCloud PIM</typename> <language></language> <personid>owncloud</personid> <profilepage>http://opendesktop.org/usermanager/search.php?username=owncloud</profilepage> <downloads>4237</downloads> <score>58</score> <description></description> <comments>3</comments> <fans>6</fans> <licensetype>16</licensetype> <approved>200</approved> <category>1</category> <license>AGPL</license> <preview1></preview1> <detailpage>https://apps.owncloud.com/content/show.php?content=168708</detailpage> <downloadtype1></downloadtype1> <downloadway1>0</downloadway1> <downloadprice1>0</downloadprice1> <downloadlink1>http://apps.owncloud.com/content/download.php?content=168708&id=1</downloadlink1> <downloadgpgsignature1></downloadgpgsignature1> <downloadgpgfingerprint1></downloadgpgfingerprint1> <downloadpackagename1></downloadpackagename1> <downloadrepository1></downloadrepository1> <downloadname1></downloadname1> <downloadsize1>1409</downloadsize1> </content> </data> </ocs> ')); $client = $this->getMock('\\OCP\\Http\\Client\\IClient'); $client->expects($this->once())->method('get')->with('https://api.owncloud.com/v1/content/data', ['timeout' => 5, 'query' => ['version' => implode('x', [8, 1, 0, 7]), 'filter' => 'approved', 'categories' => '815x1337', 'sortmode' => 'new', 'page' => 1, 'pagesize' => 100, 'approved' => 'approved']])->will($this->returnValue($response)); $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client)); $expected = [['id' => '168707', 'name' => 'Calendar 8.0', 'label' => 'recommended', 'version' => '0.6.4', 'type' => '921', 'typename' => 'ownCloud PIM', 'personid' => 'owncloud', 'license' => 'AGPL', 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=168707', 'preview' => '', 'preview-full' => '', 'changed' => 1423491836, 'description' => 'Calendar App for ownCloud', 'score' => '60', 'downloads' => 5393, 'level' => 0, 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud'], ['id' => '168708', 'name' => 'Contacts 8.0', 'label' => 'recommended', 'version' => '0.3.0.18', 'type' => '921', 'typename' => 'ownCloud PIM', 'personid' => 'owncloud', 'license' => 'AGPL', 'detailpage' => 'https://apps.owncloud.com/content/show.php?content=168708', 'preview' => '', 'preview-full' => '', 'changed' => 1423491538, 'description' => '', 'score' => '58', 'downloads' => 4237, 'level' => 200, 'profilepage' => 'http://opendesktop.org/usermanager/search.php?username=owncloud']]; $this->assertEquals($expected, $this->ocsClient->getApplications([815, 1337], 1, 'approved', [8, 1, 0, 7])); }
/** * Get a list of all apps on the appstore * @param string $filter * @param string $category * @return array|bool multi-dimensional array of apps. * Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description */ public static function getAppstoreApps($filter = 'approved', $category = null) { $categories = [$category]; $ocsClient = new OCSClient(\OC::$server->getHTTPClientService(), \OC::$server->getConfig(), \OC::$server->getLogger()); if (is_null($category)) { $categoryNames = $ocsClient->getCategories(\OC_Util::getVersion()); if (is_array($categoryNames)) { // Check that categories of apps were retrieved correctly if (!($categories = array_keys($categoryNames))) { return false; } } else { return false; } } $page = 0; $remoteApps = $ocsClient->getApplications($categories, $page, $filter, \OC_Util::getVersion()); $apps = []; $i = 0; $l = \OC::$server->getL10N('core'); foreach ($remoteApps as $app) { $potentialCleanId = self::getInternalAppIdByOcs($app['id']); // enhance app info (for example the description) $apps[$i] = OC_App::parseAppInfo($app); $apps[$i]['author'] = $app['personid']; $apps[$i]['ocs_id'] = $app['id']; $apps[$i]['internal'] = 0; $apps[$i]['active'] = $potentialCleanId !== false ? self::isEnabled($potentialCleanId) : false; $apps[$i]['update'] = false; $apps[$i]['groups'] = false; $apps[$i]['score'] = $app['score']; $apps[$i]['removable'] = false; if ($app['label'] == 'recommended') { $apps[$i]['internallabel'] = (string) $l->t('Recommended'); $apps[$i]['internalclass'] = 'recommendedapp'; } $i++; } if (empty($apps)) { return false; } else { return $apps; } }