Example #1
0
    public function testGetApplicationDownloadUrlSuccessful()
    {
        $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>
				 </meta>
				 <data>
				  <content details="download">
				   <downloadlink>https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip</downloadlink>
				   <mimetype>application/zip</mimetype>
				   <gpgfingerprint></gpgfingerprint>
				   <gpgsignature></gpgsignature>
				   <packagename></packagename>
				   <repository></repository>
				  </content>
				 </data>
				</ocs>
				'));
        $client = $this->getMock('\\OCP\\Http\\Client\\IClient');
        $client->expects($this->once())->method('get')->with('https://api.owncloud.com/v1/content/download/MyId/1', ['timeout' => 5, 'query' => ['version' => '8x1x0x7']])->will($this->returnValue($response));
        $this->clientService->expects($this->once())->method('newClient')->will($this->returnValue($client));
        $expected = ['downloadlink' => 'https://apps.owncloud.com/CONTENT/content-files/166052-files_trashbin.zip'];
        $this->assertSame($expected, $this->ocsClient->getApplicationDownload('MyId', [8, 1, 0, 7]));
    }
 public function testListCategoriesNotCachedWithAppStore()
 {
     $expected = [['id' => 0, 'ident' => 'enabled', 'displayName' => 'Enabled'], ['id' => 1, 'ident' => 'disabled', 'displayName' => 'Not enabled'], ['id' => 0, 'ident' => 'tools', 'displayName' => 'Tools'], ['id' => 1, 'ident' => 'games', 'displayName' => 'Games'], ['id' => 2, 'ident' => 'productivity', 'displayName' => 'Productivity'], ['id' => 3, 'ident' => 'multimedia', 'displayName' => 'Multimedia']];
     $this->cache->expects($this->once())->method('get')->with('listCategories')->will($this->returnValue(null));
     $this->cache->expects($this->once())->method('set')->with('listCategories', $expected, 3600);
     $this->ocsClient->expects($this->once())->method('isAppStoreEnabled')->will($this->returnValue(true));
     $this->ocsClient->expects($this->once())->method('getCategories')->will($this->returnValue(['ownCloud Tools', 'Games', 'ownCloud Productivity', 'Multimedia']));
     $this->assertSame($expected, $this->appSettingsController->listCategories());
 }
	public function testListCategoriesNotCachedWithAppStore() {
		$expected = [
			[
				'id' => 0,
				'displayName' => 'Enabled',
			],
			[
				'id' => 1,
				'displayName' => 'Not enabled',
			],
			[
				'id' => 0,
				'displayName' => 'Tools',
			],
			[
				'id' => 1,
				'displayName' => 'Awesome Games',
			],
			[
				'id' => 2,
				'displayName' => 'PIM',
			],
			[
				'id' => 3,
				'displayName' => 'Papershop',
			],
		];

		$this->cache
			->expects($this->once())
			->method('get')
			->with('listCategories')
			->will($this->returnValue(null));
		$this->cache
			->expects($this->once())
			->method('set')
			->with('listCategories', $expected, 3600);

		$this->ocsClient
			->expects($this->once())
			->method('isAppStoreEnabled')
			->will($this->returnValue(true));
		$this->ocsClient
			->expects($this->once())
			->method('getCategories')
			->will($this->returnValue(
				[
					'ownCloud Tools',
					'Awesome Games',
					'ownCloud PIM',
					'Papershop',
				]
			));

		$this->assertSame($expected, $this->appSettingsController->listCategories());
	}
Example #4
0
 public function testGetAppsDisabled()
 {
     $this->ocsClient->expects($this->any())->method($this->anything())->will($this->returnValue(null));
     $_GET['filter'] = 'disabled';
     $result = $this->api->getApps(['filter' => 'disabled']);
     $this->assertTrue($result->succeeded());
     $data = $result->getData();
     $apps = \OC_App::listAllApps(false, true, $this->ocsClient);
     $list = array();
     foreach ($apps as $app) {
         $list[] = $app['id'];
     }
     $disabled = array_diff($list, \OC_App::getEnabledApps());
     $this->assertEquals(count($disabled), count($data['apps']));
 }
 /**
  * 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 apps in a category
  *
  * @param string $category
  * @param bool $includeUpdateInfo Should we check whether there is an update
  *                                in the app store?
  * @return array
  */
 public function listApps($category = '', $includeUpdateInfo = true)
 {
     $category = $this->getCategory($category);
     $cacheName = 'listApps-' . $category . '-' . (int) $includeUpdateInfo;
     if (!is_null($this->cache->get($cacheName))) {
         $apps = $this->cache->get($cacheName);
     } else {
         switch ($category) {
             // installed apps
             case 0:
                 $apps = $this->getInstalledApps($includeUpdateInfo);
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 $version = \OCP\Util::getVersion();
                 foreach ($apps as $key => $app) {
                     if (!array_key_exists('level', $app) && array_key_exists('ocsid', $app)) {
                         $remoteAppEntry = $this->ocsClient->getApplication($app['ocsid'], $version);
                         if (is_array($remoteAppEntry) && array_key_exists('level', $remoteAppEntry)) {
                             $apps[$key]['level'] = $remoteAppEntry['level'];
                         }
                     }
                 }
                 break;
                 // not-installed apps
             // not-installed apps
             case 1:
                 $apps = \OC_App::listAllApps(true, $includeUpdateInfo, $this->ocsClient);
                 $apps = array_filter($apps, function ($app) {
                     return !$app['active'];
                 });
                 $version = \OCP\Util::getVersion();
                 foreach ($apps as $key => $app) {
                     if (!array_key_exists('level', $app) && array_key_exists('ocsid', $app)) {
                         $remoteAppEntry = $this->ocsClient->getApplication($app['ocsid'], $version);
                         if (is_array($remoteAppEntry) && array_key_exists('level', $remoteAppEntry)) {
                             $apps[$key]['level'] = $remoteAppEntry['level'];
                         }
                     }
                 }
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 break;
             default:
                 $filter = $this->config->getSystemValue('appstore.experimental.enabled', false) ? 'all' : 'approved';
                 $apps = \OC_App::getAppstoreApps($filter, $category, $this->ocsClient);
                 if (!$apps) {
                     $apps = array();
                 } else {
                     // don't list installed apps
                     $installedApps = $this->getInstalledApps(false);
                     $installedApps = array_map(function ($app) {
                         if (isset($app['ocsid'])) {
                             return $app['ocsid'];
                         }
                         return $app['id'];
                     }, $installedApps);
                     $apps = array_filter($apps, function ($app) use($installedApps) {
                         return !in_array($app['id'], $installedApps);
                     });
                     // show tooltip if app is downloaded from remote server
                     $inactiveApps = $this->getInactiveApps();
                     foreach ($apps as &$app) {
                         $app['needsDownload'] = !in_array($app['id'], $inactiveApps);
                     }
                 }
                 // sort by score
                 usort($apps, function ($a, $b) {
                     $a = (int) $a['score'];
                     $b = (int) $b['score'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a > $b ? -1 : 1;
                 });
                 break;
         }
     }
     // fix groups to be an array
     $dependencyAnalyzer = new DependencyAnalyzer(new Platform($this->config), $this->l10n);
     $apps = array_map(function ($app) use($dependencyAnalyzer) {
         // fix groups
         $groups = array();
         if (is_string($app['groups'])) {
             $groups = json_decode($app['groups']);
         }
         $app['groups'] = $groups;
         $app['canUnInstall'] = !$app['active'] && $app['removable'];
         // fix licence vs license
         if (isset($app['license']) && !isset($app['licence'])) {
             $app['licence'] = $app['license'];
         }
         // analyse dependencies
         $missing = $dependencyAnalyzer->analyze($app);
         $app['canInstall'] = empty($missing);
         $app['missingDependencies'] = $missing;
         $app['missingMinOwnCloudVersion'] = !isset($app['dependencies']['owncloud']['@attributes']['min-version']);
         $app['missingMaxOwnCloudVersion'] = !isset($app['dependencies']['owncloud']['@attributes']['max-version']);
         return $app;
     }, $apps);
     $this->cache->set($cacheName, $apps, 300);
     return ['apps' => $apps, 'status' => 'success'];
 }
Example #7
0
 /**
  * Check if an update for the app is available
  * @param string $app
  * @return string|false false or the version number of the update
  *
  * The function will check if an update for a version is available
  */
 public static function isUpdateAvailable($app)
 {
     static $isInstanceReadyForUpdates = null;
     if ($isInstanceReadyForUpdates === null) {
         $installPath = OC_App::getInstallPath();
         if ($installPath === false || $installPath === null) {
             $isInstanceReadyForUpdates = false;
         } else {
             $isInstanceReadyForUpdates = true;
         }
     }
     if ($isInstanceReadyForUpdates === false) {
         return false;
     }
     $ocsid = \OC::$server->getAppConfig()->getValue($app, 'ocsid', '');
     if ($ocsid != '') {
         $ocsClient = new OCSClient(\OC::$server->getHTTPClientService(), \OC::$server->getConfig(), \OC::$server->getLogger());
         $ocsdata = $ocsClient->getApplication($ocsid, \OCP\Util::getVersion());
         $ocsversion = (string) $ocsdata['version'];
         $currentversion = OC_App::getAppVersion($app);
         if (version_compare($ocsversion, $currentversion, '>')) {
             return $ocsversion;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #8
0
 /**
  * @param string $app
  * @return bool
  * @throws Exception if app is not compatible with this version of ownCloud
  * @throws Exception if no app-name was specified
  */
 public static function installApp($app)
 {
     $l = \OC::$server->getL10N('core');
     $config = \OC::$server->getConfig();
     $ocsClient = new OCSClient(\OC::$server->getHTTPClientService(), $config, \OC::$server->getLogger());
     $appData = $ocsClient->getApplication($app, \OCP\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)) {
         $shippedVersion = self::getAppVersion($app);
         if ($appData && version_compare($shippedVersion, $appData['version'], '<')) {
             $app = self::downloadApp($app);
         } else {
             $app = OC_Installer::installShippedApp($app);
         }
     } else {
         // Maybe the app is already installed - compare the version in this
         // case and use the local already installed one.
         // FIXME: This is a horrible hack. I feel sad. The god of code cleanness may forgive me.
         $internalAppId = self::getInternalAppIdByOcs($app);
         if ($internalAppId !== false) {
             if ($appData && version_compare(\OC_App::getAppVersion($internalAppId), $appData['version'], '<')) {
                 $app = self::downloadApp($app);
             } else {
                 self::enable($internalAppId);
                 $app = $internalAppId;
             }
         } else {
             $app = self::downloadApp($app);
         }
     }
     if ($app !== false) {
         // check if the app is compatible with this version of ownCloud
         $info = self::getAppInfo($app);
         $version = \OCP\Util::getVersion();
         if (!self::isAppCompatible($version, $info)) {
             throw new \Exception($l->t('App "%s" cannot be installed because it is not compatible with this version of ownCloud.', array($info['name'])));
         }
         // check for required dependencies
         $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l);
         $missing = $dependencyAnalyzer->analyze($info);
         if (!empty($missing)) {
             $missingMsg = join(PHP_EOL, $missing);
             throw new \Exception($l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', array($info['name'], $missingMsg)));
         }
         $config->setAppValue($app, 'enabled', 'yes');
         if (isset($appData['id'])) {
             $config->setAppValue($app, 'ocsid', $appData['id']);
         }
         \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app));
     } else {
         throw new \Exception($l->t("No app name specified"));
     }
     return $app;
 }