summaryrefslogtreecommitdiffstats
path: root/lib/private/legacy/app.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/legacy/app.php')
-rw-r--r--lib/private/legacy/app.php242
1 files changed, 57 insertions, 185 deletions
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index d25534aa822..1db1ce74cdc 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -1,6 +1,7 @@
<?php
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
*
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
* @author Bart Visscher <bartv@thisnet.nl>
@@ -326,24 +327,59 @@ class OC_App {
/**
* enables an app
*
- * @param mixed $app app
+ * @param string $appId
* @param array $groups (optional) when set, only these groups will have access to the app
* @throws \Exception
* @return void
*
* This function set an app as enabled in appconfig.
*/
- public static function enable($app, $groups = null) {
+ public function enable($appId,
+ $groups = null) {
self::$enabledAppsCache = []; // flush
- if (!Installer::isInstalled($app)) {
- $app = self::installApp($app);
+ $l = \OC::$server->getL10N('core');
+ $config = \OC::$server->getConfig();
+
+ // Check if app is already downloaded
+ $installer = new Installer();
+ $isDownloaded = $installer->isDownloaded($appId);
+
+ if(!$isDownloaded) {
+ $state = $installer->downloadApp(
+ $appId,
+ new \OC\App\AppStore\Fetcher\AppFetcher(
+ \OC::$server->getAppDataDir('appstore'),
+ \OC::$server->getHTTPClientService(),
+ new \OC\AppFramework\Utility\TimeFactory(),
+ $config
+ ),
+ \OC::$server->getHTTPClientService(),
+ \OC::$server->getTempManager(),
+ \OC::$server->getLogger()
+ );
+
+ if($state !== true) {
+ throw new \Exception(
+ sprintf(
+ 'Could not download app with id: %s',
+ $appId
+ )
+ );
+ }
+ }
+
+ if (!Installer::isInstalled($appId)) {
+ $appId = self::installApp(
+ $appId,
+ $config,
+ $l
+ );
+ $installer->installApp($appId);
} else {
// check for required dependencies
- $config = \OC::$server->getConfig();
- $l = \OC::$server->getL10N('core');
- $info = self::getAppInfo($app);
-
+ $info = self::getAppInfo($appId);
self::checkAppDependencies($config, $l, $info);
+ $installer->installApp($appId);
}
$appManager = \OC::$server->getAppManager();
@@ -356,42 +392,21 @@ class OC_App {
$groupsList[] = $groupManager->get($group);
}
}
- $appManager->enableAppForGroups($app, $groupsList);
+ $appManager->enableAppForGroups($appId, $groupsList);
} else {
- $appManager->enableApp($app);
+ $appManager->enableApp($appId);
}
- $info = self::getAppInfo($app);
+ $info = self::getAppInfo($appId);
if(isset($info['settings']) && is_array($info['settings'])) {
- $appPath = self::getAppPath($app);
- self::registerAutoloading($app, $appPath);
+ $appPath = self::getAppPath($appId);
+ self::registerAutoloading($appId, $appPath);
\OC::$server->getSettingsManager()->setupSettings($info['settings']);
}
}
/**
* @param string $app
- * @return int
- */
- private static function downloadApp($app) {
- $ocsClient = new OCSClient(
- \OC::$server->getHTTPClientService(),
- \OC::$server->getConfig(),
- \OC::$server->getLogger()
- );
- $appData = $ocsClient->getApplication($app, \OCP\Util::getVersion());
- $download = $ocsClient->getApplicationDownload($app, \OCP\Util::getVersion());
- 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 = Installer::installApp($info);
- }
- return $app;
- }
-
- /**
- * @param string $app
* @return bool
*/
public static function removeApp($app) {
@@ -409,11 +424,6 @@ class OC_App {
* @throws Exception
*/
public static function disable($app) {
- // Convert OCS ID to regular application identifier
- if(self::getInternalAppIdByOcs($app) !== false) {
- $app = self::getInternalAppIdByOcs($app);
- }
-
// flush
self::$enabledAppsCache = array();
@@ -613,18 +623,6 @@ class OC_App {
return false;
}
-
- /**
- * check if an app's directory is writable
- *
- * @param string $appId
- * @return bool
- */
- public static function isAppDirWritable($appId) {
- $path = self::getAppPath($appId);
- return ($path !== false) ? is_writable($path) : false;
- }
-
/**
* Get the path for the given app on the access
* If the app is defined in multiple directories, the first one is taken. (false if not found)
@@ -837,20 +835,11 @@ class OC_App {
/**
* List all apps, this is used in apps.php
*
- * @param bool $onlyLocal
- * @param bool $includeUpdateInfo Should we check whether there is an update
- * in the app store?
- * @param OCSClient $ocsClient
* @return array
*/
- public static function listAllApps($onlyLocal = false,
- $includeUpdateInfo = true,
- OCSClient $ocsClient) {
+ public function listAllApps() {
$installedApps = OC_App::getAllApps();
- //TODO which apps do we want to blacklist and how do we integrate
- // blacklisting with the multi apps folder feature?
-
//we don't want to show configuration for these
$blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps();
$appList = array();
@@ -893,8 +882,6 @@ class OC_App {
$info['removable'] = true;
}
- $info['update'] = ($includeUpdateInfo) ? Installer::isUpdateAvailable($app) : null;
-
$appPath = self::getAppPath($app);
if($appPath !== false) {
$appIcon = $appPath . '/img/' . $app . '.svg';
@@ -926,29 +913,8 @@ class OC_App {
$appList[] = $info;
}
}
- if ($onlyLocal) {
- $remoteApps = [];
- } else {
- $remoteApps = OC_App::getAppstoreApps('approved', null, $ocsClient);
- }
- if ($remoteApps) {
- // Remove duplicates
- foreach ($appList as $app) {
- foreach ($remoteApps AS $key => $remote) {
- if ($app['name'] === $remote['name'] ||
- (isset($app['ocsid']) &&
- $app['ocsid'] === $remote['id'])
- ) {
- unset($remoteApps[$key]);
- }
- }
- }
- $combinedApps = array_merge($appList, $remoteApps);
- } else {
- $combinedApps = $appList;
- }
- return $combinedApps;
+ return $appList;
}
/**
@@ -966,70 +932,6 @@ class OC_App {
return false;
}
- /**
- * Get a list of all apps on the appstore
- * @param string $filter
- * @param string|null $category
- * @param OCSClient $ocsClient
- * @return array|bool multi-dimensional array of apps.
- * Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description
- */
- public static function getAppstoreApps($filter = 'approved',
- $category = null,
- OCSClient $ocsClient) {
- $categories = [$category];
-
- if (is_null($category)) {
- $categoryNames = $ocsClient->getCategories(\OCP\Util::getVersion());
- if (is_array($categoryNames)) {
- // Check that categories of apps were retrieved correctly
- if (!$categories = array_keys($categoryNames)) {
- return false;
- }
- } else {
- return false;
- }
- }
-
- $page = 0;
- $remoteApps = $ocsClient->getApplications($categories, $page, $filter, \OCP\Util::getVersion());
- $apps = [];
- $i = 0;
- $l = \OC::$server->getL10N('core');
- foreach ($remoteApps as $app) {
- $potentialCleanId = self::getInternalAppIdByOcs($app['id']);
- // enhance app info (for example the description)
- $apps[$i] = OC_App::parseAppInfo($app);
- $apps[$i]['author'] = $app['personid'];
- $apps[$i]['ocs_id'] = $app['id'];
- $apps[$i]['internal'] = 0;
- $apps[$i]['active'] = ($potentialCleanId !== false) ? self::isEnabled($potentialCleanId) : false;
- $apps[$i]['update'] = false;
- $apps[$i]['groups'] = false;
- $apps[$i]['score'] = $app['score'];
- $apps[$i]['removable'] = false;
- if ($app['label'] == 'recommended') {
- $apps[$i]['internallabel'] = (string)$l->t('Recommended');
- $apps[$i]['internalclass'] = 'recommendedapp';
- }
-
- // Apps from the appstore are always assumed to be compatible with the
- // the current release as the initial filtering is done on the appstore
- $apps[$i]['dependencies']['owncloud']['@attributes']['min-version'] = implode('.', \OCP\Util::getVersion());
- $apps[$i]['dependencies']['owncloud']['@attributes']['max-version'] = implode('.', \OCP\Util::getVersion());
-
- $i++;
- }
-
-
-
- if (empty($apps)) {
- return false;
- } else {
- return $apps;
- }
- }
-
public static function shouldUpgrade($app) {
$versions = self::getAppVersions();
$currentVersion = OC_App::getAppVersion($app);
@@ -1132,46 +1034,16 @@ class OC_App {
/**
* @param string $app
+ * @param \OCP\IConfig $config
+ * @param \OCP\IL10N $l
* @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) {
- $appName = $app; // $app will be overwritten, preserve name for error logging
- $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);
- }
- }
-
+ public function installApp($app,
+ \OCP\IConfig $config,
+ \OCP\IL10N $l) {
if ($app !== false) {
// check if the app is compatible with this version of ownCloud
$info = self::getAppInfo($app);