/** * @param string $app * @return int */ public static function downloadApp($app) { $appData = OC_OCSClient::getApplication($app); $download = OC_OCSClient::getApplicationDownload($app, 1); if (isset($download['downloadlink']) and $download['downloadlink'] != '') { // Replace spaces in download link without encoding entire URL $download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']); $info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appData); $app = OC_Installer::installApp($info); } return $app; }
/** * @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")); } }
/** * update an app by it's id * @param integer $ocsid * @return bool * @throws Exception */ public static function updateAppByOCSId($ocsid) { $appdata = OC_OCSClient::getApplication($ocsid); $download = OC_OCSClient::getApplicationDownload($ocsid, 1); if (isset($download['downloadlink']) && trim($download['downloadlink']) !== '') { $download['downloadlink'] = str_replace(' ', '%20', $download['downloadlink']); $info = array('source' => 'http', 'href' => $download['downloadlink'], 'appdata' => $appdata); } else { throw new \Exception('Could not fetch app info!'); } return self::updateApp($info); }
/** * @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 { $download = OC_OCSClient::getApplicationDownload($app, 1); if (isset($download['downloadlink']) and $download['downloadlink'] != '') { $app = OC_Installer::installApp(array('source' => 'http', 'href' => $download['downloadlink'])); } } } 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 $version[0] > $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'); return true; } } else { return false; } }