Esempio n. 1
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 = 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);
         if (!is_array($info)) {
             throw new \Exception($l->t('App "%s" cannot be installed because appinfo file cannot be read.', [$info['name']]));
         }
         $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;
 }
Esempio n. 2
0
 /**
  * Installs shipped apps
  *
  * This function installs all apps found in the 'apps' directory that should be enabled by default;
  * @param bool $softErrors When updating we ignore errors and simply log them, better to have a
  *                         working ownCloud at the end instead of an aborted update.
  * @return array Array of error messages (appid => Exception)
  */
 public static function installShippedApps($softErrors = false)
 {
     $errors = [];
     foreach (\OC::$APPSROOTS as $app_dir) {
         if ($dir = opendir($app_dir['path'])) {
             while (false !== ($filename = readdir($dir))) {
                 if (substr($filename, 0, 1) != '.' and is_dir($app_dir['path'] . "/{$filename}")) {
                     if (file_exists($app_dir['path'] . "/{$filename}/appinfo/info.xml")) {
                         if (!Installer::isInstalled($filename)) {
                             $info = OC_App::getAppInfo($filename);
                             $enabled = isset($info['default_enable']);
                             if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
                                 if ($softErrors) {
                                     try {
                                         Installer::installShippedApp($filename);
                                     } catch (\Doctrine\DBAL\Exception\TableExistsException $e) {
                                         $errors[$filename] = $e;
                                         continue;
                                     }
                                 } else {
                                     Installer::installShippedApp($filename);
                                 }
                                 \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
                             }
                         }
                     }
                 }
             }
             closedir($dir);
         }
     }
     return $errors;
 }