1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Joas Schilling <[email protected]> |
4
|
|
|
* @author Lukas Reschke <[email protected]> |
5
|
|
|
* @author Morris Jobke <[email protected]> |
6
|
|
|
* @author Roeland Jago Douma <[email protected]> |
7
|
|
|
* @author Tom Needham <[email protected]> |
8
|
|
|
* |
9
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc. |
10
|
|
|
* @license AGPL-3.0 |
11
|
|
|
* |
12
|
|
|
* This code is free software: you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
14
|
|
|
* as published by the Free Software Foundation. |
15
|
|
|
* |
16
|
|
|
* This program is distributed in the hope that it will be useful, |
17
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
18
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19
|
|
|
* GNU Affero General Public License for more details. |
20
|
|
|
* |
21
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
22
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
23
|
|
|
* |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace OCA\Provisioning_API; |
27
|
|
|
|
28
|
|
|
use OC\OCSClient; |
29
|
|
|
use \OC_OCS_Result; |
30
|
|
|
use \OC_App; |
31
|
|
|
|
32
|
|
|
class Apps { |
33
|
|
|
/** @var \OCP\App\IAppManager */ |
34
|
|
|
private $appManager; |
35
|
|
|
/** @var OCSClient */ |
36
|
|
|
private $ocsClient; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param \OCP\App\IAppManager $appManager |
40
|
|
|
*/ |
41
|
7 |
|
public function __construct(\OCP\App\IAppManager $appManager, |
42
|
|
|
OCSClient $ocsClient) { |
43
|
7 |
|
$this->appManager = $appManager; |
44
|
7 |
|
$this->ocsClient = $ocsClient; |
45
|
7 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $parameters |
49
|
|
|
* @return OC_OCS_Result |
50
|
|
|
*/ |
51
|
4 |
|
public function getApps($parameters) { |
|
|
|
|
52
|
4 |
|
$apps = OC_App::listAllApps(false, true, $this->ocsClient); |
53
|
4 |
|
$list = []; |
54
|
4 |
|
foreach($apps as $app) { |
55
|
4 |
|
$list[] = $app['id']; |
56
|
4 |
|
} |
57
|
4 |
|
$filter = isset($_GET['filter']) ? $_GET['filter'] : false; |
58
|
4 |
|
if($filter){ |
59
|
|
|
switch($filter){ |
60
|
3 |
|
case 'enabled': |
61
|
1 |
|
return new OC_OCS_Result(array('apps' => \OC_App::getEnabledApps())); |
62
|
|
|
break; |
|
|
|
|
63
|
2 |
|
case 'disabled': |
64
|
1 |
|
$enabled = OC_App::getEnabledApps(); |
65
|
1 |
|
return new OC_OCS_Result(array('apps' => array_diff($list, $enabled))); |
66
|
|
|
break; |
|
|
|
|
67
|
1 |
|
default: |
68
|
|
|
// Invalid filter variable |
69
|
1 |
|
return new OC_OCS_Result(null, 101); |
70
|
|
|
break; |
|
|
|
|
71
|
1 |
|
} |
72
|
|
|
|
73
|
|
|
} else { |
74
|
1 |
|
return new OC_OCS_Result(array('apps' => $list)); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param array $parameters |
80
|
|
|
* @return OC_OCS_Result |
81
|
|
|
*/ |
82
|
2 |
|
public function getAppInfo($parameters) { |
83
|
2 |
|
$app = $parameters['appid']; |
84
|
2 |
|
$info = \OCP\App::getAppInfo($app); |
85
|
2 |
|
if(!is_null($info)) { |
86
|
1 |
|
return new OC_OCS_Result(OC_App::getAppInfo($app)); |
87
|
|
|
} else { |
88
|
1 |
|
return new OC_OCS_Result(null, \OCP\API::RESPOND_NOT_FOUND, 'The request app was not found'); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param array $parameters |
94
|
|
|
* @return OC_OCS_Result |
95
|
|
|
*/ |
96
|
|
|
public function enable($parameters) { |
97
|
|
|
$app = $parameters['appid']; |
98
|
|
|
$this->appManager->enableApp($app); |
99
|
|
|
return new OC_OCS_Result(null, 100); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param array $parameters |
104
|
|
|
* @return OC_OCS_Result |
105
|
|
|
*/ |
106
|
|
|
public function disable($parameters) { |
107
|
|
|
$app = $parameters['appid']; |
108
|
|
|
$this->appManager->disableApp($app); |
109
|
|
|
return new OC_OCS_Result(null, 100); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.