@@ -56,17 +56,17 @@ |
||
56 | 56 | $result = ['wide' => [], 'exact' => []]; |
57 | 57 | |
58 | 58 | $groups = $this->groupManager->search($search, $limit, $offset); |
59 | - $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
59 | + $groupIds = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
60 | 60 | |
61 | 61 | if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
62 | 62 | $hasMoreResults = true; |
63 | 63 | } |
64 | 64 | |
65 | - $userGroups = []; |
|
65 | + $userGroups = []; |
|
66 | 66 | if (!empty($groups) && $this->shareWithGroupOnly) { |
67 | 67 | // Intersect all the groups that match with the groups this user is a member of |
68 | 68 | $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
69 | - $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
69 | + $userGroups = array_map(function(IGroup $group) { return $group->getGID(); }, $userGroups); |
|
70 | 70 | $groupIds = array_intersect($groupIds, $userGroups); |
71 | 71 | } |
72 | 72 |
@@ -33,92 +33,92 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class GroupPlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
37 | - protected $shareWithGroupOnly; |
|
36 | + protected $shareeEnumeration; |
|
37 | + protected $shareWithGroupOnly; |
|
38 | 38 | |
39 | - /** @var IGroupManager */ |
|
40 | - private $groupManager; |
|
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var IUserSession */ |
|
44 | - private $userSession; |
|
39 | + /** @var IGroupManager */ |
|
40 | + private $groupManager; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var IUserSession */ |
|
44 | + private $userSession; |
|
45 | 45 | |
46 | - public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) { |
|
47 | - $this->groupManager = $groupManager; |
|
48 | - $this->config = $config; |
|
49 | - $this->userSession = $userSession; |
|
46 | + public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) { |
|
47 | + $this->groupManager = $groupManager; |
|
48 | + $this->config = $config; |
|
49 | + $this->userSession = $userSession; |
|
50 | 50 | |
51 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
52 | - $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
53 | - } |
|
51 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
52 | + $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes'; |
|
53 | + } |
|
54 | 54 | |
55 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | - $hasMoreResults = false; |
|
57 | - $result = ['wide' => [], 'exact' => []]; |
|
55 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
56 | + $hasMoreResults = false; |
|
57 | + $result = ['wide' => [], 'exact' => []]; |
|
58 | 58 | |
59 | - $groups = $this->groupManager->search($search, $limit, $offset); |
|
60 | - $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
59 | + $groups = $this->groupManager->search($search, $limit, $offset); |
|
60 | + $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups); |
|
61 | 61 | |
62 | - if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
|
63 | - $hasMoreResults = true; |
|
64 | - } |
|
62 | + if (!$this->shareeEnumeration || sizeof($groups) < $limit) { |
|
63 | + $hasMoreResults = true; |
|
64 | + } |
|
65 | 65 | |
66 | - $userGroups = []; |
|
67 | - if (!empty($groups) && $this->shareWithGroupOnly) { |
|
68 | - // Intersect all the groups that match with the groups this user is a member of |
|
69 | - $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
70 | - $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
71 | - $groupIds = array_intersect($groupIds, $userGroups); |
|
72 | - } |
|
66 | + $userGroups = []; |
|
67 | + if (!empty($groups) && $this->shareWithGroupOnly) { |
|
68 | + // Intersect all the groups that match with the groups this user is a member of |
|
69 | + $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser()); |
|
70 | + $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups); |
|
71 | + $groupIds = array_intersect($groupIds, $userGroups); |
|
72 | + } |
|
73 | 73 | |
74 | - $lowerSearch = strtolower($search); |
|
75 | - foreach ($groups as $group) { |
|
76 | - // FIXME: use a more efficient approach |
|
77 | - $gid = $group->getGID(); |
|
78 | - if (!in_array($gid, $groupIds)) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
82 | - $result['exact'][] = [ |
|
83 | - 'label' => $group->getDisplayName(), |
|
84 | - 'value' => [ |
|
85 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
86 | - 'shareWith' => $gid, |
|
87 | - ], |
|
88 | - ]; |
|
89 | - } else { |
|
90 | - $result['wide'][] = [ |
|
91 | - 'label' => $group->getDisplayName(), |
|
92 | - 'value' => [ |
|
93 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
94 | - 'shareWith' => $gid, |
|
95 | - ], |
|
96 | - ]; |
|
97 | - } |
|
98 | - } |
|
74 | + $lowerSearch = strtolower($search); |
|
75 | + foreach ($groups as $group) { |
|
76 | + // FIXME: use a more efficient approach |
|
77 | + $gid = $group->getGID(); |
|
78 | + if (!in_array($gid, $groupIds)) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) { |
|
82 | + $result['exact'][] = [ |
|
83 | + 'label' => $group->getDisplayName(), |
|
84 | + 'value' => [ |
|
85 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
86 | + 'shareWith' => $gid, |
|
87 | + ], |
|
88 | + ]; |
|
89 | + } else { |
|
90 | + $result['wide'][] = [ |
|
91 | + 'label' => $group->getDisplayName(), |
|
92 | + 'value' => [ |
|
93 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
94 | + 'shareWith' => $gid, |
|
95 | + ], |
|
96 | + ]; |
|
97 | + } |
|
98 | + } |
|
99 | 99 | |
100 | - if ($offset === 0 && empty($result['exact'])) { |
|
101 | - // On page one we try if the search result has a direct hit on the |
|
102 | - // user id and if so, we add that to the exact match list |
|
103 | - $group = $this->groupManager->get($search); |
|
104 | - if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
105 | - array_push($result['exact'], [ |
|
106 | - 'label' => $group->getDisplayName(), |
|
107 | - 'value' => [ |
|
108 | - 'shareType' => Share::SHARE_TYPE_GROUP, |
|
109 | - 'shareWith' => $group->getGID(), |
|
110 | - ], |
|
111 | - ]); |
|
112 | - } |
|
113 | - } |
|
100 | + if ($offset === 0 && empty($result['exact'])) { |
|
101 | + // On page one we try if the search result has a direct hit on the |
|
102 | + // user id and if so, we add that to the exact match list |
|
103 | + $group = $this->groupManager->get($search); |
|
104 | + if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) { |
|
105 | + array_push($result['exact'], [ |
|
106 | + 'label' => $group->getDisplayName(), |
|
107 | + 'value' => [ |
|
108 | + 'shareType' => Share::SHARE_TYPE_GROUP, |
|
109 | + 'shareWith' => $group->getGID(), |
|
110 | + ], |
|
111 | + ]); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - if (!$this->shareeEnumeration) { |
|
116 | - $result['wide'] = []; |
|
117 | - } |
|
115 | + if (!$this->shareeEnumeration) { |
|
116 | + $result['wide'] = []; |
|
117 | + } |
|
118 | 118 | |
119 | - $type = new SearchResultType('groups'); |
|
120 | - $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
119 | + $type = new SearchResultType('groups'); |
|
120 | + $searchResult->addResultSet($type, $result['wide'], $result['exact']); |
|
121 | 121 | |
122 | - return $hasMoreResults; |
|
123 | - } |
|
122 | + return $hasMoreResults; |
|
123 | + } |
|
124 | 124 | } |
@@ -54,7 +54,7 @@ |
||
54 | 54 | try { |
55 | 55 | $client = $this->clientService->newClient(); |
56 | 56 | $response = $client->get( |
57 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
57 | + $lookupServerUrl.'/users?search='.urlencode($search), |
|
58 | 58 | [ |
59 | 59 | 'timeout' => 10, |
60 | 60 | 'connect_timeout' => 3, |
@@ -33,54 +33,54 @@ |
||
33 | 33 | |
34 | 34 | class LookupPlugin implements ISearchPlugin { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
38 | - /** @var IClientService */ |
|
39 | - private $clientService; |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | + /** @var IClientService */ |
|
39 | + private $clientService; |
|
40 | 40 | |
41 | - public function __construct(IConfig $config, IClientService $clientService) { |
|
42 | - $this->config = $config; |
|
43 | - $this->clientService = $clientService; |
|
44 | - } |
|
41 | + public function __construct(IConfig $config, IClientService $clientService) { |
|
42 | + $this->config = $config; |
|
43 | + $this->clientService = $clientService; |
|
44 | + } |
|
45 | 45 | |
46 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
47 | - if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') { |
|
48 | - return false; |
|
49 | - } |
|
46 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
47 | + if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') { |
|
48 | + return false; |
|
49 | + } |
|
50 | 50 | |
51 | - $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
52 | - $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
53 | - $result = ['wide' => [], 'exact' => []]; |
|
51 | + $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
52 | + $lookupServerUrl = rtrim($lookupServerUrl, '/'); |
|
53 | + $result = ['wide' => [], 'exact' => []]; |
|
54 | 54 | |
55 | - try { |
|
56 | - $client = $this->clientService->newClient(); |
|
57 | - $response = $client->get( |
|
58 | - $lookupServerUrl . '/users?search=' . urlencode($search), |
|
59 | - [ |
|
60 | - 'timeout' => 10, |
|
61 | - 'connect_timeout' => 3, |
|
62 | - ] |
|
63 | - ); |
|
55 | + try { |
|
56 | + $client = $this->clientService->newClient(); |
|
57 | + $response = $client->get( |
|
58 | + $lookupServerUrl . '/users?search=' . urlencode($search), |
|
59 | + [ |
|
60 | + 'timeout' => 10, |
|
61 | + 'connect_timeout' => 3, |
|
62 | + ] |
|
63 | + ); |
|
64 | 64 | |
65 | - $body = json_decode($response->getBody(), true); |
|
65 | + $body = json_decode($response->getBody(), true); |
|
66 | 66 | |
67 | - $result = []; |
|
68 | - foreach ($body as $lookup) { |
|
69 | - $result[] = [ |
|
70 | - 'label' => $lookup['federationId'], |
|
71 | - 'value' => [ |
|
72 | - 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
73 | - 'shareWith' => $lookup['federationId'], |
|
74 | - ], |
|
75 | - 'extra' => $lookup, |
|
76 | - ]; |
|
77 | - } |
|
78 | - } catch (\Exception $e) { |
|
79 | - } |
|
67 | + $result = []; |
|
68 | + foreach ($body as $lookup) { |
|
69 | + $result[] = [ |
|
70 | + 'label' => $lookup['federationId'], |
|
71 | + 'value' => [ |
|
72 | + 'shareType' => Share::SHARE_TYPE_REMOTE, |
|
73 | + 'shareWith' => $lookup['federationId'], |
|
74 | + ], |
|
75 | + 'extra' => $lookup, |
|
76 | + ]; |
|
77 | + } |
|
78 | + } catch (\Exception $e) { |
|
79 | + } |
|
80 | 80 | |
81 | - $type = new SearchResultType('lookup'); |
|
82 | - $searchResult->addResultSet($type, $result, []); |
|
81 | + $type = new SearchResultType('lookup'); |
|
82 | + $searchResult->addResultSet($type, $result, []); |
|
83 | 83 | |
84 | - return false; |
|
85 | - } |
|
84 | + return false; |
|
85 | + } |
|
86 | 86 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | parent::__construct(); |
142 | 142 | $this->webRoot = $webRoot; |
143 | 143 | |
144 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
144 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
145 | 145 | return $c; |
146 | 146 | }); |
147 | 147 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
152 | 152 | |
153 | 153 | |
154 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
154 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
155 | 155 | return new PreviewManager( |
156 | 156 | $c->getConfig(), |
157 | 157 | $c->getRootFolder(), |
@@ -162,13 +162,13 @@ discard block |
||
162 | 162 | }); |
163 | 163 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
164 | 164 | |
165 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
165 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
166 | 166 | return new \OC\Preview\Watcher( |
167 | 167 | $c->getAppDataDir('preview') |
168 | 168 | ); |
169 | 169 | }); |
170 | 170 | |
171 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
171 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
172 | 172 | $view = new View(); |
173 | 173 | $util = new Encryption\Util( |
174 | 174 | $view, |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | ); |
187 | 187 | }); |
188 | 188 | |
189 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
189 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
190 | 190 | $util = new Encryption\Util( |
191 | 191 | new View(), |
192 | 192 | $c->getUserManager(), |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | ); |
201 | 201 | }); |
202 | 202 | |
203 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
203 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
204 | 204 | $view = new View(); |
205 | 205 | $util = new Encryption\Util( |
206 | 206 | $view, |
@@ -211,32 +211,32 @@ discard block |
||
211 | 211 | |
212 | 212 | return new Encryption\Keys\Storage($view, $util); |
213 | 213 | }); |
214 | - $this->registerService('TagMapper', function (Server $c) { |
|
214 | + $this->registerService('TagMapper', function(Server $c) { |
|
215 | 215 | return new TagMapper($c->getDatabaseConnection()); |
216 | 216 | }); |
217 | 217 | |
218 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
218 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
219 | 219 | $tagMapper = $c->query('TagMapper'); |
220 | 220 | return new TagManager($tagMapper, $c->getUserSession()); |
221 | 221 | }); |
222 | 222 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
223 | 223 | |
224 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
224 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
225 | 225 | $config = $c->getConfig(); |
226 | 226 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
227 | 227 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
228 | 228 | $factory = new $factoryClass($this); |
229 | 229 | return $factory; |
230 | 230 | }); |
231 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
231 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
232 | 232 | return $c->query('SystemTagManagerFactory')->getManager(); |
233 | 233 | }); |
234 | 234 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
235 | 235 | |
236 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
236 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
237 | 237 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
238 | 238 | }); |
239 | - $this->registerService('RootFolder', function (Server $c) { |
|
239 | + $this->registerService('RootFolder', function(Server $c) { |
|
240 | 240 | $manager = \OC\Files\Filesystem::getMountManager(null); |
241 | 241 | $view = new View(); |
242 | 242 | $root = new Root( |
@@ -257,37 +257,37 @@ discard block |
||
257 | 257 | }); |
258 | 258 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
259 | 259 | |
260 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
261 | - return new LazyRoot(function () use ($c) { |
|
260 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
261 | + return new LazyRoot(function() use ($c) { |
|
262 | 262 | return $c->query('RootFolder'); |
263 | 263 | }); |
264 | 264 | }); |
265 | 265 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
266 | 266 | |
267 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
267 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
268 | 268 | $config = $c->getConfig(); |
269 | 269 | return new \OC\User\Manager($config); |
270 | 270 | }); |
271 | 271 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
272 | 272 | |
273 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
273 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
274 | 274 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
275 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
275 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
276 | 276 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
277 | 277 | }); |
278 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
278 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
279 | 279 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
280 | 280 | }); |
281 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
281 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
282 | 282 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
283 | 283 | }); |
284 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
284 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
285 | 285 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
286 | 286 | }); |
287 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
287 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
288 | 288 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
289 | 289 | }); |
290 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
290 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
291 | 291 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
292 | 292 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
293 | 293 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | }); |
297 | 297 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
298 | 298 | |
299 | - $this->registerService(Store::class, function (Server $c) { |
|
299 | + $this->registerService(Store::class, function(Server $c) { |
|
300 | 300 | $session = $c->getSession(); |
301 | 301 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
302 | 302 | $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
@@ -307,11 +307,11 @@ discard block |
||
307 | 307 | return new Store($session, $logger, $tokenProvider); |
308 | 308 | }); |
309 | 309 | $this->registerAlias(IStore::class, Store::class); |
310 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
310 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
311 | 311 | $dbConnection = $c->getDatabaseConnection(); |
312 | 312 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
313 | 313 | }); |
314 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
314 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
315 | 315 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
316 | 316 | $crypto = $c->getCrypto(); |
317 | 317 | $config = $c->getConfig(); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | }); |
322 | 322 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
323 | 323 | |
324 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
324 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
325 | 325 | $manager = $c->getUserManager(); |
326 | 326 | $session = new \OC\Session\Memory(''); |
327 | 327 | $timeFactory = new TimeFactory(); |
@@ -334,44 +334,44 @@ discard block |
||
334 | 334 | } |
335 | 335 | |
336 | 336 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
337 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
337 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
338 | 338 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
339 | 339 | }); |
340 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
340 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
341 | 341 | /** @var $user \OC\User\User */ |
342 | 342 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
343 | 343 | }); |
344 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
344 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
345 | 345 | /** @var $user \OC\User\User */ |
346 | 346 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
347 | 347 | }); |
348 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
348 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
349 | 349 | /** @var $user \OC\User\User */ |
350 | 350 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
351 | 351 | }); |
352 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
352 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
353 | 353 | /** @var $user \OC\User\User */ |
354 | 354 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
355 | 355 | }); |
356 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
356 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
357 | 357 | /** @var $user \OC\User\User */ |
358 | 358 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
359 | 359 | }); |
360 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
360 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
361 | 361 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
362 | 362 | }); |
363 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
363 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
364 | 364 | /** @var $user \OC\User\User */ |
365 | 365 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
366 | 366 | }); |
367 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
367 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
368 | 368 | /** @var $user \OC\User\User */ |
369 | 369 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
370 | 370 | }); |
371 | - $userSession->listen('\OC\User', 'logout', function () { |
|
371 | + $userSession->listen('\OC\User', 'logout', function() { |
|
372 | 372 | \OC_Hook::emit('OC_User', 'logout', array()); |
373 | 373 | }); |
374 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
374 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
375 | 375 | /** @var $user \OC\User\User */ |
376 | 376 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
377 | 377 | }); |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | }); |
380 | 380 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
381 | 381 | |
382 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
382 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
383 | 383 | return new \OC\Authentication\TwoFactorAuth\Manager( |
384 | 384 | $c->getAppManager(), |
385 | 385 | $c->getSession(), |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
395 | 395 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
396 | 396 | |
397 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
397 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
398 | 398 | return new \OC\AllConfig( |
399 | 399 | $c->getSystemConfig() |
400 | 400 | ); |
@@ -402,17 +402,17 @@ discard block |
||
402 | 402 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
403 | 403 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
404 | 404 | |
405 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
405 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
406 | 406 | return new \OC\SystemConfig($config); |
407 | 407 | }); |
408 | 408 | |
409 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
409 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
410 | 410 | return new \OC\AppConfig($c->getDatabaseConnection()); |
411 | 411 | }); |
412 | 412 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
413 | 413 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
414 | 414 | |
415 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
415 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
416 | 416 | return new \OC\L10N\Factory( |
417 | 417 | $c->getConfig(), |
418 | 418 | $c->getRequest(), |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | }); |
423 | 423 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
424 | 424 | |
425 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
425 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
426 | 426 | $config = $c->getConfig(); |
427 | 427 | $cacheFactory = $c->getMemCacheFactory(); |
428 | 428 | $request = $c->getRequest(); |
@@ -434,18 +434,18 @@ discard block |
||
434 | 434 | }); |
435 | 435 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
436 | 436 | |
437 | - $this->registerService('AppHelper', function ($c) { |
|
437 | + $this->registerService('AppHelper', function($c) { |
|
438 | 438 | return new \OC\AppHelper(); |
439 | 439 | }); |
440 | 440 | $this->registerAlias('AppFetcher', AppFetcher::class); |
441 | 441 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
442 | 442 | |
443 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
443 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
444 | 444 | return new Cache\File(); |
445 | 445 | }); |
446 | 446 | $this->registerAlias('UserCache', \OCP\ICache::class); |
447 | 447 | |
448 | - $this->registerService(Factory::class, function (Server $c) { |
|
448 | + $this->registerService(Factory::class, function(Server $c) { |
|
449 | 449 | |
450 | 450 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
451 | 451 | '\\OC\\Memcache\\ArrayCache', |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | $version = implode(',', $v); |
463 | 463 | $instanceId = \OC_Util::getInstanceId(); |
464 | 464 | $path = \OC::$SERVERROOT; |
465 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
465 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl()); |
|
466 | 466 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
467 | 467 | $config->getSystemValue('memcache.local', null), |
468 | 468 | $config->getSystemValue('memcache.distributed', null), |
@@ -475,12 +475,12 @@ discard block |
||
475 | 475 | $this->registerAlias('MemCacheFactory', Factory::class); |
476 | 476 | $this->registerAlias(ICacheFactory::class, Factory::class); |
477 | 477 | |
478 | - $this->registerService('RedisFactory', function (Server $c) { |
|
478 | + $this->registerService('RedisFactory', function(Server $c) { |
|
479 | 479 | $systemConfig = $c->getSystemConfig(); |
480 | 480 | return new RedisFactory($systemConfig); |
481 | 481 | }); |
482 | 482 | |
483 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
483 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
484 | 484 | return new \OC\Activity\Manager( |
485 | 485 | $c->getRequest(), |
486 | 486 | $c->getUserSession(), |
@@ -490,14 +490,14 @@ discard block |
||
490 | 490 | }); |
491 | 491 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
492 | 492 | |
493 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
493 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
494 | 494 | return new \OC\Activity\EventMerger( |
495 | 495 | $c->getL10N('lib') |
496 | 496 | ); |
497 | 497 | }); |
498 | 498 | $this->registerAlias(IValidator::class, Validator::class); |
499 | 499 | |
500 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
500 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
501 | 501 | return new AvatarManager( |
502 | 502 | $c->getUserManager(), |
503 | 503 | $c->getAppDataDir('avatar'), |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | }); |
509 | 509 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
510 | 510 | |
511 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
511 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
512 | 512 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
513 | 513 | $logger = Log::getLogClass($logType); |
514 | 514 | call_user_func(array($logger, 'init')); |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | }); |
518 | 518 | $this->registerAlias('Logger', \OCP\ILogger::class); |
519 | 519 | |
520 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
520 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
521 | 521 | $config = $c->getConfig(); |
522 | 522 | return new \OC\BackgroundJob\JobList( |
523 | 523 | $c->getDatabaseConnection(), |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | }); |
528 | 528 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
529 | 529 | |
530 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
530 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
531 | 531 | $cacheFactory = $c->getMemCacheFactory(); |
532 | 532 | $logger = $c->getLogger(); |
533 | 533 | if ($cacheFactory->isAvailable()) { |
@@ -539,12 +539,12 @@ discard block |
||
539 | 539 | }); |
540 | 540 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
541 | 541 | |
542 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
542 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
543 | 543 | return new Search(); |
544 | 544 | }); |
545 | 545 | $this->registerAlias('Search', \OCP\ISearch::class); |
546 | 546 | |
547 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
547 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
548 | 548 | return new \OC\Security\RateLimiting\Limiter( |
549 | 549 | $this->getUserSession(), |
550 | 550 | $this->getRequest(), |
@@ -552,34 +552,34 @@ discard block |
||
552 | 552 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
553 | 553 | ); |
554 | 554 | }); |
555 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
555 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
556 | 556 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
557 | 557 | $this->getMemCacheFactory(), |
558 | 558 | new \OC\AppFramework\Utility\TimeFactory() |
559 | 559 | ); |
560 | 560 | }); |
561 | 561 | |
562 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
562 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
563 | 563 | return new SecureRandom(); |
564 | 564 | }); |
565 | 565 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
566 | 566 | |
567 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
567 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
568 | 568 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
569 | 569 | }); |
570 | 570 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
571 | 571 | |
572 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
572 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
573 | 573 | return new Hasher($c->getConfig()); |
574 | 574 | }); |
575 | 575 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
576 | 576 | |
577 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
577 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
578 | 578 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
579 | 579 | }); |
580 | 580 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
581 | 581 | |
582 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
582 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
583 | 583 | $systemConfig = $c->getSystemConfig(); |
584 | 584 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
585 | 585 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | }); |
594 | 594 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
595 | 595 | |
596 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
596 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
597 | 597 | $config = $c->getConfig(); |
598 | 598 | return new HTTPHelper( |
599 | 599 | $config, |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | ); |
602 | 602 | }); |
603 | 603 | |
604 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
604 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
605 | 605 | $user = \OC_User::getUser(); |
606 | 606 | $uid = $user ? $user : null; |
607 | 607 | return new ClientService( |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | ); |
617 | 617 | }); |
618 | 618 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
619 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
619 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
620 | 620 | $eventLogger = new EventLogger(); |
621 | 621 | if ($c->getSystemConfig()->getValue('debug', false)) { |
622 | 622 | // In debug mode, module is being activated by default |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | }); |
627 | 627 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
628 | 628 | |
629 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
629 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
630 | 630 | $queryLogger = new QueryLogger(); |
631 | 631 | if ($c->getSystemConfig()->getValue('debug', false)) { |
632 | 632 | // In debug mode, module is being activated by default |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | }); |
637 | 637 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
638 | 638 | |
639 | - $this->registerService(TempManager::class, function (Server $c) { |
|
639 | + $this->registerService(TempManager::class, function(Server $c) { |
|
640 | 640 | return new TempManager( |
641 | 641 | $c->getLogger(), |
642 | 642 | $c->getConfig() |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | $this->registerAlias('TempManager', TempManager::class); |
646 | 646 | $this->registerAlias(ITempManager::class, TempManager::class); |
647 | 647 | |
648 | - $this->registerService(AppManager::class, function (Server $c) { |
|
648 | + $this->registerService(AppManager::class, function(Server $c) { |
|
649 | 649 | return new \OC\App\AppManager( |
650 | 650 | $c->getUserSession(), |
651 | 651 | $c->getAppConfig(), |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | $this->registerAlias('AppManager', AppManager::class); |
658 | 658 | $this->registerAlias(IAppManager::class, AppManager::class); |
659 | 659 | |
660 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
660 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
661 | 661 | return new DateTimeZone( |
662 | 662 | $c->getConfig(), |
663 | 663 | $c->getSession() |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | }); |
666 | 666 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
667 | 667 | |
668 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
668 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
669 | 669 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
670 | 670 | |
671 | 671 | return new DateTimeFormatter( |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | }); |
676 | 676 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
677 | 677 | |
678 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
678 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
679 | 679 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
680 | 680 | $listener = new UserMountCacheListener($mountCache); |
681 | 681 | $listener->listen($c->getUserManager()); |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | }); |
684 | 684 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
685 | 685 | |
686 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
686 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
687 | 687 | $loader = \OC\Files\Filesystem::getLoader(); |
688 | 688 | $mountCache = $c->query('UserMountCache'); |
689 | 689 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -699,10 +699,10 @@ discard block |
||
699 | 699 | }); |
700 | 700 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
701 | 701 | |
702 | - $this->registerService('IniWrapper', function ($c) { |
|
702 | + $this->registerService('IniWrapper', function($c) { |
|
703 | 703 | return new IniGetWrapper(); |
704 | 704 | }); |
705 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
705 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
706 | 706 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
707 | 707 | if ($busClass) { |
708 | 708 | list($app, $class) = explode('::', $busClass, 2); |
@@ -717,10 +717,10 @@ discard block |
||
717 | 717 | return new CronBus($jobList); |
718 | 718 | } |
719 | 719 | }); |
720 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
720 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
721 | 721 | return new TrustedDomainHelper($this->getConfig()); |
722 | 722 | }); |
723 | - $this->registerService('Throttler', function (Server $c) { |
|
723 | + $this->registerService('Throttler', function(Server $c) { |
|
724 | 724 | return new Throttler( |
725 | 725 | $c->getDatabaseConnection(), |
726 | 726 | new TimeFactory(), |
@@ -728,7 +728,7 @@ discard block |
||
728 | 728 | $c->getConfig() |
729 | 729 | ); |
730 | 730 | }); |
731 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
731 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
732 | 732 | // IConfig and IAppManager requires a working database. This code |
733 | 733 | // might however be called when ownCloud is not yet setup. |
734 | 734 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | $c->getTempManager() |
750 | 750 | ); |
751 | 751 | }); |
752 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
752 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
753 | 753 | if (isset($this['urlParams'])) { |
754 | 754 | $urlParams = $this['urlParams']; |
755 | 755 | } else { |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | }); |
786 | 786 | $this->registerAlias('Request', \OCP\IRequest::class); |
787 | 787 | |
788 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
788 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
789 | 789 | return new Mailer( |
790 | 790 | $c->getConfig(), |
791 | 791 | $c->getLogger(), |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | }); |
797 | 797 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
798 | 798 | |
799 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
799 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
800 | 800 | $config = $c->getConfig(); |
801 | 801 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
802 | 802 | if (is_null($factoryClass)) { |
@@ -806,7 +806,7 @@ discard block |
||
806 | 806 | $factory = new $factoryClass($this); |
807 | 807 | return $factory->getLDAPProvider(); |
808 | 808 | }); |
809 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
809 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
810 | 810 | $ini = $c->getIniWrapper(); |
811 | 811 | $config = $c->getConfig(); |
812 | 812 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -823,49 +823,49 @@ discard block |
||
823 | 823 | }); |
824 | 824 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
825 | 825 | |
826 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
826 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
827 | 827 | return new \OC\Files\Mount\Manager(); |
828 | 828 | }); |
829 | 829 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
830 | 830 | |
831 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
831 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
832 | 832 | return new \OC\Files\Type\Detection( |
833 | 833 | $c->getURLGenerator(), |
834 | 834 | \OC::$configDir, |
835 | - \OC::$SERVERROOT . '/resources/config/' |
|
835 | + \OC::$SERVERROOT.'/resources/config/' |
|
836 | 836 | ); |
837 | 837 | }); |
838 | 838 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
839 | 839 | |
840 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
840 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
841 | 841 | return new \OC\Files\Type\Loader( |
842 | 842 | $c->getDatabaseConnection() |
843 | 843 | ); |
844 | 844 | }); |
845 | 845 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
846 | - $this->registerService(BundleFetcher::class, function () { |
|
846 | + $this->registerService(BundleFetcher::class, function() { |
|
847 | 847 | return new BundleFetcher($this->getL10N('lib')); |
848 | 848 | }); |
849 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
849 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
850 | 850 | return new Manager( |
851 | 851 | $c->query(IValidator::class) |
852 | 852 | ); |
853 | 853 | }); |
854 | 854 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
855 | 855 | |
856 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
856 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
857 | 857 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
858 | - $manager->registerCapability(function () use ($c) { |
|
858 | + $manager->registerCapability(function() use ($c) { |
|
859 | 859 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
860 | 860 | }); |
861 | - $manager->registerCapability(function () use ($c) { |
|
861 | + $manager->registerCapability(function() use ($c) { |
|
862 | 862 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
863 | 863 | }); |
864 | 864 | return $manager; |
865 | 865 | }); |
866 | 866 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
867 | 867 | |
868 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
868 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
869 | 869 | $config = $c->getConfig(); |
870 | 870 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
871 | 871 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -874,7 +874,7 @@ discard block |
||
874 | 874 | }); |
875 | 875 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
876 | 876 | |
877 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
877 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
878 | 878 | /* |
879 | 879 | * Dark magic for autoloader. |
880 | 880 | * If we do a class_exists it will try to load the class which will |
@@ -900,7 +900,7 @@ discard block |
||
900 | 900 | } |
901 | 901 | return new \OC_Defaults(); |
902 | 902 | }); |
903 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
903 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
904 | 904 | /** @var Factory $cacheFactory */ |
905 | 905 | $cacheFactory = $c->query(Factory::class); |
906 | 906 | return new SCSSCacher( |
@@ -913,13 +913,13 @@ discard block |
||
913 | 913 | $cacheFactory->create('SCSS') |
914 | 914 | ); |
915 | 915 | }); |
916 | - $this->registerService(EventDispatcher::class, function () { |
|
916 | + $this->registerService(EventDispatcher::class, function() { |
|
917 | 917 | return new EventDispatcher(); |
918 | 918 | }); |
919 | 919 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
920 | 920 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
921 | 921 | |
922 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
922 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
923 | 923 | // FIXME: Instantiiated here due to cyclic dependency |
924 | 924 | $request = new Request( |
925 | 925 | [ |
@@ -944,7 +944,7 @@ discard block |
||
944 | 944 | $request |
945 | 945 | ); |
946 | 946 | }); |
947 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
947 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
948 | 948 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
949 | 949 | |
950 | 950 | return new CsrfTokenManager( |
@@ -952,22 +952,22 @@ discard block |
||
952 | 952 | $c->query(SessionStorage::class) |
953 | 953 | ); |
954 | 954 | }); |
955 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
955 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
956 | 956 | return new SessionStorage($c->getSession()); |
957 | 957 | }); |
958 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
958 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
959 | 959 | return new ContentSecurityPolicyManager(); |
960 | 960 | }); |
961 | 961 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
962 | 962 | |
963 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
963 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
964 | 964 | return new ContentSecurityPolicyNonceManager( |
965 | 965 | $c->getCsrfTokenManager(), |
966 | 966 | $c->getRequest() |
967 | 967 | ); |
968 | 968 | }); |
969 | 969 | |
970 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
970 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
971 | 971 | $config = $c->getConfig(); |
972 | 972 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
973 | 973 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -999,7 +999,7 @@ discard block |
||
999 | 999 | }); |
1000 | 1000 | $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
1001 | 1001 | |
1002 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1002 | + $this->registerService('SettingsManager', function(Server $c) { |
|
1003 | 1003 | $manager = new \OC\Settings\Manager( |
1004 | 1004 | $c->getLogger(), |
1005 | 1005 | $c->getDatabaseConnection(), |
@@ -1019,29 +1019,29 @@ discard block |
||
1019 | 1019 | ); |
1020 | 1020 | return $manager; |
1021 | 1021 | }); |
1022 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1022 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
1023 | 1023 | return new \OC\Files\AppData\Factory( |
1024 | 1024 | $c->getRootFolder(), |
1025 | 1025 | $c->getSystemConfig() |
1026 | 1026 | ); |
1027 | 1027 | }); |
1028 | 1028 | |
1029 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1030 | - return new LockdownManager(function () use ($c) { |
|
1029 | + $this->registerService('LockdownManager', function(Server $c) { |
|
1030 | + return new LockdownManager(function() use ($c) { |
|
1031 | 1031 | return $c->getSession(); |
1032 | 1032 | }); |
1033 | 1033 | }); |
1034 | 1034 | |
1035 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1035 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
1036 | 1036 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
1037 | 1037 | }); |
1038 | 1038 | |
1039 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1039 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
1040 | 1040 | return new CloudIdManager(); |
1041 | 1041 | }); |
1042 | 1042 | |
1043 | 1043 | /* To trick DI since we don't extend the DIContainer here */ |
1044 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1044 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
1045 | 1045 | return new CleanPreviewsBackgroundJob( |
1046 | 1046 | $c->getRootFolder(), |
1047 | 1047 | $c->getLogger(), |
@@ -1056,18 +1056,18 @@ discard block |
||
1056 | 1056 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1057 | 1057 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1058 | 1058 | |
1059 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1059 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1060 | 1060 | return new Defaults( |
1061 | 1061 | $c->getThemingDefaults() |
1062 | 1062 | ); |
1063 | 1063 | }); |
1064 | 1064 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
1065 | 1065 | |
1066 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1066 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1067 | 1067 | return $c->query(\OCP\IUserSession::class)->getSession(); |
1068 | 1068 | }); |
1069 | 1069 | |
1070 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1070 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1071 | 1071 | return new ShareHelper( |
1072 | 1072 | $c->query(\OCP\Share\IManager::class) |
1073 | 1073 | ); |
@@ -1208,7 +1208,7 @@ discard block |
||
1208 | 1208 | * @deprecated since 9.2.0 use IAppData |
1209 | 1209 | */ |
1210 | 1210 | public function getAppFolder() { |
1211 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1211 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1212 | 1212 | $root = $this->getRootFolder(); |
1213 | 1213 | if (!$root->nodeExists($dir)) { |
1214 | 1214 | $folder = $root->newFolder($dir); |
@@ -132,1711 +132,1711 @@ |
||
132 | 132 | * TODO: hookup all manager classes |
133 | 133 | */ |
134 | 134 | class Server extends ServerContainer implements IServerContainer { |
135 | - /** @var string */ |
|
136 | - private $webRoot; |
|
137 | - |
|
138 | - /** |
|
139 | - * @param string $webRoot |
|
140 | - * @param \OC\Config $config |
|
141 | - */ |
|
142 | - public function __construct($webRoot, \OC\Config $config) { |
|
143 | - parent::__construct(); |
|
144 | - $this->webRoot = $webRoot; |
|
145 | - |
|
146 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
147 | - return $c; |
|
148 | - }); |
|
149 | - |
|
150 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
151 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
152 | - |
|
153 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
154 | - |
|
155 | - |
|
156 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
157 | - return new PreviewManager( |
|
158 | - $c->getConfig(), |
|
159 | - $c->getRootFolder(), |
|
160 | - $c->getAppDataDir('preview'), |
|
161 | - $c->getEventDispatcher(), |
|
162 | - $c->getSession()->get('user_id') |
|
163 | - ); |
|
164 | - }); |
|
165 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
166 | - |
|
167 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
168 | - return new \OC\Preview\Watcher( |
|
169 | - $c->getAppDataDir('preview') |
|
170 | - ); |
|
171 | - }); |
|
172 | - |
|
173 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
174 | - $view = new View(); |
|
175 | - $util = new Encryption\Util( |
|
176 | - $view, |
|
177 | - $c->getUserManager(), |
|
178 | - $c->getGroupManager(), |
|
179 | - $c->getConfig() |
|
180 | - ); |
|
181 | - return new Encryption\Manager( |
|
182 | - $c->getConfig(), |
|
183 | - $c->getLogger(), |
|
184 | - $c->getL10N('core'), |
|
185 | - new View(), |
|
186 | - $util, |
|
187 | - new ArrayCache() |
|
188 | - ); |
|
189 | - }); |
|
190 | - |
|
191 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
192 | - $util = new Encryption\Util( |
|
193 | - new View(), |
|
194 | - $c->getUserManager(), |
|
195 | - $c->getGroupManager(), |
|
196 | - $c->getConfig() |
|
197 | - ); |
|
198 | - return new Encryption\File( |
|
199 | - $util, |
|
200 | - $c->getRootFolder(), |
|
201 | - $c->getShareManager() |
|
202 | - ); |
|
203 | - }); |
|
204 | - |
|
205 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
206 | - $view = new View(); |
|
207 | - $util = new Encryption\Util( |
|
208 | - $view, |
|
209 | - $c->getUserManager(), |
|
210 | - $c->getGroupManager(), |
|
211 | - $c->getConfig() |
|
212 | - ); |
|
213 | - |
|
214 | - return new Encryption\Keys\Storage($view, $util); |
|
215 | - }); |
|
216 | - $this->registerService('TagMapper', function (Server $c) { |
|
217 | - return new TagMapper($c->getDatabaseConnection()); |
|
218 | - }); |
|
219 | - |
|
220 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
221 | - $tagMapper = $c->query('TagMapper'); |
|
222 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
223 | - }); |
|
224 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
225 | - |
|
226 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
227 | - $config = $c->getConfig(); |
|
228 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
229 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
230 | - $factory = new $factoryClass($this); |
|
231 | - return $factory; |
|
232 | - }); |
|
233 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
234 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
235 | - }); |
|
236 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
237 | - |
|
238 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
239 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
240 | - }); |
|
241 | - $this->registerService('RootFolder', function (Server $c) { |
|
242 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
243 | - $view = new View(); |
|
244 | - $root = new Root( |
|
245 | - $manager, |
|
246 | - $view, |
|
247 | - null, |
|
248 | - $c->getUserMountCache(), |
|
249 | - $this->getLogger(), |
|
250 | - $this->getUserManager() |
|
251 | - ); |
|
252 | - $connector = new HookConnector($root, $view); |
|
253 | - $connector->viewToNode(); |
|
254 | - |
|
255 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
256 | - $previewConnector->connectWatcher(); |
|
257 | - |
|
258 | - return $root; |
|
259 | - }); |
|
260 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
261 | - |
|
262 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
263 | - return new LazyRoot(function () use ($c) { |
|
264 | - return $c->query('RootFolder'); |
|
265 | - }); |
|
266 | - }); |
|
267 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
268 | - |
|
269 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
270 | - $config = $c->getConfig(); |
|
271 | - return new \OC\User\Manager($config); |
|
272 | - }); |
|
273 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
274 | - |
|
275 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
276 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
277 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
278 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
279 | - }); |
|
280 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
281 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
282 | - }); |
|
283 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
284 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
285 | - }); |
|
286 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
287 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
288 | - }); |
|
289 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
290 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
291 | - }); |
|
292 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
293 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
294 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
295 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
296 | - }); |
|
297 | - return $groupManager; |
|
298 | - }); |
|
299 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
300 | - |
|
301 | - $this->registerService(Store::class, function (Server $c) { |
|
302 | - $session = $c->getSession(); |
|
303 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
304 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
305 | - } else { |
|
306 | - $tokenProvider = null; |
|
307 | - } |
|
308 | - $logger = $c->getLogger(); |
|
309 | - return new Store($session, $logger, $tokenProvider); |
|
310 | - }); |
|
311 | - $this->registerAlias(IStore::class, Store::class); |
|
312 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
313 | - $dbConnection = $c->getDatabaseConnection(); |
|
314 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
315 | - }); |
|
316 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
317 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
318 | - $crypto = $c->getCrypto(); |
|
319 | - $config = $c->getConfig(); |
|
320 | - $logger = $c->getLogger(); |
|
321 | - $timeFactory = new TimeFactory(); |
|
322 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
323 | - }); |
|
324 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
325 | - |
|
326 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
327 | - $manager = $c->getUserManager(); |
|
328 | - $session = new \OC\Session\Memory(''); |
|
329 | - $timeFactory = new TimeFactory(); |
|
330 | - // Token providers might require a working database. This code |
|
331 | - // might however be called when ownCloud is not yet setup. |
|
332 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
333 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
334 | - } else { |
|
335 | - $defaultTokenProvider = null; |
|
336 | - } |
|
337 | - |
|
338 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
339 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
340 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
341 | - }); |
|
342 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
343 | - /** @var $user \OC\User\User */ |
|
344 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
345 | - }); |
|
346 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
347 | - /** @var $user \OC\User\User */ |
|
348 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
349 | - }); |
|
350 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
351 | - /** @var $user \OC\User\User */ |
|
352 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
353 | - }); |
|
354 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
355 | - /** @var $user \OC\User\User */ |
|
356 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
357 | - }); |
|
358 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
359 | - /** @var $user \OC\User\User */ |
|
360 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
361 | - }); |
|
362 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
363 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
364 | - }); |
|
365 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
366 | - /** @var $user \OC\User\User */ |
|
367 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
368 | - }); |
|
369 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
370 | - /** @var $user \OC\User\User */ |
|
371 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
372 | - }); |
|
373 | - $userSession->listen('\OC\User', 'logout', function () { |
|
374 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
375 | - }); |
|
376 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
377 | - /** @var $user \OC\User\User */ |
|
378 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
379 | - }); |
|
380 | - return $userSession; |
|
381 | - }); |
|
382 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
383 | - |
|
384 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
385 | - return new \OC\Authentication\TwoFactorAuth\Manager( |
|
386 | - $c->getAppManager(), |
|
387 | - $c->getSession(), |
|
388 | - $c->getConfig(), |
|
389 | - $c->getActivityManager(), |
|
390 | - $c->getLogger(), |
|
391 | - $c->query(\OC\Authentication\Token\IProvider::class), |
|
392 | - $c->query(ITimeFactory::class) |
|
393 | - ); |
|
394 | - }); |
|
395 | - |
|
396 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
397 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
398 | - |
|
399 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
400 | - return new \OC\AllConfig( |
|
401 | - $c->getSystemConfig() |
|
402 | - ); |
|
403 | - }); |
|
404 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
405 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
406 | - |
|
407 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
408 | - return new \OC\SystemConfig($config); |
|
409 | - }); |
|
410 | - |
|
411 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
412 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
413 | - }); |
|
414 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
415 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
416 | - |
|
417 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
418 | - return new \OC\L10N\Factory( |
|
419 | - $c->getConfig(), |
|
420 | - $c->getRequest(), |
|
421 | - $c->getUserSession(), |
|
422 | - \OC::$SERVERROOT |
|
423 | - ); |
|
424 | - }); |
|
425 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
426 | - |
|
427 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
428 | - $config = $c->getConfig(); |
|
429 | - $cacheFactory = $c->getMemCacheFactory(); |
|
430 | - $request = $c->getRequest(); |
|
431 | - return new \OC\URLGenerator( |
|
432 | - $config, |
|
433 | - $cacheFactory, |
|
434 | - $request |
|
435 | - ); |
|
436 | - }); |
|
437 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
438 | - |
|
439 | - $this->registerService('AppHelper', function ($c) { |
|
440 | - return new \OC\AppHelper(); |
|
441 | - }); |
|
442 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
443 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
444 | - |
|
445 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
446 | - return new Cache\File(); |
|
447 | - }); |
|
448 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
449 | - |
|
450 | - $this->registerService(Factory::class, function (Server $c) { |
|
451 | - |
|
452 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
453 | - '\\OC\\Memcache\\ArrayCache', |
|
454 | - '\\OC\\Memcache\\ArrayCache', |
|
455 | - '\\OC\\Memcache\\ArrayCache' |
|
456 | - ); |
|
457 | - $config = $c->getConfig(); |
|
458 | - $request = $c->getRequest(); |
|
459 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
460 | - |
|
461 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
462 | - $v = \OC_App::getAppVersions(); |
|
463 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
464 | - $version = implode(',', $v); |
|
465 | - $instanceId = \OC_Util::getInstanceId(); |
|
466 | - $path = \OC::$SERVERROOT; |
|
467 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
468 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
469 | - $config->getSystemValue('memcache.local', null), |
|
470 | - $config->getSystemValue('memcache.distributed', null), |
|
471 | - $config->getSystemValue('memcache.locking', null) |
|
472 | - ); |
|
473 | - } |
|
474 | - return $arrayCacheFactory; |
|
475 | - |
|
476 | - }); |
|
477 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
478 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
479 | - |
|
480 | - $this->registerService('RedisFactory', function (Server $c) { |
|
481 | - $systemConfig = $c->getSystemConfig(); |
|
482 | - return new RedisFactory($systemConfig); |
|
483 | - }); |
|
484 | - |
|
485 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
486 | - return new \OC\Activity\Manager( |
|
487 | - $c->getRequest(), |
|
488 | - $c->getUserSession(), |
|
489 | - $c->getConfig(), |
|
490 | - $c->query(IValidator::class) |
|
491 | - ); |
|
492 | - }); |
|
493 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
494 | - |
|
495 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
496 | - return new \OC\Activity\EventMerger( |
|
497 | - $c->getL10N('lib') |
|
498 | - ); |
|
499 | - }); |
|
500 | - $this->registerAlias(IValidator::class, Validator::class); |
|
501 | - |
|
502 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
503 | - return new AvatarManager( |
|
504 | - $c->getUserManager(), |
|
505 | - $c->getAppDataDir('avatar'), |
|
506 | - $c->getL10N('lib'), |
|
507 | - $c->getLogger(), |
|
508 | - $c->getConfig() |
|
509 | - ); |
|
510 | - }); |
|
511 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
512 | - |
|
513 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
514 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
515 | - $logger = Log::getLogClass($logType); |
|
516 | - call_user_func(array($logger, 'init')); |
|
517 | - |
|
518 | - return new Log($logger); |
|
519 | - }); |
|
520 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
521 | - |
|
522 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
523 | - $config = $c->getConfig(); |
|
524 | - return new \OC\BackgroundJob\JobList( |
|
525 | - $c->getDatabaseConnection(), |
|
526 | - $config, |
|
527 | - new TimeFactory() |
|
528 | - ); |
|
529 | - }); |
|
530 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
531 | - |
|
532 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
533 | - $cacheFactory = $c->getMemCacheFactory(); |
|
534 | - $logger = $c->getLogger(); |
|
535 | - if ($cacheFactory->isAvailable()) { |
|
536 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
537 | - } else { |
|
538 | - $router = new \OC\Route\Router($logger); |
|
539 | - } |
|
540 | - return $router; |
|
541 | - }); |
|
542 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
543 | - |
|
544 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
545 | - return new Search(); |
|
546 | - }); |
|
547 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
548 | - |
|
549 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
550 | - return new \OC\Security\RateLimiting\Limiter( |
|
551 | - $this->getUserSession(), |
|
552 | - $this->getRequest(), |
|
553 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
554 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
555 | - ); |
|
556 | - }); |
|
557 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
558 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
559 | - $this->getMemCacheFactory(), |
|
560 | - new \OC\AppFramework\Utility\TimeFactory() |
|
561 | - ); |
|
562 | - }); |
|
563 | - |
|
564 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
565 | - return new SecureRandom(); |
|
566 | - }); |
|
567 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
568 | - |
|
569 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
570 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
571 | - }); |
|
572 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
573 | - |
|
574 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
575 | - return new Hasher($c->getConfig()); |
|
576 | - }); |
|
577 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
578 | - |
|
579 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
580 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
581 | - }); |
|
582 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
583 | - |
|
584 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
585 | - $systemConfig = $c->getSystemConfig(); |
|
586 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
587 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
588 | - if (!$factory->isValidType($type)) { |
|
589 | - throw new \OC\DatabaseException('Invalid database type'); |
|
590 | - } |
|
591 | - $connectionParams = $factory->createConnectionParams(); |
|
592 | - $connection = $factory->getConnection($type, $connectionParams); |
|
593 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
594 | - return $connection; |
|
595 | - }); |
|
596 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
597 | - |
|
598 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
599 | - $config = $c->getConfig(); |
|
600 | - return new HTTPHelper( |
|
601 | - $config, |
|
602 | - $c->getHTTPClientService() |
|
603 | - ); |
|
604 | - }); |
|
605 | - |
|
606 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
607 | - $user = \OC_User::getUser(); |
|
608 | - $uid = $user ? $user : null; |
|
609 | - return new ClientService( |
|
610 | - $c->getConfig(), |
|
611 | - new \OC\Security\CertificateManager( |
|
612 | - $uid, |
|
613 | - new View(), |
|
614 | - $c->getConfig(), |
|
615 | - $c->getLogger(), |
|
616 | - $c->getSecureRandom() |
|
617 | - ) |
|
618 | - ); |
|
619 | - }); |
|
620 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
621 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
622 | - $eventLogger = new EventLogger(); |
|
623 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
624 | - // In debug mode, module is being activated by default |
|
625 | - $eventLogger->activate(); |
|
626 | - } |
|
627 | - return $eventLogger; |
|
628 | - }); |
|
629 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
630 | - |
|
631 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
632 | - $queryLogger = new QueryLogger(); |
|
633 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
634 | - // In debug mode, module is being activated by default |
|
635 | - $queryLogger->activate(); |
|
636 | - } |
|
637 | - return $queryLogger; |
|
638 | - }); |
|
639 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
640 | - |
|
641 | - $this->registerService(TempManager::class, function (Server $c) { |
|
642 | - return new TempManager( |
|
643 | - $c->getLogger(), |
|
644 | - $c->getConfig() |
|
645 | - ); |
|
646 | - }); |
|
647 | - $this->registerAlias('TempManager', TempManager::class); |
|
648 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
649 | - |
|
650 | - $this->registerService(AppManager::class, function (Server $c) { |
|
651 | - return new \OC\App\AppManager( |
|
652 | - $c->getUserSession(), |
|
653 | - $c->getAppConfig(), |
|
654 | - $c->getGroupManager(), |
|
655 | - $c->getMemCacheFactory(), |
|
656 | - $c->getEventDispatcher() |
|
657 | - ); |
|
658 | - }); |
|
659 | - $this->registerAlias('AppManager', AppManager::class); |
|
660 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
661 | - |
|
662 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
663 | - return new DateTimeZone( |
|
664 | - $c->getConfig(), |
|
665 | - $c->getSession() |
|
666 | - ); |
|
667 | - }); |
|
668 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
669 | - |
|
670 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
671 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
672 | - |
|
673 | - return new DateTimeFormatter( |
|
674 | - $c->getDateTimeZone()->getTimeZone(), |
|
675 | - $c->getL10N('lib', $language) |
|
676 | - ); |
|
677 | - }); |
|
678 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
679 | - |
|
680 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
681 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
682 | - $listener = new UserMountCacheListener($mountCache); |
|
683 | - $listener->listen($c->getUserManager()); |
|
684 | - return $mountCache; |
|
685 | - }); |
|
686 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
687 | - |
|
688 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
689 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
690 | - $mountCache = $c->query('UserMountCache'); |
|
691 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
692 | - |
|
693 | - // builtin providers |
|
694 | - |
|
695 | - $config = $c->getConfig(); |
|
696 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
697 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
698 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
699 | - |
|
700 | - return $manager; |
|
701 | - }); |
|
702 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
703 | - |
|
704 | - $this->registerService('IniWrapper', function ($c) { |
|
705 | - return new IniGetWrapper(); |
|
706 | - }); |
|
707 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
708 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
709 | - if ($busClass) { |
|
710 | - list($app, $class) = explode('::', $busClass, 2); |
|
711 | - if ($c->getAppManager()->isInstalled($app)) { |
|
712 | - \OC_App::loadApp($app); |
|
713 | - return $c->query($class); |
|
714 | - } else { |
|
715 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
716 | - } |
|
717 | - } else { |
|
718 | - $jobList = $c->getJobList(); |
|
719 | - return new CronBus($jobList); |
|
720 | - } |
|
721 | - }); |
|
722 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
723 | - return new TrustedDomainHelper($this->getConfig()); |
|
724 | - }); |
|
725 | - $this->registerService('Throttler', function (Server $c) { |
|
726 | - return new Throttler( |
|
727 | - $c->getDatabaseConnection(), |
|
728 | - new TimeFactory(), |
|
729 | - $c->getLogger(), |
|
730 | - $c->getConfig() |
|
731 | - ); |
|
732 | - }); |
|
733 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
734 | - // IConfig and IAppManager requires a working database. This code |
|
735 | - // might however be called when ownCloud is not yet setup. |
|
736 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
737 | - $config = $c->getConfig(); |
|
738 | - $appManager = $c->getAppManager(); |
|
739 | - } else { |
|
740 | - $config = null; |
|
741 | - $appManager = null; |
|
742 | - } |
|
743 | - |
|
744 | - return new Checker( |
|
745 | - new EnvironmentHelper(), |
|
746 | - new FileAccessHelper(), |
|
747 | - new AppLocator(), |
|
748 | - $config, |
|
749 | - $c->getMemCacheFactory(), |
|
750 | - $appManager, |
|
751 | - $c->getTempManager() |
|
752 | - ); |
|
753 | - }); |
|
754 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
755 | - if (isset($this['urlParams'])) { |
|
756 | - $urlParams = $this['urlParams']; |
|
757 | - } else { |
|
758 | - $urlParams = []; |
|
759 | - } |
|
760 | - |
|
761 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
762 | - && in_array('fakeinput', stream_get_wrappers()) |
|
763 | - ) { |
|
764 | - $stream = 'fakeinput://data'; |
|
765 | - } else { |
|
766 | - $stream = 'php://input'; |
|
767 | - } |
|
768 | - |
|
769 | - return new Request( |
|
770 | - [ |
|
771 | - 'get' => $_GET, |
|
772 | - 'post' => $_POST, |
|
773 | - 'files' => $_FILES, |
|
774 | - 'server' => $_SERVER, |
|
775 | - 'env' => $_ENV, |
|
776 | - 'cookies' => $_COOKIE, |
|
777 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
778 | - ? $_SERVER['REQUEST_METHOD'] |
|
779 | - : null, |
|
780 | - 'urlParams' => $urlParams, |
|
781 | - ], |
|
782 | - $this->getSecureRandom(), |
|
783 | - $this->getConfig(), |
|
784 | - $this->getCsrfTokenManager(), |
|
785 | - $stream |
|
786 | - ); |
|
787 | - }); |
|
788 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
789 | - |
|
790 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
791 | - return new Mailer( |
|
792 | - $c->getConfig(), |
|
793 | - $c->getLogger(), |
|
794 | - $c->query(Defaults::class), |
|
795 | - $c->getURLGenerator(), |
|
796 | - $c->getL10N('lib') |
|
797 | - ); |
|
798 | - }); |
|
799 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
800 | - |
|
801 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
802 | - $config = $c->getConfig(); |
|
803 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
804 | - if (is_null($factoryClass)) { |
|
805 | - throw new \Exception('ldapProviderFactory not set'); |
|
806 | - } |
|
807 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
808 | - $factory = new $factoryClass($this); |
|
809 | - return $factory->getLDAPProvider(); |
|
810 | - }); |
|
811 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
812 | - $ini = $c->getIniWrapper(); |
|
813 | - $config = $c->getConfig(); |
|
814 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
815 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
816 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
817 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
818 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
819 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
820 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
821 | - } |
|
822 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
823 | - } |
|
824 | - return new NoopLockingProvider(); |
|
825 | - }); |
|
826 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
827 | - |
|
828 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
829 | - return new \OC\Files\Mount\Manager(); |
|
830 | - }); |
|
831 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
832 | - |
|
833 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
834 | - return new \OC\Files\Type\Detection( |
|
835 | - $c->getURLGenerator(), |
|
836 | - \OC::$configDir, |
|
837 | - \OC::$SERVERROOT . '/resources/config/' |
|
838 | - ); |
|
839 | - }); |
|
840 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
841 | - |
|
842 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
843 | - return new \OC\Files\Type\Loader( |
|
844 | - $c->getDatabaseConnection() |
|
845 | - ); |
|
846 | - }); |
|
847 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
848 | - $this->registerService(BundleFetcher::class, function () { |
|
849 | - return new BundleFetcher($this->getL10N('lib')); |
|
850 | - }); |
|
851 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
852 | - return new Manager( |
|
853 | - $c->query(IValidator::class) |
|
854 | - ); |
|
855 | - }); |
|
856 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
857 | - |
|
858 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
859 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
860 | - $manager->registerCapability(function () use ($c) { |
|
861 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
862 | - }); |
|
863 | - $manager->registerCapability(function () use ($c) { |
|
864 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
865 | - }); |
|
866 | - return $manager; |
|
867 | - }); |
|
868 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
869 | - |
|
870 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
871 | - $config = $c->getConfig(); |
|
872 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
873 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
874 | - $factory = new $factoryClass($this); |
|
875 | - return $factory->getManager(); |
|
876 | - }); |
|
877 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
878 | - |
|
879 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
880 | - /* |
|
135 | + /** @var string */ |
|
136 | + private $webRoot; |
|
137 | + |
|
138 | + /** |
|
139 | + * @param string $webRoot |
|
140 | + * @param \OC\Config $config |
|
141 | + */ |
|
142 | + public function __construct($webRoot, \OC\Config $config) { |
|
143 | + parent::__construct(); |
|
144 | + $this->webRoot = $webRoot; |
|
145 | + |
|
146 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
147 | + return $c; |
|
148 | + }); |
|
149 | + |
|
150 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
151 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
152 | + |
|
153 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
154 | + |
|
155 | + |
|
156 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
157 | + return new PreviewManager( |
|
158 | + $c->getConfig(), |
|
159 | + $c->getRootFolder(), |
|
160 | + $c->getAppDataDir('preview'), |
|
161 | + $c->getEventDispatcher(), |
|
162 | + $c->getSession()->get('user_id') |
|
163 | + ); |
|
164 | + }); |
|
165 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
166 | + |
|
167 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
168 | + return new \OC\Preview\Watcher( |
|
169 | + $c->getAppDataDir('preview') |
|
170 | + ); |
|
171 | + }); |
|
172 | + |
|
173 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
174 | + $view = new View(); |
|
175 | + $util = new Encryption\Util( |
|
176 | + $view, |
|
177 | + $c->getUserManager(), |
|
178 | + $c->getGroupManager(), |
|
179 | + $c->getConfig() |
|
180 | + ); |
|
181 | + return new Encryption\Manager( |
|
182 | + $c->getConfig(), |
|
183 | + $c->getLogger(), |
|
184 | + $c->getL10N('core'), |
|
185 | + new View(), |
|
186 | + $util, |
|
187 | + new ArrayCache() |
|
188 | + ); |
|
189 | + }); |
|
190 | + |
|
191 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
192 | + $util = new Encryption\Util( |
|
193 | + new View(), |
|
194 | + $c->getUserManager(), |
|
195 | + $c->getGroupManager(), |
|
196 | + $c->getConfig() |
|
197 | + ); |
|
198 | + return new Encryption\File( |
|
199 | + $util, |
|
200 | + $c->getRootFolder(), |
|
201 | + $c->getShareManager() |
|
202 | + ); |
|
203 | + }); |
|
204 | + |
|
205 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
206 | + $view = new View(); |
|
207 | + $util = new Encryption\Util( |
|
208 | + $view, |
|
209 | + $c->getUserManager(), |
|
210 | + $c->getGroupManager(), |
|
211 | + $c->getConfig() |
|
212 | + ); |
|
213 | + |
|
214 | + return new Encryption\Keys\Storage($view, $util); |
|
215 | + }); |
|
216 | + $this->registerService('TagMapper', function (Server $c) { |
|
217 | + return new TagMapper($c->getDatabaseConnection()); |
|
218 | + }); |
|
219 | + |
|
220 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
221 | + $tagMapper = $c->query('TagMapper'); |
|
222 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
223 | + }); |
|
224 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
225 | + |
|
226 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
227 | + $config = $c->getConfig(); |
|
228 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
229 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
230 | + $factory = new $factoryClass($this); |
|
231 | + return $factory; |
|
232 | + }); |
|
233 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
234 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
235 | + }); |
|
236 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
237 | + |
|
238 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
239 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
240 | + }); |
|
241 | + $this->registerService('RootFolder', function (Server $c) { |
|
242 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
243 | + $view = new View(); |
|
244 | + $root = new Root( |
|
245 | + $manager, |
|
246 | + $view, |
|
247 | + null, |
|
248 | + $c->getUserMountCache(), |
|
249 | + $this->getLogger(), |
|
250 | + $this->getUserManager() |
|
251 | + ); |
|
252 | + $connector = new HookConnector($root, $view); |
|
253 | + $connector->viewToNode(); |
|
254 | + |
|
255 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
256 | + $previewConnector->connectWatcher(); |
|
257 | + |
|
258 | + return $root; |
|
259 | + }); |
|
260 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
261 | + |
|
262 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
263 | + return new LazyRoot(function () use ($c) { |
|
264 | + return $c->query('RootFolder'); |
|
265 | + }); |
|
266 | + }); |
|
267 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
268 | + |
|
269 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
270 | + $config = $c->getConfig(); |
|
271 | + return new \OC\User\Manager($config); |
|
272 | + }); |
|
273 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
274 | + |
|
275 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
276 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
277 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
278 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
279 | + }); |
|
280 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
281 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
282 | + }); |
|
283 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
284 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
285 | + }); |
|
286 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
287 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
288 | + }); |
|
289 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
290 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
291 | + }); |
|
292 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
293 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
294 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
295 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
296 | + }); |
|
297 | + return $groupManager; |
|
298 | + }); |
|
299 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
300 | + |
|
301 | + $this->registerService(Store::class, function (Server $c) { |
|
302 | + $session = $c->getSession(); |
|
303 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
304 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
305 | + } else { |
|
306 | + $tokenProvider = null; |
|
307 | + } |
|
308 | + $logger = $c->getLogger(); |
|
309 | + return new Store($session, $logger, $tokenProvider); |
|
310 | + }); |
|
311 | + $this->registerAlias(IStore::class, Store::class); |
|
312 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
313 | + $dbConnection = $c->getDatabaseConnection(); |
|
314 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
315 | + }); |
|
316 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
317 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
318 | + $crypto = $c->getCrypto(); |
|
319 | + $config = $c->getConfig(); |
|
320 | + $logger = $c->getLogger(); |
|
321 | + $timeFactory = new TimeFactory(); |
|
322 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
323 | + }); |
|
324 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
325 | + |
|
326 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
327 | + $manager = $c->getUserManager(); |
|
328 | + $session = new \OC\Session\Memory(''); |
|
329 | + $timeFactory = new TimeFactory(); |
|
330 | + // Token providers might require a working database. This code |
|
331 | + // might however be called when ownCloud is not yet setup. |
|
332 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
333 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
334 | + } else { |
|
335 | + $defaultTokenProvider = null; |
|
336 | + } |
|
337 | + |
|
338 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
339 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
340 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
341 | + }); |
|
342 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
343 | + /** @var $user \OC\User\User */ |
|
344 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
345 | + }); |
|
346 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
347 | + /** @var $user \OC\User\User */ |
|
348 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
349 | + }); |
|
350 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
351 | + /** @var $user \OC\User\User */ |
|
352 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
353 | + }); |
|
354 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
355 | + /** @var $user \OC\User\User */ |
|
356 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
357 | + }); |
|
358 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
359 | + /** @var $user \OC\User\User */ |
|
360 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
361 | + }); |
|
362 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
363 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
364 | + }); |
|
365 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
366 | + /** @var $user \OC\User\User */ |
|
367 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
368 | + }); |
|
369 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
370 | + /** @var $user \OC\User\User */ |
|
371 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
372 | + }); |
|
373 | + $userSession->listen('\OC\User', 'logout', function () { |
|
374 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
375 | + }); |
|
376 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
377 | + /** @var $user \OC\User\User */ |
|
378 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
379 | + }); |
|
380 | + return $userSession; |
|
381 | + }); |
|
382 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
383 | + |
|
384 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
385 | + return new \OC\Authentication\TwoFactorAuth\Manager( |
|
386 | + $c->getAppManager(), |
|
387 | + $c->getSession(), |
|
388 | + $c->getConfig(), |
|
389 | + $c->getActivityManager(), |
|
390 | + $c->getLogger(), |
|
391 | + $c->query(\OC\Authentication\Token\IProvider::class), |
|
392 | + $c->query(ITimeFactory::class) |
|
393 | + ); |
|
394 | + }); |
|
395 | + |
|
396 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
397 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
398 | + |
|
399 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
400 | + return new \OC\AllConfig( |
|
401 | + $c->getSystemConfig() |
|
402 | + ); |
|
403 | + }); |
|
404 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
405 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
406 | + |
|
407 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
408 | + return new \OC\SystemConfig($config); |
|
409 | + }); |
|
410 | + |
|
411 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
412 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
413 | + }); |
|
414 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
415 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
416 | + |
|
417 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
418 | + return new \OC\L10N\Factory( |
|
419 | + $c->getConfig(), |
|
420 | + $c->getRequest(), |
|
421 | + $c->getUserSession(), |
|
422 | + \OC::$SERVERROOT |
|
423 | + ); |
|
424 | + }); |
|
425 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
426 | + |
|
427 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
428 | + $config = $c->getConfig(); |
|
429 | + $cacheFactory = $c->getMemCacheFactory(); |
|
430 | + $request = $c->getRequest(); |
|
431 | + return new \OC\URLGenerator( |
|
432 | + $config, |
|
433 | + $cacheFactory, |
|
434 | + $request |
|
435 | + ); |
|
436 | + }); |
|
437 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
438 | + |
|
439 | + $this->registerService('AppHelper', function ($c) { |
|
440 | + return new \OC\AppHelper(); |
|
441 | + }); |
|
442 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
443 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
444 | + |
|
445 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
446 | + return new Cache\File(); |
|
447 | + }); |
|
448 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
449 | + |
|
450 | + $this->registerService(Factory::class, function (Server $c) { |
|
451 | + |
|
452 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
453 | + '\\OC\\Memcache\\ArrayCache', |
|
454 | + '\\OC\\Memcache\\ArrayCache', |
|
455 | + '\\OC\\Memcache\\ArrayCache' |
|
456 | + ); |
|
457 | + $config = $c->getConfig(); |
|
458 | + $request = $c->getRequest(); |
|
459 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
460 | + |
|
461 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
462 | + $v = \OC_App::getAppVersions(); |
|
463 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
464 | + $version = implode(',', $v); |
|
465 | + $instanceId = \OC_Util::getInstanceId(); |
|
466 | + $path = \OC::$SERVERROOT; |
|
467 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
468 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
469 | + $config->getSystemValue('memcache.local', null), |
|
470 | + $config->getSystemValue('memcache.distributed', null), |
|
471 | + $config->getSystemValue('memcache.locking', null) |
|
472 | + ); |
|
473 | + } |
|
474 | + return $arrayCacheFactory; |
|
475 | + |
|
476 | + }); |
|
477 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
478 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
479 | + |
|
480 | + $this->registerService('RedisFactory', function (Server $c) { |
|
481 | + $systemConfig = $c->getSystemConfig(); |
|
482 | + return new RedisFactory($systemConfig); |
|
483 | + }); |
|
484 | + |
|
485 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
486 | + return new \OC\Activity\Manager( |
|
487 | + $c->getRequest(), |
|
488 | + $c->getUserSession(), |
|
489 | + $c->getConfig(), |
|
490 | + $c->query(IValidator::class) |
|
491 | + ); |
|
492 | + }); |
|
493 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
494 | + |
|
495 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
496 | + return new \OC\Activity\EventMerger( |
|
497 | + $c->getL10N('lib') |
|
498 | + ); |
|
499 | + }); |
|
500 | + $this->registerAlias(IValidator::class, Validator::class); |
|
501 | + |
|
502 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
503 | + return new AvatarManager( |
|
504 | + $c->getUserManager(), |
|
505 | + $c->getAppDataDir('avatar'), |
|
506 | + $c->getL10N('lib'), |
|
507 | + $c->getLogger(), |
|
508 | + $c->getConfig() |
|
509 | + ); |
|
510 | + }); |
|
511 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
512 | + |
|
513 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
514 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
515 | + $logger = Log::getLogClass($logType); |
|
516 | + call_user_func(array($logger, 'init')); |
|
517 | + |
|
518 | + return new Log($logger); |
|
519 | + }); |
|
520 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
521 | + |
|
522 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
523 | + $config = $c->getConfig(); |
|
524 | + return new \OC\BackgroundJob\JobList( |
|
525 | + $c->getDatabaseConnection(), |
|
526 | + $config, |
|
527 | + new TimeFactory() |
|
528 | + ); |
|
529 | + }); |
|
530 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
531 | + |
|
532 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
533 | + $cacheFactory = $c->getMemCacheFactory(); |
|
534 | + $logger = $c->getLogger(); |
|
535 | + if ($cacheFactory->isAvailable()) { |
|
536 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
537 | + } else { |
|
538 | + $router = new \OC\Route\Router($logger); |
|
539 | + } |
|
540 | + return $router; |
|
541 | + }); |
|
542 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
543 | + |
|
544 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
545 | + return new Search(); |
|
546 | + }); |
|
547 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
548 | + |
|
549 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
|
550 | + return new \OC\Security\RateLimiting\Limiter( |
|
551 | + $this->getUserSession(), |
|
552 | + $this->getRequest(), |
|
553 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
554 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
555 | + ); |
|
556 | + }); |
|
557 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
558 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
559 | + $this->getMemCacheFactory(), |
|
560 | + new \OC\AppFramework\Utility\TimeFactory() |
|
561 | + ); |
|
562 | + }); |
|
563 | + |
|
564 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
565 | + return new SecureRandom(); |
|
566 | + }); |
|
567 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
568 | + |
|
569 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
570 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
571 | + }); |
|
572 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
573 | + |
|
574 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
575 | + return new Hasher($c->getConfig()); |
|
576 | + }); |
|
577 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
578 | + |
|
579 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
580 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
581 | + }); |
|
582 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
583 | + |
|
584 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
585 | + $systemConfig = $c->getSystemConfig(); |
|
586 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
587 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
588 | + if (!$factory->isValidType($type)) { |
|
589 | + throw new \OC\DatabaseException('Invalid database type'); |
|
590 | + } |
|
591 | + $connectionParams = $factory->createConnectionParams(); |
|
592 | + $connection = $factory->getConnection($type, $connectionParams); |
|
593 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
594 | + return $connection; |
|
595 | + }); |
|
596 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
597 | + |
|
598 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
599 | + $config = $c->getConfig(); |
|
600 | + return new HTTPHelper( |
|
601 | + $config, |
|
602 | + $c->getHTTPClientService() |
|
603 | + ); |
|
604 | + }); |
|
605 | + |
|
606 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
607 | + $user = \OC_User::getUser(); |
|
608 | + $uid = $user ? $user : null; |
|
609 | + return new ClientService( |
|
610 | + $c->getConfig(), |
|
611 | + new \OC\Security\CertificateManager( |
|
612 | + $uid, |
|
613 | + new View(), |
|
614 | + $c->getConfig(), |
|
615 | + $c->getLogger(), |
|
616 | + $c->getSecureRandom() |
|
617 | + ) |
|
618 | + ); |
|
619 | + }); |
|
620 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
621 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
622 | + $eventLogger = new EventLogger(); |
|
623 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
624 | + // In debug mode, module is being activated by default |
|
625 | + $eventLogger->activate(); |
|
626 | + } |
|
627 | + return $eventLogger; |
|
628 | + }); |
|
629 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
630 | + |
|
631 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
632 | + $queryLogger = new QueryLogger(); |
|
633 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
634 | + // In debug mode, module is being activated by default |
|
635 | + $queryLogger->activate(); |
|
636 | + } |
|
637 | + return $queryLogger; |
|
638 | + }); |
|
639 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
640 | + |
|
641 | + $this->registerService(TempManager::class, function (Server $c) { |
|
642 | + return new TempManager( |
|
643 | + $c->getLogger(), |
|
644 | + $c->getConfig() |
|
645 | + ); |
|
646 | + }); |
|
647 | + $this->registerAlias('TempManager', TempManager::class); |
|
648 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
649 | + |
|
650 | + $this->registerService(AppManager::class, function (Server $c) { |
|
651 | + return new \OC\App\AppManager( |
|
652 | + $c->getUserSession(), |
|
653 | + $c->getAppConfig(), |
|
654 | + $c->getGroupManager(), |
|
655 | + $c->getMemCacheFactory(), |
|
656 | + $c->getEventDispatcher() |
|
657 | + ); |
|
658 | + }); |
|
659 | + $this->registerAlias('AppManager', AppManager::class); |
|
660 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
661 | + |
|
662 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
663 | + return new DateTimeZone( |
|
664 | + $c->getConfig(), |
|
665 | + $c->getSession() |
|
666 | + ); |
|
667 | + }); |
|
668 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
669 | + |
|
670 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
671 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
672 | + |
|
673 | + return new DateTimeFormatter( |
|
674 | + $c->getDateTimeZone()->getTimeZone(), |
|
675 | + $c->getL10N('lib', $language) |
|
676 | + ); |
|
677 | + }); |
|
678 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
679 | + |
|
680 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
681 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
682 | + $listener = new UserMountCacheListener($mountCache); |
|
683 | + $listener->listen($c->getUserManager()); |
|
684 | + return $mountCache; |
|
685 | + }); |
|
686 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
687 | + |
|
688 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
689 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
690 | + $mountCache = $c->query('UserMountCache'); |
|
691 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
692 | + |
|
693 | + // builtin providers |
|
694 | + |
|
695 | + $config = $c->getConfig(); |
|
696 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
697 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
698 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
699 | + |
|
700 | + return $manager; |
|
701 | + }); |
|
702 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
703 | + |
|
704 | + $this->registerService('IniWrapper', function ($c) { |
|
705 | + return new IniGetWrapper(); |
|
706 | + }); |
|
707 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
708 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
709 | + if ($busClass) { |
|
710 | + list($app, $class) = explode('::', $busClass, 2); |
|
711 | + if ($c->getAppManager()->isInstalled($app)) { |
|
712 | + \OC_App::loadApp($app); |
|
713 | + return $c->query($class); |
|
714 | + } else { |
|
715 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
716 | + } |
|
717 | + } else { |
|
718 | + $jobList = $c->getJobList(); |
|
719 | + return new CronBus($jobList); |
|
720 | + } |
|
721 | + }); |
|
722 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
723 | + return new TrustedDomainHelper($this->getConfig()); |
|
724 | + }); |
|
725 | + $this->registerService('Throttler', function (Server $c) { |
|
726 | + return new Throttler( |
|
727 | + $c->getDatabaseConnection(), |
|
728 | + new TimeFactory(), |
|
729 | + $c->getLogger(), |
|
730 | + $c->getConfig() |
|
731 | + ); |
|
732 | + }); |
|
733 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
734 | + // IConfig and IAppManager requires a working database. This code |
|
735 | + // might however be called when ownCloud is not yet setup. |
|
736 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
737 | + $config = $c->getConfig(); |
|
738 | + $appManager = $c->getAppManager(); |
|
739 | + } else { |
|
740 | + $config = null; |
|
741 | + $appManager = null; |
|
742 | + } |
|
743 | + |
|
744 | + return new Checker( |
|
745 | + new EnvironmentHelper(), |
|
746 | + new FileAccessHelper(), |
|
747 | + new AppLocator(), |
|
748 | + $config, |
|
749 | + $c->getMemCacheFactory(), |
|
750 | + $appManager, |
|
751 | + $c->getTempManager() |
|
752 | + ); |
|
753 | + }); |
|
754 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
755 | + if (isset($this['urlParams'])) { |
|
756 | + $urlParams = $this['urlParams']; |
|
757 | + } else { |
|
758 | + $urlParams = []; |
|
759 | + } |
|
760 | + |
|
761 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
762 | + && in_array('fakeinput', stream_get_wrappers()) |
|
763 | + ) { |
|
764 | + $stream = 'fakeinput://data'; |
|
765 | + } else { |
|
766 | + $stream = 'php://input'; |
|
767 | + } |
|
768 | + |
|
769 | + return new Request( |
|
770 | + [ |
|
771 | + 'get' => $_GET, |
|
772 | + 'post' => $_POST, |
|
773 | + 'files' => $_FILES, |
|
774 | + 'server' => $_SERVER, |
|
775 | + 'env' => $_ENV, |
|
776 | + 'cookies' => $_COOKIE, |
|
777 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
778 | + ? $_SERVER['REQUEST_METHOD'] |
|
779 | + : null, |
|
780 | + 'urlParams' => $urlParams, |
|
781 | + ], |
|
782 | + $this->getSecureRandom(), |
|
783 | + $this->getConfig(), |
|
784 | + $this->getCsrfTokenManager(), |
|
785 | + $stream |
|
786 | + ); |
|
787 | + }); |
|
788 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
789 | + |
|
790 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
791 | + return new Mailer( |
|
792 | + $c->getConfig(), |
|
793 | + $c->getLogger(), |
|
794 | + $c->query(Defaults::class), |
|
795 | + $c->getURLGenerator(), |
|
796 | + $c->getL10N('lib') |
|
797 | + ); |
|
798 | + }); |
|
799 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
800 | + |
|
801 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
802 | + $config = $c->getConfig(); |
|
803 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
804 | + if (is_null($factoryClass)) { |
|
805 | + throw new \Exception('ldapProviderFactory not set'); |
|
806 | + } |
|
807 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
808 | + $factory = new $factoryClass($this); |
|
809 | + return $factory->getLDAPProvider(); |
|
810 | + }); |
|
811 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
812 | + $ini = $c->getIniWrapper(); |
|
813 | + $config = $c->getConfig(); |
|
814 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
815 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
816 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
817 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
818 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
819 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
820 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
821 | + } |
|
822 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
823 | + } |
|
824 | + return new NoopLockingProvider(); |
|
825 | + }); |
|
826 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
827 | + |
|
828 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
829 | + return new \OC\Files\Mount\Manager(); |
|
830 | + }); |
|
831 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
832 | + |
|
833 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
834 | + return new \OC\Files\Type\Detection( |
|
835 | + $c->getURLGenerator(), |
|
836 | + \OC::$configDir, |
|
837 | + \OC::$SERVERROOT . '/resources/config/' |
|
838 | + ); |
|
839 | + }); |
|
840 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
841 | + |
|
842 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
843 | + return new \OC\Files\Type\Loader( |
|
844 | + $c->getDatabaseConnection() |
|
845 | + ); |
|
846 | + }); |
|
847 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
848 | + $this->registerService(BundleFetcher::class, function () { |
|
849 | + return new BundleFetcher($this->getL10N('lib')); |
|
850 | + }); |
|
851 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
852 | + return new Manager( |
|
853 | + $c->query(IValidator::class) |
|
854 | + ); |
|
855 | + }); |
|
856 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
857 | + |
|
858 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
859 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
860 | + $manager->registerCapability(function () use ($c) { |
|
861 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
862 | + }); |
|
863 | + $manager->registerCapability(function () use ($c) { |
|
864 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
865 | + }); |
|
866 | + return $manager; |
|
867 | + }); |
|
868 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
869 | + |
|
870 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
871 | + $config = $c->getConfig(); |
|
872 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
873 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
874 | + $factory = new $factoryClass($this); |
|
875 | + return $factory->getManager(); |
|
876 | + }); |
|
877 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
878 | + |
|
879 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
880 | + /* |
|
881 | 881 | * Dark magic for autoloader. |
882 | 882 | * If we do a class_exists it will try to load the class which will |
883 | 883 | * make composer cache the result. Resulting in errors when enabling |
884 | 884 | * the theming app. |
885 | 885 | */ |
886 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
887 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
888 | - $classExists = true; |
|
889 | - } else { |
|
890 | - $classExists = false; |
|
891 | - } |
|
892 | - |
|
893 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
894 | - return new ThemingDefaults( |
|
895 | - $c->getConfig(), |
|
896 | - $c->getL10N('theming'), |
|
897 | - $c->getURLGenerator(), |
|
898 | - $c->getAppDataDir('theming'), |
|
899 | - $c->getMemCacheFactory(), |
|
900 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
901 | - $this->getAppManager() |
|
902 | - ); |
|
903 | - } |
|
904 | - return new \OC_Defaults(); |
|
905 | - }); |
|
906 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
907 | - /** @var Factory $cacheFactory */ |
|
908 | - $cacheFactory = $c->query(Factory::class); |
|
909 | - return new SCSSCacher( |
|
910 | - $c->getLogger(), |
|
911 | - $c->query(\OC\Files\AppData\Factory::class), |
|
912 | - $c->getURLGenerator(), |
|
913 | - $c->getConfig(), |
|
914 | - $c->getThemingDefaults(), |
|
915 | - \OC::$SERVERROOT, |
|
916 | - $cacheFactory->create('SCSS') |
|
917 | - ); |
|
918 | - }); |
|
919 | - $this->registerService(EventDispatcher::class, function () { |
|
920 | - return new EventDispatcher(); |
|
921 | - }); |
|
922 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
923 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
924 | - |
|
925 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
926 | - // FIXME: Instantiiated here due to cyclic dependency |
|
927 | - $request = new Request( |
|
928 | - [ |
|
929 | - 'get' => $_GET, |
|
930 | - 'post' => $_POST, |
|
931 | - 'files' => $_FILES, |
|
932 | - 'server' => $_SERVER, |
|
933 | - 'env' => $_ENV, |
|
934 | - 'cookies' => $_COOKIE, |
|
935 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
936 | - ? $_SERVER['REQUEST_METHOD'] |
|
937 | - : null, |
|
938 | - ], |
|
939 | - $c->getSecureRandom(), |
|
940 | - $c->getConfig() |
|
941 | - ); |
|
942 | - |
|
943 | - return new CryptoWrapper( |
|
944 | - $c->getConfig(), |
|
945 | - $c->getCrypto(), |
|
946 | - $c->getSecureRandom(), |
|
947 | - $request |
|
948 | - ); |
|
949 | - }); |
|
950 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
951 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
952 | - |
|
953 | - return new CsrfTokenManager( |
|
954 | - $tokenGenerator, |
|
955 | - $c->query(SessionStorage::class) |
|
956 | - ); |
|
957 | - }); |
|
958 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
959 | - return new SessionStorage($c->getSession()); |
|
960 | - }); |
|
961 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
962 | - return new ContentSecurityPolicyManager(); |
|
963 | - }); |
|
964 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
965 | - |
|
966 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
967 | - return new ContentSecurityPolicyNonceManager( |
|
968 | - $c->getCsrfTokenManager(), |
|
969 | - $c->getRequest() |
|
970 | - ); |
|
971 | - }); |
|
972 | - |
|
973 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
974 | - $config = $c->getConfig(); |
|
975 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
976 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
977 | - $factory = new $factoryClass($this); |
|
978 | - |
|
979 | - $manager = new \OC\Share20\Manager( |
|
980 | - $c->getLogger(), |
|
981 | - $c->getConfig(), |
|
982 | - $c->getSecureRandom(), |
|
983 | - $c->getHasher(), |
|
984 | - $c->getMountManager(), |
|
985 | - $c->getGroupManager(), |
|
986 | - $c->getL10N('lib'), |
|
987 | - $c->getL10NFactory(), |
|
988 | - $factory, |
|
989 | - $c->getUserManager(), |
|
990 | - $c->getLazyRootFolder(), |
|
991 | - $c->getEventDispatcher(), |
|
992 | - $c->getMailer(), |
|
993 | - $c->getURLGenerator(), |
|
994 | - $c->getThemingDefaults() |
|
995 | - ); |
|
996 | - |
|
997 | - return $manager; |
|
998 | - }); |
|
999 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1000 | - |
|
1001 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1002 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1003 | - |
|
1004 | - // register default plugins |
|
1005 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1006 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1007 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1008 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1009 | - |
|
1010 | - return $instance; |
|
1011 | - }); |
|
1012 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1013 | - |
|
1014 | - $this->registerService('SettingsManager', function (Server $c) { |
|
1015 | - $manager = new \OC\Settings\Manager( |
|
1016 | - $c->getLogger(), |
|
1017 | - $c->getDatabaseConnection(), |
|
1018 | - $c->getL10N('lib'), |
|
1019 | - $c->getConfig(), |
|
1020 | - $c->getEncryptionManager(), |
|
1021 | - $c->getUserManager(), |
|
1022 | - $c->getLockingProvider(), |
|
1023 | - $c->getRequest(), |
|
1024 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1025 | - $c->getURLGenerator(), |
|
1026 | - $c->query(AccountManager::class), |
|
1027 | - $c->getGroupManager(), |
|
1028 | - $c->getL10NFactory(), |
|
1029 | - $c->getThemingDefaults(), |
|
1030 | - $c->getAppManager() |
|
1031 | - ); |
|
1032 | - return $manager; |
|
1033 | - }); |
|
1034 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1035 | - return new \OC\Files\AppData\Factory( |
|
1036 | - $c->getRootFolder(), |
|
1037 | - $c->getSystemConfig() |
|
1038 | - ); |
|
1039 | - }); |
|
1040 | - |
|
1041 | - $this->registerService('LockdownManager', function (Server $c) { |
|
1042 | - return new LockdownManager(function () use ($c) { |
|
1043 | - return $c->getSession(); |
|
1044 | - }); |
|
1045 | - }); |
|
1046 | - |
|
1047 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1048 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1049 | - }); |
|
1050 | - |
|
1051 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1052 | - return new CloudIdManager(); |
|
1053 | - }); |
|
1054 | - |
|
1055 | - /* To trick DI since we don't extend the DIContainer here */ |
|
1056 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1057 | - return new CleanPreviewsBackgroundJob( |
|
1058 | - $c->getRootFolder(), |
|
1059 | - $c->getLogger(), |
|
1060 | - $c->getJobList(), |
|
1061 | - new TimeFactory() |
|
1062 | - ); |
|
1063 | - }); |
|
1064 | - |
|
1065 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1066 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1067 | - |
|
1068 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1069 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1070 | - |
|
1071 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1072 | - return new Defaults( |
|
1073 | - $c->getThemingDefaults() |
|
1074 | - ); |
|
1075 | - }); |
|
1076 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1077 | - |
|
1078 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1079 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1080 | - }); |
|
1081 | - |
|
1082 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
1083 | - return new ShareHelper( |
|
1084 | - $c->query(\OCP\Share\IManager::class) |
|
1085 | - ); |
|
1086 | - }); |
|
1087 | - } |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * @return \OCP\Contacts\IManager |
|
1091 | - */ |
|
1092 | - public function getContactsManager() { |
|
1093 | - return $this->query('ContactsManager'); |
|
1094 | - } |
|
1095 | - |
|
1096 | - /** |
|
1097 | - * @return \OC\Encryption\Manager |
|
1098 | - */ |
|
1099 | - public function getEncryptionManager() { |
|
1100 | - return $this->query('EncryptionManager'); |
|
1101 | - } |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * @return \OC\Encryption\File |
|
1105 | - */ |
|
1106 | - public function getEncryptionFilesHelper() { |
|
1107 | - return $this->query('EncryptionFileHelper'); |
|
1108 | - } |
|
1109 | - |
|
1110 | - /** |
|
1111 | - * @return \OCP\Encryption\Keys\IStorage |
|
1112 | - */ |
|
1113 | - public function getEncryptionKeyStorage() { |
|
1114 | - return $this->query('EncryptionKeyStorage'); |
|
1115 | - } |
|
1116 | - |
|
1117 | - /** |
|
1118 | - * The current request object holding all information about the request |
|
1119 | - * currently being processed is returned from this method. |
|
1120 | - * In case the current execution was not initiated by a web request null is returned |
|
1121 | - * |
|
1122 | - * @return \OCP\IRequest |
|
1123 | - */ |
|
1124 | - public function getRequest() { |
|
1125 | - return $this->query('Request'); |
|
1126 | - } |
|
1127 | - |
|
1128 | - /** |
|
1129 | - * Returns the preview manager which can create preview images for a given file |
|
1130 | - * |
|
1131 | - * @return \OCP\IPreview |
|
1132 | - */ |
|
1133 | - public function getPreviewManager() { |
|
1134 | - return $this->query('PreviewManager'); |
|
1135 | - } |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * Returns the tag manager which can get and set tags for different object types |
|
1139 | - * |
|
1140 | - * @see \OCP\ITagManager::load() |
|
1141 | - * @return \OCP\ITagManager |
|
1142 | - */ |
|
1143 | - public function getTagManager() { |
|
1144 | - return $this->query('TagManager'); |
|
1145 | - } |
|
1146 | - |
|
1147 | - /** |
|
1148 | - * Returns the system-tag manager |
|
1149 | - * |
|
1150 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1151 | - * |
|
1152 | - * @since 9.0.0 |
|
1153 | - */ |
|
1154 | - public function getSystemTagManager() { |
|
1155 | - return $this->query('SystemTagManager'); |
|
1156 | - } |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * Returns the system-tag object mapper |
|
1160 | - * |
|
1161 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1162 | - * |
|
1163 | - * @since 9.0.0 |
|
1164 | - */ |
|
1165 | - public function getSystemTagObjectMapper() { |
|
1166 | - return $this->query('SystemTagObjectMapper'); |
|
1167 | - } |
|
1168 | - |
|
1169 | - /** |
|
1170 | - * Returns the avatar manager, used for avatar functionality |
|
1171 | - * |
|
1172 | - * @return \OCP\IAvatarManager |
|
1173 | - */ |
|
1174 | - public function getAvatarManager() { |
|
1175 | - return $this->query('AvatarManager'); |
|
1176 | - } |
|
1177 | - |
|
1178 | - /** |
|
1179 | - * Returns the root folder of ownCloud's data directory |
|
1180 | - * |
|
1181 | - * @return \OCP\Files\IRootFolder |
|
1182 | - */ |
|
1183 | - public function getRootFolder() { |
|
1184 | - return $this->query('LazyRootFolder'); |
|
1185 | - } |
|
1186 | - |
|
1187 | - /** |
|
1188 | - * Returns the root folder of ownCloud's data directory |
|
1189 | - * This is the lazy variant so this gets only initialized once it |
|
1190 | - * is actually used. |
|
1191 | - * |
|
1192 | - * @return \OCP\Files\IRootFolder |
|
1193 | - */ |
|
1194 | - public function getLazyRootFolder() { |
|
1195 | - return $this->query('LazyRootFolder'); |
|
1196 | - } |
|
1197 | - |
|
1198 | - /** |
|
1199 | - * Returns a view to ownCloud's files folder |
|
1200 | - * |
|
1201 | - * @param string $userId user ID |
|
1202 | - * @return \OCP\Files\Folder|null |
|
1203 | - */ |
|
1204 | - public function getUserFolder($userId = null) { |
|
1205 | - if ($userId === null) { |
|
1206 | - $user = $this->getUserSession()->getUser(); |
|
1207 | - if (!$user) { |
|
1208 | - return null; |
|
1209 | - } |
|
1210 | - $userId = $user->getUID(); |
|
1211 | - } |
|
1212 | - $root = $this->getRootFolder(); |
|
1213 | - return $root->getUserFolder($userId); |
|
1214 | - } |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * Returns an app-specific view in ownClouds data directory |
|
1218 | - * |
|
1219 | - * @return \OCP\Files\Folder |
|
1220 | - * @deprecated since 9.2.0 use IAppData |
|
1221 | - */ |
|
1222 | - public function getAppFolder() { |
|
1223 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1224 | - $root = $this->getRootFolder(); |
|
1225 | - if (!$root->nodeExists($dir)) { |
|
1226 | - $folder = $root->newFolder($dir); |
|
1227 | - } else { |
|
1228 | - $folder = $root->get($dir); |
|
1229 | - } |
|
1230 | - return $folder; |
|
1231 | - } |
|
1232 | - |
|
1233 | - /** |
|
1234 | - * @return \OC\User\Manager |
|
1235 | - */ |
|
1236 | - public function getUserManager() { |
|
1237 | - return $this->query('UserManager'); |
|
1238 | - } |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * @return \OC\Group\Manager |
|
1242 | - */ |
|
1243 | - public function getGroupManager() { |
|
1244 | - return $this->query('GroupManager'); |
|
1245 | - } |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * @return \OC\User\Session |
|
1249 | - */ |
|
1250 | - public function getUserSession() { |
|
1251 | - return $this->query('UserSession'); |
|
1252 | - } |
|
1253 | - |
|
1254 | - /** |
|
1255 | - * @return \OCP\ISession |
|
1256 | - */ |
|
1257 | - public function getSession() { |
|
1258 | - return $this->query('UserSession')->getSession(); |
|
1259 | - } |
|
1260 | - |
|
1261 | - /** |
|
1262 | - * @param \OCP\ISession $session |
|
1263 | - */ |
|
1264 | - public function setSession(\OCP\ISession $session) { |
|
1265 | - $this->query(SessionStorage::class)->setSession($session); |
|
1266 | - $this->query('UserSession')->setSession($session); |
|
1267 | - $this->query(Store::class)->setSession($session); |
|
1268 | - } |
|
1269 | - |
|
1270 | - /** |
|
1271 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1272 | - */ |
|
1273 | - public function getTwoFactorAuthManager() { |
|
1274 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1275 | - } |
|
1276 | - |
|
1277 | - /** |
|
1278 | - * @return \OC\NavigationManager |
|
1279 | - */ |
|
1280 | - public function getNavigationManager() { |
|
1281 | - return $this->query('NavigationManager'); |
|
1282 | - } |
|
1283 | - |
|
1284 | - /** |
|
1285 | - * @return \OCP\IConfig |
|
1286 | - */ |
|
1287 | - public function getConfig() { |
|
1288 | - return $this->query('AllConfig'); |
|
1289 | - } |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * @return \OC\SystemConfig |
|
1293 | - */ |
|
1294 | - public function getSystemConfig() { |
|
1295 | - return $this->query('SystemConfig'); |
|
1296 | - } |
|
1297 | - |
|
1298 | - /** |
|
1299 | - * Returns the app config manager |
|
1300 | - * |
|
1301 | - * @return \OCP\IAppConfig |
|
1302 | - */ |
|
1303 | - public function getAppConfig() { |
|
1304 | - return $this->query('AppConfig'); |
|
1305 | - } |
|
1306 | - |
|
1307 | - /** |
|
1308 | - * @return \OCP\L10N\IFactory |
|
1309 | - */ |
|
1310 | - public function getL10NFactory() { |
|
1311 | - return $this->query('L10NFactory'); |
|
1312 | - } |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * get an L10N instance |
|
1316 | - * |
|
1317 | - * @param string $app appid |
|
1318 | - * @param string $lang |
|
1319 | - * @return IL10N |
|
1320 | - */ |
|
1321 | - public function getL10N($app, $lang = null) { |
|
1322 | - return $this->getL10NFactory()->get($app, $lang); |
|
1323 | - } |
|
1324 | - |
|
1325 | - /** |
|
1326 | - * @return \OCP\IURLGenerator |
|
1327 | - */ |
|
1328 | - public function getURLGenerator() { |
|
1329 | - return $this->query('URLGenerator'); |
|
1330 | - } |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * @return \OCP\IHelper |
|
1334 | - */ |
|
1335 | - public function getHelper() { |
|
1336 | - return $this->query('AppHelper'); |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * @return AppFetcher |
|
1341 | - */ |
|
1342 | - public function getAppFetcher() { |
|
1343 | - return $this->query(AppFetcher::class); |
|
1344 | - } |
|
1345 | - |
|
1346 | - /** |
|
1347 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1348 | - * getMemCacheFactory() instead. |
|
1349 | - * |
|
1350 | - * @return \OCP\ICache |
|
1351 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1352 | - */ |
|
1353 | - public function getCache() { |
|
1354 | - return $this->query('UserCache'); |
|
1355 | - } |
|
1356 | - |
|
1357 | - /** |
|
1358 | - * Returns an \OCP\CacheFactory instance |
|
1359 | - * |
|
1360 | - * @return \OCP\ICacheFactory |
|
1361 | - */ |
|
1362 | - public function getMemCacheFactory() { |
|
1363 | - return $this->query('MemCacheFactory'); |
|
1364 | - } |
|
1365 | - |
|
1366 | - /** |
|
1367 | - * Returns an \OC\RedisFactory instance |
|
1368 | - * |
|
1369 | - * @return \OC\RedisFactory |
|
1370 | - */ |
|
1371 | - public function getGetRedisFactory() { |
|
1372 | - return $this->query('RedisFactory'); |
|
1373 | - } |
|
1374 | - |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * Returns the current session |
|
1378 | - * |
|
1379 | - * @return \OCP\IDBConnection |
|
1380 | - */ |
|
1381 | - public function getDatabaseConnection() { |
|
1382 | - return $this->query('DatabaseConnection'); |
|
1383 | - } |
|
1384 | - |
|
1385 | - /** |
|
1386 | - * Returns the activity manager |
|
1387 | - * |
|
1388 | - * @return \OCP\Activity\IManager |
|
1389 | - */ |
|
1390 | - public function getActivityManager() { |
|
1391 | - return $this->query('ActivityManager'); |
|
1392 | - } |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * Returns an job list for controlling background jobs |
|
1396 | - * |
|
1397 | - * @return \OCP\BackgroundJob\IJobList |
|
1398 | - */ |
|
1399 | - public function getJobList() { |
|
1400 | - return $this->query('JobList'); |
|
1401 | - } |
|
1402 | - |
|
1403 | - /** |
|
1404 | - * Returns a logger instance |
|
1405 | - * |
|
1406 | - * @return \OCP\ILogger |
|
1407 | - */ |
|
1408 | - public function getLogger() { |
|
1409 | - return $this->query('Logger'); |
|
1410 | - } |
|
1411 | - |
|
1412 | - /** |
|
1413 | - * Returns a router for generating and matching urls |
|
1414 | - * |
|
1415 | - * @return \OCP\Route\IRouter |
|
1416 | - */ |
|
1417 | - public function getRouter() { |
|
1418 | - return $this->query('Router'); |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Returns a search instance |
|
1423 | - * |
|
1424 | - * @return \OCP\ISearch |
|
1425 | - */ |
|
1426 | - public function getSearch() { |
|
1427 | - return $this->query('Search'); |
|
1428 | - } |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * Returns a SecureRandom instance |
|
1432 | - * |
|
1433 | - * @return \OCP\Security\ISecureRandom |
|
1434 | - */ |
|
1435 | - public function getSecureRandom() { |
|
1436 | - return $this->query('SecureRandom'); |
|
1437 | - } |
|
1438 | - |
|
1439 | - /** |
|
1440 | - * Returns a Crypto instance |
|
1441 | - * |
|
1442 | - * @return \OCP\Security\ICrypto |
|
1443 | - */ |
|
1444 | - public function getCrypto() { |
|
1445 | - return $this->query('Crypto'); |
|
1446 | - } |
|
1447 | - |
|
1448 | - /** |
|
1449 | - * Returns a Hasher instance |
|
1450 | - * |
|
1451 | - * @return \OCP\Security\IHasher |
|
1452 | - */ |
|
1453 | - public function getHasher() { |
|
1454 | - return $this->query('Hasher'); |
|
1455 | - } |
|
1456 | - |
|
1457 | - /** |
|
1458 | - * Returns a CredentialsManager instance |
|
1459 | - * |
|
1460 | - * @return \OCP\Security\ICredentialsManager |
|
1461 | - */ |
|
1462 | - public function getCredentialsManager() { |
|
1463 | - return $this->query('CredentialsManager'); |
|
1464 | - } |
|
1465 | - |
|
1466 | - /** |
|
1467 | - * Returns an instance of the HTTP helper class |
|
1468 | - * |
|
1469 | - * @deprecated Use getHTTPClientService() |
|
1470 | - * @return \OC\HTTPHelper |
|
1471 | - */ |
|
1472 | - public function getHTTPHelper() { |
|
1473 | - return $this->query('HTTPHelper'); |
|
1474 | - } |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * Get the certificate manager for the user |
|
1478 | - * |
|
1479 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1480 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1481 | - */ |
|
1482 | - public function getCertificateManager($userId = '') { |
|
1483 | - if ($userId === '') { |
|
1484 | - $userSession = $this->getUserSession(); |
|
1485 | - $user = $userSession->getUser(); |
|
1486 | - if (is_null($user)) { |
|
1487 | - return null; |
|
1488 | - } |
|
1489 | - $userId = $user->getUID(); |
|
1490 | - } |
|
1491 | - return new CertificateManager( |
|
1492 | - $userId, |
|
1493 | - new View(), |
|
1494 | - $this->getConfig(), |
|
1495 | - $this->getLogger(), |
|
1496 | - $this->getSecureRandom() |
|
1497 | - ); |
|
1498 | - } |
|
1499 | - |
|
1500 | - /** |
|
1501 | - * Returns an instance of the HTTP client service |
|
1502 | - * |
|
1503 | - * @return \OCP\Http\Client\IClientService |
|
1504 | - */ |
|
1505 | - public function getHTTPClientService() { |
|
1506 | - return $this->query('HttpClientService'); |
|
1507 | - } |
|
1508 | - |
|
1509 | - /** |
|
1510 | - * Create a new event source |
|
1511 | - * |
|
1512 | - * @return \OCP\IEventSource |
|
1513 | - */ |
|
1514 | - public function createEventSource() { |
|
1515 | - return new \OC_EventSource(); |
|
1516 | - } |
|
1517 | - |
|
1518 | - /** |
|
1519 | - * Get the active event logger |
|
1520 | - * |
|
1521 | - * The returned logger only logs data when debug mode is enabled |
|
1522 | - * |
|
1523 | - * @return \OCP\Diagnostics\IEventLogger |
|
1524 | - */ |
|
1525 | - public function getEventLogger() { |
|
1526 | - return $this->query('EventLogger'); |
|
1527 | - } |
|
1528 | - |
|
1529 | - /** |
|
1530 | - * Get the active query logger |
|
1531 | - * |
|
1532 | - * The returned logger only logs data when debug mode is enabled |
|
1533 | - * |
|
1534 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1535 | - */ |
|
1536 | - public function getQueryLogger() { |
|
1537 | - return $this->query('QueryLogger'); |
|
1538 | - } |
|
1539 | - |
|
1540 | - /** |
|
1541 | - * Get the manager for temporary files and folders |
|
1542 | - * |
|
1543 | - * @return \OCP\ITempManager |
|
1544 | - */ |
|
1545 | - public function getTempManager() { |
|
1546 | - return $this->query('TempManager'); |
|
1547 | - } |
|
1548 | - |
|
1549 | - /** |
|
1550 | - * Get the app manager |
|
1551 | - * |
|
1552 | - * @return \OCP\App\IAppManager |
|
1553 | - */ |
|
1554 | - public function getAppManager() { |
|
1555 | - return $this->query('AppManager'); |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * Creates a new mailer |
|
1560 | - * |
|
1561 | - * @return \OCP\Mail\IMailer |
|
1562 | - */ |
|
1563 | - public function getMailer() { |
|
1564 | - return $this->query('Mailer'); |
|
1565 | - } |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * Get the webroot |
|
1569 | - * |
|
1570 | - * @return string |
|
1571 | - */ |
|
1572 | - public function getWebRoot() { |
|
1573 | - return $this->webRoot; |
|
1574 | - } |
|
1575 | - |
|
1576 | - /** |
|
1577 | - * @return \OC\OCSClient |
|
1578 | - */ |
|
1579 | - public function getOcsClient() { |
|
1580 | - return $this->query('OcsClient'); |
|
1581 | - } |
|
1582 | - |
|
1583 | - /** |
|
1584 | - * @return \OCP\IDateTimeZone |
|
1585 | - */ |
|
1586 | - public function getDateTimeZone() { |
|
1587 | - return $this->query('DateTimeZone'); |
|
1588 | - } |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * @return \OCP\IDateTimeFormatter |
|
1592 | - */ |
|
1593 | - public function getDateTimeFormatter() { |
|
1594 | - return $this->query('DateTimeFormatter'); |
|
1595 | - } |
|
1596 | - |
|
1597 | - /** |
|
1598 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1599 | - */ |
|
1600 | - public function getMountProviderCollection() { |
|
1601 | - return $this->query('MountConfigManager'); |
|
1602 | - } |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * Get the IniWrapper |
|
1606 | - * |
|
1607 | - * @return IniGetWrapper |
|
1608 | - */ |
|
1609 | - public function getIniWrapper() { |
|
1610 | - return $this->query('IniWrapper'); |
|
1611 | - } |
|
1612 | - |
|
1613 | - /** |
|
1614 | - * @return \OCP\Command\IBus |
|
1615 | - */ |
|
1616 | - public function getCommandBus() { |
|
1617 | - return $this->query('AsyncCommandBus'); |
|
1618 | - } |
|
1619 | - |
|
1620 | - /** |
|
1621 | - * Get the trusted domain helper |
|
1622 | - * |
|
1623 | - * @return TrustedDomainHelper |
|
1624 | - */ |
|
1625 | - public function getTrustedDomainHelper() { |
|
1626 | - return $this->query('TrustedDomainHelper'); |
|
1627 | - } |
|
1628 | - |
|
1629 | - /** |
|
1630 | - * Get the locking provider |
|
1631 | - * |
|
1632 | - * @return \OCP\Lock\ILockingProvider |
|
1633 | - * @since 8.1.0 |
|
1634 | - */ |
|
1635 | - public function getLockingProvider() { |
|
1636 | - return $this->query('LockingProvider'); |
|
1637 | - } |
|
1638 | - |
|
1639 | - /** |
|
1640 | - * @return \OCP\Files\Mount\IMountManager |
|
1641 | - **/ |
|
1642 | - function getMountManager() { |
|
1643 | - return $this->query('MountManager'); |
|
1644 | - } |
|
1645 | - |
|
1646 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1647 | - function getUserMountCache() { |
|
1648 | - return $this->query('UserMountCache'); |
|
1649 | - } |
|
1650 | - |
|
1651 | - /** |
|
1652 | - * Get the MimeTypeDetector |
|
1653 | - * |
|
1654 | - * @return \OCP\Files\IMimeTypeDetector |
|
1655 | - */ |
|
1656 | - public function getMimeTypeDetector() { |
|
1657 | - return $this->query('MimeTypeDetector'); |
|
1658 | - } |
|
1659 | - |
|
1660 | - /** |
|
1661 | - * Get the MimeTypeLoader |
|
1662 | - * |
|
1663 | - * @return \OCP\Files\IMimeTypeLoader |
|
1664 | - */ |
|
1665 | - public function getMimeTypeLoader() { |
|
1666 | - return $this->query('MimeTypeLoader'); |
|
1667 | - } |
|
1668 | - |
|
1669 | - /** |
|
1670 | - * Get the manager of all the capabilities |
|
1671 | - * |
|
1672 | - * @return \OC\CapabilitiesManager |
|
1673 | - */ |
|
1674 | - public function getCapabilitiesManager() { |
|
1675 | - return $this->query('CapabilitiesManager'); |
|
1676 | - } |
|
1677 | - |
|
1678 | - /** |
|
1679 | - * Get the EventDispatcher |
|
1680 | - * |
|
1681 | - * @return EventDispatcherInterface |
|
1682 | - * @since 8.2.0 |
|
1683 | - */ |
|
1684 | - public function getEventDispatcher() { |
|
1685 | - return $this->query('EventDispatcher'); |
|
1686 | - } |
|
1687 | - |
|
1688 | - /** |
|
1689 | - * Get the Notification Manager |
|
1690 | - * |
|
1691 | - * @return \OCP\Notification\IManager |
|
1692 | - * @since 8.2.0 |
|
1693 | - */ |
|
1694 | - public function getNotificationManager() { |
|
1695 | - return $this->query('NotificationManager'); |
|
1696 | - } |
|
1697 | - |
|
1698 | - /** |
|
1699 | - * @return \OCP\Comments\ICommentsManager |
|
1700 | - */ |
|
1701 | - public function getCommentsManager() { |
|
1702 | - return $this->query('CommentsManager'); |
|
1703 | - } |
|
1704 | - |
|
1705 | - /** |
|
1706 | - * @return \OCA\Theming\ThemingDefaults |
|
1707 | - */ |
|
1708 | - public function getThemingDefaults() { |
|
1709 | - return $this->query('ThemingDefaults'); |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * @return \OC\IntegrityCheck\Checker |
|
1714 | - */ |
|
1715 | - public function getIntegrityCodeChecker() { |
|
1716 | - return $this->query('IntegrityCodeChecker'); |
|
1717 | - } |
|
1718 | - |
|
1719 | - /** |
|
1720 | - * @return \OC\Session\CryptoWrapper |
|
1721 | - */ |
|
1722 | - public function getSessionCryptoWrapper() { |
|
1723 | - return $this->query('CryptoWrapper'); |
|
1724 | - } |
|
1725 | - |
|
1726 | - /** |
|
1727 | - * @return CsrfTokenManager |
|
1728 | - */ |
|
1729 | - public function getCsrfTokenManager() { |
|
1730 | - return $this->query('CsrfTokenManager'); |
|
1731 | - } |
|
1732 | - |
|
1733 | - /** |
|
1734 | - * @return Throttler |
|
1735 | - */ |
|
1736 | - public function getBruteForceThrottler() { |
|
1737 | - return $this->query('Throttler'); |
|
1738 | - } |
|
1739 | - |
|
1740 | - /** |
|
1741 | - * @return IContentSecurityPolicyManager |
|
1742 | - */ |
|
1743 | - public function getContentSecurityPolicyManager() { |
|
1744 | - return $this->query('ContentSecurityPolicyManager'); |
|
1745 | - } |
|
1746 | - |
|
1747 | - /** |
|
1748 | - * @return ContentSecurityPolicyNonceManager |
|
1749 | - */ |
|
1750 | - public function getContentSecurityPolicyNonceManager() { |
|
1751 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1752 | - } |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * Not a public API as of 8.2, wait for 9.0 |
|
1756 | - * |
|
1757 | - * @return \OCA\Files_External\Service\BackendService |
|
1758 | - */ |
|
1759 | - public function getStoragesBackendService() { |
|
1760 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1761 | - } |
|
1762 | - |
|
1763 | - /** |
|
1764 | - * Not a public API as of 8.2, wait for 9.0 |
|
1765 | - * |
|
1766 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1767 | - */ |
|
1768 | - public function getGlobalStoragesService() { |
|
1769 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1770 | - } |
|
1771 | - |
|
1772 | - /** |
|
1773 | - * Not a public API as of 8.2, wait for 9.0 |
|
1774 | - * |
|
1775 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1776 | - */ |
|
1777 | - public function getUserGlobalStoragesService() { |
|
1778 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1779 | - } |
|
1780 | - |
|
1781 | - /** |
|
1782 | - * Not a public API as of 8.2, wait for 9.0 |
|
1783 | - * |
|
1784 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1785 | - */ |
|
1786 | - public function getUserStoragesService() { |
|
1787 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1788 | - } |
|
1789 | - |
|
1790 | - /** |
|
1791 | - * @return \OCP\Share\IManager |
|
1792 | - */ |
|
1793 | - public function getShareManager() { |
|
1794 | - return $this->query('ShareManager'); |
|
1795 | - } |
|
1796 | - |
|
1797 | - /** |
|
1798 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
1799 | - */ |
|
1800 | - public function getCollaboratorSearch() { |
|
1801 | - return $this->query('CollaboratorSearch'); |
|
1802 | - } |
|
1803 | - |
|
1804 | - /** |
|
1805 | - * Returns the LDAP Provider |
|
1806 | - * |
|
1807 | - * @return \OCP\LDAP\ILDAPProvider |
|
1808 | - */ |
|
1809 | - public function getLDAPProvider() { |
|
1810 | - return $this->query('LDAPProvider'); |
|
1811 | - } |
|
1812 | - |
|
1813 | - /** |
|
1814 | - * @return \OCP\Settings\IManager |
|
1815 | - */ |
|
1816 | - public function getSettingsManager() { |
|
1817 | - return $this->query('SettingsManager'); |
|
1818 | - } |
|
1819 | - |
|
1820 | - /** |
|
1821 | - * @return \OCP\Files\IAppData |
|
1822 | - */ |
|
1823 | - public function getAppDataDir($app) { |
|
1824 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1825 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1826 | - return $factory->get($app); |
|
1827 | - } |
|
1828 | - |
|
1829 | - /** |
|
1830 | - * @return \OCP\Lockdown\ILockdownManager |
|
1831 | - */ |
|
1832 | - public function getLockdownManager() { |
|
1833 | - return $this->query('LockdownManager'); |
|
1834 | - } |
|
1835 | - |
|
1836 | - /** |
|
1837 | - * @return \OCP\Federation\ICloudIdManager |
|
1838 | - */ |
|
1839 | - public function getCloudIdManager() { |
|
1840 | - return $this->query(ICloudIdManager::class); |
|
1841 | - } |
|
886 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
887 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
888 | + $classExists = true; |
|
889 | + } else { |
|
890 | + $classExists = false; |
|
891 | + } |
|
892 | + |
|
893 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
894 | + return new ThemingDefaults( |
|
895 | + $c->getConfig(), |
|
896 | + $c->getL10N('theming'), |
|
897 | + $c->getURLGenerator(), |
|
898 | + $c->getAppDataDir('theming'), |
|
899 | + $c->getMemCacheFactory(), |
|
900 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
|
901 | + $this->getAppManager() |
|
902 | + ); |
|
903 | + } |
|
904 | + return new \OC_Defaults(); |
|
905 | + }); |
|
906 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
907 | + /** @var Factory $cacheFactory */ |
|
908 | + $cacheFactory = $c->query(Factory::class); |
|
909 | + return new SCSSCacher( |
|
910 | + $c->getLogger(), |
|
911 | + $c->query(\OC\Files\AppData\Factory::class), |
|
912 | + $c->getURLGenerator(), |
|
913 | + $c->getConfig(), |
|
914 | + $c->getThemingDefaults(), |
|
915 | + \OC::$SERVERROOT, |
|
916 | + $cacheFactory->create('SCSS') |
|
917 | + ); |
|
918 | + }); |
|
919 | + $this->registerService(EventDispatcher::class, function () { |
|
920 | + return new EventDispatcher(); |
|
921 | + }); |
|
922 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
923 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
924 | + |
|
925 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
926 | + // FIXME: Instantiiated here due to cyclic dependency |
|
927 | + $request = new Request( |
|
928 | + [ |
|
929 | + 'get' => $_GET, |
|
930 | + 'post' => $_POST, |
|
931 | + 'files' => $_FILES, |
|
932 | + 'server' => $_SERVER, |
|
933 | + 'env' => $_ENV, |
|
934 | + 'cookies' => $_COOKIE, |
|
935 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
936 | + ? $_SERVER['REQUEST_METHOD'] |
|
937 | + : null, |
|
938 | + ], |
|
939 | + $c->getSecureRandom(), |
|
940 | + $c->getConfig() |
|
941 | + ); |
|
942 | + |
|
943 | + return new CryptoWrapper( |
|
944 | + $c->getConfig(), |
|
945 | + $c->getCrypto(), |
|
946 | + $c->getSecureRandom(), |
|
947 | + $request |
|
948 | + ); |
|
949 | + }); |
|
950 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
951 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
952 | + |
|
953 | + return new CsrfTokenManager( |
|
954 | + $tokenGenerator, |
|
955 | + $c->query(SessionStorage::class) |
|
956 | + ); |
|
957 | + }); |
|
958 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
959 | + return new SessionStorage($c->getSession()); |
|
960 | + }); |
|
961 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
962 | + return new ContentSecurityPolicyManager(); |
|
963 | + }); |
|
964 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
965 | + |
|
966 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
967 | + return new ContentSecurityPolicyNonceManager( |
|
968 | + $c->getCsrfTokenManager(), |
|
969 | + $c->getRequest() |
|
970 | + ); |
|
971 | + }); |
|
972 | + |
|
973 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
974 | + $config = $c->getConfig(); |
|
975 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
976 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
977 | + $factory = new $factoryClass($this); |
|
978 | + |
|
979 | + $manager = new \OC\Share20\Manager( |
|
980 | + $c->getLogger(), |
|
981 | + $c->getConfig(), |
|
982 | + $c->getSecureRandom(), |
|
983 | + $c->getHasher(), |
|
984 | + $c->getMountManager(), |
|
985 | + $c->getGroupManager(), |
|
986 | + $c->getL10N('lib'), |
|
987 | + $c->getL10NFactory(), |
|
988 | + $factory, |
|
989 | + $c->getUserManager(), |
|
990 | + $c->getLazyRootFolder(), |
|
991 | + $c->getEventDispatcher(), |
|
992 | + $c->getMailer(), |
|
993 | + $c->getURLGenerator(), |
|
994 | + $c->getThemingDefaults() |
|
995 | + ); |
|
996 | + |
|
997 | + return $manager; |
|
998 | + }); |
|
999 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
1000 | + |
|
1001 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1002 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1003 | + |
|
1004 | + // register default plugins |
|
1005 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1006 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1007 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1008 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1009 | + |
|
1010 | + return $instance; |
|
1011 | + }); |
|
1012 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1013 | + |
|
1014 | + $this->registerService('SettingsManager', function (Server $c) { |
|
1015 | + $manager = new \OC\Settings\Manager( |
|
1016 | + $c->getLogger(), |
|
1017 | + $c->getDatabaseConnection(), |
|
1018 | + $c->getL10N('lib'), |
|
1019 | + $c->getConfig(), |
|
1020 | + $c->getEncryptionManager(), |
|
1021 | + $c->getUserManager(), |
|
1022 | + $c->getLockingProvider(), |
|
1023 | + $c->getRequest(), |
|
1024 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
1025 | + $c->getURLGenerator(), |
|
1026 | + $c->query(AccountManager::class), |
|
1027 | + $c->getGroupManager(), |
|
1028 | + $c->getL10NFactory(), |
|
1029 | + $c->getThemingDefaults(), |
|
1030 | + $c->getAppManager() |
|
1031 | + ); |
|
1032 | + return $manager; |
|
1033 | + }); |
|
1034 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
1035 | + return new \OC\Files\AppData\Factory( |
|
1036 | + $c->getRootFolder(), |
|
1037 | + $c->getSystemConfig() |
|
1038 | + ); |
|
1039 | + }); |
|
1040 | + |
|
1041 | + $this->registerService('LockdownManager', function (Server $c) { |
|
1042 | + return new LockdownManager(function () use ($c) { |
|
1043 | + return $c->getSession(); |
|
1044 | + }); |
|
1045 | + }); |
|
1046 | + |
|
1047 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
1048 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
1049 | + }); |
|
1050 | + |
|
1051 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
1052 | + return new CloudIdManager(); |
|
1053 | + }); |
|
1054 | + |
|
1055 | + /* To trick DI since we don't extend the DIContainer here */ |
|
1056 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1057 | + return new CleanPreviewsBackgroundJob( |
|
1058 | + $c->getRootFolder(), |
|
1059 | + $c->getLogger(), |
|
1060 | + $c->getJobList(), |
|
1061 | + new TimeFactory() |
|
1062 | + ); |
|
1063 | + }); |
|
1064 | + |
|
1065 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1066 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1067 | + |
|
1068 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1069 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1070 | + |
|
1071 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1072 | + return new Defaults( |
|
1073 | + $c->getThemingDefaults() |
|
1074 | + ); |
|
1075 | + }); |
|
1076 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1077 | + |
|
1078 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
1079 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1080 | + }); |
|
1081 | + |
|
1082 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
1083 | + return new ShareHelper( |
|
1084 | + $c->query(\OCP\Share\IManager::class) |
|
1085 | + ); |
|
1086 | + }); |
|
1087 | + } |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * @return \OCP\Contacts\IManager |
|
1091 | + */ |
|
1092 | + public function getContactsManager() { |
|
1093 | + return $this->query('ContactsManager'); |
|
1094 | + } |
|
1095 | + |
|
1096 | + /** |
|
1097 | + * @return \OC\Encryption\Manager |
|
1098 | + */ |
|
1099 | + public function getEncryptionManager() { |
|
1100 | + return $this->query('EncryptionManager'); |
|
1101 | + } |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * @return \OC\Encryption\File |
|
1105 | + */ |
|
1106 | + public function getEncryptionFilesHelper() { |
|
1107 | + return $this->query('EncryptionFileHelper'); |
|
1108 | + } |
|
1109 | + |
|
1110 | + /** |
|
1111 | + * @return \OCP\Encryption\Keys\IStorage |
|
1112 | + */ |
|
1113 | + public function getEncryptionKeyStorage() { |
|
1114 | + return $this->query('EncryptionKeyStorage'); |
|
1115 | + } |
|
1116 | + |
|
1117 | + /** |
|
1118 | + * The current request object holding all information about the request |
|
1119 | + * currently being processed is returned from this method. |
|
1120 | + * In case the current execution was not initiated by a web request null is returned |
|
1121 | + * |
|
1122 | + * @return \OCP\IRequest |
|
1123 | + */ |
|
1124 | + public function getRequest() { |
|
1125 | + return $this->query('Request'); |
|
1126 | + } |
|
1127 | + |
|
1128 | + /** |
|
1129 | + * Returns the preview manager which can create preview images for a given file |
|
1130 | + * |
|
1131 | + * @return \OCP\IPreview |
|
1132 | + */ |
|
1133 | + public function getPreviewManager() { |
|
1134 | + return $this->query('PreviewManager'); |
|
1135 | + } |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * Returns the tag manager which can get and set tags for different object types |
|
1139 | + * |
|
1140 | + * @see \OCP\ITagManager::load() |
|
1141 | + * @return \OCP\ITagManager |
|
1142 | + */ |
|
1143 | + public function getTagManager() { |
|
1144 | + return $this->query('TagManager'); |
|
1145 | + } |
|
1146 | + |
|
1147 | + /** |
|
1148 | + * Returns the system-tag manager |
|
1149 | + * |
|
1150 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1151 | + * |
|
1152 | + * @since 9.0.0 |
|
1153 | + */ |
|
1154 | + public function getSystemTagManager() { |
|
1155 | + return $this->query('SystemTagManager'); |
|
1156 | + } |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * Returns the system-tag object mapper |
|
1160 | + * |
|
1161 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1162 | + * |
|
1163 | + * @since 9.0.0 |
|
1164 | + */ |
|
1165 | + public function getSystemTagObjectMapper() { |
|
1166 | + return $this->query('SystemTagObjectMapper'); |
|
1167 | + } |
|
1168 | + |
|
1169 | + /** |
|
1170 | + * Returns the avatar manager, used for avatar functionality |
|
1171 | + * |
|
1172 | + * @return \OCP\IAvatarManager |
|
1173 | + */ |
|
1174 | + public function getAvatarManager() { |
|
1175 | + return $this->query('AvatarManager'); |
|
1176 | + } |
|
1177 | + |
|
1178 | + /** |
|
1179 | + * Returns the root folder of ownCloud's data directory |
|
1180 | + * |
|
1181 | + * @return \OCP\Files\IRootFolder |
|
1182 | + */ |
|
1183 | + public function getRootFolder() { |
|
1184 | + return $this->query('LazyRootFolder'); |
|
1185 | + } |
|
1186 | + |
|
1187 | + /** |
|
1188 | + * Returns the root folder of ownCloud's data directory |
|
1189 | + * This is the lazy variant so this gets only initialized once it |
|
1190 | + * is actually used. |
|
1191 | + * |
|
1192 | + * @return \OCP\Files\IRootFolder |
|
1193 | + */ |
|
1194 | + public function getLazyRootFolder() { |
|
1195 | + return $this->query('LazyRootFolder'); |
|
1196 | + } |
|
1197 | + |
|
1198 | + /** |
|
1199 | + * Returns a view to ownCloud's files folder |
|
1200 | + * |
|
1201 | + * @param string $userId user ID |
|
1202 | + * @return \OCP\Files\Folder|null |
|
1203 | + */ |
|
1204 | + public function getUserFolder($userId = null) { |
|
1205 | + if ($userId === null) { |
|
1206 | + $user = $this->getUserSession()->getUser(); |
|
1207 | + if (!$user) { |
|
1208 | + return null; |
|
1209 | + } |
|
1210 | + $userId = $user->getUID(); |
|
1211 | + } |
|
1212 | + $root = $this->getRootFolder(); |
|
1213 | + return $root->getUserFolder($userId); |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Returns an app-specific view in ownClouds data directory |
|
1218 | + * |
|
1219 | + * @return \OCP\Files\Folder |
|
1220 | + * @deprecated since 9.2.0 use IAppData |
|
1221 | + */ |
|
1222 | + public function getAppFolder() { |
|
1223 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1224 | + $root = $this->getRootFolder(); |
|
1225 | + if (!$root->nodeExists($dir)) { |
|
1226 | + $folder = $root->newFolder($dir); |
|
1227 | + } else { |
|
1228 | + $folder = $root->get($dir); |
|
1229 | + } |
|
1230 | + return $folder; |
|
1231 | + } |
|
1232 | + |
|
1233 | + /** |
|
1234 | + * @return \OC\User\Manager |
|
1235 | + */ |
|
1236 | + public function getUserManager() { |
|
1237 | + return $this->query('UserManager'); |
|
1238 | + } |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * @return \OC\Group\Manager |
|
1242 | + */ |
|
1243 | + public function getGroupManager() { |
|
1244 | + return $this->query('GroupManager'); |
|
1245 | + } |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * @return \OC\User\Session |
|
1249 | + */ |
|
1250 | + public function getUserSession() { |
|
1251 | + return $this->query('UserSession'); |
|
1252 | + } |
|
1253 | + |
|
1254 | + /** |
|
1255 | + * @return \OCP\ISession |
|
1256 | + */ |
|
1257 | + public function getSession() { |
|
1258 | + return $this->query('UserSession')->getSession(); |
|
1259 | + } |
|
1260 | + |
|
1261 | + /** |
|
1262 | + * @param \OCP\ISession $session |
|
1263 | + */ |
|
1264 | + public function setSession(\OCP\ISession $session) { |
|
1265 | + $this->query(SessionStorage::class)->setSession($session); |
|
1266 | + $this->query('UserSession')->setSession($session); |
|
1267 | + $this->query(Store::class)->setSession($session); |
|
1268 | + } |
|
1269 | + |
|
1270 | + /** |
|
1271 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1272 | + */ |
|
1273 | + public function getTwoFactorAuthManager() { |
|
1274 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1275 | + } |
|
1276 | + |
|
1277 | + /** |
|
1278 | + * @return \OC\NavigationManager |
|
1279 | + */ |
|
1280 | + public function getNavigationManager() { |
|
1281 | + return $this->query('NavigationManager'); |
|
1282 | + } |
|
1283 | + |
|
1284 | + /** |
|
1285 | + * @return \OCP\IConfig |
|
1286 | + */ |
|
1287 | + public function getConfig() { |
|
1288 | + return $this->query('AllConfig'); |
|
1289 | + } |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * @return \OC\SystemConfig |
|
1293 | + */ |
|
1294 | + public function getSystemConfig() { |
|
1295 | + return $this->query('SystemConfig'); |
|
1296 | + } |
|
1297 | + |
|
1298 | + /** |
|
1299 | + * Returns the app config manager |
|
1300 | + * |
|
1301 | + * @return \OCP\IAppConfig |
|
1302 | + */ |
|
1303 | + public function getAppConfig() { |
|
1304 | + return $this->query('AppConfig'); |
|
1305 | + } |
|
1306 | + |
|
1307 | + /** |
|
1308 | + * @return \OCP\L10N\IFactory |
|
1309 | + */ |
|
1310 | + public function getL10NFactory() { |
|
1311 | + return $this->query('L10NFactory'); |
|
1312 | + } |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * get an L10N instance |
|
1316 | + * |
|
1317 | + * @param string $app appid |
|
1318 | + * @param string $lang |
|
1319 | + * @return IL10N |
|
1320 | + */ |
|
1321 | + public function getL10N($app, $lang = null) { |
|
1322 | + return $this->getL10NFactory()->get($app, $lang); |
|
1323 | + } |
|
1324 | + |
|
1325 | + /** |
|
1326 | + * @return \OCP\IURLGenerator |
|
1327 | + */ |
|
1328 | + public function getURLGenerator() { |
|
1329 | + return $this->query('URLGenerator'); |
|
1330 | + } |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * @return \OCP\IHelper |
|
1334 | + */ |
|
1335 | + public function getHelper() { |
|
1336 | + return $this->query('AppHelper'); |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * @return AppFetcher |
|
1341 | + */ |
|
1342 | + public function getAppFetcher() { |
|
1343 | + return $this->query(AppFetcher::class); |
|
1344 | + } |
|
1345 | + |
|
1346 | + /** |
|
1347 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1348 | + * getMemCacheFactory() instead. |
|
1349 | + * |
|
1350 | + * @return \OCP\ICache |
|
1351 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1352 | + */ |
|
1353 | + public function getCache() { |
|
1354 | + return $this->query('UserCache'); |
|
1355 | + } |
|
1356 | + |
|
1357 | + /** |
|
1358 | + * Returns an \OCP\CacheFactory instance |
|
1359 | + * |
|
1360 | + * @return \OCP\ICacheFactory |
|
1361 | + */ |
|
1362 | + public function getMemCacheFactory() { |
|
1363 | + return $this->query('MemCacheFactory'); |
|
1364 | + } |
|
1365 | + |
|
1366 | + /** |
|
1367 | + * Returns an \OC\RedisFactory instance |
|
1368 | + * |
|
1369 | + * @return \OC\RedisFactory |
|
1370 | + */ |
|
1371 | + public function getGetRedisFactory() { |
|
1372 | + return $this->query('RedisFactory'); |
|
1373 | + } |
|
1374 | + |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * Returns the current session |
|
1378 | + * |
|
1379 | + * @return \OCP\IDBConnection |
|
1380 | + */ |
|
1381 | + public function getDatabaseConnection() { |
|
1382 | + return $this->query('DatabaseConnection'); |
|
1383 | + } |
|
1384 | + |
|
1385 | + /** |
|
1386 | + * Returns the activity manager |
|
1387 | + * |
|
1388 | + * @return \OCP\Activity\IManager |
|
1389 | + */ |
|
1390 | + public function getActivityManager() { |
|
1391 | + return $this->query('ActivityManager'); |
|
1392 | + } |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * Returns an job list for controlling background jobs |
|
1396 | + * |
|
1397 | + * @return \OCP\BackgroundJob\IJobList |
|
1398 | + */ |
|
1399 | + public function getJobList() { |
|
1400 | + return $this->query('JobList'); |
|
1401 | + } |
|
1402 | + |
|
1403 | + /** |
|
1404 | + * Returns a logger instance |
|
1405 | + * |
|
1406 | + * @return \OCP\ILogger |
|
1407 | + */ |
|
1408 | + public function getLogger() { |
|
1409 | + return $this->query('Logger'); |
|
1410 | + } |
|
1411 | + |
|
1412 | + /** |
|
1413 | + * Returns a router for generating and matching urls |
|
1414 | + * |
|
1415 | + * @return \OCP\Route\IRouter |
|
1416 | + */ |
|
1417 | + public function getRouter() { |
|
1418 | + return $this->query('Router'); |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Returns a search instance |
|
1423 | + * |
|
1424 | + * @return \OCP\ISearch |
|
1425 | + */ |
|
1426 | + public function getSearch() { |
|
1427 | + return $this->query('Search'); |
|
1428 | + } |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * Returns a SecureRandom instance |
|
1432 | + * |
|
1433 | + * @return \OCP\Security\ISecureRandom |
|
1434 | + */ |
|
1435 | + public function getSecureRandom() { |
|
1436 | + return $this->query('SecureRandom'); |
|
1437 | + } |
|
1438 | + |
|
1439 | + /** |
|
1440 | + * Returns a Crypto instance |
|
1441 | + * |
|
1442 | + * @return \OCP\Security\ICrypto |
|
1443 | + */ |
|
1444 | + public function getCrypto() { |
|
1445 | + return $this->query('Crypto'); |
|
1446 | + } |
|
1447 | + |
|
1448 | + /** |
|
1449 | + * Returns a Hasher instance |
|
1450 | + * |
|
1451 | + * @return \OCP\Security\IHasher |
|
1452 | + */ |
|
1453 | + public function getHasher() { |
|
1454 | + return $this->query('Hasher'); |
|
1455 | + } |
|
1456 | + |
|
1457 | + /** |
|
1458 | + * Returns a CredentialsManager instance |
|
1459 | + * |
|
1460 | + * @return \OCP\Security\ICredentialsManager |
|
1461 | + */ |
|
1462 | + public function getCredentialsManager() { |
|
1463 | + return $this->query('CredentialsManager'); |
|
1464 | + } |
|
1465 | + |
|
1466 | + /** |
|
1467 | + * Returns an instance of the HTTP helper class |
|
1468 | + * |
|
1469 | + * @deprecated Use getHTTPClientService() |
|
1470 | + * @return \OC\HTTPHelper |
|
1471 | + */ |
|
1472 | + public function getHTTPHelper() { |
|
1473 | + return $this->query('HTTPHelper'); |
|
1474 | + } |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * Get the certificate manager for the user |
|
1478 | + * |
|
1479 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1480 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1481 | + */ |
|
1482 | + public function getCertificateManager($userId = '') { |
|
1483 | + if ($userId === '') { |
|
1484 | + $userSession = $this->getUserSession(); |
|
1485 | + $user = $userSession->getUser(); |
|
1486 | + if (is_null($user)) { |
|
1487 | + return null; |
|
1488 | + } |
|
1489 | + $userId = $user->getUID(); |
|
1490 | + } |
|
1491 | + return new CertificateManager( |
|
1492 | + $userId, |
|
1493 | + new View(), |
|
1494 | + $this->getConfig(), |
|
1495 | + $this->getLogger(), |
|
1496 | + $this->getSecureRandom() |
|
1497 | + ); |
|
1498 | + } |
|
1499 | + |
|
1500 | + /** |
|
1501 | + * Returns an instance of the HTTP client service |
|
1502 | + * |
|
1503 | + * @return \OCP\Http\Client\IClientService |
|
1504 | + */ |
|
1505 | + public function getHTTPClientService() { |
|
1506 | + return $this->query('HttpClientService'); |
|
1507 | + } |
|
1508 | + |
|
1509 | + /** |
|
1510 | + * Create a new event source |
|
1511 | + * |
|
1512 | + * @return \OCP\IEventSource |
|
1513 | + */ |
|
1514 | + public function createEventSource() { |
|
1515 | + return new \OC_EventSource(); |
|
1516 | + } |
|
1517 | + |
|
1518 | + /** |
|
1519 | + * Get the active event logger |
|
1520 | + * |
|
1521 | + * The returned logger only logs data when debug mode is enabled |
|
1522 | + * |
|
1523 | + * @return \OCP\Diagnostics\IEventLogger |
|
1524 | + */ |
|
1525 | + public function getEventLogger() { |
|
1526 | + return $this->query('EventLogger'); |
|
1527 | + } |
|
1528 | + |
|
1529 | + /** |
|
1530 | + * Get the active query logger |
|
1531 | + * |
|
1532 | + * The returned logger only logs data when debug mode is enabled |
|
1533 | + * |
|
1534 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1535 | + */ |
|
1536 | + public function getQueryLogger() { |
|
1537 | + return $this->query('QueryLogger'); |
|
1538 | + } |
|
1539 | + |
|
1540 | + /** |
|
1541 | + * Get the manager for temporary files and folders |
|
1542 | + * |
|
1543 | + * @return \OCP\ITempManager |
|
1544 | + */ |
|
1545 | + public function getTempManager() { |
|
1546 | + return $this->query('TempManager'); |
|
1547 | + } |
|
1548 | + |
|
1549 | + /** |
|
1550 | + * Get the app manager |
|
1551 | + * |
|
1552 | + * @return \OCP\App\IAppManager |
|
1553 | + */ |
|
1554 | + public function getAppManager() { |
|
1555 | + return $this->query('AppManager'); |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * Creates a new mailer |
|
1560 | + * |
|
1561 | + * @return \OCP\Mail\IMailer |
|
1562 | + */ |
|
1563 | + public function getMailer() { |
|
1564 | + return $this->query('Mailer'); |
|
1565 | + } |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * Get the webroot |
|
1569 | + * |
|
1570 | + * @return string |
|
1571 | + */ |
|
1572 | + public function getWebRoot() { |
|
1573 | + return $this->webRoot; |
|
1574 | + } |
|
1575 | + |
|
1576 | + /** |
|
1577 | + * @return \OC\OCSClient |
|
1578 | + */ |
|
1579 | + public function getOcsClient() { |
|
1580 | + return $this->query('OcsClient'); |
|
1581 | + } |
|
1582 | + |
|
1583 | + /** |
|
1584 | + * @return \OCP\IDateTimeZone |
|
1585 | + */ |
|
1586 | + public function getDateTimeZone() { |
|
1587 | + return $this->query('DateTimeZone'); |
|
1588 | + } |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * @return \OCP\IDateTimeFormatter |
|
1592 | + */ |
|
1593 | + public function getDateTimeFormatter() { |
|
1594 | + return $this->query('DateTimeFormatter'); |
|
1595 | + } |
|
1596 | + |
|
1597 | + /** |
|
1598 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1599 | + */ |
|
1600 | + public function getMountProviderCollection() { |
|
1601 | + return $this->query('MountConfigManager'); |
|
1602 | + } |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * Get the IniWrapper |
|
1606 | + * |
|
1607 | + * @return IniGetWrapper |
|
1608 | + */ |
|
1609 | + public function getIniWrapper() { |
|
1610 | + return $this->query('IniWrapper'); |
|
1611 | + } |
|
1612 | + |
|
1613 | + /** |
|
1614 | + * @return \OCP\Command\IBus |
|
1615 | + */ |
|
1616 | + public function getCommandBus() { |
|
1617 | + return $this->query('AsyncCommandBus'); |
|
1618 | + } |
|
1619 | + |
|
1620 | + /** |
|
1621 | + * Get the trusted domain helper |
|
1622 | + * |
|
1623 | + * @return TrustedDomainHelper |
|
1624 | + */ |
|
1625 | + public function getTrustedDomainHelper() { |
|
1626 | + return $this->query('TrustedDomainHelper'); |
|
1627 | + } |
|
1628 | + |
|
1629 | + /** |
|
1630 | + * Get the locking provider |
|
1631 | + * |
|
1632 | + * @return \OCP\Lock\ILockingProvider |
|
1633 | + * @since 8.1.0 |
|
1634 | + */ |
|
1635 | + public function getLockingProvider() { |
|
1636 | + return $this->query('LockingProvider'); |
|
1637 | + } |
|
1638 | + |
|
1639 | + /** |
|
1640 | + * @return \OCP\Files\Mount\IMountManager |
|
1641 | + **/ |
|
1642 | + function getMountManager() { |
|
1643 | + return $this->query('MountManager'); |
|
1644 | + } |
|
1645 | + |
|
1646 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1647 | + function getUserMountCache() { |
|
1648 | + return $this->query('UserMountCache'); |
|
1649 | + } |
|
1650 | + |
|
1651 | + /** |
|
1652 | + * Get the MimeTypeDetector |
|
1653 | + * |
|
1654 | + * @return \OCP\Files\IMimeTypeDetector |
|
1655 | + */ |
|
1656 | + public function getMimeTypeDetector() { |
|
1657 | + return $this->query('MimeTypeDetector'); |
|
1658 | + } |
|
1659 | + |
|
1660 | + /** |
|
1661 | + * Get the MimeTypeLoader |
|
1662 | + * |
|
1663 | + * @return \OCP\Files\IMimeTypeLoader |
|
1664 | + */ |
|
1665 | + public function getMimeTypeLoader() { |
|
1666 | + return $this->query('MimeTypeLoader'); |
|
1667 | + } |
|
1668 | + |
|
1669 | + /** |
|
1670 | + * Get the manager of all the capabilities |
|
1671 | + * |
|
1672 | + * @return \OC\CapabilitiesManager |
|
1673 | + */ |
|
1674 | + public function getCapabilitiesManager() { |
|
1675 | + return $this->query('CapabilitiesManager'); |
|
1676 | + } |
|
1677 | + |
|
1678 | + /** |
|
1679 | + * Get the EventDispatcher |
|
1680 | + * |
|
1681 | + * @return EventDispatcherInterface |
|
1682 | + * @since 8.2.0 |
|
1683 | + */ |
|
1684 | + public function getEventDispatcher() { |
|
1685 | + return $this->query('EventDispatcher'); |
|
1686 | + } |
|
1687 | + |
|
1688 | + /** |
|
1689 | + * Get the Notification Manager |
|
1690 | + * |
|
1691 | + * @return \OCP\Notification\IManager |
|
1692 | + * @since 8.2.0 |
|
1693 | + */ |
|
1694 | + public function getNotificationManager() { |
|
1695 | + return $this->query('NotificationManager'); |
|
1696 | + } |
|
1697 | + |
|
1698 | + /** |
|
1699 | + * @return \OCP\Comments\ICommentsManager |
|
1700 | + */ |
|
1701 | + public function getCommentsManager() { |
|
1702 | + return $this->query('CommentsManager'); |
|
1703 | + } |
|
1704 | + |
|
1705 | + /** |
|
1706 | + * @return \OCA\Theming\ThemingDefaults |
|
1707 | + */ |
|
1708 | + public function getThemingDefaults() { |
|
1709 | + return $this->query('ThemingDefaults'); |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * @return \OC\IntegrityCheck\Checker |
|
1714 | + */ |
|
1715 | + public function getIntegrityCodeChecker() { |
|
1716 | + return $this->query('IntegrityCodeChecker'); |
|
1717 | + } |
|
1718 | + |
|
1719 | + /** |
|
1720 | + * @return \OC\Session\CryptoWrapper |
|
1721 | + */ |
|
1722 | + public function getSessionCryptoWrapper() { |
|
1723 | + return $this->query('CryptoWrapper'); |
|
1724 | + } |
|
1725 | + |
|
1726 | + /** |
|
1727 | + * @return CsrfTokenManager |
|
1728 | + */ |
|
1729 | + public function getCsrfTokenManager() { |
|
1730 | + return $this->query('CsrfTokenManager'); |
|
1731 | + } |
|
1732 | + |
|
1733 | + /** |
|
1734 | + * @return Throttler |
|
1735 | + */ |
|
1736 | + public function getBruteForceThrottler() { |
|
1737 | + return $this->query('Throttler'); |
|
1738 | + } |
|
1739 | + |
|
1740 | + /** |
|
1741 | + * @return IContentSecurityPolicyManager |
|
1742 | + */ |
|
1743 | + public function getContentSecurityPolicyManager() { |
|
1744 | + return $this->query('ContentSecurityPolicyManager'); |
|
1745 | + } |
|
1746 | + |
|
1747 | + /** |
|
1748 | + * @return ContentSecurityPolicyNonceManager |
|
1749 | + */ |
|
1750 | + public function getContentSecurityPolicyNonceManager() { |
|
1751 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1752 | + } |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * Not a public API as of 8.2, wait for 9.0 |
|
1756 | + * |
|
1757 | + * @return \OCA\Files_External\Service\BackendService |
|
1758 | + */ |
|
1759 | + public function getStoragesBackendService() { |
|
1760 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1761 | + } |
|
1762 | + |
|
1763 | + /** |
|
1764 | + * Not a public API as of 8.2, wait for 9.0 |
|
1765 | + * |
|
1766 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1767 | + */ |
|
1768 | + public function getGlobalStoragesService() { |
|
1769 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1770 | + } |
|
1771 | + |
|
1772 | + /** |
|
1773 | + * Not a public API as of 8.2, wait for 9.0 |
|
1774 | + * |
|
1775 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1776 | + */ |
|
1777 | + public function getUserGlobalStoragesService() { |
|
1778 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1779 | + } |
|
1780 | + |
|
1781 | + /** |
|
1782 | + * Not a public API as of 8.2, wait for 9.0 |
|
1783 | + * |
|
1784 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1785 | + */ |
|
1786 | + public function getUserStoragesService() { |
|
1787 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1788 | + } |
|
1789 | + |
|
1790 | + /** |
|
1791 | + * @return \OCP\Share\IManager |
|
1792 | + */ |
|
1793 | + public function getShareManager() { |
|
1794 | + return $this->query('ShareManager'); |
|
1795 | + } |
|
1796 | + |
|
1797 | + /** |
|
1798 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
1799 | + */ |
|
1800 | + public function getCollaboratorSearch() { |
|
1801 | + return $this->query('CollaboratorSearch'); |
|
1802 | + } |
|
1803 | + |
|
1804 | + /** |
|
1805 | + * Returns the LDAP Provider |
|
1806 | + * |
|
1807 | + * @return \OCP\LDAP\ILDAPProvider |
|
1808 | + */ |
|
1809 | + public function getLDAPProvider() { |
|
1810 | + return $this->query('LDAPProvider'); |
|
1811 | + } |
|
1812 | + |
|
1813 | + /** |
|
1814 | + * @return \OCP\Settings\IManager |
|
1815 | + */ |
|
1816 | + public function getSettingsManager() { |
|
1817 | + return $this->query('SettingsManager'); |
|
1818 | + } |
|
1819 | + |
|
1820 | + /** |
|
1821 | + * @return \OCP\Files\IAppData |
|
1822 | + */ |
|
1823 | + public function getAppDataDir($app) { |
|
1824 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1825 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1826 | + return $factory->get($app); |
|
1827 | + } |
|
1828 | + |
|
1829 | + /** |
|
1830 | + * @return \OCP\Lockdown\ILockdownManager |
|
1831 | + */ |
|
1832 | + public function getLockdownManager() { |
|
1833 | + return $this->query('LockdownManager'); |
|
1834 | + } |
|
1835 | + |
|
1836 | + /** |
|
1837 | + * @return \OCP\Federation\ICloudIdManager |
|
1838 | + */ |
|
1839 | + public function getCloudIdManager() { |
|
1840 | + return $this->query(ICloudIdManager::class); |
|
1841 | + } |
|
1842 | 1842 | } |
@@ -30,13 +30,13 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearchPlugin { |
33 | - /** |
|
34 | - * @param string $search |
|
35 | - * @param int $limit |
|
36 | - * @param int $offset |
|
37 | - * @param ISearchResult $searchResult |
|
38 | - * @return bool whether the plugin has more results |
|
39 | - * @since 13.0.0 |
|
40 | - */ |
|
41 | - public function search($search, $limit, $offset, ISearchResult $searchResult); |
|
33 | + /** |
|
34 | + * @param string $search |
|
35 | + * @param int $limit |
|
36 | + * @param int $offset |
|
37 | + * @param ISearchResult $searchResult |
|
38 | + * @return bool whether the plugin has more results |
|
39 | + * @since 13.0.0 |
|
40 | + */ |
|
41 | + public function search($search, $limit, $offset, ISearchResult $searchResult); |
|
42 | 42 | } |
@@ -30,21 +30,21 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearch { |
33 | - /** |
|
34 | - * @param string $search |
|
35 | - * @param array $shareTypes |
|
36 | - * @param bool $lookup |
|
37 | - * @param int $limit |
|
38 | - * @param int $offset |
|
39 | - * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available |
|
40 | - * @since 13.0.0 |
|
41 | - */ |
|
42 | - public function search($search, array $shareTypes, $lookup, $limit, $offset); |
|
33 | + /** |
|
34 | + * @param string $search |
|
35 | + * @param array $shareTypes |
|
36 | + * @param bool $lookup |
|
37 | + * @param int $limit |
|
38 | + * @param int $offset |
|
39 | + * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available |
|
40 | + * @since 13.0.0 |
|
41 | + */ |
|
42 | + public function search($search, array $shareTypes, $lookup, $limit, $offset); |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and |
|
46 | - * 'class' with the class name of the plugin |
|
47 | - * @since 13.0.0 |
|
48 | - */ |
|
49 | - public function registerPlugin(array $pluginInfo); |
|
44 | + /** |
|
45 | + * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and |
|
46 | + * 'class' with the class name of the plugin |
|
47 | + * @since 13.0.0 |
|
48 | + */ |
|
49 | + public function registerPlugin(array $pluginInfo); |
|
50 | 50 | } |
@@ -30,44 +30,44 @@ |
||
30 | 30 | * @since 13.0.0 |
31 | 31 | */ |
32 | 32 | interface ISearchResult { |
33 | - /** |
|
34 | - * @param SearchResultType $type |
|
35 | - * @param array $matches |
|
36 | - * @param array|null $exactMatches |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null); |
|
33 | + /** |
|
34 | + * @param SearchResultType $type |
|
35 | + * @param array $matches |
|
36 | + * @param array|null $exactMatches |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param SearchResultType $type |
|
43 | - * @param string $collaboratorId |
|
44 | - * @return bool |
|
45 | - * @since 13.0.0 |
|
46 | - */ |
|
47 | - public function hasResult(SearchResultType $type, $collaboratorId); |
|
41 | + /** |
|
42 | + * @param SearchResultType $type |
|
43 | + * @param string $collaboratorId |
|
44 | + * @return bool |
|
45 | + * @since 13.0.0 |
|
46 | + */ |
|
47 | + public function hasResult(SearchResultType $type, $collaboratorId); |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param SearchResultType $type |
|
51 | - * @since 13.0.0 |
|
52 | - */ |
|
53 | - public function unsetResult(SearchResultType $type); |
|
49 | + /** |
|
50 | + * @param SearchResultType $type |
|
51 | + * @since 13.0.0 |
|
52 | + */ |
|
53 | + public function unsetResult(SearchResultType $type); |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param SearchResultType $type |
|
57 | - * @since 13.0.0 |
|
58 | - */ |
|
59 | - public function markExactIdMatch(SearchResultType $type); |
|
55 | + /** |
|
56 | + * @param SearchResultType $type |
|
57 | + * @since 13.0.0 |
|
58 | + */ |
|
59 | + public function markExactIdMatch(SearchResultType $type); |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param SearchResultType $type |
|
63 | - * @return bool |
|
64 | - * @since 13.0.0 |
|
65 | - */ |
|
66 | - public function hasExactIdMatch(SearchResultType $type); |
|
61 | + /** |
|
62 | + * @param SearchResultType $type |
|
63 | + * @return bool |
|
64 | + * @since 13.0.0 |
|
65 | + */ |
|
66 | + public function hasExactIdMatch(SearchResultType $type); |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - * @since 13.0.0 |
|
71 | - */ |
|
72 | - public function asArray(); |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + * @since 13.0.0 |
|
71 | + */ |
|
72 | + public function asArray(); |
|
73 | 73 | } |
@@ -30,203 +30,203 @@ |
||
30 | 30 | use OCP\ICache; |
31 | 31 | |
32 | 32 | class InfoParser { |
33 | - /** @var \OCP\ICache|null */ |
|
34 | - private $cache; |
|
35 | - |
|
36 | - /** |
|
37 | - * @param ICache|null $cache |
|
38 | - */ |
|
39 | - public function __construct(ICache $cache = null) { |
|
40 | - $this->cache = $cache; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $file the xml file to be loaded |
|
45 | - * @return null|array where null is an indicator for an error |
|
46 | - */ |
|
47 | - public function parse($file) { |
|
48 | - if (!file_exists($file)) { |
|
49 | - return null; |
|
50 | - } |
|
51 | - |
|
52 | - if(!is_null($this->cache)) { |
|
53 | - $fileCacheKey = $file . filemtime($file); |
|
54 | - if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
55 | - return json_decode($cachedValue, true); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - libxml_use_internal_errors(true); |
|
60 | - $loadEntities = libxml_disable_entity_loader(false); |
|
61 | - $xml = simplexml_load_file($file); |
|
62 | - |
|
63 | - libxml_disable_entity_loader($loadEntities); |
|
64 | - if ($xml === false) { |
|
65 | - libxml_clear_errors(); |
|
66 | - return null; |
|
67 | - } |
|
68 | - $array = $this->xmlToArray($xml); |
|
69 | - |
|
70 | - if (is_null($array)) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - |
|
74 | - if (!array_key_exists('info', $array)) { |
|
75 | - $array['info'] = []; |
|
76 | - } |
|
77 | - if (!array_key_exists('remote', $array)) { |
|
78 | - $array['remote'] = []; |
|
79 | - } |
|
80 | - if (!array_key_exists('public', $array)) { |
|
81 | - $array['public'] = []; |
|
82 | - } |
|
83 | - if (!array_key_exists('types', $array)) { |
|
84 | - $array['types'] = []; |
|
85 | - } |
|
86 | - if (!array_key_exists('repair-steps', $array)) { |
|
87 | - $array['repair-steps'] = []; |
|
88 | - } |
|
89 | - if (!array_key_exists('install', $array['repair-steps'])) { |
|
90 | - $array['repair-steps']['install'] = []; |
|
91 | - } |
|
92 | - if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
93 | - $array['repair-steps']['pre-migration'] = []; |
|
94 | - } |
|
95 | - if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
96 | - $array['repair-steps']['post-migration'] = []; |
|
97 | - } |
|
98 | - if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
99 | - $array['repair-steps']['live-migration'] = []; |
|
100 | - } |
|
101 | - if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
102 | - $array['repair-steps']['uninstall'] = []; |
|
103 | - } |
|
104 | - if (!array_key_exists('background-jobs', $array)) { |
|
105 | - $array['background-jobs'] = []; |
|
106 | - } |
|
107 | - if (!array_key_exists('two-factor-providers', $array)) { |
|
108 | - $array['two-factor-providers'] = []; |
|
109 | - } |
|
110 | - if (!array_key_exists('commands', $array)) { |
|
111 | - $array['commands'] = []; |
|
112 | - } |
|
113 | - if (!array_key_exists('activity', $array)) { |
|
114 | - $array['activity'] = []; |
|
115 | - } |
|
116 | - if (!array_key_exists('filters', $array['activity'])) { |
|
117 | - $array['activity']['filters'] = []; |
|
118 | - } |
|
119 | - if (!array_key_exists('settings', $array['activity'])) { |
|
120 | - $array['activity']['settings'] = []; |
|
121 | - } |
|
122 | - if (!array_key_exists('providers', $array['activity'])) { |
|
123 | - $array['activity']['providers'] = []; |
|
124 | - } |
|
125 | - |
|
126 | - if (array_key_exists('types', $array)) { |
|
127 | - if (is_array($array['types'])) { |
|
128 | - foreach ($array['types'] as $type => $v) { |
|
129 | - unset($array['types'][$type]); |
|
130 | - if (is_string($type)) { |
|
131 | - $array['types'][] = $type; |
|
132 | - } |
|
133 | - } |
|
134 | - } else { |
|
135 | - $array['types'] = []; |
|
136 | - } |
|
137 | - } |
|
138 | - if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
139 | - $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
140 | - } |
|
141 | - if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
142 | - $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
143 | - } |
|
144 | - if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
145 | - $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
146 | - } |
|
147 | - if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
148 | - $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
149 | - } |
|
150 | - if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
151 | - $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
152 | - } |
|
153 | - if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
154 | - $array['background-jobs'] = $array['background-jobs']['job']; |
|
155 | - } |
|
156 | - if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
157 | - $array['commands'] = $array['commands']['command']; |
|
158 | - } |
|
159 | - if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | - $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | - } |
|
162 | - if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | - $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | - } |
|
165 | - if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | - $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | - } |
|
168 | - if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | - && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | - && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | - ) { |
|
172 | - $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | - } |
|
174 | - |
|
175 | - if(!is_null($this->cache)) { |
|
176 | - $this->cache->set($fileCacheKey, json_encode($array)); |
|
177 | - } |
|
178 | - return $array; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param \SimpleXMLElement $xml |
|
183 | - * @return array |
|
184 | - */ |
|
185 | - public function xmlToArray($xml) { |
|
186 | - if (!$xml->children()) { |
|
187 | - return (string)$xml; |
|
188 | - } |
|
189 | - |
|
190 | - $array = []; |
|
191 | - foreach ($xml->children() as $element => $node) { |
|
192 | - $totalElement = count($xml->{$element}); |
|
193 | - |
|
194 | - if (!isset($array[$element])) { |
|
195 | - $array[$element] = $totalElement > 1 ? [] : ""; |
|
196 | - } |
|
197 | - /** @var \SimpleXMLElement $node */ |
|
198 | - // Has attributes |
|
199 | - if ($attributes = $node->attributes()) { |
|
200 | - $data = [ |
|
201 | - '@attributes' => [], |
|
202 | - ]; |
|
203 | - if (!count($node->children())){ |
|
204 | - $value = (string)$node; |
|
205 | - if (!empty($value)) { |
|
206 | - $data['@value'] = (string)$node; |
|
207 | - } |
|
208 | - } else { |
|
209 | - $data = array_merge($data, $this->xmlToArray($node)); |
|
210 | - } |
|
211 | - foreach ($attributes as $attr => $value) { |
|
212 | - $data['@attributes'][$attr] = (string)$value; |
|
213 | - } |
|
214 | - |
|
215 | - if ($totalElement > 1) { |
|
216 | - $array[$element][] = $data; |
|
217 | - } else { |
|
218 | - $array[$element] = $data; |
|
219 | - } |
|
220 | - // Just a value |
|
221 | - } else { |
|
222 | - if ($totalElement > 1) { |
|
223 | - $array[$element][] = $this->xmlToArray($node); |
|
224 | - } else { |
|
225 | - $array[$element] = $this->xmlToArray($node); |
|
226 | - } |
|
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - return $array; |
|
231 | - } |
|
33 | + /** @var \OCP\ICache|null */ |
|
34 | + private $cache; |
|
35 | + |
|
36 | + /** |
|
37 | + * @param ICache|null $cache |
|
38 | + */ |
|
39 | + public function __construct(ICache $cache = null) { |
|
40 | + $this->cache = $cache; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $file the xml file to be loaded |
|
45 | + * @return null|array where null is an indicator for an error |
|
46 | + */ |
|
47 | + public function parse($file) { |
|
48 | + if (!file_exists($file)) { |
|
49 | + return null; |
|
50 | + } |
|
51 | + |
|
52 | + if(!is_null($this->cache)) { |
|
53 | + $fileCacheKey = $file . filemtime($file); |
|
54 | + if ($cachedValue = $this->cache->get($fileCacheKey)) { |
|
55 | + return json_decode($cachedValue, true); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + libxml_use_internal_errors(true); |
|
60 | + $loadEntities = libxml_disable_entity_loader(false); |
|
61 | + $xml = simplexml_load_file($file); |
|
62 | + |
|
63 | + libxml_disable_entity_loader($loadEntities); |
|
64 | + if ($xml === false) { |
|
65 | + libxml_clear_errors(); |
|
66 | + return null; |
|
67 | + } |
|
68 | + $array = $this->xmlToArray($xml); |
|
69 | + |
|
70 | + if (is_null($array)) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + |
|
74 | + if (!array_key_exists('info', $array)) { |
|
75 | + $array['info'] = []; |
|
76 | + } |
|
77 | + if (!array_key_exists('remote', $array)) { |
|
78 | + $array['remote'] = []; |
|
79 | + } |
|
80 | + if (!array_key_exists('public', $array)) { |
|
81 | + $array['public'] = []; |
|
82 | + } |
|
83 | + if (!array_key_exists('types', $array)) { |
|
84 | + $array['types'] = []; |
|
85 | + } |
|
86 | + if (!array_key_exists('repair-steps', $array)) { |
|
87 | + $array['repair-steps'] = []; |
|
88 | + } |
|
89 | + if (!array_key_exists('install', $array['repair-steps'])) { |
|
90 | + $array['repair-steps']['install'] = []; |
|
91 | + } |
|
92 | + if (!array_key_exists('pre-migration', $array['repair-steps'])) { |
|
93 | + $array['repair-steps']['pre-migration'] = []; |
|
94 | + } |
|
95 | + if (!array_key_exists('post-migration', $array['repair-steps'])) { |
|
96 | + $array['repair-steps']['post-migration'] = []; |
|
97 | + } |
|
98 | + if (!array_key_exists('live-migration', $array['repair-steps'])) { |
|
99 | + $array['repair-steps']['live-migration'] = []; |
|
100 | + } |
|
101 | + if (!array_key_exists('uninstall', $array['repair-steps'])) { |
|
102 | + $array['repair-steps']['uninstall'] = []; |
|
103 | + } |
|
104 | + if (!array_key_exists('background-jobs', $array)) { |
|
105 | + $array['background-jobs'] = []; |
|
106 | + } |
|
107 | + if (!array_key_exists('two-factor-providers', $array)) { |
|
108 | + $array['two-factor-providers'] = []; |
|
109 | + } |
|
110 | + if (!array_key_exists('commands', $array)) { |
|
111 | + $array['commands'] = []; |
|
112 | + } |
|
113 | + if (!array_key_exists('activity', $array)) { |
|
114 | + $array['activity'] = []; |
|
115 | + } |
|
116 | + if (!array_key_exists('filters', $array['activity'])) { |
|
117 | + $array['activity']['filters'] = []; |
|
118 | + } |
|
119 | + if (!array_key_exists('settings', $array['activity'])) { |
|
120 | + $array['activity']['settings'] = []; |
|
121 | + } |
|
122 | + if (!array_key_exists('providers', $array['activity'])) { |
|
123 | + $array['activity']['providers'] = []; |
|
124 | + } |
|
125 | + |
|
126 | + if (array_key_exists('types', $array)) { |
|
127 | + if (is_array($array['types'])) { |
|
128 | + foreach ($array['types'] as $type => $v) { |
|
129 | + unset($array['types'][$type]); |
|
130 | + if (is_string($type)) { |
|
131 | + $array['types'][] = $type; |
|
132 | + } |
|
133 | + } |
|
134 | + } else { |
|
135 | + $array['types'] = []; |
|
136 | + } |
|
137 | + } |
|
138 | + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { |
|
139 | + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; |
|
140 | + } |
|
141 | + if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { |
|
142 | + $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; |
|
143 | + } |
|
144 | + if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) { |
|
145 | + $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step']; |
|
146 | + } |
|
147 | + if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { |
|
148 | + $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; |
|
149 | + } |
|
150 | + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { |
|
151 | + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; |
|
152 | + } |
|
153 | + if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) { |
|
154 | + $array['background-jobs'] = $array['background-jobs']['job']; |
|
155 | + } |
|
156 | + if (isset($array['commands']['command']) && is_array($array['commands']['command'])) { |
|
157 | + $array['commands'] = $array['commands']['command']; |
|
158 | + } |
|
159 | + if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) { |
|
160 | + $array['activity']['filters'] = $array['activity']['filters']['filter']; |
|
161 | + } |
|
162 | + if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) { |
|
163 | + $array['activity']['settings'] = $array['activity']['settings']['setting']; |
|
164 | + } |
|
165 | + if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) { |
|
166 | + $array['activity']['providers'] = $array['activity']['providers']['provider']; |
|
167 | + } |
|
168 | + if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
169 | + && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']) |
|
170 | + && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class']) |
|
171 | + ) { |
|
172 | + $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
|
173 | + } |
|
174 | + |
|
175 | + if(!is_null($this->cache)) { |
|
176 | + $this->cache->set($fileCacheKey, json_encode($array)); |
|
177 | + } |
|
178 | + return $array; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param \SimpleXMLElement $xml |
|
183 | + * @return array |
|
184 | + */ |
|
185 | + public function xmlToArray($xml) { |
|
186 | + if (!$xml->children()) { |
|
187 | + return (string)$xml; |
|
188 | + } |
|
189 | + |
|
190 | + $array = []; |
|
191 | + foreach ($xml->children() as $element => $node) { |
|
192 | + $totalElement = count($xml->{$element}); |
|
193 | + |
|
194 | + if (!isset($array[$element])) { |
|
195 | + $array[$element] = $totalElement > 1 ? [] : ""; |
|
196 | + } |
|
197 | + /** @var \SimpleXMLElement $node */ |
|
198 | + // Has attributes |
|
199 | + if ($attributes = $node->attributes()) { |
|
200 | + $data = [ |
|
201 | + '@attributes' => [], |
|
202 | + ]; |
|
203 | + if (!count($node->children())){ |
|
204 | + $value = (string)$node; |
|
205 | + if (!empty($value)) { |
|
206 | + $data['@value'] = (string)$node; |
|
207 | + } |
|
208 | + } else { |
|
209 | + $data = array_merge($data, $this->xmlToArray($node)); |
|
210 | + } |
|
211 | + foreach ($attributes as $attr => $value) { |
|
212 | + $data['@attributes'][$attr] = (string)$value; |
|
213 | + } |
|
214 | + |
|
215 | + if ($totalElement > 1) { |
|
216 | + $array[$element][] = $data; |
|
217 | + } else { |
|
218 | + $array[$element] = $data; |
|
219 | + } |
|
220 | + // Just a value |
|
221 | + } else { |
|
222 | + if ($totalElement > 1) { |
|
223 | + $array[$element][] = $this->xmlToArray($node); |
|
224 | + } else { |
|
225 | + $array[$element] = $this->xmlToArray($node); |
|
226 | + } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + return $array; |
|
231 | + } |
|
232 | 232 | } |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | return null; |
50 | 50 | } |
51 | 51 | |
52 | - if(!is_null($this->cache)) { |
|
53 | - $fileCacheKey = $file . filemtime($file); |
|
52 | + if (!is_null($this->cache)) { |
|
53 | + $fileCacheKey = $file.filemtime($file); |
|
54 | 54 | if ($cachedValue = $this->cache->get($fileCacheKey)) { |
55 | 55 | return json_decode($cachedValue, true); |
56 | 56 | } |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin']; |
173 | 173 | } |
174 | 174 | |
175 | - if(!is_null($this->cache)) { |
|
175 | + if (!is_null($this->cache)) { |
|
176 | 176 | $this->cache->set($fileCacheKey, json_encode($array)); |
177 | 177 | } |
178 | 178 | return $array; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | public function xmlToArray($xml) { |
186 | 186 | if (!$xml->children()) { |
187 | - return (string)$xml; |
|
187 | + return (string) $xml; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | $array = []; |
@@ -200,16 +200,16 @@ discard block |
||
200 | 200 | $data = [ |
201 | 201 | '@attributes' => [], |
202 | 202 | ]; |
203 | - if (!count($node->children())){ |
|
204 | - $value = (string)$node; |
|
203 | + if (!count($node->children())) { |
|
204 | + $value = (string) $node; |
|
205 | 205 | if (!empty($value)) { |
206 | - $data['@value'] = (string)$node; |
|
206 | + $data['@value'] = (string) $node; |
|
207 | 207 | } |
208 | 208 | } else { |
209 | 209 | $data = array_merge($data, $this->xmlToArray($node)); |
210 | 210 | } |
211 | 211 | foreach ($attributes as $attr => $value) { |
212 | - $data['@attributes'][$attr] = (string)$value; |
|
212 | + $data['@attributes'][$attr] = (string) $value; |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | if ($totalElement > 1) { |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | |
87 | 87 | if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
88 | 88 | $singleResult = [[ |
89 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
89 | + 'label' => $contact['FN']." ($emailAddress)", |
|
90 | 90 | 'value' => [ |
91 | 91 | 'shareType' => Share::SHARE_TYPE_USER, |
92 | 92 | 'shareWith' => $cloud->getUser(), |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
109 | 109 | $singleResult = [[ |
110 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
110 | + 'label' => $contact['FN']." ($emailAddress)", |
|
111 | 111 | 'value' => [ |
112 | 112 | 'shareType' => Share::SHARE_TYPE_USER, |
113 | 113 | 'shareWith' => $cloud->getUser(), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | $searchResult->markExactIdMatch($emailType); |
125 | 125 | } |
126 | 126 | $result['exact'][] = [ |
127 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
127 | + 'label' => $contact['FN']." ($emailAddress)", |
|
128 | 128 | 'value' => [ |
129 | 129 | 'shareType' => Share::SHARE_TYPE_EMAIL, |
130 | 130 | 'shareWith' => $emailAddress, |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | ]; |
133 | 133 | } else { |
134 | 134 | $result['wide'][] = [ |
135 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
135 | + 'label' => $contact['FN']." ($emailAddress)", |
|
136 | 136 | 'value' => [ |
137 | 137 | 'shareType' => Share::SHARE_TYPE_EMAIL, |
138 | 138 | 'shareWith' => $emailAddress, |
@@ -33,132 +33,132 @@ |
||
33 | 33 | use OCP\Share; |
34 | 34 | |
35 | 35 | class MailPlugin implements ISearchPlugin { |
36 | - protected $shareeEnumeration; |
|
37 | - |
|
38 | - /** @var IManager */ |
|
39 | - private $contactsManager; |
|
40 | - /** @var ICloudIdManager */ |
|
41 | - private $cloudIdManager; |
|
42 | - /** @var IConfig */ |
|
43 | - private $config; |
|
44 | - |
|
45 | - public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | - $this->contactsManager = $contactsManager; |
|
47 | - $this->cloudIdManager = $cloudIdManager; |
|
48 | - $this->config = $config; |
|
49 | - |
|
50 | - $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @param $search |
|
55 | - * @param $limit |
|
56 | - * @param $offset |
|
57 | - * @param ISearchResult $searchResult |
|
58 | - * @return bool |
|
59 | - * @since 13.0.0 |
|
60 | - */ |
|
61 | - public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
62 | - $result = ['wide' => [], 'exact' => []]; |
|
63 | - $userType = new SearchResultType('users'); |
|
64 | - $emailType = new SearchResultType('emails'); |
|
65 | - |
|
66 | - // Search in contacts |
|
67 | - //@todo Pagination missing |
|
68 | - $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); |
|
69 | - $lowerSearch = strtolower($search); |
|
70 | - foreach ($addressBookContacts as $contact) { |
|
71 | - if (isset($contact['EMAIL'])) { |
|
72 | - $emailAddresses = $contact['EMAIL']; |
|
73 | - if (!is_array($emailAddresses)) { |
|
74 | - $emailAddresses = [$emailAddresses]; |
|
75 | - } |
|
76 | - foreach ($emailAddresses as $emailAddress) { |
|
77 | - $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
78 | - |
|
79 | - if (isset($contact['isLocalSystemBook'])) { |
|
80 | - if ($exactEmailMatch) { |
|
81 | - try { |
|
82 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
83 | - } catch (\InvalidArgumentException $e) { |
|
84 | - continue; |
|
85 | - } |
|
86 | - |
|
87 | - if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
88 | - $singleResult = [[ |
|
89 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
90 | - 'value' => [ |
|
91 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
92 | - 'shareWith' => $cloud->getUser(), |
|
93 | - ], |
|
94 | - ]]; |
|
95 | - $searchResult->addResultSet($userType, [], $singleResult); |
|
96 | - $searchResult->markExactIdMatch($emailType); |
|
97 | - } |
|
98 | - return false; |
|
99 | - } |
|
100 | - |
|
101 | - if ($this->shareeEnumeration) { |
|
102 | - try { |
|
103 | - $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
104 | - } catch (\InvalidArgumentException $e) { |
|
105 | - continue; |
|
106 | - } |
|
107 | - |
|
108 | - if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
109 | - $singleResult = [[ |
|
110 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
111 | - 'value' => [ |
|
112 | - 'shareType' => Share::SHARE_TYPE_USER, |
|
113 | - 'shareWith' => $cloud->getUser(), |
|
114 | - ]], |
|
115 | - ]; |
|
116 | - $searchResult->addResultSet($userType, $singleResult, []); |
|
117 | - } |
|
118 | - } |
|
119 | - continue; |
|
120 | - } |
|
121 | - |
|
122 | - if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) { |
|
123 | - if ($exactEmailMatch) { |
|
124 | - $searchResult->markExactIdMatch($emailType); |
|
125 | - } |
|
126 | - $result['exact'][] = [ |
|
127 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
128 | - 'value' => [ |
|
129 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
130 | - 'shareWith' => $emailAddress, |
|
131 | - ], |
|
132 | - ]; |
|
133 | - } else { |
|
134 | - $result['wide'][] = [ |
|
135 | - 'label' => $contact['FN'] . " ($emailAddress)", |
|
136 | - 'value' => [ |
|
137 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
138 | - 'shareWith' => $emailAddress, |
|
139 | - ], |
|
140 | - ]; |
|
141 | - } |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - if (!$this->shareeEnumeration) { |
|
147 | - $result['wide'] = []; |
|
148 | - } |
|
149 | - |
|
150 | - if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) { |
|
151 | - $result['exact'][] = [ |
|
152 | - 'label' => $search, |
|
153 | - 'value' => [ |
|
154 | - 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
155 | - 'shareWith' => $search, |
|
156 | - ], |
|
157 | - ]; |
|
158 | - } |
|
159 | - |
|
160 | - $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
161 | - |
|
162 | - return true; |
|
163 | - } |
|
36 | + protected $shareeEnumeration; |
|
37 | + |
|
38 | + /** @var IManager */ |
|
39 | + private $contactsManager; |
|
40 | + /** @var ICloudIdManager */ |
|
41 | + private $cloudIdManager; |
|
42 | + /** @var IConfig */ |
|
43 | + private $config; |
|
44 | + |
|
45 | + public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) { |
|
46 | + $this->contactsManager = $contactsManager; |
|
47 | + $this->cloudIdManager = $cloudIdManager; |
|
48 | + $this->config = $config; |
|
49 | + |
|
50 | + $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes'; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @param $search |
|
55 | + * @param $limit |
|
56 | + * @param $offset |
|
57 | + * @param ISearchResult $searchResult |
|
58 | + * @return bool |
|
59 | + * @since 13.0.0 |
|
60 | + */ |
|
61 | + public function search($search, $limit, $offset, ISearchResult $searchResult) { |
|
62 | + $result = ['wide' => [], 'exact' => []]; |
|
63 | + $userType = new SearchResultType('users'); |
|
64 | + $emailType = new SearchResultType('emails'); |
|
65 | + |
|
66 | + // Search in contacts |
|
67 | + //@todo Pagination missing |
|
68 | + $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']); |
|
69 | + $lowerSearch = strtolower($search); |
|
70 | + foreach ($addressBookContacts as $contact) { |
|
71 | + if (isset($contact['EMAIL'])) { |
|
72 | + $emailAddresses = $contact['EMAIL']; |
|
73 | + if (!is_array($emailAddresses)) { |
|
74 | + $emailAddresses = [$emailAddresses]; |
|
75 | + } |
|
76 | + foreach ($emailAddresses as $emailAddress) { |
|
77 | + $exactEmailMatch = strtolower($emailAddress) === $lowerSearch; |
|
78 | + |
|
79 | + if (isset($contact['isLocalSystemBook'])) { |
|
80 | + if ($exactEmailMatch) { |
|
81 | + try { |
|
82 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
83 | + } catch (\InvalidArgumentException $e) { |
|
84 | + continue; |
|
85 | + } |
|
86 | + |
|
87 | + if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
88 | + $singleResult = [[ |
|
89 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
90 | + 'value' => [ |
|
91 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
92 | + 'shareWith' => $cloud->getUser(), |
|
93 | + ], |
|
94 | + ]]; |
|
95 | + $searchResult->addResultSet($userType, [], $singleResult); |
|
96 | + $searchResult->markExactIdMatch($emailType); |
|
97 | + } |
|
98 | + return false; |
|
99 | + } |
|
100 | + |
|
101 | + if ($this->shareeEnumeration) { |
|
102 | + try { |
|
103 | + $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]); |
|
104 | + } catch (\InvalidArgumentException $e) { |
|
105 | + continue; |
|
106 | + } |
|
107 | + |
|
108 | + if (!$searchResult->hasResult($userType, $cloud->getUser())) { |
|
109 | + $singleResult = [[ |
|
110 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
111 | + 'value' => [ |
|
112 | + 'shareType' => Share::SHARE_TYPE_USER, |
|
113 | + 'shareWith' => $cloud->getUser(), |
|
114 | + ]], |
|
115 | + ]; |
|
116 | + $searchResult->addResultSet($userType, $singleResult, []); |
|
117 | + } |
|
118 | + } |
|
119 | + continue; |
|
120 | + } |
|
121 | + |
|
122 | + if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) { |
|
123 | + if ($exactEmailMatch) { |
|
124 | + $searchResult->markExactIdMatch($emailType); |
|
125 | + } |
|
126 | + $result['exact'][] = [ |
|
127 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
128 | + 'value' => [ |
|
129 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
130 | + 'shareWith' => $emailAddress, |
|
131 | + ], |
|
132 | + ]; |
|
133 | + } else { |
|
134 | + $result['wide'][] = [ |
|
135 | + 'label' => $contact['FN'] . " ($emailAddress)", |
|
136 | + 'value' => [ |
|
137 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
138 | + 'shareWith' => $emailAddress, |
|
139 | + ], |
|
140 | + ]; |
|
141 | + } |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + if (!$this->shareeEnumeration) { |
|
147 | + $result['wide'] = []; |
|
148 | + } |
|
149 | + |
|
150 | + if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) { |
|
151 | + $result['exact'][] = [ |
|
152 | + 'label' => $search, |
|
153 | + 'value' => [ |
|
154 | + 'shareType' => Share::SHARE_TYPE_EMAIL, |
|
155 | + 'shareWith' => $search, |
|
156 | + ], |
|
157 | + ]; |
|
158 | + } |
|
159 | + |
|
160 | + $searchResult->addResultSet($emailType, $result['wide'], $result['exact']); |
|
161 | + |
|
162 | + return true; |
|
163 | + } |
|
164 | 164 | } |
@@ -61,1189 +61,1189 @@ |
||
61 | 61 | * upgrading and removing apps. |
62 | 62 | */ |
63 | 63 | class OC_App { |
64 | - static private $appVersion = []; |
|
65 | - static private $adminForms = array(); |
|
66 | - static private $personalForms = array(); |
|
67 | - static private $appInfo = array(); |
|
68 | - static private $appTypes = array(); |
|
69 | - static private $loadedApps = array(); |
|
70 | - static private $altLogin = array(); |
|
71 | - static private $alreadyRegistered = []; |
|
72 | - const officialApp = 200; |
|
73 | - |
|
74 | - /** |
|
75 | - * clean the appId |
|
76 | - * |
|
77 | - * @param string|boolean $app AppId that needs to be cleaned |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function cleanAppId($app) { |
|
81 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check if an app is loaded |
|
86 | - * |
|
87 | - * @param string $app |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public static function isAppLoaded($app) { |
|
91 | - return in_array($app, self::$loadedApps, true); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * loads all apps |
|
96 | - * |
|
97 | - * @param string[] | string | null $types |
|
98 | - * @return bool |
|
99 | - * |
|
100 | - * This function walks through the ownCloud directory and loads all apps |
|
101 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | - * exists. |
|
103 | - * |
|
104 | - * if $types is set, only apps of those types will be loaded |
|
105 | - */ |
|
106 | - public static function loadApps($types = null) { |
|
107 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - // Load the enabled apps here |
|
111 | - $apps = self::getEnabledApps(); |
|
112 | - |
|
113 | - // Add each apps' folder as allowed class path |
|
114 | - foreach($apps as $app) { |
|
115 | - $path = self::getAppPath($app); |
|
116 | - if($path !== false) { |
|
117 | - self::registerAutoloading($app, $path); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - // prevent app.php from printing output |
|
122 | - ob_start(); |
|
123 | - foreach ($apps as $app) { |
|
124 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | - self::loadApp($app); |
|
126 | - } |
|
127 | - } |
|
128 | - ob_end_clean(); |
|
129 | - |
|
130 | - return true; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * load a single app |
|
135 | - * |
|
136 | - * @param string $app |
|
137 | - */ |
|
138 | - public static function loadApp($app) { |
|
139 | - self::$loadedApps[] = $app; |
|
140 | - $appPath = self::getAppPath($app); |
|
141 | - if($appPath === false) { |
|
142 | - return; |
|
143 | - } |
|
144 | - |
|
145 | - // in case someone calls loadApp() directly |
|
146 | - self::registerAutoloading($app, $appPath); |
|
147 | - |
|
148 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | - self::requireAppFile($app); |
|
151 | - if (self::isType($app, array('authentication'))) { |
|
152 | - // since authentication apps affect the "is app enabled for group" check, |
|
153 | - // the enabled apps cache needs to be cleared to make sure that the |
|
154 | - // next time getEnableApps() is called it will also include apps that were |
|
155 | - // enabled for groups |
|
156 | - self::$enabledAppsCache = array(); |
|
157 | - } |
|
158 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
159 | - } |
|
160 | - |
|
161 | - $info = self::getAppInfo($app); |
|
162 | - if (!empty($info['activity']['filters'])) { |
|
163 | - foreach ($info['activity']['filters'] as $filter) { |
|
164 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
165 | - } |
|
166 | - } |
|
167 | - if (!empty($info['activity']['settings'])) { |
|
168 | - foreach ($info['activity']['settings'] as $setting) { |
|
169 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
170 | - } |
|
171 | - } |
|
172 | - if (!empty($info['activity']['providers'])) { |
|
173 | - foreach ($info['activity']['providers'] as $provider) { |
|
174 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
175 | - } |
|
176 | - } |
|
177 | - if (!empty($info['collaboration']['collaborators']['searchPlugins'])) { |
|
178 | - foreach ($info['collaboration']['collaborators']['searchPlugins'] as $plugin) { |
|
179 | - \OC::$server->getCollaboratorSearch()->registerPlugin($plugin); |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @internal |
|
186 | - * @param string $app |
|
187 | - * @param string $path |
|
188 | - */ |
|
189 | - public static function registerAutoloading($app, $path) { |
|
190 | - $key = $app . '-' . $path; |
|
191 | - if(isset(self::$alreadyRegistered[$key])) { |
|
192 | - return; |
|
193 | - } |
|
194 | - self::$alreadyRegistered[$key] = true; |
|
195 | - // Register on PSR-4 composer autoloader |
|
196 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
197 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
198 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
199 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
200 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
201 | - } |
|
202 | - |
|
203 | - // Register on legacy autoloader |
|
204 | - \OC::$loader->addValidRoot($path); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Load app.php from the given app |
|
209 | - * |
|
210 | - * @param string $app app name |
|
211 | - */ |
|
212 | - private static function requireAppFile($app) { |
|
213 | - try { |
|
214 | - // encapsulated here to avoid variable scope conflicts |
|
215 | - require_once $app . '/appinfo/app.php'; |
|
216 | - } catch (Error $ex) { |
|
217 | - \OC::$server->getLogger()->logException($ex); |
|
218 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
219 | - if (!in_array($app, $blacklist)) { |
|
220 | - self::disable($app); |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * check if an app is of a specific type |
|
227 | - * |
|
228 | - * @param string $app |
|
229 | - * @param string|array $types |
|
230 | - * @return bool |
|
231 | - */ |
|
232 | - public static function isType($app, $types) { |
|
233 | - if (is_string($types)) { |
|
234 | - $types = array($types); |
|
235 | - } |
|
236 | - $appTypes = self::getAppTypes($app); |
|
237 | - foreach ($types as $type) { |
|
238 | - if (array_search($type, $appTypes) !== false) { |
|
239 | - return true; |
|
240 | - } |
|
241 | - } |
|
242 | - return false; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * get the types of an app |
|
247 | - * |
|
248 | - * @param string $app |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - private static function getAppTypes($app) { |
|
252 | - //load the cache |
|
253 | - if (count(self::$appTypes) == 0) { |
|
254 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
255 | - } |
|
256 | - |
|
257 | - if (isset(self::$appTypes[$app])) { |
|
258 | - return explode(',', self::$appTypes[$app]); |
|
259 | - } else { |
|
260 | - return array(); |
|
261 | - } |
|
262 | - } |
|
263 | - |
|
264 | - /** |
|
265 | - * read app types from info.xml and cache them in the database |
|
266 | - */ |
|
267 | - public static function setAppTypes($app) { |
|
268 | - $appData = self::getAppInfo($app); |
|
269 | - if(!is_array($appData)) { |
|
270 | - return; |
|
271 | - } |
|
272 | - |
|
273 | - if (isset($appData['types'])) { |
|
274 | - $appTypes = implode(',', $appData['types']); |
|
275 | - } else { |
|
276 | - $appTypes = ''; |
|
277 | - $appData['types'] = []; |
|
278 | - } |
|
279 | - |
|
280 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
281 | - |
|
282 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
283 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
284 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
285 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * get all enabled apps |
|
292 | - */ |
|
293 | - protected static $enabledAppsCache = array(); |
|
294 | - |
|
295 | - /** |
|
296 | - * Returns apps enabled for the current user. |
|
297 | - * |
|
298 | - * @param bool $forceRefresh whether to refresh the cache |
|
299 | - * @param bool $all whether to return apps for all users, not only the |
|
300 | - * currently logged in one |
|
301 | - * @return string[] |
|
302 | - */ |
|
303 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
304 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
305 | - return array(); |
|
306 | - } |
|
307 | - // in incognito mode or when logged out, $user will be false, |
|
308 | - // which is also the case during an upgrade |
|
309 | - $appManager = \OC::$server->getAppManager(); |
|
310 | - if ($all) { |
|
311 | - $user = null; |
|
312 | - } else { |
|
313 | - $user = \OC::$server->getUserSession()->getUser(); |
|
314 | - } |
|
315 | - |
|
316 | - if (is_null($user)) { |
|
317 | - $apps = $appManager->getInstalledApps(); |
|
318 | - } else { |
|
319 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
320 | - } |
|
321 | - $apps = array_filter($apps, function ($app) { |
|
322 | - return $app !== 'files';//we add this manually |
|
323 | - }); |
|
324 | - sort($apps); |
|
325 | - array_unshift($apps, 'files'); |
|
326 | - return $apps; |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * checks whether or not an app is enabled |
|
331 | - * |
|
332 | - * @param string $app app |
|
333 | - * @return bool |
|
334 | - * |
|
335 | - * This function checks whether or not an app is enabled. |
|
336 | - */ |
|
337 | - public static function isEnabled($app) { |
|
338 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * enables an app |
|
343 | - * |
|
344 | - * @param string $appId |
|
345 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
346 | - * @throws \Exception |
|
347 | - * @return void |
|
348 | - * |
|
349 | - * This function set an app as enabled in appconfig. |
|
350 | - */ |
|
351 | - public function enable($appId, |
|
352 | - $groups = null) { |
|
353 | - self::$enabledAppsCache = []; // flush |
|
354 | - |
|
355 | - // Check if app is already downloaded |
|
356 | - $installer = new Installer( |
|
357 | - \OC::$server->getAppFetcher(), |
|
358 | - \OC::$server->getHTTPClientService(), |
|
359 | - \OC::$server->getTempManager(), |
|
360 | - \OC::$server->getLogger(), |
|
361 | - \OC::$server->getConfig() |
|
362 | - ); |
|
363 | - $isDownloaded = $installer->isDownloaded($appId); |
|
364 | - |
|
365 | - if(!$isDownloaded) { |
|
366 | - $installer->downloadApp($appId); |
|
367 | - } |
|
368 | - |
|
369 | - $installer->installApp($appId); |
|
370 | - |
|
371 | - $appManager = \OC::$server->getAppManager(); |
|
372 | - if (!is_null($groups)) { |
|
373 | - $groupManager = \OC::$server->getGroupManager(); |
|
374 | - $groupsList = []; |
|
375 | - foreach ($groups as $group) { |
|
376 | - $groupItem = $groupManager->get($group); |
|
377 | - if ($groupItem instanceof \OCP\IGroup) { |
|
378 | - $groupsList[] = $groupManager->get($group); |
|
379 | - } |
|
380 | - } |
|
381 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
382 | - } else { |
|
383 | - $appManager->enableApp($appId); |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * @param string $app |
|
389 | - * @return bool |
|
390 | - */ |
|
391 | - public static function removeApp($app) { |
|
392 | - if (\OC::$server->getAppManager()->isShipped($app)) { |
|
393 | - return false; |
|
394 | - } |
|
395 | - |
|
396 | - $installer = new Installer( |
|
397 | - \OC::$server->getAppFetcher(), |
|
398 | - \OC::$server->getHTTPClientService(), |
|
399 | - \OC::$server->getTempManager(), |
|
400 | - \OC::$server->getLogger(), |
|
401 | - \OC::$server->getConfig() |
|
402 | - ); |
|
403 | - return $installer->removeApp($app); |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * This function set an app as disabled in appconfig. |
|
408 | - * |
|
409 | - * @param string $app app |
|
410 | - * @throws Exception |
|
411 | - */ |
|
412 | - public static function disable($app) { |
|
413 | - // flush |
|
414 | - self::$enabledAppsCache = array(); |
|
415 | - |
|
416 | - // run uninstall steps |
|
417 | - $appData = OC_App::getAppInfo($app); |
|
418 | - if (!is_null($appData)) { |
|
419 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
420 | - } |
|
421 | - |
|
422 | - // emit disable hook - needed anymore ? |
|
423 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
424 | - |
|
425 | - // finally disable it |
|
426 | - $appManager = \OC::$server->getAppManager(); |
|
427 | - $appManager->disableApp($app); |
|
428 | - } |
|
429 | - |
|
430 | - // This is private as well. It simply works, so don't ask for more details |
|
431 | - private static function proceedNavigation($list) { |
|
432 | - usort($list, function($a, $b) { |
|
433 | - if (isset($a['order']) && isset($b['order'])) { |
|
434 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
435 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
436 | - return isset($a['order']) ? -1 : 1; |
|
437 | - } else { |
|
438 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
439 | - } |
|
440 | - }); |
|
441 | - |
|
442 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
443 | - foreach ($list as $index => &$navEntry) { |
|
444 | - if ($navEntry['id'] == $activeApp) { |
|
445 | - $navEntry['active'] = true; |
|
446 | - } else { |
|
447 | - $navEntry['active'] = false; |
|
448 | - } |
|
449 | - } |
|
450 | - unset($navEntry); |
|
451 | - |
|
452 | - return $list; |
|
453 | - } |
|
454 | - |
|
455 | - /** |
|
456 | - * Get the path where to install apps |
|
457 | - * |
|
458 | - * @return string|false |
|
459 | - */ |
|
460 | - public static function getInstallPath() { |
|
461 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
462 | - return false; |
|
463 | - } |
|
464 | - |
|
465 | - foreach (OC::$APPSROOTS as $dir) { |
|
466 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
467 | - return $dir['path']; |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
472 | - return null; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * search for an app in all app-directories |
|
478 | - * |
|
479 | - * @param string $appId |
|
480 | - * @return false|string |
|
481 | - */ |
|
482 | - public static function findAppInDirectories($appId) { |
|
483 | - $sanitizedAppId = self::cleanAppId($appId); |
|
484 | - if($sanitizedAppId !== $appId) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - static $app_dir = array(); |
|
488 | - |
|
489 | - if (isset($app_dir[$appId])) { |
|
490 | - return $app_dir[$appId]; |
|
491 | - } |
|
492 | - |
|
493 | - $possibleApps = array(); |
|
494 | - foreach (OC::$APPSROOTS as $dir) { |
|
495 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
496 | - $possibleApps[] = $dir; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - if (empty($possibleApps)) { |
|
501 | - return false; |
|
502 | - } elseif (count($possibleApps) === 1) { |
|
503 | - $dir = array_shift($possibleApps); |
|
504 | - $app_dir[$appId] = $dir; |
|
505 | - return $dir; |
|
506 | - } else { |
|
507 | - $versionToLoad = array(); |
|
508 | - foreach ($possibleApps as $possibleApp) { |
|
509 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
510 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
511 | - $versionToLoad = array( |
|
512 | - 'dir' => $possibleApp, |
|
513 | - 'version' => $version, |
|
514 | - ); |
|
515 | - } |
|
516 | - } |
|
517 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
518 | - return $versionToLoad['dir']; |
|
519 | - //TODO - write test |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Get the directory for the given app. |
|
525 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
526 | - * |
|
527 | - * @param string $appId |
|
528 | - * @return string|false |
|
529 | - */ |
|
530 | - public static function getAppPath($appId) { |
|
531 | - if ($appId === null || trim($appId) === '') { |
|
532 | - return false; |
|
533 | - } |
|
534 | - |
|
535 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
536 | - return $dir['path'] . '/' . $appId; |
|
537 | - } |
|
538 | - return false; |
|
539 | - } |
|
540 | - |
|
541 | - /** |
|
542 | - * Get the path for the given app on the access |
|
543 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
544 | - * |
|
545 | - * @param string $appId |
|
546 | - * @return string|false |
|
547 | - */ |
|
548 | - public static function getAppWebPath($appId) { |
|
549 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
550 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
551 | - } |
|
552 | - return false; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * get the last version of the app from appinfo/info.xml |
|
557 | - * |
|
558 | - * @param string $appId |
|
559 | - * @param bool $useCache |
|
560 | - * @return string |
|
561 | - */ |
|
562 | - public static function getAppVersion($appId, $useCache = true) { |
|
563 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
564 | - return self::$appVersion[$appId]; |
|
565 | - } |
|
566 | - |
|
567 | - $file = self::getAppPath($appId); |
|
568 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
569 | - return self::$appVersion[$appId]; |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * get app's version based on it's path |
|
574 | - * |
|
575 | - * @param string $path |
|
576 | - * @return string |
|
577 | - */ |
|
578 | - public static function getAppVersionByPath($path) { |
|
579 | - $infoFile = $path . '/appinfo/info.xml'; |
|
580 | - $appData = self::getAppInfo($infoFile, true); |
|
581 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Read all app metadata from the info.xml file |
|
587 | - * |
|
588 | - * @param string $appId id of the app or the path of the info.xml file |
|
589 | - * @param bool $path |
|
590 | - * @param string $lang |
|
591 | - * @return array|null |
|
592 | - * @note all data is read from info.xml, not just pre-defined fields |
|
593 | - */ |
|
594 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
595 | - if ($path) { |
|
596 | - $file = $appId; |
|
597 | - } else { |
|
598 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
599 | - return self::$appInfo[$appId]; |
|
600 | - } |
|
601 | - $appPath = self::getAppPath($appId); |
|
602 | - if($appPath === false) { |
|
603 | - return null; |
|
604 | - } |
|
605 | - $file = $appPath . '/appinfo/info.xml'; |
|
606 | - } |
|
607 | - |
|
608 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
609 | - $data = $parser->parse($file); |
|
610 | - |
|
611 | - if (is_array($data)) { |
|
612 | - $data = OC_App::parseAppInfo($data, $lang); |
|
613 | - } |
|
614 | - if(isset($data['ocsid'])) { |
|
615 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
616 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
617 | - $data['ocsid'] = $storedId; |
|
618 | - } |
|
619 | - } |
|
620 | - |
|
621 | - if ($lang === null) { |
|
622 | - self::$appInfo[$appId] = $data; |
|
623 | - } |
|
624 | - |
|
625 | - return $data; |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Returns the navigation |
|
630 | - * |
|
631 | - * @return array |
|
632 | - * |
|
633 | - * This function returns an array containing all entries added. The |
|
634 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
635 | - * given for each app the following keys exist: |
|
636 | - * - active: boolean, signals if the user is on this navigation entry |
|
637 | - */ |
|
638 | - public static function getNavigation() { |
|
639 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
640 | - return self::proceedNavigation($entries); |
|
641 | - } |
|
642 | - |
|
643 | - /** |
|
644 | - * Returns the Settings Navigation |
|
645 | - * |
|
646 | - * @return string[] |
|
647 | - * |
|
648 | - * This function returns an array containing all settings pages added. The |
|
649 | - * entries are sorted by the key 'order' ascending. |
|
650 | - */ |
|
651 | - public static function getSettingsNavigation() { |
|
652 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
653 | - return self::proceedNavigation($entries); |
|
654 | - } |
|
655 | - |
|
656 | - /** |
|
657 | - * get the id of loaded app |
|
658 | - * |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public static function getCurrentApp() { |
|
662 | - $request = \OC::$server->getRequest(); |
|
663 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
664 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
665 | - if (empty($topFolder)) { |
|
666 | - $path_info = $request->getPathInfo(); |
|
667 | - if ($path_info) { |
|
668 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
669 | - } |
|
670 | - } |
|
671 | - if ($topFolder == 'apps') { |
|
672 | - $length = strlen($topFolder); |
|
673 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
674 | - } else { |
|
675 | - return $topFolder; |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * @param string $type |
|
681 | - * @return array |
|
682 | - */ |
|
683 | - public static function getForms($type) { |
|
684 | - $forms = array(); |
|
685 | - switch ($type) { |
|
686 | - case 'admin': |
|
687 | - $source = self::$adminForms; |
|
688 | - break; |
|
689 | - case 'personal': |
|
690 | - $source = self::$personalForms; |
|
691 | - break; |
|
692 | - default: |
|
693 | - return array(); |
|
694 | - } |
|
695 | - foreach ($source as $form) { |
|
696 | - $forms[] = include $form; |
|
697 | - } |
|
698 | - return $forms; |
|
699 | - } |
|
700 | - |
|
701 | - /** |
|
702 | - * register an admin form to be shown |
|
703 | - * |
|
704 | - * @param string $app |
|
705 | - * @param string $page |
|
706 | - */ |
|
707 | - public static function registerAdmin($app, $page) { |
|
708 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * register a personal form to be shown |
|
713 | - * @param string $app |
|
714 | - * @param string $page |
|
715 | - */ |
|
716 | - public static function registerPersonal($app, $page) { |
|
717 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
718 | - } |
|
719 | - |
|
720 | - /** |
|
721 | - * @param array $entry |
|
722 | - */ |
|
723 | - public static function registerLogIn(array $entry) { |
|
724 | - self::$altLogin[] = $entry; |
|
725 | - } |
|
726 | - |
|
727 | - /** |
|
728 | - * @return array |
|
729 | - */ |
|
730 | - public static function getAlternativeLogIns() { |
|
731 | - return self::$altLogin; |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * get a list of all apps in the apps folder |
|
736 | - * |
|
737 | - * @return array an array of app names (string IDs) |
|
738 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
739 | - */ |
|
740 | - public static function getAllApps() { |
|
741 | - |
|
742 | - $apps = array(); |
|
743 | - |
|
744 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
745 | - if (!is_readable($apps_dir['path'])) { |
|
746 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
747 | - continue; |
|
748 | - } |
|
749 | - $dh = opendir($apps_dir['path']); |
|
750 | - |
|
751 | - if (is_resource($dh)) { |
|
752 | - while (($file = readdir($dh)) !== false) { |
|
753 | - |
|
754 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
755 | - |
|
756 | - $apps[] = $file; |
|
757 | - } |
|
758 | - } |
|
759 | - } |
|
760 | - } |
|
761 | - |
|
762 | - return $apps; |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * List all apps, this is used in apps.php |
|
767 | - * |
|
768 | - * @return array |
|
769 | - */ |
|
770 | - public function listAllApps() { |
|
771 | - $installedApps = OC_App::getAllApps(); |
|
772 | - |
|
773 | - $appManager = \OC::$server->getAppManager(); |
|
774 | - //we don't want to show configuration for these |
|
775 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
776 | - $appList = array(); |
|
777 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
778 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
779 | - |
|
780 | - foreach ($installedApps as $app) { |
|
781 | - if (array_search($app, $blacklist) === false) { |
|
782 | - |
|
783 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
784 | - if (!is_array($info)) { |
|
785 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
786 | - continue; |
|
787 | - } |
|
788 | - |
|
789 | - if (!isset($info['name'])) { |
|
790 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
791 | - continue; |
|
792 | - } |
|
793 | - |
|
794 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
795 | - $info['groups'] = null; |
|
796 | - if ($enabled === 'yes') { |
|
797 | - $active = true; |
|
798 | - } else if ($enabled === 'no') { |
|
799 | - $active = false; |
|
800 | - } else { |
|
801 | - $active = true; |
|
802 | - $info['groups'] = $enabled; |
|
803 | - } |
|
804 | - |
|
805 | - $info['active'] = $active; |
|
806 | - |
|
807 | - if ($appManager->isShipped($app)) { |
|
808 | - $info['internal'] = true; |
|
809 | - $info['level'] = self::officialApp; |
|
810 | - $info['removable'] = false; |
|
811 | - } else { |
|
812 | - $info['internal'] = false; |
|
813 | - $info['removable'] = true; |
|
814 | - } |
|
815 | - |
|
816 | - $appPath = self::getAppPath($app); |
|
817 | - if($appPath !== false) { |
|
818 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
819 | - if (file_exists($appIcon)) { |
|
820 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
821 | - $info['previewAsIcon'] = true; |
|
822 | - } else { |
|
823 | - $appIcon = $appPath . '/img/app.svg'; |
|
824 | - if (file_exists($appIcon)) { |
|
825 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
826 | - $info['previewAsIcon'] = true; |
|
827 | - } |
|
828 | - } |
|
829 | - } |
|
830 | - // fix documentation |
|
831 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
832 | - foreach ($info['documentation'] as $key => $url) { |
|
833 | - // If it is not an absolute URL we assume it is a key |
|
834 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
835 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
836 | - $url = $urlGenerator->linkToDocs($url); |
|
837 | - } |
|
838 | - |
|
839 | - $info['documentation'][$key] = $url; |
|
840 | - } |
|
841 | - } |
|
842 | - |
|
843 | - $info['version'] = OC_App::getAppVersion($app); |
|
844 | - $appList[] = $info; |
|
845 | - } |
|
846 | - } |
|
847 | - |
|
848 | - return $appList; |
|
849 | - } |
|
850 | - |
|
851 | - /** |
|
852 | - * Returns the internal app ID or false |
|
853 | - * @param string $ocsID |
|
854 | - * @return string|false |
|
855 | - */ |
|
856 | - public static function getInternalAppIdByOcs($ocsID) { |
|
857 | - if(is_numeric($ocsID)) { |
|
858 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
859 | - if(array_search($ocsID, $idArray)) { |
|
860 | - return array_search($ocsID, $idArray); |
|
861 | - } |
|
862 | - } |
|
863 | - return false; |
|
864 | - } |
|
865 | - |
|
866 | - public static function shouldUpgrade($app) { |
|
867 | - $versions = self::getAppVersions(); |
|
868 | - $currentVersion = OC_App::getAppVersion($app); |
|
869 | - if ($currentVersion && isset($versions[$app])) { |
|
870 | - $installedVersion = $versions[$app]; |
|
871 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
872 | - return true; |
|
873 | - } |
|
874 | - } |
|
875 | - return false; |
|
876 | - } |
|
877 | - |
|
878 | - /** |
|
879 | - * Adjust the number of version parts of $version1 to match |
|
880 | - * the number of version parts of $version2. |
|
881 | - * |
|
882 | - * @param string $version1 version to adjust |
|
883 | - * @param string $version2 version to take the number of parts from |
|
884 | - * @return string shortened $version1 |
|
885 | - */ |
|
886 | - private static function adjustVersionParts($version1, $version2) { |
|
887 | - $version1 = explode('.', $version1); |
|
888 | - $version2 = explode('.', $version2); |
|
889 | - // reduce $version1 to match the number of parts in $version2 |
|
890 | - while (count($version1) > count($version2)) { |
|
891 | - array_pop($version1); |
|
892 | - } |
|
893 | - // if $version1 does not have enough parts, add some |
|
894 | - while (count($version1) < count($version2)) { |
|
895 | - $version1[] = '0'; |
|
896 | - } |
|
897 | - return implode('.', $version1); |
|
898 | - } |
|
899 | - |
|
900 | - /** |
|
901 | - * Check whether the current ownCloud version matches the given |
|
902 | - * application's version requirements. |
|
903 | - * |
|
904 | - * The comparison is made based on the number of parts that the |
|
905 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
906 | - * app info version is expecting version 6.0, the comparison is |
|
907 | - * made on the first two parts of the ownCloud version. |
|
908 | - * This means that it's possible to specify "requiremin" => 6 |
|
909 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
910 | - * |
|
911 | - * @param string $ocVersion ownCloud version to check against |
|
912 | - * @param array $appInfo app info (from xml) |
|
913 | - * |
|
914 | - * @return boolean true if compatible, otherwise false |
|
915 | - */ |
|
916 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
917 | - $requireMin = ''; |
|
918 | - $requireMax = ''; |
|
919 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
920 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
921 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
922 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
923 | - } else if (isset($appInfo['requiremin'])) { |
|
924 | - $requireMin = $appInfo['requiremin']; |
|
925 | - } else if (isset($appInfo['require'])) { |
|
926 | - $requireMin = $appInfo['require']; |
|
927 | - } |
|
928 | - |
|
929 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
930 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
931 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
932 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
933 | - } else if (isset($appInfo['requiremax'])) { |
|
934 | - $requireMax = $appInfo['requiremax']; |
|
935 | - } |
|
936 | - |
|
937 | - if (is_array($ocVersion)) { |
|
938 | - $ocVersion = implode('.', $ocVersion); |
|
939 | - } |
|
940 | - |
|
941 | - if (!empty($requireMin) |
|
942 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
943 | - ) { |
|
944 | - |
|
945 | - return false; |
|
946 | - } |
|
947 | - |
|
948 | - if (!empty($requireMax) |
|
949 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
950 | - ) { |
|
951 | - return false; |
|
952 | - } |
|
953 | - |
|
954 | - return true; |
|
955 | - } |
|
956 | - |
|
957 | - /** |
|
958 | - * get the installed version of all apps |
|
959 | - */ |
|
960 | - public static function getAppVersions() { |
|
961 | - static $versions; |
|
962 | - |
|
963 | - if(!$versions) { |
|
964 | - $appConfig = \OC::$server->getAppConfig(); |
|
965 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
966 | - } |
|
967 | - return $versions; |
|
968 | - } |
|
969 | - |
|
970 | - /** |
|
971 | - * @param string $app |
|
972 | - * @param \OCP\IConfig $config |
|
973 | - * @param \OCP\IL10N $l |
|
974 | - * @return bool |
|
975 | - * |
|
976 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
977 | - * @throws Exception if no app-name was specified |
|
978 | - */ |
|
979 | - public function installApp($app, |
|
980 | - \OCP\IConfig $config, |
|
981 | - \OCP\IL10N $l) { |
|
982 | - if ($app !== false) { |
|
983 | - // check if the app is compatible with this version of ownCloud |
|
984 | - $info = self::getAppInfo($app); |
|
985 | - if(!is_array($info)) { |
|
986 | - throw new \Exception( |
|
987 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
988 | - [$info['name']] |
|
989 | - ) |
|
990 | - ); |
|
991 | - } |
|
992 | - |
|
993 | - $version = \OCP\Util::getVersion(); |
|
994 | - if (!self::isAppCompatible($version, $info)) { |
|
995 | - throw new \Exception( |
|
996 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
997 | - array($info['name']) |
|
998 | - ) |
|
999 | - ); |
|
1000 | - } |
|
1001 | - |
|
1002 | - // check for required dependencies |
|
1003 | - self::checkAppDependencies($config, $l, $info); |
|
1004 | - |
|
1005 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1006 | - if (isset($appData['id'])) { |
|
1007 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1008 | - } |
|
1009 | - |
|
1010 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1011 | - $appPath = self::getAppPath($app); |
|
1012 | - self::registerAutoloading($app, $appPath); |
|
1013 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1014 | - } |
|
1015 | - |
|
1016 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1017 | - } else { |
|
1018 | - if(empty($appName) ) { |
|
1019 | - throw new \Exception($l->t("No app name specified")); |
|
1020 | - } else { |
|
1021 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - |
|
1025 | - return $app; |
|
1026 | - } |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * update the database for the app and call the update script |
|
1030 | - * |
|
1031 | - * @param string $appId |
|
1032 | - * @return bool |
|
1033 | - */ |
|
1034 | - public static function updateApp($appId) { |
|
1035 | - $appPath = self::getAppPath($appId); |
|
1036 | - if($appPath === false) { |
|
1037 | - return false; |
|
1038 | - } |
|
1039 | - self::registerAutoloading($appId, $appPath); |
|
1040 | - |
|
1041 | - $appData = self::getAppInfo($appId); |
|
1042 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1043 | - |
|
1044 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1045 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1046 | - } else { |
|
1047 | - $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
1048 | - $ms->migrate(); |
|
1049 | - } |
|
1050 | - |
|
1051 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1052 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1053 | - unset(self::$appVersion[$appId]); |
|
1054 | - |
|
1055 | - // run upgrade code |
|
1056 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1057 | - self::loadApp($appId); |
|
1058 | - include $appPath . '/appinfo/update.php'; |
|
1059 | - } |
|
1060 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1061 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1062 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1063 | - } |
|
1064 | - |
|
1065 | - //set remote/public handlers |
|
1066 | - if (array_key_exists('ocsid', $appData)) { |
|
1067 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1068 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1069 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1070 | - } |
|
1071 | - foreach ($appData['remote'] as $name => $path) { |
|
1072 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1073 | - } |
|
1074 | - foreach ($appData['public'] as $name => $path) { |
|
1075 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1076 | - } |
|
1077 | - |
|
1078 | - self::setAppTypes($appId); |
|
1079 | - |
|
1080 | - $version = \OC_App::getAppVersion($appId); |
|
1081 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1082 | - |
|
1083 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1084 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1085 | - )); |
|
1086 | - |
|
1087 | - return true; |
|
1088 | - } |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * @param string $appId |
|
1092 | - * @param string[] $steps |
|
1093 | - * @throws \OC\NeedsUpdateException |
|
1094 | - */ |
|
1095 | - public static function executeRepairSteps($appId, array $steps) { |
|
1096 | - if (empty($steps)) { |
|
1097 | - return; |
|
1098 | - } |
|
1099 | - // load the app |
|
1100 | - self::loadApp($appId); |
|
1101 | - |
|
1102 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1103 | - |
|
1104 | - // load the steps |
|
1105 | - $r = new Repair([], $dispatcher); |
|
1106 | - foreach ($steps as $step) { |
|
1107 | - try { |
|
1108 | - $r->addStep($step); |
|
1109 | - } catch (Exception $ex) { |
|
1110 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1111 | - \OC::$server->getLogger()->logException($ex); |
|
1112 | - } |
|
1113 | - } |
|
1114 | - // run the steps |
|
1115 | - $r->run(); |
|
1116 | - } |
|
1117 | - |
|
1118 | - public static function setupBackgroundJobs(array $jobs) { |
|
1119 | - $queue = \OC::$server->getJobList(); |
|
1120 | - foreach ($jobs as $job) { |
|
1121 | - $queue->add($job); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * @param string $appId |
|
1127 | - * @param string[] $steps |
|
1128 | - */ |
|
1129 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1130 | - $queue = \OC::$server->getJobList(); |
|
1131 | - foreach ($steps as $step) { |
|
1132 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1133 | - 'app' => $appId, |
|
1134 | - 'step' => $step]); |
|
1135 | - } |
|
1136 | - } |
|
1137 | - |
|
1138 | - /** |
|
1139 | - * @param string $appId |
|
1140 | - * @return \OC\Files\View|false |
|
1141 | - */ |
|
1142 | - public static function getStorage($appId) { |
|
1143 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
1144 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1145 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1146 | - if (!$view->file_exists($appId)) { |
|
1147 | - $view->mkdir($appId); |
|
1148 | - } |
|
1149 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1150 | - } else { |
|
1151 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1152 | - return false; |
|
1153 | - } |
|
1154 | - } else { |
|
1155 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1156 | - return false; |
|
1157 | - } |
|
1158 | - } |
|
1159 | - |
|
1160 | - protected static function findBestL10NOption($options, $lang) { |
|
1161 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1162 | - |
|
1163 | - $lang = strtolower($lang); |
|
1164 | - $similarLang = $lang; |
|
1165 | - if (strpos($similarLang, '_')) { |
|
1166 | - // For "de_DE" we want to find "de" and the other way around |
|
1167 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1168 | - } |
|
1169 | - |
|
1170 | - foreach ($options as $option) { |
|
1171 | - if (is_array($option)) { |
|
1172 | - if ($fallback === false) { |
|
1173 | - $fallback = $option['@value']; |
|
1174 | - } |
|
1175 | - |
|
1176 | - if (!isset($option['@attributes']['lang'])) { |
|
1177 | - continue; |
|
1178 | - } |
|
1179 | - |
|
1180 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1181 | - if ($attributeLang === $lang) { |
|
1182 | - return $option['@value']; |
|
1183 | - } |
|
1184 | - |
|
1185 | - if ($attributeLang === $similarLang) { |
|
1186 | - $similarLangFallback = $option['@value']; |
|
1187 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1188 | - if ($similarLangFallback === false) { |
|
1189 | - $similarLangFallback = $option['@value']; |
|
1190 | - } |
|
1191 | - } |
|
1192 | - } else { |
|
1193 | - $englishFallback = $option; |
|
1194 | - } |
|
1195 | - } |
|
1196 | - |
|
1197 | - if ($similarLangFallback !== false) { |
|
1198 | - return $similarLangFallback; |
|
1199 | - } else if ($englishFallback !== false) { |
|
1200 | - return $englishFallback; |
|
1201 | - } |
|
1202 | - return (string) $fallback; |
|
1203 | - } |
|
1204 | - |
|
1205 | - /** |
|
1206 | - * parses the app data array and enhanced the 'description' value |
|
1207 | - * |
|
1208 | - * @param array $data the app data |
|
1209 | - * @param string $lang |
|
1210 | - * @return array improved app data |
|
1211 | - */ |
|
1212 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1213 | - |
|
1214 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1215 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1216 | - } |
|
1217 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1218 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1219 | - } |
|
1220 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1221 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1222 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1223 | - $data['description'] = trim($data['description']); |
|
1224 | - } else { |
|
1225 | - $data['description'] = ''; |
|
1226 | - } |
|
1227 | - |
|
1228 | - return $data; |
|
1229 | - } |
|
1230 | - |
|
1231 | - /** |
|
1232 | - * @param \OCP\IConfig $config |
|
1233 | - * @param \OCP\IL10N $l |
|
1234 | - * @param array $info |
|
1235 | - * @throws \Exception |
|
1236 | - */ |
|
1237 | - public static function checkAppDependencies($config, $l, $info) { |
|
1238 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1239 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1240 | - if (!empty($missing)) { |
|
1241 | - $missingMsg = implode(PHP_EOL, $missing); |
|
1242 | - throw new \Exception( |
|
1243 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1244 | - [$info['name'], $missingMsg] |
|
1245 | - ) |
|
1246 | - ); |
|
1247 | - } |
|
1248 | - } |
|
64 | + static private $appVersion = []; |
|
65 | + static private $adminForms = array(); |
|
66 | + static private $personalForms = array(); |
|
67 | + static private $appInfo = array(); |
|
68 | + static private $appTypes = array(); |
|
69 | + static private $loadedApps = array(); |
|
70 | + static private $altLogin = array(); |
|
71 | + static private $alreadyRegistered = []; |
|
72 | + const officialApp = 200; |
|
73 | + |
|
74 | + /** |
|
75 | + * clean the appId |
|
76 | + * |
|
77 | + * @param string|boolean $app AppId that needs to be cleaned |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function cleanAppId($app) { |
|
81 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check if an app is loaded |
|
86 | + * |
|
87 | + * @param string $app |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public static function isAppLoaded($app) { |
|
91 | + return in_array($app, self::$loadedApps, true); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * loads all apps |
|
96 | + * |
|
97 | + * @param string[] | string | null $types |
|
98 | + * @return bool |
|
99 | + * |
|
100 | + * This function walks through the ownCloud directory and loads all apps |
|
101 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | + * exists. |
|
103 | + * |
|
104 | + * if $types is set, only apps of those types will be loaded |
|
105 | + */ |
|
106 | + public static function loadApps($types = null) { |
|
107 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + // Load the enabled apps here |
|
111 | + $apps = self::getEnabledApps(); |
|
112 | + |
|
113 | + // Add each apps' folder as allowed class path |
|
114 | + foreach($apps as $app) { |
|
115 | + $path = self::getAppPath($app); |
|
116 | + if($path !== false) { |
|
117 | + self::registerAutoloading($app, $path); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + // prevent app.php from printing output |
|
122 | + ob_start(); |
|
123 | + foreach ($apps as $app) { |
|
124 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | + self::loadApp($app); |
|
126 | + } |
|
127 | + } |
|
128 | + ob_end_clean(); |
|
129 | + |
|
130 | + return true; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * load a single app |
|
135 | + * |
|
136 | + * @param string $app |
|
137 | + */ |
|
138 | + public static function loadApp($app) { |
|
139 | + self::$loadedApps[] = $app; |
|
140 | + $appPath = self::getAppPath($app); |
|
141 | + if($appPath === false) { |
|
142 | + return; |
|
143 | + } |
|
144 | + |
|
145 | + // in case someone calls loadApp() directly |
|
146 | + self::registerAutoloading($app, $appPath); |
|
147 | + |
|
148 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | + self::requireAppFile($app); |
|
151 | + if (self::isType($app, array('authentication'))) { |
|
152 | + // since authentication apps affect the "is app enabled for group" check, |
|
153 | + // the enabled apps cache needs to be cleared to make sure that the |
|
154 | + // next time getEnableApps() is called it will also include apps that were |
|
155 | + // enabled for groups |
|
156 | + self::$enabledAppsCache = array(); |
|
157 | + } |
|
158 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
159 | + } |
|
160 | + |
|
161 | + $info = self::getAppInfo($app); |
|
162 | + if (!empty($info['activity']['filters'])) { |
|
163 | + foreach ($info['activity']['filters'] as $filter) { |
|
164 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
165 | + } |
|
166 | + } |
|
167 | + if (!empty($info['activity']['settings'])) { |
|
168 | + foreach ($info['activity']['settings'] as $setting) { |
|
169 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
170 | + } |
|
171 | + } |
|
172 | + if (!empty($info['activity']['providers'])) { |
|
173 | + foreach ($info['activity']['providers'] as $provider) { |
|
174 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
175 | + } |
|
176 | + } |
|
177 | + if (!empty($info['collaboration']['collaborators']['searchPlugins'])) { |
|
178 | + foreach ($info['collaboration']['collaborators']['searchPlugins'] as $plugin) { |
|
179 | + \OC::$server->getCollaboratorSearch()->registerPlugin($plugin); |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @internal |
|
186 | + * @param string $app |
|
187 | + * @param string $path |
|
188 | + */ |
|
189 | + public static function registerAutoloading($app, $path) { |
|
190 | + $key = $app . '-' . $path; |
|
191 | + if(isset(self::$alreadyRegistered[$key])) { |
|
192 | + return; |
|
193 | + } |
|
194 | + self::$alreadyRegistered[$key] = true; |
|
195 | + // Register on PSR-4 composer autoloader |
|
196 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
197 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
198 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
199 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
200 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
201 | + } |
|
202 | + |
|
203 | + // Register on legacy autoloader |
|
204 | + \OC::$loader->addValidRoot($path); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Load app.php from the given app |
|
209 | + * |
|
210 | + * @param string $app app name |
|
211 | + */ |
|
212 | + private static function requireAppFile($app) { |
|
213 | + try { |
|
214 | + // encapsulated here to avoid variable scope conflicts |
|
215 | + require_once $app . '/appinfo/app.php'; |
|
216 | + } catch (Error $ex) { |
|
217 | + \OC::$server->getLogger()->logException($ex); |
|
218 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
219 | + if (!in_array($app, $blacklist)) { |
|
220 | + self::disable($app); |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * check if an app is of a specific type |
|
227 | + * |
|
228 | + * @param string $app |
|
229 | + * @param string|array $types |
|
230 | + * @return bool |
|
231 | + */ |
|
232 | + public static function isType($app, $types) { |
|
233 | + if (is_string($types)) { |
|
234 | + $types = array($types); |
|
235 | + } |
|
236 | + $appTypes = self::getAppTypes($app); |
|
237 | + foreach ($types as $type) { |
|
238 | + if (array_search($type, $appTypes) !== false) { |
|
239 | + return true; |
|
240 | + } |
|
241 | + } |
|
242 | + return false; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * get the types of an app |
|
247 | + * |
|
248 | + * @param string $app |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + private static function getAppTypes($app) { |
|
252 | + //load the cache |
|
253 | + if (count(self::$appTypes) == 0) { |
|
254 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
255 | + } |
|
256 | + |
|
257 | + if (isset(self::$appTypes[$app])) { |
|
258 | + return explode(',', self::$appTypes[$app]); |
|
259 | + } else { |
|
260 | + return array(); |
|
261 | + } |
|
262 | + } |
|
263 | + |
|
264 | + /** |
|
265 | + * read app types from info.xml and cache them in the database |
|
266 | + */ |
|
267 | + public static function setAppTypes($app) { |
|
268 | + $appData = self::getAppInfo($app); |
|
269 | + if(!is_array($appData)) { |
|
270 | + return; |
|
271 | + } |
|
272 | + |
|
273 | + if (isset($appData['types'])) { |
|
274 | + $appTypes = implode(',', $appData['types']); |
|
275 | + } else { |
|
276 | + $appTypes = ''; |
|
277 | + $appData['types'] = []; |
|
278 | + } |
|
279 | + |
|
280 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
281 | + |
|
282 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
283 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
284 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
285 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * get all enabled apps |
|
292 | + */ |
|
293 | + protected static $enabledAppsCache = array(); |
|
294 | + |
|
295 | + /** |
|
296 | + * Returns apps enabled for the current user. |
|
297 | + * |
|
298 | + * @param bool $forceRefresh whether to refresh the cache |
|
299 | + * @param bool $all whether to return apps for all users, not only the |
|
300 | + * currently logged in one |
|
301 | + * @return string[] |
|
302 | + */ |
|
303 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
304 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
305 | + return array(); |
|
306 | + } |
|
307 | + // in incognito mode or when logged out, $user will be false, |
|
308 | + // which is also the case during an upgrade |
|
309 | + $appManager = \OC::$server->getAppManager(); |
|
310 | + if ($all) { |
|
311 | + $user = null; |
|
312 | + } else { |
|
313 | + $user = \OC::$server->getUserSession()->getUser(); |
|
314 | + } |
|
315 | + |
|
316 | + if (is_null($user)) { |
|
317 | + $apps = $appManager->getInstalledApps(); |
|
318 | + } else { |
|
319 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
320 | + } |
|
321 | + $apps = array_filter($apps, function ($app) { |
|
322 | + return $app !== 'files';//we add this manually |
|
323 | + }); |
|
324 | + sort($apps); |
|
325 | + array_unshift($apps, 'files'); |
|
326 | + return $apps; |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * checks whether or not an app is enabled |
|
331 | + * |
|
332 | + * @param string $app app |
|
333 | + * @return bool |
|
334 | + * |
|
335 | + * This function checks whether or not an app is enabled. |
|
336 | + */ |
|
337 | + public static function isEnabled($app) { |
|
338 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * enables an app |
|
343 | + * |
|
344 | + * @param string $appId |
|
345 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
346 | + * @throws \Exception |
|
347 | + * @return void |
|
348 | + * |
|
349 | + * This function set an app as enabled in appconfig. |
|
350 | + */ |
|
351 | + public function enable($appId, |
|
352 | + $groups = null) { |
|
353 | + self::$enabledAppsCache = []; // flush |
|
354 | + |
|
355 | + // Check if app is already downloaded |
|
356 | + $installer = new Installer( |
|
357 | + \OC::$server->getAppFetcher(), |
|
358 | + \OC::$server->getHTTPClientService(), |
|
359 | + \OC::$server->getTempManager(), |
|
360 | + \OC::$server->getLogger(), |
|
361 | + \OC::$server->getConfig() |
|
362 | + ); |
|
363 | + $isDownloaded = $installer->isDownloaded($appId); |
|
364 | + |
|
365 | + if(!$isDownloaded) { |
|
366 | + $installer->downloadApp($appId); |
|
367 | + } |
|
368 | + |
|
369 | + $installer->installApp($appId); |
|
370 | + |
|
371 | + $appManager = \OC::$server->getAppManager(); |
|
372 | + if (!is_null($groups)) { |
|
373 | + $groupManager = \OC::$server->getGroupManager(); |
|
374 | + $groupsList = []; |
|
375 | + foreach ($groups as $group) { |
|
376 | + $groupItem = $groupManager->get($group); |
|
377 | + if ($groupItem instanceof \OCP\IGroup) { |
|
378 | + $groupsList[] = $groupManager->get($group); |
|
379 | + } |
|
380 | + } |
|
381 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
382 | + } else { |
|
383 | + $appManager->enableApp($appId); |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * @param string $app |
|
389 | + * @return bool |
|
390 | + */ |
|
391 | + public static function removeApp($app) { |
|
392 | + if (\OC::$server->getAppManager()->isShipped($app)) { |
|
393 | + return false; |
|
394 | + } |
|
395 | + |
|
396 | + $installer = new Installer( |
|
397 | + \OC::$server->getAppFetcher(), |
|
398 | + \OC::$server->getHTTPClientService(), |
|
399 | + \OC::$server->getTempManager(), |
|
400 | + \OC::$server->getLogger(), |
|
401 | + \OC::$server->getConfig() |
|
402 | + ); |
|
403 | + return $installer->removeApp($app); |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * This function set an app as disabled in appconfig. |
|
408 | + * |
|
409 | + * @param string $app app |
|
410 | + * @throws Exception |
|
411 | + */ |
|
412 | + public static function disable($app) { |
|
413 | + // flush |
|
414 | + self::$enabledAppsCache = array(); |
|
415 | + |
|
416 | + // run uninstall steps |
|
417 | + $appData = OC_App::getAppInfo($app); |
|
418 | + if (!is_null($appData)) { |
|
419 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
420 | + } |
|
421 | + |
|
422 | + // emit disable hook - needed anymore ? |
|
423 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
424 | + |
|
425 | + // finally disable it |
|
426 | + $appManager = \OC::$server->getAppManager(); |
|
427 | + $appManager->disableApp($app); |
|
428 | + } |
|
429 | + |
|
430 | + // This is private as well. It simply works, so don't ask for more details |
|
431 | + private static function proceedNavigation($list) { |
|
432 | + usort($list, function($a, $b) { |
|
433 | + if (isset($a['order']) && isset($b['order'])) { |
|
434 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
435 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
436 | + return isset($a['order']) ? -1 : 1; |
|
437 | + } else { |
|
438 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
439 | + } |
|
440 | + }); |
|
441 | + |
|
442 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
443 | + foreach ($list as $index => &$navEntry) { |
|
444 | + if ($navEntry['id'] == $activeApp) { |
|
445 | + $navEntry['active'] = true; |
|
446 | + } else { |
|
447 | + $navEntry['active'] = false; |
|
448 | + } |
|
449 | + } |
|
450 | + unset($navEntry); |
|
451 | + |
|
452 | + return $list; |
|
453 | + } |
|
454 | + |
|
455 | + /** |
|
456 | + * Get the path where to install apps |
|
457 | + * |
|
458 | + * @return string|false |
|
459 | + */ |
|
460 | + public static function getInstallPath() { |
|
461 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
462 | + return false; |
|
463 | + } |
|
464 | + |
|
465 | + foreach (OC::$APPSROOTS as $dir) { |
|
466 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
467 | + return $dir['path']; |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
472 | + return null; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * search for an app in all app-directories |
|
478 | + * |
|
479 | + * @param string $appId |
|
480 | + * @return false|string |
|
481 | + */ |
|
482 | + public static function findAppInDirectories($appId) { |
|
483 | + $sanitizedAppId = self::cleanAppId($appId); |
|
484 | + if($sanitizedAppId !== $appId) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + static $app_dir = array(); |
|
488 | + |
|
489 | + if (isset($app_dir[$appId])) { |
|
490 | + return $app_dir[$appId]; |
|
491 | + } |
|
492 | + |
|
493 | + $possibleApps = array(); |
|
494 | + foreach (OC::$APPSROOTS as $dir) { |
|
495 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
496 | + $possibleApps[] = $dir; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + if (empty($possibleApps)) { |
|
501 | + return false; |
|
502 | + } elseif (count($possibleApps) === 1) { |
|
503 | + $dir = array_shift($possibleApps); |
|
504 | + $app_dir[$appId] = $dir; |
|
505 | + return $dir; |
|
506 | + } else { |
|
507 | + $versionToLoad = array(); |
|
508 | + foreach ($possibleApps as $possibleApp) { |
|
509 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
510 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
511 | + $versionToLoad = array( |
|
512 | + 'dir' => $possibleApp, |
|
513 | + 'version' => $version, |
|
514 | + ); |
|
515 | + } |
|
516 | + } |
|
517 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
518 | + return $versionToLoad['dir']; |
|
519 | + //TODO - write test |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Get the directory for the given app. |
|
525 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
526 | + * |
|
527 | + * @param string $appId |
|
528 | + * @return string|false |
|
529 | + */ |
|
530 | + public static function getAppPath($appId) { |
|
531 | + if ($appId === null || trim($appId) === '') { |
|
532 | + return false; |
|
533 | + } |
|
534 | + |
|
535 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
536 | + return $dir['path'] . '/' . $appId; |
|
537 | + } |
|
538 | + return false; |
|
539 | + } |
|
540 | + |
|
541 | + /** |
|
542 | + * Get the path for the given app on the access |
|
543 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
544 | + * |
|
545 | + * @param string $appId |
|
546 | + * @return string|false |
|
547 | + */ |
|
548 | + public static function getAppWebPath($appId) { |
|
549 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
550 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
551 | + } |
|
552 | + return false; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * get the last version of the app from appinfo/info.xml |
|
557 | + * |
|
558 | + * @param string $appId |
|
559 | + * @param bool $useCache |
|
560 | + * @return string |
|
561 | + */ |
|
562 | + public static function getAppVersion($appId, $useCache = true) { |
|
563 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
564 | + return self::$appVersion[$appId]; |
|
565 | + } |
|
566 | + |
|
567 | + $file = self::getAppPath($appId); |
|
568 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
569 | + return self::$appVersion[$appId]; |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * get app's version based on it's path |
|
574 | + * |
|
575 | + * @param string $path |
|
576 | + * @return string |
|
577 | + */ |
|
578 | + public static function getAppVersionByPath($path) { |
|
579 | + $infoFile = $path . '/appinfo/info.xml'; |
|
580 | + $appData = self::getAppInfo($infoFile, true); |
|
581 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Read all app metadata from the info.xml file |
|
587 | + * |
|
588 | + * @param string $appId id of the app or the path of the info.xml file |
|
589 | + * @param bool $path |
|
590 | + * @param string $lang |
|
591 | + * @return array|null |
|
592 | + * @note all data is read from info.xml, not just pre-defined fields |
|
593 | + */ |
|
594 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
595 | + if ($path) { |
|
596 | + $file = $appId; |
|
597 | + } else { |
|
598 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
599 | + return self::$appInfo[$appId]; |
|
600 | + } |
|
601 | + $appPath = self::getAppPath($appId); |
|
602 | + if($appPath === false) { |
|
603 | + return null; |
|
604 | + } |
|
605 | + $file = $appPath . '/appinfo/info.xml'; |
|
606 | + } |
|
607 | + |
|
608 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
609 | + $data = $parser->parse($file); |
|
610 | + |
|
611 | + if (is_array($data)) { |
|
612 | + $data = OC_App::parseAppInfo($data, $lang); |
|
613 | + } |
|
614 | + if(isset($data['ocsid'])) { |
|
615 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
616 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
617 | + $data['ocsid'] = $storedId; |
|
618 | + } |
|
619 | + } |
|
620 | + |
|
621 | + if ($lang === null) { |
|
622 | + self::$appInfo[$appId] = $data; |
|
623 | + } |
|
624 | + |
|
625 | + return $data; |
|
626 | + } |
|
627 | + |
|
628 | + /** |
|
629 | + * Returns the navigation |
|
630 | + * |
|
631 | + * @return array |
|
632 | + * |
|
633 | + * This function returns an array containing all entries added. The |
|
634 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
635 | + * given for each app the following keys exist: |
|
636 | + * - active: boolean, signals if the user is on this navigation entry |
|
637 | + */ |
|
638 | + public static function getNavigation() { |
|
639 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
640 | + return self::proceedNavigation($entries); |
|
641 | + } |
|
642 | + |
|
643 | + /** |
|
644 | + * Returns the Settings Navigation |
|
645 | + * |
|
646 | + * @return string[] |
|
647 | + * |
|
648 | + * This function returns an array containing all settings pages added. The |
|
649 | + * entries are sorted by the key 'order' ascending. |
|
650 | + */ |
|
651 | + public static function getSettingsNavigation() { |
|
652 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
653 | + return self::proceedNavigation($entries); |
|
654 | + } |
|
655 | + |
|
656 | + /** |
|
657 | + * get the id of loaded app |
|
658 | + * |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public static function getCurrentApp() { |
|
662 | + $request = \OC::$server->getRequest(); |
|
663 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
664 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
665 | + if (empty($topFolder)) { |
|
666 | + $path_info = $request->getPathInfo(); |
|
667 | + if ($path_info) { |
|
668 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
669 | + } |
|
670 | + } |
|
671 | + if ($topFolder == 'apps') { |
|
672 | + $length = strlen($topFolder); |
|
673 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
674 | + } else { |
|
675 | + return $topFolder; |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * @param string $type |
|
681 | + * @return array |
|
682 | + */ |
|
683 | + public static function getForms($type) { |
|
684 | + $forms = array(); |
|
685 | + switch ($type) { |
|
686 | + case 'admin': |
|
687 | + $source = self::$adminForms; |
|
688 | + break; |
|
689 | + case 'personal': |
|
690 | + $source = self::$personalForms; |
|
691 | + break; |
|
692 | + default: |
|
693 | + return array(); |
|
694 | + } |
|
695 | + foreach ($source as $form) { |
|
696 | + $forms[] = include $form; |
|
697 | + } |
|
698 | + return $forms; |
|
699 | + } |
|
700 | + |
|
701 | + /** |
|
702 | + * register an admin form to be shown |
|
703 | + * |
|
704 | + * @param string $app |
|
705 | + * @param string $page |
|
706 | + */ |
|
707 | + public static function registerAdmin($app, $page) { |
|
708 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * register a personal form to be shown |
|
713 | + * @param string $app |
|
714 | + * @param string $page |
|
715 | + */ |
|
716 | + public static function registerPersonal($app, $page) { |
|
717 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
718 | + } |
|
719 | + |
|
720 | + /** |
|
721 | + * @param array $entry |
|
722 | + */ |
|
723 | + public static function registerLogIn(array $entry) { |
|
724 | + self::$altLogin[] = $entry; |
|
725 | + } |
|
726 | + |
|
727 | + /** |
|
728 | + * @return array |
|
729 | + */ |
|
730 | + public static function getAlternativeLogIns() { |
|
731 | + return self::$altLogin; |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * get a list of all apps in the apps folder |
|
736 | + * |
|
737 | + * @return array an array of app names (string IDs) |
|
738 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
739 | + */ |
|
740 | + public static function getAllApps() { |
|
741 | + |
|
742 | + $apps = array(); |
|
743 | + |
|
744 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
745 | + if (!is_readable($apps_dir['path'])) { |
|
746 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
747 | + continue; |
|
748 | + } |
|
749 | + $dh = opendir($apps_dir['path']); |
|
750 | + |
|
751 | + if (is_resource($dh)) { |
|
752 | + while (($file = readdir($dh)) !== false) { |
|
753 | + |
|
754 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
755 | + |
|
756 | + $apps[] = $file; |
|
757 | + } |
|
758 | + } |
|
759 | + } |
|
760 | + } |
|
761 | + |
|
762 | + return $apps; |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * List all apps, this is used in apps.php |
|
767 | + * |
|
768 | + * @return array |
|
769 | + */ |
|
770 | + public function listAllApps() { |
|
771 | + $installedApps = OC_App::getAllApps(); |
|
772 | + |
|
773 | + $appManager = \OC::$server->getAppManager(); |
|
774 | + //we don't want to show configuration for these |
|
775 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
776 | + $appList = array(); |
|
777 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
778 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
779 | + |
|
780 | + foreach ($installedApps as $app) { |
|
781 | + if (array_search($app, $blacklist) === false) { |
|
782 | + |
|
783 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
784 | + if (!is_array($info)) { |
|
785 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
786 | + continue; |
|
787 | + } |
|
788 | + |
|
789 | + if (!isset($info['name'])) { |
|
790 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
791 | + continue; |
|
792 | + } |
|
793 | + |
|
794 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
795 | + $info['groups'] = null; |
|
796 | + if ($enabled === 'yes') { |
|
797 | + $active = true; |
|
798 | + } else if ($enabled === 'no') { |
|
799 | + $active = false; |
|
800 | + } else { |
|
801 | + $active = true; |
|
802 | + $info['groups'] = $enabled; |
|
803 | + } |
|
804 | + |
|
805 | + $info['active'] = $active; |
|
806 | + |
|
807 | + if ($appManager->isShipped($app)) { |
|
808 | + $info['internal'] = true; |
|
809 | + $info['level'] = self::officialApp; |
|
810 | + $info['removable'] = false; |
|
811 | + } else { |
|
812 | + $info['internal'] = false; |
|
813 | + $info['removable'] = true; |
|
814 | + } |
|
815 | + |
|
816 | + $appPath = self::getAppPath($app); |
|
817 | + if($appPath !== false) { |
|
818 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
819 | + if (file_exists($appIcon)) { |
|
820 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
821 | + $info['previewAsIcon'] = true; |
|
822 | + } else { |
|
823 | + $appIcon = $appPath . '/img/app.svg'; |
|
824 | + if (file_exists($appIcon)) { |
|
825 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
826 | + $info['previewAsIcon'] = true; |
|
827 | + } |
|
828 | + } |
|
829 | + } |
|
830 | + // fix documentation |
|
831 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
832 | + foreach ($info['documentation'] as $key => $url) { |
|
833 | + // If it is not an absolute URL we assume it is a key |
|
834 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
835 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
836 | + $url = $urlGenerator->linkToDocs($url); |
|
837 | + } |
|
838 | + |
|
839 | + $info['documentation'][$key] = $url; |
|
840 | + } |
|
841 | + } |
|
842 | + |
|
843 | + $info['version'] = OC_App::getAppVersion($app); |
|
844 | + $appList[] = $info; |
|
845 | + } |
|
846 | + } |
|
847 | + |
|
848 | + return $appList; |
|
849 | + } |
|
850 | + |
|
851 | + /** |
|
852 | + * Returns the internal app ID or false |
|
853 | + * @param string $ocsID |
|
854 | + * @return string|false |
|
855 | + */ |
|
856 | + public static function getInternalAppIdByOcs($ocsID) { |
|
857 | + if(is_numeric($ocsID)) { |
|
858 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
859 | + if(array_search($ocsID, $idArray)) { |
|
860 | + return array_search($ocsID, $idArray); |
|
861 | + } |
|
862 | + } |
|
863 | + return false; |
|
864 | + } |
|
865 | + |
|
866 | + public static function shouldUpgrade($app) { |
|
867 | + $versions = self::getAppVersions(); |
|
868 | + $currentVersion = OC_App::getAppVersion($app); |
|
869 | + if ($currentVersion && isset($versions[$app])) { |
|
870 | + $installedVersion = $versions[$app]; |
|
871 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
872 | + return true; |
|
873 | + } |
|
874 | + } |
|
875 | + return false; |
|
876 | + } |
|
877 | + |
|
878 | + /** |
|
879 | + * Adjust the number of version parts of $version1 to match |
|
880 | + * the number of version parts of $version2. |
|
881 | + * |
|
882 | + * @param string $version1 version to adjust |
|
883 | + * @param string $version2 version to take the number of parts from |
|
884 | + * @return string shortened $version1 |
|
885 | + */ |
|
886 | + private static function adjustVersionParts($version1, $version2) { |
|
887 | + $version1 = explode('.', $version1); |
|
888 | + $version2 = explode('.', $version2); |
|
889 | + // reduce $version1 to match the number of parts in $version2 |
|
890 | + while (count($version1) > count($version2)) { |
|
891 | + array_pop($version1); |
|
892 | + } |
|
893 | + // if $version1 does not have enough parts, add some |
|
894 | + while (count($version1) < count($version2)) { |
|
895 | + $version1[] = '0'; |
|
896 | + } |
|
897 | + return implode('.', $version1); |
|
898 | + } |
|
899 | + |
|
900 | + /** |
|
901 | + * Check whether the current ownCloud version matches the given |
|
902 | + * application's version requirements. |
|
903 | + * |
|
904 | + * The comparison is made based on the number of parts that the |
|
905 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
906 | + * app info version is expecting version 6.0, the comparison is |
|
907 | + * made on the first two parts of the ownCloud version. |
|
908 | + * This means that it's possible to specify "requiremin" => 6 |
|
909 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
910 | + * |
|
911 | + * @param string $ocVersion ownCloud version to check against |
|
912 | + * @param array $appInfo app info (from xml) |
|
913 | + * |
|
914 | + * @return boolean true if compatible, otherwise false |
|
915 | + */ |
|
916 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
917 | + $requireMin = ''; |
|
918 | + $requireMax = ''; |
|
919 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
920 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
921 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
922 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
923 | + } else if (isset($appInfo['requiremin'])) { |
|
924 | + $requireMin = $appInfo['requiremin']; |
|
925 | + } else if (isset($appInfo['require'])) { |
|
926 | + $requireMin = $appInfo['require']; |
|
927 | + } |
|
928 | + |
|
929 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
930 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
931 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
932 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
933 | + } else if (isset($appInfo['requiremax'])) { |
|
934 | + $requireMax = $appInfo['requiremax']; |
|
935 | + } |
|
936 | + |
|
937 | + if (is_array($ocVersion)) { |
|
938 | + $ocVersion = implode('.', $ocVersion); |
|
939 | + } |
|
940 | + |
|
941 | + if (!empty($requireMin) |
|
942 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
943 | + ) { |
|
944 | + |
|
945 | + return false; |
|
946 | + } |
|
947 | + |
|
948 | + if (!empty($requireMax) |
|
949 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
950 | + ) { |
|
951 | + return false; |
|
952 | + } |
|
953 | + |
|
954 | + return true; |
|
955 | + } |
|
956 | + |
|
957 | + /** |
|
958 | + * get the installed version of all apps |
|
959 | + */ |
|
960 | + public static function getAppVersions() { |
|
961 | + static $versions; |
|
962 | + |
|
963 | + if(!$versions) { |
|
964 | + $appConfig = \OC::$server->getAppConfig(); |
|
965 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
966 | + } |
|
967 | + return $versions; |
|
968 | + } |
|
969 | + |
|
970 | + /** |
|
971 | + * @param string $app |
|
972 | + * @param \OCP\IConfig $config |
|
973 | + * @param \OCP\IL10N $l |
|
974 | + * @return bool |
|
975 | + * |
|
976 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
977 | + * @throws Exception if no app-name was specified |
|
978 | + */ |
|
979 | + public function installApp($app, |
|
980 | + \OCP\IConfig $config, |
|
981 | + \OCP\IL10N $l) { |
|
982 | + if ($app !== false) { |
|
983 | + // check if the app is compatible with this version of ownCloud |
|
984 | + $info = self::getAppInfo($app); |
|
985 | + if(!is_array($info)) { |
|
986 | + throw new \Exception( |
|
987 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
988 | + [$info['name']] |
|
989 | + ) |
|
990 | + ); |
|
991 | + } |
|
992 | + |
|
993 | + $version = \OCP\Util::getVersion(); |
|
994 | + if (!self::isAppCompatible($version, $info)) { |
|
995 | + throw new \Exception( |
|
996 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
997 | + array($info['name']) |
|
998 | + ) |
|
999 | + ); |
|
1000 | + } |
|
1001 | + |
|
1002 | + // check for required dependencies |
|
1003 | + self::checkAppDependencies($config, $l, $info); |
|
1004 | + |
|
1005 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1006 | + if (isset($appData['id'])) { |
|
1007 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1008 | + } |
|
1009 | + |
|
1010 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1011 | + $appPath = self::getAppPath($app); |
|
1012 | + self::registerAutoloading($app, $appPath); |
|
1013 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1014 | + } |
|
1015 | + |
|
1016 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1017 | + } else { |
|
1018 | + if(empty($appName) ) { |
|
1019 | + throw new \Exception($l->t("No app name specified")); |
|
1020 | + } else { |
|
1021 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + |
|
1025 | + return $app; |
|
1026 | + } |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * update the database for the app and call the update script |
|
1030 | + * |
|
1031 | + * @param string $appId |
|
1032 | + * @return bool |
|
1033 | + */ |
|
1034 | + public static function updateApp($appId) { |
|
1035 | + $appPath = self::getAppPath($appId); |
|
1036 | + if($appPath === false) { |
|
1037 | + return false; |
|
1038 | + } |
|
1039 | + self::registerAutoloading($appId, $appPath); |
|
1040 | + |
|
1041 | + $appData = self::getAppInfo($appId); |
|
1042 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1043 | + |
|
1044 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1045 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1046 | + } else { |
|
1047 | + $ms = new MigrationService($appId, \OC::$server->getDatabaseConnection()); |
|
1048 | + $ms->migrate(); |
|
1049 | + } |
|
1050 | + |
|
1051 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1052 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1053 | + unset(self::$appVersion[$appId]); |
|
1054 | + |
|
1055 | + // run upgrade code |
|
1056 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1057 | + self::loadApp($appId); |
|
1058 | + include $appPath . '/appinfo/update.php'; |
|
1059 | + } |
|
1060 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1061 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1062 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1063 | + } |
|
1064 | + |
|
1065 | + //set remote/public handlers |
|
1066 | + if (array_key_exists('ocsid', $appData)) { |
|
1067 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1068 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1069 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1070 | + } |
|
1071 | + foreach ($appData['remote'] as $name => $path) { |
|
1072 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1073 | + } |
|
1074 | + foreach ($appData['public'] as $name => $path) { |
|
1075 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1076 | + } |
|
1077 | + |
|
1078 | + self::setAppTypes($appId); |
|
1079 | + |
|
1080 | + $version = \OC_App::getAppVersion($appId); |
|
1081 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1082 | + |
|
1083 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1084 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1085 | + )); |
|
1086 | + |
|
1087 | + return true; |
|
1088 | + } |
|
1089 | + |
|
1090 | + /** |
|
1091 | + * @param string $appId |
|
1092 | + * @param string[] $steps |
|
1093 | + * @throws \OC\NeedsUpdateException |
|
1094 | + */ |
|
1095 | + public static function executeRepairSteps($appId, array $steps) { |
|
1096 | + if (empty($steps)) { |
|
1097 | + return; |
|
1098 | + } |
|
1099 | + // load the app |
|
1100 | + self::loadApp($appId); |
|
1101 | + |
|
1102 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1103 | + |
|
1104 | + // load the steps |
|
1105 | + $r = new Repair([], $dispatcher); |
|
1106 | + foreach ($steps as $step) { |
|
1107 | + try { |
|
1108 | + $r->addStep($step); |
|
1109 | + } catch (Exception $ex) { |
|
1110 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1111 | + \OC::$server->getLogger()->logException($ex); |
|
1112 | + } |
|
1113 | + } |
|
1114 | + // run the steps |
|
1115 | + $r->run(); |
|
1116 | + } |
|
1117 | + |
|
1118 | + public static function setupBackgroundJobs(array $jobs) { |
|
1119 | + $queue = \OC::$server->getJobList(); |
|
1120 | + foreach ($jobs as $job) { |
|
1121 | + $queue->add($job); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * @param string $appId |
|
1127 | + * @param string[] $steps |
|
1128 | + */ |
|
1129 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1130 | + $queue = \OC::$server->getJobList(); |
|
1131 | + foreach ($steps as $step) { |
|
1132 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1133 | + 'app' => $appId, |
|
1134 | + 'step' => $step]); |
|
1135 | + } |
|
1136 | + } |
|
1137 | + |
|
1138 | + /** |
|
1139 | + * @param string $appId |
|
1140 | + * @return \OC\Files\View|false |
|
1141 | + */ |
|
1142 | + public static function getStorage($appId) { |
|
1143 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
1144 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1145 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1146 | + if (!$view->file_exists($appId)) { |
|
1147 | + $view->mkdir($appId); |
|
1148 | + } |
|
1149 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1150 | + } else { |
|
1151 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1152 | + return false; |
|
1153 | + } |
|
1154 | + } else { |
|
1155 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1156 | + return false; |
|
1157 | + } |
|
1158 | + } |
|
1159 | + |
|
1160 | + protected static function findBestL10NOption($options, $lang) { |
|
1161 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1162 | + |
|
1163 | + $lang = strtolower($lang); |
|
1164 | + $similarLang = $lang; |
|
1165 | + if (strpos($similarLang, '_')) { |
|
1166 | + // For "de_DE" we want to find "de" and the other way around |
|
1167 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1168 | + } |
|
1169 | + |
|
1170 | + foreach ($options as $option) { |
|
1171 | + if (is_array($option)) { |
|
1172 | + if ($fallback === false) { |
|
1173 | + $fallback = $option['@value']; |
|
1174 | + } |
|
1175 | + |
|
1176 | + if (!isset($option['@attributes']['lang'])) { |
|
1177 | + continue; |
|
1178 | + } |
|
1179 | + |
|
1180 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1181 | + if ($attributeLang === $lang) { |
|
1182 | + return $option['@value']; |
|
1183 | + } |
|
1184 | + |
|
1185 | + if ($attributeLang === $similarLang) { |
|
1186 | + $similarLangFallback = $option['@value']; |
|
1187 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1188 | + if ($similarLangFallback === false) { |
|
1189 | + $similarLangFallback = $option['@value']; |
|
1190 | + } |
|
1191 | + } |
|
1192 | + } else { |
|
1193 | + $englishFallback = $option; |
|
1194 | + } |
|
1195 | + } |
|
1196 | + |
|
1197 | + if ($similarLangFallback !== false) { |
|
1198 | + return $similarLangFallback; |
|
1199 | + } else if ($englishFallback !== false) { |
|
1200 | + return $englishFallback; |
|
1201 | + } |
|
1202 | + return (string) $fallback; |
|
1203 | + } |
|
1204 | + |
|
1205 | + /** |
|
1206 | + * parses the app data array and enhanced the 'description' value |
|
1207 | + * |
|
1208 | + * @param array $data the app data |
|
1209 | + * @param string $lang |
|
1210 | + * @return array improved app data |
|
1211 | + */ |
|
1212 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1213 | + |
|
1214 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1215 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1216 | + } |
|
1217 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1218 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1219 | + } |
|
1220 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1221 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1222 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1223 | + $data['description'] = trim($data['description']); |
|
1224 | + } else { |
|
1225 | + $data['description'] = ''; |
|
1226 | + } |
|
1227 | + |
|
1228 | + return $data; |
|
1229 | + } |
|
1230 | + |
|
1231 | + /** |
|
1232 | + * @param \OCP\IConfig $config |
|
1233 | + * @param \OCP\IL10N $l |
|
1234 | + * @param array $info |
|
1235 | + * @throws \Exception |
|
1236 | + */ |
|
1237 | + public static function checkAppDependencies($config, $l, $info) { |
|
1238 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1239 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1240 | + if (!empty($missing)) { |
|
1241 | + $missingMsg = implode(PHP_EOL, $missing); |
|
1242 | + throw new \Exception( |
|
1243 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1244 | + [$info['name'], $missingMsg] |
|
1245 | + ) |
|
1246 | + ); |
|
1247 | + } |
|
1248 | + } |
|
1249 | 1249 | } |