コード例 #1
0
 /**
  * @dataProvider providesOC
  * @param $expectedMissing
  * @param $oc
  */
 function testOC($expectedMissing, $oc)
 {
     $app = array('dependencies' => array());
     if (!is_null($oc)) {
         $app['dependencies']['owncloud'] = $oc;
     }
     $missing = $this->analyser->analyze($app);
     $this->assertTrue(is_array($missing));
     $this->assertEquals($expectedMissing, $missing);
 }
コード例 #2
0
ファイル: app.php プロジェクト: kebenxiaoming/owncloudRedis
 /**
  * @param mixed $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();
     $appData = OC_OCSClient::getApplication($app);
     // 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 = OC_Util::getVersion();
         if (!self::isAppCompatible($version, $info)) {
             throw new \Exception($l->t('App \\"%s\\" can\'t 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($app);
         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;
 }
コード例 #3
0
 /**
  * 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'];
 }
コード例 #4
0
 /**
  * Get all available apps in a category
  *
  * @param int $category
  * @return array
  */
 public function listApps($category = 0)
 {
     if (!is_null($this->cache->get('listApps-' . $category))) {
         $apps = $this->cache->get('listApps-' . $category);
     } else {
         switch ($category) {
             // installed apps
             case 0:
                 $apps = $this->getInstalledApps();
                 usort($apps, function ($a, $b) {
                     $a = (string) $a['name'];
                     $b = (string) $b['name'];
                     if ($a === $b) {
                         return 0;
                     }
                     return $a < $b ? -1 : 1;
                 });
                 break;
                 // not-installed apps
             // not-installed apps
             case 1:
                 $apps = \OC_App::listAllApps(true);
                 $apps = array_filter($apps, function ($app) {
                     return !$app['active'];
                 });
                 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);
                 if (!$apps) {
                     $apps = array();
                 } else {
                     // don't list installed apps
                     $installedApps = $this->getInstalledApps();
                     $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);
                     });
                 }
                 // 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;
         return $app;
     }, $apps);
     $this->cache->set('listApps-' . $category, $apps, 300);
     return ['apps' => $apps, 'status' => 'success'];
 }
コード例 #5
0
 /**
  * Get all available categories
  * @param int $category
  * @return array
  */
 public function listApps($category = 0)
 {
     if (!is_null($this->cache->get('listApps-' . $category))) {
         $apps = $this->cache->get('listApps-' . $category);
     } else {
         switch ($category) {
             // installed apps
             case 0:
                 $apps = \OC_App::listAllApps(true);
                 $apps = array_filter($apps, function ($app) {
                     return $app['active'];
                 });
                 break;
                 // not-installed apps
             // not-installed apps
             case 1:
                 $apps = \OC_App::listAllApps(true);
                 $apps = array_filter($apps, function ($app) {
                     return !$app['active'];
                 });
                 break;
             default:
                 if ($category === 2) {
                     $apps = \OC_App::getAppstoreApps('approved');
                     $apps = array_filter($apps, function ($app) {
                         return isset($app['internalclass']) && $app['internalclass'] === 'recommendedapp';
                     });
                 } else {
                     $apps = \OC_App::getAppstoreApps('approved', $category);
                 }
                 if (!$apps) {
                     $apps = array();
                 }
                 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;
         return $app;
     }, $apps);
     $this->cache->set('listApps-' . $category, $apps, 300);
     return ['apps' => $apps, 'status' => 'success'];
 }