Exemple #1
0
    public function testGetCategoriesSuccessful()
    {
        $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>6</totalitems>
				 </meta>
				 <data>
				  <category>
				   <id>920</id>
				   <name>ownCloud Multimedia</name>
				  </category>
				  <category>
				   <id>921</id>
				   <name>ownCloud PIM</name>
				  </category>
				  <category>
				   <id>922</id>
				   <name>ownCloud Productivity</name>
				  </category>
				  <category>
				   <id>923</id>
				   <name>ownCloud Game</name>
				  </category>
				  <category>
				   <id>924</id>
				   <name>ownCloud Tool</name>
				  </category>
				  <category>
				   <id>925</id>
				   <name>ownCloud other</name>
				  </category>
				 </data>
				</ocs>
				'));
        $client = $this->getMock('\\OCP\\Http\\Client\\IClient');
        $client->expects($this->once())->method('get')->with('https://api.owncloud.com/v1/content/categories', ['timeout' => 5, 'query' => ['version' => '8x1x0x7']])->will($this->returnValue($response));
        $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client));
        $expected = [920 => 'ownCloud Multimedia', 921 => 'ownCloud PIM', 922 => 'ownCloud Productivity', 923 => 'ownCloud Game', 924 => 'ownCloud Tool', 925 => 'ownCloud other'];
        $this->assertSame($expected, $this->ocsClient->getCategories([8, 1, 0, 7]));
    }
 /**
  * Get all available categories
  * @return array
  */
 public function listCategories()
 {
     if (!is_null($this->cache->get('listCategories'))) {
         return $this->cache->get('listCategories');
     }
     $categories = [['id' => 0, 'displayName' => (string) $this->l10n->t('Enabled')], ['id' => 1, 'displayName' => (string) $this->l10n->t('Not enabled')]];
     if ($this->ocsClient->isAppStoreEnabled()) {
         // apps from external repo via OCS
         $ocs = $this->ocsClient->getCategories();
         if ($ocs) {
             foreach ($ocs as $k => $v) {
                 $categories[] = ['id' => $k, 'displayName' => str_replace('ownCloud ', '', $v)];
             }
         }
     }
     $this->cache->set('listCategories', $categories, 3600);
     return $categories;
 }
 /**
  * Get all available categories
  * @return array
  */
 public function listCategories()
 {
     if (!is_null($this->cache->get('listCategories'))) {
         return $this->cache->get('listCategories');
     }
     $categories = [['id' => self::CAT_ENABLED, 'ident' => 'enabled', 'displayName' => (string) $this->l10n->t('Enabled')], ['id' => self::CAT_DISABLED, 'ident' => 'disabled', 'displayName' => (string) $this->l10n->t('Not enabled')]];
     if ($this->ocsClient->isAppStoreEnabled()) {
         // apps from external repo via OCS
         $ocs = $this->ocsClient->getCategories(\OCP\Util::getVersion());
         if ($ocs) {
             foreach ($ocs as $k => $v) {
                 $name = str_replace('ownCloud ', '', $v);
                 $ident = str_replace(' ', '-', urlencode(strtolower($name)));
                 $categories[] = ['id' => $k, 'ident' => $ident, 'displayName' => $name];
             }
         }
     }
     $this->cache->set('listCategories', $categories, 3600);
     return $categories;
 }
Exemple #4
0
 /**
  * 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;
     }
 }
Exemple #5
0
 /**
  * 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;
     }
 }