diff options
Diffstat (limited to 'settings/ajax')
-rw-r--r-- | settings/ajax/apps/categories.php | 30 | ||||
-rw-r--r-- | settings/ajax/apps/index.php | 65 | ||||
-rw-r--r-- | settings/ajax/apps/ocs.php | 68 | ||||
-rw-r--r-- | settings/ajax/updateapp.php | 21 |
4 files changed, 107 insertions, 77 deletions
diff --git a/settings/ajax/apps/categories.php b/settings/ajax/apps/categories.php new file mode 100644 index 00000000000..3bde28be99b --- /dev/null +++ b/settings/ajax/apps/categories.php @@ -0,0 +1,30 @@ +<?php +/** + * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +OC_JSON::checkAdminUser(); + +$l = OC_L10N::get('settings'); + +$categories = array( + array('id' => 0, 'displayName' => (string)$l->t('Enabled') ), + array('id' => 1, 'displayName' => (string)$l->t('Not enabled') ), +); + +if(OC_Config::getValue('appstoreenabled', true)) { + $categories[] = array('id' => 2, 'displayName' => (string)$l->t('Recommended') ); + // apps from external repo via OCS + $ocs = OC_OCSClient::getCategories(); + foreach($ocs as $k => $v) { + $categories[] = array( + 'id' => $k, + 'displayName' => str_replace('ownCloud ', '', $v) + ); + } +} + +OCP\JSON::success($categories); diff --git a/settings/ajax/apps/index.php b/settings/ajax/apps/index.php new file mode 100644 index 00000000000..24fba8be312 --- /dev/null +++ b/settings/ajax/apps/index.php @@ -0,0 +1,65 @@ +<?php +/** + * Copyright (c) 2014 Thomas Müller <deepdiver@owncloud.com> + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +OC_JSON::checkAdminUser(); + +$l = OC_L10N::get('settings'); + +$category = intval($_GET['category']); +$apps = array(); + +switch($category) { + // installed apps + case 0: + $apps = \OC_App::listAllApps(true); + $apps = array_filter($apps, function($app) { + return $app['active']; + }); + break; + // 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 +$apps = array_map(function($app){ + $groups = array(); + if (is_string($app['groups'])) { + $groups = json_decode($app['groups']); + } + $app['groups'] = $groups; + $app['canUnInstall'] = !$app['active'] && $app['removable']; + return $app; +}, $apps); + +OCP\JSON::success(array("apps" => $apps)); diff --git a/settings/ajax/apps/ocs.php b/settings/ajax/apps/ocs.php deleted file mode 100644 index aad0690e01c..00000000000 --- a/settings/ajax/apps/ocs.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php -/** - * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> - * This file is licensed under the Affero General Public License version 3 or - * later. - * See the COPYING-README file. - */ - -OC_JSON::checkAdminUser(); - -$l = \OC::$server->getL10N('settings'); - -if(OC_Config::getValue('appstoreenabled', true)==false) { - OCP\JSON::success(array('type' => 'external', 'data' => array())); -} - -$enabledApps=OC_App::getEnabledApps(); - -if(is_null($enabledApps)) { - OCP\JSON::error(array('data' => array('message' => $l->t('Unable to load list from App Store')))); -} - -$apps=array(); - -// apps from external repo via OCS -$categoryNames=OC_OCSClient::getCategories(); -if(is_array($categoryNames)) { - $categories=array_keys($categoryNames); - $page=0; - $filter='approved'; - $externalApps=OC_OCSClient::getApplications($categories, $page, $filter); - foreach($externalApps as $app) { - // show only external apps that aren't enabled yet - $local=false; - foreach($enabledApps as $a) { - if($a === $app['name']) { - $local=true; - } - } - - if(!$local) { - if($app['preview'] === '') { - $pre=OC_Helper::imagePath('settings', 'trans.png'); - } else { - $pre=$app['preview']; - } - if($app['label'] === 'recommended') { - $label='3rd Party'; - } else { - $label='Recommended'; - } - $apps[]=array( - 'name'=>$app['name'], - 'id'=>$app['id'], - 'active'=>false, - 'description'=>$app['description'], - 'author'=>$app['personid'], - 'license'=>$app['license'], - 'preview'=>$pre, - 'internal'=>false, - 'internallabel'=>$label, - 'update'=>false, - ); - } - } -} - -OCP\JSON::success(array('type' => 'external', 'data' => $apps)); diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php index 6375a41024a..3e28c65285d 100644 --- a/settings/ajax/updateapp.php +++ b/settings/ajax/updateapp.php @@ -12,30 +12,33 @@ if (!array_key_exists('appid', $_POST)) { OCP\JSON::error(array( 'message' => 'No AppId given!' )); - exit; + return; } $appId = $_POST['appid']; if (!is_numeric($appId)) { - $appId = OC_Appconfig::getValue($appId, 'ocsid', null); - $isShipped = OC_App::isShipped($appId); - + $appId = \OC::$server->getAppConfig()->getValue($appId, 'ocsid', null); if ($appId === null) { OCP\JSON::error(array( 'message' => 'No OCS-ID found for app!' )); exit; } -} else { - $isShipped = false; } $appId = OC_App::cleanAppId($appId); -\OC_Config::setValue('maintenance', true); -$result = OC_Installer::updateAppByOCSId($appId, $isShipped); -\OC_Config::setValue('maintenance', false); +$config = \OC::$server->getConfig(); +$config->setSystemValue('maintenance', true); +try { + $result = OC_Installer::updateAppByOCSId($appId); + $config->setSystemValue('maintenance', false); +} catch(Exception $ex) { + $config->setSystemValue('maintenance', false); + OC_JSON::error(array("data" => array( "message" => $ex->getMessage() ))); + return; +} if($result !== false) { OC_JSON::success(array('data' => array('appid' => $appId))); |