/** * @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; }
/** * 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_Appconfig::getValue($app, 'ocsid', ''); if ($ocsid != '') { $ocsdata = OC_OCSClient::getApplication($ocsid); $ocsversion = (string) $ocsdata['version']; $currentversion = OC_App::getAppVersion($app); if (version_compare($ocsversion, $currentversion, '>')) { return $ocsversion; } else { return false; } } else { return false; } }
/** * @brief enables an app * @param mixed $app app * @throws \Exception * @return void * * This function set an app as enabled in appconfig. */ public static function enable($app) { self::$enabledAppsCache = array(); // flush if (!OC_Installer::isInstalled($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)) { $app = OC_Installer::installShippedApp($app); } else { $appdata = OC_OCSClient::getApplication($app, \OC_Util::getVersion()); $download = OC_OCSClient::getApplicationDownload($app, 1, \OC_Util::getVersion()); if (isset($download['downloadlink']) and $download['downloadlink'] != '') { $info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appdata); $app = OC_Installer::installApp($info); } } } $l = OC_L10N::get('core'); if ($app !== false) { // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); $version = OC_Util::getVersion(); if (!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) { throw new \Exception($l->t("App \"%s\" can't be installed because it is not compatible with this version of ownCloud.", array($info['name']))); } else { OC_Appconfig::setValue($app, 'enabled', 'yes'); if (isset($appdata['id'])) { OC_Appconfig::setValue($app, 'ocsid', $appdata['id']); } \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); } } else { throw new \Exception($l->t("No app name specified")); } }
/** * @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'); $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 { $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']))); } else { OC_Appconfig::setValue($app, 'enabled', 'yes'); if (isset($appData['id'])) { OC_Appconfig::setValue($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; }
/** * @brief Check if an update for the app is available * @param $name name of the application * @return boolean 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) { $ocsid = OC_Appconfig::getValue($app, 'ocsid', ''); if ($ocsid != '') { $ocsdata = OC_OCSClient::getApplication($ocsid, \OC_Util::getVersion()); $ocsversion = (string) $ocsdata['version']; $currentversion = OC_App::getAppVersion($app); if ($ocsversion != $currentversion) { return $ocsversion; } else { return false; } } else { return false; } }
/** * @brief enables an app * @param mixed $app app * @return bool * * This function set an app as enabled in appconfig. */ public static function enable($app) { if (!OC_Installer::isInstalled($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)) { $app = OC_Installer::installShippedApp($app); } else { $appdata = OC_OCSClient::getApplication($app); $download = OC_OCSClient::getApplicationDownload($app, 1); if (isset($download['downloadlink']) and $download['downloadlink'] != '') { $info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appdata); $app = OC_Installer::installApp($info); } } } if ($app !== false) { // check if the app is compatible with this version of ownCloud $info = OC_App::getAppInfo($app); $version = OC_Util::getVersion(); if (!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) { OC_Log::write('core', 'App "' . $info['name'] . '" can\'t be installed because it is' . ' not compatible with this version of ownCloud', OC_Log::ERROR); return false; } else { OC_Appconfig::setValue($app, 'enabled', 'yes'); if (isset($appdata['id'])) { OC_Appconfig::setValue($app, 'ocsid', $appdata['id']); } return true; } } else { return false; } }