@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | * Get the certificate manager for the user |
1144 | 1144 | * |
1145 | 1145 | * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
1146 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1146 | + * @return null|CertificateManager | null if $uid is null and no user is logged in |
|
1147 | 1147 | */ |
1148 | 1148 | public function getCertificateManager($userId = '') { |
1149 | 1149 | if ($userId === '') { |
@@ -1464,6 +1464,7 @@ discard block |
||
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | /** |
1467 | + * @param string $app |
|
1467 | 1468 | * @return \OCP\Files\IAppData |
1468 | 1469 | */ |
1469 | 1470 | public function getAppDataDir($app) { |
@@ -52,8 +52,6 @@ discard block |
||
52 | 52 | use OC\Command\AsyncBus; |
53 | 53 | use OC\Contacts\ContactsMenu\ActionFactory; |
54 | 54 | use OC\Diagnostics\EventLogger; |
55 | -use OC\Diagnostics\NullEventLogger; |
|
56 | -use OC\Diagnostics\NullQueryLogger; |
|
57 | 55 | use OC\Diagnostics\QueryLogger; |
58 | 56 | use OC\Federation\CloudIdManager; |
59 | 57 | use OC\Files\Config\UserMountCache; |
@@ -98,7 +96,6 @@ discard block |
||
98 | 96 | use OC\Tagging\TagMapper; |
99 | 97 | use OC\Template\SCSSCacher; |
100 | 98 | use OCA\Theming\ThemingDefaults; |
101 | - |
|
102 | 99 | use OCP\App\IAppManager; |
103 | 100 | use OCP\Defaults; |
104 | 101 | use OCA\Theming\Util; |
@@ -126,1648 +126,1648 @@ |
||
126 | 126 | * TODO: hookup all manager classes |
127 | 127 | */ |
128 | 128 | class Server extends ServerContainer implements IServerContainer { |
129 | - /** @var string */ |
|
130 | - private $webRoot; |
|
131 | - |
|
132 | - /** |
|
133 | - * @param string $webRoot |
|
134 | - * @param \OC\Config $config |
|
135 | - */ |
|
136 | - public function __construct($webRoot, \OC\Config $config) { |
|
137 | - parent::__construct(); |
|
138 | - $this->webRoot = $webRoot; |
|
139 | - |
|
140 | - $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
141 | - return $c; |
|
142 | - }); |
|
143 | - |
|
144 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
145 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
146 | - |
|
147 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
152 | - return new PreviewManager( |
|
153 | - $c->getConfig(), |
|
154 | - $c->getRootFolder(), |
|
155 | - $c->getAppDataDir('preview'), |
|
156 | - $c->getEventDispatcher(), |
|
157 | - $c->getSession()->get('user_id') |
|
158 | - ); |
|
159 | - }); |
|
160 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
161 | - |
|
162 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
163 | - return new \OC\Preview\Watcher( |
|
164 | - $c->getAppDataDir('preview') |
|
165 | - ); |
|
166 | - }); |
|
167 | - |
|
168 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
169 | - $view = new View(); |
|
170 | - $util = new Encryption\Util( |
|
171 | - $view, |
|
172 | - $c->getUserManager(), |
|
173 | - $c->getGroupManager(), |
|
174 | - $c->getConfig() |
|
175 | - ); |
|
176 | - return new Encryption\Manager( |
|
177 | - $c->getConfig(), |
|
178 | - $c->getLogger(), |
|
179 | - $c->getL10N('core'), |
|
180 | - new View(), |
|
181 | - $util, |
|
182 | - new ArrayCache() |
|
183 | - ); |
|
184 | - }); |
|
185 | - |
|
186 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
187 | - $util = new Encryption\Util( |
|
188 | - new View(), |
|
189 | - $c->getUserManager(), |
|
190 | - $c->getGroupManager(), |
|
191 | - $c->getConfig() |
|
192 | - ); |
|
193 | - return new Encryption\File( |
|
194 | - $util, |
|
195 | - $c->getRootFolder(), |
|
196 | - $c->getShareManager() |
|
197 | - ); |
|
198 | - }); |
|
199 | - |
|
200 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
201 | - $view = new View(); |
|
202 | - $util = new Encryption\Util( |
|
203 | - $view, |
|
204 | - $c->getUserManager(), |
|
205 | - $c->getGroupManager(), |
|
206 | - $c->getConfig() |
|
207 | - ); |
|
208 | - |
|
209 | - return new Encryption\Keys\Storage($view, $util); |
|
210 | - }); |
|
211 | - $this->registerService('TagMapper', function (Server $c) { |
|
212 | - return new TagMapper($c->getDatabaseConnection()); |
|
213 | - }); |
|
214 | - |
|
215 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
216 | - $tagMapper = $c->query('TagMapper'); |
|
217 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
218 | - }); |
|
219 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
220 | - |
|
221 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
222 | - $config = $c->getConfig(); |
|
223 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
224 | - /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
225 | - $factory = new $factoryClass($this); |
|
226 | - return $factory; |
|
227 | - }); |
|
228 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
229 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
230 | - }); |
|
231 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
232 | - |
|
233 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
234 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
235 | - }); |
|
236 | - $this->registerService('RootFolder', function (Server $c) { |
|
237 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
238 | - $view = new View(); |
|
239 | - $root = new Root( |
|
240 | - $manager, |
|
241 | - $view, |
|
242 | - null, |
|
243 | - $c->getUserMountCache(), |
|
244 | - $this->getLogger(), |
|
245 | - $this->getUserManager() |
|
246 | - ); |
|
247 | - $connector = new HookConnector($root, $view); |
|
248 | - $connector->viewToNode(); |
|
249 | - |
|
250 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
251 | - $previewConnector->connectWatcher(); |
|
252 | - |
|
253 | - return $root; |
|
254 | - }); |
|
255 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
256 | - |
|
257 | - $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
258 | - return new LazyRoot(function() use ($c) { |
|
259 | - return $c->query('RootFolder'); |
|
260 | - }); |
|
261 | - }); |
|
262 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
263 | - |
|
264 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
265 | - $config = $c->getConfig(); |
|
266 | - return new \OC\User\Manager($config); |
|
267 | - }); |
|
268 | - $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
269 | - |
|
270 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
271 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
272 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
273 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
274 | - }); |
|
275 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
276 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
277 | - }); |
|
278 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
279 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
280 | - }); |
|
281 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
282 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
283 | - }); |
|
284 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
285 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
286 | - }); |
|
287 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
288 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
289 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
290 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
291 | - }); |
|
292 | - return $groupManager; |
|
293 | - }); |
|
294 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
295 | - |
|
296 | - $this->registerService(Store::class, function(Server $c) { |
|
297 | - $session = $c->getSession(); |
|
298 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
299 | - $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
300 | - } else { |
|
301 | - $tokenProvider = null; |
|
302 | - } |
|
303 | - $logger = $c->getLogger(); |
|
304 | - return new Store($session, $logger, $tokenProvider); |
|
305 | - }); |
|
306 | - $this->registerAlias(IStore::class, Store::class); |
|
307 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
308 | - $dbConnection = $c->getDatabaseConnection(); |
|
309 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
310 | - }); |
|
311 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
312 | - $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
313 | - $crypto = $c->getCrypto(); |
|
314 | - $config = $c->getConfig(); |
|
315 | - $logger = $c->getLogger(); |
|
316 | - $timeFactory = new TimeFactory(); |
|
317 | - return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
318 | - }); |
|
319 | - $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
320 | - |
|
321 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
322 | - $manager = $c->getUserManager(); |
|
323 | - $session = new \OC\Session\Memory(''); |
|
324 | - $timeFactory = new TimeFactory(); |
|
325 | - // Token providers might require a working database. This code |
|
326 | - // might however be called when ownCloud is not yet setup. |
|
327 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
328 | - $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
329 | - } else { |
|
330 | - $defaultTokenProvider = null; |
|
331 | - } |
|
332 | - |
|
333 | - $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
334 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
335 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
336 | - }); |
|
337 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
338 | - /** @var $user \OC\User\User */ |
|
339 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
340 | - }); |
|
341 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
342 | - /** @var $user \OC\User\User */ |
|
343 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
344 | - }); |
|
345 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
346 | - /** @var $user \OC\User\User */ |
|
347 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
348 | - }); |
|
349 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
350 | - /** @var $user \OC\User\User */ |
|
351 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
352 | - }); |
|
353 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
354 | - /** @var $user \OC\User\User */ |
|
355 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
356 | - }); |
|
357 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
358 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
359 | - }); |
|
360 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
361 | - /** @var $user \OC\User\User */ |
|
362 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
363 | - }); |
|
364 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
365 | - /** @var $user \OC\User\User */ |
|
366 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
367 | - }); |
|
368 | - $userSession->listen('\OC\User', 'logout', function () { |
|
369 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
370 | - }); |
|
371 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
372 | - /** @var $user \OC\User\User */ |
|
373 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
374 | - }); |
|
375 | - return $userSession; |
|
376 | - }); |
|
377 | - $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
378 | - |
|
379 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
380 | - return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
381 | - }); |
|
382 | - |
|
383 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
384 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
385 | - |
|
386 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
387 | - return new \OC\AllConfig( |
|
388 | - $c->getSystemConfig() |
|
389 | - ); |
|
390 | - }); |
|
391 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
392 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
393 | - |
|
394 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
395 | - return new \OC\SystemConfig($config); |
|
396 | - }); |
|
397 | - |
|
398 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
399 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
400 | - }); |
|
401 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
402 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
403 | - |
|
404 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
405 | - return new \OC\L10N\Factory( |
|
406 | - $c->getConfig(), |
|
407 | - $c->getRequest(), |
|
408 | - $c->getUserSession(), |
|
409 | - \OC::$SERVERROOT |
|
410 | - ); |
|
411 | - }); |
|
412 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
413 | - |
|
414 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
415 | - $config = $c->getConfig(); |
|
416 | - $cacheFactory = $c->getMemCacheFactory(); |
|
417 | - $request = $c->getRequest(); |
|
418 | - return new \OC\URLGenerator( |
|
419 | - $config, |
|
420 | - $cacheFactory, |
|
421 | - $request |
|
422 | - ); |
|
423 | - }); |
|
424 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
425 | - |
|
426 | - $this->registerService('AppHelper', function ($c) { |
|
427 | - return new \OC\AppHelper(); |
|
428 | - }); |
|
429 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
430 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
431 | - |
|
432 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
433 | - return new Cache\File(); |
|
434 | - }); |
|
435 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
436 | - |
|
437 | - $this->registerService(Factory::class, function (Server $c) { |
|
438 | - |
|
439 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
440 | - '\\OC\\Memcache\\ArrayCache', |
|
441 | - '\\OC\\Memcache\\ArrayCache', |
|
442 | - '\\OC\\Memcache\\ArrayCache' |
|
443 | - ); |
|
444 | - $config = $c->getConfig(); |
|
445 | - $request = $c->getRequest(); |
|
446 | - $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
447 | - |
|
448 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
449 | - $v = \OC_App::getAppVersions(); |
|
450 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
451 | - $version = implode(',', $v); |
|
452 | - $instanceId = \OC_Util::getInstanceId(); |
|
453 | - $path = \OC::$SERVERROOT; |
|
454 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
455 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
456 | - $config->getSystemValue('memcache.local', null), |
|
457 | - $config->getSystemValue('memcache.distributed', null), |
|
458 | - $config->getSystemValue('memcache.locking', null) |
|
459 | - ); |
|
460 | - } |
|
461 | - return $arrayCacheFactory; |
|
462 | - |
|
463 | - }); |
|
464 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
465 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
466 | - |
|
467 | - $this->registerService('RedisFactory', function (Server $c) { |
|
468 | - $systemConfig = $c->getSystemConfig(); |
|
469 | - return new RedisFactory($systemConfig); |
|
470 | - }); |
|
471 | - |
|
472 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
473 | - return new \OC\Activity\Manager( |
|
474 | - $c->getRequest(), |
|
475 | - $c->getUserSession(), |
|
476 | - $c->getConfig(), |
|
477 | - $c->query(IValidator::class) |
|
478 | - ); |
|
479 | - }); |
|
480 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
481 | - |
|
482 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
483 | - return new \OC\Activity\EventMerger( |
|
484 | - $c->getL10N('lib') |
|
485 | - ); |
|
486 | - }); |
|
487 | - $this->registerAlias(IValidator::class, Validator::class); |
|
488 | - |
|
489 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
490 | - return new AvatarManager( |
|
491 | - $c->getUserManager(), |
|
492 | - $c->getAppDataDir('avatar'), |
|
493 | - $c->getL10N('lib'), |
|
494 | - $c->getLogger(), |
|
495 | - $c->getConfig() |
|
496 | - ); |
|
497 | - }); |
|
498 | - $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
499 | - |
|
500 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
501 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
502 | - $logger = Log::getLogClass($logType); |
|
503 | - call_user_func(array($logger, 'init')); |
|
504 | - |
|
505 | - return new Log($logger); |
|
506 | - }); |
|
507 | - $this->registerAlias('Logger', \OCP\ILogger::class); |
|
508 | - |
|
509 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
510 | - $config = $c->getConfig(); |
|
511 | - return new \OC\BackgroundJob\JobList( |
|
512 | - $c->getDatabaseConnection(), |
|
513 | - $config, |
|
514 | - new TimeFactory() |
|
515 | - ); |
|
516 | - }); |
|
517 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
518 | - |
|
519 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
520 | - $cacheFactory = $c->getMemCacheFactory(); |
|
521 | - $logger = $c->getLogger(); |
|
522 | - if ($cacheFactory->isAvailable()) { |
|
523 | - $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
524 | - } else { |
|
525 | - $router = new \OC\Route\Router($logger); |
|
526 | - } |
|
527 | - return $router; |
|
528 | - }); |
|
529 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
530 | - |
|
531 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
532 | - return new Search(); |
|
533 | - }); |
|
534 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
535 | - |
|
536 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
537 | - return new \OC\Security\RateLimiting\Limiter( |
|
538 | - $this->getUserSession(), |
|
539 | - $this->getRequest(), |
|
540 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
541 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
542 | - ); |
|
543 | - }); |
|
544 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
545 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
546 | - $this->getMemCacheFactory(), |
|
547 | - new \OC\AppFramework\Utility\TimeFactory() |
|
548 | - ); |
|
549 | - }); |
|
550 | - |
|
551 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
552 | - return new SecureRandom(); |
|
553 | - }); |
|
554 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
555 | - |
|
556 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
557 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
558 | - }); |
|
559 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
560 | - |
|
561 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
562 | - return new Hasher($c->getConfig()); |
|
563 | - }); |
|
564 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
565 | - |
|
566 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
567 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
568 | - }); |
|
569 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
570 | - |
|
571 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
572 | - $systemConfig = $c->getSystemConfig(); |
|
573 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
574 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
575 | - if (!$factory->isValidType($type)) { |
|
576 | - throw new \OC\DatabaseException('Invalid database type'); |
|
577 | - } |
|
578 | - $connectionParams = $factory->createConnectionParams(); |
|
579 | - $connection = $factory->getConnection($type, $connectionParams); |
|
580 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
581 | - return $connection; |
|
582 | - }); |
|
583 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
584 | - |
|
585 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
586 | - $config = $c->getConfig(); |
|
587 | - return new HTTPHelper( |
|
588 | - $config, |
|
589 | - $c->getHTTPClientService() |
|
590 | - ); |
|
591 | - }); |
|
592 | - |
|
593 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
594 | - $user = \OC_User::getUser(); |
|
595 | - $uid = $user ? $user : null; |
|
596 | - return new ClientService( |
|
597 | - $c->getConfig(), |
|
598 | - new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
599 | - ); |
|
600 | - }); |
|
601 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
602 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
603 | - $eventLogger = new EventLogger(); |
|
604 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
605 | - // In debug mode, module is being activated by default |
|
606 | - $eventLogger->activate(); |
|
607 | - } |
|
608 | - return $eventLogger; |
|
609 | - }); |
|
610 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
611 | - |
|
612 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
613 | - $queryLogger = new QueryLogger(); |
|
614 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
615 | - // In debug mode, module is being activated by default |
|
616 | - $queryLogger->activate(); |
|
617 | - } |
|
618 | - return $queryLogger; |
|
619 | - }); |
|
620 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
621 | - |
|
622 | - $this->registerService(TempManager::class, function (Server $c) { |
|
623 | - return new TempManager( |
|
624 | - $c->getLogger(), |
|
625 | - $c->getConfig() |
|
626 | - ); |
|
627 | - }); |
|
628 | - $this->registerAlias('TempManager', TempManager::class); |
|
629 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
630 | - |
|
631 | - $this->registerService(AppManager::class, function (Server $c) { |
|
632 | - return new \OC\App\AppManager( |
|
633 | - $c->getUserSession(), |
|
634 | - $c->getAppConfig(), |
|
635 | - $c->getGroupManager(), |
|
636 | - $c->getMemCacheFactory(), |
|
637 | - $c->getEventDispatcher() |
|
638 | - ); |
|
639 | - }); |
|
640 | - $this->registerAlias('AppManager', AppManager::class); |
|
641 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
642 | - |
|
643 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
644 | - return new DateTimeZone( |
|
645 | - $c->getConfig(), |
|
646 | - $c->getSession() |
|
647 | - ); |
|
648 | - }); |
|
649 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
650 | - |
|
651 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
652 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
653 | - |
|
654 | - return new DateTimeFormatter( |
|
655 | - $c->getDateTimeZone()->getTimeZone(), |
|
656 | - $c->getL10N('lib', $language) |
|
657 | - ); |
|
658 | - }); |
|
659 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
660 | - |
|
661 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
662 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
663 | - $listener = new UserMountCacheListener($mountCache); |
|
664 | - $listener->listen($c->getUserManager()); |
|
665 | - return $mountCache; |
|
666 | - }); |
|
667 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
668 | - |
|
669 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
670 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
671 | - $mountCache = $c->query('UserMountCache'); |
|
672 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
673 | - |
|
674 | - // builtin providers |
|
675 | - |
|
676 | - $config = $c->getConfig(); |
|
677 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
678 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
679 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
680 | - |
|
681 | - return $manager; |
|
682 | - }); |
|
683 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
684 | - |
|
685 | - $this->registerService('IniWrapper', function ($c) { |
|
686 | - return new IniGetWrapper(); |
|
687 | - }); |
|
688 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
689 | - $jobList = $c->getJobList(); |
|
690 | - return new AsyncBus($jobList); |
|
691 | - }); |
|
692 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
693 | - return new TrustedDomainHelper($this->getConfig()); |
|
694 | - }); |
|
695 | - $this->registerService('Throttler', function(Server $c) { |
|
696 | - return new Throttler( |
|
697 | - $c->getDatabaseConnection(), |
|
698 | - new TimeFactory(), |
|
699 | - $c->getLogger(), |
|
700 | - $c->getConfig() |
|
701 | - ); |
|
702 | - }); |
|
703 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
704 | - // IConfig and IAppManager requires a working database. This code |
|
705 | - // might however be called when ownCloud is not yet setup. |
|
706 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
707 | - $config = $c->getConfig(); |
|
708 | - $appManager = $c->getAppManager(); |
|
709 | - } else { |
|
710 | - $config = null; |
|
711 | - $appManager = null; |
|
712 | - } |
|
713 | - |
|
714 | - return new Checker( |
|
715 | - new EnvironmentHelper(), |
|
716 | - new FileAccessHelper(), |
|
717 | - new AppLocator(), |
|
718 | - $config, |
|
719 | - $c->getMemCacheFactory(), |
|
720 | - $appManager, |
|
721 | - $c->getTempManager() |
|
722 | - ); |
|
723 | - }); |
|
724 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
725 | - if (isset($this['urlParams'])) { |
|
726 | - $urlParams = $this['urlParams']; |
|
727 | - } else { |
|
728 | - $urlParams = []; |
|
729 | - } |
|
730 | - |
|
731 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
732 | - && in_array('fakeinput', stream_get_wrappers()) |
|
733 | - ) { |
|
734 | - $stream = 'fakeinput://data'; |
|
735 | - } else { |
|
736 | - $stream = 'php://input'; |
|
737 | - } |
|
738 | - |
|
739 | - return new Request( |
|
740 | - [ |
|
741 | - 'get' => $_GET, |
|
742 | - 'post' => $_POST, |
|
743 | - 'files' => $_FILES, |
|
744 | - 'server' => $_SERVER, |
|
745 | - 'env' => $_ENV, |
|
746 | - 'cookies' => $_COOKIE, |
|
747 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
748 | - ? $_SERVER['REQUEST_METHOD'] |
|
749 | - : null, |
|
750 | - 'urlParams' => $urlParams, |
|
751 | - ], |
|
752 | - $this->getSecureRandom(), |
|
753 | - $this->getConfig(), |
|
754 | - $this->getCsrfTokenManager(), |
|
755 | - $stream |
|
756 | - ); |
|
757 | - }); |
|
758 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
759 | - |
|
760 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
761 | - return new Mailer( |
|
762 | - $c->getConfig(), |
|
763 | - $c->getLogger(), |
|
764 | - $c->query(Defaults::class), |
|
765 | - $c->getURLGenerator(), |
|
766 | - $c->getL10N('lib') |
|
767 | - ); |
|
768 | - }); |
|
769 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
770 | - |
|
771 | - $this->registerService('LDAPProvider', function(Server $c) { |
|
772 | - $config = $c->getConfig(); |
|
773 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
774 | - if(is_null($factoryClass)) { |
|
775 | - throw new \Exception('ldapProviderFactory not set'); |
|
776 | - } |
|
777 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
778 | - $factory = new $factoryClass($this); |
|
779 | - return $factory->getLDAPProvider(); |
|
780 | - }); |
|
781 | - $this->registerService('LockingProvider', function (Server $c) { |
|
782 | - $ini = $c->getIniWrapper(); |
|
783 | - $config = $c->getConfig(); |
|
784 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
785 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
786 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
787 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
788 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
789 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
790 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
791 | - } |
|
792 | - return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
793 | - } |
|
794 | - return new NoopLockingProvider(); |
|
795 | - }); |
|
796 | - |
|
797 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
798 | - return new \OC\Files\Mount\Manager(); |
|
799 | - }); |
|
800 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
801 | - |
|
802 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
803 | - return new \OC\Files\Type\Detection( |
|
804 | - $c->getURLGenerator(), |
|
805 | - \OC::$configDir, |
|
806 | - \OC::$SERVERROOT . '/resources/config/' |
|
807 | - ); |
|
808 | - }); |
|
809 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
810 | - |
|
811 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
812 | - return new \OC\Files\Type\Loader( |
|
813 | - $c->getDatabaseConnection() |
|
814 | - ); |
|
815 | - }); |
|
816 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
817 | - $this->registerService(BundleFetcher::class, function () { |
|
818 | - return new BundleFetcher($this->getL10N('lib')); |
|
819 | - }); |
|
820 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
821 | - return new Manager( |
|
822 | - $c->query(IValidator::class) |
|
823 | - ); |
|
824 | - }); |
|
825 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
826 | - |
|
827 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
828 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
829 | - $manager->registerCapability(function () use ($c) { |
|
830 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
831 | - }); |
|
832 | - return $manager; |
|
833 | - }); |
|
834 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
835 | - |
|
836 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
837 | - $config = $c->getConfig(); |
|
838 | - $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
839 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
840 | - $factory = new $factoryClass($this); |
|
841 | - return $factory->getManager(); |
|
842 | - }); |
|
843 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
844 | - |
|
845 | - $this->registerService('ThemingDefaults', function(Server $c) { |
|
846 | - /* |
|
129 | + /** @var string */ |
|
130 | + private $webRoot; |
|
131 | + |
|
132 | + /** |
|
133 | + * @param string $webRoot |
|
134 | + * @param \OC\Config $config |
|
135 | + */ |
|
136 | + public function __construct($webRoot, \OC\Config $config) { |
|
137 | + parent::__construct(); |
|
138 | + $this->webRoot = $webRoot; |
|
139 | + |
|
140 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
141 | + return $c; |
|
142 | + }); |
|
143 | + |
|
144 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
145 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
146 | + |
|
147 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
152 | + return new PreviewManager( |
|
153 | + $c->getConfig(), |
|
154 | + $c->getRootFolder(), |
|
155 | + $c->getAppDataDir('preview'), |
|
156 | + $c->getEventDispatcher(), |
|
157 | + $c->getSession()->get('user_id') |
|
158 | + ); |
|
159 | + }); |
|
160 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
161 | + |
|
162 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
163 | + return new \OC\Preview\Watcher( |
|
164 | + $c->getAppDataDir('preview') |
|
165 | + ); |
|
166 | + }); |
|
167 | + |
|
168 | + $this->registerService('EncryptionManager', function (Server $c) { |
|
169 | + $view = new View(); |
|
170 | + $util = new Encryption\Util( |
|
171 | + $view, |
|
172 | + $c->getUserManager(), |
|
173 | + $c->getGroupManager(), |
|
174 | + $c->getConfig() |
|
175 | + ); |
|
176 | + return new Encryption\Manager( |
|
177 | + $c->getConfig(), |
|
178 | + $c->getLogger(), |
|
179 | + $c->getL10N('core'), |
|
180 | + new View(), |
|
181 | + $util, |
|
182 | + new ArrayCache() |
|
183 | + ); |
|
184 | + }); |
|
185 | + |
|
186 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
187 | + $util = new Encryption\Util( |
|
188 | + new View(), |
|
189 | + $c->getUserManager(), |
|
190 | + $c->getGroupManager(), |
|
191 | + $c->getConfig() |
|
192 | + ); |
|
193 | + return new Encryption\File( |
|
194 | + $util, |
|
195 | + $c->getRootFolder(), |
|
196 | + $c->getShareManager() |
|
197 | + ); |
|
198 | + }); |
|
199 | + |
|
200 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
201 | + $view = new View(); |
|
202 | + $util = new Encryption\Util( |
|
203 | + $view, |
|
204 | + $c->getUserManager(), |
|
205 | + $c->getGroupManager(), |
|
206 | + $c->getConfig() |
|
207 | + ); |
|
208 | + |
|
209 | + return new Encryption\Keys\Storage($view, $util); |
|
210 | + }); |
|
211 | + $this->registerService('TagMapper', function (Server $c) { |
|
212 | + return new TagMapper($c->getDatabaseConnection()); |
|
213 | + }); |
|
214 | + |
|
215 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
216 | + $tagMapper = $c->query('TagMapper'); |
|
217 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
218 | + }); |
|
219 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
220 | + |
|
221 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
222 | + $config = $c->getConfig(); |
|
223 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
|
224 | + /** @var \OC\SystemTag\ManagerFactory $factory */ |
|
225 | + $factory = new $factoryClass($this); |
|
226 | + return $factory; |
|
227 | + }); |
|
228 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
229 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
230 | + }); |
|
231 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
232 | + |
|
233 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
234 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
235 | + }); |
|
236 | + $this->registerService('RootFolder', function (Server $c) { |
|
237 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
238 | + $view = new View(); |
|
239 | + $root = new Root( |
|
240 | + $manager, |
|
241 | + $view, |
|
242 | + null, |
|
243 | + $c->getUserMountCache(), |
|
244 | + $this->getLogger(), |
|
245 | + $this->getUserManager() |
|
246 | + ); |
|
247 | + $connector = new HookConnector($root, $view); |
|
248 | + $connector->viewToNode(); |
|
249 | + |
|
250 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
251 | + $previewConnector->connectWatcher(); |
|
252 | + |
|
253 | + return $root; |
|
254 | + }); |
|
255 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
256 | + |
|
257 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
258 | + return new LazyRoot(function() use ($c) { |
|
259 | + return $c->query('RootFolder'); |
|
260 | + }); |
|
261 | + }); |
|
262 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
263 | + |
|
264 | + $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
265 | + $config = $c->getConfig(); |
|
266 | + return new \OC\User\Manager($config); |
|
267 | + }); |
|
268 | + $this->registerAlias('UserManager', \OCP\IUserManager::class); |
|
269 | + |
|
270 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
271 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
|
272 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
273 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
274 | + }); |
|
275 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
276 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
277 | + }); |
|
278 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
279 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
280 | + }); |
|
281 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
282 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
283 | + }); |
|
284 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
285 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
286 | + }); |
|
287 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
288 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
289 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
290 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
291 | + }); |
|
292 | + return $groupManager; |
|
293 | + }); |
|
294 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
295 | + |
|
296 | + $this->registerService(Store::class, function(Server $c) { |
|
297 | + $session = $c->getSession(); |
|
298 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
299 | + $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
300 | + } else { |
|
301 | + $tokenProvider = null; |
|
302 | + } |
|
303 | + $logger = $c->getLogger(); |
|
304 | + return new Store($session, $logger, $tokenProvider); |
|
305 | + }); |
|
306 | + $this->registerAlias(IStore::class, Store::class); |
|
307 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
308 | + $dbConnection = $c->getDatabaseConnection(); |
|
309 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
310 | + }); |
|
311 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
312 | + $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
|
313 | + $crypto = $c->getCrypto(); |
|
314 | + $config = $c->getConfig(); |
|
315 | + $logger = $c->getLogger(); |
|
316 | + $timeFactory = new TimeFactory(); |
|
317 | + return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
|
318 | + }); |
|
319 | + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
|
320 | + |
|
321 | + $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
322 | + $manager = $c->getUserManager(); |
|
323 | + $session = new \OC\Session\Memory(''); |
|
324 | + $timeFactory = new TimeFactory(); |
|
325 | + // Token providers might require a working database. This code |
|
326 | + // might however be called when ownCloud is not yet setup. |
|
327 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
328 | + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
|
329 | + } else { |
|
330 | + $defaultTokenProvider = null; |
|
331 | + } |
|
332 | + |
|
333 | + $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
|
334 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
335 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
336 | + }); |
|
337 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
338 | + /** @var $user \OC\User\User */ |
|
339 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
340 | + }); |
|
341 | + $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
342 | + /** @var $user \OC\User\User */ |
|
343 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
344 | + }); |
|
345 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
346 | + /** @var $user \OC\User\User */ |
|
347 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
348 | + }); |
|
349 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
350 | + /** @var $user \OC\User\User */ |
|
351 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
352 | + }); |
|
353 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
354 | + /** @var $user \OC\User\User */ |
|
355 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
356 | + }); |
|
357 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
358 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
359 | + }); |
|
360 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
361 | + /** @var $user \OC\User\User */ |
|
362 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
363 | + }); |
|
364 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
365 | + /** @var $user \OC\User\User */ |
|
366 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
367 | + }); |
|
368 | + $userSession->listen('\OC\User', 'logout', function () { |
|
369 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
370 | + }); |
|
371 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
372 | + /** @var $user \OC\User\User */ |
|
373 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
374 | + }); |
|
375 | + return $userSession; |
|
376 | + }); |
|
377 | + $this->registerAlias('UserSession', \OCP\IUserSession::class); |
|
378 | + |
|
379 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
380 | + return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
|
381 | + }); |
|
382 | + |
|
383 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
384 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
385 | + |
|
386 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
387 | + return new \OC\AllConfig( |
|
388 | + $c->getSystemConfig() |
|
389 | + ); |
|
390 | + }); |
|
391 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
392 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
393 | + |
|
394 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
395 | + return new \OC\SystemConfig($config); |
|
396 | + }); |
|
397 | + |
|
398 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
399 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
400 | + }); |
|
401 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
402 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
403 | + |
|
404 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
405 | + return new \OC\L10N\Factory( |
|
406 | + $c->getConfig(), |
|
407 | + $c->getRequest(), |
|
408 | + $c->getUserSession(), |
|
409 | + \OC::$SERVERROOT |
|
410 | + ); |
|
411 | + }); |
|
412 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
413 | + |
|
414 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
415 | + $config = $c->getConfig(); |
|
416 | + $cacheFactory = $c->getMemCacheFactory(); |
|
417 | + $request = $c->getRequest(); |
|
418 | + return new \OC\URLGenerator( |
|
419 | + $config, |
|
420 | + $cacheFactory, |
|
421 | + $request |
|
422 | + ); |
|
423 | + }); |
|
424 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
425 | + |
|
426 | + $this->registerService('AppHelper', function ($c) { |
|
427 | + return new \OC\AppHelper(); |
|
428 | + }); |
|
429 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
430 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
431 | + |
|
432 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
433 | + return new Cache\File(); |
|
434 | + }); |
|
435 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
436 | + |
|
437 | + $this->registerService(Factory::class, function (Server $c) { |
|
438 | + |
|
439 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
440 | + '\\OC\\Memcache\\ArrayCache', |
|
441 | + '\\OC\\Memcache\\ArrayCache', |
|
442 | + '\\OC\\Memcache\\ArrayCache' |
|
443 | + ); |
|
444 | + $config = $c->getConfig(); |
|
445 | + $request = $c->getRequest(); |
|
446 | + $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
|
447 | + |
|
448 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
449 | + $v = \OC_App::getAppVersions(); |
|
450 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
451 | + $version = implode(',', $v); |
|
452 | + $instanceId = \OC_Util::getInstanceId(); |
|
453 | + $path = \OC::$SERVERROOT; |
|
454 | + $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
455 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
456 | + $config->getSystemValue('memcache.local', null), |
|
457 | + $config->getSystemValue('memcache.distributed', null), |
|
458 | + $config->getSystemValue('memcache.locking', null) |
|
459 | + ); |
|
460 | + } |
|
461 | + return $arrayCacheFactory; |
|
462 | + |
|
463 | + }); |
|
464 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
465 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
466 | + |
|
467 | + $this->registerService('RedisFactory', function (Server $c) { |
|
468 | + $systemConfig = $c->getSystemConfig(); |
|
469 | + return new RedisFactory($systemConfig); |
|
470 | + }); |
|
471 | + |
|
472 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
473 | + return new \OC\Activity\Manager( |
|
474 | + $c->getRequest(), |
|
475 | + $c->getUserSession(), |
|
476 | + $c->getConfig(), |
|
477 | + $c->query(IValidator::class) |
|
478 | + ); |
|
479 | + }); |
|
480 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
481 | + |
|
482 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
483 | + return new \OC\Activity\EventMerger( |
|
484 | + $c->getL10N('lib') |
|
485 | + ); |
|
486 | + }); |
|
487 | + $this->registerAlias(IValidator::class, Validator::class); |
|
488 | + |
|
489 | + $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
490 | + return new AvatarManager( |
|
491 | + $c->getUserManager(), |
|
492 | + $c->getAppDataDir('avatar'), |
|
493 | + $c->getL10N('lib'), |
|
494 | + $c->getLogger(), |
|
495 | + $c->getConfig() |
|
496 | + ); |
|
497 | + }); |
|
498 | + $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
|
499 | + |
|
500 | + $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
501 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
502 | + $logger = Log::getLogClass($logType); |
|
503 | + call_user_func(array($logger, 'init')); |
|
504 | + |
|
505 | + return new Log($logger); |
|
506 | + }); |
|
507 | + $this->registerAlias('Logger', \OCP\ILogger::class); |
|
508 | + |
|
509 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
510 | + $config = $c->getConfig(); |
|
511 | + return new \OC\BackgroundJob\JobList( |
|
512 | + $c->getDatabaseConnection(), |
|
513 | + $config, |
|
514 | + new TimeFactory() |
|
515 | + ); |
|
516 | + }); |
|
517 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
518 | + |
|
519 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
520 | + $cacheFactory = $c->getMemCacheFactory(); |
|
521 | + $logger = $c->getLogger(); |
|
522 | + if ($cacheFactory->isAvailable()) { |
|
523 | + $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
|
524 | + } else { |
|
525 | + $router = new \OC\Route\Router($logger); |
|
526 | + } |
|
527 | + return $router; |
|
528 | + }); |
|
529 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
530 | + |
|
531 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
532 | + return new Search(); |
|
533 | + }); |
|
534 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
535 | + |
|
536 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) { |
|
537 | + return new \OC\Security\RateLimiting\Limiter( |
|
538 | + $this->getUserSession(), |
|
539 | + $this->getRequest(), |
|
540 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
541 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
542 | + ); |
|
543 | + }); |
|
544 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
545 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
546 | + $this->getMemCacheFactory(), |
|
547 | + new \OC\AppFramework\Utility\TimeFactory() |
|
548 | + ); |
|
549 | + }); |
|
550 | + |
|
551 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
552 | + return new SecureRandom(); |
|
553 | + }); |
|
554 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
555 | + |
|
556 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
557 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
558 | + }); |
|
559 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
560 | + |
|
561 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
562 | + return new Hasher($c->getConfig()); |
|
563 | + }); |
|
564 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
565 | + |
|
566 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
567 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
568 | + }); |
|
569 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
570 | + |
|
571 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
572 | + $systemConfig = $c->getSystemConfig(); |
|
573 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
574 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
575 | + if (!$factory->isValidType($type)) { |
|
576 | + throw new \OC\DatabaseException('Invalid database type'); |
|
577 | + } |
|
578 | + $connectionParams = $factory->createConnectionParams(); |
|
579 | + $connection = $factory->getConnection($type, $connectionParams); |
|
580 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
581 | + return $connection; |
|
582 | + }); |
|
583 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
584 | + |
|
585 | + $this->registerService('HTTPHelper', function (Server $c) { |
|
586 | + $config = $c->getConfig(); |
|
587 | + return new HTTPHelper( |
|
588 | + $config, |
|
589 | + $c->getHTTPClientService() |
|
590 | + ); |
|
591 | + }); |
|
592 | + |
|
593 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
594 | + $user = \OC_User::getUser(); |
|
595 | + $uid = $user ? $user : null; |
|
596 | + return new ClientService( |
|
597 | + $c->getConfig(), |
|
598 | + new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
|
599 | + ); |
|
600 | + }); |
|
601 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
602 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
603 | + $eventLogger = new EventLogger(); |
|
604 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
605 | + // In debug mode, module is being activated by default |
|
606 | + $eventLogger->activate(); |
|
607 | + } |
|
608 | + return $eventLogger; |
|
609 | + }); |
|
610 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
611 | + |
|
612 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
613 | + $queryLogger = new QueryLogger(); |
|
614 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
615 | + // In debug mode, module is being activated by default |
|
616 | + $queryLogger->activate(); |
|
617 | + } |
|
618 | + return $queryLogger; |
|
619 | + }); |
|
620 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
621 | + |
|
622 | + $this->registerService(TempManager::class, function (Server $c) { |
|
623 | + return new TempManager( |
|
624 | + $c->getLogger(), |
|
625 | + $c->getConfig() |
|
626 | + ); |
|
627 | + }); |
|
628 | + $this->registerAlias('TempManager', TempManager::class); |
|
629 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
630 | + |
|
631 | + $this->registerService(AppManager::class, function (Server $c) { |
|
632 | + return new \OC\App\AppManager( |
|
633 | + $c->getUserSession(), |
|
634 | + $c->getAppConfig(), |
|
635 | + $c->getGroupManager(), |
|
636 | + $c->getMemCacheFactory(), |
|
637 | + $c->getEventDispatcher() |
|
638 | + ); |
|
639 | + }); |
|
640 | + $this->registerAlias('AppManager', AppManager::class); |
|
641 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
642 | + |
|
643 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
644 | + return new DateTimeZone( |
|
645 | + $c->getConfig(), |
|
646 | + $c->getSession() |
|
647 | + ); |
|
648 | + }); |
|
649 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
650 | + |
|
651 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
652 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
653 | + |
|
654 | + return new DateTimeFormatter( |
|
655 | + $c->getDateTimeZone()->getTimeZone(), |
|
656 | + $c->getL10N('lib', $language) |
|
657 | + ); |
|
658 | + }); |
|
659 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
660 | + |
|
661 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
662 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
663 | + $listener = new UserMountCacheListener($mountCache); |
|
664 | + $listener->listen($c->getUserManager()); |
|
665 | + return $mountCache; |
|
666 | + }); |
|
667 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
668 | + |
|
669 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
670 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
671 | + $mountCache = $c->query('UserMountCache'); |
|
672 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
673 | + |
|
674 | + // builtin providers |
|
675 | + |
|
676 | + $config = $c->getConfig(); |
|
677 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
678 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
679 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
680 | + |
|
681 | + return $manager; |
|
682 | + }); |
|
683 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
684 | + |
|
685 | + $this->registerService('IniWrapper', function ($c) { |
|
686 | + return new IniGetWrapper(); |
|
687 | + }); |
|
688 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
689 | + $jobList = $c->getJobList(); |
|
690 | + return new AsyncBus($jobList); |
|
691 | + }); |
|
692 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
693 | + return new TrustedDomainHelper($this->getConfig()); |
|
694 | + }); |
|
695 | + $this->registerService('Throttler', function(Server $c) { |
|
696 | + return new Throttler( |
|
697 | + $c->getDatabaseConnection(), |
|
698 | + new TimeFactory(), |
|
699 | + $c->getLogger(), |
|
700 | + $c->getConfig() |
|
701 | + ); |
|
702 | + }); |
|
703 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
704 | + // IConfig and IAppManager requires a working database. This code |
|
705 | + // might however be called when ownCloud is not yet setup. |
|
706 | + if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
707 | + $config = $c->getConfig(); |
|
708 | + $appManager = $c->getAppManager(); |
|
709 | + } else { |
|
710 | + $config = null; |
|
711 | + $appManager = null; |
|
712 | + } |
|
713 | + |
|
714 | + return new Checker( |
|
715 | + new EnvironmentHelper(), |
|
716 | + new FileAccessHelper(), |
|
717 | + new AppLocator(), |
|
718 | + $config, |
|
719 | + $c->getMemCacheFactory(), |
|
720 | + $appManager, |
|
721 | + $c->getTempManager() |
|
722 | + ); |
|
723 | + }); |
|
724 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
725 | + if (isset($this['urlParams'])) { |
|
726 | + $urlParams = $this['urlParams']; |
|
727 | + } else { |
|
728 | + $urlParams = []; |
|
729 | + } |
|
730 | + |
|
731 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
732 | + && in_array('fakeinput', stream_get_wrappers()) |
|
733 | + ) { |
|
734 | + $stream = 'fakeinput://data'; |
|
735 | + } else { |
|
736 | + $stream = 'php://input'; |
|
737 | + } |
|
738 | + |
|
739 | + return new Request( |
|
740 | + [ |
|
741 | + 'get' => $_GET, |
|
742 | + 'post' => $_POST, |
|
743 | + 'files' => $_FILES, |
|
744 | + 'server' => $_SERVER, |
|
745 | + 'env' => $_ENV, |
|
746 | + 'cookies' => $_COOKIE, |
|
747 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
748 | + ? $_SERVER['REQUEST_METHOD'] |
|
749 | + : null, |
|
750 | + 'urlParams' => $urlParams, |
|
751 | + ], |
|
752 | + $this->getSecureRandom(), |
|
753 | + $this->getConfig(), |
|
754 | + $this->getCsrfTokenManager(), |
|
755 | + $stream |
|
756 | + ); |
|
757 | + }); |
|
758 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
759 | + |
|
760 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
761 | + return new Mailer( |
|
762 | + $c->getConfig(), |
|
763 | + $c->getLogger(), |
|
764 | + $c->query(Defaults::class), |
|
765 | + $c->getURLGenerator(), |
|
766 | + $c->getL10N('lib') |
|
767 | + ); |
|
768 | + }); |
|
769 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
770 | + |
|
771 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
772 | + $config = $c->getConfig(); |
|
773 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
774 | + if(is_null($factoryClass)) { |
|
775 | + throw new \Exception('ldapProviderFactory not set'); |
|
776 | + } |
|
777 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
778 | + $factory = new $factoryClass($this); |
|
779 | + return $factory->getLDAPProvider(); |
|
780 | + }); |
|
781 | + $this->registerService('LockingProvider', function (Server $c) { |
|
782 | + $ini = $c->getIniWrapper(); |
|
783 | + $config = $c->getConfig(); |
|
784 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
785 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
786 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
787 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
788 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
789 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
790 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
791 | + } |
|
792 | + return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
|
793 | + } |
|
794 | + return new NoopLockingProvider(); |
|
795 | + }); |
|
796 | + |
|
797 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
798 | + return new \OC\Files\Mount\Manager(); |
|
799 | + }); |
|
800 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
801 | + |
|
802 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
803 | + return new \OC\Files\Type\Detection( |
|
804 | + $c->getURLGenerator(), |
|
805 | + \OC::$configDir, |
|
806 | + \OC::$SERVERROOT . '/resources/config/' |
|
807 | + ); |
|
808 | + }); |
|
809 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
810 | + |
|
811 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
812 | + return new \OC\Files\Type\Loader( |
|
813 | + $c->getDatabaseConnection() |
|
814 | + ); |
|
815 | + }); |
|
816 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
817 | + $this->registerService(BundleFetcher::class, function () { |
|
818 | + return new BundleFetcher($this->getL10N('lib')); |
|
819 | + }); |
|
820 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
821 | + return new Manager( |
|
822 | + $c->query(IValidator::class) |
|
823 | + ); |
|
824 | + }); |
|
825 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
826 | + |
|
827 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
828 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
829 | + $manager->registerCapability(function () use ($c) { |
|
830 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
831 | + }); |
|
832 | + return $manager; |
|
833 | + }); |
|
834 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
835 | + |
|
836 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
837 | + $config = $c->getConfig(); |
|
838 | + $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
|
839 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
840 | + $factory = new $factoryClass($this); |
|
841 | + return $factory->getManager(); |
|
842 | + }); |
|
843 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
844 | + |
|
845 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
846 | + /* |
|
847 | 847 | * Dark magic for autoloader. |
848 | 848 | * If we do a class_exists it will try to load the class which will |
849 | 849 | * make composer cache the result. Resulting in errors when enabling |
850 | 850 | * the theming app. |
851 | 851 | */ |
852 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
853 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
854 | - $classExists = true; |
|
855 | - } else { |
|
856 | - $classExists = false; |
|
857 | - } |
|
858 | - |
|
859 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
860 | - return new ThemingDefaults( |
|
861 | - $c->getConfig(), |
|
862 | - $c->getL10N('theming'), |
|
863 | - $c->getURLGenerator(), |
|
864 | - $c->getAppDataDir('theming'), |
|
865 | - $c->getMemCacheFactory(), |
|
866 | - new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')) |
|
867 | - ); |
|
868 | - } |
|
869 | - return new \OC_Defaults(); |
|
870 | - }); |
|
871 | - $this->registerService(SCSSCacher::class, function(Server $c) { |
|
872 | - /** @var Factory $cacheFactory */ |
|
873 | - $cacheFactory = $c->query(Factory::class); |
|
874 | - return new SCSSCacher( |
|
875 | - $c->getLogger(), |
|
876 | - $c->query(\OC\Files\AppData\Factory::class), |
|
877 | - $c->getURLGenerator(), |
|
878 | - $c->getConfig(), |
|
879 | - $c->getThemingDefaults(), |
|
880 | - \OC::$SERVERROOT, |
|
881 | - $cacheFactory->create('SCSS') |
|
882 | - ); |
|
883 | - }); |
|
884 | - $this->registerService(EventDispatcher::class, function () { |
|
885 | - return new EventDispatcher(); |
|
886 | - }); |
|
887 | - $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
888 | - $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
889 | - |
|
890 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
891 | - // FIXME: Instantiiated here due to cyclic dependency |
|
892 | - $request = new Request( |
|
893 | - [ |
|
894 | - 'get' => $_GET, |
|
895 | - 'post' => $_POST, |
|
896 | - 'files' => $_FILES, |
|
897 | - 'server' => $_SERVER, |
|
898 | - 'env' => $_ENV, |
|
899 | - 'cookies' => $_COOKIE, |
|
900 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
901 | - ? $_SERVER['REQUEST_METHOD'] |
|
902 | - : null, |
|
903 | - ], |
|
904 | - $c->getSecureRandom(), |
|
905 | - $c->getConfig() |
|
906 | - ); |
|
907 | - |
|
908 | - return new CryptoWrapper( |
|
909 | - $c->getConfig(), |
|
910 | - $c->getCrypto(), |
|
911 | - $c->getSecureRandom(), |
|
912 | - $request |
|
913 | - ); |
|
914 | - }); |
|
915 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
916 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
917 | - |
|
918 | - return new CsrfTokenManager( |
|
919 | - $tokenGenerator, |
|
920 | - $c->query(SessionStorage::class) |
|
921 | - ); |
|
922 | - }); |
|
923 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
924 | - return new SessionStorage($c->getSession()); |
|
925 | - }); |
|
926 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
927 | - return new ContentSecurityPolicyManager(); |
|
928 | - }); |
|
929 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
930 | - |
|
931 | - $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
932 | - return new ContentSecurityPolicyNonceManager( |
|
933 | - $c->getCsrfTokenManager(), |
|
934 | - $c->getRequest() |
|
935 | - ); |
|
936 | - }); |
|
937 | - |
|
938 | - $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
939 | - $config = $c->getConfig(); |
|
940 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
941 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
942 | - $factory = new $factoryClass($this); |
|
943 | - |
|
944 | - $manager = new \OC\Share20\Manager( |
|
945 | - $c->getLogger(), |
|
946 | - $c->getConfig(), |
|
947 | - $c->getSecureRandom(), |
|
948 | - $c->getHasher(), |
|
949 | - $c->getMountManager(), |
|
950 | - $c->getGroupManager(), |
|
951 | - $c->getL10N('core'), |
|
952 | - $factory, |
|
953 | - $c->getUserManager(), |
|
954 | - $c->getLazyRootFolder(), |
|
955 | - $c->getEventDispatcher() |
|
956 | - ); |
|
957 | - |
|
958 | - return $manager; |
|
959 | - }); |
|
960 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
961 | - |
|
962 | - $this->registerService('SettingsManager', function(Server $c) { |
|
963 | - $manager = new \OC\Settings\Manager( |
|
964 | - $c->getLogger(), |
|
965 | - $c->getDatabaseConnection(), |
|
966 | - $c->getL10N('lib'), |
|
967 | - $c->getConfig(), |
|
968 | - $c->getEncryptionManager(), |
|
969 | - $c->getUserManager(), |
|
970 | - $c->getLockingProvider(), |
|
971 | - $c->getRequest(), |
|
972 | - new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
973 | - $c->getURLGenerator() |
|
974 | - ); |
|
975 | - return $manager; |
|
976 | - }); |
|
977 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
978 | - return new \OC\Files\AppData\Factory( |
|
979 | - $c->getRootFolder(), |
|
980 | - $c->getSystemConfig() |
|
981 | - ); |
|
982 | - }); |
|
983 | - |
|
984 | - $this->registerService('LockdownManager', function (Server $c) { |
|
985 | - return new LockdownManager(function() use ($c) { |
|
986 | - return $c->getSession(); |
|
987 | - }); |
|
988 | - }); |
|
989 | - |
|
990 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
991 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
992 | - }); |
|
993 | - |
|
994 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
995 | - return new CloudIdManager(); |
|
996 | - }); |
|
997 | - |
|
998 | - /* To trick DI since we don't extend the DIContainer here */ |
|
999 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1000 | - return new CleanPreviewsBackgroundJob( |
|
1001 | - $c->getRootFolder(), |
|
1002 | - $c->getLogger(), |
|
1003 | - $c->getJobList(), |
|
1004 | - new TimeFactory() |
|
1005 | - ); |
|
1006 | - }); |
|
1007 | - |
|
1008 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1009 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1010 | - |
|
1011 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1012 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1013 | - |
|
1014 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1015 | - return new Defaults( |
|
1016 | - $c->getThemingDefaults() |
|
1017 | - ); |
|
1018 | - }); |
|
1019 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1020 | - |
|
1021 | - $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1022 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1023 | - }); |
|
1024 | - |
|
1025 | - $this->registerService(IShareHelper::class, function(Server $c) { |
|
1026 | - return new ShareHelper( |
|
1027 | - $c->query(\OCP\Share\IManager::class) |
|
1028 | - ); |
|
1029 | - }); |
|
1030 | - } |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * @return \OCP\Contacts\IManager |
|
1034 | - */ |
|
1035 | - public function getContactsManager() { |
|
1036 | - return $this->query('ContactsManager'); |
|
1037 | - } |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * @return \OC\Encryption\Manager |
|
1041 | - */ |
|
1042 | - public function getEncryptionManager() { |
|
1043 | - return $this->query('EncryptionManager'); |
|
1044 | - } |
|
1045 | - |
|
1046 | - /** |
|
1047 | - * @return \OC\Encryption\File |
|
1048 | - */ |
|
1049 | - public function getEncryptionFilesHelper() { |
|
1050 | - return $this->query('EncryptionFileHelper'); |
|
1051 | - } |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * @return \OCP\Encryption\Keys\IStorage |
|
1055 | - */ |
|
1056 | - public function getEncryptionKeyStorage() { |
|
1057 | - return $this->query('EncryptionKeyStorage'); |
|
1058 | - } |
|
1059 | - |
|
1060 | - /** |
|
1061 | - * The current request object holding all information about the request |
|
1062 | - * currently being processed is returned from this method. |
|
1063 | - * In case the current execution was not initiated by a web request null is returned |
|
1064 | - * |
|
1065 | - * @return \OCP\IRequest |
|
1066 | - */ |
|
1067 | - public function getRequest() { |
|
1068 | - return $this->query('Request'); |
|
1069 | - } |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * Returns the preview manager which can create preview images for a given file |
|
1073 | - * |
|
1074 | - * @return \OCP\IPreview |
|
1075 | - */ |
|
1076 | - public function getPreviewManager() { |
|
1077 | - return $this->query('PreviewManager'); |
|
1078 | - } |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * Returns the tag manager which can get and set tags for different object types |
|
1082 | - * |
|
1083 | - * @see \OCP\ITagManager::load() |
|
1084 | - * @return \OCP\ITagManager |
|
1085 | - */ |
|
1086 | - public function getTagManager() { |
|
1087 | - return $this->query('TagManager'); |
|
1088 | - } |
|
1089 | - |
|
1090 | - /** |
|
1091 | - * Returns the system-tag manager |
|
1092 | - * |
|
1093 | - * @return \OCP\SystemTag\ISystemTagManager |
|
1094 | - * |
|
1095 | - * @since 9.0.0 |
|
1096 | - */ |
|
1097 | - public function getSystemTagManager() { |
|
1098 | - return $this->query('SystemTagManager'); |
|
1099 | - } |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Returns the system-tag object mapper |
|
1103 | - * |
|
1104 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1105 | - * |
|
1106 | - * @since 9.0.0 |
|
1107 | - */ |
|
1108 | - public function getSystemTagObjectMapper() { |
|
1109 | - return $this->query('SystemTagObjectMapper'); |
|
1110 | - } |
|
1111 | - |
|
1112 | - /** |
|
1113 | - * Returns the avatar manager, used for avatar functionality |
|
1114 | - * |
|
1115 | - * @return \OCP\IAvatarManager |
|
1116 | - */ |
|
1117 | - public function getAvatarManager() { |
|
1118 | - return $this->query('AvatarManager'); |
|
1119 | - } |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * Returns the root folder of ownCloud's data directory |
|
1123 | - * |
|
1124 | - * @return \OCP\Files\IRootFolder |
|
1125 | - */ |
|
1126 | - public function getRootFolder() { |
|
1127 | - return $this->query('LazyRootFolder'); |
|
1128 | - } |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * Returns the root folder of ownCloud's data directory |
|
1132 | - * This is the lazy variant so this gets only initialized once it |
|
1133 | - * is actually used. |
|
1134 | - * |
|
1135 | - * @return \OCP\Files\IRootFolder |
|
1136 | - */ |
|
1137 | - public function getLazyRootFolder() { |
|
1138 | - return $this->query('LazyRootFolder'); |
|
1139 | - } |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Returns a view to ownCloud's files folder |
|
1143 | - * |
|
1144 | - * @param string $userId user ID |
|
1145 | - * @return \OCP\Files\Folder|null |
|
1146 | - */ |
|
1147 | - public function getUserFolder($userId = null) { |
|
1148 | - if ($userId === null) { |
|
1149 | - $user = $this->getUserSession()->getUser(); |
|
1150 | - if (!$user) { |
|
1151 | - return null; |
|
1152 | - } |
|
1153 | - $userId = $user->getUID(); |
|
1154 | - } |
|
1155 | - $root = $this->getRootFolder(); |
|
1156 | - return $root->getUserFolder($userId); |
|
1157 | - } |
|
1158 | - |
|
1159 | - /** |
|
1160 | - * Returns an app-specific view in ownClouds data directory |
|
1161 | - * |
|
1162 | - * @return \OCP\Files\Folder |
|
1163 | - * @deprecated since 9.2.0 use IAppData |
|
1164 | - */ |
|
1165 | - public function getAppFolder() { |
|
1166 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1167 | - $root = $this->getRootFolder(); |
|
1168 | - if (!$root->nodeExists($dir)) { |
|
1169 | - $folder = $root->newFolder($dir); |
|
1170 | - } else { |
|
1171 | - $folder = $root->get($dir); |
|
1172 | - } |
|
1173 | - return $folder; |
|
1174 | - } |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * @return \OC\User\Manager |
|
1178 | - */ |
|
1179 | - public function getUserManager() { |
|
1180 | - return $this->query('UserManager'); |
|
1181 | - } |
|
1182 | - |
|
1183 | - /** |
|
1184 | - * @return \OC\Group\Manager |
|
1185 | - */ |
|
1186 | - public function getGroupManager() { |
|
1187 | - return $this->query('GroupManager'); |
|
1188 | - } |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * @return \OC\User\Session |
|
1192 | - */ |
|
1193 | - public function getUserSession() { |
|
1194 | - return $this->query('UserSession'); |
|
1195 | - } |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * @return \OCP\ISession |
|
1199 | - */ |
|
1200 | - public function getSession() { |
|
1201 | - return $this->query('UserSession')->getSession(); |
|
1202 | - } |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * @param \OCP\ISession $session |
|
1206 | - */ |
|
1207 | - public function setSession(\OCP\ISession $session) { |
|
1208 | - $this->query(SessionStorage::class)->setSession($session); |
|
1209 | - $this->query('UserSession')->setSession($session); |
|
1210 | - $this->query(Store::class)->setSession($session); |
|
1211 | - } |
|
1212 | - |
|
1213 | - /** |
|
1214 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1215 | - */ |
|
1216 | - public function getTwoFactorAuthManager() { |
|
1217 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * @return \OC\NavigationManager |
|
1222 | - */ |
|
1223 | - public function getNavigationManager() { |
|
1224 | - return $this->query('NavigationManager'); |
|
1225 | - } |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * @return \OCP\IConfig |
|
1229 | - */ |
|
1230 | - public function getConfig() { |
|
1231 | - return $this->query('AllConfig'); |
|
1232 | - } |
|
1233 | - |
|
1234 | - /** |
|
1235 | - * @internal For internal use only |
|
1236 | - * @return \OC\SystemConfig |
|
1237 | - */ |
|
1238 | - public function getSystemConfig() { |
|
1239 | - return $this->query('SystemConfig'); |
|
1240 | - } |
|
1241 | - |
|
1242 | - /** |
|
1243 | - * Returns the app config manager |
|
1244 | - * |
|
1245 | - * @return \OCP\IAppConfig |
|
1246 | - */ |
|
1247 | - public function getAppConfig() { |
|
1248 | - return $this->query('AppConfig'); |
|
1249 | - } |
|
1250 | - |
|
1251 | - /** |
|
1252 | - * @return \OCP\L10N\IFactory |
|
1253 | - */ |
|
1254 | - public function getL10NFactory() { |
|
1255 | - return $this->query('L10NFactory'); |
|
1256 | - } |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * get an L10N instance |
|
1260 | - * |
|
1261 | - * @param string $app appid |
|
1262 | - * @param string $lang |
|
1263 | - * @return IL10N |
|
1264 | - */ |
|
1265 | - public function getL10N($app, $lang = null) { |
|
1266 | - return $this->getL10NFactory()->get($app, $lang); |
|
1267 | - } |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * @return \OCP\IURLGenerator |
|
1271 | - */ |
|
1272 | - public function getURLGenerator() { |
|
1273 | - return $this->query('URLGenerator'); |
|
1274 | - } |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * @return \OCP\IHelper |
|
1278 | - */ |
|
1279 | - public function getHelper() { |
|
1280 | - return $this->query('AppHelper'); |
|
1281 | - } |
|
1282 | - |
|
1283 | - /** |
|
1284 | - * @return AppFetcher |
|
1285 | - */ |
|
1286 | - public function getAppFetcher() { |
|
1287 | - return $this->query(AppFetcher::class); |
|
1288 | - } |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1292 | - * getMemCacheFactory() instead. |
|
1293 | - * |
|
1294 | - * @return \OCP\ICache |
|
1295 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1296 | - */ |
|
1297 | - public function getCache() { |
|
1298 | - return $this->query('UserCache'); |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Returns an \OCP\CacheFactory instance |
|
1303 | - * |
|
1304 | - * @return \OCP\ICacheFactory |
|
1305 | - */ |
|
1306 | - public function getMemCacheFactory() { |
|
1307 | - return $this->query('MemCacheFactory'); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Returns an \OC\RedisFactory instance |
|
1312 | - * |
|
1313 | - * @return \OC\RedisFactory |
|
1314 | - */ |
|
1315 | - public function getGetRedisFactory() { |
|
1316 | - return $this->query('RedisFactory'); |
|
1317 | - } |
|
1318 | - |
|
1319 | - |
|
1320 | - /** |
|
1321 | - * Returns the current session |
|
1322 | - * |
|
1323 | - * @return \OCP\IDBConnection |
|
1324 | - */ |
|
1325 | - public function getDatabaseConnection() { |
|
1326 | - return $this->query('DatabaseConnection'); |
|
1327 | - } |
|
1328 | - |
|
1329 | - /** |
|
1330 | - * Returns the activity manager |
|
1331 | - * |
|
1332 | - * @return \OCP\Activity\IManager |
|
1333 | - */ |
|
1334 | - public function getActivityManager() { |
|
1335 | - return $this->query('ActivityManager'); |
|
1336 | - } |
|
1337 | - |
|
1338 | - /** |
|
1339 | - * Returns an job list for controlling background jobs |
|
1340 | - * |
|
1341 | - * @return \OCP\BackgroundJob\IJobList |
|
1342 | - */ |
|
1343 | - public function getJobList() { |
|
1344 | - return $this->query('JobList'); |
|
1345 | - } |
|
1346 | - |
|
1347 | - /** |
|
1348 | - * Returns a logger instance |
|
1349 | - * |
|
1350 | - * @return \OCP\ILogger |
|
1351 | - */ |
|
1352 | - public function getLogger() { |
|
1353 | - return $this->query('Logger'); |
|
1354 | - } |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * Returns a router for generating and matching urls |
|
1358 | - * |
|
1359 | - * @return \OCP\Route\IRouter |
|
1360 | - */ |
|
1361 | - public function getRouter() { |
|
1362 | - return $this->query('Router'); |
|
1363 | - } |
|
1364 | - |
|
1365 | - /** |
|
1366 | - * Returns a search instance |
|
1367 | - * |
|
1368 | - * @return \OCP\ISearch |
|
1369 | - */ |
|
1370 | - public function getSearch() { |
|
1371 | - return $this->query('Search'); |
|
1372 | - } |
|
1373 | - |
|
1374 | - /** |
|
1375 | - * Returns a SecureRandom instance |
|
1376 | - * |
|
1377 | - * @return \OCP\Security\ISecureRandom |
|
1378 | - */ |
|
1379 | - public function getSecureRandom() { |
|
1380 | - return $this->query('SecureRandom'); |
|
1381 | - } |
|
1382 | - |
|
1383 | - /** |
|
1384 | - * Returns a Crypto instance |
|
1385 | - * |
|
1386 | - * @return \OCP\Security\ICrypto |
|
1387 | - */ |
|
1388 | - public function getCrypto() { |
|
1389 | - return $this->query('Crypto'); |
|
1390 | - } |
|
1391 | - |
|
1392 | - /** |
|
1393 | - * Returns a Hasher instance |
|
1394 | - * |
|
1395 | - * @return \OCP\Security\IHasher |
|
1396 | - */ |
|
1397 | - public function getHasher() { |
|
1398 | - return $this->query('Hasher'); |
|
1399 | - } |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * Returns a CredentialsManager instance |
|
1403 | - * |
|
1404 | - * @return \OCP\Security\ICredentialsManager |
|
1405 | - */ |
|
1406 | - public function getCredentialsManager() { |
|
1407 | - return $this->query('CredentialsManager'); |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * Returns an instance of the HTTP helper class |
|
1412 | - * |
|
1413 | - * @deprecated Use getHTTPClientService() |
|
1414 | - * @return \OC\HTTPHelper |
|
1415 | - */ |
|
1416 | - public function getHTTPHelper() { |
|
1417 | - return $this->query('HTTPHelper'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * Get the certificate manager for the user |
|
1422 | - * |
|
1423 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1424 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1425 | - */ |
|
1426 | - public function getCertificateManager($userId = '') { |
|
1427 | - if ($userId === '') { |
|
1428 | - $userSession = $this->getUserSession(); |
|
1429 | - $user = $userSession->getUser(); |
|
1430 | - if (is_null($user)) { |
|
1431 | - return null; |
|
1432 | - } |
|
1433 | - $userId = $user->getUID(); |
|
1434 | - } |
|
1435 | - return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1436 | - } |
|
1437 | - |
|
1438 | - /** |
|
1439 | - * Returns an instance of the HTTP client service |
|
1440 | - * |
|
1441 | - * @return \OCP\Http\Client\IClientService |
|
1442 | - */ |
|
1443 | - public function getHTTPClientService() { |
|
1444 | - return $this->query('HttpClientService'); |
|
1445 | - } |
|
1446 | - |
|
1447 | - /** |
|
1448 | - * Create a new event source |
|
1449 | - * |
|
1450 | - * @return \OCP\IEventSource |
|
1451 | - */ |
|
1452 | - public function createEventSource() { |
|
1453 | - return new \OC_EventSource(); |
|
1454 | - } |
|
1455 | - |
|
1456 | - /** |
|
1457 | - * Get the active event logger |
|
1458 | - * |
|
1459 | - * The returned logger only logs data when debug mode is enabled |
|
1460 | - * |
|
1461 | - * @return \OCP\Diagnostics\IEventLogger |
|
1462 | - */ |
|
1463 | - public function getEventLogger() { |
|
1464 | - return $this->query('EventLogger'); |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Get the active query logger |
|
1469 | - * |
|
1470 | - * The returned logger only logs data when debug mode is enabled |
|
1471 | - * |
|
1472 | - * @return \OCP\Diagnostics\IQueryLogger |
|
1473 | - */ |
|
1474 | - public function getQueryLogger() { |
|
1475 | - return $this->query('QueryLogger'); |
|
1476 | - } |
|
1477 | - |
|
1478 | - /** |
|
1479 | - * Get the manager for temporary files and folders |
|
1480 | - * |
|
1481 | - * @return \OCP\ITempManager |
|
1482 | - */ |
|
1483 | - public function getTempManager() { |
|
1484 | - return $this->query('TempManager'); |
|
1485 | - } |
|
1486 | - |
|
1487 | - /** |
|
1488 | - * Get the app manager |
|
1489 | - * |
|
1490 | - * @return \OCP\App\IAppManager |
|
1491 | - */ |
|
1492 | - public function getAppManager() { |
|
1493 | - return $this->query('AppManager'); |
|
1494 | - } |
|
1495 | - |
|
1496 | - /** |
|
1497 | - * Creates a new mailer |
|
1498 | - * |
|
1499 | - * @return \OCP\Mail\IMailer |
|
1500 | - */ |
|
1501 | - public function getMailer() { |
|
1502 | - return $this->query('Mailer'); |
|
1503 | - } |
|
1504 | - |
|
1505 | - /** |
|
1506 | - * Get the webroot |
|
1507 | - * |
|
1508 | - * @return string |
|
1509 | - */ |
|
1510 | - public function getWebRoot() { |
|
1511 | - return $this->webRoot; |
|
1512 | - } |
|
1513 | - |
|
1514 | - /** |
|
1515 | - * @return \OC\OCSClient |
|
1516 | - */ |
|
1517 | - public function getOcsClient() { |
|
1518 | - return $this->query('OcsClient'); |
|
1519 | - } |
|
1520 | - |
|
1521 | - /** |
|
1522 | - * @return \OCP\IDateTimeZone |
|
1523 | - */ |
|
1524 | - public function getDateTimeZone() { |
|
1525 | - return $this->query('DateTimeZone'); |
|
1526 | - } |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * @return \OCP\IDateTimeFormatter |
|
1530 | - */ |
|
1531 | - public function getDateTimeFormatter() { |
|
1532 | - return $this->query('DateTimeFormatter'); |
|
1533 | - } |
|
1534 | - |
|
1535 | - /** |
|
1536 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
1537 | - */ |
|
1538 | - public function getMountProviderCollection() { |
|
1539 | - return $this->query('MountConfigManager'); |
|
1540 | - } |
|
1541 | - |
|
1542 | - /** |
|
1543 | - * Get the IniWrapper |
|
1544 | - * |
|
1545 | - * @return IniGetWrapper |
|
1546 | - */ |
|
1547 | - public function getIniWrapper() { |
|
1548 | - return $this->query('IniWrapper'); |
|
1549 | - } |
|
1550 | - |
|
1551 | - /** |
|
1552 | - * @return \OCP\Command\IBus |
|
1553 | - */ |
|
1554 | - public function getCommandBus() { |
|
1555 | - return $this->query('AsyncCommandBus'); |
|
1556 | - } |
|
1557 | - |
|
1558 | - /** |
|
1559 | - * Get the trusted domain helper |
|
1560 | - * |
|
1561 | - * @return TrustedDomainHelper |
|
1562 | - */ |
|
1563 | - public function getTrustedDomainHelper() { |
|
1564 | - return $this->query('TrustedDomainHelper'); |
|
1565 | - } |
|
1566 | - |
|
1567 | - /** |
|
1568 | - * Get the locking provider |
|
1569 | - * |
|
1570 | - * @return \OCP\Lock\ILockingProvider |
|
1571 | - * @since 8.1.0 |
|
1572 | - */ |
|
1573 | - public function getLockingProvider() { |
|
1574 | - return $this->query('LockingProvider'); |
|
1575 | - } |
|
1576 | - |
|
1577 | - /** |
|
1578 | - * @return \OCP\Files\Mount\IMountManager |
|
1579 | - **/ |
|
1580 | - function getMountManager() { |
|
1581 | - return $this->query('MountManager'); |
|
1582 | - } |
|
1583 | - |
|
1584 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
1585 | - function getUserMountCache() { |
|
1586 | - return $this->query('UserMountCache'); |
|
1587 | - } |
|
1588 | - |
|
1589 | - /** |
|
1590 | - * Get the MimeTypeDetector |
|
1591 | - * |
|
1592 | - * @return \OCP\Files\IMimeTypeDetector |
|
1593 | - */ |
|
1594 | - public function getMimeTypeDetector() { |
|
1595 | - return $this->query('MimeTypeDetector'); |
|
1596 | - } |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * Get the MimeTypeLoader |
|
1600 | - * |
|
1601 | - * @return \OCP\Files\IMimeTypeLoader |
|
1602 | - */ |
|
1603 | - public function getMimeTypeLoader() { |
|
1604 | - return $this->query('MimeTypeLoader'); |
|
1605 | - } |
|
1606 | - |
|
1607 | - /** |
|
1608 | - * Get the manager of all the capabilities |
|
1609 | - * |
|
1610 | - * @return \OC\CapabilitiesManager |
|
1611 | - */ |
|
1612 | - public function getCapabilitiesManager() { |
|
1613 | - return $this->query('CapabilitiesManager'); |
|
1614 | - } |
|
1615 | - |
|
1616 | - /** |
|
1617 | - * Get the EventDispatcher |
|
1618 | - * |
|
1619 | - * @return EventDispatcherInterface |
|
1620 | - * @since 8.2.0 |
|
1621 | - */ |
|
1622 | - public function getEventDispatcher() { |
|
1623 | - return $this->query('EventDispatcher'); |
|
1624 | - } |
|
1625 | - |
|
1626 | - /** |
|
1627 | - * Get the Notification Manager |
|
1628 | - * |
|
1629 | - * @return \OCP\Notification\IManager |
|
1630 | - * @since 8.2.0 |
|
1631 | - */ |
|
1632 | - public function getNotificationManager() { |
|
1633 | - return $this->query('NotificationManager'); |
|
1634 | - } |
|
1635 | - |
|
1636 | - /** |
|
1637 | - * @return \OCP\Comments\ICommentsManager |
|
1638 | - */ |
|
1639 | - public function getCommentsManager() { |
|
1640 | - return $this->query('CommentsManager'); |
|
1641 | - } |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * @return \OCA\Theming\ThemingDefaults |
|
1645 | - */ |
|
1646 | - public function getThemingDefaults() { |
|
1647 | - return $this->query('ThemingDefaults'); |
|
1648 | - } |
|
1649 | - |
|
1650 | - /** |
|
1651 | - * @return \OC\IntegrityCheck\Checker |
|
1652 | - */ |
|
1653 | - public function getIntegrityCodeChecker() { |
|
1654 | - return $this->query('IntegrityCodeChecker'); |
|
1655 | - } |
|
1656 | - |
|
1657 | - /** |
|
1658 | - * @return \OC\Session\CryptoWrapper |
|
1659 | - */ |
|
1660 | - public function getSessionCryptoWrapper() { |
|
1661 | - return $this->query('CryptoWrapper'); |
|
1662 | - } |
|
1663 | - |
|
1664 | - /** |
|
1665 | - * @return CsrfTokenManager |
|
1666 | - */ |
|
1667 | - public function getCsrfTokenManager() { |
|
1668 | - return $this->query('CsrfTokenManager'); |
|
1669 | - } |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * @return Throttler |
|
1673 | - */ |
|
1674 | - public function getBruteForceThrottler() { |
|
1675 | - return $this->query('Throttler'); |
|
1676 | - } |
|
1677 | - |
|
1678 | - /** |
|
1679 | - * @return IContentSecurityPolicyManager |
|
1680 | - */ |
|
1681 | - public function getContentSecurityPolicyManager() { |
|
1682 | - return $this->query('ContentSecurityPolicyManager'); |
|
1683 | - } |
|
1684 | - |
|
1685 | - /** |
|
1686 | - * @return ContentSecurityPolicyNonceManager |
|
1687 | - */ |
|
1688 | - public function getContentSecurityPolicyNonceManager() { |
|
1689 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
1690 | - } |
|
1691 | - |
|
1692 | - /** |
|
1693 | - * Not a public API as of 8.2, wait for 9.0 |
|
1694 | - * |
|
1695 | - * @return \OCA\Files_External\Service\BackendService |
|
1696 | - */ |
|
1697 | - public function getStoragesBackendService() { |
|
1698 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1699 | - } |
|
1700 | - |
|
1701 | - /** |
|
1702 | - * Not a public API as of 8.2, wait for 9.0 |
|
1703 | - * |
|
1704 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1705 | - */ |
|
1706 | - public function getGlobalStoragesService() { |
|
1707 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1708 | - } |
|
1709 | - |
|
1710 | - /** |
|
1711 | - * Not a public API as of 8.2, wait for 9.0 |
|
1712 | - * |
|
1713 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1714 | - */ |
|
1715 | - public function getUserGlobalStoragesService() { |
|
1716 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1717 | - } |
|
1718 | - |
|
1719 | - /** |
|
1720 | - * Not a public API as of 8.2, wait for 9.0 |
|
1721 | - * |
|
1722 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
1723 | - */ |
|
1724 | - public function getUserStoragesService() { |
|
1725 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1726 | - } |
|
1727 | - |
|
1728 | - /** |
|
1729 | - * @return \OCP\Share\IManager |
|
1730 | - */ |
|
1731 | - public function getShareManager() { |
|
1732 | - return $this->query('ShareManager'); |
|
1733 | - } |
|
1734 | - |
|
1735 | - /** |
|
1736 | - * Returns the LDAP Provider |
|
1737 | - * |
|
1738 | - * @return \OCP\LDAP\ILDAPProvider |
|
1739 | - */ |
|
1740 | - public function getLDAPProvider() { |
|
1741 | - return $this->query('LDAPProvider'); |
|
1742 | - } |
|
1743 | - |
|
1744 | - /** |
|
1745 | - * @return \OCP\Settings\IManager |
|
1746 | - */ |
|
1747 | - public function getSettingsManager() { |
|
1748 | - return $this->query('SettingsManager'); |
|
1749 | - } |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * @return \OCP\Files\IAppData |
|
1753 | - */ |
|
1754 | - public function getAppDataDir($app) { |
|
1755 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
1756 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1757 | - return $factory->get($app); |
|
1758 | - } |
|
1759 | - |
|
1760 | - /** |
|
1761 | - * @return \OCP\Lockdown\ILockdownManager |
|
1762 | - */ |
|
1763 | - public function getLockdownManager() { |
|
1764 | - return $this->query('LockdownManager'); |
|
1765 | - } |
|
1766 | - |
|
1767 | - /** |
|
1768 | - * @return \OCP\Federation\ICloudIdManager |
|
1769 | - */ |
|
1770 | - public function getCloudIdManager() { |
|
1771 | - return $this->query(ICloudIdManager::class); |
|
1772 | - } |
|
852 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
853 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
854 | + $classExists = true; |
|
855 | + } else { |
|
856 | + $classExists = false; |
|
857 | + } |
|
858 | + |
|
859 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
|
860 | + return new ThemingDefaults( |
|
861 | + $c->getConfig(), |
|
862 | + $c->getL10N('theming'), |
|
863 | + $c->getURLGenerator(), |
|
864 | + $c->getAppDataDir('theming'), |
|
865 | + $c->getMemCacheFactory(), |
|
866 | + new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')) |
|
867 | + ); |
|
868 | + } |
|
869 | + return new \OC_Defaults(); |
|
870 | + }); |
|
871 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
872 | + /** @var Factory $cacheFactory */ |
|
873 | + $cacheFactory = $c->query(Factory::class); |
|
874 | + return new SCSSCacher( |
|
875 | + $c->getLogger(), |
|
876 | + $c->query(\OC\Files\AppData\Factory::class), |
|
877 | + $c->getURLGenerator(), |
|
878 | + $c->getConfig(), |
|
879 | + $c->getThemingDefaults(), |
|
880 | + \OC::$SERVERROOT, |
|
881 | + $cacheFactory->create('SCSS') |
|
882 | + ); |
|
883 | + }); |
|
884 | + $this->registerService(EventDispatcher::class, function () { |
|
885 | + return new EventDispatcher(); |
|
886 | + }); |
|
887 | + $this->registerAlias('EventDispatcher', EventDispatcher::class); |
|
888 | + $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
|
889 | + |
|
890 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
891 | + // FIXME: Instantiiated here due to cyclic dependency |
|
892 | + $request = new Request( |
|
893 | + [ |
|
894 | + 'get' => $_GET, |
|
895 | + 'post' => $_POST, |
|
896 | + 'files' => $_FILES, |
|
897 | + 'server' => $_SERVER, |
|
898 | + 'env' => $_ENV, |
|
899 | + 'cookies' => $_COOKIE, |
|
900 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
901 | + ? $_SERVER['REQUEST_METHOD'] |
|
902 | + : null, |
|
903 | + ], |
|
904 | + $c->getSecureRandom(), |
|
905 | + $c->getConfig() |
|
906 | + ); |
|
907 | + |
|
908 | + return new CryptoWrapper( |
|
909 | + $c->getConfig(), |
|
910 | + $c->getCrypto(), |
|
911 | + $c->getSecureRandom(), |
|
912 | + $request |
|
913 | + ); |
|
914 | + }); |
|
915 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
916 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
917 | + |
|
918 | + return new CsrfTokenManager( |
|
919 | + $tokenGenerator, |
|
920 | + $c->query(SessionStorage::class) |
|
921 | + ); |
|
922 | + }); |
|
923 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
924 | + return new SessionStorage($c->getSession()); |
|
925 | + }); |
|
926 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
927 | + return new ContentSecurityPolicyManager(); |
|
928 | + }); |
|
929 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
930 | + |
|
931 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
932 | + return new ContentSecurityPolicyNonceManager( |
|
933 | + $c->getCsrfTokenManager(), |
|
934 | + $c->getRequest() |
|
935 | + ); |
|
936 | + }); |
|
937 | + |
|
938 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
939 | + $config = $c->getConfig(); |
|
940 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
|
941 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
942 | + $factory = new $factoryClass($this); |
|
943 | + |
|
944 | + $manager = new \OC\Share20\Manager( |
|
945 | + $c->getLogger(), |
|
946 | + $c->getConfig(), |
|
947 | + $c->getSecureRandom(), |
|
948 | + $c->getHasher(), |
|
949 | + $c->getMountManager(), |
|
950 | + $c->getGroupManager(), |
|
951 | + $c->getL10N('core'), |
|
952 | + $factory, |
|
953 | + $c->getUserManager(), |
|
954 | + $c->getLazyRootFolder(), |
|
955 | + $c->getEventDispatcher() |
|
956 | + ); |
|
957 | + |
|
958 | + return $manager; |
|
959 | + }); |
|
960 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
961 | + |
|
962 | + $this->registerService('SettingsManager', function(Server $c) { |
|
963 | + $manager = new \OC\Settings\Manager( |
|
964 | + $c->getLogger(), |
|
965 | + $c->getDatabaseConnection(), |
|
966 | + $c->getL10N('lib'), |
|
967 | + $c->getConfig(), |
|
968 | + $c->getEncryptionManager(), |
|
969 | + $c->getUserManager(), |
|
970 | + $c->getLockingProvider(), |
|
971 | + $c->getRequest(), |
|
972 | + new \OC\Settings\Mapper($c->getDatabaseConnection()), |
|
973 | + $c->getURLGenerator() |
|
974 | + ); |
|
975 | + return $manager; |
|
976 | + }); |
|
977 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
978 | + return new \OC\Files\AppData\Factory( |
|
979 | + $c->getRootFolder(), |
|
980 | + $c->getSystemConfig() |
|
981 | + ); |
|
982 | + }); |
|
983 | + |
|
984 | + $this->registerService('LockdownManager', function (Server $c) { |
|
985 | + return new LockdownManager(function() use ($c) { |
|
986 | + return $c->getSession(); |
|
987 | + }); |
|
988 | + }); |
|
989 | + |
|
990 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
991 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
992 | + }); |
|
993 | + |
|
994 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
995 | + return new CloudIdManager(); |
|
996 | + }); |
|
997 | + |
|
998 | + /* To trick DI since we don't extend the DIContainer here */ |
|
999 | + $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
1000 | + return new CleanPreviewsBackgroundJob( |
|
1001 | + $c->getRootFolder(), |
|
1002 | + $c->getLogger(), |
|
1003 | + $c->getJobList(), |
|
1004 | + new TimeFactory() |
|
1005 | + ); |
|
1006 | + }); |
|
1007 | + |
|
1008 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1009 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1010 | + |
|
1011 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1012 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1013 | + |
|
1014 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1015 | + return new Defaults( |
|
1016 | + $c->getThemingDefaults() |
|
1017 | + ); |
|
1018 | + }); |
|
1019 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
1020 | + |
|
1021 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
1022 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
1023 | + }); |
|
1024 | + |
|
1025 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
1026 | + return new ShareHelper( |
|
1027 | + $c->query(\OCP\Share\IManager::class) |
|
1028 | + ); |
|
1029 | + }); |
|
1030 | + } |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * @return \OCP\Contacts\IManager |
|
1034 | + */ |
|
1035 | + public function getContactsManager() { |
|
1036 | + return $this->query('ContactsManager'); |
|
1037 | + } |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * @return \OC\Encryption\Manager |
|
1041 | + */ |
|
1042 | + public function getEncryptionManager() { |
|
1043 | + return $this->query('EncryptionManager'); |
|
1044 | + } |
|
1045 | + |
|
1046 | + /** |
|
1047 | + * @return \OC\Encryption\File |
|
1048 | + */ |
|
1049 | + public function getEncryptionFilesHelper() { |
|
1050 | + return $this->query('EncryptionFileHelper'); |
|
1051 | + } |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * @return \OCP\Encryption\Keys\IStorage |
|
1055 | + */ |
|
1056 | + public function getEncryptionKeyStorage() { |
|
1057 | + return $this->query('EncryptionKeyStorage'); |
|
1058 | + } |
|
1059 | + |
|
1060 | + /** |
|
1061 | + * The current request object holding all information about the request |
|
1062 | + * currently being processed is returned from this method. |
|
1063 | + * In case the current execution was not initiated by a web request null is returned |
|
1064 | + * |
|
1065 | + * @return \OCP\IRequest |
|
1066 | + */ |
|
1067 | + public function getRequest() { |
|
1068 | + return $this->query('Request'); |
|
1069 | + } |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * Returns the preview manager which can create preview images for a given file |
|
1073 | + * |
|
1074 | + * @return \OCP\IPreview |
|
1075 | + */ |
|
1076 | + public function getPreviewManager() { |
|
1077 | + return $this->query('PreviewManager'); |
|
1078 | + } |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * Returns the tag manager which can get and set tags for different object types |
|
1082 | + * |
|
1083 | + * @see \OCP\ITagManager::load() |
|
1084 | + * @return \OCP\ITagManager |
|
1085 | + */ |
|
1086 | + public function getTagManager() { |
|
1087 | + return $this->query('TagManager'); |
|
1088 | + } |
|
1089 | + |
|
1090 | + /** |
|
1091 | + * Returns the system-tag manager |
|
1092 | + * |
|
1093 | + * @return \OCP\SystemTag\ISystemTagManager |
|
1094 | + * |
|
1095 | + * @since 9.0.0 |
|
1096 | + */ |
|
1097 | + public function getSystemTagManager() { |
|
1098 | + return $this->query('SystemTagManager'); |
|
1099 | + } |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Returns the system-tag object mapper |
|
1103 | + * |
|
1104 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
1105 | + * |
|
1106 | + * @since 9.0.0 |
|
1107 | + */ |
|
1108 | + public function getSystemTagObjectMapper() { |
|
1109 | + return $this->query('SystemTagObjectMapper'); |
|
1110 | + } |
|
1111 | + |
|
1112 | + /** |
|
1113 | + * Returns the avatar manager, used for avatar functionality |
|
1114 | + * |
|
1115 | + * @return \OCP\IAvatarManager |
|
1116 | + */ |
|
1117 | + public function getAvatarManager() { |
|
1118 | + return $this->query('AvatarManager'); |
|
1119 | + } |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * Returns the root folder of ownCloud's data directory |
|
1123 | + * |
|
1124 | + * @return \OCP\Files\IRootFolder |
|
1125 | + */ |
|
1126 | + public function getRootFolder() { |
|
1127 | + return $this->query('LazyRootFolder'); |
|
1128 | + } |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * Returns the root folder of ownCloud's data directory |
|
1132 | + * This is the lazy variant so this gets only initialized once it |
|
1133 | + * is actually used. |
|
1134 | + * |
|
1135 | + * @return \OCP\Files\IRootFolder |
|
1136 | + */ |
|
1137 | + public function getLazyRootFolder() { |
|
1138 | + return $this->query('LazyRootFolder'); |
|
1139 | + } |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Returns a view to ownCloud's files folder |
|
1143 | + * |
|
1144 | + * @param string $userId user ID |
|
1145 | + * @return \OCP\Files\Folder|null |
|
1146 | + */ |
|
1147 | + public function getUserFolder($userId = null) { |
|
1148 | + if ($userId === null) { |
|
1149 | + $user = $this->getUserSession()->getUser(); |
|
1150 | + if (!$user) { |
|
1151 | + return null; |
|
1152 | + } |
|
1153 | + $userId = $user->getUID(); |
|
1154 | + } |
|
1155 | + $root = $this->getRootFolder(); |
|
1156 | + return $root->getUserFolder($userId); |
|
1157 | + } |
|
1158 | + |
|
1159 | + /** |
|
1160 | + * Returns an app-specific view in ownClouds data directory |
|
1161 | + * |
|
1162 | + * @return \OCP\Files\Folder |
|
1163 | + * @deprecated since 9.2.0 use IAppData |
|
1164 | + */ |
|
1165 | + public function getAppFolder() { |
|
1166 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
1167 | + $root = $this->getRootFolder(); |
|
1168 | + if (!$root->nodeExists($dir)) { |
|
1169 | + $folder = $root->newFolder($dir); |
|
1170 | + } else { |
|
1171 | + $folder = $root->get($dir); |
|
1172 | + } |
|
1173 | + return $folder; |
|
1174 | + } |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * @return \OC\User\Manager |
|
1178 | + */ |
|
1179 | + public function getUserManager() { |
|
1180 | + return $this->query('UserManager'); |
|
1181 | + } |
|
1182 | + |
|
1183 | + /** |
|
1184 | + * @return \OC\Group\Manager |
|
1185 | + */ |
|
1186 | + public function getGroupManager() { |
|
1187 | + return $this->query('GroupManager'); |
|
1188 | + } |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * @return \OC\User\Session |
|
1192 | + */ |
|
1193 | + public function getUserSession() { |
|
1194 | + return $this->query('UserSession'); |
|
1195 | + } |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * @return \OCP\ISession |
|
1199 | + */ |
|
1200 | + public function getSession() { |
|
1201 | + return $this->query('UserSession')->getSession(); |
|
1202 | + } |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * @param \OCP\ISession $session |
|
1206 | + */ |
|
1207 | + public function setSession(\OCP\ISession $session) { |
|
1208 | + $this->query(SessionStorage::class)->setSession($session); |
|
1209 | + $this->query('UserSession')->setSession($session); |
|
1210 | + $this->query(Store::class)->setSession($session); |
|
1211 | + } |
|
1212 | + |
|
1213 | + /** |
|
1214 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1215 | + */ |
|
1216 | + public function getTwoFactorAuthManager() { |
|
1217 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * @return \OC\NavigationManager |
|
1222 | + */ |
|
1223 | + public function getNavigationManager() { |
|
1224 | + return $this->query('NavigationManager'); |
|
1225 | + } |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * @return \OCP\IConfig |
|
1229 | + */ |
|
1230 | + public function getConfig() { |
|
1231 | + return $this->query('AllConfig'); |
|
1232 | + } |
|
1233 | + |
|
1234 | + /** |
|
1235 | + * @internal For internal use only |
|
1236 | + * @return \OC\SystemConfig |
|
1237 | + */ |
|
1238 | + public function getSystemConfig() { |
|
1239 | + return $this->query('SystemConfig'); |
|
1240 | + } |
|
1241 | + |
|
1242 | + /** |
|
1243 | + * Returns the app config manager |
|
1244 | + * |
|
1245 | + * @return \OCP\IAppConfig |
|
1246 | + */ |
|
1247 | + public function getAppConfig() { |
|
1248 | + return $this->query('AppConfig'); |
|
1249 | + } |
|
1250 | + |
|
1251 | + /** |
|
1252 | + * @return \OCP\L10N\IFactory |
|
1253 | + */ |
|
1254 | + public function getL10NFactory() { |
|
1255 | + return $this->query('L10NFactory'); |
|
1256 | + } |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * get an L10N instance |
|
1260 | + * |
|
1261 | + * @param string $app appid |
|
1262 | + * @param string $lang |
|
1263 | + * @return IL10N |
|
1264 | + */ |
|
1265 | + public function getL10N($app, $lang = null) { |
|
1266 | + return $this->getL10NFactory()->get($app, $lang); |
|
1267 | + } |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * @return \OCP\IURLGenerator |
|
1271 | + */ |
|
1272 | + public function getURLGenerator() { |
|
1273 | + return $this->query('URLGenerator'); |
|
1274 | + } |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * @return \OCP\IHelper |
|
1278 | + */ |
|
1279 | + public function getHelper() { |
|
1280 | + return $this->query('AppHelper'); |
|
1281 | + } |
|
1282 | + |
|
1283 | + /** |
|
1284 | + * @return AppFetcher |
|
1285 | + */ |
|
1286 | + public function getAppFetcher() { |
|
1287 | + return $this->query(AppFetcher::class); |
|
1288 | + } |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1292 | + * getMemCacheFactory() instead. |
|
1293 | + * |
|
1294 | + * @return \OCP\ICache |
|
1295 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1296 | + */ |
|
1297 | + public function getCache() { |
|
1298 | + return $this->query('UserCache'); |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Returns an \OCP\CacheFactory instance |
|
1303 | + * |
|
1304 | + * @return \OCP\ICacheFactory |
|
1305 | + */ |
|
1306 | + public function getMemCacheFactory() { |
|
1307 | + return $this->query('MemCacheFactory'); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Returns an \OC\RedisFactory instance |
|
1312 | + * |
|
1313 | + * @return \OC\RedisFactory |
|
1314 | + */ |
|
1315 | + public function getGetRedisFactory() { |
|
1316 | + return $this->query('RedisFactory'); |
|
1317 | + } |
|
1318 | + |
|
1319 | + |
|
1320 | + /** |
|
1321 | + * Returns the current session |
|
1322 | + * |
|
1323 | + * @return \OCP\IDBConnection |
|
1324 | + */ |
|
1325 | + public function getDatabaseConnection() { |
|
1326 | + return $this->query('DatabaseConnection'); |
|
1327 | + } |
|
1328 | + |
|
1329 | + /** |
|
1330 | + * Returns the activity manager |
|
1331 | + * |
|
1332 | + * @return \OCP\Activity\IManager |
|
1333 | + */ |
|
1334 | + public function getActivityManager() { |
|
1335 | + return $this->query('ActivityManager'); |
|
1336 | + } |
|
1337 | + |
|
1338 | + /** |
|
1339 | + * Returns an job list for controlling background jobs |
|
1340 | + * |
|
1341 | + * @return \OCP\BackgroundJob\IJobList |
|
1342 | + */ |
|
1343 | + public function getJobList() { |
|
1344 | + return $this->query('JobList'); |
|
1345 | + } |
|
1346 | + |
|
1347 | + /** |
|
1348 | + * Returns a logger instance |
|
1349 | + * |
|
1350 | + * @return \OCP\ILogger |
|
1351 | + */ |
|
1352 | + public function getLogger() { |
|
1353 | + return $this->query('Logger'); |
|
1354 | + } |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * Returns a router for generating and matching urls |
|
1358 | + * |
|
1359 | + * @return \OCP\Route\IRouter |
|
1360 | + */ |
|
1361 | + public function getRouter() { |
|
1362 | + return $this->query('Router'); |
|
1363 | + } |
|
1364 | + |
|
1365 | + /** |
|
1366 | + * Returns a search instance |
|
1367 | + * |
|
1368 | + * @return \OCP\ISearch |
|
1369 | + */ |
|
1370 | + public function getSearch() { |
|
1371 | + return $this->query('Search'); |
|
1372 | + } |
|
1373 | + |
|
1374 | + /** |
|
1375 | + * Returns a SecureRandom instance |
|
1376 | + * |
|
1377 | + * @return \OCP\Security\ISecureRandom |
|
1378 | + */ |
|
1379 | + public function getSecureRandom() { |
|
1380 | + return $this->query('SecureRandom'); |
|
1381 | + } |
|
1382 | + |
|
1383 | + /** |
|
1384 | + * Returns a Crypto instance |
|
1385 | + * |
|
1386 | + * @return \OCP\Security\ICrypto |
|
1387 | + */ |
|
1388 | + public function getCrypto() { |
|
1389 | + return $this->query('Crypto'); |
|
1390 | + } |
|
1391 | + |
|
1392 | + /** |
|
1393 | + * Returns a Hasher instance |
|
1394 | + * |
|
1395 | + * @return \OCP\Security\IHasher |
|
1396 | + */ |
|
1397 | + public function getHasher() { |
|
1398 | + return $this->query('Hasher'); |
|
1399 | + } |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * Returns a CredentialsManager instance |
|
1403 | + * |
|
1404 | + * @return \OCP\Security\ICredentialsManager |
|
1405 | + */ |
|
1406 | + public function getCredentialsManager() { |
|
1407 | + return $this->query('CredentialsManager'); |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * Returns an instance of the HTTP helper class |
|
1412 | + * |
|
1413 | + * @deprecated Use getHTTPClientService() |
|
1414 | + * @return \OC\HTTPHelper |
|
1415 | + */ |
|
1416 | + public function getHTTPHelper() { |
|
1417 | + return $this->query('HTTPHelper'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * Get the certificate manager for the user |
|
1422 | + * |
|
1423 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
1424 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
1425 | + */ |
|
1426 | + public function getCertificateManager($userId = '') { |
|
1427 | + if ($userId === '') { |
|
1428 | + $userSession = $this->getUserSession(); |
|
1429 | + $user = $userSession->getUser(); |
|
1430 | + if (is_null($user)) { |
|
1431 | + return null; |
|
1432 | + } |
|
1433 | + $userId = $user->getUID(); |
|
1434 | + } |
|
1435 | + return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger()); |
|
1436 | + } |
|
1437 | + |
|
1438 | + /** |
|
1439 | + * Returns an instance of the HTTP client service |
|
1440 | + * |
|
1441 | + * @return \OCP\Http\Client\IClientService |
|
1442 | + */ |
|
1443 | + public function getHTTPClientService() { |
|
1444 | + return $this->query('HttpClientService'); |
|
1445 | + } |
|
1446 | + |
|
1447 | + /** |
|
1448 | + * Create a new event source |
|
1449 | + * |
|
1450 | + * @return \OCP\IEventSource |
|
1451 | + */ |
|
1452 | + public function createEventSource() { |
|
1453 | + return new \OC_EventSource(); |
|
1454 | + } |
|
1455 | + |
|
1456 | + /** |
|
1457 | + * Get the active event logger |
|
1458 | + * |
|
1459 | + * The returned logger only logs data when debug mode is enabled |
|
1460 | + * |
|
1461 | + * @return \OCP\Diagnostics\IEventLogger |
|
1462 | + */ |
|
1463 | + public function getEventLogger() { |
|
1464 | + return $this->query('EventLogger'); |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Get the active query logger |
|
1469 | + * |
|
1470 | + * The returned logger only logs data when debug mode is enabled |
|
1471 | + * |
|
1472 | + * @return \OCP\Diagnostics\IQueryLogger |
|
1473 | + */ |
|
1474 | + public function getQueryLogger() { |
|
1475 | + return $this->query('QueryLogger'); |
|
1476 | + } |
|
1477 | + |
|
1478 | + /** |
|
1479 | + * Get the manager for temporary files and folders |
|
1480 | + * |
|
1481 | + * @return \OCP\ITempManager |
|
1482 | + */ |
|
1483 | + public function getTempManager() { |
|
1484 | + return $this->query('TempManager'); |
|
1485 | + } |
|
1486 | + |
|
1487 | + /** |
|
1488 | + * Get the app manager |
|
1489 | + * |
|
1490 | + * @return \OCP\App\IAppManager |
|
1491 | + */ |
|
1492 | + public function getAppManager() { |
|
1493 | + return $this->query('AppManager'); |
|
1494 | + } |
|
1495 | + |
|
1496 | + /** |
|
1497 | + * Creates a new mailer |
|
1498 | + * |
|
1499 | + * @return \OCP\Mail\IMailer |
|
1500 | + */ |
|
1501 | + public function getMailer() { |
|
1502 | + return $this->query('Mailer'); |
|
1503 | + } |
|
1504 | + |
|
1505 | + /** |
|
1506 | + * Get the webroot |
|
1507 | + * |
|
1508 | + * @return string |
|
1509 | + */ |
|
1510 | + public function getWebRoot() { |
|
1511 | + return $this->webRoot; |
|
1512 | + } |
|
1513 | + |
|
1514 | + /** |
|
1515 | + * @return \OC\OCSClient |
|
1516 | + */ |
|
1517 | + public function getOcsClient() { |
|
1518 | + return $this->query('OcsClient'); |
|
1519 | + } |
|
1520 | + |
|
1521 | + /** |
|
1522 | + * @return \OCP\IDateTimeZone |
|
1523 | + */ |
|
1524 | + public function getDateTimeZone() { |
|
1525 | + return $this->query('DateTimeZone'); |
|
1526 | + } |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * @return \OCP\IDateTimeFormatter |
|
1530 | + */ |
|
1531 | + public function getDateTimeFormatter() { |
|
1532 | + return $this->query('DateTimeFormatter'); |
|
1533 | + } |
|
1534 | + |
|
1535 | + /** |
|
1536 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
1537 | + */ |
|
1538 | + public function getMountProviderCollection() { |
|
1539 | + return $this->query('MountConfigManager'); |
|
1540 | + } |
|
1541 | + |
|
1542 | + /** |
|
1543 | + * Get the IniWrapper |
|
1544 | + * |
|
1545 | + * @return IniGetWrapper |
|
1546 | + */ |
|
1547 | + public function getIniWrapper() { |
|
1548 | + return $this->query('IniWrapper'); |
|
1549 | + } |
|
1550 | + |
|
1551 | + /** |
|
1552 | + * @return \OCP\Command\IBus |
|
1553 | + */ |
|
1554 | + public function getCommandBus() { |
|
1555 | + return $this->query('AsyncCommandBus'); |
|
1556 | + } |
|
1557 | + |
|
1558 | + /** |
|
1559 | + * Get the trusted domain helper |
|
1560 | + * |
|
1561 | + * @return TrustedDomainHelper |
|
1562 | + */ |
|
1563 | + public function getTrustedDomainHelper() { |
|
1564 | + return $this->query('TrustedDomainHelper'); |
|
1565 | + } |
|
1566 | + |
|
1567 | + /** |
|
1568 | + * Get the locking provider |
|
1569 | + * |
|
1570 | + * @return \OCP\Lock\ILockingProvider |
|
1571 | + * @since 8.1.0 |
|
1572 | + */ |
|
1573 | + public function getLockingProvider() { |
|
1574 | + return $this->query('LockingProvider'); |
|
1575 | + } |
|
1576 | + |
|
1577 | + /** |
|
1578 | + * @return \OCP\Files\Mount\IMountManager |
|
1579 | + **/ |
|
1580 | + function getMountManager() { |
|
1581 | + return $this->query('MountManager'); |
|
1582 | + } |
|
1583 | + |
|
1584 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
1585 | + function getUserMountCache() { |
|
1586 | + return $this->query('UserMountCache'); |
|
1587 | + } |
|
1588 | + |
|
1589 | + /** |
|
1590 | + * Get the MimeTypeDetector |
|
1591 | + * |
|
1592 | + * @return \OCP\Files\IMimeTypeDetector |
|
1593 | + */ |
|
1594 | + public function getMimeTypeDetector() { |
|
1595 | + return $this->query('MimeTypeDetector'); |
|
1596 | + } |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * Get the MimeTypeLoader |
|
1600 | + * |
|
1601 | + * @return \OCP\Files\IMimeTypeLoader |
|
1602 | + */ |
|
1603 | + public function getMimeTypeLoader() { |
|
1604 | + return $this->query('MimeTypeLoader'); |
|
1605 | + } |
|
1606 | + |
|
1607 | + /** |
|
1608 | + * Get the manager of all the capabilities |
|
1609 | + * |
|
1610 | + * @return \OC\CapabilitiesManager |
|
1611 | + */ |
|
1612 | + public function getCapabilitiesManager() { |
|
1613 | + return $this->query('CapabilitiesManager'); |
|
1614 | + } |
|
1615 | + |
|
1616 | + /** |
|
1617 | + * Get the EventDispatcher |
|
1618 | + * |
|
1619 | + * @return EventDispatcherInterface |
|
1620 | + * @since 8.2.0 |
|
1621 | + */ |
|
1622 | + public function getEventDispatcher() { |
|
1623 | + return $this->query('EventDispatcher'); |
|
1624 | + } |
|
1625 | + |
|
1626 | + /** |
|
1627 | + * Get the Notification Manager |
|
1628 | + * |
|
1629 | + * @return \OCP\Notification\IManager |
|
1630 | + * @since 8.2.0 |
|
1631 | + */ |
|
1632 | + public function getNotificationManager() { |
|
1633 | + return $this->query('NotificationManager'); |
|
1634 | + } |
|
1635 | + |
|
1636 | + /** |
|
1637 | + * @return \OCP\Comments\ICommentsManager |
|
1638 | + */ |
|
1639 | + public function getCommentsManager() { |
|
1640 | + return $this->query('CommentsManager'); |
|
1641 | + } |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * @return \OCA\Theming\ThemingDefaults |
|
1645 | + */ |
|
1646 | + public function getThemingDefaults() { |
|
1647 | + return $this->query('ThemingDefaults'); |
|
1648 | + } |
|
1649 | + |
|
1650 | + /** |
|
1651 | + * @return \OC\IntegrityCheck\Checker |
|
1652 | + */ |
|
1653 | + public function getIntegrityCodeChecker() { |
|
1654 | + return $this->query('IntegrityCodeChecker'); |
|
1655 | + } |
|
1656 | + |
|
1657 | + /** |
|
1658 | + * @return \OC\Session\CryptoWrapper |
|
1659 | + */ |
|
1660 | + public function getSessionCryptoWrapper() { |
|
1661 | + return $this->query('CryptoWrapper'); |
|
1662 | + } |
|
1663 | + |
|
1664 | + /** |
|
1665 | + * @return CsrfTokenManager |
|
1666 | + */ |
|
1667 | + public function getCsrfTokenManager() { |
|
1668 | + return $this->query('CsrfTokenManager'); |
|
1669 | + } |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * @return Throttler |
|
1673 | + */ |
|
1674 | + public function getBruteForceThrottler() { |
|
1675 | + return $this->query('Throttler'); |
|
1676 | + } |
|
1677 | + |
|
1678 | + /** |
|
1679 | + * @return IContentSecurityPolicyManager |
|
1680 | + */ |
|
1681 | + public function getContentSecurityPolicyManager() { |
|
1682 | + return $this->query('ContentSecurityPolicyManager'); |
|
1683 | + } |
|
1684 | + |
|
1685 | + /** |
|
1686 | + * @return ContentSecurityPolicyNonceManager |
|
1687 | + */ |
|
1688 | + public function getContentSecurityPolicyNonceManager() { |
|
1689 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
1690 | + } |
|
1691 | + |
|
1692 | + /** |
|
1693 | + * Not a public API as of 8.2, wait for 9.0 |
|
1694 | + * |
|
1695 | + * @return \OCA\Files_External\Service\BackendService |
|
1696 | + */ |
|
1697 | + public function getStoragesBackendService() { |
|
1698 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
1699 | + } |
|
1700 | + |
|
1701 | + /** |
|
1702 | + * Not a public API as of 8.2, wait for 9.0 |
|
1703 | + * |
|
1704 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
1705 | + */ |
|
1706 | + public function getGlobalStoragesService() { |
|
1707 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
1708 | + } |
|
1709 | + |
|
1710 | + /** |
|
1711 | + * Not a public API as of 8.2, wait for 9.0 |
|
1712 | + * |
|
1713 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
1714 | + */ |
|
1715 | + public function getUserGlobalStoragesService() { |
|
1716 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
1717 | + } |
|
1718 | + |
|
1719 | + /** |
|
1720 | + * Not a public API as of 8.2, wait for 9.0 |
|
1721 | + * |
|
1722 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
1723 | + */ |
|
1724 | + public function getUserStoragesService() { |
|
1725 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
1726 | + } |
|
1727 | + |
|
1728 | + /** |
|
1729 | + * @return \OCP\Share\IManager |
|
1730 | + */ |
|
1731 | + public function getShareManager() { |
|
1732 | + return $this->query('ShareManager'); |
|
1733 | + } |
|
1734 | + |
|
1735 | + /** |
|
1736 | + * Returns the LDAP Provider |
|
1737 | + * |
|
1738 | + * @return \OCP\LDAP\ILDAPProvider |
|
1739 | + */ |
|
1740 | + public function getLDAPProvider() { |
|
1741 | + return $this->query('LDAPProvider'); |
|
1742 | + } |
|
1743 | + |
|
1744 | + /** |
|
1745 | + * @return \OCP\Settings\IManager |
|
1746 | + */ |
|
1747 | + public function getSettingsManager() { |
|
1748 | + return $this->query('SettingsManager'); |
|
1749 | + } |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * @return \OCP\Files\IAppData |
|
1753 | + */ |
|
1754 | + public function getAppDataDir($app) { |
|
1755 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
1756 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
1757 | + return $factory->get($app); |
|
1758 | + } |
|
1759 | + |
|
1760 | + /** |
|
1761 | + * @return \OCP\Lockdown\ILockdownManager |
|
1762 | + */ |
|
1763 | + public function getLockdownManager() { |
|
1764 | + return $this->query('LockdownManager'); |
|
1765 | + } |
|
1766 | + |
|
1767 | + /** |
|
1768 | + * @return \OCP\Federation\ICloudIdManager |
|
1769 | + */ |
|
1770 | + public function getCloudIdManager() { |
|
1771 | + return $this->query(ICloudIdManager::class); |
|
1772 | + } |
|
1773 | 1773 | } |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | |
150 | 150 | |
151 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
151 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
152 | 152 | return new PreviewManager( |
153 | 153 | $c->getConfig(), |
154 | 154 | $c->getRootFolder(), |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | }); |
160 | 160 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
161 | 161 | |
162 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
162 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
163 | 163 | return new \OC\Preview\Watcher( |
164 | 164 | $c->getAppDataDir('preview') |
165 | 165 | ); |
166 | 166 | }); |
167 | 167 | |
168 | - $this->registerService('EncryptionManager', function (Server $c) { |
|
168 | + $this->registerService('EncryptionManager', function(Server $c) { |
|
169 | 169 | $view = new View(); |
170 | 170 | $util = new Encryption\Util( |
171 | 171 | $view, |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | ); |
184 | 184 | }); |
185 | 185 | |
186 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
186 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
187 | 187 | $util = new Encryption\Util( |
188 | 188 | new View(), |
189 | 189 | $c->getUserManager(), |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | ); |
198 | 198 | }); |
199 | 199 | |
200 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
200 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
201 | 201 | $view = new View(); |
202 | 202 | $util = new Encryption\Util( |
203 | 203 | $view, |
@@ -208,32 +208,32 @@ discard block |
||
208 | 208 | |
209 | 209 | return new Encryption\Keys\Storage($view, $util); |
210 | 210 | }); |
211 | - $this->registerService('TagMapper', function (Server $c) { |
|
211 | + $this->registerService('TagMapper', function(Server $c) { |
|
212 | 212 | return new TagMapper($c->getDatabaseConnection()); |
213 | 213 | }); |
214 | 214 | |
215 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
215 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
216 | 216 | $tagMapper = $c->query('TagMapper'); |
217 | 217 | return new TagManager($tagMapper, $c->getUserSession()); |
218 | 218 | }); |
219 | 219 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
220 | 220 | |
221 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
221 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
222 | 222 | $config = $c->getConfig(); |
223 | 223 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
224 | 224 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
225 | 225 | $factory = new $factoryClass($this); |
226 | 226 | return $factory; |
227 | 227 | }); |
228 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
228 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
229 | 229 | return $c->query('SystemTagManagerFactory')->getManager(); |
230 | 230 | }); |
231 | 231 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
232 | 232 | |
233 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
233 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
234 | 234 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
235 | 235 | }); |
236 | - $this->registerService('RootFolder', function (Server $c) { |
|
236 | + $this->registerService('RootFolder', function(Server $c) { |
|
237 | 237 | $manager = \OC\Files\Filesystem::getMountManager(null); |
238 | 238 | $view = new View(); |
239 | 239 | $root = new Root( |
@@ -261,30 +261,30 @@ discard block |
||
261 | 261 | }); |
262 | 262 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
263 | 263 | |
264 | - $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
|
264 | + $this->registerService(\OCP\IUserManager::class, function(Server $c) { |
|
265 | 265 | $config = $c->getConfig(); |
266 | 266 | return new \OC\User\Manager($config); |
267 | 267 | }); |
268 | 268 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
269 | 269 | |
270 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
270 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
271 | 271 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
272 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
272 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
273 | 273 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
274 | 274 | }); |
275 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
275 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
276 | 276 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
277 | 277 | }); |
278 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
278 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
279 | 279 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
280 | 280 | }); |
281 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
281 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
282 | 282 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
283 | 283 | }); |
284 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
284 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
285 | 285 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
286 | 286 | }); |
287 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
287 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
288 | 288 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
289 | 289 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
290 | 290 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -304,11 +304,11 @@ discard block |
||
304 | 304 | return new Store($session, $logger, $tokenProvider); |
305 | 305 | }); |
306 | 306 | $this->registerAlias(IStore::class, Store::class); |
307 | - $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
|
307 | + $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) { |
|
308 | 308 | $dbConnection = $c->getDatabaseConnection(); |
309 | 309 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
310 | 310 | }); |
311 | - $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
|
311 | + $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) { |
|
312 | 312 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
313 | 313 | $crypto = $c->getCrypto(); |
314 | 314 | $config = $c->getConfig(); |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | }); |
319 | 319 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
320 | 320 | |
321 | - $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
|
321 | + $this->registerService(\OCP\IUserSession::class, function(Server $c) { |
|
322 | 322 | $manager = $c->getUserManager(); |
323 | 323 | $session = new \OC\Session\Memory(''); |
324 | 324 | $timeFactory = new TimeFactory(); |
@@ -331,44 +331,44 @@ discard block |
||
331 | 331 | } |
332 | 332 | |
333 | 333 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
334 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
334 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
335 | 335 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
336 | 336 | }); |
337 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
337 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
338 | 338 | /** @var $user \OC\User\User */ |
339 | 339 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
340 | 340 | }); |
341 | - $userSession->listen('\OC\User', 'preDelete', function ($user) { |
|
341 | + $userSession->listen('\OC\User', 'preDelete', function($user) { |
|
342 | 342 | /** @var $user \OC\User\User */ |
343 | 343 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
344 | 344 | }); |
345 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
345 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
346 | 346 | /** @var $user \OC\User\User */ |
347 | 347 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
348 | 348 | }); |
349 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
349 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
350 | 350 | /** @var $user \OC\User\User */ |
351 | 351 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
352 | 352 | }); |
353 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
353 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
354 | 354 | /** @var $user \OC\User\User */ |
355 | 355 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
356 | 356 | }); |
357 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
357 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
358 | 358 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
359 | 359 | }); |
360 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
360 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password) { |
|
361 | 361 | /** @var $user \OC\User\User */ |
362 | 362 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
363 | 363 | }); |
364 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
364 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
365 | 365 | /** @var $user \OC\User\User */ |
366 | 366 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
367 | 367 | }); |
368 | - $userSession->listen('\OC\User', 'logout', function () { |
|
368 | + $userSession->listen('\OC\User', 'logout', function() { |
|
369 | 369 | \OC_Hook::emit('OC_User', 'logout', array()); |
370 | 370 | }); |
371 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
371 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
372 | 372 | /** @var $user \OC\User\User */ |
373 | 373 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
374 | 374 | }); |
@@ -376,14 +376,14 @@ discard block |
||
376 | 376 | }); |
377 | 377 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
378 | 378 | |
379 | - $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
|
379 | + $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) { |
|
380 | 380 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
381 | 381 | }); |
382 | 382 | |
383 | 383 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
384 | 384 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
385 | 385 | |
386 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
386 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
387 | 387 | return new \OC\AllConfig( |
388 | 388 | $c->getSystemConfig() |
389 | 389 | ); |
@@ -391,17 +391,17 @@ discard block |
||
391 | 391 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
392 | 392 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
393 | 393 | |
394 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
394 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
395 | 395 | return new \OC\SystemConfig($config); |
396 | 396 | }); |
397 | 397 | |
398 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
398 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
399 | 399 | return new \OC\AppConfig($c->getDatabaseConnection()); |
400 | 400 | }); |
401 | 401 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
402 | 402 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
403 | 403 | |
404 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
404 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
405 | 405 | return new \OC\L10N\Factory( |
406 | 406 | $c->getConfig(), |
407 | 407 | $c->getRequest(), |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | }); |
412 | 412 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
413 | 413 | |
414 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
414 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
415 | 415 | $config = $c->getConfig(); |
416 | 416 | $cacheFactory = $c->getMemCacheFactory(); |
417 | 417 | $request = $c->getRequest(); |
@@ -423,18 +423,18 @@ discard block |
||
423 | 423 | }); |
424 | 424 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
425 | 425 | |
426 | - $this->registerService('AppHelper', function ($c) { |
|
426 | + $this->registerService('AppHelper', function($c) { |
|
427 | 427 | return new \OC\AppHelper(); |
428 | 428 | }); |
429 | 429 | $this->registerAlias('AppFetcher', AppFetcher::class); |
430 | 430 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
431 | 431 | |
432 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
432 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
433 | 433 | return new Cache\File(); |
434 | 434 | }); |
435 | 435 | $this->registerAlias('UserCache', \OCP\ICache::class); |
436 | 436 | |
437 | - $this->registerService(Factory::class, function (Server $c) { |
|
437 | + $this->registerService(Factory::class, function(Server $c) { |
|
438 | 438 | |
439 | 439 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
440 | 440 | '\\OC\\Memcache\\ArrayCache', |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | $version = implode(',', $v); |
452 | 452 | $instanceId = \OC_Util::getInstanceId(); |
453 | 453 | $path = \OC::$SERVERROOT; |
454 | - $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
|
454 | + $prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl()); |
|
455 | 455 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
456 | 456 | $config->getSystemValue('memcache.local', null), |
457 | 457 | $config->getSystemValue('memcache.distributed', null), |
@@ -464,12 +464,12 @@ discard block |
||
464 | 464 | $this->registerAlias('MemCacheFactory', Factory::class); |
465 | 465 | $this->registerAlias(ICacheFactory::class, Factory::class); |
466 | 466 | |
467 | - $this->registerService('RedisFactory', function (Server $c) { |
|
467 | + $this->registerService('RedisFactory', function(Server $c) { |
|
468 | 468 | $systemConfig = $c->getSystemConfig(); |
469 | 469 | return new RedisFactory($systemConfig); |
470 | 470 | }); |
471 | 471 | |
472 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
472 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
473 | 473 | return new \OC\Activity\Manager( |
474 | 474 | $c->getRequest(), |
475 | 475 | $c->getUserSession(), |
@@ -479,14 +479,14 @@ discard block |
||
479 | 479 | }); |
480 | 480 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
481 | 481 | |
482 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
482 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
483 | 483 | return new \OC\Activity\EventMerger( |
484 | 484 | $c->getL10N('lib') |
485 | 485 | ); |
486 | 486 | }); |
487 | 487 | $this->registerAlias(IValidator::class, Validator::class); |
488 | 488 | |
489 | - $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
|
489 | + $this->registerService(\OCP\IAvatarManager::class, function(Server $c) { |
|
490 | 490 | return new AvatarManager( |
491 | 491 | $c->getUserManager(), |
492 | 492 | $c->getAppDataDir('avatar'), |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | }); |
498 | 498 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
499 | 499 | |
500 | - $this->registerService(\OCP\ILogger::class, function (Server $c) { |
|
500 | + $this->registerService(\OCP\ILogger::class, function(Server $c) { |
|
501 | 501 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
502 | 502 | $logger = Log::getLogClass($logType); |
503 | 503 | call_user_func(array($logger, 'init')); |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | }); |
507 | 507 | $this->registerAlias('Logger', \OCP\ILogger::class); |
508 | 508 | |
509 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
509 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
510 | 510 | $config = $c->getConfig(); |
511 | 511 | return new \OC\BackgroundJob\JobList( |
512 | 512 | $c->getDatabaseConnection(), |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | }); |
517 | 517 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
518 | 518 | |
519 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
519 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
520 | 520 | $cacheFactory = $c->getMemCacheFactory(); |
521 | 521 | $logger = $c->getLogger(); |
522 | 522 | if ($cacheFactory->isAvailable()) { |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | }); |
529 | 529 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
530 | 530 | |
531 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
531 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
532 | 532 | return new Search(); |
533 | 533 | }); |
534 | 534 | $this->registerAlias('Search', \OCP\ISearch::class); |
@@ -548,27 +548,27 @@ discard block |
||
548 | 548 | ); |
549 | 549 | }); |
550 | 550 | |
551 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
551 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
552 | 552 | return new SecureRandom(); |
553 | 553 | }); |
554 | 554 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
555 | 555 | |
556 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
556 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
557 | 557 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
558 | 558 | }); |
559 | 559 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
560 | 560 | |
561 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
561 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
562 | 562 | return new Hasher($c->getConfig()); |
563 | 563 | }); |
564 | 564 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
565 | 565 | |
566 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
566 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
567 | 567 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
568 | 568 | }); |
569 | 569 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
570 | 570 | |
571 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
571 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
572 | 572 | $systemConfig = $c->getSystemConfig(); |
573 | 573 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
574 | 574 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -582,7 +582,7 @@ discard block |
||
582 | 582 | }); |
583 | 583 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
584 | 584 | |
585 | - $this->registerService('HTTPHelper', function (Server $c) { |
|
585 | + $this->registerService('HTTPHelper', function(Server $c) { |
|
586 | 586 | $config = $c->getConfig(); |
587 | 587 | return new HTTPHelper( |
588 | 588 | $config, |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | ); |
591 | 591 | }); |
592 | 592 | |
593 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
593 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
594 | 594 | $user = \OC_User::getUser(); |
595 | 595 | $uid = $user ? $user : null; |
596 | 596 | return new ClientService( |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | ); |
600 | 600 | }); |
601 | 601 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
602 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
602 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
603 | 603 | $eventLogger = new EventLogger(); |
604 | 604 | if ($c->getSystemConfig()->getValue('debug', false)) { |
605 | 605 | // In debug mode, module is being activated by default |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | }); |
610 | 610 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
611 | 611 | |
612 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
612 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
613 | 613 | $queryLogger = new QueryLogger(); |
614 | 614 | if ($c->getSystemConfig()->getValue('debug', false)) { |
615 | 615 | // In debug mode, module is being activated by default |
@@ -619,7 +619,7 @@ discard block |
||
619 | 619 | }); |
620 | 620 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
621 | 621 | |
622 | - $this->registerService(TempManager::class, function (Server $c) { |
|
622 | + $this->registerService(TempManager::class, function(Server $c) { |
|
623 | 623 | return new TempManager( |
624 | 624 | $c->getLogger(), |
625 | 625 | $c->getConfig() |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | $this->registerAlias('TempManager', TempManager::class); |
629 | 629 | $this->registerAlias(ITempManager::class, TempManager::class); |
630 | 630 | |
631 | - $this->registerService(AppManager::class, function (Server $c) { |
|
631 | + $this->registerService(AppManager::class, function(Server $c) { |
|
632 | 632 | return new \OC\App\AppManager( |
633 | 633 | $c->getUserSession(), |
634 | 634 | $c->getAppConfig(), |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | $this->registerAlias('AppManager', AppManager::class); |
641 | 641 | $this->registerAlias(IAppManager::class, AppManager::class); |
642 | 642 | |
643 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
643 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
644 | 644 | return new DateTimeZone( |
645 | 645 | $c->getConfig(), |
646 | 646 | $c->getSession() |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | }); |
649 | 649 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
650 | 650 | |
651 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
651 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
652 | 652 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
653 | 653 | |
654 | 654 | return new DateTimeFormatter( |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | }); |
659 | 659 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
660 | 660 | |
661 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
661 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
662 | 662 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
663 | 663 | $listener = new UserMountCacheListener($mountCache); |
664 | 664 | $listener->listen($c->getUserManager()); |
@@ -666,10 +666,10 @@ discard block |
||
666 | 666 | }); |
667 | 667 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
668 | 668 | |
669 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
669 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
670 | 670 | $loader = \OC\Files\Filesystem::getLoader(); |
671 | 671 | $mountCache = $c->query('UserMountCache'); |
672 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
672 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
673 | 673 | |
674 | 674 | // builtin providers |
675 | 675 | |
@@ -682,14 +682,14 @@ discard block |
||
682 | 682 | }); |
683 | 683 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
684 | 684 | |
685 | - $this->registerService('IniWrapper', function ($c) { |
|
685 | + $this->registerService('IniWrapper', function($c) { |
|
686 | 686 | return new IniGetWrapper(); |
687 | 687 | }); |
688 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
688 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
689 | 689 | $jobList = $c->getJobList(); |
690 | 690 | return new AsyncBus($jobList); |
691 | 691 | }); |
692 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
692 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
693 | 693 | return new TrustedDomainHelper($this->getConfig()); |
694 | 694 | }); |
695 | 695 | $this->registerService('Throttler', function(Server $c) { |
@@ -700,10 +700,10 @@ discard block |
||
700 | 700 | $c->getConfig() |
701 | 701 | ); |
702 | 702 | }); |
703 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
703 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
704 | 704 | // IConfig and IAppManager requires a working database. This code |
705 | 705 | // might however be called when ownCloud is not yet setup. |
706 | - if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
706 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
707 | 707 | $config = $c->getConfig(); |
708 | 708 | $appManager = $c->getAppManager(); |
709 | 709 | } else { |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | $c->getTempManager() |
722 | 722 | ); |
723 | 723 | }); |
724 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
724 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
725 | 725 | if (isset($this['urlParams'])) { |
726 | 726 | $urlParams = $this['urlParams']; |
727 | 727 | } else { |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | }); |
758 | 758 | $this->registerAlias('Request', \OCP\IRequest::class); |
759 | 759 | |
760 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
760 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
761 | 761 | return new Mailer( |
762 | 762 | $c->getConfig(), |
763 | 763 | $c->getLogger(), |
@@ -771,14 +771,14 @@ discard block |
||
771 | 771 | $this->registerService('LDAPProvider', function(Server $c) { |
772 | 772 | $config = $c->getConfig(); |
773 | 773 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
774 | - if(is_null($factoryClass)) { |
|
774 | + if (is_null($factoryClass)) { |
|
775 | 775 | throw new \Exception('ldapProviderFactory not set'); |
776 | 776 | } |
777 | 777 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
778 | 778 | $factory = new $factoryClass($this); |
779 | 779 | return $factory->getLDAPProvider(); |
780 | 780 | }); |
781 | - $this->registerService('LockingProvider', function (Server $c) { |
|
781 | + $this->registerService('LockingProvider', function(Server $c) { |
|
782 | 782 | $ini = $c->getIniWrapper(); |
783 | 783 | $config = $c->getConfig(); |
784 | 784 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -794,39 +794,39 @@ discard block |
||
794 | 794 | return new NoopLockingProvider(); |
795 | 795 | }); |
796 | 796 | |
797 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
797 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
798 | 798 | return new \OC\Files\Mount\Manager(); |
799 | 799 | }); |
800 | 800 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
801 | 801 | |
802 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
802 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
803 | 803 | return new \OC\Files\Type\Detection( |
804 | 804 | $c->getURLGenerator(), |
805 | 805 | \OC::$configDir, |
806 | - \OC::$SERVERROOT . '/resources/config/' |
|
806 | + \OC::$SERVERROOT.'/resources/config/' |
|
807 | 807 | ); |
808 | 808 | }); |
809 | 809 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
810 | 810 | |
811 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
811 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
812 | 812 | return new \OC\Files\Type\Loader( |
813 | 813 | $c->getDatabaseConnection() |
814 | 814 | ); |
815 | 815 | }); |
816 | 816 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
817 | - $this->registerService(BundleFetcher::class, function () { |
|
817 | + $this->registerService(BundleFetcher::class, function() { |
|
818 | 818 | return new BundleFetcher($this->getL10N('lib')); |
819 | 819 | }); |
820 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
820 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
821 | 821 | return new Manager( |
822 | 822 | $c->query(IValidator::class) |
823 | 823 | ); |
824 | 824 | }); |
825 | 825 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
826 | 826 | |
827 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
827 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
828 | 828 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
829 | - $manager->registerCapability(function () use ($c) { |
|
829 | + $manager->registerCapability(function() use ($c) { |
|
830 | 830 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
831 | 831 | }); |
832 | 832 | return $manager; |
@@ -881,13 +881,13 @@ discard block |
||
881 | 881 | $cacheFactory->create('SCSS') |
882 | 882 | ); |
883 | 883 | }); |
884 | - $this->registerService(EventDispatcher::class, function () { |
|
884 | + $this->registerService(EventDispatcher::class, function() { |
|
885 | 885 | return new EventDispatcher(); |
886 | 886 | }); |
887 | 887 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
888 | 888 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
889 | 889 | |
890 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
890 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
891 | 891 | // FIXME: Instantiiated here due to cyclic dependency |
892 | 892 | $request = new Request( |
893 | 893 | [ |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | $request |
913 | 913 | ); |
914 | 914 | }); |
915 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
915 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
916 | 916 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
917 | 917 | |
918 | 918 | return new CsrfTokenManager( |
@@ -920,10 +920,10 @@ discard block |
||
920 | 920 | $c->query(SessionStorage::class) |
921 | 921 | ); |
922 | 922 | }); |
923 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
923 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
924 | 924 | return new SessionStorage($c->getSession()); |
925 | 925 | }); |
926 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
926 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
927 | 927 | return new ContentSecurityPolicyManager(); |
928 | 928 | }); |
929 | 929 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
@@ -974,29 +974,29 @@ discard block |
||
974 | 974 | ); |
975 | 975 | return $manager; |
976 | 976 | }); |
977 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
977 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
978 | 978 | return new \OC\Files\AppData\Factory( |
979 | 979 | $c->getRootFolder(), |
980 | 980 | $c->getSystemConfig() |
981 | 981 | ); |
982 | 982 | }); |
983 | 983 | |
984 | - $this->registerService('LockdownManager', function (Server $c) { |
|
984 | + $this->registerService('LockdownManager', function(Server $c) { |
|
985 | 985 | return new LockdownManager(function() use ($c) { |
986 | 986 | return $c->getSession(); |
987 | 987 | }); |
988 | 988 | }); |
989 | 989 | |
990 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
990 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
991 | 991 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
992 | 992 | }); |
993 | 993 | |
994 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
994 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
995 | 995 | return new CloudIdManager(); |
996 | 996 | }); |
997 | 997 | |
998 | 998 | /* To trick DI since we don't extend the DIContainer here */ |
999 | - $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
|
999 | + $this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) { |
|
1000 | 1000 | return new CleanPreviewsBackgroundJob( |
1001 | 1001 | $c->getRootFolder(), |
1002 | 1002 | $c->getLogger(), |
@@ -1011,7 +1011,7 @@ discard block |
||
1011 | 1011 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
1012 | 1012 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1013 | 1013 | |
1014 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1014 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1015 | 1015 | return new Defaults( |
1016 | 1016 | $c->getThemingDefaults() |
1017 | 1017 | ); |
@@ -1163,7 +1163,7 @@ discard block |
||
1163 | 1163 | * @deprecated since 9.2.0 use IAppData |
1164 | 1164 | */ |
1165 | 1165 | public function getAppFolder() { |
1166 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
1166 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
1167 | 1167 | $root = $this->getRootFolder(); |
1168 | 1168 | if (!$root->nodeExists($dir)) { |
1169 | 1169 | $folder = $root->newFolder($dir); |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | /** |
228 | 228 | * By default renders no output |
229 | - * @return null |
|
229 | + * @return string |
|
230 | 230 | * @since 6.0.0 |
231 | 231 | */ |
232 | 232 | public function render() { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Get the currently used Content-Security-Policy |
262 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
262 | + * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
263 | 263 | * none specified. |
264 | 264 | * @since 8.1.0 |
265 | 265 | */ |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function cacheFor($cacheSeconds) { |
93 | 93 | |
94 | - if($cacheSeconds > 0) { |
|
95 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
94 | + if ($cacheSeconds > 0) { |
|
95 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
96 | 96 | } else { |
97 | 97 | $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
98 | 98 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @since 8.0.0 |
147 | 147 | */ |
148 | 148 | public function invalidateCookies(array $cookieNames) { |
149 | - foreach($cookieNames as $cookieName) { |
|
149 | + foreach ($cookieNames as $cookieName) { |
|
150 | 150 | $this->invalidateCookie($cookieName); |
151 | 151 | } |
152 | 152 | return $this; |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * @since 6.0.0 - return value was added in 7.0.0 |
171 | 171 | */ |
172 | 172 | public function addHeader($name, $value) { |
173 | - $name = trim($name); // always remove leading and trailing whitespace |
|
173 | + $name = trim($name); // always remove leading and trailing whitespace |
|
174 | 174 | // to be able to reliably check for security |
175 | 175 | // headers |
176 | 176 | |
177 | - if(is_null($value)) { |
|
177 | + if (is_null($value)) { |
|
178 | 178 | unset($this->headers[$name]); |
179 | 179 | } else { |
180 | 180 | $this->headers[$name] = $value; |
@@ -205,19 +205,19 @@ discard block |
||
205 | 205 | public function getHeaders() { |
206 | 206 | $mergeWith = []; |
207 | 207 | |
208 | - if($this->lastModified) { |
|
208 | + if ($this->lastModified) { |
|
209 | 209 | $mergeWith['Last-Modified'] = |
210 | 210 | $this->lastModified->format(\DateTime::RFC2822); |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Build Content-Security-Policy and use default if none has been specified |
214 | - if(is_null($this->contentSecurityPolicy)) { |
|
214 | + if (is_null($this->contentSecurityPolicy)) { |
|
215 | 215 | $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
216 | 216 | } |
217 | 217 | $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
218 | 218 | |
219 | - if($this->ETag) { |
|
220 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
219 | + if ($this->ETag) { |
|
220 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return array_merge($mergeWith, $this->headers); |
@@ -42,304 +42,304 @@ |
||
42 | 42 | */ |
43 | 43 | class Response { |
44 | 44 | |
45 | - /** |
|
46 | - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - private $headers = array( |
|
50 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
51 | - ); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Cookies that will be need to be constructed as header |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - private $cookies = array(); |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * HTTP status code - defaults to STATUS OK |
|
63 | - * @var int |
|
64 | - */ |
|
65 | - private $status = Http::STATUS_OK; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Last modified date |
|
70 | - * @var \DateTime |
|
71 | - */ |
|
72 | - private $lastModified; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * ETag |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - private $ETag; |
|
80 | - |
|
81 | - /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
82 | - private $contentSecurityPolicy = null; |
|
83 | - |
|
84 | - /** @var bool */ |
|
85 | - private $throttled = false; |
|
86 | - |
|
87 | - /** |
|
88 | - * Caches the response |
|
89 | - * @param int $cacheSeconds the amount of seconds that should be cached |
|
90 | - * if 0 then caching will be disabled |
|
91 | - * @return $this |
|
92 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
93 | - */ |
|
94 | - public function cacheFor($cacheSeconds) { |
|
95 | - |
|
96 | - if($cacheSeconds > 0) { |
|
97 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
98 | - } else { |
|
99 | - $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
100 | - } |
|
101 | - |
|
102 | - return $this; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Adds a new cookie to the response |
|
107 | - * @param string $name The name of the cookie |
|
108 | - * @param string $value The value of the cookie |
|
109 | - * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
110 | - * to null cookie will be considered as session |
|
111 | - * cookie. |
|
112 | - * @return $this |
|
113 | - * @since 8.0.0 |
|
114 | - */ |
|
115 | - public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
116 | - $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
117 | - return $this; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the specified cookies |
|
123 | - * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
124 | - * @return $this |
|
125 | - * @since 8.0.0 |
|
126 | - */ |
|
127 | - public function setCookies(array $cookies) { |
|
128 | - $this->cookies = $cookies; |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Invalidates the specified cookie |
|
135 | - * @param string $name |
|
136 | - * @return $this |
|
137 | - * @since 8.0.0 |
|
138 | - */ |
|
139 | - public function invalidateCookie($name) { |
|
140 | - $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
141 | - return $this; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Invalidates the specified cookies |
|
146 | - * @param array $cookieNames array('foo', 'bar') |
|
147 | - * @return $this |
|
148 | - * @since 8.0.0 |
|
149 | - */ |
|
150 | - public function invalidateCookies(array $cookieNames) { |
|
151 | - foreach($cookieNames as $cookieName) { |
|
152 | - $this->invalidateCookie($cookieName); |
|
153 | - } |
|
154 | - return $this; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns the cookies |
|
159 | - * @return array |
|
160 | - * @since 8.0.0 |
|
161 | - */ |
|
162 | - public function getCookies() { |
|
163 | - return $this->cookies; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Adds a new header to the response that will be called before the render |
|
168 | - * function |
|
169 | - * @param string $name The name of the HTTP header |
|
170 | - * @param string $value The value, null will delete it |
|
171 | - * @return $this |
|
172 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
173 | - */ |
|
174 | - public function addHeader($name, $value) { |
|
175 | - $name = trim($name); // always remove leading and trailing whitespace |
|
176 | - // to be able to reliably check for security |
|
177 | - // headers |
|
178 | - |
|
179 | - if(is_null($value)) { |
|
180 | - unset($this->headers[$name]); |
|
181 | - } else { |
|
182 | - $this->headers[$name] = $value; |
|
183 | - } |
|
184 | - |
|
185 | - return $this; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Set the headers |
|
191 | - * @param array $headers value header pairs |
|
192 | - * @return $this |
|
193 | - * @since 8.0.0 |
|
194 | - */ |
|
195 | - public function setHeaders(array $headers) { |
|
196 | - $this->headers = $headers; |
|
197 | - |
|
198 | - return $this; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Returns the set headers |
|
204 | - * @return array the headers |
|
205 | - * @since 6.0.0 |
|
206 | - */ |
|
207 | - public function getHeaders() { |
|
208 | - $mergeWith = []; |
|
209 | - |
|
210 | - if($this->lastModified) { |
|
211 | - $mergeWith['Last-Modified'] = |
|
212 | - $this->lastModified->format(\DateTime::RFC2822); |
|
213 | - } |
|
214 | - |
|
215 | - // Build Content-Security-Policy and use default if none has been specified |
|
216 | - if(is_null($this->contentSecurityPolicy)) { |
|
217 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
218 | - } |
|
219 | - $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
220 | - |
|
221 | - if($this->ETag) { |
|
222 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
223 | - } |
|
224 | - |
|
225 | - return array_merge($mergeWith, $this->headers); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * By default renders no output |
|
231 | - * @return null |
|
232 | - * @since 6.0.0 |
|
233 | - */ |
|
234 | - public function render() { |
|
235 | - return null; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Set response status |
|
241 | - * @param int $status a HTTP status code, see also the STATUS constants |
|
242 | - * @return Response Reference to this object |
|
243 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
244 | - */ |
|
245 | - public function setStatus($status) { |
|
246 | - $this->status = $status; |
|
247 | - |
|
248 | - return $this; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Set a Content-Security-Policy |
|
253 | - * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
254 | - * @return $this |
|
255 | - * @since 8.1.0 |
|
256 | - */ |
|
257 | - public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
258 | - $this->contentSecurityPolicy = $csp; |
|
259 | - return $this; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get the currently used Content-Security-Policy |
|
264 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
265 | - * none specified. |
|
266 | - * @since 8.1.0 |
|
267 | - */ |
|
268 | - public function getContentSecurityPolicy() { |
|
269 | - return $this->contentSecurityPolicy; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Get response status |
|
275 | - * @since 6.0.0 |
|
276 | - */ |
|
277 | - public function getStatus() { |
|
278 | - return $this->status; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Get the ETag |
|
284 | - * @return string the etag |
|
285 | - * @since 6.0.0 |
|
286 | - */ |
|
287 | - public function getETag() { |
|
288 | - return $this->ETag; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Get "last modified" date |
|
294 | - * @return \DateTime RFC2822 formatted last modified date |
|
295 | - * @since 6.0.0 |
|
296 | - */ |
|
297 | - public function getLastModified() { |
|
298 | - return $this->lastModified; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Set the ETag |
|
304 | - * @param string $ETag |
|
305 | - * @return Response Reference to this object |
|
306 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
307 | - */ |
|
308 | - public function setETag($ETag) { |
|
309 | - $this->ETag = $ETag; |
|
310 | - |
|
311 | - return $this; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Set "last modified" date |
|
317 | - * @param \DateTime $lastModified |
|
318 | - * @return Response Reference to this object |
|
319 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
320 | - */ |
|
321 | - public function setLastModified($lastModified) { |
|
322 | - $this->lastModified = $lastModified; |
|
323 | - |
|
324 | - return $this; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Marks the response as to throttle. Will be throttled when the |
|
329 | - * @BruteForceProtection annotation is added. |
|
330 | - * |
|
331 | - * @since 12.0.0 |
|
332 | - */ |
|
333 | - public function throttle() { |
|
334 | - $this->throttled = true; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Whether the current response is throttled. |
|
339 | - * |
|
340 | - * @since 12.0.0 |
|
341 | - */ |
|
342 | - public function isThrottled() { |
|
343 | - return $this->throttled; |
|
344 | - } |
|
45 | + /** |
|
46 | + * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + private $headers = array( |
|
50 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
51 | + ); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Cookies that will be need to be constructed as header |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + private $cookies = array(); |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * HTTP status code - defaults to STATUS OK |
|
63 | + * @var int |
|
64 | + */ |
|
65 | + private $status = Http::STATUS_OK; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Last modified date |
|
70 | + * @var \DateTime |
|
71 | + */ |
|
72 | + private $lastModified; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * ETag |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + private $ETag; |
|
80 | + |
|
81 | + /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
82 | + private $contentSecurityPolicy = null; |
|
83 | + |
|
84 | + /** @var bool */ |
|
85 | + private $throttled = false; |
|
86 | + |
|
87 | + /** |
|
88 | + * Caches the response |
|
89 | + * @param int $cacheSeconds the amount of seconds that should be cached |
|
90 | + * if 0 then caching will be disabled |
|
91 | + * @return $this |
|
92 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
93 | + */ |
|
94 | + public function cacheFor($cacheSeconds) { |
|
95 | + |
|
96 | + if($cacheSeconds > 0) { |
|
97 | + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
98 | + } else { |
|
99 | + $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
100 | + } |
|
101 | + |
|
102 | + return $this; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Adds a new cookie to the response |
|
107 | + * @param string $name The name of the cookie |
|
108 | + * @param string $value The value of the cookie |
|
109 | + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
110 | + * to null cookie will be considered as session |
|
111 | + * cookie. |
|
112 | + * @return $this |
|
113 | + * @since 8.0.0 |
|
114 | + */ |
|
115 | + public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
116 | + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
117 | + return $this; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the specified cookies |
|
123 | + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
124 | + * @return $this |
|
125 | + * @since 8.0.0 |
|
126 | + */ |
|
127 | + public function setCookies(array $cookies) { |
|
128 | + $this->cookies = $cookies; |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Invalidates the specified cookie |
|
135 | + * @param string $name |
|
136 | + * @return $this |
|
137 | + * @since 8.0.0 |
|
138 | + */ |
|
139 | + public function invalidateCookie($name) { |
|
140 | + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
141 | + return $this; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Invalidates the specified cookies |
|
146 | + * @param array $cookieNames array('foo', 'bar') |
|
147 | + * @return $this |
|
148 | + * @since 8.0.0 |
|
149 | + */ |
|
150 | + public function invalidateCookies(array $cookieNames) { |
|
151 | + foreach($cookieNames as $cookieName) { |
|
152 | + $this->invalidateCookie($cookieName); |
|
153 | + } |
|
154 | + return $this; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns the cookies |
|
159 | + * @return array |
|
160 | + * @since 8.0.0 |
|
161 | + */ |
|
162 | + public function getCookies() { |
|
163 | + return $this->cookies; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Adds a new header to the response that will be called before the render |
|
168 | + * function |
|
169 | + * @param string $name The name of the HTTP header |
|
170 | + * @param string $value The value, null will delete it |
|
171 | + * @return $this |
|
172 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
173 | + */ |
|
174 | + public function addHeader($name, $value) { |
|
175 | + $name = trim($name); // always remove leading and trailing whitespace |
|
176 | + // to be able to reliably check for security |
|
177 | + // headers |
|
178 | + |
|
179 | + if(is_null($value)) { |
|
180 | + unset($this->headers[$name]); |
|
181 | + } else { |
|
182 | + $this->headers[$name] = $value; |
|
183 | + } |
|
184 | + |
|
185 | + return $this; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Set the headers |
|
191 | + * @param array $headers value header pairs |
|
192 | + * @return $this |
|
193 | + * @since 8.0.0 |
|
194 | + */ |
|
195 | + public function setHeaders(array $headers) { |
|
196 | + $this->headers = $headers; |
|
197 | + |
|
198 | + return $this; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Returns the set headers |
|
204 | + * @return array the headers |
|
205 | + * @since 6.0.0 |
|
206 | + */ |
|
207 | + public function getHeaders() { |
|
208 | + $mergeWith = []; |
|
209 | + |
|
210 | + if($this->lastModified) { |
|
211 | + $mergeWith['Last-Modified'] = |
|
212 | + $this->lastModified->format(\DateTime::RFC2822); |
|
213 | + } |
|
214 | + |
|
215 | + // Build Content-Security-Policy and use default if none has been specified |
|
216 | + if(is_null($this->contentSecurityPolicy)) { |
|
217 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
218 | + } |
|
219 | + $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
220 | + |
|
221 | + if($this->ETag) { |
|
222 | + $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
223 | + } |
|
224 | + |
|
225 | + return array_merge($mergeWith, $this->headers); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * By default renders no output |
|
231 | + * @return null |
|
232 | + * @since 6.0.0 |
|
233 | + */ |
|
234 | + public function render() { |
|
235 | + return null; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Set response status |
|
241 | + * @param int $status a HTTP status code, see also the STATUS constants |
|
242 | + * @return Response Reference to this object |
|
243 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
244 | + */ |
|
245 | + public function setStatus($status) { |
|
246 | + $this->status = $status; |
|
247 | + |
|
248 | + return $this; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Set a Content-Security-Policy |
|
253 | + * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
254 | + * @return $this |
|
255 | + * @since 8.1.0 |
|
256 | + */ |
|
257 | + public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
258 | + $this->contentSecurityPolicy = $csp; |
|
259 | + return $this; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get the currently used Content-Security-Policy |
|
264 | + * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
265 | + * none specified. |
|
266 | + * @since 8.1.0 |
|
267 | + */ |
|
268 | + public function getContentSecurityPolicy() { |
|
269 | + return $this->contentSecurityPolicy; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Get response status |
|
275 | + * @since 6.0.0 |
|
276 | + */ |
|
277 | + public function getStatus() { |
|
278 | + return $this->status; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Get the ETag |
|
284 | + * @return string the etag |
|
285 | + * @since 6.0.0 |
|
286 | + */ |
|
287 | + public function getETag() { |
|
288 | + return $this->ETag; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Get "last modified" date |
|
294 | + * @return \DateTime RFC2822 formatted last modified date |
|
295 | + * @since 6.0.0 |
|
296 | + */ |
|
297 | + public function getLastModified() { |
|
298 | + return $this->lastModified; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Set the ETag |
|
304 | + * @param string $ETag |
|
305 | + * @return Response Reference to this object |
|
306 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
307 | + */ |
|
308 | + public function setETag($ETag) { |
|
309 | + $this->ETag = $ETag; |
|
310 | + |
|
311 | + return $this; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Set "last modified" date |
|
317 | + * @param \DateTime $lastModified |
|
318 | + * @return Response Reference to this object |
|
319 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
320 | + */ |
|
321 | + public function setLastModified($lastModified) { |
|
322 | + $this->lastModified = $lastModified; |
|
323 | + |
|
324 | + return $this; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Marks the response as to throttle. Will be throttled when the |
|
329 | + * @BruteForceProtection annotation is added. |
|
330 | + * |
|
331 | + * @since 12.0.0 |
|
332 | + */ |
|
333 | + public function throttle() { |
|
334 | + $this->throttled = true; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Whether the current response is throttled. |
|
339 | + * |
|
340 | + * @since 12.0.0 |
|
341 | + */ |
|
342 | + public function isThrottled() { |
|
343 | + return $this->throttled; |
|
344 | + } |
|
345 | 345 | } |
@@ -134,7 +134,7 @@ |
||
134 | 134 | * @param RequestInterface $request |
135 | 135 | * @param ResponseInterface $response |
136 | 136 | * |
137 | - * @return void|bool |
|
137 | + * @return null|false |
|
138 | 138 | */ |
139 | 139 | public function httpPost(RequestInterface $request, ResponseInterface $response) { |
140 | 140 | $path = $request->getPath(); |
@@ -34,194 +34,194 @@ |
||
34 | 34 | use OCP\IConfig; |
35 | 35 | |
36 | 36 | class PublishPlugin extends ServerPlugin { |
37 | - const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Reference to SabreDAV server object. |
|
41 | - * |
|
42 | - * @var \Sabre\DAV\Server |
|
43 | - */ |
|
44 | - protected $server; |
|
45 | - |
|
46 | - /** |
|
47 | - * Config instance to get instance secret. |
|
48 | - * |
|
49 | - * @var IConfig |
|
50 | - */ |
|
51 | - protected $config; |
|
52 | - |
|
53 | - /** |
|
54 | - * URL Generator for absolute URLs. |
|
55 | - * |
|
56 | - * @var IURLGenerator |
|
57 | - */ |
|
58 | - protected $urlGenerator; |
|
59 | - |
|
60 | - /** |
|
61 | - * PublishPlugin constructor. |
|
62 | - * |
|
63 | - * @param IConfig $config |
|
64 | - * @param IURLGenerator $urlGenerator |
|
65 | - */ |
|
66 | - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
67 | - $this->config = $config; |
|
68 | - $this->urlGenerator = $urlGenerator; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * This method should return a list of server-features. |
|
73 | - * |
|
74 | - * This is for example 'versioning' and is added to the DAV: header |
|
75 | - * in an OPTIONS response. |
|
76 | - * |
|
77 | - * @return string[] |
|
78 | - */ |
|
79 | - public function getFeatures() { |
|
80 | - // May have to be changed to be detected |
|
81 | - return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Returns a plugin name. |
|
86 | - * |
|
87 | - * Using this name other plugins will be able to access other plugins |
|
88 | - * using Sabre\DAV\Server::getPlugin |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function getPluginName() { |
|
93 | - return 'oc-calendar-publishing'; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * This initializes the plugin. |
|
98 | - * |
|
99 | - * This function is called by Sabre\DAV\Server, after |
|
100 | - * addPlugin is called. |
|
101 | - * |
|
102 | - * This method should set up the required event subscriptions. |
|
103 | - * |
|
104 | - * @param Server $server |
|
105 | - */ |
|
106 | - public function initialize(Server $server) { |
|
107 | - $this->server = $server; |
|
108 | - |
|
109 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
111 | - } |
|
112 | - |
|
113 | - public function propFind(PropFind $propFind, INode $node) { |
|
114 | - if ($node instanceof Calendar) { |
|
115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
116 | - if ($node->getPublishStatus()) { |
|
117 | - // We return the publish-url only if the calendar is published. |
|
118 | - $token = $node->getPublishStatus(); |
|
119 | - $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
120 | - |
|
121 | - return new Publisher($publishUrl, true); |
|
122 | - } |
|
123 | - }); |
|
124 | - |
|
125 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
126 | - return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
127 | - }); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * We intercept this to handle POST requests on calendars. |
|
133 | - * |
|
134 | - * @param RequestInterface $request |
|
135 | - * @param ResponseInterface $response |
|
136 | - * |
|
137 | - * @return void|bool |
|
138 | - */ |
|
139 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
140 | - $path = $request->getPath(); |
|
141 | - |
|
142 | - // Only handling xml |
|
143 | - $contentType = $request->getHeader('Content-Type'); |
|
144 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - // Making sure the node exists |
|
149 | - try { |
|
150 | - $node = $this->server->tree->getNodeForPath($path); |
|
151 | - } catch (NotFound $e) { |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $requestBody = $request->getBodyAsString(); |
|
156 | - |
|
157 | - // If this request handler could not deal with this POST request, it |
|
158 | - // will return 'null' and other plugins get a chance to handle the |
|
159 | - // request. |
|
160 | - // |
|
161 | - // However, we already requested the full body. This is a problem, |
|
162 | - // because a body can only be read once. This is why we preemptively |
|
163 | - // re-populated the request body with the existing data. |
|
164 | - $request->setBody($requestBody); |
|
165 | - |
|
166 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
167 | - |
|
168 | - switch ($documentType) { |
|
169 | - |
|
170 | - case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
171 | - |
|
172 | - // We can only deal with IShareableCalendar objects |
|
173 | - if (!$node instanceof Calendar) { |
|
174 | - return; |
|
175 | - } |
|
176 | - $this->server->transactionType = 'post-publish-calendar'; |
|
177 | - |
|
178 | - // Getting ACL info |
|
179 | - $acl = $this->server->getPlugin('acl'); |
|
180 | - |
|
181 | - // If there's no ACL support, we allow everything |
|
182 | - if ($acl) { |
|
183 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
184 | - } |
|
185 | - |
|
186 | - $node->setPublishStatus(true); |
|
187 | - |
|
188 | - // iCloud sends back the 202, so we will too. |
|
189 | - $response->setStatus(202); |
|
190 | - |
|
191 | - // Adding this because sending a response body may cause issues, |
|
192 | - // and I wanted some type of indicator the response was handled. |
|
193 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
194 | - |
|
195 | - // Breaking the event chain |
|
196 | - return false; |
|
197 | - |
|
198 | - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
199 | - |
|
200 | - // We can only deal with IShareableCalendar objects |
|
201 | - if (!$node instanceof Calendar) { |
|
202 | - return; |
|
203 | - } |
|
204 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
205 | - |
|
206 | - // Getting ACL info |
|
207 | - $acl = $this->server->getPlugin('acl'); |
|
208 | - |
|
209 | - // If there's no ACL support, we allow everything |
|
210 | - if ($acl) { |
|
211 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
212 | - } |
|
213 | - |
|
214 | - $node->setPublishStatus(false); |
|
215 | - |
|
216 | - $response->setStatus(200); |
|
217 | - |
|
218 | - // Adding this because sending a response body may cause issues, |
|
219 | - // and I wanted some type of indicator the response was handled. |
|
220 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
221 | - |
|
222 | - // Breaking the event chain |
|
223 | - return false; |
|
37 | + const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Reference to SabreDAV server object. |
|
41 | + * |
|
42 | + * @var \Sabre\DAV\Server |
|
43 | + */ |
|
44 | + protected $server; |
|
45 | + |
|
46 | + /** |
|
47 | + * Config instance to get instance secret. |
|
48 | + * |
|
49 | + * @var IConfig |
|
50 | + */ |
|
51 | + protected $config; |
|
52 | + |
|
53 | + /** |
|
54 | + * URL Generator for absolute URLs. |
|
55 | + * |
|
56 | + * @var IURLGenerator |
|
57 | + */ |
|
58 | + protected $urlGenerator; |
|
59 | + |
|
60 | + /** |
|
61 | + * PublishPlugin constructor. |
|
62 | + * |
|
63 | + * @param IConfig $config |
|
64 | + * @param IURLGenerator $urlGenerator |
|
65 | + */ |
|
66 | + public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
67 | + $this->config = $config; |
|
68 | + $this->urlGenerator = $urlGenerator; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * This method should return a list of server-features. |
|
73 | + * |
|
74 | + * This is for example 'versioning' and is added to the DAV: header |
|
75 | + * in an OPTIONS response. |
|
76 | + * |
|
77 | + * @return string[] |
|
78 | + */ |
|
79 | + public function getFeatures() { |
|
80 | + // May have to be changed to be detected |
|
81 | + return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Returns a plugin name. |
|
86 | + * |
|
87 | + * Using this name other plugins will be able to access other plugins |
|
88 | + * using Sabre\DAV\Server::getPlugin |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function getPluginName() { |
|
93 | + return 'oc-calendar-publishing'; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * This initializes the plugin. |
|
98 | + * |
|
99 | + * This function is called by Sabre\DAV\Server, after |
|
100 | + * addPlugin is called. |
|
101 | + * |
|
102 | + * This method should set up the required event subscriptions. |
|
103 | + * |
|
104 | + * @param Server $server |
|
105 | + */ |
|
106 | + public function initialize(Server $server) { |
|
107 | + $this->server = $server; |
|
108 | + |
|
109 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
111 | + } |
|
112 | + |
|
113 | + public function propFind(PropFind $propFind, INode $node) { |
|
114 | + if ($node instanceof Calendar) { |
|
115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
116 | + if ($node->getPublishStatus()) { |
|
117 | + // We return the publish-url only if the calendar is published. |
|
118 | + $token = $node->getPublishStatus(); |
|
119 | + $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
120 | + |
|
121 | + return new Publisher($publishUrl, true); |
|
122 | + } |
|
123 | + }); |
|
124 | + |
|
125 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
126 | + return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
127 | + }); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * We intercept this to handle POST requests on calendars. |
|
133 | + * |
|
134 | + * @param RequestInterface $request |
|
135 | + * @param ResponseInterface $response |
|
136 | + * |
|
137 | + * @return void|bool |
|
138 | + */ |
|
139 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
140 | + $path = $request->getPath(); |
|
141 | + |
|
142 | + // Only handling xml |
|
143 | + $contentType = $request->getHeader('Content-Type'); |
|
144 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + // Making sure the node exists |
|
149 | + try { |
|
150 | + $node = $this->server->tree->getNodeForPath($path); |
|
151 | + } catch (NotFound $e) { |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $requestBody = $request->getBodyAsString(); |
|
156 | + |
|
157 | + // If this request handler could not deal with this POST request, it |
|
158 | + // will return 'null' and other plugins get a chance to handle the |
|
159 | + // request. |
|
160 | + // |
|
161 | + // However, we already requested the full body. This is a problem, |
|
162 | + // because a body can only be read once. This is why we preemptively |
|
163 | + // re-populated the request body with the existing data. |
|
164 | + $request->setBody($requestBody); |
|
165 | + |
|
166 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
167 | + |
|
168 | + switch ($documentType) { |
|
169 | + |
|
170 | + case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
171 | + |
|
172 | + // We can only deal with IShareableCalendar objects |
|
173 | + if (!$node instanceof Calendar) { |
|
174 | + return; |
|
175 | + } |
|
176 | + $this->server->transactionType = 'post-publish-calendar'; |
|
177 | + |
|
178 | + // Getting ACL info |
|
179 | + $acl = $this->server->getPlugin('acl'); |
|
180 | + |
|
181 | + // If there's no ACL support, we allow everything |
|
182 | + if ($acl) { |
|
183 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
184 | + } |
|
185 | + |
|
186 | + $node->setPublishStatus(true); |
|
187 | + |
|
188 | + // iCloud sends back the 202, so we will too. |
|
189 | + $response->setStatus(202); |
|
190 | + |
|
191 | + // Adding this because sending a response body may cause issues, |
|
192 | + // and I wanted some type of indicator the response was handled. |
|
193 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
194 | + |
|
195 | + // Breaking the event chain |
|
196 | + return false; |
|
197 | + |
|
198 | + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
199 | + |
|
200 | + // We can only deal with IShareableCalendar objects |
|
201 | + if (!$node instanceof Calendar) { |
|
202 | + return; |
|
203 | + } |
|
204 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
205 | + |
|
206 | + // Getting ACL info |
|
207 | + $acl = $this->server->getPlugin('acl'); |
|
208 | + |
|
209 | + // If there's no ACL support, we allow everything |
|
210 | + if ($acl) { |
|
211 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
212 | + } |
|
213 | + |
|
214 | + $node->setPublishStatus(false); |
|
215 | + |
|
216 | + $response->setStatus(200); |
|
217 | + |
|
218 | + // Adding this because sending a response body may cause issues, |
|
219 | + // and I wanted some type of indicator the response was handled. |
|
220 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
221 | + |
|
222 | + // Breaking the event chain |
|
223 | + return false; |
|
224 | 224 | |
225 | - } |
|
226 | - } |
|
225 | + } |
|
226 | + } |
|
227 | 227 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - public function getPluginName() { |
|
92 | + public function getPluginName() { |
|
93 | 93 | return 'oc-calendar-publishing'; |
94 | 94 | } |
95 | 95 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | $this->server = $server; |
108 | 108 | |
109 | 109 | $this->server->on('method:POST', [$this, 'httpPost']); |
110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | public function propFind(PropFind $propFind, INode $node) { |
114 | 114 | if ($node instanceof Calendar) { |
115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) { |
|
116 | 116 | if ($node->getPublishStatus()) { |
117 | 117 | // We return the publish-url only if the calendar is published. |
118 | 118 | $token = $node->getPublishStatus(); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
33 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
33 | + * @param CardDavBackend $carddavBackend |
|
34 | 34 | * @param string $principalPrefix |
35 | 35 | */ |
36 | 36 | public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
@@ -25,46 +25,46 @@ |
||
25 | 25 | |
26 | 26 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { |
27 | 27 | |
28 | - /** @var IL10N */ |
|
29 | - protected $l10n; |
|
28 | + /** @var IL10N */ |
|
29 | + protected $l10n; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
33 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
34 | - * @param string $principalPrefix |
|
35 | - */ |
|
36 | - public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
|
37 | - parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
38 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
33 | + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
34 | + * @param string $principalPrefix |
|
35 | + */ |
|
36 | + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
|
37 | + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
38 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * This method returns a node for a principal. |
|
43 | - * |
|
44 | - * The passed array contains principal information, and is guaranteed to |
|
45 | - * at least contain a uri item. Other properties may or may not be |
|
46 | - * supplied by the authentication backend. |
|
47 | - * |
|
48 | - * @param array $principal |
|
49 | - * @return \Sabre\DAV\INode |
|
50 | - */ |
|
51 | - function getChildForPrincipal(array $principal) { |
|
41 | + /** |
|
42 | + * This method returns a node for a principal. |
|
43 | + * |
|
44 | + * The passed array contains principal information, and is guaranteed to |
|
45 | + * at least contain a uri item. Other properties may or may not be |
|
46 | + * supplied by the authentication backend. |
|
47 | + * |
|
48 | + * @param array $principal |
|
49 | + * @return \Sabre\DAV\INode |
|
50 | + */ |
|
51 | + function getChildForPrincipal(array $principal) { |
|
52 | 52 | |
53 | - return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); |
|
53 | + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - function getName() { |
|
57 | + function getName() { |
|
58 | 58 | |
59 | - if ($this->principalPrefix === 'principals') { |
|
60 | - return parent::getName(); |
|
61 | - } |
|
62 | - // Grabbing all the components of the principal path. |
|
63 | - $parts = explode('/', $this->principalPrefix); |
|
59 | + if ($this->principalPrefix === 'principals') { |
|
60 | + return parent::getName(); |
|
61 | + } |
|
62 | + // Grabbing all the components of the principal path. |
|
63 | + $parts = explode('/', $this->principalPrefix); |
|
64 | 64 | |
65 | - // We are only interested in the second part. |
|
66 | - return $parts[1]; |
|
65 | + // We are only interested in the second part. |
|
66 | + return $parts[1]; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -770,7 +770,7 @@ |
||
770 | 770 | |
771 | 771 | /** |
772 | 772 | * @param Share[] $shares |
773 | - * @param $userId |
|
773 | + * @param string $userId |
|
774 | 774 | * @return Share[] The updates shares if no update is found for a share return the original |
775 | 775 | */ |
776 | 776 | private function resolveGroupShares($shares, $userId) { |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | ->orderBy('id'); |
289 | 289 | |
290 | 290 | $cursor = $qb->execute(); |
291 | - while($data = $cursor->fetch()) { |
|
291 | + while ($data = $cursor->fetch()) { |
|
292 | 292 | $children[] = $this->createShare($data); |
293 | 293 | } |
294 | 294 | $cursor->closeCursor(); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $user = $this->userManager->get($recipient); |
334 | 334 | |
335 | 335 | if (is_null($group)) { |
336 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
336 | + throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | if (!$group->inGroup($user)) { |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | ); |
494 | 494 | } |
495 | 495 | |
496 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
497 | 497 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
498 | 498 | |
499 | 499 | $qb->orderBy('id'); |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | |
550 | 550 | $cursor = $qb->execute(); |
551 | 551 | $shares = []; |
552 | - while($data = $cursor->fetch()) { |
|
552 | + while ($data = $cursor->fetch()) { |
|
553 | 553 | $shares[] = $this->createShare($data); |
554 | 554 | } |
555 | 555 | $cursor->closeCursor(); |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | ->execute(); |
629 | 629 | |
630 | 630 | $shares = []; |
631 | - while($data = $cursor->fetch()) { |
|
631 | + while ($data = $cursor->fetch()) { |
|
632 | 632 | $shares[] = $this->createShare($data); |
633 | 633 | } |
634 | 634 | $cursor->closeCursor(); |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | |
700 | 700 | $cursor = $qb->execute(); |
701 | 701 | |
702 | - while($data = $cursor->fetch()) { |
|
702 | + while ($data = $cursor->fetch()) { |
|
703 | 703 | if ($this->isAccessibleResult($data)) { |
704 | 704 | $shares[] = $this->createShare($data); |
705 | 705 | } |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | $shares2 = []; |
715 | 715 | |
716 | 716 | $start = 0; |
717 | - while(true) { |
|
717 | + while (true) { |
|
718 | 718 | $groups = array_slice($allGroups, $start, 100); |
719 | 719 | $start += 100; |
720 | 720 | |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | )); |
758 | 758 | |
759 | 759 | $cursor = $qb->execute(); |
760 | - while($data = $cursor->fetch()) { |
|
760 | + while ($data = $cursor->fetch()) { |
|
761 | 761 | if ($offset > 0) { |
762 | 762 | $offset--; |
763 | 763 | continue; |
@@ -826,14 +826,14 @@ discard block |
||
826 | 826 | */ |
827 | 827 | private function createShare($data) { |
828 | 828 | $share = new Share($this->rootFolder, $this->userManager); |
829 | - $share->setId((int)$data['id']) |
|
830 | - ->setShareType((int)$data['share_type']) |
|
831 | - ->setPermissions((int)$data['permissions']) |
|
829 | + $share->setId((int) $data['id']) |
|
830 | + ->setShareType((int) $data['share_type']) |
|
831 | + ->setPermissions((int) $data['permissions']) |
|
832 | 832 | ->setTarget($data['file_target']) |
833 | - ->setMailSend((bool)$data['mail_send']); |
|
833 | + ->setMailSend((bool) $data['mail_send']); |
|
834 | 834 | |
835 | 835 | $shareTime = new \DateTime(); |
836 | - $shareTime->setTimestamp((int)$data['stime']); |
|
836 | + $shareTime->setTimestamp((int) $data['stime']); |
|
837 | 837 | $share->setShareTime($shareTime); |
838 | 838 | |
839 | 839 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | $share->setSharedBy($data['uid_initiator']); |
849 | 849 | $share->setShareOwner($data['uid_owner']); |
850 | 850 | |
851 | - $share->setNodeId((int)$data['file_source']); |
|
851 | + $share->setNodeId((int) $data['file_source']); |
|
852 | 852 | $share->setNodeType($data['item_type']); |
853 | 853 | |
854 | 854 | if ($data['expiration'] !== null) { |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | if (isset($data['f_permissions'])) { |
860 | 860 | $entryData = $data; |
861 | 861 | $entryData['permissions'] = $entryData['f_permissions']; |
862 | - $entryData['parent'] = $entryData['f_parent'];; |
|
862 | + $entryData['parent'] = $entryData['f_parent']; ; |
|
863 | 863 | $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
864 | 864 | \OC::$server->getMimeTypeLoader())); |
865 | 865 | } |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | $result = []; |
879 | 879 | |
880 | 880 | $start = 0; |
881 | - while(true) { |
|
881 | + while (true) { |
|
882 | 882 | /** @var Share[] $shareSlice */ |
883 | 883 | $shareSlice = array_slice($shares, $start, 100); |
884 | 884 | $start += 100; |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | $shareMap = []; |
894 | 894 | |
895 | 895 | foreach ($shareSlice as $share) { |
896 | - $ids[] = (int)$share->getId(); |
|
896 | + $ids[] = (int) $share->getId(); |
|
897 | 897 | $shareMap[$share->getId()] = $share; |
898 | 898 | } |
899 | 899 | |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | |
911 | 911 | $stmt = $query->execute(); |
912 | 912 | |
913 | - while($data = $stmt->fetch()) { |
|
914 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
913 | + while ($data = $stmt->fetch()) { |
|
914 | + $shareMap[$data['parent']]->setPermissions((int) $data['permissions']); |
|
915 | 915 | $shareMap[$data['parent']]->setTarget($data['file_target']); |
916 | 916 | } |
917 | 917 | |
@@ -1008,8 +1008,8 @@ discard block |
||
1008 | 1008 | |
1009 | 1009 | $cursor = $qb->execute(); |
1010 | 1010 | $ids = []; |
1011 | - while($row = $cursor->fetch()) { |
|
1012 | - $ids[] = (int)$row['id']; |
|
1011 | + while ($row = $cursor->fetch()) { |
|
1012 | + $ids[] = (int) $row['id']; |
|
1013 | 1013 | } |
1014 | 1014 | $cursor->closeCursor(); |
1015 | 1015 | |
@@ -1051,8 +1051,8 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | $cursor = $qb->execute(); |
1053 | 1053 | $ids = []; |
1054 | - while($row = $cursor->fetch()) { |
|
1055 | - $ids[] = (int)$row['id']; |
|
1054 | + while ($row = $cursor->fetch()) { |
|
1055 | + $ids[] = (int) $row['id']; |
|
1056 | 1056 | } |
1057 | 1057 | $cursor->closeCursor(); |
1058 | 1058 | |
@@ -1106,8 +1106,8 @@ discard block |
||
1106 | 1106 | |
1107 | 1107 | $users = []; |
1108 | 1108 | $link = false; |
1109 | - while($row = $cursor->fetch()) { |
|
1110 | - $type = (int)$row['share_type']; |
|
1109 | + while ($row = $cursor->fetch()) { |
|
1110 | + $type = (int) $row['share_type']; |
|
1111 | 1111 | if ($type === \OCP\Share::SHARE_TYPE_USER) { |
1112 | 1112 | $uid = $row['share_with']; |
1113 | 1113 | $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
@@ -46,1140 +46,1140 @@ |
||
46 | 46 | */ |
47 | 47 | class DefaultShareProvider implements IShareProvider { |
48 | 48 | |
49 | - // Special share type for user modified group shares |
|
50 | - const SHARE_TYPE_USERGROUP = 2; |
|
51 | - |
|
52 | - /** @var IDBConnection */ |
|
53 | - private $dbConn; |
|
54 | - |
|
55 | - /** @var IUserManager */ |
|
56 | - private $userManager; |
|
57 | - |
|
58 | - /** @var IGroupManager */ |
|
59 | - private $groupManager; |
|
60 | - |
|
61 | - /** @var IRootFolder */ |
|
62 | - private $rootFolder; |
|
63 | - |
|
64 | - /** |
|
65 | - * DefaultShareProvider constructor. |
|
66 | - * |
|
67 | - * @param IDBConnection $connection |
|
68 | - * @param IUserManager $userManager |
|
69 | - * @param IGroupManager $groupManager |
|
70 | - * @param IRootFolder $rootFolder |
|
71 | - */ |
|
72 | - public function __construct( |
|
73 | - IDBConnection $connection, |
|
74 | - IUserManager $userManager, |
|
75 | - IGroupManager $groupManager, |
|
76 | - IRootFolder $rootFolder) { |
|
77 | - $this->dbConn = $connection; |
|
78 | - $this->userManager = $userManager; |
|
79 | - $this->groupManager = $groupManager; |
|
80 | - $this->rootFolder = $rootFolder; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Return the identifier of this provider. |
|
85 | - * |
|
86 | - * @return string Containing only [a-zA-Z0-9] |
|
87 | - */ |
|
88 | - public function identifier() { |
|
89 | - return 'ocinternal'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Share a path |
|
94 | - * |
|
95 | - * @param \OCP\Share\IShare $share |
|
96 | - * @return \OCP\Share\IShare The share object |
|
97 | - * @throws ShareNotFound |
|
98 | - * @throws \Exception |
|
99 | - */ |
|
100 | - public function create(\OCP\Share\IShare $share) { |
|
101 | - $qb = $this->dbConn->getQueryBuilder(); |
|
102 | - |
|
103 | - $qb->insert('share'); |
|
104 | - $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
105 | - |
|
106 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
107 | - //Set the UID of the user we share with |
|
108 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
109 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
110 | - //Set the GID of the group we share with |
|
111 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
112 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
113 | - //Set the token of the share |
|
114 | - $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
115 | - |
|
116 | - //If a password is set store it |
|
117 | - if ($share->getPassword() !== null) { |
|
118 | - $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
119 | - } |
|
120 | - |
|
121 | - //If an expiration date is set store it |
|
122 | - if ($share->getExpirationDate() !== null) { |
|
123 | - $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
124 | - } |
|
125 | - |
|
126 | - if (method_exists($share, 'getParent')) { |
|
127 | - $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
128 | - } |
|
129 | - } else { |
|
130 | - throw new \Exception('invalid share type!'); |
|
131 | - } |
|
132 | - |
|
133 | - // Set what is shares |
|
134 | - $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
135 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
136 | - $qb->setParameter('itemType', 'file'); |
|
137 | - } else { |
|
138 | - $qb->setParameter('itemType', 'folder'); |
|
139 | - } |
|
140 | - |
|
141 | - // Set the file id |
|
142 | - $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
143 | - $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
144 | - |
|
145 | - // set the permissions |
|
146 | - $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
147 | - |
|
148 | - // Set who created this share |
|
149 | - $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
150 | - |
|
151 | - // Set who is the owner of this file/folder (and this the owner of the share) |
|
152 | - $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
153 | - |
|
154 | - // Set the file target |
|
155 | - $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
156 | - |
|
157 | - // Set the time this share was created |
|
158 | - $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
159 | - |
|
160 | - // insert the data and fetch the id of the share |
|
161 | - $this->dbConn->beginTransaction(); |
|
162 | - $qb->execute(); |
|
163 | - $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
164 | - |
|
165 | - // Now fetch the inserted share and create a complete share object |
|
166 | - $qb = $this->dbConn->getQueryBuilder(); |
|
167 | - $qb->select('*') |
|
168 | - ->from('share') |
|
169 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
170 | - |
|
171 | - $cursor = $qb->execute(); |
|
172 | - $data = $cursor->fetch(); |
|
173 | - $this->dbConn->commit(); |
|
174 | - $cursor->closeCursor(); |
|
175 | - |
|
176 | - if ($data === false) { |
|
177 | - throw new ShareNotFound(); |
|
178 | - } |
|
179 | - |
|
180 | - $share = $this->createShare($data); |
|
181 | - return $share; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Update a share |
|
186 | - * |
|
187 | - * @param \OCP\Share\IShare $share |
|
188 | - * @return \OCP\Share\IShare The share object |
|
189 | - */ |
|
190 | - public function update(\OCP\Share\IShare $share) { |
|
191 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
192 | - /* |
|
49 | + // Special share type for user modified group shares |
|
50 | + const SHARE_TYPE_USERGROUP = 2; |
|
51 | + |
|
52 | + /** @var IDBConnection */ |
|
53 | + private $dbConn; |
|
54 | + |
|
55 | + /** @var IUserManager */ |
|
56 | + private $userManager; |
|
57 | + |
|
58 | + /** @var IGroupManager */ |
|
59 | + private $groupManager; |
|
60 | + |
|
61 | + /** @var IRootFolder */ |
|
62 | + private $rootFolder; |
|
63 | + |
|
64 | + /** |
|
65 | + * DefaultShareProvider constructor. |
|
66 | + * |
|
67 | + * @param IDBConnection $connection |
|
68 | + * @param IUserManager $userManager |
|
69 | + * @param IGroupManager $groupManager |
|
70 | + * @param IRootFolder $rootFolder |
|
71 | + */ |
|
72 | + public function __construct( |
|
73 | + IDBConnection $connection, |
|
74 | + IUserManager $userManager, |
|
75 | + IGroupManager $groupManager, |
|
76 | + IRootFolder $rootFolder) { |
|
77 | + $this->dbConn = $connection; |
|
78 | + $this->userManager = $userManager; |
|
79 | + $this->groupManager = $groupManager; |
|
80 | + $this->rootFolder = $rootFolder; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Return the identifier of this provider. |
|
85 | + * |
|
86 | + * @return string Containing only [a-zA-Z0-9] |
|
87 | + */ |
|
88 | + public function identifier() { |
|
89 | + return 'ocinternal'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Share a path |
|
94 | + * |
|
95 | + * @param \OCP\Share\IShare $share |
|
96 | + * @return \OCP\Share\IShare The share object |
|
97 | + * @throws ShareNotFound |
|
98 | + * @throws \Exception |
|
99 | + */ |
|
100 | + public function create(\OCP\Share\IShare $share) { |
|
101 | + $qb = $this->dbConn->getQueryBuilder(); |
|
102 | + |
|
103 | + $qb->insert('share'); |
|
104 | + $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
105 | + |
|
106 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
107 | + //Set the UID of the user we share with |
|
108 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
109 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
110 | + //Set the GID of the group we share with |
|
111 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
112 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
113 | + //Set the token of the share |
|
114 | + $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
115 | + |
|
116 | + //If a password is set store it |
|
117 | + if ($share->getPassword() !== null) { |
|
118 | + $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
119 | + } |
|
120 | + |
|
121 | + //If an expiration date is set store it |
|
122 | + if ($share->getExpirationDate() !== null) { |
|
123 | + $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
124 | + } |
|
125 | + |
|
126 | + if (method_exists($share, 'getParent')) { |
|
127 | + $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
128 | + } |
|
129 | + } else { |
|
130 | + throw new \Exception('invalid share type!'); |
|
131 | + } |
|
132 | + |
|
133 | + // Set what is shares |
|
134 | + $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
135 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
136 | + $qb->setParameter('itemType', 'file'); |
|
137 | + } else { |
|
138 | + $qb->setParameter('itemType', 'folder'); |
|
139 | + } |
|
140 | + |
|
141 | + // Set the file id |
|
142 | + $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
143 | + $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
144 | + |
|
145 | + // set the permissions |
|
146 | + $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
147 | + |
|
148 | + // Set who created this share |
|
149 | + $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
150 | + |
|
151 | + // Set who is the owner of this file/folder (and this the owner of the share) |
|
152 | + $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
153 | + |
|
154 | + // Set the file target |
|
155 | + $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
156 | + |
|
157 | + // Set the time this share was created |
|
158 | + $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
159 | + |
|
160 | + // insert the data and fetch the id of the share |
|
161 | + $this->dbConn->beginTransaction(); |
|
162 | + $qb->execute(); |
|
163 | + $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
164 | + |
|
165 | + // Now fetch the inserted share and create a complete share object |
|
166 | + $qb = $this->dbConn->getQueryBuilder(); |
|
167 | + $qb->select('*') |
|
168 | + ->from('share') |
|
169 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
170 | + |
|
171 | + $cursor = $qb->execute(); |
|
172 | + $data = $cursor->fetch(); |
|
173 | + $this->dbConn->commit(); |
|
174 | + $cursor->closeCursor(); |
|
175 | + |
|
176 | + if ($data === false) { |
|
177 | + throw new ShareNotFound(); |
|
178 | + } |
|
179 | + |
|
180 | + $share = $this->createShare($data); |
|
181 | + return $share; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Update a share |
|
186 | + * |
|
187 | + * @param \OCP\Share\IShare $share |
|
188 | + * @return \OCP\Share\IShare The share object |
|
189 | + */ |
|
190 | + public function update(\OCP\Share\IShare $share) { |
|
191 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
192 | + /* |
|
193 | 193 | * We allow updating the recipient on user shares. |
194 | 194 | */ |
195 | - $qb = $this->dbConn->getQueryBuilder(); |
|
196 | - $qb->update('share') |
|
197 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
198 | - ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
199 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
200 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
201 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
202 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
203 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
204 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
205 | - ->execute(); |
|
206 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
207 | - $qb = $this->dbConn->getQueryBuilder(); |
|
208 | - $qb->update('share') |
|
209 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
210 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
211 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
212 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
213 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
214 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
215 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
216 | - ->execute(); |
|
217 | - |
|
218 | - /* |
|
195 | + $qb = $this->dbConn->getQueryBuilder(); |
|
196 | + $qb->update('share') |
|
197 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
198 | + ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
199 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
200 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
201 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
202 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
203 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
204 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
205 | + ->execute(); |
|
206 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
207 | + $qb = $this->dbConn->getQueryBuilder(); |
|
208 | + $qb->update('share') |
|
209 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
210 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
211 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
212 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
213 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
214 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
215 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
216 | + ->execute(); |
|
217 | + |
|
218 | + /* |
|
219 | 219 | * Update all user defined group shares |
220 | 220 | */ |
221 | - $qb = $this->dbConn->getQueryBuilder(); |
|
222 | - $qb->update('share') |
|
223 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
224 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
225 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
226 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
227 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
228 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
229 | - ->execute(); |
|
230 | - |
|
231 | - /* |
|
221 | + $qb = $this->dbConn->getQueryBuilder(); |
|
222 | + $qb->update('share') |
|
223 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
224 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
225 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
226 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
227 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
228 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
229 | + ->execute(); |
|
230 | + |
|
231 | + /* |
|
232 | 232 | * Now update the permissions for all children that have not set it to 0 |
233 | 233 | */ |
234 | - $qb = $this->dbConn->getQueryBuilder(); |
|
235 | - $qb->update('share') |
|
236 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
237 | - ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
238 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
239 | - ->execute(); |
|
240 | - |
|
241 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
242 | - $qb = $this->dbConn->getQueryBuilder(); |
|
243 | - $qb->update('share') |
|
244 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
245 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
246 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
247 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
248 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
249 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
250 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
251 | - ->set('token', $qb->createNamedParameter($share->getToken())) |
|
252 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
253 | - ->execute(); |
|
254 | - } |
|
255 | - |
|
256 | - return $share; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Get all children of this share |
|
261 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
262 | - * |
|
263 | - * @param \OCP\Share\IShare $parent |
|
264 | - * @return \OCP\Share\IShare[] |
|
265 | - */ |
|
266 | - public function getChildren(\OCP\Share\IShare $parent) { |
|
267 | - $children = []; |
|
268 | - |
|
269 | - $qb = $this->dbConn->getQueryBuilder(); |
|
270 | - $qb->select('*') |
|
271 | - ->from('share') |
|
272 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
273 | - ->andWhere( |
|
274 | - $qb->expr()->in( |
|
275 | - 'share_type', |
|
276 | - $qb->createNamedParameter([ |
|
277 | - \OCP\Share::SHARE_TYPE_USER, |
|
278 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
279 | - \OCP\Share::SHARE_TYPE_LINK, |
|
280 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
281 | - ) |
|
282 | - ) |
|
283 | - ->andWhere($qb->expr()->orX( |
|
284 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
285 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
286 | - )) |
|
287 | - ->orderBy('id'); |
|
288 | - |
|
289 | - $cursor = $qb->execute(); |
|
290 | - while($data = $cursor->fetch()) { |
|
291 | - $children[] = $this->createShare($data); |
|
292 | - } |
|
293 | - $cursor->closeCursor(); |
|
294 | - |
|
295 | - return $children; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Delete a share |
|
300 | - * |
|
301 | - * @param \OCP\Share\IShare $share |
|
302 | - */ |
|
303 | - public function delete(\OCP\Share\IShare $share) { |
|
304 | - $qb = $this->dbConn->getQueryBuilder(); |
|
305 | - $qb->delete('share') |
|
306 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
307 | - |
|
308 | - /* |
|
234 | + $qb = $this->dbConn->getQueryBuilder(); |
|
235 | + $qb->update('share') |
|
236 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
237 | + ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
238 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
239 | + ->execute(); |
|
240 | + |
|
241 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
242 | + $qb = $this->dbConn->getQueryBuilder(); |
|
243 | + $qb->update('share') |
|
244 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
245 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
246 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
247 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
248 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
249 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
250 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
251 | + ->set('token', $qb->createNamedParameter($share->getToken())) |
|
252 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
253 | + ->execute(); |
|
254 | + } |
|
255 | + |
|
256 | + return $share; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Get all children of this share |
|
261 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
262 | + * |
|
263 | + * @param \OCP\Share\IShare $parent |
|
264 | + * @return \OCP\Share\IShare[] |
|
265 | + */ |
|
266 | + public function getChildren(\OCP\Share\IShare $parent) { |
|
267 | + $children = []; |
|
268 | + |
|
269 | + $qb = $this->dbConn->getQueryBuilder(); |
|
270 | + $qb->select('*') |
|
271 | + ->from('share') |
|
272 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
273 | + ->andWhere( |
|
274 | + $qb->expr()->in( |
|
275 | + 'share_type', |
|
276 | + $qb->createNamedParameter([ |
|
277 | + \OCP\Share::SHARE_TYPE_USER, |
|
278 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
279 | + \OCP\Share::SHARE_TYPE_LINK, |
|
280 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
281 | + ) |
|
282 | + ) |
|
283 | + ->andWhere($qb->expr()->orX( |
|
284 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
285 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
286 | + )) |
|
287 | + ->orderBy('id'); |
|
288 | + |
|
289 | + $cursor = $qb->execute(); |
|
290 | + while($data = $cursor->fetch()) { |
|
291 | + $children[] = $this->createShare($data); |
|
292 | + } |
|
293 | + $cursor->closeCursor(); |
|
294 | + |
|
295 | + return $children; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Delete a share |
|
300 | + * |
|
301 | + * @param \OCP\Share\IShare $share |
|
302 | + */ |
|
303 | + public function delete(\OCP\Share\IShare $share) { |
|
304 | + $qb = $this->dbConn->getQueryBuilder(); |
|
305 | + $qb->delete('share') |
|
306 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
307 | + |
|
308 | + /* |
|
309 | 309 | * If the share is a group share delete all possible |
310 | 310 | * user defined groups shares. |
311 | 311 | */ |
312 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
313 | - $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
314 | - } |
|
315 | - |
|
316 | - $qb->execute(); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Unshare a share from the recipient. If this is a group share |
|
321 | - * this means we need a special entry in the share db. |
|
322 | - * |
|
323 | - * @param \OCP\Share\IShare $share |
|
324 | - * @param string $recipient UserId of recipient |
|
325 | - * @throws BackendError |
|
326 | - * @throws ProviderException |
|
327 | - */ |
|
328 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
329 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
330 | - |
|
331 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
332 | - $user = $this->userManager->get($recipient); |
|
333 | - |
|
334 | - if (is_null($group)) { |
|
335 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
336 | - } |
|
337 | - |
|
338 | - if (!$group->inGroup($user)) { |
|
339 | - throw new ProviderException('Recipient not in receiving group'); |
|
340 | - } |
|
341 | - |
|
342 | - // Try to fetch user specific share |
|
343 | - $qb = $this->dbConn->getQueryBuilder(); |
|
344 | - $stmt = $qb->select('*') |
|
345 | - ->from('share') |
|
346 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
347 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
348 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
349 | - ->andWhere($qb->expr()->orX( |
|
350 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
351 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
352 | - )) |
|
353 | - ->execute(); |
|
354 | - |
|
355 | - $data = $stmt->fetch(); |
|
356 | - |
|
357 | - /* |
|
312 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
313 | + $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
314 | + } |
|
315 | + |
|
316 | + $qb->execute(); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Unshare a share from the recipient. If this is a group share |
|
321 | + * this means we need a special entry in the share db. |
|
322 | + * |
|
323 | + * @param \OCP\Share\IShare $share |
|
324 | + * @param string $recipient UserId of recipient |
|
325 | + * @throws BackendError |
|
326 | + * @throws ProviderException |
|
327 | + */ |
|
328 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
329 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
330 | + |
|
331 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
332 | + $user = $this->userManager->get($recipient); |
|
333 | + |
|
334 | + if (is_null($group)) { |
|
335 | + throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
336 | + } |
|
337 | + |
|
338 | + if (!$group->inGroup($user)) { |
|
339 | + throw new ProviderException('Recipient not in receiving group'); |
|
340 | + } |
|
341 | + |
|
342 | + // Try to fetch user specific share |
|
343 | + $qb = $this->dbConn->getQueryBuilder(); |
|
344 | + $stmt = $qb->select('*') |
|
345 | + ->from('share') |
|
346 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
347 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
348 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
349 | + ->andWhere($qb->expr()->orX( |
|
350 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
351 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
352 | + )) |
|
353 | + ->execute(); |
|
354 | + |
|
355 | + $data = $stmt->fetch(); |
|
356 | + |
|
357 | + /* |
|
358 | 358 | * Check if there already is a user specific group share. |
359 | 359 | * If there is update it (if required). |
360 | 360 | */ |
361 | - if ($data === false) { |
|
362 | - $qb = $this->dbConn->getQueryBuilder(); |
|
363 | - |
|
364 | - $type = $share->getNodeType(); |
|
365 | - |
|
366 | - //Insert new share |
|
367 | - $qb->insert('share') |
|
368 | - ->values([ |
|
369 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
370 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
371 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
372 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
373 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
374 | - 'item_type' => $qb->createNamedParameter($type), |
|
375 | - 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
376 | - 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
377 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
378 | - 'permissions' => $qb->createNamedParameter(0), |
|
379 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
380 | - ])->execute(); |
|
381 | - |
|
382 | - } else if ($data['permissions'] !== 0) { |
|
383 | - |
|
384 | - // Update existing usergroup share |
|
385 | - $qb = $this->dbConn->getQueryBuilder(); |
|
386 | - $qb->update('share') |
|
387 | - ->set('permissions', $qb->createNamedParameter(0)) |
|
388 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
389 | - ->execute(); |
|
390 | - } |
|
391 | - |
|
392 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
393 | - |
|
394 | - if ($share->getSharedWith() !== $recipient) { |
|
395 | - throw new ProviderException('Recipient does not match'); |
|
396 | - } |
|
397 | - |
|
398 | - // We can just delete user and link shares |
|
399 | - $this->delete($share); |
|
400 | - } else { |
|
401 | - throw new ProviderException('Invalid shareType'); |
|
402 | - } |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * @inheritdoc |
|
407 | - */ |
|
408 | - public function move(\OCP\Share\IShare $share, $recipient) { |
|
409 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
410 | - // Just update the target |
|
411 | - $qb = $this->dbConn->getQueryBuilder(); |
|
412 | - $qb->update('share') |
|
413 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
414 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
415 | - ->execute(); |
|
416 | - |
|
417 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
418 | - |
|
419 | - // Check if there is a usergroup share |
|
420 | - $qb = $this->dbConn->getQueryBuilder(); |
|
421 | - $stmt = $qb->select('id') |
|
422 | - ->from('share') |
|
423 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
424 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
425 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
426 | - ->andWhere($qb->expr()->orX( |
|
427 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
428 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
429 | - )) |
|
430 | - ->setMaxResults(1) |
|
431 | - ->execute(); |
|
432 | - |
|
433 | - $data = $stmt->fetch(); |
|
434 | - $stmt->closeCursor(); |
|
435 | - |
|
436 | - if ($data === false) { |
|
437 | - // No usergroup share yet. Create one. |
|
438 | - $qb = $this->dbConn->getQueryBuilder(); |
|
439 | - $qb->insert('share') |
|
440 | - ->values([ |
|
441 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
442 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
443 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
444 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
445 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
446 | - 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
447 | - 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
448 | - 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
449 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
450 | - 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
451 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
452 | - ])->execute(); |
|
453 | - } else { |
|
454 | - // Already a usergroup share. Update it. |
|
455 | - $qb = $this->dbConn->getQueryBuilder(); |
|
456 | - $qb->update('share') |
|
457 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
458 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
459 | - ->execute(); |
|
460 | - } |
|
461 | - } |
|
462 | - |
|
463 | - return $share; |
|
464 | - } |
|
465 | - |
|
466 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
467 | - $qb = $this->dbConn->getQueryBuilder(); |
|
468 | - $qb->select('*') |
|
469 | - ->from('share', 's') |
|
470 | - ->andWhere($qb->expr()->orX( |
|
471 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
472 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
473 | - )); |
|
474 | - |
|
475 | - $qb->andWhere($qb->expr()->orX( |
|
476 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
477 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
478 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
479 | - )); |
|
480 | - |
|
481 | - /** |
|
482 | - * Reshares for this user are shares where they are the owner. |
|
483 | - */ |
|
484 | - if ($reshares === false) { |
|
485 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
486 | - } else { |
|
487 | - $qb->andWhere( |
|
488 | - $qb->expr()->orX( |
|
489 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
490 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
491 | - ) |
|
492 | - ); |
|
493 | - } |
|
494 | - |
|
495 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
497 | - |
|
498 | - $qb->orderBy('id'); |
|
499 | - |
|
500 | - $cursor = $qb->execute(); |
|
501 | - $shares = []; |
|
502 | - while ($data = $cursor->fetch()) { |
|
503 | - $shares[$data['fileid']][] = $this->createShare($data); |
|
504 | - } |
|
505 | - $cursor->closeCursor(); |
|
506 | - |
|
507 | - return $shares; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @inheritdoc |
|
512 | - */ |
|
513 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
514 | - $qb = $this->dbConn->getQueryBuilder(); |
|
515 | - $qb->select('*') |
|
516 | - ->from('share') |
|
517 | - ->andWhere($qb->expr()->orX( |
|
518 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
519 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
520 | - )); |
|
521 | - |
|
522 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
523 | - |
|
524 | - /** |
|
525 | - * Reshares for this user are shares where they are the owner. |
|
526 | - */ |
|
527 | - if ($reshares === false) { |
|
528 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
529 | - } else { |
|
530 | - $qb->andWhere( |
|
531 | - $qb->expr()->orX( |
|
532 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
533 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
534 | - ) |
|
535 | - ); |
|
536 | - } |
|
537 | - |
|
538 | - if ($node !== null) { |
|
539 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
540 | - } |
|
541 | - |
|
542 | - if ($limit !== -1) { |
|
543 | - $qb->setMaxResults($limit); |
|
544 | - } |
|
545 | - |
|
546 | - $qb->setFirstResult($offset); |
|
547 | - $qb->orderBy('id'); |
|
548 | - |
|
549 | - $cursor = $qb->execute(); |
|
550 | - $shares = []; |
|
551 | - while($data = $cursor->fetch()) { |
|
552 | - $shares[] = $this->createShare($data); |
|
553 | - } |
|
554 | - $cursor->closeCursor(); |
|
555 | - |
|
556 | - return $shares; |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * @inheritdoc |
|
561 | - */ |
|
562 | - public function getShareById($id, $recipientId = null) { |
|
563 | - $qb = $this->dbConn->getQueryBuilder(); |
|
564 | - |
|
565 | - $qb->select('*') |
|
566 | - ->from('share') |
|
567 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
568 | - ->andWhere( |
|
569 | - $qb->expr()->in( |
|
570 | - 'share_type', |
|
571 | - $qb->createNamedParameter([ |
|
572 | - \OCP\Share::SHARE_TYPE_USER, |
|
573 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
574 | - \OCP\Share::SHARE_TYPE_LINK, |
|
575 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
576 | - ) |
|
577 | - ) |
|
578 | - ->andWhere($qb->expr()->orX( |
|
579 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
580 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
581 | - )); |
|
582 | - |
|
583 | - $cursor = $qb->execute(); |
|
584 | - $data = $cursor->fetch(); |
|
585 | - $cursor->closeCursor(); |
|
586 | - |
|
587 | - if ($data === false) { |
|
588 | - throw new ShareNotFound(); |
|
589 | - } |
|
590 | - |
|
591 | - try { |
|
592 | - $share = $this->createShare($data); |
|
593 | - } catch (InvalidShare $e) { |
|
594 | - throw new ShareNotFound(); |
|
595 | - } |
|
596 | - |
|
597 | - // If the recipient is set for a group share resolve to that user |
|
598 | - if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
599 | - $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
600 | - } |
|
601 | - |
|
602 | - return $share; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Get shares for a given path |
|
607 | - * |
|
608 | - * @param \OCP\Files\Node $path |
|
609 | - * @return \OCP\Share\IShare[] |
|
610 | - */ |
|
611 | - public function getSharesByPath(Node $path) { |
|
612 | - $qb = $this->dbConn->getQueryBuilder(); |
|
613 | - |
|
614 | - $cursor = $qb->select('*') |
|
615 | - ->from('share') |
|
616 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
617 | - ->andWhere( |
|
618 | - $qb->expr()->orX( |
|
619 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
620 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
621 | - ) |
|
622 | - ) |
|
623 | - ->andWhere($qb->expr()->orX( |
|
624 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
625 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
626 | - )) |
|
627 | - ->execute(); |
|
628 | - |
|
629 | - $shares = []; |
|
630 | - while($data = $cursor->fetch()) { |
|
631 | - $shares[] = $this->createShare($data); |
|
632 | - } |
|
633 | - $cursor->closeCursor(); |
|
634 | - |
|
635 | - return $shares; |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * Returns whether the given database result can be interpreted as |
|
640 | - * a share with accessible file (not trashed, not deleted) |
|
641 | - */ |
|
642 | - private function isAccessibleResult($data) { |
|
643 | - // exclude shares leading to deleted file entries |
|
644 | - if ($data['fileid'] === null) { |
|
645 | - return false; |
|
646 | - } |
|
647 | - |
|
648 | - // exclude shares leading to trashbin on home storages |
|
649 | - $pathSections = explode('/', $data['path'], 2); |
|
650 | - // FIXME: would not detect rare md5'd home storage case properly |
|
651 | - if ($pathSections[0] !== 'files' |
|
652 | - && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
653 | - return false; |
|
654 | - } |
|
655 | - return true; |
|
656 | - } |
|
657 | - |
|
658 | - /** |
|
659 | - * @inheritdoc |
|
660 | - */ |
|
661 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
662 | - /** @var Share[] $shares */ |
|
663 | - $shares = []; |
|
664 | - |
|
665 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
666 | - //Get shares directly with this user |
|
667 | - $qb = $this->dbConn->getQueryBuilder(); |
|
668 | - $qb->select('s.*', |
|
669 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
670 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
671 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
672 | - ) |
|
673 | - ->selectAlias('st.id', 'storage_string_id') |
|
674 | - ->from('share', 's') |
|
675 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
676 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
677 | - |
|
678 | - // Order by id |
|
679 | - $qb->orderBy('s.id'); |
|
680 | - |
|
681 | - // Set limit and offset |
|
682 | - if ($limit !== -1) { |
|
683 | - $qb->setMaxResults($limit); |
|
684 | - } |
|
685 | - $qb->setFirstResult($offset); |
|
686 | - |
|
687 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
688 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
689 | - ->andWhere($qb->expr()->orX( |
|
690 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
691 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
692 | - )); |
|
693 | - |
|
694 | - // Filter by node if provided |
|
695 | - if ($node !== null) { |
|
696 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
697 | - } |
|
698 | - |
|
699 | - $cursor = $qb->execute(); |
|
700 | - |
|
701 | - while($data = $cursor->fetch()) { |
|
702 | - if ($this->isAccessibleResult($data)) { |
|
703 | - $shares[] = $this->createShare($data); |
|
704 | - } |
|
705 | - } |
|
706 | - $cursor->closeCursor(); |
|
707 | - |
|
708 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
709 | - $user = $this->userManager->get($userId); |
|
710 | - $allGroups = $this->groupManager->getUserGroups($user); |
|
711 | - |
|
712 | - /** @var Share[] $shares2 */ |
|
713 | - $shares2 = []; |
|
714 | - |
|
715 | - $start = 0; |
|
716 | - while(true) { |
|
717 | - $groups = array_slice($allGroups, $start, 100); |
|
718 | - $start += 100; |
|
719 | - |
|
720 | - if ($groups === []) { |
|
721 | - break; |
|
722 | - } |
|
723 | - |
|
724 | - $qb = $this->dbConn->getQueryBuilder(); |
|
725 | - $qb->select('s.*', |
|
726 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
727 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
728 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
729 | - ) |
|
730 | - ->selectAlias('st.id', 'storage_string_id') |
|
731 | - ->from('share', 's') |
|
732 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
733 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
734 | - ->orderBy('s.id') |
|
735 | - ->setFirstResult(0); |
|
736 | - |
|
737 | - if ($limit !== -1) { |
|
738 | - $qb->setMaxResults($limit - count($shares)); |
|
739 | - } |
|
740 | - |
|
741 | - // Filter by node if provided |
|
742 | - if ($node !== null) { |
|
743 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - $groups = array_filter($groups, function($group) { return $group instanceof IGroup; }); |
|
748 | - $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
749 | - |
|
750 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
751 | - ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
752 | - $groups, |
|
753 | - IQueryBuilder::PARAM_STR_ARRAY |
|
754 | - ))) |
|
755 | - ->andWhere($qb->expr()->orX( |
|
756 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
757 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
758 | - )); |
|
759 | - |
|
760 | - $cursor = $qb->execute(); |
|
761 | - while($data = $cursor->fetch()) { |
|
762 | - if ($offset > 0) { |
|
763 | - $offset--; |
|
764 | - continue; |
|
765 | - } |
|
766 | - |
|
767 | - if ($this->isAccessibleResult($data)) { |
|
768 | - $shares2[] = $this->createShare($data); |
|
769 | - } |
|
770 | - } |
|
771 | - $cursor->closeCursor(); |
|
772 | - } |
|
773 | - |
|
774 | - /* |
|
361 | + if ($data === false) { |
|
362 | + $qb = $this->dbConn->getQueryBuilder(); |
|
363 | + |
|
364 | + $type = $share->getNodeType(); |
|
365 | + |
|
366 | + //Insert new share |
|
367 | + $qb->insert('share') |
|
368 | + ->values([ |
|
369 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
370 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
371 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
372 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
373 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
374 | + 'item_type' => $qb->createNamedParameter($type), |
|
375 | + 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
376 | + 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
377 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
378 | + 'permissions' => $qb->createNamedParameter(0), |
|
379 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
380 | + ])->execute(); |
|
381 | + |
|
382 | + } else if ($data['permissions'] !== 0) { |
|
383 | + |
|
384 | + // Update existing usergroup share |
|
385 | + $qb = $this->dbConn->getQueryBuilder(); |
|
386 | + $qb->update('share') |
|
387 | + ->set('permissions', $qb->createNamedParameter(0)) |
|
388 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
389 | + ->execute(); |
|
390 | + } |
|
391 | + |
|
392 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
393 | + |
|
394 | + if ($share->getSharedWith() !== $recipient) { |
|
395 | + throw new ProviderException('Recipient does not match'); |
|
396 | + } |
|
397 | + |
|
398 | + // We can just delete user and link shares |
|
399 | + $this->delete($share); |
|
400 | + } else { |
|
401 | + throw new ProviderException('Invalid shareType'); |
|
402 | + } |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * @inheritdoc |
|
407 | + */ |
|
408 | + public function move(\OCP\Share\IShare $share, $recipient) { |
|
409 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
410 | + // Just update the target |
|
411 | + $qb = $this->dbConn->getQueryBuilder(); |
|
412 | + $qb->update('share') |
|
413 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
414 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
415 | + ->execute(); |
|
416 | + |
|
417 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
418 | + |
|
419 | + // Check if there is a usergroup share |
|
420 | + $qb = $this->dbConn->getQueryBuilder(); |
|
421 | + $stmt = $qb->select('id') |
|
422 | + ->from('share') |
|
423 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
424 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
425 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
426 | + ->andWhere($qb->expr()->orX( |
|
427 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
428 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
429 | + )) |
|
430 | + ->setMaxResults(1) |
|
431 | + ->execute(); |
|
432 | + |
|
433 | + $data = $stmt->fetch(); |
|
434 | + $stmt->closeCursor(); |
|
435 | + |
|
436 | + if ($data === false) { |
|
437 | + // No usergroup share yet. Create one. |
|
438 | + $qb = $this->dbConn->getQueryBuilder(); |
|
439 | + $qb->insert('share') |
|
440 | + ->values([ |
|
441 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
442 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
443 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
444 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
445 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
446 | + 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
447 | + 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
448 | + 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
449 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
450 | + 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
451 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
452 | + ])->execute(); |
|
453 | + } else { |
|
454 | + // Already a usergroup share. Update it. |
|
455 | + $qb = $this->dbConn->getQueryBuilder(); |
|
456 | + $qb->update('share') |
|
457 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
458 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
459 | + ->execute(); |
|
460 | + } |
|
461 | + } |
|
462 | + |
|
463 | + return $share; |
|
464 | + } |
|
465 | + |
|
466 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
467 | + $qb = $this->dbConn->getQueryBuilder(); |
|
468 | + $qb->select('*') |
|
469 | + ->from('share', 's') |
|
470 | + ->andWhere($qb->expr()->orX( |
|
471 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
472 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
473 | + )); |
|
474 | + |
|
475 | + $qb->andWhere($qb->expr()->orX( |
|
476 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
477 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
478 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
479 | + )); |
|
480 | + |
|
481 | + /** |
|
482 | + * Reshares for this user are shares where they are the owner. |
|
483 | + */ |
|
484 | + if ($reshares === false) { |
|
485 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
486 | + } else { |
|
487 | + $qb->andWhere( |
|
488 | + $qb->expr()->orX( |
|
489 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
490 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
491 | + ) |
|
492 | + ); |
|
493 | + } |
|
494 | + |
|
495 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
497 | + |
|
498 | + $qb->orderBy('id'); |
|
499 | + |
|
500 | + $cursor = $qb->execute(); |
|
501 | + $shares = []; |
|
502 | + while ($data = $cursor->fetch()) { |
|
503 | + $shares[$data['fileid']][] = $this->createShare($data); |
|
504 | + } |
|
505 | + $cursor->closeCursor(); |
|
506 | + |
|
507 | + return $shares; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @inheritdoc |
|
512 | + */ |
|
513 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
514 | + $qb = $this->dbConn->getQueryBuilder(); |
|
515 | + $qb->select('*') |
|
516 | + ->from('share') |
|
517 | + ->andWhere($qb->expr()->orX( |
|
518 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
519 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
520 | + )); |
|
521 | + |
|
522 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
523 | + |
|
524 | + /** |
|
525 | + * Reshares for this user are shares where they are the owner. |
|
526 | + */ |
|
527 | + if ($reshares === false) { |
|
528 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
529 | + } else { |
|
530 | + $qb->andWhere( |
|
531 | + $qb->expr()->orX( |
|
532 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
533 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
534 | + ) |
|
535 | + ); |
|
536 | + } |
|
537 | + |
|
538 | + if ($node !== null) { |
|
539 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
540 | + } |
|
541 | + |
|
542 | + if ($limit !== -1) { |
|
543 | + $qb->setMaxResults($limit); |
|
544 | + } |
|
545 | + |
|
546 | + $qb->setFirstResult($offset); |
|
547 | + $qb->orderBy('id'); |
|
548 | + |
|
549 | + $cursor = $qb->execute(); |
|
550 | + $shares = []; |
|
551 | + while($data = $cursor->fetch()) { |
|
552 | + $shares[] = $this->createShare($data); |
|
553 | + } |
|
554 | + $cursor->closeCursor(); |
|
555 | + |
|
556 | + return $shares; |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * @inheritdoc |
|
561 | + */ |
|
562 | + public function getShareById($id, $recipientId = null) { |
|
563 | + $qb = $this->dbConn->getQueryBuilder(); |
|
564 | + |
|
565 | + $qb->select('*') |
|
566 | + ->from('share') |
|
567 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
568 | + ->andWhere( |
|
569 | + $qb->expr()->in( |
|
570 | + 'share_type', |
|
571 | + $qb->createNamedParameter([ |
|
572 | + \OCP\Share::SHARE_TYPE_USER, |
|
573 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
574 | + \OCP\Share::SHARE_TYPE_LINK, |
|
575 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
576 | + ) |
|
577 | + ) |
|
578 | + ->andWhere($qb->expr()->orX( |
|
579 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
580 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
581 | + )); |
|
582 | + |
|
583 | + $cursor = $qb->execute(); |
|
584 | + $data = $cursor->fetch(); |
|
585 | + $cursor->closeCursor(); |
|
586 | + |
|
587 | + if ($data === false) { |
|
588 | + throw new ShareNotFound(); |
|
589 | + } |
|
590 | + |
|
591 | + try { |
|
592 | + $share = $this->createShare($data); |
|
593 | + } catch (InvalidShare $e) { |
|
594 | + throw new ShareNotFound(); |
|
595 | + } |
|
596 | + |
|
597 | + // If the recipient is set for a group share resolve to that user |
|
598 | + if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
599 | + $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
600 | + } |
|
601 | + |
|
602 | + return $share; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Get shares for a given path |
|
607 | + * |
|
608 | + * @param \OCP\Files\Node $path |
|
609 | + * @return \OCP\Share\IShare[] |
|
610 | + */ |
|
611 | + public function getSharesByPath(Node $path) { |
|
612 | + $qb = $this->dbConn->getQueryBuilder(); |
|
613 | + |
|
614 | + $cursor = $qb->select('*') |
|
615 | + ->from('share') |
|
616 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
617 | + ->andWhere( |
|
618 | + $qb->expr()->orX( |
|
619 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
620 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
621 | + ) |
|
622 | + ) |
|
623 | + ->andWhere($qb->expr()->orX( |
|
624 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
625 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
626 | + )) |
|
627 | + ->execute(); |
|
628 | + |
|
629 | + $shares = []; |
|
630 | + while($data = $cursor->fetch()) { |
|
631 | + $shares[] = $this->createShare($data); |
|
632 | + } |
|
633 | + $cursor->closeCursor(); |
|
634 | + |
|
635 | + return $shares; |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * Returns whether the given database result can be interpreted as |
|
640 | + * a share with accessible file (not trashed, not deleted) |
|
641 | + */ |
|
642 | + private function isAccessibleResult($data) { |
|
643 | + // exclude shares leading to deleted file entries |
|
644 | + if ($data['fileid'] === null) { |
|
645 | + return false; |
|
646 | + } |
|
647 | + |
|
648 | + // exclude shares leading to trashbin on home storages |
|
649 | + $pathSections = explode('/', $data['path'], 2); |
|
650 | + // FIXME: would not detect rare md5'd home storage case properly |
|
651 | + if ($pathSections[0] !== 'files' |
|
652 | + && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
653 | + return false; |
|
654 | + } |
|
655 | + return true; |
|
656 | + } |
|
657 | + |
|
658 | + /** |
|
659 | + * @inheritdoc |
|
660 | + */ |
|
661 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
662 | + /** @var Share[] $shares */ |
|
663 | + $shares = []; |
|
664 | + |
|
665 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
666 | + //Get shares directly with this user |
|
667 | + $qb = $this->dbConn->getQueryBuilder(); |
|
668 | + $qb->select('s.*', |
|
669 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
670 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
671 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
672 | + ) |
|
673 | + ->selectAlias('st.id', 'storage_string_id') |
|
674 | + ->from('share', 's') |
|
675 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
676 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
677 | + |
|
678 | + // Order by id |
|
679 | + $qb->orderBy('s.id'); |
|
680 | + |
|
681 | + // Set limit and offset |
|
682 | + if ($limit !== -1) { |
|
683 | + $qb->setMaxResults($limit); |
|
684 | + } |
|
685 | + $qb->setFirstResult($offset); |
|
686 | + |
|
687 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
688 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
689 | + ->andWhere($qb->expr()->orX( |
|
690 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
691 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
692 | + )); |
|
693 | + |
|
694 | + // Filter by node if provided |
|
695 | + if ($node !== null) { |
|
696 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
697 | + } |
|
698 | + |
|
699 | + $cursor = $qb->execute(); |
|
700 | + |
|
701 | + while($data = $cursor->fetch()) { |
|
702 | + if ($this->isAccessibleResult($data)) { |
|
703 | + $shares[] = $this->createShare($data); |
|
704 | + } |
|
705 | + } |
|
706 | + $cursor->closeCursor(); |
|
707 | + |
|
708 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
709 | + $user = $this->userManager->get($userId); |
|
710 | + $allGroups = $this->groupManager->getUserGroups($user); |
|
711 | + |
|
712 | + /** @var Share[] $shares2 */ |
|
713 | + $shares2 = []; |
|
714 | + |
|
715 | + $start = 0; |
|
716 | + while(true) { |
|
717 | + $groups = array_slice($allGroups, $start, 100); |
|
718 | + $start += 100; |
|
719 | + |
|
720 | + if ($groups === []) { |
|
721 | + break; |
|
722 | + } |
|
723 | + |
|
724 | + $qb = $this->dbConn->getQueryBuilder(); |
|
725 | + $qb->select('s.*', |
|
726 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
727 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
728 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
729 | + ) |
|
730 | + ->selectAlias('st.id', 'storage_string_id') |
|
731 | + ->from('share', 's') |
|
732 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
733 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
734 | + ->orderBy('s.id') |
|
735 | + ->setFirstResult(0); |
|
736 | + |
|
737 | + if ($limit !== -1) { |
|
738 | + $qb->setMaxResults($limit - count($shares)); |
|
739 | + } |
|
740 | + |
|
741 | + // Filter by node if provided |
|
742 | + if ($node !== null) { |
|
743 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + $groups = array_filter($groups, function($group) { return $group instanceof IGroup; }); |
|
748 | + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
749 | + |
|
750 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
751 | + ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
752 | + $groups, |
|
753 | + IQueryBuilder::PARAM_STR_ARRAY |
|
754 | + ))) |
|
755 | + ->andWhere($qb->expr()->orX( |
|
756 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
757 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
758 | + )); |
|
759 | + |
|
760 | + $cursor = $qb->execute(); |
|
761 | + while($data = $cursor->fetch()) { |
|
762 | + if ($offset > 0) { |
|
763 | + $offset--; |
|
764 | + continue; |
|
765 | + } |
|
766 | + |
|
767 | + if ($this->isAccessibleResult($data)) { |
|
768 | + $shares2[] = $this->createShare($data); |
|
769 | + } |
|
770 | + } |
|
771 | + $cursor->closeCursor(); |
|
772 | + } |
|
773 | + |
|
774 | + /* |
|
775 | 775 | * Resolve all group shares to user specific shares |
776 | 776 | */ |
777 | - $shares = $this->resolveGroupShares($shares2, $userId); |
|
778 | - } else { |
|
779 | - throw new BackendError('Invalid backend'); |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - return $shares; |
|
784 | - } |
|
785 | - |
|
786 | - /** |
|
787 | - * Get a share by token |
|
788 | - * |
|
789 | - * @param string $token |
|
790 | - * @return \OCP\Share\IShare |
|
791 | - * @throws ShareNotFound |
|
792 | - */ |
|
793 | - public function getShareByToken($token) { |
|
794 | - $qb = $this->dbConn->getQueryBuilder(); |
|
795 | - |
|
796 | - $cursor = $qb->select('*') |
|
797 | - ->from('share') |
|
798 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
799 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
800 | - ->andWhere($qb->expr()->orX( |
|
801 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
802 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
803 | - )) |
|
804 | - ->execute(); |
|
805 | - |
|
806 | - $data = $cursor->fetch(); |
|
807 | - |
|
808 | - if ($data === false) { |
|
809 | - throw new ShareNotFound(); |
|
810 | - } |
|
811 | - |
|
812 | - try { |
|
813 | - $share = $this->createShare($data); |
|
814 | - } catch (InvalidShare $e) { |
|
815 | - throw new ShareNotFound(); |
|
816 | - } |
|
817 | - |
|
818 | - return $share; |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Create a share object from an database row |
|
823 | - * |
|
824 | - * @param mixed[] $data |
|
825 | - * @return \OCP\Share\IShare |
|
826 | - * @throws InvalidShare |
|
827 | - */ |
|
828 | - private function createShare($data) { |
|
829 | - $share = new Share($this->rootFolder, $this->userManager); |
|
830 | - $share->setId((int)$data['id']) |
|
831 | - ->setShareType((int)$data['share_type']) |
|
832 | - ->setPermissions((int)$data['permissions']) |
|
833 | - ->setTarget($data['file_target']) |
|
834 | - ->setMailSend((bool)$data['mail_send']); |
|
835 | - |
|
836 | - $shareTime = new \DateTime(); |
|
837 | - $shareTime->setTimestamp((int)$data['stime']); |
|
838 | - $share->setShareTime($shareTime); |
|
839 | - |
|
840 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
841 | - $share->setSharedWith($data['share_with']); |
|
842 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
843 | - $share->setSharedWith($data['share_with']); |
|
844 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
845 | - $share->setPassword($data['password']); |
|
846 | - $share->setToken($data['token']); |
|
847 | - } |
|
848 | - |
|
849 | - $share->setSharedBy($data['uid_initiator']); |
|
850 | - $share->setShareOwner($data['uid_owner']); |
|
851 | - |
|
852 | - $share->setNodeId((int)$data['file_source']); |
|
853 | - $share->setNodeType($data['item_type']); |
|
854 | - |
|
855 | - if ($data['expiration'] !== null) { |
|
856 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
857 | - $share->setExpirationDate($expiration); |
|
858 | - } |
|
859 | - |
|
860 | - if (isset($data['f_permissions'])) { |
|
861 | - $entryData = $data; |
|
862 | - $entryData['permissions'] = $entryData['f_permissions']; |
|
863 | - $entryData['parent'] = $entryData['f_parent'];; |
|
864 | - $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
865 | - \OC::$server->getMimeTypeLoader())); |
|
866 | - } |
|
867 | - |
|
868 | - $share->setProviderId($this->identifier()); |
|
869 | - |
|
870 | - return $share; |
|
871 | - } |
|
872 | - |
|
873 | - /** |
|
874 | - * @param Share[] $shares |
|
875 | - * @param $userId |
|
876 | - * @return Share[] The updates shares if no update is found for a share return the original |
|
877 | - */ |
|
878 | - private function resolveGroupShares($shares, $userId) { |
|
879 | - $result = []; |
|
880 | - |
|
881 | - $start = 0; |
|
882 | - while(true) { |
|
883 | - /** @var Share[] $shareSlice */ |
|
884 | - $shareSlice = array_slice($shares, $start, 100); |
|
885 | - $start += 100; |
|
886 | - |
|
887 | - if ($shareSlice === []) { |
|
888 | - break; |
|
889 | - } |
|
890 | - |
|
891 | - /** @var int[] $ids */ |
|
892 | - $ids = []; |
|
893 | - /** @var Share[] $shareMap */ |
|
894 | - $shareMap = []; |
|
895 | - |
|
896 | - foreach ($shareSlice as $share) { |
|
897 | - $ids[] = (int)$share->getId(); |
|
898 | - $shareMap[$share->getId()] = $share; |
|
899 | - } |
|
900 | - |
|
901 | - $qb = $this->dbConn->getQueryBuilder(); |
|
902 | - |
|
903 | - $query = $qb->select('*') |
|
904 | - ->from('share') |
|
905 | - ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
906 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
907 | - ->andWhere($qb->expr()->orX( |
|
908 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
909 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
910 | - )); |
|
911 | - |
|
912 | - $stmt = $query->execute(); |
|
913 | - |
|
914 | - while($data = $stmt->fetch()) { |
|
915 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
916 | - $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
917 | - } |
|
918 | - |
|
919 | - $stmt->closeCursor(); |
|
920 | - |
|
921 | - foreach ($shareMap as $share) { |
|
922 | - $result[] = $share; |
|
923 | - } |
|
924 | - } |
|
925 | - |
|
926 | - return $result; |
|
927 | - } |
|
928 | - |
|
929 | - /** |
|
930 | - * A user is deleted from the system |
|
931 | - * So clean up the relevant shares. |
|
932 | - * |
|
933 | - * @param string $uid |
|
934 | - * @param int $shareType |
|
935 | - */ |
|
936 | - public function userDeleted($uid, $shareType) { |
|
937 | - $qb = $this->dbConn->getQueryBuilder(); |
|
938 | - |
|
939 | - $qb->delete('share'); |
|
940 | - |
|
941 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
942 | - /* |
|
777 | + $shares = $this->resolveGroupShares($shares2, $userId); |
|
778 | + } else { |
|
779 | + throw new BackendError('Invalid backend'); |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + return $shares; |
|
784 | + } |
|
785 | + |
|
786 | + /** |
|
787 | + * Get a share by token |
|
788 | + * |
|
789 | + * @param string $token |
|
790 | + * @return \OCP\Share\IShare |
|
791 | + * @throws ShareNotFound |
|
792 | + */ |
|
793 | + public function getShareByToken($token) { |
|
794 | + $qb = $this->dbConn->getQueryBuilder(); |
|
795 | + |
|
796 | + $cursor = $qb->select('*') |
|
797 | + ->from('share') |
|
798 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
799 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
800 | + ->andWhere($qb->expr()->orX( |
|
801 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
802 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
803 | + )) |
|
804 | + ->execute(); |
|
805 | + |
|
806 | + $data = $cursor->fetch(); |
|
807 | + |
|
808 | + if ($data === false) { |
|
809 | + throw new ShareNotFound(); |
|
810 | + } |
|
811 | + |
|
812 | + try { |
|
813 | + $share = $this->createShare($data); |
|
814 | + } catch (InvalidShare $e) { |
|
815 | + throw new ShareNotFound(); |
|
816 | + } |
|
817 | + |
|
818 | + return $share; |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Create a share object from an database row |
|
823 | + * |
|
824 | + * @param mixed[] $data |
|
825 | + * @return \OCP\Share\IShare |
|
826 | + * @throws InvalidShare |
|
827 | + */ |
|
828 | + private function createShare($data) { |
|
829 | + $share = new Share($this->rootFolder, $this->userManager); |
|
830 | + $share->setId((int)$data['id']) |
|
831 | + ->setShareType((int)$data['share_type']) |
|
832 | + ->setPermissions((int)$data['permissions']) |
|
833 | + ->setTarget($data['file_target']) |
|
834 | + ->setMailSend((bool)$data['mail_send']); |
|
835 | + |
|
836 | + $shareTime = new \DateTime(); |
|
837 | + $shareTime->setTimestamp((int)$data['stime']); |
|
838 | + $share->setShareTime($shareTime); |
|
839 | + |
|
840 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
841 | + $share->setSharedWith($data['share_with']); |
|
842 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
843 | + $share->setSharedWith($data['share_with']); |
|
844 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
845 | + $share->setPassword($data['password']); |
|
846 | + $share->setToken($data['token']); |
|
847 | + } |
|
848 | + |
|
849 | + $share->setSharedBy($data['uid_initiator']); |
|
850 | + $share->setShareOwner($data['uid_owner']); |
|
851 | + |
|
852 | + $share->setNodeId((int)$data['file_source']); |
|
853 | + $share->setNodeType($data['item_type']); |
|
854 | + |
|
855 | + if ($data['expiration'] !== null) { |
|
856 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
857 | + $share->setExpirationDate($expiration); |
|
858 | + } |
|
859 | + |
|
860 | + if (isset($data['f_permissions'])) { |
|
861 | + $entryData = $data; |
|
862 | + $entryData['permissions'] = $entryData['f_permissions']; |
|
863 | + $entryData['parent'] = $entryData['f_parent'];; |
|
864 | + $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
865 | + \OC::$server->getMimeTypeLoader())); |
|
866 | + } |
|
867 | + |
|
868 | + $share->setProviderId($this->identifier()); |
|
869 | + |
|
870 | + return $share; |
|
871 | + } |
|
872 | + |
|
873 | + /** |
|
874 | + * @param Share[] $shares |
|
875 | + * @param $userId |
|
876 | + * @return Share[] The updates shares if no update is found for a share return the original |
|
877 | + */ |
|
878 | + private function resolveGroupShares($shares, $userId) { |
|
879 | + $result = []; |
|
880 | + |
|
881 | + $start = 0; |
|
882 | + while(true) { |
|
883 | + /** @var Share[] $shareSlice */ |
|
884 | + $shareSlice = array_slice($shares, $start, 100); |
|
885 | + $start += 100; |
|
886 | + |
|
887 | + if ($shareSlice === []) { |
|
888 | + break; |
|
889 | + } |
|
890 | + |
|
891 | + /** @var int[] $ids */ |
|
892 | + $ids = []; |
|
893 | + /** @var Share[] $shareMap */ |
|
894 | + $shareMap = []; |
|
895 | + |
|
896 | + foreach ($shareSlice as $share) { |
|
897 | + $ids[] = (int)$share->getId(); |
|
898 | + $shareMap[$share->getId()] = $share; |
|
899 | + } |
|
900 | + |
|
901 | + $qb = $this->dbConn->getQueryBuilder(); |
|
902 | + |
|
903 | + $query = $qb->select('*') |
|
904 | + ->from('share') |
|
905 | + ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
906 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
907 | + ->andWhere($qb->expr()->orX( |
|
908 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
909 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
910 | + )); |
|
911 | + |
|
912 | + $stmt = $query->execute(); |
|
913 | + |
|
914 | + while($data = $stmt->fetch()) { |
|
915 | + $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
916 | + $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
917 | + } |
|
918 | + |
|
919 | + $stmt->closeCursor(); |
|
920 | + |
|
921 | + foreach ($shareMap as $share) { |
|
922 | + $result[] = $share; |
|
923 | + } |
|
924 | + } |
|
925 | + |
|
926 | + return $result; |
|
927 | + } |
|
928 | + |
|
929 | + /** |
|
930 | + * A user is deleted from the system |
|
931 | + * So clean up the relevant shares. |
|
932 | + * |
|
933 | + * @param string $uid |
|
934 | + * @param int $shareType |
|
935 | + */ |
|
936 | + public function userDeleted($uid, $shareType) { |
|
937 | + $qb = $this->dbConn->getQueryBuilder(); |
|
938 | + |
|
939 | + $qb->delete('share'); |
|
940 | + |
|
941 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
942 | + /* |
|
943 | 943 | * Delete all user shares that are owned by this user |
944 | 944 | * or that are received by this user |
945 | 945 | */ |
946 | 946 | |
947 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
947 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
948 | 948 | |
949 | - $qb->andWhere( |
|
950 | - $qb->expr()->orX( |
|
951 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
952 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
953 | - ) |
|
954 | - ); |
|
955 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
956 | - /* |
|
949 | + $qb->andWhere( |
|
950 | + $qb->expr()->orX( |
|
951 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
952 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
953 | + ) |
|
954 | + ); |
|
955 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
956 | + /* |
|
957 | 957 | * Delete all group shares that are owned by this user |
958 | 958 | * Or special user group shares that are received by this user |
959 | 959 | */ |
960 | - $qb->where( |
|
961 | - $qb->expr()->andX( |
|
962 | - $qb->expr()->orX( |
|
963 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
964 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
965 | - ), |
|
966 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
967 | - ) |
|
968 | - ); |
|
969 | - |
|
970 | - $qb->orWhere( |
|
971 | - $qb->expr()->andX( |
|
972 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
973 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
974 | - ) |
|
975 | - ); |
|
976 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
977 | - /* |
|
960 | + $qb->where( |
|
961 | + $qb->expr()->andX( |
|
962 | + $qb->expr()->orX( |
|
963 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
964 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
965 | + ), |
|
966 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
967 | + ) |
|
968 | + ); |
|
969 | + |
|
970 | + $qb->orWhere( |
|
971 | + $qb->expr()->andX( |
|
972 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
973 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
974 | + ) |
|
975 | + ); |
|
976 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
977 | + /* |
|
978 | 978 | * Delete all link shares owned by this user. |
979 | 979 | * And all link shares initiated by this user (until #22327 is in) |
980 | 980 | */ |
981 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
982 | - |
|
983 | - $qb->andWhere( |
|
984 | - $qb->expr()->orX( |
|
985 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
986 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
987 | - ) |
|
988 | - ); |
|
989 | - } |
|
990 | - |
|
991 | - $qb->execute(); |
|
992 | - } |
|
993 | - |
|
994 | - /** |
|
995 | - * Delete all shares received by this group. As well as any custom group |
|
996 | - * shares for group members. |
|
997 | - * |
|
998 | - * @param string $gid |
|
999 | - */ |
|
1000 | - public function groupDeleted($gid) { |
|
1001 | - /* |
|
981 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
982 | + |
|
983 | + $qb->andWhere( |
|
984 | + $qb->expr()->orX( |
|
985 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
986 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
987 | + ) |
|
988 | + ); |
|
989 | + } |
|
990 | + |
|
991 | + $qb->execute(); |
|
992 | + } |
|
993 | + |
|
994 | + /** |
|
995 | + * Delete all shares received by this group. As well as any custom group |
|
996 | + * shares for group members. |
|
997 | + * |
|
998 | + * @param string $gid |
|
999 | + */ |
|
1000 | + public function groupDeleted($gid) { |
|
1001 | + /* |
|
1002 | 1002 | * First delete all custom group shares for group members |
1003 | 1003 | */ |
1004 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1005 | - $qb->select('id') |
|
1006 | - ->from('share') |
|
1007 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1008 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1009 | - |
|
1010 | - $cursor = $qb->execute(); |
|
1011 | - $ids = []; |
|
1012 | - while($row = $cursor->fetch()) { |
|
1013 | - $ids[] = (int)$row['id']; |
|
1014 | - } |
|
1015 | - $cursor->closeCursor(); |
|
1016 | - |
|
1017 | - if (!empty($ids)) { |
|
1018 | - $chunks = array_chunk($ids, 100); |
|
1019 | - foreach ($chunks as $chunk) { |
|
1020 | - $qb->delete('share') |
|
1021 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1022 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1023 | - $qb->execute(); |
|
1024 | - } |
|
1025 | - } |
|
1026 | - |
|
1027 | - /* |
|
1004 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1005 | + $qb->select('id') |
|
1006 | + ->from('share') |
|
1007 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1008 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1009 | + |
|
1010 | + $cursor = $qb->execute(); |
|
1011 | + $ids = []; |
|
1012 | + while($row = $cursor->fetch()) { |
|
1013 | + $ids[] = (int)$row['id']; |
|
1014 | + } |
|
1015 | + $cursor->closeCursor(); |
|
1016 | + |
|
1017 | + if (!empty($ids)) { |
|
1018 | + $chunks = array_chunk($ids, 100); |
|
1019 | + foreach ($chunks as $chunk) { |
|
1020 | + $qb->delete('share') |
|
1021 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1022 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1023 | + $qb->execute(); |
|
1024 | + } |
|
1025 | + } |
|
1026 | + |
|
1027 | + /* |
|
1028 | 1028 | * Now delete all the group shares |
1029 | 1029 | */ |
1030 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1031 | - $qb->delete('share') |
|
1032 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1033 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1034 | - $qb->execute(); |
|
1035 | - } |
|
1036 | - |
|
1037 | - /** |
|
1038 | - * Delete custom group shares to this group for this user |
|
1039 | - * |
|
1040 | - * @param string $uid |
|
1041 | - * @param string $gid |
|
1042 | - */ |
|
1043 | - public function userDeletedFromGroup($uid, $gid) { |
|
1044 | - /* |
|
1030 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1031 | + $qb->delete('share') |
|
1032 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1033 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1034 | + $qb->execute(); |
|
1035 | + } |
|
1036 | + |
|
1037 | + /** |
|
1038 | + * Delete custom group shares to this group for this user |
|
1039 | + * |
|
1040 | + * @param string $uid |
|
1041 | + * @param string $gid |
|
1042 | + */ |
|
1043 | + public function userDeletedFromGroup($uid, $gid) { |
|
1044 | + /* |
|
1045 | 1045 | * Get all group shares |
1046 | 1046 | */ |
1047 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1048 | - $qb->select('id') |
|
1049 | - ->from('share') |
|
1050 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1051 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1052 | - |
|
1053 | - $cursor = $qb->execute(); |
|
1054 | - $ids = []; |
|
1055 | - while($row = $cursor->fetch()) { |
|
1056 | - $ids[] = (int)$row['id']; |
|
1057 | - } |
|
1058 | - $cursor->closeCursor(); |
|
1059 | - |
|
1060 | - if (!empty($ids)) { |
|
1061 | - $chunks = array_chunk($ids, 100); |
|
1062 | - foreach ($chunks as $chunk) { |
|
1063 | - /* |
|
1047 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1048 | + $qb->select('id') |
|
1049 | + ->from('share') |
|
1050 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1051 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1052 | + |
|
1053 | + $cursor = $qb->execute(); |
|
1054 | + $ids = []; |
|
1055 | + while($row = $cursor->fetch()) { |
|
1056 | + $ids[] = (int)$row['id']; |
|
1057 | + } |
|
1058 | + $cursor->closeCursor(); |
|
1059 | + |
|
1060 | + if (!empty($ids)) { |
|
1061 | + $chunks = array_chunk($ids, 100); |
|
1062 | + foreach ($chunks as $chunk) { |
|
1063 | + /* |
|
1064 | 1064 | * Delete all special shares wit this users for the found group shares |
1065 | 1065 | */ |
1066 | - $qb->delete('share') |
|
1067 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1068 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1069 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1070 | - $qb->execute(); |
|
1071 | - } |
|
1072 | - } |
|
1073 | - } |
|
1074 | - |
|
1075 | - /** |
|
1076 | - * @inheritdoc |
|
1077 | - */ |
|
1078 | - public function getAccessList($nodes, $currentAccess) { |
|
1079 | - $ids = []; |
|
1080 | - foreach ($nodes as $node) { |
|
1081 | - $ids[] = $node->getId(); |
|
1082 | - } |
|
1083 | - |
|
1084 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1085 | - |
|
1086 | - $or = $qb->expr()->orX( |
|
1087 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1088 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1089 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1090 | - ); |
|
1091 | - |
|
1092 | - if ($currentAccess) { |
|
1093 | - $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1094 | - } |
|
1095 | - |
|
1096 | - $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1097 | - ->from('share') |
|
1098 | - ->where( |
|
1099 | - $or |
|
1100 | - ) |
|
1101 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1102 | - ->andWhere($qb->expr()->orX( |
|
1103 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1104 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1105 | - )); |
|
1106 | - $cursor = $qb->execute(); |
|
1107 | - |
|
1108 | - $users = []; |
|
1109 | - $link = false; |
|
1110 | - while($row = $cursor->fetch()) { |
|
1111 | - $type = (int)$row['share_type']; |
|
1112 | - if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1113 | - $uid = $row['share_with']; |
|
1114 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1115 | - $users[$uid][$row['id']] = $row; |
|
1116 | - } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1117 | - $gid = $row['share_with']; |
|
1118 | - $group = $this->groupManager->get($gid); |
|
1119 | - |
|
1120 | - if ($group === null) { |
|
1121 | - continue; |
|
1122 | - } |
|
1123 | - |
|
1124 | - $userList = $group->getUsers(); |
|
1125 | - foreach ($userList as $user) { |
|
1126 | - $uid = $user->getUID(); |
|
1127 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1128 | - $users[$uid][$row['id']] = $row; |
|
1129 | - } |
|
1130 | - } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1131 | - $link = true; |
|
1132 | - } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1133 | - $uid = $row['share_with']; |
|
1134 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1135 | - $users[$uid][$row['id']] = $row; |
|
1136 | - } |
|
1137 | - } |
|
1138 | - $cursor->closeCursor(); |
|
1139 | - |
|
1140 | - if ($currentAccess === true) { |
|
1141 | - $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1142 | - $users = array_filter($users); |
|
1143 | - } else { |
|
1144 | - $users = array_keys($users); |
|
1145 | - } |
|
1146 | - |
|
1147 | - return ['users' => $users, 'public' => $link]; |
|
1148 | - } |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * For each user the path with the fewest slashes is returned |
|
1152 | - * @param array $shares |
|
1153 | - * @return array |
|
1154 | - */ |
|
1155 | - protected function filterSharesOfUser(array $shares) { |
|
1156 | - // Group shares when the user has a share exception |
|
1157 | - foreach ($shares as $id => $share) { |
|
1158 | - $type = (int) $share['share_type']; |
|
1159 | - $permissions = (int) $share['permissions']; |
|
1160 | - |
|
1161 | - if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1162 | - unset($shares[$share['parent']]); |
|
1163 | - |
|
1164 | - if ($permissions === 0) { |
|
1165 | - unset($shares[$id]); |
|
1166 | - } |
|
1167 | - } |
|
1168 | - } |
|
1169 | - |
|
1170 | - $best = []; |
|
1171 | - $bestDepth = 0; |
|
1172 | - foreach ($shares as $id => $share) { |
|
1173 | - $depth = substr_count($share['file_target'], '/'); |
|
1174 | - if (empty($best) || $depth < $bestDepth) { |
|
1175 | - $bestDepth = $depth; |
|
1176 | - $best = [ |
|
1177 | - 'node_id' => $share['file_source'], |
|
1178 | - 'node_path' => $share['file_target'], |
|
1179 | - ]; |
|
1180 | - } |
|
1181 | - } |
|
1182 | - |
|
1183 | - return $best; |
|
1184 | - } |
|
1066 | + $qb->delete('share') |
|
1067 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1068 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1069 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1070 | + $qb->execute(); |
|
1071 | + } |
|
1072 | + } |
|
1073 | + } |
|
1074 | + |
|
1075 | + /** |
|
1076 | + * @inheritdoc |
|
1077 | + */ |
|
1078 | + public function getAccessList($nodes, $currentAccess) { |
|
1079 | + $ids = []; |
|
1080 | + foreach ($nodes as $node) { |
|
1081 | + $ids[] = $node->getId(); |
|
1082 | + } |
|
1083 | + |
|
1084 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1085 | + |
|
1086 | + $or = $qb->expr()->orX( |
|
1087 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1088 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1089 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1090 | + ); |
|
1091 | + |
|
1092 | + if ($currentAccess) { |
|
1093 | + $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1094 | + } |
|
1095 | + |
|
1096 | + $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1097 | + ->from('share') |
|
1098 | + ->where( |
|
1099 | + $or |
|
1100 | + ) |
|
1101 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1102 | + ->andWhere($qb->expr()->orX( |
|
1103 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1104 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1105 | + )); |
|
1106 | + $cursor = $qb->execute(); |
|
1107 | + |
|
1108 | + $users = []; |
|
1109 | + $link = false; |
|
1110 | + while($row = $cursor->fetch()) { |
|
1111 | + $type = (int)$row['share_type']; |
|
1112 | + if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1113 | + $uid = $row['share_with']; |
|
1114 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1115 | + $users[$uid][$row['id']] = $row; |
|
1116 | + } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1117 | + $gid = $row['share_with']; |
|
1118 | + $group = $this->groupManager->get($gid); |
|
1119 | + |
|
1120 | + if ($group === null) { |
|
1121 | + continue; |
|
1122 | + } |
|
1123 | + |
|
1124 | + $userList = $group->getUsers(); |
|
1125 | + foreach ($userList as $user) { |
|
1126 | + $uid = $user->getUID(); |
|
1127 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1128 | + $users[$uid][$row['id']] = $row; |
|
1129 | + } |
|
1130 | + } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1131 | + $link = true; |
|
1132 | + } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1133 | + $uid = $row['share_with']; |
|
1134 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1135 | + $users[$uid][$row['id']] = $row; |
|
1136 | + } |
|
1137 | + } |
|
1138 | + $cursor->closeCursor(); |
|
1139 | + |
|
1140 | + if ($currentAccess === true) { |
|
1141 | + $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1142 | + $users = array_filter($users); |
|
1143 | + } else { |
|
1144 | + $users = array_keys($users); |
|
1145 | + } |
|
1146 | + |
|
1147 | + return ['users' => $users, 'public' => $link]; |
|
1148 | + } |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * For each user the path with the fewest slashes is returned |
|
1152 | + * @param array $shares |
|
1153 | + * @return array |
|
1154 | + */ |
|
1155 | + protected function filterSharesOfUser(array $shares) { |
|
1156 | + // Group shares when the user has a share exception |
|
1157 | + foreach ($shares as $id => $share) { |
|
1158 | + $type = (int) $share['share_type']; |
|
1159 | + $permissions = (int) $share['permissions']; |
|
1160 | + |
|
1161 | + if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1162 | + unset($shares[$share['parent']]); |
|
1163 | + |
|
1164 | + if ($permissions === 0) { |
|
1165 | + unset($shares[$id]); |
|
1166 | + } |
|
1167 | + } |
|
1168 | + } |
|
1169 | + |
|
1170 | + $best = []; |
|
1171 | + $bestDepth = 0; |
|
1172 | + foreach ($shares as $id => $share) { |
|
1173 | + $depth = substr_count($share['file_target'], '/'); |
|
1174 | + if (empty($best) || $depth < $bestDepth) { |
|
1175 | + $bestDepth = $depth; |
|
1176 | + $best = [ |
|
1177 | + 'node_id' => $share['file_source'], |
|
1178 | + 'node_path' => $share['file_target'], |
|
1179 | + ]; |
|
1180 | + } |
|
1181 | + } |
|
1182 | + |
|
1183 | + return $best; |
|
1184 | + } |
|
1185 | 1185 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * The deserialize method is called during xml parsing. |
62 | 62 | * |
63 | 63 | * @param Reader $reader |
64 | - * @return mixed |
|
64 | + * @return null|ShareTypeList |
|
65 | 65 | */ |
66 | 66 | static function xmlDeserialize(Reader $reader) { |
67 | 67 | $shareTypes = []; |
@@ -32,61 +32,61 @@ |
||
32 | 32 | * This property contains multiple "share-type" elements, each containing a share type. |
33 | 33 | */ |
34 | 34 | class ShareTypeList implements Element { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Share types |
|
39 | - * |
|
40 | - * @var int[] |
|
41 | - */ |
|
42 | - private $shareTypes; |
|
37 | + /** |
|
38 | + * Share types |
|
39 | + * |
|
40 | + * @var int[] |
|
41 | + */ |
|
42 | + private $shareTypes; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int[] $shareTypes |
|
46 | - */ |
|
47 | - public function __construct($shareTypes) { |
|
48 | - $this->shareTypes = $shareTypes; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param int[] $shareTypes |
|
46 | + */ |
|
47 | + public function __construct($shareTypes) { |
|
48 | + $this->shareTypes = $shareTypes; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the share types |
|
53 | - * |
|
54 | - * @return int[] |
|
55 | - */ |
|
56 | - public function getShareTypes() { |
|
57 | - return $this->shareTypes; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Returns the share types |
|
53 | + * |
|
54 | + * @return int[] |
|
55 | + */ |
|
56 | + public function getShareTypes() { |
|
57 | + return $this->shareTypes; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The deserialize method is called during xml parsing. |
|
62 | - * |
|
63 | - * @param Reader $reader |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - static function xmlDeserialize(Reader $reader) { |
|
67 | - $shareTypes = []; |
|
60 | + /** |
|
61 | + * The deserialize method is called during xml parsing. |
|
62 | + * |
|
63 | + * @param Reader $reader |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + static function xmlDeserialize(Reader $reader) { |
|
67 | + $shareTypes = []; |
|
68 | 68 | |
69 | - $tree = $reader->parseInnerTree(); |
|
70 | - if ($tree === null) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - foreach ($tree as $elem) { |
|
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
76 | - } |
|
77 | - } |
|
78 | - return new self($shareTypes); |
|
79 | - } |
|
69 | + $tree = $reader->parseInnerTree(); |
|
70 | + if ($tree === null) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + foreach ($tree as $elem) { |
|
74 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | + $shareTypes[] = (int)$elem['value']; |
|
76 | + } |
|
77 | + } |
|
78 | + return new self($shareTypes); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * The xmlSerialize metod is called during xml writing. |
|
83 | - * |
|
84 | - * @param Writer $writer |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - function xmlSerialize(Writer $writer) { |
|
88 | - foreach ($this->shareTypes as $shareType) { |
|
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | - } |
|
91 | - } |
|
81 | + /** |
|
82 | + * The xmlSerialize metod is called during xml writing. |
|
83 | + * |
|
84 | + * @param Writer $writer |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + function xmlSerialize(Writer $writer) { |
|
88 | + foreach ($this->shareTypes as $shareType) { |
|
89 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | return null; |
72 | 72 | } |
73 | 73 | foreach ($tree as $elem) { |
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
74 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
75 | + $shareTypes[] = (int) $elem['value']; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | return new self($shareTypes); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | function xmlSerialize(Writer $writer) { |
88 | 88 | foreach ($this->shareTypes as $shareType) { |
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
89 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -80,7 +80,7 @@ |
||
80 | 80 | * the next element. |
81 | 81 | * |
82 | 82 | * @param Reader $reader |
83 | - * @return mixed |
|
83 | + * @return null|TagList |
|
84 | 84 | */ |
85 | 85 | static function xmlDeserialize(Reader $reader) { |
86 | 86 | $tags = []; |
@@ -34,92 +34,92 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - $tree = $reader->parseInnerTree(); |
|
89 | - if ($tree === null) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - foreach ($tree as $elem) { |
|
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | - $tags[] = $elem['value']; |
|
95 | - } |
|
96 | - } |
|
97 | - return new self($tags); |
|
98 | - } |
|
88 | + $tree = $reader->parseInnerTree(); |
|
89 | + if ($tree === null) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + foreach ($tree as $elem) { |
|
93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | + $tags[] = $elem['value']; |
|
95 | + } |
|
96 | + } |
|
97 | + return new self($tags); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * The xmlSerialize metod is called during xml writing. |
|
102 | - * |
|
103 | - * Use the $writer argument to write its own xml serialization. |
|
104 | - * |
|
105 | - * An important note: do _not_ create a parent element. Any element |
|
106 | - * implementing XmlSerializble should only ever write what's considered |
|
107 | - * its 'inner xml'. |
|
108 | - * |
|
109 | - * The parent of the current element is responsible for writing a |
|
110 | - * containing element. |
|
111 | - * |
|
112 | - * This allows serializers to be re-used for different element names. |
|
113 | - * |
|
114 | - * If you are opening new elements, you must also close them again. |
|
115 | - * |
|
116 | - * @param Writer $writer |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - function xmlSerialize(Writer $writer) { |
|
100 | + /** |
|
101 | + * The xmlSerialize metod is called during xml writing. |
|
102 | + * |
|
103 | + * Use the $writer argument to write its own xml serialization. |
|
104 | + * |
|
105 | + * An important note: do _not_ create a parent element. Any element |
|
106 | + * implementing XmlSerializble should only ever write what's considered |
|
107 | + * its 'inner xml'. |
|
108 | + * |
|
109 | + * The parent of the current element is responsible for writing a |
|
110 | + * containing element. |
|
111 | + * |
|
112 | + * This allows serializers to be re-used for different element names. |
|
113 | + * |
|
114 | + * If you are opening new elements, you must also close them again. |
|
115 | + * |
|
116 | + * @param Writer $writer |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + function xmlSerialize(Writer $writer) { |
|
120 | 120 | |
121 | - foreach ($this->tags as $tag) { |
|
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | - } |
|
124 | - } |
|
121 | + foreach ($this->tags as $tag) { |
|
122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | foreach ($tree as $elem) { |
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
93 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
94 | 94 | $tags[] = $elem['value']; |
95 | 95 | } |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function xmlSerialize(Writer $writer) { |
120 | 120 | |
121 | 121 | foreach ($this->tags as $tag) { |
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
122 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -318,6 +318,11 @@ |
||
318 | 318 | */ |
319 | 319 | // FIXME This method is only public, until OC_L10N does not need it anymore, |
320 | 320 | // FIXME This is also the reason, why it is not in the public interface |
321 | + |
|
322 | + /** |
|
323 | + * @param string $app |
|
324 | + * @param string $lang |
|
325 | + */ |
|
321 | 326 | public function getL10nFilesForApp($app, $lang) { |
322 | 327 | $languageFiles = []; |
323 | 328 |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @link https://github.com/owncloud/core/issues/21955 |
133 | 133 | */ |
134 | - if($this->config->getSystemValue('installed', false)) { |
|
135 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | - if(!is_null($userId)) { |
|
134 | + if ($this->config->getSystemValue('installed', false)) { |
|
135 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | + if (!is_null($userId)) { |
|
137 | 137 | $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
138 | 138 | } else { |
139 | 139 | $userLang = null; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | // merge with translations from theme |
203 | 203 | $theme = $this->config->getSystemValue('theme'); |
204 | 204 | if (!empty($theme)) { |
205 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
205 | + $themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot)); |
|
206 | 206 | |
207 | 207 | if (is_dir($themeDir)) { |
208 | 208 | $files = scandir($themeDir); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | private function isSubDirectory($sub, $parent) { |
299 | 299 | // Check whether $sub contains no ".." |
300 | - if(strpos($sub, '..') !== false) { |
|
300 | + if (strpos($sub, '..') !== false) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | 303 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | $languageFiles = []; |
323 | 323 | |
324 | 324 | $i18nDir = $this->findL10nDir($app); |
325 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
325 | + $transFile = strip_tags($i18nDir).strip_tags($lang).'.json'; |
|
326 | 326 | |
327 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
328 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
329 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
330 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
327 | + if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/') |
|
328 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/') |
|
329 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/') |
|
330 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/') |
|
331 | 331 | ) |
332 | 332 | && file_exists($transFile)) { |
333 | 333 | // load the translations file |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | // merge with translations from theme |
338 | 338 | $theme = $this->config->getSystemValue('theme'); |
339 | 339 | if (!empty($theme)) { |
340 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
340 | + $transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot)); |
|
341 | 341 | if (file_exists($transFile)) { |
342 | 342 | $languageFiles[] = $transFile; |
343 | 343 | } |
@@ -354,14 +354,14 @@ discard block |
||
354 | 354 | */ |
355 | 355 | protected function findL10nDir($app = null) { |
356 | 356 | if (in_array($app, ['core', 'lib', 'settings'])) { |
357 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
358 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
357 | + if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) { |
|
358 | + return $this->serverRoot.'/'.$app.'/l10n/'; |
|
359 | 359 | } |
360 | 360 | } else if ($app && \OC_App::getAppPath($app) !== false) { |
361 | 361 | // Check if the app is in the app folder |
362 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
362 | + return \OC_App::getAppPath($app).'/l10n/'; |
|
363 | 363 | } |
364 | - return $this->serverRoot . '/core/l10n/'; |
|
364 | + return $this->serverRoot.'/core/l10n/'; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -378,15 +378,15 @@ discard block |
||
378 | 378 | return $this->pluralFunctions[$string]; |
379 | 379 | } |
380 | 380 | |
381 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
381 | + if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
382 | 382 | // sanitize |
383 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
384 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
383 | + $nplurals = preg_replace('/[^0-9]/', '', $matches[1]); |
|
384 | + $plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]); |
|
385 | 385 | |
386 | 386 | $body = str_replace( |
387 | - array( 'plural', 'n', '$n$plurals', ), |
|
388 | - array( '$plural', '$n', '$nplurals', ), |
|
389 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
387 | + array('plural', 'n', '$n$plurals',), |
|
388 | + array('$plural', '$n', '$nplurals',), |
|
389 | + 'nplurals='.$nplurals.'; plural='.$plural |
|
390 | 390 | ); |
391 | 391 | |
392 | 392 | // add parents |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | $body .= ';'; |
395 | 395 | $res = ''; |
396 | 396 | $p = 0; |
397 | - for($i = 0; $i < strlen($body); $i++) { |
|
397 | + for ($i = 0; $i < strlen($body); $i++) { |
|
398 | 398 | $ch = $body[$i]; |
399 | - switch ( $ch ) { |
|
399 | + switch ($ch) { |
|
400 | 400 | case '?': |
401 | 401 | $res .= ' ? ('; |
402 | 402 | $p++; |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $res .= ') : ('; |
406 | 406 | break; |
407 | 407 | case ';': |
408 | - $res .= str_repeat( ')', $p ) . ';'; |
|
408 | + $res .= str_repeat(')', $p).';'; |
|
409 | 409 | $p = 0; |
410 | 410 | break; |
411 | 411 | default: |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
416 | + $body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
417 | 417 | $function = create_function('$n', $body); |
418 | 418 | $this->pluralFunctions[$string] = $function; |
419 | 419 | return $function; |
@@ -40,379 +40,379 @@ |
||
40 | 40 | */ |
41 | 41 | class Factory implements IFactory { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - protected $requestLanguage = ''; |
|
45 | - |
|
46 | - /** |
|
47 | - * cached instances |
|
48 | - * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | - */ |
|
50 | - protected $instances = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array Structure: App => string[] |
|
54 | - */ |
|
55 | - protected $availableLanguages = []; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var array Structure: string => callable |
|
59 | - */ |
|
60 | - protected $pluralFunctions = []; |
|
61 | - |
|
62 | - /** @var IConfig */ |
|
63 | - protected $config; |
|
64 | - |
|
65 | - /** @var IRequest */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** @var IUserSession */ |
|
69 | - protected $userSession; |
|
70 | - |
|
71 | - /** @var string */ |
|
72 | - protected $serverRoot; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param IConfig $config |
|
76 | - * @param IRequest $request |
|
77 | - * @param IUserSession $userSession |
|
78 | - * @param string $serverRoot |
|
79 | - */ |
|
80 | - public function __construct(IConfig $config, |
|
81 | - IRequest $request, |
|
82 | - IUserSession $userSession, |
|
83 | - $serverRoot) { |
|
84 | - $this->config = $config; |
|
85 | - $this->request = $request; |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->serverRoot = $serverRoot; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get a language instance |
|
92 | - * |
|
93 | - * @param string $app |
|
94 | - * @param string|null $lang |
|
95 | - * @return \OCP\IL10N |
|
96 | - */ |
|
97 | - public function get($app, $lang = null) { |
|
98 | - $app = \OC_App::cleanAppId($app); |
|
99 | - if ($lang !== null) { |
|
100 | - $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | - } |
|
102 | - |
|
103 | - $forceLang = $this->config->getSystemValue('force_language', false); |
|
104 | - if (is_string($forceLang)) { |
|
105 | - $lang = $forceLang; |
|
106 | - } |
|
107 | - |
|
108 | - if ($lang === null || !$this->languageExists($app, $lang)) { |
|
109 | - $lang = $this->findLanguage($app); |
|
110 | - } |
|
111 | - |
|
112 | - if (!isset($this->instances[$lang][$app])) { |
|
113 | - $this->instances[$lang][$app] = new L10N( |
|
114 | - $this, $app, $lang, |
|
115 | - $this->getL10nFilesForApp($app, $lang) |
|
116 | - ); |
|
117 | - } |
|
118 | - |
|
119 | - return $this->instances[$lang][$app]; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Find the best language |
|
124 | - * |
|
125 | - * @param string|null $app App id or null for core |
|
126 | - * @return string language If nothing works it returns 'en' |
|
127 | - */ |
|
128 | - public function findLanguage($app = null) { |
|
129 | - if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
130 | - return $this->requestLanguage; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * At this point Nextcloud might not yet be installed and thus the lookup |
|
135 | - * in the preferences table might fail. For this reason we need to check |
|
136 | - * whether the instance has already been installed |
|
137 | - * |
|
138 | - * @link https://github.com/owncloud/core/issues/21955 |
|
139 | - */ |
|
140 | - if($this->config->getSystemValue('installed', false)) { |
|
141 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
142 | - if(!is_null($userId)) { |
|
143 | - $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
144 | - } else { |
|
145 | - $userLang = null; |
|
146 | - } |
|
147 | - } else { |
|
148 | - $userId = null; |
|
149 | - $userLang = null; |
|
150 | - } |
|
151 | - |
|
152 | - if ($userLang) { |
|
153 | - $this->requestLanguage = $userLang; |
|
154 | - if ($this->languageExists($app, $userLang)) { |
|
155 | - return $userLang; |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - try { |
|
160 | - // Try to get the language from the Request |
|
161 | - $lang = $this->getLanguageFromRequest($app); |
|
162 | - if ($userId !== null && $app === null && !$userLang) { |
|
163 | - $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
164 | - } |
|
165 | - return $lang; |
|
166 | - } catch (LanguageNotFoundException $e) { |
|
167 | - // Finding language from request failed fall back to default language |
|
168 | - $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
169 | - if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
170 | - return $defaultLanguage; |
|
171 | - } |
|
172 | - } |
|
173 | - |
|
174 | - // We could not find any language so fall back to english |
|
175 | - return 'en'; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Find all available languages for an app |
|
180 | - * |
|
181 | - * @param string|null $app App id or null for core |
|
182 | - * @return array an array of available languages |
|
183 | - */ |
|
184 | - public function findAvailableLanguages($app = null) { |
|
185 | - $key = $app; |
|
186 | - if ($key === null) { |
|
187 | - $key = 'null'; |
|
188 | - } |
|
189 | - |
|
190 | - // also works with null as key |
|
191 | - if (!empty($this->availableLanguages[$key])) { |
|
192 | - return $this->availableLanguages[$key]; |
|
193 | - } |
|
194 | - |
|
195 | - $available = ['en']; //english is always available |
|
196 | - $dir = $this->findL10nDir($app); |
|
197 | - if (is_dir($dir)) { |
|
198 | - $files = scandir($dir); |
|
199 | - if ($files !== false) { |
|
200 | - foreach ($files as $file) { |
|
201 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
202 | - $available[] = substr($file, 0, -5); |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - // merge with translations from theme |
|
209 | - $theme = $this->config->getSystemValue('theme'); |
|
210 | - if (!empty($theme)) { |
|
211 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
212 | - |
|
213 | - if (is_dir($themeDir)) { |
|
214 | - $files = scandir($themeDir); |
|
215 | - if ($files !== false) { |
|
216 | - foreach ($files as $file) { |
|
217 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
218 | - $available[] = substr($file, 0, -5); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - $this->availableLanguages[$key] = $available; |
|
226 | - return $available; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string|null $app App id or null for core |
|
231 | - * @param string $lang |
|
232 | - * @return bool |
|
233 | - */ |
|
234 | - public function languageExists($app, $lang) { |
|
235 | - if ($lang === 'en') {//english is always available |
|
236 | - return true; |
|
237 | - } |
|
238 | - |
|
239 | - $languages = $this->findAvailableLanguages($app); |
|
240 | - return array_search($lang, $languages) !== false; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string|null $app |
|
245 | - * @return string |
|
246 | - * @throws LanguageNotFoundException |
|
247 | - */ |
|
248 | - private function getLanguageFromRequest($app) { |
|
249 | - $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
250 | - if ($header) { |
|
251 | - $available = $this->findAvailableLanguages($app); |
|
252 | - |
|
253 | - // E.g. make sure that 'de' is before 'de_DE'. |
|
254 | - sort($available); |
|
255 | - |
|
256 | - $preferences = preg_split('/,\s*/', strtolower($header)); |
|
257 | - foreach ($preferences as $preference) { |
|
258 | - list($preferred_language) = explode(';', $preference); |
|
259 | - $preferred_language = str_replace('-', '_', $preferred_language); |
|
260 | - |
|
261 | - foreach ($available as $available_language) { |
|
262 | - if ($preferred_language === strtolower($available_language)) { |
|
263 | - return $available_language; |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - // Fallback from de_De to de |
|
268 | - foreach ($available as $available_language) { |
|
269 | - if (substr($preferred_language, 0, 2) === $available_language) { |
|
270 | - return $available_language; |
|
271 | - } |
|
272 | - } |
|
273 | - } |
|
274 | - } |
|
275 | - |
|
276 | - throw new LanguageNotFoundException(); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Checks if $sub is a subdirectory of $parent |
|
281 | - * |
|
282 | - * @param string $sub |
|
283 | - * @param string $parent |
|
284 | - * @return bool |
|
285 | - */ |
|
286 | - private function isSubDirectory($sub, $parent) { |
|
287 | - // Check whether $sub contains no ".." |
|
288 | - if(strpos($sub, '..') !== false) { |
|
289 | - return false; |
|
290 | - } |
|
291 | - |
|
292 | - // Check whether $sub is a subdirectory of $parent |
|
293 | - if (strpos($sub, $parent) === 0) { |
|
294 | - return true; |
|
295 | - } |
|
296 | - |
|
297 | - return false; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Get a list of language files that should be loaded |
|
302 | - * |
|
303 | - * @param string $app |
|
304 | - * @param string $lang |
|
305 | - * @return string[] |
|
306 | - */ |
|
307 | - // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
308 | - // FIXME This is also the reason, why it is not in the public interface |
|
309 | - public function getL10nFilesForApp($app, $lang) { |
|
310 | - $languageFiles = []; |
|
311 | - |
|
312 | - $i18nDir = $this->findL10nDir($app); |
|
313 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
314 | - |
|
315 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
316 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
317 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
318 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
319 | - ) |
|
320 | - && file_exists($transFile)) { |
|
321 | - // load the translations file |
|
322 | - $languageFiles[] = $transFile; |
|
323 | - } |
|
324 | - |
|
325 | - // merge with translations from theme |
|
326 | - $theme = $this->config->getSystemValue('theme'); |
|
327 | - if (!empty($theme)) { |
|
328 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
329 | - if (file_exists($transFile)) { |
|
330 | - $languageFiles[] = $transFile; |
|
331 | - } |
|
332 | - } |
|
333 | - |
|
334 | - return $languageFiles; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * find the l10n directory |
|
339 | - * |
|
340 | - * @param string $app App id or empty string for core |
|
341 | - * @return string directory |
|
342 | - */ |
|
343 | - protected function findL10nDir($app = null) { |
|
344 | - if (in_array($app, ['core', 'lib', 'settings'])) { |
|
345 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
346 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
347 | - } |
|
348 | - } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
349 | - // Check if the app is in the app folder |
|
350 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
351 | - } |
|
352 | - return $this->serverRoot . '/core/l10n/'; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Creates a function from the plural string |
|
358 | - * |
|
359 | - * Parts of the code is copied from Habari: |
|
360 | - * https://github.com/habari/system/blob/master/classes/locale.php |
|
361 | - * @param string $string |
|
362 | - * @return string |
|
363 | - */ |
|
364 | - public function createPluralFunction($string) { |
|
365 | - if (isset($this->pluralFunctions[$string])) { |
|
366 | - return $this->pluralFunctions[$string]; |
|
367 | - } |
|
368 | - |
|
369 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
370 | - // sanitize |
|
371 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
372 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
373 | - |
|
374 | - $body = str_replace( |
|
375 | - array( 'plural', 'n', '$n$plurals', ), |
|
376 | - array( '$plural', '$n', '$nplurals', ), |
|
377 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
378 | - ); |
|
379 | - |
|
380 | - // add parents |
|
381 | - // important since PHP's ternary evaluates from left to right |
|
382 | - $body .= ';'; |
|
383 | - $res = ''; |
|
384 | - $p = 0; |
|
385 | - for($i = 0; $i < strlen($body); $i++) { |
|
386 | - $ch = $body[$i]; |
|
387 | - switch ( $ch ) { |
|
388 | - case '?': |
|
389 | - $res .= ' ? ('; |
|
390 | - $p++; |
|
391 | - break; |
|
392 | - case ':': |
|
393 | - $res .= ') : ('; |
|
394 | - break; |
|
395 | - case ';': |
|
396 | - $res .= str_repeat( ')', $p ) . ';'; |
|
397 | - $p = 0; |
|
398 | - break; |
|
399 | - default: |
|
400 | - $res .= $ch; |
|
401 | - } |
|
402 | - } |
|
403 | - |
|
404 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
405 | - $function = create_function('$n', $body); |
|
406 | - $this->pluralFunctions[$string] = $function; |
|
407 | - return $function; |
|
408 | - } else { |
|
409 | - // default: one plural form for all cases but n==1 (english) |
|
410 | - $function = create_function( |
|
411 | - '$n', |
|
412 | - '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
413 | - ); |
|
414 | - $this->pluralFunctions[$string] = $function; |
|
415 | - return $function; |
|
416 | - } |
|
417 | - } |
|
43 | + /** @var string */ |
|
44 | + protected $requestLanguage = ''; |
|
45 | + |
|
46 | + /** |
|
47 | + * cached instances |
|
48 | + * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | + */ |
|
50 | + protected $instances = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array Structure: App => string[] |
|
54 | + */ |
|
55 | + protected $availableLanguages = []; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var array Structure: string => callable |
|
59 | + */ |
|
60 | + protected $pluralFunctions = []; |
|
61 | + |
|
62 | + /** @var IConfig */ |
|
63 | + protected $config; |
|
64 | + |
|
65 | + /** @var IRequest */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** @var IUserSession */ |
|
69 | + protected $userSession; |
|
70 | + |
|
71 | + /** @var string */ |
|
72 | + protected $serverRoot; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param IConfig $config |
|
76 | + * @param IRequest $request |
|
77 | + * @param IUserSession $userSession |
|
78 | + * @param string $serverRoot |
|
79 | + */ |
|
80 | + public function __construct(IConfig $config, |
|
81 | + IRequest $request, |
|
82 | + IUserSession $userSession, |
|
83 | + $serverRoot) { |
|
84 | + $this->config = $config; |
|
85 | + $this->request = $request; |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->serverRoot = $serverRoot; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get a language instance |
|
92 | + * |
|
93 | + * @param string $app |
|
94 | + * @param string|null $lang |
|
95 | + * @return \OCP\IL10N |
|
96 | + */ |
|
97 | + public function get($app, $lang = null) { |
|
98 | + $app = \OC_App::cleanAppId($app); |
|
99 | + if ($lang !== null) { |
|
100 | + $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | + } |
|
102 | + |
|
103 | + $forceLang = $this->config->getSystemValue('force_language', false); |
|
104 | + if (is_string($forceLang)) { |
|
105 | + $lang = $forceLang; |
|
106 | + } |
|
107 | + |
|
108 | + if ($lang === null || !$this->languageExists($app, $lang)) { |
|
109 | + $lang = $this->findLanguage($app); |
|
110 | + } |
|
111 | + |
|
112 | + if (!isset($this->instances[$lang][$app])) { |
|
113 | + $this->instances[$lang][$app] = new L10N( |
|
114 | + $this, $app, $lang, |
|
115 | + $this->getL10nFilesForApp($app, $lang) |
|
116 | + ); |
|
117 | + } |
|
118 | + |
|
119 | + return $this->instances[$lang][$app]; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Find the best language |
|
124 | + * |
|
125 | + * @param string|null $app App id or null for core |
|
126 | + * @return string language If nothing works it returns 'en' |
|
127 | + */ |
|
128 | + public function findLanguage($app = null) { |
|
129 | + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
130 | + return $this->requestLanguage; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * At this point Nextcloud might not yet be installed and thus the lookup |
|
135 | + * in the preferences table might fail. For this reason we need to check |
|
136 | + * whether the instance has already been installed |
|
137 | + * |
|
138 | + * @link https://github.com/owncloud/core/issues/21955 |
|
139 | + */ |
|
140 | + if($this->config->getSystemValue('installed', false)) { |
|
141 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
142 | + if(!is_null($userId)) { |
|
143 | + $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
144 | + } else { |
|
145 | + $userLang = null; |
|
146 | + } |
|
147 | + } else { |
|
148 | + $userId = null; |
|
149 | + $userLang = null; |
|
150 | + } |
|
151 | + |
|
152 | + if ($userLang) { |
|
153 | + $this->requestLanguage = $userLang; |
|
154 | + if ($this->languageExists($app, $userLang)) { |
|
155 | + return $userLang; |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + try { |
|
160 | + // Try to get the language from the Request |
|
161 | + $lang = $this->getLanguageFromRequest($app); |
|
162 | + if ($userId !== null && $app === null && !$userLang) { |
|
163 | + $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
164 | + } |
|
165 | + return $lang; |
|
166 | + } catch (LanguageNotFoundException $e) { |
|
167 | + // Finding language from request failed fall back to default language |
|
168 | + $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
169 | + if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
170 | + return $defaultLanguage; |
|
171 | + } |
|
172 | + } |
|
173 | + |
|
174 | + // We could not find any language so fall back to english |
|
175 | + return 'en'; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Find all available languages for an app |
|
180 | + * |
|
181 | + * @param string|null $app App id or null for core |
|
182 | + * @return array an array of available languages |
|
183 | + */ |
|
184 | + public function findAvailableLanguages($app = null) { |
|
185 | + $key = $app; |
|
186 | + if ($key === null) { |
|
187 | + $key = 'null'; |
|
188 | + } |
|
189 | + |
|
190 | + // also works with null as key |
|
191 | + if (!empty($this->availableLanguages[$key])) { |
|
192 | + return $this->availableLanguages[$key]; |
|
193 | + } |
|
194 | + |
|
195 | + $available = ['en']; //english is always available |
|
196 | + $dir = $this->findL10nDir($app); |
|
197 | + if (is_dir($dir)) { |
|
198 | + $files = scandir($dir); |
|
199 | + if ($files !== false) { |
|
200 | + foreach ($files as $file) { |
|
201 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
202 | + $available[] = substr($file, 0, -5); |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + // merge with translations from theme |
|
209 | + $theme = $this->config->getSystemValue('theme'); |
|
210 | + if (!empty($theme)) { |
|
211 | + $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
212 | + |
|
213 | + if (is_dir($themeDir)) { |
|
214 | + $files = scandir($themeDir); |
|
215 | + if ($files !== false) { |
|
216 | + foreach ($files as $file) { |
|
217 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
218 | + $available[] = substr($file, 0, -5); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + $this->availableLanguages[$key] = $available; |
|
226 | + return $available; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string|null $app App id or null for core |
|
231 | + * @param string $lang |
|
232 | + * @return bool |
|
233 | + */ |
|
234 | + public function languageExists($app, $lang) { |
|
235 | + if ($lang === 'en') {//english is always available |
|
236 | + return true; |
|
237 | + } |
|
238 | + |
|
239 | + $languages = $this->findAvailableLanguages($app); |
|
240 | + return array_search($lang, $languages) !== false; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string|null $app |
|
245 | + * @return string |
|
246 | + * @throws LanguageNotFoundException |
|
247 | + */ |
|
248 | + private function getLanguageFromRequest($app) { |
|
249 | + $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
250 | + if ($header) { |
|
251 | + $available = $this->findAvailableLanguages($app); |
|
252 | + |
|
253 | + // E.g. make sure that 'de' is before 'de_DE'. |
|
254 | + sort($available); |
|
255 | + |
|
256 | + $preferences = preg_split('/,\s*/', strtolower($header)); |
|
257 | + foreach ($preferences as $preference) { |
|
258 | + list($preferred_language) = explode(';', $preference); |
|
259 | + $preferred_language = str_replace('-', '_', $preferred_language); |
|
260 | + |
|
261 | + foreach ($available as $available_language) { |
|
262 | + if ($preferred_language === strtolower($available_language)) { |
|
263 | + return $available_language; |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + // Fallback from de_De to de |
|
268 | + foreach ($available as $available_language) { |
|
269 | + if (substr($preferred_language, 0, 2) === $available_language) { |
|
270 | + return $available_language; |
|
271 | + } |
|
272 | + } |
|
273 | + } |
|
274 | + } |
|
275 | + |
|
276 | + throw new LanguageNotFoundException(); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Checks if $sub is a subdirectory of $parent |
|
281 | + * |
|
282 | + * @param string $sub |
|
283 | + * @param string $parent |
|
284 | + * @return bool |
|
285 | + */ |
|
286 | + private function isSubDirectory($sub, $parent) { |
|
287 | + // Check whether $sub contains no ".." |
|
288 | + if(strpos($sub, '..') !== false) { |
|
289 | + return false; |
|
290 | + } |
|
291 | + |
|
292 | + // Check whether $sub is a subdirectory of $parent |
|
293 | + if (strpos($sub, $parent) === 0) { |
|
294 | + return true; |
|
295 | + } |
|
296 | + |
|
297 | + return false; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Get a list of language files that should be loaded |
|
302 | + * |
|
303 | + * @param string $app |
|
304 | + * @param string $lang |
|
305 | + * @return string[] |
|
306 | + */ |
|
307 | + // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
308 | + // FIXME This is also the reason, why it is not in the public interface |
|
309 | + public function getL10nFilesForApp($app, $lang) { |
|
310 | + $languageFiles = []; |
|
311 | + |
|
312 | + $i18nDir = $this->findL10nDir($app); |
|
313 | + $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
314 | + |
|
315 | + if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
316 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
317 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
318 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
319 | + ) |
|
320 | + && file_exists($transFile)) { |
|
321 | + // load the translations file |
|
322 | + $languageFiles[] = $transFile; |
|
323 | + } |
|
324 | + |
|
325 | + // merge with translations from theme |
|
326 | + $theme = $this->config->getSystemValue('theme'); |
|
327 | + if (!empty($theme)) { |
|
328 | + $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
329 | + if (file_exists($transFile)) { |
|
330 | + $languageFiles[] = $transFile; |
|
331 | + } |
|
332 | + } |
|
333 | + |
|
334 | + return $languageFiles; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * find the l10n directory |
|
339 | + * |
|
340 | + * @param string $app App id or empty string for core |
|
341 | + * @return string directory |
|
342 | + */ |
|
343 | + protected function findL10nDir($app = null) { |
|
344 | + if (in_array($app, ['core', 'lib', 'settings'])) { |
|
345 | + if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
346 | + return $this->serverRoot . '/' . $app . '/l10n/'; |
|
347 | + } |
|
348 | + } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
349 | + // Check if the app is in the app folder |
|
350 | + return \OC_App::getAppPath($app) . '/l10n/'; |
|
351 | + } |
|
352 | + return $this->serverRoot . '/core/l10n/'; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Creates a function from the plural string |
|
358 | + * |
|
359 | + * Parts of the code is copied from Habari: |
|
360 | + * https://github.com/habari/system/blob/master/classes/locale.php |
|
361 | + * @param string $string |
|
362 | + * @return string |
|
363 | + */ |
|
364 | + public function createPluralFunction($string) { |
|
365 | + if (isset($this->pluralFunctions[$string])) { |
|
366 | + return $this->pluralFunctions[$string]; |
|
367 | + } |
|
368 | + |
|
369 | + if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
370 | + // sanitize |
|
371 | + $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
372 | + $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
373 | + |
|
374 | + $body = str_replace( |
|
375 | + array( 'plural', 'n', '$n$plurals', ), |
|
376 | + array( '$plural', '$n', '$nplurals', ), |
|
377 | + 'nplurals='. $nplurals . '; plural=' . $plural |
|
378 | + ); |
|
379 | + |
|
380 | + // add parents |
|
381 | + // important since PHP's ternary evaluates from left to right |
|
382 | + $body .= ';'; |
|
383 | + $res = ''; |
|
384 | + $p = 0; |
|
385 | + for($i = 0; $i < strlen($body); $i++) { |
|
386 | + $ch = $body[$i]; |
|
387 | + switch ( $ch ) { |
|
388 | + case '?': |
|
389 | + $res .= ' ? ('; |
|
390 | + $p++; |
|
391 | + break; |
|
392 | + case ':': |
|
393 | + $res .= ') : ('; |
|
394 | + break; |
|
395 | + case ';': |
|
396 | + $res .= str_repeat( ')', $p ) . ';'; |
|
397 | + $p = 0; |
|
398 | + break; |
|
399 | + default: |
|
400 | + $res .= $ch; |
|
401 | + } |
|
402 | + } |
|
403 | + |
|
404 | + $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
405 | + $function = create_function('$n', $body); |
|
406 | + $this->pluralFunctions[$string] = $function; |
|
407 | + return $function; |
|
408 | + } else { |
|
409 | + // default: one plural form for all cases but n==1 (english) |
|
410 | + $function = create_function( |
|
411 | + '$n', |
|
412 | + '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
413 | + ); |
|
414 | + $this->pluralFunctions[$string] = $function; |
|
415 | + return $function; |
|
416 | + } |
|
417 | + } |
|
418 | 418 | } |
@@ -110,6 +110,9 @@ |
||
110 | 110 | return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
111 | 111 | } |
112 | 112 | |
113 | + /** |
|
114 | + * @param ICacheEntry $entry |
|
115 | + */ |
|
113 | 116 | protected function formatCacheEntry($entry) { |
114 | 117 | $path = isset($entry['path']) ? $entry['path'] : ''; |
115 | 118 | $entry = parent::formatCacheEntry($entry); |
@@ -37,112 +37,112 @@ |
||
37 | 37 | * don't use this class directly if you need to get metadata, use \OC\Files\Filesystem::getFileInfo instead |
38 | 38 | */ |
39 | 39 | class Cache extends CacheJail { |
40 | - /** |
|
41 | - * @var \OCA\Files_Sharing\SharedStorage |
|
42 | - */ |
|
43 | - private $storage; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var ICacheEntry |
|
47 | - */ |
|
48 | - private $sourceRootInfo; |
|
49 | - |
|
50 | - private $rootUnchanged = true; |
|
51 | - |
|
52 | - private $ownerDisplayName; |
|
53 | - |
|
54 | - private $numericId; |
|
55 | - |
|
56 | - /** |
|
57 | - * @param \OCA\Files_Sharing\SharedStorage $storage |
|
58 | - * @param ICacheEntry $sourceRootInfo |
|
59 | - */ |
|
60 | - public function __construct($storage, ICacheEntry $sourceRootInfo) { |
|
61 | - $this->storage = $storage; |
|
62 | - $this->sourceRootInfo = $sourceRootInfo; |
|
63 | - $this->numericId = $sourceRootInfo->getStorageId(); |
|
64 | - parent::__construct( |
|
65 | - null, |
|
66 | - $this->sourceRootInfo->getPath() |
|
67 | - ); |
|
68 | - } |
|
69 | - |
|
70 | - public function getCache() { |
|
71 | - if (is_null($this->cache)) { |
|
72 | - $sourceStorage = $this->storage->getSourceStorage(); |
|
73 | - if ($sourceStorage) { |
|
74 | - $this->cache = $sourceStorage->getCache(); |
|
75 | - } else { |
|
76 | - // don't set $this->cache here since sourceStorage will be set later |
|
77 | - return new FailedCache(); |
|
78 | - } |
|
79 | - } |
|
80 | - return $this->cache; |
|
81 | - } |
|
82 | - |
|
83 | - public function getNumericStorageId() { |
|
84 | - if (isset($this->numericId)) { |
|
85 | - return $this->numericId; |
|
86 | - } else { |
|
87 | - return false; |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - public function get($file) { |
|
92 | - if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
93 | - return $this->formatCacheEntry(clone $this->sourceRootInfo); |
|
94 | - } |
|
95 | - return parent::get($file); |
|
96 | - } |
|
97 | - |
|
98 | - public function update($id, array $data) { |
|
99 | - $this->rootUnchanged = false; |
|
100 | - parent::update($id, $data); |
|
101 | - } |
|
102 | - |
|
103 | - public function insert($file, array $data) { |
|
104 | - $this->rootUnchanged = false; |
|
105 | - return parent::insert($file, $data); |
|
106 | - } |
|
107 | - |
|
108 | - public function remove($file) { |
|
109 | - $this->rootUnchanged = false; |
|
110 | - parent::remove($file); |
|
111 | - } |
|
112 | - |
|
113 | - public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
114 | - $this->rootUnchanged = false; |
|
115 | - return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
116 | - } |
|
117 | - |
|
118 | - protected function formatCacheEntry($entry) { |
|
119 | - $path = isset($entry['path']) ? $entry['path'] : ''; |
|
120 | - $entry = parent::formatCacheEntry($entry); |
|
121 | - $sharePermissions = $this->storage->getPermissions($path); |
|
122 | - if (isset($entry['permissions'])) { |
|
123 | - $entry['permissions'] &= $sharePermissions; |
|
124 | - } else { |
|
125 | - $entry['permissions'] = $sharePermissions; |
|
126 | - } |
|
127 | - $entry['uid_owner'] = $this->storage->getOwner($path); |
|
128 | - $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
129 | - if ($path === '') { |
|
130 | - $entry['is_share_mount_point'] = true; |
|
131 | - } |
|
132 | - return $entry; |
|
133 | - } |
|
134 | - |
|
135 | - private function getOwnerDisplayName() { |
|
136 | - if (!$this->ownerDisplayName) { |
|
137 | - $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner('')); |
|
138 | - } |
|
139 | - return $this->ownerDisplayName; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * remove all entries for files that are stored on the storage from the cache |
|
144 | - */ |
|
145 | - public function clear() { |
|
146 | - // Not a valid action for Shared Cache |
|
147 | - } |
|
40 | + /** |
|
41 | + * @var \OCA\Files_Sharing\SharedStorage |
|
42 | + */ |
|
43 | + private $storage; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var ICacheEntry |
|
47 | + */ |
|
48 | + private $sourceRootInfo; |
|
49 | + |
|
50 | + private $rootUnchanged = true; |
|
51 | + |
|
52 | + private $ownerDisplayName; |
|
53 | + |
|
54 | + private $numericId; |
|
55 | + |
|
56 | + /** |
|
57 | + * @param \OCA\Files_Sharing\SharedStorage $storage |
|
58 | + * @param ICacheEntry $sourceRootInfo |
|
59 | + */ |
|
60 | + public function __construct($storage, ICacheEntry $sourceRootInfo) { |
|
61 | + $this->storage = $storage; |
|
62 | + $this->sourceRootInfo = $sourceRootInfo; |
|
63 | + $this->numericId = $sourceRootInfo->getStorageId(); |
|
64 | + parent::__construct( |
|
65 | + null, |
|
66 | + $this->sourceRootInfo->getPath() |
|
67 | + ); |
|
68 | + } |
|
69 | + |
|
70 | + public function getCache() { |
|
71 | + if (is_null($this->cache)) { |
|
72 | + $sourceStorage = $this->storage->getSourceStorage(); |
|
73 | + if ($sourceStorage) { |
|
74 | + $this->cache = $sourceStorage->getCache(); |
|
75 | + } else { |
|
76 | + // don't set $this->cache here since sourceStorage will be set later |
|
77 | + return new FailedCache(); |
|
78 | + } |
|
79 | + } |
|
80 | + return $this->cache; |
|
81 | + } |
|
82 | + |
|
83 | + public function getNumericStorageId() { |
|
84 | + if (isset($this->numericId)) { |
|
85 | + return $this->numericId; |
|
86 | + } else { |
|
87 | + return false; |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + public function get($file) { |
|
92 | + if ($this->rootUnchanged && ($file === '' || $file === $this->sourceRootInfo->getId())) { |
|
93 | + return $this->formatCacheEntry(clone $this->sourceRootInfo); |
|
94 | + } |
|
95 | + return parent::get($file); |
|
96 | + } |
|
97 | + |
|
98 | + public function update($id, array $data) { |
|
99 | + $this->rootUnchanged = false; |
|
100 | + parent::update($id, $data); |
|
101 | + } |
|
102 | + |
|
103 | + public function insert($file, array $data) { |
|
104 | + $this->rootUnchanged = false; |
|
105 | + return parent::insert($file, $data); |
|
106 | + } |
|
107 | + |
|
108 | + public function remove($file) { |
|
109 | + $this->rootUnchanged = false; |
|
110 | + parent::remove($file); |
|
111 | + } |
|
112 | + |
|
113 | + public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) { |
|
114 | + $this->rootUnchanged = false; |
|
115 | + return parent::moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
116 | + } |
|
117 | + |
|
118 | + protected function formatCacheEntry($entry) { |
|
119 | + $path = isset($entry['path']) ? $entry['path'] : ''; |
|
120 | + $entry = parent::formatCacheEntry($entry); |
|
121 | + $sharePermissions = $this->storage->getPermissions($path); |
|
122 | + if (isset($entry['permissions'])) { |
|
123 | + $entry['permissions'] &= $sharePermissions; |
|
124 | + } else { |
|
125 | + $entry['permissions'] = $sharePermissions; |
|
126 | + } |
|
127 | + $entry['uid_owner'] = $this->storage->getOwner($path); |
|
128 | + $entry['displayname_owner'] = $this->getOwnerDisplayName(); |
|
129 | + if ($path === '') { |
|
130 | + $entry['is_share_mount_point'] = true; |
|
131 | + } |
|
132 | + return $entry; |
|
133 | + } |
|
134 | + |
|
135 | + private function getOwnerDisplayName() { |
|
136 | + if (!$this->ownerDisplayName) { |
|
137 | + $this->ownerDisplayName = \OC_User::getDisplayName($this->storage->getOwner('')); |
|
138 | + } |
|
139 | + return $this->ownerDisplayName; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * remove all entries for files that are stored on the storage from the cache |
|
144 | + */ |
|
145 | + public function clear() { |
|
146 | + // Not a valid action for Shared Cache |
|
147 | + } |
|
148 | 148 | } |