@@ -32,30 +32,30 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | interface IEventDispatcher { |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @param string $eventName preferably the fully-qualified class name of the Event sub class |
|
| 37 | - * @param callable $listener the object that is invoked when a matching event is dispatched |
|
| 38 | - * @param int $priority |
|
| 39 | - * |
|
| 40 | - * @since 17.0.0 |
|
| 41 | - */ |
|
| 42 | - public function addListener(string $eventName, callable $listener, int $priority = 0): void; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for |
|
| 46 | - * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
| 47 | - * @param int $priority |
|
| 48 | - * |
|
| 49 | - * @since 17.0.0 |
|
| 50 | - */ |
|
| 51 | - public function addServiceListener(string $eventName, string $className, int $priority = 0): void; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param string $eventName |
|
| 55 | - * @param Event $event |
|
| 56 | - * |
|
| 57 | - * @since 17.0.0 |
|
| 58 | - */ |
|
| 59 | - public function dispatch(string $eventName, Event $event): void; |
|
| 35 | + /** |
|
| 36 | + * @param string $eventName preferably the fully-qualified class name of the Event sub class |
|
| 37 | + * @param callable $listener the object that is invoked when a matching event is dispatched |
|
| 38 | + * @param int $priority |
|
| 39 | + * |
|
| 40 | + * @since 17.0.0 |
|
| 41 | + */ |
|
| 42 | + public function addListener(string $eventName, callable $listener, int $priority = 0): void; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for |
|
| 46 | + * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container |
|
| 47 | + * @param int $priority |
|
| 48 | + * |
|
| 49 | + * @since 17.0.0 |
|
| 50 | + */ |
|
| 51 | + public function addServiceListener(string $eventName, string $className, int $priority = 0): void; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param string $eventName |
|
| 55 | + * @param Event $event |
|
| 56 | + * |
|
| 57 | + * @since 17.0.0 |
|
| 58 | + */ |
|
| 59 | + public function dispatch(string $eventName, Event $event): void; |
|
| 60 | 60 | |
| 61 | 61 | } |
@@ -30,11 +30,11 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | interface IEventListener { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param Event $event |
|
| 35 | - * |
|
| 36 | - * @since 17.0.0 |
|
| 37 | - */ |
|
| 38 | - public function handle(Event $event): void; |
|
| 33 | + /** |
|
| 34 | + * @param Event $event |
|
| 35 | + * |
|
| 36 | + * @since 17.0.0 |
|
| 37 | + */ |
|
| 38 | + public function handle(Event $event): void; |
|
| 39 | 39 | |
| 40 | 40 | } |
@@ -32,32 +32,32 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class RegistryEvent extends Event { |
| 34 | 34 | |
| 35 | - /** @var IProvider */ |
|
| 36 | - private $provider; |
|
| 37 | - |
|
| 38 | - /** @IUser */ |
|
| 39 | - private $user; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @since 15.0.0 |
|
| 43 | - */ |
|
| 44 | - public function __construct(IProvider $provider, IUser $user) { |
|
| 45 | - parent::__construct(); |
|
| 46 | - $this->provider = $provider; |
|
| 47 | - $this->user = $user; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @since 15.0.0 |
|
| 52 | - */ |
|
| 53 | - public function getProvider(): IProvider { |
|
| 54 | - return $this->provider; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @since 15.0.0 |
|
| 59 | - */ |
|
| 60 | - public function getUser(): IUser { |
|
| 61 | - return $this->user; |
|
| 62 | - } |
|
| 35 | + /** @var IProvider */ |
|
| 36 | + private $provider; |
|
| 37 | + |
|
| 38 | + /** @IUser */ |
|
| 39 | + private $user; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @since 15.0.0 |
|
| 43 | + */ |
|
| 44 | + public function __construct(IProvider $provider, IUser $user) { |
|
| 45 | + parent::__construct(); |
|
| 46 | + $this->provider = $provider; |
|
| 47 | + $this->user = $user; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @since 15.0.0 |
|
| 52 | + */ |
|
| 53 | + public function getProvider(): IProvider { |
|
| 54 | + return $this->provider; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @since 15.0.0 |
|
| 59 | + */ |
|
| 60 | + public function getUser(): IUser { |
|
| 61 | + return $this->user; |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -39,40 +39,40 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | final class ServiceEventListener { |
| 41 | 41 | |
| 42 | - /** @var IContainer */ |
|
| 43 | - private $container; |
|
| 42 | + /** @var IContainer */ |
|
| 43 | + private $container; |
|
| 44 | 44 | |
| 45 | - /** @var string */ |
|
| 46 | - private $class; |
|
| 45 | + /** @var string */ |
|
| 46 | + private $class; |
|
| 47 | 47 | |
| 48 | - /** @var ILogger */ |
|
| 49 | - private $logger; |
|
| 48 | + /** @var ILogger */ |
|
| 49 | + private $logger; |
|
| 50 | 50 | |
| 51 | - /** @var null|IEventListener */ |
|
| 52 | - private $service; |
|
| 51 | + /** @var null|IEventListener */ |
|
| 52 | + private $service; |
|
| 53 | 53 | |
| 54 | - public function __construct(IContainer $container, |
|
| 55 | - string $class, |
|
| 56 | - ILogger $logger) { |
|
| 57 | - $this->container = $container; |
|
| 58 | - $this->class = $class; |
|
| 59 | - $this->logger = $logger; |
|
| 60 | - } |
|
| 54 | + public function __construct(IContainer $container, |
|
| 55 | + string $class, |
|
| 56 | + ILogger $logger) { |
|
| 57 | + $this->container = $container; |
|
| 58 | + $this->class = $class; |
|
| 59 | + $this->logger = $logger; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function __invoke(Event $event) { |
|
| 63 | - if ($this->service === null) { |
|
| 64 | - try { |
|
| 65 | - $this->service = $this->container->query($this->class); |
|
| 66 | - } catch (QueryException $e) { |
|
| 67 | - $this->logger->logException($e, [ |
|
| 68 | - 'level' => ILogger::ERROR, |
|
| 69 | - 'message' => "Could not load event listener service " . $this->class, |
|
| 70 | - ]); |
|
| 71 | - return; |
|
| 72 | - } |
|
| 73 | - } |
|
| 62 | + public function __invoke(Event $event) { |
|
| 63 | + if ($this->service === null) { |
|
| 64 | + try { |
|
| 65 | + $this->service = $this->container->query($this->class); |
|
| 66 | + } catch (QueryException $e) { |
|
| 67 | + $this->logger->logException($e, [ |
|
| 68 | + 'level' => ILogger::ERROR, |
|
| 69 | + 'message' => "Could not load event listener service " . $this->class, |
|
| 70 | + ]); |
|
| 71 | + return; |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $this->service->handle($event); |
|
| 76 | - } |
|
| 75 | + $this->service->handle($event); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | 78 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | } catch (QueryException $e) { |
| 67 | 67 | $this->logger->logException($e, [ |
| 68 | 68 | 'level' => ILogger::ERROR, |
| 69 | - 'message' => "Could not load event listener service " . $this->class, |
|
| 69 | + 'message' => "Could not load event listener service ".$this->class, |
|
| 70 | 70 | ]); |
| 71 | 71 | return; |
| 72 | 72 | } |
@@ -34,52 +34,52 @@ |
||
| 34 | 34 | |
| 35 | 35 | class EventDispatcher implements IEventDispatcher { |
| 36 | 36 | |
| 37 | - /** @var SymfonyDispatcher */ |
|
| 38 | - private $dispatcher; |
|
| 39 | - |
|
| 40 | - /** @var IContainer */ |
|
| 41 | - private $container; |
|
| 42 | - |
|
| 43 | - /** @var ILogger */ |
|
| 44 | - private $logger; |
|
| 45 | - |
|
| 46 | - public function __construct(SymfonyDispatcher $dispatcher, |
|
| 47 | - IServerContainer $container, |
|
| 48 | - ILogger $logger) { |
|
| 49 | - $this->dispatcher = $dispatcher; |
|
| 50 | - $this->container = $container; |
|
| 51 | - $this->logger = $logger; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function addListener(string $eventName, |
|
| 55 | - callable $listener, |
|
| 56 | - int $priority = 0): void { |
|
| 57 | - $this->dispatcher->addListener($eventName, $listener, $priority); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - public function addServiceListener(string $eventName, |
|
| 61 | - string $className, |
|
| 62 | - int $priority = 0): void { |
|
| 63 | - $listener = new ServiceEventListener( |
|
| 64 | - $this->container, |
|
| 65 | - $className, |
|
| 66 | - $this->logger |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - $this->addListener($eventName, $listener, $priority); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - public function dispatch(string $eventName, |
|
| 73 | - Event $event): void { |
|
| 74 | - |
|
| 75 | - $this->dispatcher->dispatch($eventName, $event); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return SymfonyDispatcher |
|
| 80 | - */ |
|
| 81 | - public function getSymfonyDispatcher(): SymfonyDispatcher { |
|
| 82 | - return $this->dispatcher; |
|
| 83 | - } |
|
| 37 | + /** @var SymfonyDispatcher */ |
|
| 38 | + private $dispatcher; |
|
| 39 | + |
|
| 40 | + /** @var IContainer */ |
|
| 41 | + private $container; |
|
| 42 | + |
|
| 43 | + /** @var ILogger */ |
|
| 44 | + private $logger; |
|
| 45 | + |
|
| 46 | + public function __construct(SymfonyDispatcher $dispatcher, |
|
| 47 | + IServerContainer $container, |
|
| 48 | + ILogger $logger) { |
|
| 49 | + $this->dispatcher = $dispatcher; |
|
| 50 | + $this->container = $container; |
|
| 51 | + $this->logger = $logger; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function addListener(string $eventName, |
|
| 55 | + callable $listener, |
|
| 56 | + int $priority = 0): void { |
|
| 57 | + $this->dispatcher->addListener($eventName, $listener, $priority); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + public function addServiceListener(string $eventName, |
|
| 61 | + string $className, |
|
| 62 | + int $priority = 0): void { |
|
| 63 | + $listener = new ServiceEventListener( |
|
| 64 | + $this->container, |
|
| 65 | + $className, |
|
| 66 | + $this->logger |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + $this->addListener($eventName, $listener, $priority); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + public function dispatch(string $eventName, |
|
| 73 | + Event $event): void { |
|
| 74 | + |
|
| 75 | + $this->dispatcher->dispatch($eventName, $event); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return SymfonyDispatcher |
|
| 80 | + */ |
|
| 81 | + public function getSymfonyDispatcher(): SymfonyDispatcher { |
|
| 82 | + return $this->dispatcher; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | } |
@@ -33,108 +33,108 @@ |
||
| 33 | 33 | |
| 34 | 34 | class SymfonyAdapter implements EventDispatcherInterface { |
| 35 | 35 | |
| 36 | - /** @var EventDispatcher */ |
|
| 37 | - private $eventDispatcher; |
|
| 38 | - |
|
| 39 | - public function __construct(EventDispatcher $eventDispatcher) { |
|
| 40 | - $this->eventDispatcher = $eventDispatcher; |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Dispatches an event to all registered listeners. |
|
| 45 | - * |
|
| 46 | - * @param string $eventName The name of the event to dispatch. The name of |
|
| 47 | - * the event is the name of the method that is |
|
| 48 | - * invoked on listeners. |
|
| 49 | - * @param SymfonyEvent|null $event The event to pass to the event handlers/listeners |
|
| 50 | - * If not supplied, an empty Event instance is created |
|
| 51 | - * |
|
| 52 | - * @return SymfonyEvent |
|
| 53 | - */ |
|
| 54 | - public function dispatch($eventName, SymfonyEvent $event = null) { |
|
| 55 | - if ($event instanceof Event) { |
|
| 56 | - $this->eventDispatcher->dispatch($eventName, $event); |
|
| 57 | - } else { |
|
| 58 | - // Legacy event |
|
| 59 | - $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $event); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Adds an event listener that listens on the specified events. |
|
| 65 | - * |
|
| 66 | - * @param string $eventName The event to listen on |
|
| 67 | - * @param callable $listener The listener |
|
| 68 | - * @param int $priority The higher this value, the earlier an event |
|
| 69 | - * listener will be triggered in the chain (defaults to 0) |
|
| 70 | - */ |
|
| 71 | - public function addListener($eventName, $listener, $priority = 0) { |
|
| 72 | - if (is_callable($listener)) { |
|
| 73 | - $this->eventDispatcher->addListener($eventName, $listener, $priority); |
|
| 74 | - } else { |
|
| 75 | - // Legacy listener |
|
| 76 | - $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Adds an event subscriber. |
|
| 82 | - * |
|
| 83 | - * The subscriber is asked for all the events it is |
|
| 84 | - * interested in and added as a listener for these events. |
|
| 85 | - */ |
|
| 86 | - public function addSubscriber(EventSubscriberInterface $subscriber) { |
|
| 87 | - $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Removes an event listener from the specified events. |
|
| 92 | - * |
|
| 93 | - * @param string $eventName The event to remove a listener from |
|
| 94 | - * @param callable $listener The listener to remove |
|
| 95 | - */ |
|
| 96 | - public function removeListener($eventName, $listener) { |
|
| 97 | - $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - public function removeSubscriber(EventSubscriberInterface $subscriber) { |
|
| 101 | - $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Gets the listeners of a specific event or all listeners sorted by descending priority. |
|
| 106 | - * |
|
| 107 | - * @param string|null $eventName The name of the event |
|
| 108 | - * |
|
| 109 | - * @return array The event listeners for the specified event, or all event listeners by event name |
|
| 110 | - */ |
|
| 111 | - public function getListeners($eventName = null) { |
|
| 112 | - return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Gets the listener priority for a specific event. |
|
| 117 | - * |
|
| 118 | - * Returns null if the event or the listener does not exist. |
|
| 119 | - * |
|
| 120 | - * @param string $eventName The name of the event |
|
| 121 | - * @param callable $listener The listener |
|
| 122 | - * |
|
| 123 | - * @return int|null The event listener priority |
|
| 124 | - */ |
|
| 125 | - public function getListenerPriority($eventName, $listener) { |
|
| 126 | - return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Checks whether an event has any registered listeners. |
|
| 131 | - * |
|
| 132 | - * @param string|null $eventName The name of the event |
|
| 133 | - * |
|
| 134 | - * @return bool true if the specified event has any listeners, false otherwise |
|
| 135 | - */ |
|
| 136 | - public function hasListeners($eventName = null) { |
|
| 137 | - return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName); |
|
| 138 | - } |
|
| 36 | + /** @var EventDispatcher */ |
|
| 37 | + private $eventDispatcher; |
|
| 38 | + |
|
| 39 | + public function __construct(EventDispatcher $eventDispatcher) { |
|
| 40 | + $this->eventDispatcher = $eventDispatcher; |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Dispatches an event to all registered listeners. |
|
| 45 | + * |
|
| 46 | + * @param string $eventName The name of the event to dispatch. The name of |
|
| 47 | + * the event is the name of the method that is |
|
| 48 | + * invoked on listeners. |
|
| 49 | + * @param SymfonyEvent|null $event The event to pass to the event handlers/listeners |
|
| 50 | + * If not supplied, an empty Event instance is created |
|
| 51 | + * |
|
| 52 | + * @return SymfonyEvent |
|
| 53 | + */ |
|
| 54 | + public function dispatch($eventName, SymfonyEvent $event = null) { |
|
| 55 | + if ($event instanceof Event) { |
|
| 56 | + $this->eventDispatcher->dispatch($eventName, $event); |
|
| 57 | + } else { |
|
| 58 | + // Legacy event |
|
| 59 | + $this->eventDispatcher->getSymfonyDispatcher()->dispatch($eventName, $event); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Adds an event listener that listens on the specified events. |
|
| 65 | + * |
|
| 66 | + * @param string $eventName The event to listen on |
|
| 67 | + * @param callable $listener The listener |
|
| 68 | + * @param int $priority The higher this value, the earlier an event |
|
| 69 | + * listener will be triggered in the chain (defaults to 0) |
|
| 70 | + */ |
|
| 71 | + public function addListener($eventName, $listener, $priority = 0) { |
|
| 72 | + if (is_callable($listener)) { |
|
| 73 | + $this->eventDispatcher->addListener($eventName, $listener, $priority); |
|
| 74 | + } else { |
|
| 75 | + // Legacy listener |
|
| 76 | + $this->eventDispatcher->getSymfonyDispatcher()->addListener($eventName, $listener, $priority); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Adds an event subscriber. |
|
| 82 | + * |
|
| 83 | + * The subscriber is asked for all the events it is |
|
| 84 | + * interested in and added as a listener for these events. |
|
| 85 | + */ |
|
| 86 | + public function addSubscriber(EventSubscriberInterface $subscriber) { |
|
| 87 | + $this->eventDispatcher->getSymfonyDispatcher()->addSubscriber($subscriber); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Removes an event listener from the specified events. |
|
| 92 | + * |
|
| 93 | + * @param string $eventName The event to remove a listener from |
|
| 94 | + * @param callable $listener The listener to remove |
|
| 95 | + */ |
|
| 96 | + public function removeListener($eventName, $listener) { |
|
| 97 | + $this->eventDispatcher->getSymfonyDispatcher()->removeListener($eventName, $listener); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + public function removeSubscriber(EventSubscriberInterface $subscriber) { |
|
| 101 | + $this->eventDispatcher->getSymfonyDispatcher()->removeSubscriber($subscriber); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Gets the listeners of a specific event or all listeners sorted by descending priority. |
|
| 106 | + * |
|
| 107 | + * @param string|null $eventName The name of the event |
|
| 108 | + * |
|
| 109 | + * @return array The event listeners for the specified event, or all event listeners by event name |
|
| 110 | + */ |
|
| 111 | + public function getListeners($eventName = null) { |
|
| 112 | + return $this->eventDispatcher->getSymfonyDispatcher()->getListeners($eventName); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Gets the listener priority for a specific event. |
|
| 117 | + * |
|
| 118 | + * Returns null if the event or the listener does not exist. |
|
| 119 | + * |
|
| 120 | + * @param string $eventName The name of the event |
|
| 121 | + * @param callable $listener The listener |
|
| 122 | + * |
|
| 123 | + * @return int|null The event listener priority |
|
| 124 | + */ |
|
| 125 | + public function getListenerPriority($eventName, $listener) { |
|
| 126 | + return $this->eventDispatcher->getSymfonyDispatcher()->getListenerPriority($eventName, $listener); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Checks whether an event has any registered listeners. |
|
| 131 | + * |
|
| 132 | + * @param string|null $eventName The name of the event |
|
| 133 | + * |
|
| 134 | + * @return bool true if the specified event has any listeners, false otherwise |
|
| 135 | + */ |
|
| 136 | + public function hasListeners($eventName = null) { |
|
| 137 | + return $this->eventDispatcher->getSymfonyDispatcher()->hasListeners($eventName); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | } |
@@ -168,1896 +168,1896 @@ |
||
| 168 | 168 | * TODO: hookup all manager classes |
| 169 | 169 | */ |
| 170 | 170 | class Server extends ServerContainer implements IServerContainer { |
| 171 | - /** @var string */ |
|
| 172 | - private $webRoot; |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param string $webRoot |
|
| 176 | - * @param \OC\Config $config |
|
| 177 | - */ |
|
| 178 | - public function __construct($webRoot, \OC\Config $config) { |
|
| 179 | - parent::__construct(); |
|
| 180 | - $this->webRoot = $webRoot; |
|
| 181 | - |
|
| 182 | - // To find out if we are running from CLI or not |
|
| 183 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
| 184 | - |
|
| 185 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 186 | - return $c; |
|
| 187 | - }); |
|
| 188 | - |
|
| 189 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 190 | - $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 191 | - |
|
| 192 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 193 | - $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 194 | - |
|
| 195 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 196 | - $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 197 | - |
|
| 198 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 199 | - $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 200 | - |
|
| 201 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 205 | - return new PreviewManager( |
|
| 206 | - $c->getConfig(), |
|
| 207 | - $c->getRootFolder(), |
|
| 208 | - $c->getAppDataDir('preview'), |
|
| 209 | - $c->getEventDispatcher(), |
|
| 210 | - $c->getSession()->get('user_id') |
|
| 211 | - ); |
|
| 212 | - }); |
|
| 213 | - $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 214 | - |
|
| 215 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 216 | - return new \OC\Preview\Watcher( |
|
| 217 | - $c->getAppDataDir('preview') |
|
| 218 | - ); |
|
| 219 | - }); |
|
| 220 | - |
|
| 221 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 222 | - $view = new View(); |
|
| 223 | - $util = new Encryption\Util( |
|
| 224 | - $view, |
|
| 225 | - $c->getUserManager(), |
|
| 226 | - $c->getGroupManager(), |
|
| 227 | - $c->getConfig() |
|
| 228 | - ); |
|
| 229 | - return new Encryption\Manager( |
|
| 230 | - $c->getConfig(), |
|
| 231 | - $c->getLogger(), |
|
| 232 | - $c->getL10N('core'), |
|
| 233 | - new View(), |
|
| 234 | - $util, |
|
| 235 | - new ArrayCache() |
|
| 236 | - ); |
|
| 237 | - }); |
|
| 238 | - $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 239 | - |
|
| 240 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 241 | - $util = new Encryption\Util( |
|
| 242 | - new View(), |
|
| 243 | - $c->getUserManager(), |
|
| 244 | - $c->getGroupManager(), |
|
| 245 | - $c->getConfig() |
|
| 246 | - ); |
|
| 247 | - return new Encryption\File( |
|
| 248 | - $util, |
|
| 249 | - $c->getRootFolder(), |
|
| 250 | - $c->getShareManager() |
|
| 251 | - ); |
|
| 252 | - }); |
|
| 253 | - |
|
| 254 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 255 | - $view = new View(); |
|
| 256 | - $util = new Encryption\Util( |
|
| 257 | - $view, |
|
| 258 | - $c->getUserManager(), |
|
| 259 | - $c->getGroupManager(), |
|
| 260 | - $c->getConfig() |
|
| 261 | - ); |
|
| 262 | - |
|
| 263 | - return new Encryption\Keys\Storage($view, $util); |
|
| 264 | - }); |
|
| 265 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 266 | - return new TagMapper($c->getDatabaseConnection()); |
|
| 267 | - }); |
|
| 268 | - |
|
| 269 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 270 | - $tagMapper = $c->query('TagMapper'); |
|
| 271 | - return new TagManager($tagMapper, $c->getUserSession()); |
|
| 272 | - }); |
|
| 273 | - $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 274 | - |
|
| 275 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 276 | - $config = $c->getConfig(); |
|
| 277 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 278 | - return new $factoryClass($this); |
|
| 279 | - }); |
|
| 280 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 281 | - return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 282 | - }); |
|
| 283 | - $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 284 | - |
|
| 285 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 286 | - return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 287 | - }); |
|
| 288 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 289 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 290 | - $view = new View(); |
|
| 291 | - $root = new Root( |
|
| 292 | - $manager, |
|
| 293 | - $view, |
|
| 294 | - null, |
|
| 295 | - $c->getUserMountCache(), |
|
| 296 | - $this->getLogger(), |
|
| 297 | - $this->getUserManager() |
|
| 298 | - ); |
|
| 299 | - $connector = new HookConnector($root, $view); |
|
| 300 | - $connector->viewToNode(); |
|
| 301 | - |
|
| 302 | - $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 303 | - $previewConnector->connectWatcher(); |
|
| 304 | - |
|
| 305 | - return $root; |
|
| 306 | - }); |
|
| 307 | - $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 308 | - |
|
| 309 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 310 | - return new LazyRoot(function () use ($c) { |
|
| 311 | - return $c->query('RootFolder'); |
|
| 312 | - }); |
|
| 313 | - }); |
|
| 314 | - $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 315 | - |
|
| 316 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
| 317 | - return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
|
| 318 | - }); |
|
| 319 | - $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
| 320 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 321 | - |
|
| 322 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 323 | - $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
| 324 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 325 | - \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 326 | - }); |
|
| 327 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 328 | - \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 329 | - }); |
|
| 330 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 331 | - \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 332 | - }); |
|
| 333 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 334 | - \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 335 | - }); |
|
| 336 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 337 | - \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 338 | - }); |
|
| 339 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 340 | - \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 341 | - //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 342 | - \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 343 | - }); |
|
| 344 | - return $groupManager; |
|
| 345 | - }); |
|
| 346 | - $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 347 | - |
|
| 348 | - $this->registerService(Store::class, function (Server $c) { |
|
| 349 | - $session = $c->getSession(); |
|
| 350 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 351 | - $tokenProvider = $c->query(IProvider::class); |
|
| 352 | - } else { |
|
| 353 | - $tokenProvider = null; |
|
| 354 | - } |
|
| 355 | - $logger = $c->getLogger(); |
|
| 356 | - return new Store($session, $logger, $tokenProvider); |
|
| 357 | - }); |
|
| 358 | - $this->registerAlias(IStore::class, Store::class); |
|
| 359 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 360 | - $dbConnection = $c->getDatabaseConnection(); |
|
| 361 | - return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 362 | - }); |
|
| 363 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 364 | - |
|
| 365 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 366 | - $manager = $c->getUserManager(); |
|
| 367 | - $session = new \OC\Session\Memory(''); |
|
| 368 | - $timeFactory = new TimeFactory(); |
|
| 369 | - // Token providers might require a working database. This code |
|
| 370 | - // might however be called when ownCloud is not yet setup. |
|
| 371 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 372 | - $defaultTokenProvider = $c->query(IProvider::class); |
|
| 373 | - } else { |
|
| 374 | - $defaultTokenProvider = null; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $dispatcher = $c->getEventDispatcher(); |
|
| 378 | - |
|
| 379 | - $userSession = new \OC\User\Session( |
|
| 380 | - $manager, |
|
| 381 | - $session, |
|
| 382 | - $timeFactory, |
|
| 383 | - $defaultTokenProvider, |
|
| 384 | - $c->getConfig(), |
|
| 385 | - $c->getSecureRandom(), |
|
| 386 | - $c->getLockdownManager(), |
|
| 387 | - $c->getLogger() |
|
| 388 | - ); |
|
| 389 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 390 | - \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 391 | - }); |
|
| 392 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 393 | - /** @var $user \OC\User\User */ |
|
| 394 | - \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 395 | - }); |
|
| 396 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
| 397 | - /** @var $user \OC\User\User */ |
|
| 398 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 399 | - $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 400 | - }); |
|
| 401 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 402 | - /** @var $user \OC\User\User */ |
|
| 403 | - \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 404 | - }); |
|
| 405 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 406 | - /** @var $user \OC\User\User */ |
|
| 407 | - \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 408 | - }); |
|
| 409 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 410 | - /** @var $user \OC\User\User */ |
|
| 411 | - \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 412 | - }); |
|
| 413 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 414 | - \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 415 | - }); |
|
| 416 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 417 | - /** @var $user \OC\User\User */ |
|
| 418 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
| 419 | - }); |
|
| 420 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 421 | - /** @var $user \OC\User\User */ |
|
| 422 | - \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 423 | - }); |
|
| 424 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 425 | - \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 426 | - }); |
|
| 427 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 428 | - /** @var $user \OC\User\User */ |
|
| 429 | - \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 430 | - }); |
|
| 431 | - return $userSession; |
|
| 432 | - }); |
|
| 433 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 434 | - $this->registerAlias('UserSession', \OC\User\Session::class); |
|
| 435 | - |
|
| 436 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 437 | - |
|
| 438 | - $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 439 | - $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 440 | - |
|
| 441 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 442 | - return new \OC\AllConfig( |
|
| 443 | - $c->getSystemConfig() |
|
| 444 | - ); |
|
| 445 | - }); |
|
| 446 | - $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 447 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 448 | - |
|
| 449 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 450 | - return new \OC\SystemConfig($config); |
|
| 451 | - }); |
|
| 452 | - |
|
| 453 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 454 | - return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 455 | - }); |
|
| 456 | - $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 457 | - $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 458 | - |
|
| 459 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 460 | - return new \OC\L10N\Factory( |
|
| 461 | - $c->getConfig(), |
|
| 462 | - $c->getRequest(), |
|
| 463 | - $c->getUserSession(), |
|
| 464 | - \OC::$SERVERROOT |
|
| 465 | - ); |
|
| 466 | - }); |
|
| 467 | - $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 468 | - |
|
| 469 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 470 | - $config = $c->getConfig(); |
|
| 471 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 472 | - $request = $c->getRequest(); |
|
| 473 | - return new \OC\URLGenerator( |
|
| 474 | - $config, |
|
| 475 | - $cacheFactory, |
|
| 476 | - $request |
|
| 477 | - ); |
|
| 478 | - }); |
|
| 479 | - $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 480 | - |
|
| 481 | - $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 482 | - $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 483 | - |
|
| 484 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 485 | - return new Cache\File(); |
|
| 486 | - }); |
|
| 487 | - $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 488 | - |
|
| 489 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 490 | - |
|
| 491 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 492 | - ArrayCache::class, |
|
| 493 | - ArrayCache::class, |
|
| 494 | - ArrayCache::class |
|
| 495 | - ); |
|
| 496 | - $config = $c->getConfig(); |
|
| 497 | - |
|
| 498 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 499 | - $v = \OC_App::getAppVersions(); |
|
| 500 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 501 | - $version = implode(',', $v); |
|
| 502 | - $instanceId = \OC_Util::getInstanceId(); |
|
| 503 | - $path = \OC::$SERVERROOT; |
|
| 504 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 505 | - return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 506 | - $config->getSystemValue('memcache.local', null), |
|
| 507 | - $config->getSystemValue('memcache.distributed', null), |
|
| 508 | - $config->getSystemValue('memcache.locking', null) |
|
| 509 | - ); |
|
| 510 | - } |
|
| 511 | - return $arrayCacheFactory; |
|
| 512 | - |
|
| 513 | - }); |
|
| 514 | - $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 515 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 516 | - |
|
| 517 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 518 | - $systemConfig = $c->getSystemConfig(); |
|
| 519 | - return new RedisFactory($systemConfig); |
|
| 520 | - }); |
|
| 521 | - |
|
| 522 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 523 | - return new \OC\Activity\Manager( |
|
| 524 | - $c->getRequest(), |
|
| 525 | - $c->getUserSession(), |
|
| 526 | - $c->getConfig(), |
|
| 527 | - $c->query(IValidator::class) |
|
| 528 | - ); |
|
| 529 | - }); |
|
| 530 | - $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 531 | - |
|
| 532 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 533 | - return new \OC\Activity\EventMerger( |
|
| 534 | - $c->getL10N('lib') |
|
| 535 | - ); |
|
| 536 | - }); |
|
| 537 | - $this->registerAlias(IValidator::class, Validator::class); |
|
| 538 | - |
|
| 539 | - $this->registerService(AvatarManager::class, function(Server $c) { |
|
| 540 | - return new AvatarManager( |
|
| 541 | - $c->query(\OC\User\Manager::class), |
|
| 542 | - $c->getAppDataDir('avatar'), |
|
| 543 | - $c->getL10N('lib'), |
|
| 544 | - $c->getLogger(), |
|
| 545 | - $c->getConfig() |
|
| 546 | - ); |
|
| 547 | - }); |
|
| 548 | - $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
| 549 | - $this->registerAlias('AvatarManager', AvatarManager::class); |
|
| 550 | - |
|
| 551 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 552 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 553 | - |
|
| 554 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 555 | - $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 556 | - $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 557 | - $logger = $factory->get($logType); |
|
| 558 | - $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 559 | - |
|
| 560 | - return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 561 | - }); |
|
| 562 | - $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
| 563 | - $this->registerAlias('Logger', \OC\Log::class); |
|
| 564 | - |
|
| 565 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 566 | - return new LogFactory($c, $this->getSystemConfig()); |
|
| 567 | - }); |
|
| 568 | - |
|
| 569 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 570 | - $config = $c->getConfig(); |
|
| 571 | - return new \OC\BackgroundJob\JobList( |
|
| 572 | - $c->getDatabaseConnection(), |
|
| 573 | - $config, |
|
| 574 | - new TimeFactory() |
|
| 575 | - ); |
|
| 576 | - }); |
|
| 577 | - $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 578 | - |
|
| 579 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 580 | - $cacheFactory = $c->getMemCacheFactory(); |
|
| 581 | - $logger = $c->getLogger(); |
|
| 582 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 583 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 584 | - } else { |
|
| 585 | - $router = new \OC\Route\Router($logger); |
|
| 586 | - } |
|
| 587 | - return $router; |
|
| 588 | - }); |
|
| 589 | - $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 590 | - |
|
| 591 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 592 | - return new Search(); |
|
| 593 | - }); |
|
| 594 | - $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 595 | - |
|
| 596 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
| 597 | - return new \OC\Security\RateLimiting\Limiter( |
|
| 598 | - $this->getUserSession(), |
|
| 599 | - $this->getRequest(), |
|
| 600 | - new \OC\AppFramework\Utility\TimeFactory(), |
|
| 601 | - $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 602 | - ); |
|
| 603 | - }); |
|
| 604 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 605 | - return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 606 | - $this->getMemCacheFactory(), |
|
| 607 | - new \OC\AppFramework\Utility\TimeFactory() |
|
| 608 | - ); |
|
| 609 | - }); |
|
| 610 | - |
|
| 611 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 612 | - return new SecureRandom(); |
|
| 613 | - }); |
|
| 614 | - $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 615 | - |
|
| 616 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 617 | - return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 618 | - }); |
|
| 619 | - $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 620 | - |
|
| 621 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 622 | - return new Hasher($c->getConfig()); |
|
| 623 | - }); |
|
| 624 | - $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 625 | - |
|
| 626 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 627 | - return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 628 | - }); |
|
| 629 | - $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 630 | - |
|
| 631 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 632 | - $systemConfig = $c->getSystemConfig(); |
|
| 633 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 634 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 635 | - if (!$factory->isValidType($type)) { |
|
| 636 | - throw new \OC\DatabaseException('Invalid database type'); |
|
| 637 | - } |
|
| 638 | - $connectionParams = $factory->createConnectionParams(); |
|
| 639 | - $connection = $factory->getConnection($type, $connectionParams); |
|
| 640 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 641 | - return $connection; |
|
| 642 | - }); |
|
| 643 | - $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 647 | - $user = \OC_User::getUser(); |
|
| 648 | - $uid = $user ? $user : null; |
|
| 649 | - return new ClientService( |
|
| 650 | - $c->getConfig(), |
|
| 651 | - new \OC\Security\CertificateManager( |
|
| 652 | - $uid, |
|
| 653 | - new View(), |
|
| 654 | - $c->getConfig(), |
|
| 655 | - $c->getLogger(), |
|
| 656 | - $c->getSecureRandom() |
|
| 657 | - ) |
|
| 658 | - ); |
|
| 659 | - }); |
|
| 660 | - $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 661 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 662 | - $eventLogger = new EventLogger(); |
|
| 663 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 664 | - // In debug mode, module is being activated by default |
|
| 665 | - $eventLogger->activate(); |
|
| 666 | - } |
|
| 667 | - return $eventLogger; |
|
| 668 | - }); |
|
| 669 | - $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 670 | - |
|
| 671 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 672 | - $queryLogger = new QueryLogger(); |
|
| 673 | - if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 674 | - // In debug mode, module is being activated by default |
|
| 675 | - $queryLogger->activate(); |
|
| 676 | - } |
|
| 677 | - return $queryLogger; |
|
| 678 | - }); |
|
| 679 | - $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 680 | - |
|
| 681 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 682 | - return new TempManager( |
|
| 683 | - $c->getLogger(), |
|
| 684 | - $c->getConfig() |
|
| 685 | - ); |
|
| 686 | - }); |
|
| 687 | - $this->registerAlias('TempManager', TempManager::class); |
|
| 688 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 689 | - |
|
| 690 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 691 | - return new \OC\App\AppManager( |
|
| 692 | - $c->getUserSession(), |
|
| 693 | - $c->query(\OC\AppConfig::class), |
|
| 694 | - $c->getGroupManager(), |
|
| 695 | - $c->getMemCacheFactory(), |
|
| 696 | - $c->getEventDispatcher() |
|
| 697 | - ); |
|
| 698 | - }); |
|
| 699 | - $this->registerAlias('AppManager', AppManager::class); |
|
| 700 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 701 | - |
|
| 702 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 703 | - return new DateTimeZone( |
|
| 704 | - $c->getConfig(), |
|
| 705 | - $c->getSession() |
|
| 706 | - ); |
|
| 707 | - }); |
|
| 708 | - $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 709 | - |
|
| 710 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 711 | - $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 712 | - |
|
| 713 | - return new DateTimeFormatter( |
|
| 714 | - $c->getDateTimeZone()->getTimeZone(), |
|
| 715 | - $c->getL10N('lib', $language) |
|
| 716 | - ); |
|
| 717 | - }); |
|
| 718 | - $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 719 | - |
|
| 720 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 721 | - $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 722 | - $listener = new UserMountCacheListener($mountCache); |
|
| 723 | - $listener->listen($c->getUserManager()); |
|
| 724 | - return $mountCache; |
|
| 725 | - }); |
|
| 726 | - $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 727 | - |
|
| 728 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 729 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
| 730 | - $mountCache = $c->query('UserMountCache'); |
|
| 731 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 732 | - |
|
| 733 | - // builtin providers |
|
| 734 | - |
|
| 735 | - $config = $c->getConfig(); |
|
| 736 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
| 737 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 738 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 739 | - |
|
| 740 | - return $manager; |
|
| 741 | - }); |
|
| 742 | - $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 743 | - |
|
| 744 | - $this->registerService('IniWrapper', function ($c) { |
|
| 745 | - return new IniGetWrapper(); |
|
| 746 | - }); |
|
| 747 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 748 | - $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 749 | - if ($busClass) { |
|
| 750 | - list($app, $class) = explode('::', $busClass, 2); |
|
| 751 | - if ($c->getAppManager()->isInstalled($app)) { |
|
| 752 | - \OC_App::loadApp($app); |
|
| 753 | - return $c->query($class); |
|
| 754 | - } else { |
|
| 755 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 756 | - } |
|
| 757 | - } else { |
|
| 758 | - $jobList = $c->getJobList(); |
|
| 759 | - return new CronBus($jobList); |
|
| 760 | - } |
|
| 761 | - }); |
|
| 762 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 763 | - return new TrustedDomainHelper($this->getConfig()); |
|
| 764 | - }); |
|
| 765 | - $this->registerService(Throttler::class, function (Server $c) { |
|
| 766 | - return new Throttler( |
|
| 767 | - $c->getDatabaseConnection(), |
|
| 768 | - new TimeFactory(), |
|
| 769 | - $c->getLogger(), |
|
| 770 | - $c->getConfig() |
|
| 771 | - ); |
|
| 772 | - }); |
|
| 773 | - $this->registerAlias('Throttler', Throttler::class); |
|
| 774 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 775 | - // IConfig and IAppManager requires a working database. This code |
|
| 776 | - // might however be called when ownCloud is not yet setup. |
|
| 777 | - if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 778 | - $config = $c->getConfig(); |
|
| 779 | - $appManager = $c->getAppManager(); |
|
| 780 | - } else { |
|
| 781 | - $config = null; |
|
| 782 | - $appManager = null; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - return new Checker( |
|
| 786 | - new EnvironmentHelper(), |
|
| 787 | - new FileAccessHelper(), |
|
| 788 | - new AppLocator(), |
|
| 789 | - $config, |
|
| 790 | - $c->getMemCacheFactory(), |
|
| 791 | - $appManager, |
|
| 792 | - $c->getTempManager() |
|
| 793 | - ); |
|
| 794 | - }); |
|
| 795 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 796 | - if (isset($this['urlParams'])) { |
|
| 797 | - $urlParams = $this['urlParams']; |
|
| 798 | - } else { |
|
| 799 | - $urlParams = []; |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 803 | - && in_array('fakeinput', stream_get_wrappers()) |
|
| 804 | - ) { |
|
| 805 | - $stream = 'fakeinput://data'; |
|
| 806 | - } else { |
|
| 807 | - $stream = 'php://input'; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - return new Request( |
|
| 811 | - [ |
|
| 812 | - 'get' => $_GET, |
|
| 813 | - 'post' => $_POST, |
|
| 814 | - 'files' => $_FILES, |
|
| 815 | - 'server' => $_SERVER, |
|
| 816 | - 'env' => $_ENV, |
|
| 817 | - 'cookies' => $_COOKIE, |
|
| 818 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 819 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 820 | - : '', |
|
| 821 | - 'urlParams' => $urlParams, |
|
| 822 | - ], |
|
| 823 | - $this->getSecureRandom(), |
|
| 824 | - $this->getConfig(), |
|
| 825 | - $this->getCsrfTokenManager(), |
|
| 826 | - $stream |
|
| 827 | - ); |
|
| 828 | - }); |
|
| 829 | - $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 830 | - |
|
| 831 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 832 | - return new Mailer( |
|
| 833 | - $c->getConfig(), |
|
| 834 | - $c->getLogger(), |
|
| 835 | - $c->query(Defaults::class), |
|
| 836 | - $c->getURLGenerator(), |
|
| 837 | - $c->getL10N('lib') |
|
| 838 | - ); |
|
| 839 | - }); |
|
| 840 | - $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 841 | - |
|
| 842 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 843 | - $config = $c->getConfig(); |
|
| 844 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 845 | - if (is_null($factoryClass)) { |
|
| 846 | - throw new \Exception('ldapProviderFactory not set'); |
|
| 847 | - } |
|
| 848 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 849 | - $factory = new $factoryClass($this); |
|
| 850 | - return $factory->getLDAPProvider(); |
|
| 851 | - }); |
|
| 852 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 853 | - $ini = $c->getIniWrapper(); |
|
| 854 | - $config = $c->getConfig(); |
|
| 855 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 856 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 857 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 858 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 859 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
| 860 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 861 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
| 862 | - } |
|
| 863 | - return new DBLockingProvider( |
|
| 864 | - $c->getDatabaseConnection(), |
|
| 865 | - $c->getLogger(), |
|
| 866 | - new TimeFactory(), |
|
| 867 | - $ttl, |
|
| 868 | - !\OC::$CLI |
|
| 869 | - ); |
|
| 870 | - } |
|
| 871 | - return new NoopLockingProvider(); |
|
| 872 | - }); |
|
| 873 | - $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
| 874 | - |
|
| 875 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 876 | - return new \OC\Files\Mount\Manager(); |
|
| 877 | - }); |
|
| 878 | - $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 879 | - |
|
| 880 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 881 | - return new \OC\Files\Type\Detection( |
|
| 882 | - $c->getURLGenerator(), |
|
| 883 | - \OC::$configDir, |
|
| 884 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 885 | - ); |
|
| 886 | - }); |
|
| 887 | - $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 888 | - |
|
| 889 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 890 | - return new \OC\Files\Type\Loader( |
|
| 891 | - $c->getDatabaseConnection() |
|
| 892 | - ); |
|
| 893 | - }); |
|
| 894 | - $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 895 | - $this->registerService(BundleFetcher::class, function () { |
|
| 896 | - return new BundleFetcher($this->getL10N('lib')); |
|
| 897 | - }); |
|
| 898 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 899 | - return new Manager( |
|
| 900 | - $c->query(IValidator::class) |
|
| 901 | - ); |
|
| 902 | - }); |
|
| 903 | - $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 904 | - |
|
| 905 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 906 | - $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 907 | - $manager->registerCapability(function () use ($c) { |
|
| 908 | - return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 909 | - }); |
|
| 910 | - $manager->registerCapability(function () use ($c) { |
|
| 911 | - return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 912 | - }); |
|
| 913 | - return $manager; |
|
| 914 | - }); |
|
| 915 | - $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 916 | - |
|
| 917 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 918 | - $config = $c->getConfig(); |
|
| 919 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 920 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 921 | - $factory = new $factoryClass($this); |
|
| 922 | - $manager = $factory->getManager(); |
|
| 923 | - |
|
| 924 | - $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 925 | - $manager = $c->getUserManager(); |
|
| 926 | - $user = $manager->get($id); |
|
| 927 | - if(is_null($user)) { |
|
| 928 | - $l = $c->getL10N('core'); |
|
| 929 | - $displayName = $l->t('Unknown user'); |
|
| 930 | - } else { |
|
| 931 | - $displayName = $user->getDisplayName(); |
|
| 932 | - } |
|
| 933 | - return $displayName; |
|
| 934 | - }); |
|
| 935 | - |
|
| 936 | - return $manager; |
|
| 937 | - }); |
|
| 938 | - $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 939 | - |
|
| 940 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 941 | - /* |
|
| 171 | + /** @var string */ |
|
| 172 | + private $webRoot; |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param string $webRoot |
|
| 176 | + * @param \OC\Config $config |
|
| 177 | + */ |
|
| 178 | + public function __construct($webRoot, \OC\Config $config) { |
|
| 179 | + parent::__construct(); |
|
| 180 | + $this->webRoot = $webRoot; |
|
| 181 | + |
|
| 182 | + // To find out if we are running from CLI or not |
|
| 183 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
| 184 | + |
|
| 185 | + $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 186 | + return $c; |
|
| 187 | + }); |
|
| 188 | + |
|
| 189 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
| 190 | + $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
| 191 | + |
|
| 192 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
| 193 | + $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
| 194 | + |
|
| 195 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
| 196 | + $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
| 197 | + |
|
| 198 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
| 199 | + $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
| 200 | + |
|
| 201 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 205 | + return new PreviewManager( |
|
| 206 | + $c->getConfig(), |
|
| 207 | + $c->getRootFolder(), |
|
| 208 | + $c->getAppDataDir('preview'), |
|
| 209 | + $c->getEventDispatcher(), |
|
| 210 | + $c->getSession()->get('user_id') |
|
| 211 | + ); |
|
| 212 | + }); |
|
| 213 | + $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
|
| 214 | + |
|
| 215 | + $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 216 | + return new \OC\Preview\Watcher( |
|
| 217 | + $c->getAppDataDir('preview') |
|
| 218 | + ); |
|
| 219 | + }); |
|
| 220 | + |
|
| 221 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 222 | + $view = new View(); |
|
| 223 | + $util = new Encryption\Util( |
|
| 224 | + $view, |
|
| 225 | + $c->getUserManager(), |
|
| 226 | + $c->getGroupManager(), |
|
| 227 | + $c->getConfig() |
|
| 228 | + ); |
|
| 229 | + return new Encryption\Manager( |
|
| 230 | + $c->getConfig(), |
|
| 231 | + $c->getLogger(), |
|
| 232 | + $c->getL10N('core'), |
|
| 233 | + new View(), |
|
| 234 | + $util, |
|
| 235 | + new ArrayCache() |
|
| 236 | + ); |
|
| 237 | + }); |
|
| 238 | + $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
| 239 | + |
|
| 240 | + $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 241 | + $util = new Encryption\Util( |
|
| 242 | + new View(), |
|
| 243 | + $c->getUserManager(), |
|
| 244 | + $c->getGroupManager(), |
|
| 245 | + $c->getConfig() |
|
| 246 | + ); |
|
| 247 | + return new Encryption\File( |
|
| 248 | + $util, |
|
| 249 | + $c->getRootFolder(), |
|
| 250 | + $c->getShareManager() |
|
| 251 | + ); |
|
| 252 | + }); |
|
| 253 | + |
|
| 254 | + $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 255 | + $view = new View(); |
|
| 256 | + $util = new Encryption\Util( |
|
| 257 | + $view, |
|
| 258 | + $c->getUserManager(), |
|
| 259 | + $c->getGroupManager(), |
|
| 260 | + $c->getConfig() |
|
| 261 | + ); |
|
| 262 | + |
|
| 263 | + return new Encryption\Keys\Storage($view, $util); |
|
| 264 | + }); |
|
| 265 | + $this->registerService('TagMapper', function (Server $c) { |
|
| 266 | + return new TagMapper($c->getDatabaseConnection()); |
|
| 267 | + }); |
|
| 268 | + |
|
| 269 | + $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 270 | + $tagMapper = $c->query('TagMapper'); |
|
| 271 | + return new TagManager($tagMapper, $c->getUserSession()); |
|
| 272 | + }); |
|
| 273 | + $this->registerAlias('TagManager', \OCP\ITagManager::class); |
|
| 274 | + |
|
| 275 | + $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 276 | + $config = $c->getConfig(); |
|
| 277 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
| 278 | + return new $factoryClass($this); |
|
| 279 | + }); |
|
| 280 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 281 | + return $c->query('SystemTagManagerFactory')->getManager(); |
|
| 282 | + }); |
|
| 283 | + $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
|
| 284 | + |
|
| 285 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 286 | + return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
|
| 287 | + }); |
|
| 288 | + $this->registerService('RootFolder', function (Server $c) { |
|
| 289 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
| 290 | + $view = new View(); |
|
| 291 | + $root = new Root( |
|
| 292 | + $manager, |
|
| 293 | + $view, |
|
| 294 | + null, |
|
| 295 | + $c->getUserMountCache(), |
|
| 296 | + $this->getLogger(), |
|
| 297 | + $this->getUserManager() |
|
| 298 | + ); |
|
| 299 | + $connector = new HookConnector($root, $view); |
|
| 300 | + $connector->viewToNode(); |
|
| 301 | + |
|
| 302 | + $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
|
| 303 | + $previewConnector->connectWatcher(); |
|
| 304 | + |
|
| 305 | + return $root; |
|
| 306 | + }); |
|
| 307 | + $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
|
| 308 | + |
|
| 309 | + $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 310 | + return new LazyRoot(function () use ($c) { |
|
| 311 | + return $c->query('RootFolder'); |
|
| 312 | + }); |
|
| 313 | + }); |
|
| 314 | + $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
|
| 315 | + |
|
| 316 | + $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
| 317 | + return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
|
| 318 | + }); |
|
| 319 | + $this->registerAlias('UserManager', \OC\User\Manager::class); |
|
| 320 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
| 321 | + |
|
| 322 | + $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 323 | + $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
|
| 324 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 325 | + \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
|
| 326 | + }); |
|
| 327 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 328 | + \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
|
| 329 | + }); |
|
| 330 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 331 | + \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
|
| 332 | + }); |
|
| 333 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 334 | + \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
|
| 335 | + }); |
|
| 336 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 337 | + \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 338 | + }); |
|
| 339 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 340 | + \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 341 | + //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
|
| 342 | + \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
|
| 343 | + }); |
|
| 344 | + return $groupManager; |
|
| 345 | + }); |
|
| 346 | + $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
|
| 347 | + |
|
| 348 | + $this->registerService(Store::class, function (Server $c) { |
|
| 349 | + $session = $c->getSession(); |
|
| 350 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 351 | + $tokenProvider = $c->query(IProvider::class); |
|
| 352 | + } else { |
|
| 353 | + $tokenProvider = null; |
|
| 354 | + } |
|
| 355 | + $logger = $c->getLogger(); |
|
| 356 | + return new Store($session, $logger, $tokenProvider); |
|
| 357 | + }); |
|
| 358 | + $this->registerAlias(IStore::class, Store::class); |
|
| 359 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 360 | + $dbConnection = $c->getDatabaseConnection(); |
|
| 361 | + return new Authentication\Token\DefaultTokenMapper($dbConnection); |
|
| 362 | + }); |
|
| 363 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
| 364 | + |
|
| 365 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 366 | + $manager = $c->getUserManager(); |
|
| 367 | + $session = new \OC\Session\Memory(''); |
|
| 368 | + $timeFactory = new TimeFactory(); |
|
| 369 | + // Token providers might require a working database. This code |
|
| 370 | + // might however be called when ownCloud is not yet setup. |
|
| 371 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 372 | + $defaultTokenProvider = $c->query(IProvider::class); |
|
| 373 | + } else { |
|
| 374 | + $defaultTokenProvider = null; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $dispatcher = $c->getEventDispatcher(); |
|
| 378 | + |
|
| 379 | + $userSession = new \OC\User\Session( |
|
| 380 | + $manager, |
|
| 381 | + $session, |
|
| 382 | + $timeFactory, |
|
| 383 | + $defaultTokenProvider, |
|
| 384 | + $c->getConfig(), |
|
| 385 | + $c->getSecureRandom(), |
|
| 386 | + $c->getLockdownManager(), |
|
| 387 | + $c->getLogger() |
|
| 388 | + ); |
|
| 389 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 390 | + \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 391 | + }); |
|
| 392 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 393 | + /** @var $user \OC\User\User */ |
|
| 394 | + \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
|
| 395 | + }); |
|
| 396 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
| 397 | + /** @var $user \OC\User\User */ |
|
| 398 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
|
| 399 | + $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
| 400 | + }); |
|
| 401 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 402 | + /** @var $user \OC\User\User */ |
|
| 403 | + \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
|
| 404 | + }); |
|
| 405 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 406 | + /** @var $user \OC\User\User */ |
|
| 407 | + \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 408 | + }); |
|
| 409 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 410 | + /** @var $user \OC\User\User */ |
|
| 411 | + \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
|
| 412 | + }); |
|
| 413 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 414 | + \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
|
| 415 | + }); |
|
| 416 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 417 | + /** @var $user \OC\User\User */ |
|
| 418 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
|
| 419 | + }); |
|
| 420 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 421 | + /** @var $user \OC\User\User */ |
|
| 422 | + \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
|
| 423 | + }); |
|
| 424 | + $userSession->listen('\OC\User', 'logout', function () { |
|
| 425 | + \OC_Hook::emit('OC_User', 'logout', array()); |
|
| 426 | + }); |
|
| 427 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 428 | + /** @var $user \OC\User\User */ |
|
| 429 | + \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
|
| 430 | + }); |
|
| 431 | + return $userSession; |
|
| 432 | + }); |
|
| 433 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
| 434 | + $this->registerAlias('UserSession', \OC\User\Session::class); |
|
| 435 | + |
|
| 436 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
| 437 | + |
|
| 438 | + $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
|
| 439 | + $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
|
| 440 | + |
|
| 441 | + $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 442 | + return new \OC\AllConfig( |
|
| 443 | + $c->getSystemConfig() |
|
| 444 | + ); |
|
| 445 | + }); |
|
| 446 | + $this->registerAlias('AllConfig', \OC\AllConfig::class); |
|
| 447 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
| 448 | + |
|
| 449 | + $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 450 | + return new \OC\SystemConfig($config); |
|
| 451 | + }); |
|
| 452 | + |
|
| 453 | + $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 454 | + return new \OC\AppConfig($c->getDatabaseConnection()); |
|
| 455 | + }); |
|
| 456 | + $this->registerAlias('AppConfig', \OC\AppConfig::class); |
|
| 457 | + $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
|
| 458 | + |
|
| 459 | + $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 460 | + return new \OC\L10N\Factory( |
|
| 461 | + $c->getConfig(), |
|
| 462 | + $c->getRequest(), |
|
| 463 | + $c->getUserSession(), |
|
| 464 | + \OC::$SERVERROOT |
|
| 465 | + ); |
|
| 466 | + }); |
|
| 467 | + $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
|
| 468 | + |
|
| 469 | + $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 470 | + $config = $c->getConfig(); |
|
| 471 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 472 | + $request = $c->getRequest(); |
|
| 473 | + return new \OC\URLGenerator( |
|
| 474 | + $config, |
|
| 475 | + $cacheFactory, |
|
| 476 | + $request |
|
| 477 | + ); |
|
| 478 | + }); |
|
| 479 | + $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
|
| 480 | + |
|
| 481 | + $this->registerAlias('AppFetcher', AppFetcher::class); |
|
| 482 | + $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
|
| 483 | + |
|
| 484 | + $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 485 | + return new Cache\File(); |
|
| 486 | + }); |
|
| 487 | + $this->registerAlias('UserCache', \OCP\ICache::class); |
|
| 488 | + |
|
| 489 | + $this->registerService(Factory::class, function (Server $c) { |
|
| 490 | + |
|
| 491 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
|
| 492 | + ArrayCache::class, |
|
| 493 | + ArrayCache::class, |
|
| 494 | + ArrayCache::class |
|
| 495 | + ); |
|
| 496 | + $config = $c->getConfig(); |
|
| 497 | + |
|
| 498 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 499 | + $v = \OC_App::getAppVersions(); |
|
| 500 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
| 501 | + $version = implode(',', $v); |
|
| 502 | + $instanceId = \OC_Util::getInstanceId(); |
|
| 503 | + $path = \OC::$SERVERROOT; |
|
| 504 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 505 | + return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
|
| 506 | + $config->getSystemValue('memcache.local', null), |
|
| 507 | + $config->getSystemValue('memcache.distributed', null), |
|
| 508 | + $config->getSystemValue('memcache.locking', null) |
|
| 509 | + ); |
|
| 510 | + } |
|
| 511 | + return $arrayCacheFactory; |
|
| 512 | + |
|
| 513 | + }); |
|
| 514 | + $this->registerAlias('MemCacheFactory', Factory::class); |
|
| 515 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
| 516 | + |
|
| 517 | + $this->registerService('RedisFactory', function (Server $c) { |
|
| 518 | + $systemConfig = $c->getSystemConfig(); |
|
| 519 | + return new RedisFactory($systemConfig); |
|
| 520 | + }); |
|
| 521 | + |
|
| 522 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 523 | + return new \OC\Activity\Manager( |
|
| 524 | + $c->getRequest(), |
|
| 525 | + $c->getUserSession(), |
|
| 526 | + $c->getConfig(), |
|
| 527 | + $c->query(IValidator::class) |
|
| 528 | + ); |
|
| 529 | + }); |
|
| 530 | + $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
| 531 | + |
|
| 532 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 533 | + return new \OC\Activity\EventMerger( |
|
| 534 | + $c->getL10N('lib') |
|
| 535 | + ); |
|
| 536 | + }); |
|
| 537 | + $this->registerAlias(IValidator::class, Validator::class); |
|
| 538 | + |
|
| 539 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
| 540 | + return new AvatarManager( |
|
| 541 | + $c->query(\OC\User\Manager::class), |
|
| 542 | + $c->getAppDataDir('avatar'), |
|
| 543 | + $c->getL10N('lib'), |
|
| 544 | + $c->getLogger(), |
|
| 545 | + $c->getConfig() |
|
| 546 | + ); |
|
| 547 | + }); |
|
| 548 | + $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class); |
|
| 549 | + $this->registerAlias('AvatarManager', AvatarManager::class); |
|
| 550 | + |
|
| 551 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
| 552 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
| 553 | + |
|
| 554 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 555 | + $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
|
| 556 | + $factory = new LogFactory($c, $this->getSystemConfig()); |
|
| 557 | + $logger = $factory->get($logType); |
|
| 558 | + $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
|
| 559 | + |
|
| 560 | + return new Log($logger, $this->getSystemConfig(), null, $registry); |
|
| 561 | + }); |
|
| 562 | + $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
|
| 563 | + $this->registerAlias('Logger', \OC\Log::class); |
|
| 564 | + |
|
| 565 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 566 | + return new LogFactory($c, $this->getSystemConfig()); |
|
| 567 | + }); |
|
| 568 | + |
|
| 569 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 570 | + $config = $c->getConfig(); |
|
| 571 | + return new \OC\BackgroundJob\JobList( |
|
| 572 | + $c->getDatabaseConnection(), |
|
| 573 | + $config, |
|
| 574 | + new TimeFactory() |
|
| 575 | + ); |
|
| 576 | + }); |
|
| 577 | + $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
|
| 578 | + |
|
| 579 | + $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 580 | + $cacheFactory = $c->getMemCacheFactory(); |
|
| 581 | + $logger = $c->getLogger(); |
|
| 582 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
| 583 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
| 584 | + } else { |
|
| 585 | + $router = new \OC\Route\Router($logger); |
|
| 586 | + } |
|
| 587 | + return $router; |
|
| 588 | + }); |
|
| 589 | + $this->registerAlias('Router', \OCP\Route\IRouter::class); |
|
| 590 | + |
|
| 591 | + $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 592 | + return new Search(); |
|
| 593 | + }); |
|
| 594 | + $this->registerAlias('Search', \OCP\ISearch::class); |
|
| 595 | + |
|
| 596 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
| 597 | + return new \OC\Security\RateLimiting\Limiter( |
|
| 598 | + $this->getUserSession(), |
|
| 599 | + $this->getRequest(), |
|
| 600 | + new \OC\AppFramework\Utility\TimeFactory(), |
|
| 601 | + $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
|
| 602 | + ); |
|
| 603 | + }); |
|
| 604 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 605 | + return new \OC\Security\RateLimiting\Backend\MemoryCache( |
|
| 606 | + $this->getMemCacheFactory(), |
|
| 607 | + new \OC\AppFramework\Utility\TimeFactory() |
|
| 608 | + ); |
|
| 609 | + }); |
|
| 610 | + |
|
| 611 | + $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 612 | + return new SecureRandom(); |
|
| 613 | + }); |
|
| 614 | + $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
| 615 | + |
|
| 616 | + $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 617 | + return new Crypto($c->getConfig(), $c->getSecureRandom()); |
|
| 618 | + }); |
|
| 619 | + $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
|
| 620 | + |
|
| 621 | + $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 622 | + return new Hasher($c->getConfig()); |
|
| 623 | + }); |
|
| 624 | + $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
|
| 625 | + |
|
| 626 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 627 | + return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
|
| 628 | + }); |
|
| 629 | + $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
|
| 630 | + |
|
| 631 | + $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 632 | + $systemConfig = $c->getSystemConfig(); |
|
| 633 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
| 634 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
| 635 | + if (!$factory->isValidType($type)) { |
|
| 636 | + throw new \OC\DatabaseException('Invalid database type'); |
|
| 637 | + } |
|
| 638 | + $connectionParams = $factory->createConnectionParams(); |
|
| 639 | + $connection = $factory->getConnection($type, $connectionParams); |
|
| 640 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
| 641 | + return $connection; |
|
| 642 | + }); |
|
| 643 | + $this->registerAlias('DatabaseConnection', IDBConnection::class); |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 647 | + $user = \OC_User::getUser(); |
|
| 648 | + $uid = $user ? $user : null; |
|
| 649 | + return new ClientService( |
|
| 650 | + $c->getConfig(), |
|
| 651 | + new \OC\Security\CertificateManager( |
|
| 652 | + $uid, |
|
| 653 | + new View(), |
|
| 654 | + $c->getConfig(), |
|
| 655 | + $c->getLogger(), |
|
| 656 | + $c->getSecureRandom() |
|
| 657 | + ) |
|
| 658 | + ); |
|
| 659 | + }); |
|
| 660 | + $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
|
| 661 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 662 | + $eventLogger = new EventLogger(); |
|
| 663 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 664 | + // In debug mode, module is being activated by default |
|
| 665 | + $eventLogger->activate(); |
|
| 666 | + } |
|
| 667 | + return $eventLogger; |
|
| 668 | + }); |
|
| 669 | + $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
|
| 670 | + |
|
| 671 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 672 | + $queryLogger = new QueryLogger(); |
|
| 673 | + if ($c->getSystemConfig()->getValue('debug', false)) { |
|
| 674 | + // In debug mode, module is being activated by default |
|
| 675 | + $queryLogger->activate(); |
|
| 676 | + } |
|
| 677 | + return $queryLogger; |
|
| 678 | + }); |
|
| 679 | + $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
|
| 680 | + |
|
| 681 | + $this->registerService(TempManager::class, function (Server $c) { |
|
| 682 | + return new TempManager( |
|
| 683 | + $c->getLogger(), |
|
| 684 | + $c->getConfig() |
|
| 685 | + ); |
|
| 686 | + }); |
|
| 687 | + $this->registerAlias('TempManager', TempManager::class); |
|
| 688 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
| 689 | + |
|
| 690 | + $this->registerService(AppManager::class, function (Server $c) { |
|
| 691 | + return new \OC\App\AppManager( |
|
| 692 | + $c->getUserSession(), |
|
| 693 | + $c->query(\OC\AppConfig::class), |
|
| 694 | + $c->getGroupManager(), |
|
| 695 | + $c->getMemCacheFactory(), |
|
| 696 | + $c->getEventDispatcher() |
|
| 697 | + ); |
|
| 698 | + }); |
|
| 699 | + $this->registerAlias('AppManager', AppManager::class); |
|
| 700 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
| 701 | + |
|
| 702 | + $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 703 | + return new DateTimeZone( |
|
| 704 | + $c->getConfig(), |
|
| 705 | + $c->getSession() |
|
| 706 | + ); |
|
| 707 | + }); |
|
| 708 | + $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
|
| 709 | + |
|
| 710 | + $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 711 | + $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
|
| 712 | + |
|
| 713 | + return new DateTimeFormatter( |
|
| 714 | + $c->getDateTimeZone()->getTimeZone(), |
|
| 715 | + $c->getL10N('lib', $language) |
|
| 716 | + ); |
|
| 717 | + }); |
|
| 718 | + $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
|
| 719 | + |
|
| 720 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 721 | + $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
|
| 722 | + $listener = new UserMountCacheListener($mountCache); |
|
| 723 | + $listener->listen($c->getUserManager()); |
|
| 724 | + return $mountCache; |
|
| 725 | + }); |
|
| 726 | + $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
|
| 727 | + |
|
| 728 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 729 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
| 730 | + $mountCache = $c->query('UserMountCache'); |
|
| 731 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
| 732 | + |
|
| 733 | + // builtin providers |
|
| 734 | + |
|
| 735 | + $config = $c->getConfig(); |
|
| 736 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
| 737 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
| 738 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
| 739 | + |
|
| 740 | + return $manager; |
|
| 741 | + }); |
|
| 742 | + $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
|
| 743 | + |
|
| 744 | + $this->registerService('IniWrapper', function ($c) { |
|
| 745 | + return new IniGetWrapper(); |
|
| 746 | + }); |
|
| 747 | + $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 748 | + $busClass = $c->getConfig()->getSystemValue('commandbus'); |
|
| 749 | + if ($busClass) { |
|
| 750 | + list($app, $class) = explode('::', $busClass, 2); |
|
| 751 | + if ($c->getAppManager()->isInstalled($app)) { |
|
| 752 | + \OC_App::loadApp($app); |
|
| 753 | + return $c->query($class); |
|
| 754 | + } else { |
|
| 755 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
| 756 | + } |
|
| 757 | + } else { |
|
| 758 | + $jobList = $c->getJobList(); |
|
| 759 | + return new CronBus($jobList); |
|
| 760 | + } |
|
| 761 | + }); |
|
| 762 | + $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 763 | + return new TrustedDomainHelper($this->getConfig()); |
|
| 764 | + }); |
|
| 765 | + $this->registerService(Throttler::class, function (Server $c) { |
|
| 766 | + return new Throttler( |
|
| 767 | + $c->getDatabaseConnection(), |
|
| 768 | + new TimeFactory(), |
|
| 769 | + $c->getLogger(), |
|
| 770 | + $c->getConfig() |
|
| 771 | + ); |
|
| 772 | + }); |
|
| 773 | + $this->registerAlias('Throttler', Throttler::class); |
|
| 774 | + $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 775 | + // IConfig and IAppManager requires a working database. This code |
|
| 776 | + // might however be called when ownCloud is not yet setup. |
|
| 777 | + if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 778 | + $config = $c->getConfig(); |
|
| 779 | + $appManager = $c->getAppManager(); |
|
| 780 | + } else { |
|
| 781 | + $config = null; |
|
| 782 | + $appManager = null; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + return new Checker( |
|
| 786 | + new EnvironmentHelper(), |
|
| 787 | + new FileAccessHelper(), |
|
| 788 | + new AppLocator(), |
|
| 789 | + $config, |
|
| 790 | + $c->getMemCacheFactory(), |
|
| 791 | + $appManager, |
|
| 792 | + $c->getTempManager() |
|
| 793 | + ); |
|
| 794 | + }); |
|
| 795 | + $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 796 | + if (isset($this['urlParams'])) { |
|
| 797 | + $urlParams = $this['urlParams']; |
|
| 798 | + } else { |
|
| 799 | + $urlParams = []; |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
| 803 | + && in_array('fakeinput', stream_get_wrappers()) |
|
| 804 | + ) { |
|
| 805 | + $stream = 'fakeinput://data'; |
|
| 806 | + } else { |
|
| 807 | + $stream = 'php://input'; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + return new Request( |
|
| 811 | + [ |
|
| 812 | + 'get' => $_GET, |
|
| 813 | + 'post' => $_POST, |
|
| 814 | + 'files' => $_FILES, |
|
| 815 | + 'server' => $_SERVER, |
|
| 816 | + 'env' => $_ENV, |
|
| 817 | + 'cookies' => $_COOKIE, |
|
| 818 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 819 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 820 | + : '', |
|
| 821 | + 'urlParams' => $urlParams, |
|
| 822 | + ], |
|
| 823 | + $this->getSecureRandom(), |
|
| 824 | + $this->getConfig(), |
|
| 825 | + $this->getCsrfTokenManager(), |
|
| 826 | + $stream |
|
| 827 | + ); |
|
| 828 | + }); |
|
| 829 | + $this->registerAlias('Request', \OCP\IRequest::class); |
|
| 830 | + |
|
| 831 | + $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 832 | + return new Mailer( |
|
| 833 | + $c->getConfig(), |
|
| 834 | + $c->getLogger(), |
|
| 835 | + $c->query(Defaults::class), |
|
| 836 | + $c->getURLGenerator(), |
|
| 837 | + $c->getL10N('lib') |
|
| 838 | + ); |
|
| 839 | + }); |
|
| 840 | + $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
|
| 841 | + |
|
| 842 | + $this->registerService('LDAPProvider', function (Server $c) { |
|
| 843 | + $config = $c->getConfig(); |
|
| 844 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
| 845 | + if (is_null($factoryClass)) { |
|
| 846 | + throw new \Exception('ldapProviderFactory not set'); |
|
| 847 | + } |
|
| 848 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
| 849 | + $factory = new $factoryClass($this); |
|
| 850 | + return $factory->getLDAPProvider(); |
|
| 851 | + }); |
|
| 852 | + $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 853 | + $ini = $c->getIniWrapper(); |
|
| 854 | + $config = $c->getConfig(); |
|
| 855 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
| 856 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
| 857 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
| 858 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 859 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
| 860 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
| 861 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
| 862 | + } |
|
| 863 | + return new DBLockingProvider( |
|
| 864 | + $c->getDatabaseConnection(), |
|
| 865 | + $c->getLogger(), |
|
| 866 | + new TimeFactory(), |
|
| 867 | + $ttl, |
|
| 868 | + !\OC::$CLI |
|
| 869 | + ); |
|
| 870 | + } |
|
| 871 | + return new NoopLockingProvider(); |
|
| 872 | + }); |
|
| 873 | + $this->registerAlias('LockingProvider', ILockingProvider::class); |
|
| 874 | + |
|
| 875 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 876 | + return new \OC\Files\Mount\Manager(); |
|
| 877 | + }); |
|
| 878 | + $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
|
| 879 | + |
|
| 880 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 881 | + return new \OC\Files\Type\Detection( |
|
| 882 | + $c->getURLGenerator(), |
|
| 883 | + \OC::$configDir, |
|
| 884 | + \OC::$SERVERROOT . '/resources/config/' |
|
| 885 | + ); |
|
| 886 | + }); |
|
| 887 | + $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
|
| 888 | + |
|
| 889 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 890 | + return new \OC\Files\Type\Loader( |
|
| 891 | + $c->getDatabaseConnection() |
|
| 892 | + ); |
|
| 893 | + }); |
|
| 894 | + $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
|
| 895 | + $this->registerService(BundleFetcher::class, function () { |
|
| 896 | + return new BundleFetcher($this->getL10N('lib')); |
|
| 897 | + }); |
|
| 898 | + $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 899 | + return new Manager( |
|
| 900 | + $c->query(IValidator::class) |
|
| 901 | + ); |
|
| 902 | + }); |
|
| 903 | + $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
| 904 | + |
|
| 905 | + $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 906 | + $manager = new \OC\CapabilitiesManager($c->getLogger()); |
|
| 907 | + $manager->registerCapability(function () use ($c) { |
|
| 908 | + return new \OC\OCS\CoreCapabilities($c->getConfig()); |
|
| 909 | + }); |
|
| 910 | + $manager->registerCapability(function () use ($c) { |
|
| 911 | + return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
|
| 912 | + }); |
|
| 913 | + return $manager; |
|
| 914 | + }); |
|
| 915 | + $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
|
| 916 | + |
|
| 917 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 918 | + $config = $c->getConfig(); |
|
| 919 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
| 920 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
| 921 | + $factory = new $factoryClass($this); |
|
| 922 | + $manager = $factory->getManager(); |
|
| 923 | + |
|
| 924 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
| 925 | + $manager = $c->getUserManager(); |
|
| 926 | + $user = $manager->get($id); |
|
| 927 | + if(is_null($user)) { |
|
| 928 | + $l = $c->getL10N('core'); |
|
| 929 | + $displayName = $l->t('Unknown user'); |
|
| 930 | + } else { |
|
| 931 | + $displayName = $user->getDisplayName(); |
|
| 932 | + } |
|
| 933 | + return $displayName; |
|
| 934 | + }); |
|
| 935 | + |
|
| 936 | + return $manager; |
|
| 937 | + }); |
|
| 938 | + $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
|
| 939 | + |
|
| 940 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 941 | + /* |
|
| 942 | 942 | * Dark magic for autoloader. |
| 943 | 943 | * If we do a class_exists it will try to load the class which will |
| 944 | 944 | * make composer cache the result. Resulting in errors when enabling |
| 945 | 945 | * the theming app. |
| 946 | 946 | */ |
| 947 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 948 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 949 | - $classExists = true; |
|
| 950 | - } else { |
|
| 951 | - $classExists = false; |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 955 | - return new ThemingDefaults( |
|
| 956 | - $c->getConfig(), |
|
| 957 | - $c->getL10N('theming'), |
|
| 958 | - $c->getURLGenerator(), |
|
| 959 | - $c->getMemCacheFactory(), |
|
| 960 | - new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 961 | - new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
| 962 | - $c->getAppManager(), |
|
| 963 | - $c->getNavigationManager() |
|
| 964 | - ); |
|
| 965 | - } |
|
| 966 | - return new \OC_Defaults(); |
|
| 967 | - }); |
|
| 968 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 969 | - return new SCSSCacher( |
|
| 970 | - $c->getLogger(), |
|
| 971 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 972 | - $c->getURLGenerator(), |
|
| 973 | - $c->getConfig(), |
|
| 974 | - $c->getThemingDefaults(), |
|
| 975 | - \OC::$SERVERROOT, |
|
| 976 | - $this->getMemCacheFactory(), |
|
| 977 | - $c->query(IconsCacher::class), |
|
| 978 | - new TimeFactory() |
|
| 979 | - ); |
|
| 980 | - }); |
|
| 981 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 982 | - return new JSCombiner( |
|
| 983 | - $c->getAppDataDir('js'), |
|
| 984 | - $c->getURLGenerator(), |
|
| 985 | - $this->getMemCacheFactory(), |
|
| 986 | - $c->getSystemConfig(), |
|
| 987 | - $c->getLogger() |
|
| 988 | - ); |
|
| 989 | - }); |
|
| 990 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 991 | - $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 992 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 993 | - |
|
| 994 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 995 | - // FIXME: Instantiiated here due to cyclic dependency |
|
| 996 | - $request = new Request( |
|
| 997 | - [ |
|
| 998 | - 'get' => $_GET, |
|
| 999 | - 'post' => $_POST, |
|
| 1000 | - 'files' => $_FILES, |
|
| 1001 | - 'server' => $_SERVER, |
|
| 1002 | - 'env' => $_ENV, |
|
| 1003 | - 'cookies' => $_COOKIE, |
|
| 1004 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1005 | - ? $_SERVER['REQUEST_METHOD'] |
|
| 1006 | - : null, |
|
| 1007 | - ], |
|
| 1008 | - $c->getSecureRandom(), |
|
| 1009 | - $c->getConfig() |
|
| 1010 | - ); |
|
| 1011 | - |
|
| 1012 | - return new CryptoWrapper( |
|
| 1013 | - $c->getConfig(), |
|
| 1014 | - $c->getCrypto(), |
|
| 1015 | - $c->getSecureRandom(), |
|
| 1016 | - $request |
|
| 1017 | - ); |
|
| 1018 | - }); |
|
| 1019 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 1020 | - $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 1021 | - |
|
| 1022 | - return new CsrfTokenManager( |
|
| 1023 | - $tokenGenerator, |
|
| 1024 | - $c->query(SessionStorage::class) |
|
| 1025 | - ); |
|
| 1026 | - }); |
|
| 1027 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1028 | - return new SessionStorage($c->getSession()); |
|
| 1029 | - }); |
|
| 1030 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 1031 | - return new ContentSecurityPolicyManager(); |
|
| 1032 | - }); |
|
| 1033 | - $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 1034 | - |
|
| 1035 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1036 | - return new ContentSecurityPolicyNonceManager( |
|
| 1037 | - $c->getCsrfTokenManager(), |
|
| 1038 | - $c->getRequest() |
|
| 1039 | - ); |
|
| 1040 | - }); |
|
| 1041 | - |
|
| 1042 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1043 | - $config = $c->getConfig(); |
|
| 1044 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1045 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1046 | - $factory = new $factoryClass($this); |
|
| 1047 | - |
|
| 1048 | - $manager = new \OC\Share20\Manager( |
|
| 1049 | - $c->getLogger(), |
|
| 1050 | - $c->getConfig(), |
|
| 1051 | - $c->getSecureRandom(), |
|
| 1052 | - $c->getHasher(), |
|
| 1053 | - $c->getMountManager(), |
|
| 1054 | - $c->getGroupManager(), |
|
| 1055 | - $c->getL10N('lib'), |
|
| 1056 | - $c->getL10NFactory(), |
|
| 1057 | - $factory, |
|
| 1058 | - $c->getUserManager(), |
|
| 1059 | - $c->getLazyRootFolder(), |
|
| 1060 | - $c->getEventDispatcher(), |
|
| 1061 | - $c->getMailer(), |
|
| 1062 | - $c->getURLGenerator(), |
|
| 1063 | - $c->getThemingDefaults() |
|
| 1064 | - ); |
|
| 1065 | - |
|
| 1066 | - return $manager; |
|
| 1067 | - }); |
|
| 1068 | - $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1069 | - |
|
| 1070 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1071 | - $instance = new Collaboration\Collaborators\Search($c); |
|
| 1072 | - |
|
| 1073 | - // register default plugins |
|
| 1074 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1075 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1076 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1077 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1078 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1079 | - |
|
| 1080 | - return $instance; |
|
| 1081 | - }); |
|
| 1082 | - $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1083 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1084 | - |
|
| 1085 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1086 | - |
|
| 1087 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1088 | - |
|
| 1089 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1090 | - $manager = new \OC\Settings\Manager( |
|
| 1091 | - $c->getLogger(), |
|
| 1092 | - $c->getL10NFactory(), |
|
| 1093 | - $c->getURLGenerator(), |
|
| 1094 | - $c |
|
| 1095 | - ); |
|
| 1096 | - return $manager; |
|
| 1097 | - }); |
|
| 1098 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1099 | - return new \OC\Files\AppData\Factory( |
|
| 1100 | - $c->getRootFolder(), |
|
| 1101 | - $c->getSystemConfig() |
|
| 1102 | - ); |
|
| 1103 | - }); |
|
| 1104 | - |
|
| 1105 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1106 | - return new LockdownManager(function () use ($c) { |
|
| 1107 | - return $c->getSession(); |
|
| 1108 | - }); |
|
| 1109 | - }); |
|
| 1110 | - |
|
| 1111 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1112 | - return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1113 | - }); |
|
| 1114 | - |
|
| 1115 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1116 | - return new CloudIdManager(); |
|
| 1117 | - }); |
|
| 1118 | - |
|
| 1119 | - $this->registerService(IConfig::class, function (Server $c) { |
|
| 1120 | - return new GlobalScale\Config($c->getConfig()); |
|
| 1121 | - }); |
|
| 1122 | - |
|
| 1123 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1124 | - return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
| 1125 | - }); |
|
| 1126 | - |
|
| 1127 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1128 | - return new CloudFederationFactory(); |
|
| 1129 | - }); |
|
| 1130 | - |
|
| 1131 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1132 | - $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1133 | - |
|
| 1134 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1135 | - $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1136 | - |
|
| 1137 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1138 | - return new Defaults( |
|
| 1139 | - $c->getThemingDefaults() |
|
| 1140 | - ); |
|
| 1141 | - }); |
|
| 1142 | - $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1143 | - |
|
| 1144 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1145 | - return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1146 | - }); |
|
| 1147 | - |
|
| 1148 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1149 | - return new ShareHelper( |
|
| 1150 | - $c->query(\OCP\Share\IManager::class) |
|
| 1151 | - ); |
|
| 1152 | - }); |
|
| 1153 | - |
|
| 1154 | - $this->registerService(Installer::class, function(Server $c) { |
|
| 1155 | - return new Installer( |
|
| 1156 | - $c->getAppFetcher(), |
|
| 1157 | - $c->getHTTPClientService(), |
|
| 1158 | - $c->getTempManager(), |
|
| 1159 | - $c->getLogger(), |
|
| 1160 | - $c->getConfig() |
|
| 1161 | - ); |
|
| 1162 | - }); |
|
| 1163 | - |
|
| 1164 | - $this->registerService(IApiFactory::class, function(Server $c) { |
|
| 1165 | - return new ApiFactory($c->getHTTPClientService()); |
|
| 1166 | - }); |
|
| 1167 | - |
|
| 1168 | - $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
| 1169 | - $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1170 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1171 | - }); |
|
| 1172 | - |
|
| 1173 | - $this->registerService(IContactsStore::class, function(Server $c) { |
|
| 1174 | - return new ContactsStore( |
|
| 1175 | - $c->getContactsManager(), |
|
| 1176 | - $c->getConfig(), |
|
| 1177 | - $c->getUserManager(), |
|
| 1178 | - $c->getGroupManager() |
|
| 1179 | - ); |
|
| 1180 | - }); |
|
| 1181 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1182 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1183 | - |
|
| 1184 | - $this->registerService(IStorageFactory::class, function() { |
|
| 1185 | - return new StorageFactory(); |
|
| 1186 | - }); |
|
| 1187 | - |
|
| 1188 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1189 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1190 | - |
|
| 1191 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
| 1192 | - return new \OC\Security\IdentityProof\Manager( |
|
| 1193 | - $c->query(\OC\Files\AppData\Factory::class), |
|
| 1194 | - $c->getCrypto(), |
|
| 1195 | - $c->getConfig() |
|
| 1196 | - ); |
|
| 1197 | - }); |
|
| 1198 | - |
|
| 1199 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1200 | - |
|
| 1201 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1202 | - |
|
| 1203 | - $this->connectDispatcher(); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - /** |
|
| 1207 | - * @return \OCP\Calendar\IManager |
|
| 1208 | - */ |
|
| 1209 | - public function getCalendarManager() { |
|
| 1210 | - return $this->query('CalendarManager'); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - /** |
|
| 1214 | - * @return \OCP\Calendar\Resource\IManager |
|
| 1215 | - */ |
|
| 1216 | - public function getCalendarResourceBackendManager() { |
|
| 1217 | - return $this->query('CalendarResourceBackendManager'); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - /** |
|
| 1221 | - * @return \OCP\Calendar\Room\IManager |
|
| 1222 | - */ |
|
| 1223 | - public function getCalendarRoomBackendManager() { |
|
| 1224 | - return $this->query('CalendarRoomBackendManager'); |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - private function connectDispatcher() { |
|
| 1228 | - $dispatcher = $this->getEventDispatcher(); |
|
| 1229 | - |
|
| 1230 | - // Delete avatar on user deletion |
|
| 1231 | - $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
| 1232 | - $logger = $this->getLogger(); |
|
| 1233 | - $manager = $this->getAvatarManager(); |
|
| 1234 | - /** @var IUser $user */ |
|
| 1235 | - $user = $e->getSubject(); |
|
| 1236 | - |
|
| 1237 | - try { |
|
| 1238 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1239 | - $avatar->remove(); |
|
| 1240 | - } catch (NotFoundException $e) { |
|
| 1241 | - // no avatar to remove |
|
| 1242 | - } catch (\Exception $e) { |
|
| 1243 | - // Ignore exceptions |
|
| 1244 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1245 | - } |
|
| 1246 | - }); |
|
| 1247 | - |
|
| 1248 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1249 | - $manager = $this->getAvatarManager(); |
|
| 1250 | - /** @var IUser $user */ |
|
| 1251 | - $user = $e->getSubject(); |
|
| 1252 | - $feature = $e->getArgument('feature'); |
|
| 1253 | - $oldValue = $e->getArgument('oldValue'); |
|
| 1254 | - $value = $e->getArgument('value'); |
|
| 1255 | - |
|
| 1256 | - // We only change the avatar on display name changes |
|
| 1257 | - if ($feature !== 'displayName') { |
|
| 1258 | - return; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - try { |
|
| 1262 | - $avatar = $manager->getAvatar($user->getUID()); |
|
| 1263 | - $avatar->userChanged($feature, $oldValue, $value); |
|
| 1264 | - } catch (NotFoundException $e) { |
|
| 1265 | - // no avatar to remove |
|
| 1266 | - } |
|
| 1267 | - }); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - /** |
|
| 1271 | - * @return \OCP\Contacts\IManager |
|
| 1272 | - */ |
|
| 1273 | - public function getContactsManager() { |
|
| 1274 | - return $this->query('ContactsManager'); |
|
| 1275 | - } |
|
| 1276 | - |
|
| 1277 | - /** |
|
| 1278 | - * @return \OC\Encryption\Manager |
|
| 1279 | - */ |
|
| 1280 | - public function getEncryptionManager() { |
|
| 1281 | - return $this->query('EncryptionManager'); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - /** |
|
| 1285 | - * @return \OC\Encryption\File |
|
| 1286 | - */ |
|
| 1287 | - public function getEncryptionFilesHelper() { |
|
| 1288 | - return $this->query('EncryptionFileHelper'); |
|
| 1289 | - } |
|
| 1290 | - |
|
| 1291 | - /** |
|
| 1292 | - * @return \OCP\Encryption\Keys\IStorage |
|
| 1293 | - */ |
|
| 1294 | - public function getEncryptionKeyStorage() { |
|
| 1295 | - return $this->query('EncryptionKeyStorage'); |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - /** |
|
| 1299 | - * The current request object holding all information about the request |
|
| 1300 | - * currently being processed is returned from this method. |
|
| 1301 | - * In case the current execution was not initiated by a web request null is returned |
|
| 1302 | - * |
|
| 1303 | - * @return \OCP\IRequest |
|
| 1304 | - */ |
|
| 1305 | - public function getRequest() { |
|
| 1306 | - return $this->query('Request'); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * Returns the preview manager which can create preview images for a given file |
|
| 1311 | - * |
|
| 1312 | - * @return \OCP\IPreview |
|
| 1313 | - */ |
|
| 1314 | - public function getPreviewManager() { |
|
| 1315 | - return $this->query('PreviewManager'); |
|
| 1316 | - } |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * Returns the tag manager which can get and set tags for different object types |
|
| 1320 | - * |
|
| 1321 | - * @see \OCP\ITagManager::load() |
|
| 1322 | - * @return \OCP\ITagManager |
|
| 1323 | - */ |
|
| 1324 | - public function getTagManager() { |
|
| 1325 | - return $this->query('TagManager'); |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - /** |
|
| 1329 | - * Returns the system-tag manager |
|
| 1330 | - * |
|
| 1331 | - * @return \OCP\SystemTag\ISystemTagManager |
|
| 1332 | - * |
|
| 1333 | - * @since 9.0.0 |
|
| 1334 | - */ |
|
| 1335 | - public function getSystemTagManager() { |
|
| 1336 | - return $this->query('SystemTagManager'); |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - /** |
|
| 1340 | - * Returns the system-tag object mapper |
|
| 1341 | - * |
|
| 1342 | - * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1343 | - * |
|
| 1344 | - * @since 9.0.0 |
|
| 1345 | - */ |
|
| 1346 | - public function getSystemTagObjectMapper() { |
|
| 1347 | - return $this->query('SystemTagObjectMapper'); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - /** |
|
| 1351 | - * Returns the avatar manager, used for avatar functionality |
|
| 1352 | - * |
|
| 1353 | - * @return \OCP\IAvatarManager |
|
| 1354 | - */ |
|
| 1355 | - public function getAvatarManager() { |
|
| 1356 | - return $this->query('AvatarManager'); |
|
| 1357 | - } |
|
| 1358 | - |
|
| 1359 | - /** |
|
| 1360 | - * Returns the root folder of ownCloud's data directory |
|
| 1361 | - * |
|
| 1362 | - * @return \OCP\Files\IRootFolder |
|
| 1363 | - */ |
|
| 1364 | - public function getRootFolder() { |
|
| 1365 | - return $this->query('LazyRootFolder'); |
|
| 1366 | - } |
|
| 1367 | - |
|
| 1368 | - /** |
|
| 1369 | - * Returns the root folder of ownCloud's data directory |
|
| 1370 | - * This is the lazy variant so this gets only initialized once it |
|
| 1371 | - * is actually used. |
|
| 1372 | - * |
|
| 1373 | - * @return \OCP\Files\IRootFolder |
|
| 1374 | - */ |
|
| 1375 | - public function getLazyRootFolder() { |
|
| 1376 | - return $this->query('LazyRootFolder'); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - /** |
|
| 1380 | - * Returns a view to ownCloud's files folder |
|
| 1381 | - * |
|
| 1382 | - * @param string $userId user ID |
|
| 1383 | - * @return \OCP\Files\Folder|null |
|
| 1384 | - */ |
|
| 1385 | - public function getUserFolder($userId = null) { |
|
| 1386 | - if ($userId === null) { |
|
| 1387 | - $user = $this->getUserSession()->getUser(); |
|
| 1388 | - if (!$user) { |
|
| 1389 | - return null; |
|
| 1390 | - } |
|
| 1391 | - $userId = $user->getUID(); |
|
| 1392 | - } |
|
| 1393 | - $root = $this->getRootFolder(); |
|
| 1394 | - return $root->getUserFolder($userId); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - /** |
|
| 1398 | - * Returns an app-specific view in ownClouds data directory |
|
| 1399 | - * |
|
| 1400 | - * @return \OCP\Files\Folder |
|
| 1401 | - * @deprecated since 9.2.0 use IAppData |
|
| 1402 | - */ |
|
| 1403 | - public function getAppFolder() { |
|
| 1404 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1405 | - $root = $this->getRootFolder(); |
|
| 1406 | - if (!$root->nodeExists($dir)) { |
|
| 1407 | - $folder = $root->newFolder($dir); |
|
| 1408 | - } else { |
|
| 1409 | - $folder = $root->get($dir); |
|
| 1410 | - } |
|
| 1411 | - return $folder; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - /** |
|
| 1415 | - * @return \OC\User\Manager |
|
| 1416 | - */ |
|
| 1417 | - public function getUserManager() { |
|
| 1418 | - return $this->query('UserManager'); |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * @return \OC\Group\Manager |
|
| 1423 | - */ |
|
| 1424 | - public function getGroupManager() { |
|
| 1425 | - return $this->query('GroupManager'); |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - /** |
|
| 1429 | - * @return \OC\User\Session |
|
| 1430 | - */ |
|
| 1431 | - public function getUserSession() { |
|
| 1432 | - return $this->query('UserSession'); |
|
| 1433 | - } |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * @return \OCP\ISession |
|
| 1437 | - */ |
|
| 1438 | - public function getSession() { |
|
| 1439 | - return $this->query('UserSession')->getSession(); |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * @param \OCP\ISession $session |
|
| 1444 | - */ |
|
| 1445 | - public function setSession(\OCP\ISession $session) { |
|
| 1446 | - $this->query(SessionStorage::class)->setSession($session); |
|
| 1447 | - $this->query('UserSession')->setSession($session); |
|
| 1448 | - $this->query(Store::class)->setSession($session); |
|
| 1449 | - } |
|
| 1450 | - |
|
| 1451 | - /** |
|
| 1452 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1453 | - */ |
|
| 1454 | - public function getTwoFactorAuthManager() { |
|
| 1455 | - return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1456 | - } |
|
| 1457 | - |
|
| 1458 | - /** |
|
| 1459 | - * @return \OC\NavigationManager |
|
| 1460 | - */ |
|
| 1461 | - public function getNavigationManager() { |
|
| 1462 | - return $this->query('NavigationManager'); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - /** |
|
| 1466 | - * @return \OCP\IConfig |
|
| 1467 | - */ |
|
| 1468 | - public function getConfig() { |
|
| 1469 | - return $this->query('AllConfig'); |
|
| 1470 | - } |
|
| 1471 | - |
|
| 1472 | - /** |
|
| 1473 | - * @return \OC\SystemConfig |
|
| 1474 | - */ |
|
| 1475 | - public function getSystemConfig() { |
|
| 1476 | - return $this->query('SystemConfig'); |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - /** |
|
| 1480 | - * Returns the app config manager |
|
| 1481 | - * |
|
| 1482 | - * @return \OCP\IAppConfig |
|
| 1483 | - */ |
|
| 1484 | - public function getAppConfig() { |
|
| 1485 | - return $this->query('AppConfig'); |
|
| 1486 | - } |
|
| 1487 | - |
|
| 1488 | - /** |
|
| 1489 | - * @return \OCP\L10N\IFactory |
|
| 1490 | - */ |
|
| 1491 | - public function getL10NFactory() { |
|
| 1492 | - return $this->query('L10NFactory'); |
|
| 1493 | - } |
|
| 1494 | - |
|
| 1495 | - /** |
|
| 1496 | - * get an L10N instance |
|
| 1497 | - * |
|
| 1498 | - * @param string $app appid |
|
| 1499 | - * @param string $lang |
|
| 1500 | - * @return IL10N |
|
| 1501 | - */ |
|
| 1502 | - public function getL10N($app, $lang = null) { |
|
| 1503 | - return $this->getL10NFactory()->get($app, $lang); |
|
| 1504 | - } |
|
| 1505 | - |
|
| 1506 | - /** |
|
| 1507 | - * @return \OCP\IURLGenerator |
|
| 1508 | - */ |
|
| 1509 | - public function getURLGenerator() { |
|
| 1510 | - return $this->query('URLGenerator'); |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - /** |
|
| 1514 | - * @return AppFetcher |
|
| 1515 | - */ |
|
| 1516 | - public function getAppFetcher() { |
|
| 1517 | - return $this->query(AppFetcher::class); |
|
| 1518 | - } |
|
| 1519 | - |
|
| 1520 | - /** |
|
| 1521 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1522 | - * getMemCacheFactory() instead. |
|
| 1523 | - * |
|
| 1524 | - * @return \OCP\ICache |
|
| 1525 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1526 | - */ |
|
| 1527 | - public function getCache() { |
|
| 1528 | - return $this->query('UserCache'); |
|
| 1529 | - } |
|
| 1530 | - |
|
| 1531 | - /** |
|
| 1532 | - * Returns an \OCP\CacheFactory instance |
|
| 1533 | - * |
|
| 1534 | - * @return \OCP\ICacheFactory |
|
| 1535 | - */ |
|
| 1536 | - public function getMemCacheFactory() { |
|
| 1537 | - return $this->query('MemCacheFactory'); |
|
| 1538 | - } |
|
| 1539 | - |
|
| 1540 | - /** |
|
| 1541 | - * Returns an \OC\RedisFactory instance |
|
| 1542 | - * |
|
| 1543 | - * @return \OC\RedisFactory |
|
| 1544 | - */ |
|
| 1545 | - public function getGetRedisFactory() { |
|
| 1546 | - return $this->query('RedisFactory'); |
|
| 1547 | - } |
|
| 1548 | - |
|
| 1549 | - |
|
| 1550 | - /** |
|
| 1551 | - * Returns the current session |
|
| 1552 | - * |
|
| 1553 | - * @return \OCP\IDBConnection |
|
| 1554 | - */ |
|
| 1555 | - public function getDatabaseConnection() { |
|
| 1556 | - return $this->query('DatabaseConnection'); |
|
| 1557 | - } |
|
| 1558 | - |
|
| 1559 | - /** |
|
| 1560 | - * Returns the activity manager |
|
| 1561 | - * |
|
| 1562 | - * @return \OCP\Activity\IManager |
|
| 1563 | - */ |
|
| 1564 | - public function getActivityManager() { |
|
| 1565 | - return $this->query('ActivityManager'); |
|
| 1566 | - } |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * Returns an job list for controlling background jobs |
|
| 1570 | - * |
|
| 1571 | - * @return \OCP\BackgroundJob\IJobList |
|
| 1572 | - */ |
|
| 1573 | - public function getJobList() { |
|
| 1574 | - return $this->query('JobList'); |
|
| 1575 | - } |
|
| 1576 | - |
|
| 1577 | - /** |
|
| 1578 | - * Returns a logger instance |
|
| 1579 | - * |
|
| 1580 | - * @return \OCP\ILogger |
|
| 1581 | - */ |
|
| 1582 | - public function getLogger() { |
|
| 1583 | - return $this->query('Logger'); |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - /** |
|
| 1587 | - * @return ILogFactory |
|
| 1588 | - * @throws \OCP\AppFramework\QueryException |
|
| 1589 | - */ |
|
| 1590 | - public function getLogFactory() { |
|
| 1591 | - return $this->query(ILogFactory::class); |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - /** |
|
| 1595 | - * Returns a router for generating and matching urls |
|
| 1596 | - * |
|
| 1597 | - * @return \OCP\Route\IRouter |
|
| 1598 | - */ |
|
| 1599 | - public function getRouter() { |
|
| 1600 | - return $this->query('Router'); |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - /** |
|
| 1604 | - * Returns a search instance |
|
| 1605 | - * |
|
| 1606 | - * @return \OCP\ISearch |
|
| 1607 | - */ |
|
| 1608 | - public function getSearch() { |
|
| 1609 | - return $this->query('Search'); |
|
| 1610 | - } |
|
| 1611 | - |
|
| 1612 | - /** |
|
| 1613 | - * Returns a SecureRandom instance |
|
| 1614 | - * |
|
| 1615 | - * @return \OCP\Security\ISecureRandom |
|
| 1616 | - */ |
|
| 1617 | - public function getSecureRandom() { |
|
| 1618 | - return $this->query('SecureRandom'); |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - /** |
|
| 1622 | - * Returns a Crypto instance |
|
| 1623 | - * |
|
| 1624 | - * @return \OCP\Security\ICrypto |
|
| 1625 | - */ |
|
| 1626 | - public function getCrypto() { |
|
| 1627 | - return $this->query('Crypto'); |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - /** |
|
| 1631 | - * Returns a Hasher instance |
|
| 1632 | - * |
|
| 1633 | - * @return \OCP\Security\IHasher |
|
| 1634 | - */ |
|
| 1635 | - public function getHasher() { |
|
| 1636 | - return $this->query('Hasher'); |
|
| 1637 | - } |
|
| 1638 | - |
|
| 1639 | - /** |
|
| 1640 | - * Returns a CredentialsManager instance |
|
| 1641 | - * |
|
| 1642 | - * @return \OCP\Security\ICredentialsManager |
|
| 1643 | - */ |
|
| 1644 | - public function getCredentialsManager() { |
|
| 1645 | - return $this->query('CredentialsManager'); |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * Get the certificate manager for the user |
|
| 1650 | - * |
|
| 1651 | - * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1652 | - * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1653 | - */ |
|
| 1654 | - public function getCertificateManager($userId = '') { |
|
| 1655 | - if ($userId === '') { |
|
| 1656 | - $userSession = $this->getUserSession(); |
|
| 1657 | - $user = $userSession->getUser(); |
|
| 1658 | - if (is_null($user)) { |
|
| 1659 | - return null; |
|
| 1660 | - } |
|
| 1661 | - $userId = $user->getUID(); |
|
| 1662 | - } |
|
| 1663 | - return new CertificateManager( |
|
| 1664 | - $userId, |
|
| 1665 | - new View(), |
|
| 1666 | - $this->getConfig(), |
|
| 1667 | - $this->getLogger(), |
|
| 1668 | - $this->getSecureRandom() |
|
| 1669 | - ); |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - /** |
|
| 1673 | - * Returns an instance of the HTTP client service |
|
| 1674 | - * |
|
| 1675 | - * @return \OCP\Http\Client\IClientService |
|
| 1676 | - */ |
|
| 1677 | - public function getHTTPClientService() { |
|
| 1678 | - return $this->query('HttpClientService'); |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - /** |
|
| 1682 | - * Create a new event source |
|
| 1683 | - * |
|
| 1684 | - * @return \OCP\IEventSource |
|
| 1685 | - */ |
|
| 1686 | - public function createEventSource() { |
|
| 1687 | - return new \OC_EventSource(); |
|
| 1688 | - } |
|
| 1689 | - |
|
| 1690 | - /** |
|
| 1691 | - * Get the active event logger |
|
| 1692 | - * |
|
| 1693 | - * The returned logger only logs data when debug mode is enabled |
|
| 1694 | - * |
|
| 1695 | - * @return \OCP\Diagnostics\IEventLogger |
|
| 1696 | - */ |
|
| 1697 | - public function getEventLogger() { |
|
| 1698 | - return $this->query('EventLogger'); |
|
| 1699 | - } |
|
| 1700 | - |
|
| 1701 | - /** |
|
| 1702 | - * Get the active query logger |
|
| 1703 | - * |
|
| 1704 | - * The returned logger only logs data when debug mode is enabled |
|
| 1705 | - * |
|
| 1706 | - * @return \OCP\Diagnostics\IQueryLogger |
|
| 1707 | - */ |
|
| 1708 | - public function getQueryLogger() { |
|
| 1709 | - return $this->query('QueryLogger'); |
|
| 1710 | - } |
|
| 1711 | - |
|
| 1712 | - /** |
|
| 1713 | - * Get the manager for temporary files and folders |
|
| 1714 | - * |
|
| 1715 | - * @return \OCP\ITempManager |
|
| 1716 | - */ |
|
| 1717 | - public function getTempManager() { |
|
| 1718 | - return $this->query('TempManager'); |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - /** |
|
| 1722 | - * Get the app manager |
|
| 1723 | - * |
|
| 1724 | - * @return \OCP\App\IAppManager |
|
| 1725 | - */ |
|
| 1726 | - public function getAppManager() { |
|
| 1727 | - return $this->query('AppManager'); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - /** |
|
| 1731 | - * Creates a new mailer |
|
| 1732 | - * |
|
| 1733 | - * @return \OCP\Mail\IMailer |
|
| 1734 | - */ |
|
| 1735 | - public function getMailer() { |
|
| 1736 | - return $this->query('Mailer'); |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - /** |
|
| 1740 | - * Get the webroot |
|
| 1741 | - * |
|
| 1742 | - * @return string |
|
| 1743 | - */ |
|
| 1744 | - public function getWebRoot() { |
|
| 1745 | - return $this->webRoot; |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - /** |
|
| 1749 | - * @return \OC\OCSClient |
|
| 1750 | - */ |
|
| 1751 | - public function getOcsClient() { |
|
| 1752 | - return $this->query('OcsClient'); |
|
| 1753 | - } |
|
| 1754 | - |
|
| 1755 | - /** |
|
| 1756 | - * @return \OCP\IDateTimeZone |
|
| 1757 | - */ |
|
| 1758 | - public function getDateTimeZone() { |
|
| 1759 | - return $this->query('DateTimeZone'); |
|
| 1760 | - } |
|
| 1761 | - |
|
| 1762 | - /** |
|
| 1763 | - * @return \OCP\IDateTimeFormatter |
|
| 1764 | - */ |
|
| 1765 | - public function getDateTimeFormatter() { |
|
| 1766 | - return $this->query('DateTimeFormatter'); |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1771 | - */ |
|
| 1772 | - public function getMountProviderCollection() { |
|
| 1773 | - return $this->query('MountConfigManager'); |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - /** |
|
| 1777 | - * Get the IniWrapper |
|
| 1778 | - * |
|
| 1779 | - * @return IniGetWrapper |
|
| 1780 | - */ |
|
| 1781 | - public function getIniWrapper() { |
|
| 1782 | - return $this->query('IniWrapper'); |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - /** |
|
| 1786 | - * @return \OCP\Command\IBus |
|
| 1787 | - */ |
|
| 1788 | - public function getCommandBus() { |
|
| 1789 | - return $this->query('AsyncCommandBus'); |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - /** |
|
| 1793 | - * Get the trusted domain helper |
|
| 1794 | - * |
|
| 1795 | - * @return TrustedDomainHelper |
|
| 1796 | - */ |
|
| 1797 | - public function getTrustedDomainHelper() { |
|
| 1798 | - return $this->query('TrustedDomainHelper'); |
|
| 1799 | - } |
|
| 1800 | - |
|
| 1801 | - /** |
|
| 1802 | - * Get the locking provider |
|
| 1803 | - * |
|
| 1804 | - * @return \OCP\Lock\ILockingProvider |
|
| 1805 | - * @since 8.1.0 |
|
| 1806 | - */ |
|
| 1807 | - public function getLockingProvider() { |
|
| 1808 | - return $this->query('LockingProvider'); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - /** |
|
| 1812 | - * @return \OCP\Files\Mount\IMountManager |
|
| 1813 | - **/ |
|
| 1814 | - function getMountManager() { |
|
| 1815 | - return $this->query('MountManager'); |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1819 | - function getUserMountCache() { |
|
| 1820 | - return $this->query('UserMountCache'); |
|
| 1821 | - } |
|
| 1822 | - |
|
| 1823 | - /** |
|
| 1824 | - * Get the MimeTypeDetector |
|
| 1825 | - * |
|
| 1826 | - * @return \OCP\Files\IMimeTypeDetector |
|
| 1827 | - */ |
|
| 1828 | - public function getMimeTypeDetector() { |
|
| 1829 | - return $this->query('MimeTypeDetector'); |
|
| 1830 | - } |
|
| 1831 | - |
|
| 1832 | - /** |
|
| 1833 | - * Get the MimeTypeLoader |
|
| 1834 | - * |
|
| 1835 | - * @return \OCP\Files\IMimeTypeLoader |
|
| 1836 | - */ |
|
| 1837 | - public function getMimeTypeLoader() { |
|
| 1838 | - return $this->query('MimeTypeLoader'); |
|
| 1839 | - } |
|
| 1840 | - |
|
| 1841 | - /** |
|
| 1842 | - * Get the manager of all the capabilities |
|
| 1843 | - * |
|
| 1844 | - * @return \OC\CapabilitiesManager |
|
| 1845 | - */ |
|
| 1846 | - public function getCapabilitiesManager() { |
|
| 1847 | - return $this->query('CapabilitiesManager'); |
|
| 1848 | - } |
|
| 1849 | - |
|
| 1850 | - /** |
|
| 1851 | - * Get the EventDispatcher |
|
| 1852 | - * |
|
| 1853 | - * @return EventDispatcherInterface |
|
| 1854 | - * @since 8.2.0 |
|
| 1855 | - */ |
|
| 1856 | - public function getEventDispatcher() { |
|
| 1857 | - return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1858 | - } |
|
| 1859 | - |
|
| 1860 | - /** |
|
| 1861 | - * Get the Notification Manager |
|
| 1862 | - * |
|
| 1863 | - * @return \OCP\Notification\IManager |
|
| 1864 | - * @since 8.2.0 |
|
| 1865 | - */ |
|
| 1866 | - public function getNotificationManager() { |
|
| 1867 | - return $this->query('NotificationManager'); |
|
| 1868 | - } |
|
| 1869 | - |
|
| 1870 | - /** |
|
| 1871 | - * @return \OCP\Comments\ICommentsManager |
|
| 1872 | - */ |
|
| 1873 | - public function getCommentsManager() { |
|
| 1874 | - return $this->query('CommentsManager'); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - /** |
|
| 1878 | - * @return \OCA\Theming\ThemingDefaults |
|
| 1879 | - */ |
|
| 1880 | - public function getThemingDefaults() { |
|
| 1881 | - return $this->query('ThemingDefaults'); |
|
| 1882 | - } |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * @return \OC\IntegrityCheck\Checker |
|
| 1886 | - */ |
|
| 1887 | - public function getIntegrityCodeChecker() { |
|
| 1888 | - return $this->query('IntegrityCodeChecker'); |
|
| 1889 | - } |
|
| 1890 | - |
|
| 1891 | - /** |
|
| 1892 | - * @return \OC\Session\CryptoWrapper |
|
| 1893 | - */ |
|
| 1894 | - public function getSessionCryptoWrapper() { |
|
| 1895 | - return $this->query('CryptoWrapper'); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - /** |
|
| 1899 | - * @return CsrfTokenManager |
|
| 1900 | - */ |
|
| 1901 | - public function getCsrfTokenManager() { |
|
| 1902 | - return $this->query('CsrfTokenManager'); |
|
| 1903 | - } |
|
| 1904 | - |
|
| 1905 | - /** |
|
| 1906 | - * @return Throttler |
|
| 1907 | - */ |
|
| 1908 | - public function getBruteForceThrottler() { |
|
| 1909 | - return $this->query('Throttler'); |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - /** |
|
| 1913 | - * @return IContentSecurityPolicyManager |
|
| 1914 | - */ |
|
| 1915 | - public function getContentSecurityPolicyManager() { |
|
| 1916 | - return $this->query('ContentSecurityPolicyManager'); |
|
| 1917 | - } |
|
| 1918 | - |
|
| 1919 | - /** |
|
| 1920 | - * @return ContentSecurityPolicyNonceManager |
|
| 1921 | - */ |
|
| 1922 | - public function getContentSecurityPolicyNonceManager() { |
|
| 1923 | - return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1924 | - } |
|
| 1925 | - |
|
| 1926 | - /** |
|
| 1927 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1928 | - * |
|
| 1929 | - * @return \OCA\Files_External\Service\BackendService |
|
| 1930 | - */ |
|
| 1931 | - public function getStoragesBackendService() { |
|
| 1932 | - return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1933 | - } |
|
| 1934 | - |
|
| 1935 | - /** |
|
| 1936 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1937 | - * |
|
| 1938 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1939 | - */ |
|
| 1940 | - public function getGlobalStoragesService() { |
|
| 1941 | - return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1942 | - } |
|
| 1943 | - |
|
| 1944 | - /** |
|
| 1945 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1946 | - * |
|
| 1947 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1948 | - */ |
|
| 1949 | - public function getUserGlobalStoragesService() { |
|
| 1950 | - return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - /** |
|
| 1954 | - * Not a public API as of 8.2, wait for 9.0 |
|
| 1955 | - * |
|
| 1956 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1957 | - */ |
|
| 1958 | - public function getUserStoragesService() { |
|
| 1959 | - return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1960 | - } |
|
| 1961 | - |
|
| 1962 | - /** |
|
| 1963 | - * @return \OCP\Share\IManager |
|
| 1964 | - */ |
|
| 1965 | - public function getShareManager() { |
|
| 1966 | - return $this->query('ShareManager'); |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - /** |
|
| 1970 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 1971 | - */ |
|
| 1972 | - public function getCollaboratorSearch() { |
|
| 1973 | - return $this->query('CollaboratorSearch'); |
|
| 1974 | - } |
|
| 1975 | - |
|
| 1976 | - /** |
|
| 1977 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 1978 | - */ |
|
| 1979 | - public function getAutoCompleteManager(){ |
|
| 1980 | - return $this->query(IManager::class); |
|
| 1981 | - } |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * Returns the LDAP Provider |
|
| 1985 | - * |
|
| 1986 | - * @return \OCP\LDAP\ILDAPProvider |
|
| 1987 | - */ |
|
| 1988 | - public function getLDAPProvider() { |
|
| 1989 | - return $this->query('LDAPProvider'); |
|
| 1990 | - } |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * @return \OCP\Settings\IManager |
|
| 1994 | - */ |
|
| 1995 | - public function getSettingsManager() { |
|
| 1996 | - return $this->query('SettingsManager'); |
|
| 1997 | - } |
|
| 1998 | - |
|
| 1999 | - /** |
|
| 2000 | - * @return \OCP\Files\IAppData |
|
| 2001 | - */ |
|
| 2002 | - public function getAppDataDir($app) { |
|
| 2003 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2004 | - $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 2005 | - return $factory->get($app); |
|
| 2006 | - } |
|
| 2007 | - |
|
| 2008 | - /** |
|
| 2009 | - * @return \OCP\Lockdown\ILockdownManager |
|
| 2010 | - */ |
|
| 2011 | - public function getLockdownManager() { |
|
| 2012 | - return $this->query('LockdownManager'); |
|
| 2013 | - } |
|
| 2014 | - |
|
| 2015 | - /** |
|
| 2016 | - * @return \OCP\Federation\ICloudIdManager |
|
| 2017 | - */ |
|
| 2018 | - public function getCloudIdManager() { |
|
| 2019 | - return $this->query(ICloudIdManager::class); |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - /** |
|
| 2023 | - * @return \OCP\GlobalScale\IConfig |
|
| 2024 | - */ |
|
| 2025 | - public function getGlobalScaleConfig() { |
|
| 2026 | - return $this->query(IConfig::class); |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - /** |
|
| 2030 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2031 | - */ |
|
| 2032 | - public function getCloudFederationProviderManager() { |
|
| 2033 | - return $this->query(ICloudFederationProviderManager::class); |
|
| 2034 | - } |
|
| 2035 | - |
|
| 2036 | - /** |
|
| 2037 | - * @return \OCP\Remote\Api\IApiFactory |
|
| 2038 | - */ |
|
| 2039 | - public function getRemoteApiFactory() { |
|
| 2040 | - return $this->query(IApiFactory::class); |
|
| 2041 | - } |
|
| 2042 | - |
|
| 2043 | - /** |
|
| 2044 | - * @return \OCP\Federation\ICloudFederationFactory |
|
| 2045 | - */ |
|
| 2046 | - public function getCloudFederationFactory() { |
|
| 2047 | - return $this->query(ICloudFederationFactory::class); |
|
| 2048 | - } |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * @return \OCP\Remote\IInstanceFactory |
|
| 2052 | - */ |
|
| 2053 | - public function getRemoteInstanceFactory() { |
|
| 2054 | - return $this->query(IInstanceFactory::class); |
|
| 2055 | - } |
|
| 2056 | - |
|
| 2057 | - /** |
|
| 2058 | - * @return IStorageFactory |
|
| 2059 | - */ |
|
| 2060 | - public function getStorageFactory() { |
|
| 2061 | - return $this->query(IStorageFactory::class); |
|
| 2062 | - } |
|
| 947 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
| 948 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
| 949 | + $classExists = true; |
|
| 950 | + } else { |
|
| 951 | + $classExists = false; |
|
| 952 | + } |
|
| 953 | + |
|
| 954 | + if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
| 955 | + return new ThemingDefaults( |
|
| 956 | + $c->getConfig(), |
|
| 957 | + $c->getL10N('theming'), |
|
| 958 | + $c->getURLGenerator(), |
|
| 959 | + $c->getMemCacheFactory(), |
|
| 960 | + new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')), |
|
| 961 | + new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()), |
|
| 962 | + $c->getAppManager(), |
|
| 963 | + $c->getNavigationManager() |
|
| 964 | + ); |
|
| 965 | + } |
|
| 966 | + return new \OC_Defaults(); |
|
| 967 | + }); |
|
| 968 | + $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 969 | + return new SCSSCacher( |
|
| 970 | + $c->getLogger(), |
|
| 971 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 972 | + $c->getURLGenerator(), |
|
| 973 | + $c->getConfig(), |
|
| 974 | + $c->getThemingDefaults(), |
|
| 975 | + \OC::$SERVERROOT, |
|
| 976 | + $this->getMemCacheFactory(), |
|
| 977 | + $c->query(IconsCacher::class), |
|
| 978 | + new TimeFactory() |
|
| 979 | + ); |
|
| 980 | + }); |
|
| 981 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 982 | + return new JSCombiner( |
|
| 983 | + $c->getAppDataDir('js'), |
|
| 984 | + $c->getURLGenerator(), |
|
| 985 | + $this->getMemCacheFactory(), |
|
| 986 | + $c->getSystemConfig(), |
|
| 987 | + $c->getLogger() |
|
| 988 | + ); |
|
| 989 | + }); |
|
| 990 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
| 991 | + $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 992 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
| 993 | + |
|
| 994 | + $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 995 | + // FIXME: Instantiiated here due to cyclic dependency |
|
| 996 | + $request = new Request( |
|
| 997 | + [ |
|
| 998 | + 'get' => $_GET, |
|
| 999 | + 'post' => $_POST, |
|
| 1000 | + 'files' => $_FILES, |
|
| 1001 | + 'server' => $_SERVER, |
|
| 1002 | + 'env' => $_ENV, |
|
| 1003 | + 'cookies' => $_COOKIE, |
|
| 1004 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
| 1005 | + ? $_SERVER['REQUEST_METHOD'] |
|
| 1006 | + : null, |
|
| 1007 | + ], |
|
| 1008 | + $c->getSecureRandom(), |
|
| 1009 | + $c->getConfig() |
|
| 1010 | + ); |
|
| 1011 | + |
|
| 1012 | + return new CryptoWrapper( |
|
| 1013 | + $c->getConfig(), |
|
| 1014 | + $c->getCrypto(), |
|
| 1015 | + $c->getSecureRandom(), |
|
| 1016 | + $request |
|
| 1017 | + ); |
|
| 1018 | + }); |
|
| 1019 | + $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 1020 | + $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
|
| 1021 | + |
|
| 1022 | + return new CsrfTokenManager( |
|
| 1023 | + $tokenGenerator, |
|
| 1024 | + $c->query(SessionStorage::class) |
|
| 1025 | + ); |
|
| 1026 | + }); |
|
| 1027 | + $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1028 | + return new SessionStorage($c->getSession()); |
|
| 1029 | + }); |
|
| 1030 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 1031 | + return new ContentSecurityPolicyManager(); |
|
| 1032 | + }); |
|
| 1033 | + $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
|
| 1034 | + |
|
| 1035 | + $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1036 | + return new ContentSecurityPolicyNonceManager( |
|
| 1037 | + $c->getCsrfTokenManager(), |
|
| 1038 | + $c->getRequest() |
|
| 1039 | + ); |
|
| 1040 | + }); |
|
| 1041 | + |
|
| 1042 | + $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1043 | + $config = $c->getConfig(); |
|
| 1044 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
| 1045 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
| 1046 | + $factory = new $factoryClass($this); |
|
| 1047 | + |
|
| 1048 | + $manager = new \OC\Share20\Manager( |
|
| 1049 | + $c->getLogger(), |
|
| 1050 | + $c->getConfig(), |
|
| 1051 | + $c->getSecureRandom(), |
|
| 1052 | + $c->getHasher(), |
|
| 1053 | + $c->getMountManager(), |
|
| 1054 | + $c->getGroupManager(), |
|
| 1055 | + $c->getL10N('lib'), |
|
| 1056 | + $c->getL10NFactory(), |
|
| 1057 | + $factory, |
|
| 1058 | + $c->getUserManager(), |
|
| 1059 | + $c->getLazyRootFolder(), |
|
| 1060 | + $c->getEventDispatcher(), |
|
| 1061 | + $c->getMailer(), |
|
| 1062 | + $c->getURLGenerator(), |
|
| 1063 | + $c->getThemingDefaults() |
|
| 1064 | + ); |
|
| 1065 | + |
|
| 1066 | + return $manager; |
|
| 1067 | + }); |
|
| 1068 | + $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
|
| 1069 | + |
|
| 1070 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
| 1071 | + $instance = new Collaboration\Collaborators\Search($c); |
|
| 1072 | + |
|
| 1073 | + // register default plugins |
|
| 1074 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
| 1075 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
| 1076 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
| 1077 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
| 1078 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
| 1079 | + |
|
| 1080 | + return $instance; |
|
| 1081 | + }); |
|
| 1082 | + $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
| 1083 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
| 1084 | + |
|
| 1085 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
| 1086 | + |
|
| 1087 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
| 1088 | + |
|
| 1089 | + $this->registerService('SettingsManager', function (Server $c) { |
|
| 1090 | + $manager = new \OC\Settings\Manager( |
|
| 1091 | + $c->getLogger(), |
|
| 1092 | + $c->getL10NFactory(), |
|
| 1093 | + $c->getURLGenerator(), |
|
| 1094 | + $c |
|
| 1095 | + ); |
|
| 1096 | + return $manager; |
|
| 1097 | + }); |
|
| 1098 | + $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1099 | + return new \OC\Files\AppData\Factory( |
|
| 1100 | + $c->getRootFolder(), |
|
| 1101 | + $c->getSystemConfig() |
|
| 1102 | + ); |
|
| 1103 | + }); |
|
| 1104 | + |
|
| 1105 | + $this->registerService('LockdownManager', function (Server $c) { |
|
| 1106 | + return new LockdownManager(function () use ($c) { |
|
| 1107 | + return $c->getSession(); |
|
| 1108 | + }); |
|
| 1109 | + }); |
|
| 1110 | + |
|
| 1111 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1112 | + return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
|
| 1113 | + }); |
|
| 1114 | + |
|
| 1115 | + $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1116 | + return new CloudIdManager(); |
|
| 1117 | + }); |
|
| 1118 | + |
|
| 1119 | + $this->registerService(IConfig::class, function (Server $c) { |
|
| 1120 | + return new GlobalScale\Config($c->getConfig()); |
|
| 1121 | + }); |
|
| 1122 | + |
|
| 1123 | + $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1124 | + return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
|
| 1125 | + }); |
|
| 1126 | + |
|
| 1127 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1128 | + return new CloudFederationFactory(); |
|
| 1129 | + }); |
|
| 1130 | + |
|
| 1131 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
| 1132 | + $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
| 1133 | + |
|
| 1134 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
| 1135 | + $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
| 1136 | + |
|
| 1137 | + $this->registerService(Defaults::class, function (Server $c) { |
|
| 1138 | + return new Defaults( |
|
| 1139 | + $c->getThemingDefaults() |
|
| 1140 | + ); |
|
| 1141 | + }); |
|
| 1142 | + $this->registerAlias('Defaults', \OCP\Defaults::class); |
|
| 1143 | + |
|
| 1144 | + $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1145 | + return $c->query(\OCP\IUserSession::class)->getSession(); |
|
| 1146 | + }); |
|
| 1147 | + |
|
| 1148 | + $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1149 | + return new ShareHelper( |
|
| 1150 | + $c->query(\OCP\Share\IManager::class) |
|
| 1151 | + ); |
|
| 1152 | + }); |
|
| 1153 | + |
|
| 1154 | + $this->registerService(Installer::class, function(Server $c) { |
|
| 1155 | + return new Installer( |
|
| 1156 | + $c->getAppFetcher(), |
|
| 1157 | + $c->getHTTPClientService(), |
|
| 1158 | + $c->getTempManager(), |
|
| 1159 | + $c->getLogger(), |
|
| 1160 | + $c->getConfig() |
|
| 1161 | + ); |
|
| 1162 | + }); |
|
| 1163 | + |
|
| 1164 | + $this->registerService(IApiFactory::class, function(Server $c) { |
|
| 1165 | + return new ApiFactory($c->getHTTPClientService()); |
|
| 1166 | + }); |
|
| 1167 | + |
|
| 1168 | + $this->registerService(IInstanceFactory::class, function(Server $c) { |
|
| 1169 | + $memcacheFactory = $c->getMemCacheFactory(); |
|
| 1170 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
|
| 1171 | + }); |
|
| 1172 | + |
|
| 1173 | + $this->registerService(IContactsStore::class, function(Server $c) { |
|
| 1174 | + return new ContactsStore( |
|
| 1175 | + $c->getContactsManager(), |
|
| 1176 | + $c->getConfig(), |
|
| 1177 | + $c->getUserManager(), |
|
| 1178 | + $c->getGroupManager() |
|
| 1179 | + ); |
|
| 1180 | + }); |
|
| 1181 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
| 1182 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
| 1183 | + |
|
| 1184 | + $this->registerService(IStorageFactory::class, function() { |
|
| 1185 | + return new StorageFactory(); |
|
| 1186 | + }); |
|
| 1187 | + |
|
| 1188 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
| 1189 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
| 1190 | + |
|
| 1191 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
| 1192 | + return new \OC\Security\IdentityProof\Manager( |
|
| 1193 | + $c->query(\OC\Files\AppData\Factory::class), |
|
| 1194 | + $c->getCrypto(), |
|
| 1195 | + $c->getConfig() |
|
| 1196 | + ); |
|
| 1197 | + }); |
|
| 1198 | + |
|
| 1199 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
| 1200 | + |
|
| 1201 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
| 1202 | + |
|
| 1203 | + $this->connectDispatcher(); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + /** |
|
| 1207 | + * @return \OCP\Calendar\IManager |
|
| 1208 | + */ |
|
| 1209 | + public function getCalendarManager() { |
|
| 1210 | + return $this->query('CalendarManager'); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + /** |
|
| 1214 | + * @return \OCP\Calendar\Resource\IManager |
|
| 1215 | + */ |
|
| 1216 | + public function getCalendarResourceBackendManager() { |
|
| 1217 | + return $this->query('CalendarResourceBackendManager'); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + /** |
|
| 1221 | + * @return \OCP\Calendar\Room\IManager |
|
| 1222 | + */ |
|
| 1223 | + public function getCalendarRoomBackendManager() { |
|
| 1224 | + return $this->query('CalendarRoomBackendManager'); |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + private function connectDispatcher() { |
|
| 1228 | + $dispatcher = $this->getEventDispatcher(); |
|
| 1229 | + |
|
| 1230 | + // Delete avatar on user deletion |
|
| 1231 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
| 1232 | + $logger = $this->getLogger(); |
|
| 1233 | + $manager = $this->getAvatarManager(); |
|
| 1234 | + /** @var IUser $user */ |
|
| 1235 | + $user = $e->getSubject(); |
|
| 1236 | + |
|
| 1237 | + try { |
|
| 1238 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1239 | + $avatar->remove(); |
|
| 1240 | + } catch (NotFoundException $e) { |
|
| 1241 | + // no avatar to remove |
|
| 1242 | + } catch (\Exception $e) { |
|
| 1243 | + // Ignore exceptions |
|
| 1244 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1245 | + } |
|
| 1246 | + }); |
|
| 1247 | + |
|
| 1248 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1249 | + $manager = $this->getAvatarManager(); |
|
| 1250 | + /** @var IUser $user */ |
|
| 1251 | + $user = $e->getSubject(); |
|
| 1252 | + $feature = $e->getArgument('feature'); |
|
| 1253 | + $oldValue = $e->getArgument('oldValue'); |
|
| 1254 | + $value = $e->getArgument('value'); |
|
| 1255 | + |
|
| 1256 | + // We only change the avatar on display name changes |
|
| 1257 | + if ($feature !== 'displayName') { |
|
| 1258 | + return; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + try { |
|
| 1262 | + $avatar = $manager->getAvatar($user->getUID()); |
|
| 1263 | + $avatar->userChanged($feature, $oldValue, $value); |
|
| 1264 | + } catch (NotFoundException $e) { |
|
| 1265 | + // no avatar to remove |
|
| 1266 | + } |
|
| 1267 | + }); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + /** |
|
| 1271 | + * @return \OCP\Contacts\IManager |
|
| 1272 | + */ |
|
| 1273 | + public function getContactsManager() { |
|
| 1274 | + return $this->query('ContactsManager'); |
|
| 1275 | + } |
|
| 1276 | + |
|
| 1277 | + /** |
|
| 1278 | + * @return \OC\Encryption\Manager |
|
| 1279 | + */ |
|
| 1280 | + public function getEncryptionManager() { |
|
| 1281 | + return $this->query('EncryptionManager'); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + /** |
|
| 1285 | + * @return \OC\Encryption\File |
|
| 1286 | + */ |
|
| 1287 | + public function getEncryptionFilesHelper() { |
|
| 1288 | + return $this->query('EncryptionFileHelper'); |
|
| 1289 | + } |
|
| 1290 | + |
|
| 1291 | + /** |
|
| 1292 | + * @return \OCP\Encryption\Keys\IStorage |
|
| 1293 | + */ |
|
| 1294 | + public function getEncryptionKeyStorage() { |
|
| 1295 | + return $this->query('EncryptionKeyStorage'); |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + /** |
|
| 1299 | + * The current request object holding all information about the request |
|
| 1300 | + * currently being processed is returned from this method. |
|
| 1301 | + * In case the current execution was not initiated by a web request null is returned |
|
| 1302 | + * |
|
| 1303 | + * @return \OCP\IRequest |
|
| 1304 | + */ |
|
| 1305 | + public function getRequest() { |
|
| 1306 | + return $this->query('Request'); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * Returns the preview manager which can create preview images for a given file |
|
| 1311 | + * |
|
| 1312 | + * @return \OCP\IPreview |
|
| 1313 | + */ |
|
| 1314 | + public function getPreviewManager() { |
|
| 1315 | + return $this->query('PreviewManager'); |
|
| 1316 | + } |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * Returns the tag manager which can get and set tags for different object types |
|
| 1320 | + * |
|
| 1321 | + * @see \OCP\ITagManager::load() |
|
| 1322 | + * @return \OCP\ITagManager |
|
| 1323 | + */ |
|
| 1324 | + public function getTagManager() { |
|
| 1325 | + return $this->query('TagManager'); |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + /** |
|
| 1329 | + * Returns the system-tag manager |
|
| 1330 | + * |
|
| 1331 | + * @return \OCP\SystemTag\ISystemTagManager |
|
| 1332 | + * |
|
| 1333 | + * @since 9.0.0 |
|
| 1334 | + */ |
|
| 1335 | + public function getSystemTagManager() { |
|
| 1336 | + return $this->query('SystemTagManager'); |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + /** |
|
| 1340 | + * Returns the system-tag object mapper |
|
| 1341 | + * |
|
| 1342 | + * @return \OCP\SystemTag\ISystemTagObjectMapper |
|
| 1343 | + * |
|
| 1344 | + * @since 9.0.0 |
|
| 1345 | + */ |
|
| 1346 | + public function getSystemTagObjectMapper() { |
|
| 1347 | + return $this->query('SystemTagObjectMapper'); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + /** |
|
| 1351 | + * Returns the avatar manager, used for avatar functionality |
|
| 1352 | + * |
|
| 1353 | + * @return \OCP\IAvatarManager |
|
| 1354 | + */ |
|
| 1355 | + public function getAvatarManager() { |
|
| 1356 | + return $this->query('AvatarManager'); |
|
| 1357 | + } |
|
| 1358 | + |
|
| 1359 | + /** |
|
| 1360 | + * Returns the root folder of ownCloud's data directory |
|
| 1361 | + * |
|
| 1362 | + * @return \OCP\Files\IRootFolder |
|
| 1363 | + */ |
|
| 1364 | + public function getRootFolder() { |
|
| 1365 | + return $this->query('LazyRootFolder'); |
|
| 1366 | + } |
|
| 1367 | + |
|
| 1368 | + /** |
|
| 1369 | + * Returns the root folder of ownCloud's data directory |
|
| 1370 | + * This is the lazy variant so this gets only initialized once it |
|
| 1371 | + * is actually used. |
|
| 1372 | + * |
|
| 1373 | + * @return \OCP\Files\IRootFolder |
|
| 1374 | + */ |
|
| 1375 | + public function getLazyRootFolder() { |
|
| 1376 | + return $this->query('LazyRootFolder'); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + /** |
|
| 1380 | + * Returns a view to ownCloud's files folder |
|
| 1381 | + * |
|
| 1382 | + * @param string $userId user ID |
|
| 1383 | + * @return \OCP\Files\Folder|null |
|
| 1384 | + */ |
|
| 1385 | + public function getUserFolder($userId = null) { |
|
| 1386 | + if ($userId === null) { |
|
| 1387 | + $user = $this->getUserSession()->getUser(); |
|
| 1388 | + if (!$user) { |
|
| 1389 | + return null; |
|
| 1390 | + } |
|
| 1391 | + $userId = $user->getUID(); |
|
| 1392 | + } |
|
| 1393 | + $root = $this->getRootFolder(); |
|
| 1394 | + return $root->getUserFolder($userId); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + /** |
|
| 1398 | + * Returns an app-specific view in ownClouds data directory |
|
| 1399 | + * |
|
| 1400 | + * @return \OCP\Files\Folder |
|
| 1401 | + * @deprecated since 9.2.0 use IAppData |
|
| 1402 | + */ |
|
| 1403 | + public function getAppFolder() { |
|
| 1404 | + $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1405 | + $root = $this->getRootFolder(); |
|
| 1406 | + if (!$root->nodeExists($dir)) { |
|
| 1407 | + $folder = $root->newFolder($dir); |
|
| 1408 | + } else { |
|
| 1409 | + $folder = $root->get($dir); |
|
| 1410 | + } |
|
| 1411 | + return $folder; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + /** |
|
| 1415 | + * @return \OC\User\Manager |
|
| 1416 | + */ |
|
| 1417 | + public function getUserManager() { |
|
| 1418 | + return $this->query('UserManager'); |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * @return \OC\Group\Manager |
|
| 1423 | + */ |
|
| 1424 | + public function getGroupManager() { |
|
| 1425 | + return $this->query('GroupManager'); |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + /** |
|
| 1429 | + * @return \OC\User\Session |
|
| 1430 | + */ |
|
| 1431 | + public function getUserSession() { |
|
| 1432 | + return $this->query('UserSession'); |
|
| 1433 | + } |
|
| 1434 | + |
|
| 1435 | + /** |
|
| 1436 | + * @return \OCP\ISession |
|
| 1437 | + */ |
|
| 1438 | + public function getSession() { |
|
| 1439 | + return $this->query('UserSession')->getSession(); |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * @param \OCP\ISession $session |
|
| 1444 | + */ |
|
| 1445 | + public function setSession(\OCP\ISession $session) { |
|
| 1446 | + $this->query(SessionStorage::class)->setSession($session); |
|
| 1447 | + $this->query('UserSession')->setSession($session); |
|
| 1448 | + $this->query(Store::class)->setSession($session); |
|
| 1449 | + } |
|
| 1450 | + |
|
| 1451 | + /** |
|
| 1452 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
| 1453 | + */ |
|
| 1454 | + public function getTwoFactorAuthManager() { |
|
| 1455 | + return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
|
| 1456 | + } |
|
| 1457 | + |
|
| 1458 | + /** |
|
| 1459 | + * @return \OC\NavigationManager |
|
| 1460 | + */ |
|
| 1461 | + public function getNavigationManager() { |
|
| 1462 | + return $this->query('NavigationManager'); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + /** |
|
| 1466 | + * @return \OCP\IConfig |
|
| 1467 | + */ |
|
| 1468 | + public function getConfig() { |
|
| 1469 | + return $this->query('AllConfig'); |
|
| 1470 | + } |
|
| 1471 | + |
|
| 1472 | + /** |
|
| 1473 | + * @return \OC\SystemConfig |
|
| 1474 | + */ |
|
| 1475 | + public function getSystemConfig() { |
|
| 1476 | + return $this->query('SystemConfig'); |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + /** |
|
| 1480 | + * Returns the app config manager |
|
| 1481 | + * |
|
| 1482 | + * @return \OCP\IAppConfig |
|
| 1483 | + */ |
|
| 1484 | + public function getAppConfig() { |
|
| 1485 | + return $this->query('AppConfig'); |
|
| 1486 | + } |
|
| 1487 | + |
|
| 1488 | + /** |
|
| 1489 | + * @return \OCP\L10N\IFactory |
|
| 1490 | + */ |
|
| 1491 | + public function getL10NFactory() { |
|
| 1492 | + return $this->query('L10NFactory'); |
|
| 1493 | + } |
|
| 1494 | + |
|
| 1495 | + /** |
|
| 1496 | + * get an L10N instance |
|
| 1497 | + * |
|
| 1498 | + * @param string $app appid |
|
| 1499 | + * @param string $lang |
|
| 1500 | + * @return IL10N |
|
| 1501 | + */ |
|
| 1502 | + public function getL10N($app, $lang = null) { |
|
| 1503 | + return $this->getL10NFactory()->get($app, $lang); |
|
| 1504 | + } |
|
| 1505 | + |
|
| 1506 | + /** |
|
| 1507 | + * @return \OCP\IURLGenerator |
|
| 1508 | + */ |
|
| 1509 | + public function getURLGenerator() { |
|
| 1510 | + return $this->query('URLGenerator'); |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + /** |
|
| 1514 | + * @return AppFetcher |
|
| 1515 | + */ |
|
| 1516 | + public function getAppFetcher() { |
|
| 1517 | + return $this->query(AppFetcher::class); |
|
| 1518 | + } |
|
| 1519 | + |
|
| 1520 | + /** |
|
| 1521 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
| 1522 | + * getMemCacheFactory() instead. |
|
| 1523 | + * |
|
| 1524 | + * @return \OCP\ICache |
|
| 1525 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
| 1526 | + */ |
|
| 1527 | + public function getCache() { |
|
| 1528 | + return $this->query('UserCache'); |
|
| 1529 | + } |
|
| 1530 | + |
|
| 1531 | + /** |
|
| 1532 | + * Returns an \OCP\CacheFactory instance |
|
| 1533 | + * |
|
| 1534 | + * @return \OCP\ICacheFactory |
|
| 1535 | + */ |
|
| 1536 | + public function getMemCacheFactory() { |
|
| 1537 | + return $this->query('MemCacheFactory'); |
|
| 1538 | + } |
|
| 1539 | + |
|
| 1540 | + /** |
|
| 1541 | + * Returns an \OC\RedisFactory instance |
|
| 1542 | + * |
|
| 1543 | + * @return \OC\RedisFactory |
|
| 1544 | + */ |
|
| 1545 | + public function getGetRedisFactory() { |
|
| 1546 | + return $this->query('RedisFactory'); |
|
| 1547 | + } |
|
| 1548 | + |
|
| 1549 | + |
|
| 1550 | + /** |
|
| 1551 | + * Returns the current session |
|
| 1552 | + * |
|
| 1553 | + * @return \OCP\IDBConnection |
|
| 1554 | + */ |
|
| 1555 | + public function getDatabaseConnection() { |
|
| 1556 | + return $this->query('DatabaseConnection'); |
|
| 1557 | + } |
|
| 1558 | + |
|
| 1559 | + /** |
|
| 1560 | + * Returns the activity manager |
|
| 1561 | + * |
|
| 1562 | + * @return \OCP\Activity\IManager |
|
| 1563 | + */ |
|
| 1564 | + public function getActivityManager() { |
|
| 1565 | + return $this->query('ActivityManager'); |
|
| 1566 | + } |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * Returns an job list for controlling background jobs |
|
| 1570 | + * |
|
| 1571 | + * @return \OCP\BackgroundJob\IJobList |
|
| 1572 | + */ |
|
| 1573 | + public function getJobList() { |
|
| 1574 | + return $this->query('JobList'); |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + /** |
|
| 1578 | + * Returns a logger instance |
|
| 1579 | + * |
|
| 1580 | + * @return \OCP\ILogger |
|
| 1581 | + */ |
|
| 1582 | + public function getLogger() { |
|
| 1583 | + return $this->query('Logger'); |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + /** |
|
| 1587 | + * @return ILogFactory |
|
| 1588 | + * @throws \OCP\AppFramework\QueryException |
|
| 1589 | + */ |
|
| 1590 | + public function getLogFactory() { |
|
| 1591 | + return $this->query(ILogFactory::class); |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + /** |
|
| 1595 | + * Returns a router for generating and matching urls |
|
| 1596 | + * |
|
| 1597 | + * @return \OCP\Route\IRouter |
|
| 1598 | + */ |
|
| 1599 | + public function getRouter() { |
|
| 1600 | + return $this->query('Router'); |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + /** |
|
| 1604 | + * Returns a search instance |
|
| 1605 | + * |
|
| 1606 | + * @return \OCP\ISearch |
|
| 1607 | + */ |
|
| 1608 | + public function getSearch() { |
|
| 1609 | + return $this->query('Search'); |
|
| 1610 | + } |
|
| 1611 | + |
|
| 1612 | + /** |
|
| 1613 | + * Returns a SecureRandom instance |
|
| 1614 | + * |
|
| 1615 | + * @return \OCP\Security\ISecureRandom |
|
| 1616 | + */ |
|
| 1617 | + public function getSecureRandom() { |
|
| 1618 | + return $this->query('SecureRandom'); |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + /** |
|
| 1622 | + * Returns a Crypto instance |
|
| 1623 | + * |
|
| 1624 | + * @return \OCP\Security\ICrypto |
|
| 1625 | + */ |
|
| 1626 | + public function getCrypto() { |
|
| 1627 | + return $this->query('Crypto'); |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + /** |
|
| 1631 | + * Returns a Hasher instance |
|
| 1632 | + * |
|
| 1633 | + * @return \OCP\Security\IHasher |
|
| 1634 | + */ |
|
| 1635 | + public function getHasher() { |
|
| 1636 | + return $this->query('Hasher'); |
|
| 1637 | + } |
|
| 1638 | + |
|
| 1639 | + /** |
|
| 1640 | + * Returns a CredentialsManager instance |
|
| 1641 | + * |
|
| 1642 | + * @return \OCP\Security\ICredentialsManager |
|
| 1643 | + */ |
|
| 1644 | + public function getCredentialsManager() { |
|
| 1645 | + return $this->query('CredentialsManager'); |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * Get the certificate manager for the user |
|
| 1650 | + * |
|
| 1651 | + * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
|
| 1652 | + * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
|
| 1653 | + */ |
|
| 1654 | + public function getCertificateManager($userId = '') { |
|
| 1655 | + if ($userId === '') { |
|
| 1656 | + $userSession = $this->getUserSession(); |
|
| 1657 | + $user = $userSession->getUser(); |
|
| 1658 | + if (is_null($user)) { |
|
| 1659 | + return null; |
|
| 1660 | + } |
|
| 1661 | + $userId = $user->getUID(); |
|
| 1662 | + } |
|
| 1663 | + return new CertificateManager( |
|
| 1664 | + $userId, |
|
| 1665 | + new View(), |
|
| 1666 | + $this->getConfig(), |
|
| 1667 | + $this->getLogger(), |
|
| 1668 | + $this->getSecureRandom() |
|
| 1669 | + ); |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + /** |
|
| 1673 | + * Returns an instance of the HTTP client service |
|
| 1674 | + * |
|
| 1675 | + * @return \OCP\Http\Client\IClientService |
|
| 1676 | + */ |
|
| 1677 | + public function getHTTPClientService() { |
|
| 1678 | + return $this->query('HttpClientService'); |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + /** |
|
| 1682 | + * Create a new event source |
|
| 1683 | + * |
|
| 1684 | + * @return \OCP\IEventSource |
|
| 1685 | + */ |
|
| 1686 | + public function createEventSource() { |
|
| 1687 | + return new \OC_EventSource(); |
|
| 1688 | + } |
|
| 1689 | + |
|
| 1690 | + /** |
|
| 1691 | + * Get the active event logger |
|
| 1692 | + * |
|
| 1693 | + * The returned logger only logs data when debug mode is enabled |
|
| 1694 | + * |
|
| 1695 | + * @return \OCP\Diagnostics\IEventLogger |
|
| 1696 | + */ |
|
| 1697 | + public function getEventLogger() { |
|
| 1698 | + return $this->query('EventLogger'); |
|
| 1699 | + } |
|
| 1700 | + |
|
| 1701 | + /** |
|
| 1702 | + * Get the active query logger |
|
| 1703 | + * |
|
| 1704 | + * The returned logger only logs data when debug mode is enabled |
|
| 1705 | + * |
|
| 1706 | + * @return \OCP\Diagnostics\IQueryLogger |
|
| 1707 | + */ |
|
| 1708 | + public function getQueryLogger() { |
|
| 1709 | + return $this->query('QueryLogger'); |
|
| 1710 | + } |
|
| 1711 | + |
|
| 1712 | + /** |
|
| 1713 | + * Get the manager for temporary files and folders |
|
| 1714 | + * |
|
| 1715 | + * @return \OCP\ITempManager |
|
| 1716 | + */ |
|
| 1717 | + public function getTempManager() { |
|
| 1718 | + return $this->query('TempManager'); |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + /** |
|
| 1722 | + * Get the app manager |
|
| 1723 | + * |
|
| 1724 | + * @return \OCP\App\IAppManager |
|
| 1725 | + */ |
|
| 1726 | + public function getAppManager() { |
|
| 1727 | + return $this->query('AppManager'); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + /** |
|
| 1731 | + * Creates a new mailer |
|
| 1732 | + * |
|
| 1733 | + * @return \OCP\Mail\IMailer |
|
| 1734 | + */ |
|
| 1735 | + public function getMailer() { |
|
| 1736 | + return $this->query('Mailer'); |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + /** |
|
| 1740 | + * Get the webroot |
|
| 1741 | + * |
|
| 1742 | + * @return string |
|
| 1743 | + */ |
|
| 1744 | + public function getWebRoot() { |
|
| 1745 | + return $this->webRoot; |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + /** |
|
| 1749 | + * @return \OC\OCSClient |
|
| 1750 | + */ |
|
| 1751 | + public function getOcsClient() { |
|
| 1752 | + return $this->query('OcsClient'); |
|
| 1753 | + } |
|
| 1754 | + |
|
| 1755 | + /** |
|
| 1756 | + * @return \OCP\IDateTimeZone |
|
| 1757 | + */ |
|
| 1758 | + public function getDateTimeZone() { |
|
| 1759 | + return $this->query('DateTimeZone'); |
|
| 1760 | + } |
|
| 1761 | + |
|
| 1762 | + /** |
|
| 1763 | + * @return \OCP\IDateTimeFormatter |
|
| 1764 | + */ |
|
| 1765 | + public function getDateTimeFormatter() { |
|
| 1766 | + return $this->query('DateTimeFormatter'); |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * @return \OCP\Files\Config\IMountProviderCollection |
|
| 1771 | + */ |
|
| 1772 | + public function getMountProviderCollection() { |
|
| 1773 | + return $this->query('MountConfigManager'); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + /** |
|
| 1777 | + * Get the IniWrapper |
|
| 1778 | + * |
|
| 1779 | + * @return IniGetWrapper |
|
| 1780 | + */ |
|
| 1781 | + public function getIniWrapper() { |
|
| 1782 | + return $this->query('IniWrapper'); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + /** |
|
| 1786 | + * @return \OCP\Command\IBus |
|
| 1787 | + */ |
|
| 1788 | + public function getCommandBus() { |
|
| 1789 | + return $this->query('AsyncCommandBus'); |
|
| 1790 | + } |
|
| 1791 | + |
|
| 1792 | + /** |
|
| 1793 | + * Get the trusted domain helper |
|
| 1794 | + * |
|
| 1795 | + * @return TrustedDomainHelper |
|
| 1796 | + */ |
|
| 1797 | + public function getTrustedDomainHelper() { |
|
| 1798 | + return $this->query('TrustedDomainHelper'); |
|
| 1799 | + } |
|
| 1800 | + |
|
| 1801 | + /** |
|
| 1802 | + * Get the locking provider |
|
| 1803 | + * |
|
| 1804 | + * @return \OCP\Lock\ILockingProvider |
|
| 1805 | + * @since 8.1.0 |
|
| 1806 | + */ |
|
| 1807 | + public function getLockingProvider() { |
|
| 1808 | + return $this->query('LockingProvider'); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + /** |
|
| 1812 | + * @return \OCP\Files\Mount\IMountManager |
|
| 1813 | + **/ |
|
| 1814 | + function getMountManager() { |
|
| 1815 | + return $this->query('MountManager'); |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + /** @return \OCP\Files\Config\IUserMountCache */ |
|
| 1819 | + function getUserMountCache() { |
|
| 1820 | + return $this->query('UserMountCache'); |
|
| 1821 | + } |
|
| 1822 | + |
|
| 1823 | + /** |
|
| 1824 | + * Get the MimeTypeDetector |
|
| 1825 | + * |
|
| 1826 | + * @return \OCP\Files\IMimeTypeDetector |
|
| 1827 | + */ |
|
| 1828 | + public function getMimeTypeDetector() { |
|
| 1829 | + return $this->query('MimeTypeDetector'); |
|
| 1830 | + } |
|
| 1831 | + |
|
| 1832 | + /** |
|
| 1833 | + * Get the MimeTypeLoader |
|
| 1834 | + * |
|
| 1835 | + * @return \OCP\Files\IMimeTypeLoader |
|
| 1836 | + */ |
|
| 1837 | + public function getMimeTypeLoader() { |
|
| 1838 | + return $this->query('MimeTypeLoader'); |
|
| 1839 | + } |
|
| 1840 | + |
|
| 1841 | + /** |
|
| 1842 | + * Get the manager of all the capabilities |
|
| 1843 | + * |
|
| 1844 | + * @return \OC\CapabilitiesManager |
|
| 1845 | + */ |
|
| 1846 | + public function getCapabilitiesManager() { |
|
| 1847 | + return $this->query('CapabilitiesManager'); |
|
| 1848 | + } |
|
| 1849 | + |
|
| 1850 | + /** |
|
| 1851 | + * Get the EventDispatcher |
|
| 1852 | + * |
|
| 1853 | + * @return EventDispatcherInterface |
|
| 1854 | + * @since 8.2.0 |
|
| 1855 | + */ |
|
| 1856 | + public function getEventDispatcher() { |
|
| 1857 | + return $this->query(\OC\EventDispatcher\SymfonyAdapter::class); |
|
| 1858 | + } |
|
| 1859 | + |
|
| 1860 | + /** |
|
| 1861 | + * Get the Notification Manager |
|
| 1862 | + * |
|
| 1863 | + * @return \OCP\Notification\IManager |
|
| 1864 | + * @since 8.2.0 |
|
| 1865 | + */ |
|
| 1866 | + public function getNotificationManager() { |
|
| 1867 | + return $this->query('NotificationManager'); |
|
| 1868 | + } |
|
| 1869 | + |
|
| 1870 | + /** |
|
| 1871 | + * @return \OCP\Comments\ICommentsManager |
|
| 1872 | + */ |
|
| 1873 | + public function getCommentsManager() { |
|
| 1874 | + return $this->query('CommentsManager'); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + /** |
|
| 1878 | + * @return \OCA\Theming\ThemingDefaults |
|
| 1879 | + */ |
|
| 1880 | + public function getThemingDefaults() { |
|
| 1881 | + return $this->query('ThemingDefaults'); |
|
| 1882 | + } |
|
| 1883 | + |
|
| 1884 | + /** |
|
| 1885 | + * @return \OC\IntegrityCheck\Checker |
|
| 1886 | + */ |
|
| 1887 | + public function getIntegrityCodeChecker() { |
|
| 1888 | + return $this->query('IntegrityCodeChecker'); |
|
| 1889 | + } |
|
| 1890 | + |
|
| 1891 | + /** |
|
| 1892 | + * @return \OC\Session\CryptoWrapper |
|
| 1893 | + */ |
|
| 1894 | + public function getSessionCryptoWrapper() { |
|
| 1895 | + return $this->query('CryptoWrapper'); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + /** |
|
| 1899 | + * @return CsrfTokenManager |
|
| 1900 | + */ |
|
| 1901 | + public function getCsrfTokenManager() { |
|
| 1902 | + return $this->query('CsrfTokenManager'); |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + /** |
|
| 1906 | + * @return Throttler |
|
| 1907 | + */ |
|
| 1908 | + public function getBruteForceThrottler() { |
|
| 1909 | + return $this->query('Throttler'); |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + /** |
|
| 1913 | + * @return IContentSecurityPolicyManager |
|
| 1914 | + */ |
|
| 1915 | + public function getContentSecurityPolicyManager() { |
|
| 1916 | + return $this->query('ContentSecurityPolicyManager'); |
|
| 1917 | + } |
|
| 1918 | + |
|
| 1919 | + /** |
|
| 1920 | + * @return ContentSecurityPolicyNonceManager |
|
| 1921 | + */ |
|
| 1922 | + public function getContentSecurityPolicyNonceManager() { |
|
| 1923 | + return $this->query('ContentSecurityPolicyNonceManager'); |
|
| 1924 | + } |
|
| 1925 | + |
|
| 1926 | + /** |
|
| 1927 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1928 | + * |
|
| 1929 | + * @return \OCA\Files_External\Service\BackendService |
|
| 1930 | + */ |
|
| 1931 | + public function getStoragesBackendService() { |
|
| 1932 | + return $this->query('OCA\\Files_External\\Service\\BackendService'); |
|
| 1933 | + } |
|
| 1934 | + |
|
| 1935 | + /** |
|
| 1936 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1937 | + * |
|
| 1938 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
| 1939 | + */ |
|
| 1940 | + public function getGlobalStoragesService() { |
|
| 1941 | + return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService'); |
|
| 1942 | + } |
|
| 1943 | + |
|
| 1944 | + /** |
|
| 1945 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1946 | + * |
|
| 1947 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
| 1948 | + */ |
|
| 1949 | + public function getUserGlobalStoragesService() { |
|
| 1950 | + return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService'); |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + /** |
|
| 1954 | + * Not a public API as of 8.2, wait for 9.0 |
|
| 1955 | + * |
|
| 1956 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
| 1957 | + */ |
|
| 1958 | + public function getUserStoragesService() { |
|
| 1959 | + return $this->query('OCA\\Files_External\\Service\\UserStoragesService'); |
|
| 1960 | + } |
|
| 1961 | + |
|
| 1962 | + /** |
|
| 1963 | + * @return \OCP\Share\IManager |
|
| 1964 | + */ |
|
| 1965 | + public function getShareManager() { |
|
| 1966 | + return $this->query('ShareManager'); |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + /** |
|
| 1970 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
| 1971 | + */ |
|
| 1972 | + public function getCollaboratorSearch() { |
|
| 1973 | + return $this->query('CollaboratorSearch'); |
|
| 1974 | + } |
|
| 1975 | + |
|
| 1976 | + /** |
|
| 1977 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
| 1978 | + */ |
|
| 1979 | + public function getAutoCompleteManager(){ |
|
| 1980 | + return $this->query(IManager::class); |
|
| 1981 | + } |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * Returns the LDAP Provider |
|
| 1985 | + * |
|
| 1986 | + * @return \OCP\LDAP\ILDAPProvider |
|
| 1987 | + */ |
|
| 1988 | + public function getLDAPProvider() { |
|
| 1989 | + return $this->query('LDAPProvider'); |
|
| 1990 | + } |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * @return \OCP\Settings\IManager |
|
| 1994 | + */ |
|
| 1995 | + public function getSettingsManager() { |
|
| 1996 | + return $this->query('SettingsManager'); |
|
| 1997 | + } |
|
| 1998 | + |
|
| 1999 | + /** |
|
| 2000 | + * @return \OCP\Files\IAppData |
|
| 2001 | + */ |
|
| 2002 | + public function getAppDataDir($app) { |
|
| 2003 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
| 2004 | + $factory = $this->query(\OC\Files\AppData\Factory::class); |
|
| 2005 | + return $factory->get($app); |
|
| 2006 | + } |
|
| 2007 | + |
|
| 2008 | + /** |
|
| 2009 | + * @return \OCP\Lockdown\ILockdownManager |
|
| 2010 | + */ |
|
| 2011 | + public function getLockdownManager() { |
|
| 2012 | + return $this->query('LockdownManager'); |
|
| 2013 | + } |
|
| 2014 | + |
|
| 2015 | + /** |
|
| 2016 | + * @return \OCP\Federation\ICloudIdManager |
|
| 2017 | + */ |
|
| 2018 | + public function getCloudIdManager() { |
|
| 2019 | + return $this->query(ICloudIdManager::class); |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + /** |
|
| 2023 | + * @return \OCP\GlobalScale\IConfig |
|
| 2024 | + */ |
|
| 2025 | + public function getGlobalScaleConfig() { |
|
| 2026 | + return $this->query(IConfig::class); |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + /** |
|
| 2030 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
| 2031 | + */ |
|
| 2032 | + public function getCloudFederationProviderManager() { |
|
| 2033 | + return $this->query(ICloudFederationProviderManager::class); |
|
| 2034 | + } |
|
| 2035 | + |
|
| 2036 | + /** |
|
| 2037 | + * @return \OCP\Remote\Api\IApiFactory |
|
| 2038 | + */ |
|
| 2039 | + public function getRemoteApiFactory() { |
|
| 2040 | + return $this->query(IApiFactory::class); |
|
| 2041 | + } |
|
| 2042 | + |
|
| 2043 | + /** |
|
| 2044 | + * @return \OCP\Federation\ICloudFederationFactory |
|
| 2045 | + */ |
|
| 2046 | + public function getCloudFederationFactory() { |
|
| 2047 | + return $this->query(ICloudFederationFactory::class); |
|
| 2048 | + } |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * @return \OCP\Remote\IInstanceFactory |
|
| 2052 | + */ |
|
| 2053 | + public function getRemoteInstanceFactory() { |
|
| 2054 | + return $this->query(IInstanceFactory::class); |
|
| 2055 | + } |
|
| 2056 | + |
|
| 2057 | + /** |
|
| 2058 | + * @return IStorageFactory |
|
| 2059 | + */ |
|
| 2060 | + public function getStorageFactory() { |
|
| 2061 | + return $this->query(IStorageFactory::class); |
|
| 2062 | + } |
|
| 2063 | 2063 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // To find out if we are running from CLI or not |
| 183 | 183 | $this->registerParameter('isCLI', \OC::$CLI); |
| 184 | 184 | |
| 185 | - $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
|
| 185 | + $this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) { |
|
| 186 | 186 | return $c; |
| 187 | 187 | }); |
| 188 | 188 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
| 202 | 202 | |
| 203 | 203 | |
| 204 | - $this->registerService(\OCP\IPreview::class, function (Server $c) { |
|
| 204 | + $this->registerService(\OCP\IPreview::class, function(Server $c) { |
|
| 205 | 205 | return new PreviewManager( |
| 206 | 206 | $c->getConfig(), |
| 207 | 207 | $c->getRootFolder(), |
@@ -212,13 +212,13 @@ discard block |
||
| 212 | 212 | }); |
| 213 | 213 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
| 214 | 214 | |
| 215 | - $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
|
| 215 | + $this->registerService(\OC\Preview\Watcher::class, function(Server $c) { |
|
| 216 | 216 | return new \OC\Preview\Watcher( |
| 217 | 217 | $c->getAppDataDir('preview') |
| 218 | 218 | ); |
| 219 | 219 | }); |
| 220 | 220 | |
| 221 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
| 221 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
| 222 | 222 | $view = new View(); |
| 223 | 223 | $util = new Encryption\Util( |
| 224 | 224 | $view, |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | }); |
| 238 | 238 | $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
| 239 | 239 | |
| 240 | - $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 240 | + $this->registerService('EncryptionFileHelper', function(Server $c) { |
|
| 241 | 241 | $util = new Encryption\Util( |
| 242 | 242 | new View(), |
| 243 | 243 | $c->getUserManager(), |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | ); |
| 252 | 252 | }); |
| 253 | 253 | |
| 254 | - $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 254 | + $this->registerService('EncryptionKeyStorage', function(Server $c) { |
|
| 255 | 255 | $view = new View(); |
| 256 | 256 | $util = new Encryption\Util( |
| 257 | 257 | $view, |
@@ -262,30 +262,30 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | return new Encryption\Keys\Storage($view, $util); |
| 264 | 264 | }); |
| 265 | - $this->registerService('TagMapper', function (Server $c) { |
|
| 265 | + $this->registerService('TagMapper', function(Server $c) { |
|
| 266 | 266 | return new TagMapper($c->getDatabaseConnection()); |
| 267 | 267 | }); |
| 268 | 268 | |
| 269 | - $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
|
| 269 | + $this->registerService(\OCP\ITagManager::class, function(Server $c) { |
|
| 270 | 270 | $tagMapper = $c->query('TagMapper'); |
| 271 | 271 | return new TagManager($tagMapper, $c->getUserSession()); |
| 272 | 272 | }); |
| 273 | 273 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
| 274 | 274 | |
| 275 | - $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 275 | + $this->registerService('SystemTagManagerFactory', function(Server $c) { |
|
| 276 | 276 | $config = $c->getConfig(); |
| 277 | 277 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
| 278 | 278 | return new $factoryClass($this); |
| 279 | 279 | }); |
| 280 | - $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
|
| 280 | + $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) { |
|
| 281 | 281 | return $c->query('SystemTagManagerFactory')->getManager(); |
| 282 | 282 | }); |
| 283 | 283 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
| 284 | 284 | |
| 285 | - $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
|
| 285 | + $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) { |
|
| 286 | 286 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
| 287 | 287 | }); |
| 288 | - $this->registerService('RootFolder', function (Server $c) { |
|
| 288 | + $this->registerService('RootFolder', function(Server $c) { |
|
| 289 | 289 | $manager = \OC\Files\Filesystem::getMountManager(null); |
| 290 | 290 | $view = new View(); |
| 291 | 291 | $root = new Root( |
@@ -306,37 +306,37 @@ discard block |
||
| 306 | 306 | }); |
| 307 | 307 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
| 308 | 308 | |
| 309 | - $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
|
| 310 | - return new LazyRoot(function () use ($c) { |
|
| 309 | + $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) { |
|
| 310 | + return new LazyRoot(function() use ($c) { |
|
| 311 | 311 | return $c->query('RootFolder'); |
| 312 | 312 | }); |
| 313 | 313 | }); |
| 314 | 314 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
| 315 | 315 | |
| 316 | - $this->registerService(\OC\User\Manager::class, function (Server $c) { |
|
| 316 | + $this->registerService(\OC\User\Manager::class, function(Server $c) { |
|
| 317 | 317 | return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher()); |
| 318 | 318 | }); |
| 319 | 319 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
| 320 | 320 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
| 321 | 321 | |
| 322 | - $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
|
| 322 | + $this->registerService(\OCP\IGroupManager::class, function(Server $c) { |
|
| 323 | 323 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger()); |
| 324 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
| 324 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
| 325 | 325 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
| 326 | 326 | }); |
| 327 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
|
| 327 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) { |
|
| 328 | 328 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
| 329 | 329 | }); |
| 330 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
| 330 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
| 331 | 331 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
| 332 | 332 | }); |
| 333 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
| 333 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
| 334 | 334 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
| 335 | 335 | }); |
| 336 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 336 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 337 | 337 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 338 | 338 | }); |
| 339 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
| 339 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
| 340 | 340 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
| 341 | 341 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
| 342 | 342 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | }); |
| 346 | 346 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
| 347 | 347 | |
| 348 | - $this->registerService(Store::class, function (Server $c) { |
|
| 348 | + $this->registerService(Store::class, function(Server $c) { |
|
| 349 | 349 | $session = $c->getSession(); |
| 350 | 350 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
| 351 | 351 | $tokenProvider = $c->query(IProvider::class); |
@@ -356,13 +356,13 @@ discard block |
||
| 356 | 356 | return new Store($session, $logger, $tokenProvider); |
| 357 | 357 | }); |
| 358 | 358 | $this->registerAlias(IStore::class, Store::class); |
| 359 | - $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
|
| 359 | + $this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) { |
|
| 360 | 360 | $dbConnection = $c->getDatabaseConnection(); |
| 361 | 361 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
| 362 | 362 | }); |
| 363 | 363 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
| 364 | 364 | |
| 365 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
| 365 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
| 366 | 366 | $manager = $c->getUserManager(); |
| 367 | 367 | $session = new \OC\Session\Memory(''); |
| 368 | 368 | $timeFactory = new TimeFactory(); |
@@ -386,45 +386,45 @@ discard block |
||
| 386 | 386 | $c->getLockdownManager(), |
| 387 | 387 | $c->getLogger() |
| 388 | 388 | ); |
| 389 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
| 389 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
| 390 | 390 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 391 | 391 | }); |
| 392 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
| 392 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
| 393 | 393 | /** @var $user \OC\User\User */ |
| 394 | 394 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
| 395 | 395 | }); |
| 396 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
|
| 396 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) { |
|
| 397 | 397 | /** @var $user \OC\User\User */ |
| 398 | 398 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
| 399 | 399 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
| 400 | 400 | }); |
| 401 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
| 401 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
| 402 | 402 | /** @var $user \OC\User\User */ |
| 403 | 403 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
| 404 | 404 | }); |
| 405 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 405 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
| 406 | 406 | /** @var $user \OC\User\User */ |
| 407 | 407 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 408 | 408 | }); |
| 409 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 409 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
| 410 | 410 | /** @var $user \OC\User\User */ |
| 411 | 411 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
| 412 | 412 | }); |
| 413 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
| 413 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
| 414 | 414 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
| 415 | 415 | }); |
| 416 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) { |
|
| 416 | + $userSession->listen('\OC\User', 'postLogin', function($user, $password, $isTokenLogin) { |
|
| 417 | 417 | /** @var $user \OC\User\User */ |
| 418 | 418 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin)); |
| 419 | 419 | }); |
| 420 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 420 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
| 421 | 421 | /** @var $user \OC\User\User */ |
| 422 | 422 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
| 423 | 423 | }); |
| 424 | - $userSession->listen('\OC\User', 'logout', function () { |
|
| 424 | + $userSession->listen('\OC\User', 'logout', function() { |
|
| 425 | 425 | \OC_Hook::emit('OC_User', 'logout', array()); |
| 426 | 426 | }); |
| 427 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
| 427 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
| 428 | 428 | /** @var $user \OC\User\User */ |
| 429 | 429 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
| 430 | 430 | }); |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
| 439 | 439 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
| 440 | 440 | |
| 441 | - $this->registerService(\OC\AllConfig::class, function (Server $c) { |
|
| 441 | + $this->registerService(\OC\AllConfig::class, function(Server $c) { |
|
| 442 | 442 | return new \OC\AllConfig( |
| 443 | 443 | $c->getSystemConfig() |
| 444 | 444 | ); |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
| 447 | 447 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
| 448 | 448 | |
| 449 | - $this->registerService('SystemConfig', function ($c) use ($config) { |
|
| 449 | + $this->registerService('SystemConfig', function($c) use ($config) { |
|
| 450 | 450 | return new \OC\SystemConfig($config); |
| 451 | 451 | }); |
| 452 | 452 | |
| 453 | - $this->registerService(\OC\AppConfig::class, function (Server $c) { |
|
| 453 | + $this->registerService(\OC\AppConfig::class, function(Server $c) { |
|
| 454 | 454 | return new \OC\AppConfig($c->getDatabaseConnection()); |
| 455 | 455 | }); |
| 456 | 456 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
| 457 | 457 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
| 458 | 458 | |
| 459 | - $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
|
| 459 | + $this->registerService(\OCP\L10N\IFactory::class, function(Server $c) { |
|
| 460 | 460 | return new \OC\L10N\Factory( |
| 461 | 461 | $c->getConfig(), |
| 462 | 462 | $c->getRequest(), |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | }); |
| 467 | 467 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
| 468 | 468 | |
| 469 | - $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
|
| 469 | + $this->registerService(\OCP\IURLGenerator::class, function(Server $c) { |
|
| 470 | 470 | $config = $c->getConfig(); |
| 471 | 471 | $cacheFactory = $c->getMemCacheFactory(); |
| 472 | 472 | $request = $c->getRequest(); |
@@ -481,12 +481,12 @@ discard block |
||
| 481 | 481 | $this->registerAlias('AppFetcher', AppFetcher::class); |
| 482 | 482 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
| 483 | 483 | |
| 484 | - $this->registerService(\OCP\ICache::class, function ($c) { |
|
| 484 | + $this->registerService(\OCP\ICache::class, function($c) { |
|
| 485 | 485 | return new Cache\File(); |
| 486 | 486 | }); |
| 487 | 487 | $this->registerAlias('UserCache', \OCP\ICache::class); |
| 488 | 488 | |
| 489 | - $this->registerService(Factory::class, function (Server $c) { |
|
| 489 | + $this->registerService(Factory::class, function(Server $c) { |
|
| 490 | 490 | |
| 491 | 491 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
| 492 | 492 | ArrayCache::class, |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | $version = implode(',', $v); |
| 502 | 502 | $instanceId = \OC_Util::getInstanceId(); |
| 503 | 503 | $path = \OC::$SERVERROOT; |
| 504 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
| 504 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
| 505 | 505 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
| 506 | 506 | $config->getSystemValue('memcache.local', null), |
| 507 | 507 | $config->getSystemValue('memcache.distributed', null), |
@@ -514,12 +514,12 @@ discard block |
||
| 514 | 514 | $this->registerAlias('MemCacheFactory', Factory::class); |
| 515 | 515 | $this->registerAlias(ICacheFactory::class, Factory::class); |
| 516 | 516 | |
| 517 | - $this->registerService('RedisFactory', function (Server $c) { |
|
| 517 | + $this->registerService('RedisFactory', function(Server $c) { |
|
| 518 | 518 | $systemConfig = $c->getSystemConfig(); |
| 519 | 519 | return new RedisFactory($systemConfig); |
| 520 | 520 | }); |
| 521 | 521 | |
| 522 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
| 522 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
| 523 | 523 | return new \OC\Activity\Manager( |
| 524 | 524 | $c->getRequest(), |
| 525 | 525 | $c->getUserSession(), |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | }); |
| 530 | 530 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
| 531 | 531 | |
| 532 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
| 532 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
| 533 | 533 | return new \OC\Activity\EventMerger( |
| 534 | 534 | $c->getL10N('lib') |
| 535 | 535 | ); |
@@ -551,7 +551,7 @@ discard block |
||
| 551 | 551 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
| 552 | 552 | $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
| 553 | 553 | |
| 554 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
| 554 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
| 555 | 555 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
| 556 | 556 | $factory = new LogFactory($c, $this->getSystemConfig()); |
| 557 | 557 | $logger = $factory->get($logType); |
@@ -562,11 +562,11 @@ discard block |
||
| 562 | 562 | $this->registerAlias(\OCP\ILogger::class, \OC\Log::class); |
| 563 | 563 | $this->registerAlias('Logger', \OC\Log::class); |
| 564 | 564 | |
| 565 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
| 565 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
| 566 | 566 | return new LogFactory($c, $this->getSystemConfig()); |
| 567 | 567 | }); |
| 568 | 568 | |
| 569 | - $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
|
| 569 | + $this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) { |
|
| 570 | 570 | $config = $c->getConfig(); |
| 571 | 571 | return new \OC\BackgroundJob\JobList( |
| 572 | 572 | $c->getDatabaseConnection(), |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | }); |
| 577 | 577 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
| 578 | 578 | |
| 579 | - $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
|
| 579 | + $this->registerService(\OCP\Route\IRouter::class, function(Server $c) { |
|
| 580 | 580 | $cacheFactory = $c->getMemCacheFactory(); |
| 581 | 581 | $logger = $c->getLogger(); |
| 582 | 582 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -588,12 +588,12 @@ discard block |
||
| 588 | 588 | }); |
| 589 | 589 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
| 590 | 590 | |
| 591 | - $this->registerService(\OCP\ISearch::class, function ($c) { |
|
| 591 | + $this->registerService(\OCP\ISearch::class, function($c) { |
|
| 592 | 592 | return new Search(); |
| 593 | 593 | }); |
| 594 | 594 | $this->registerAlias('Search', \OCP\ISearch::class); |
| 595 | 595 | |
| 596 | - $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) { |
|
| 596 | + $this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) { |
|
| 597 | 597 | return new \OC\Security\RateLimiting\Limiter( |
| 598 | 598 | $this->getUserSession(), |
| 599 | 599 | $this->getRequest(), |
@@ -601,34 +601,34 @@ discard block |
||
| 601 | 601 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
| 602 | 602 | ); |
| 603 | 603 | }); |
| 604 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
| 604 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
| 605 | 605 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
| 606 | 606 | $this->getMemCacheFactory(), |
| 607 | 607 | new \OC\AppFramework\Utility\TimeFactory() |
| 608 | 608 | ); |
| 609 | 609 | }); |
| 610 | 610 | |
| 611 | - $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
|
| 611 | + $this->registerService(\OCP\Security\ISecureRandom::class, function($c) { |
|
| 612 | 612 | return new SecureRandom(); |
| 613 | 613 | }); |
| 614 | 614 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
| 615 | 615 | |
| 616 | - $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
|
| 616 | + $this->registerService(\OCP\Security\ICrypto::class, function(Server $c) { |
|
| 617 | 617 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
| 618 | 618 | }); |
| 619 | 619 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
| 620 | 620 | |
| 621 | - $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
|
| 621 | + $this->registerService(\OCP\Security\IHasher::class, function(Server $c) { |
|
| 622 | 622 | return new Hasher($c->getConfig()); |
| 623 | 623 | }); |
| 624 | 624 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
| 625 | 625 | |
| 626 | - $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
|
| 626 | + $this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) { |
|
| 627 | 627 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
| 628 | 628 | }); |
| 629 | 629 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
| 630 | 630 | |
| 631 | - $this->registerService(IDBConnection::class, function (Server $c) { |
|
| 631 | + $this->registerService(IDBConnection::class, function(Server $c) { |
|
| 632 | 632 | $systemConfig = $c->getSystemConfig(); |
| 633 | 633 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
| 634 | 634 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
| 644 | 644 | |
| 645 | 645 | |
| 646 | - $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
|
| 646 | + $this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) { |
|
| 647 | 647 | $user = \OC_User::getUser(); |
| 648 | 648 | $uid = $user ? $user : null; |
| 649 | 649 | return new ClientService( |
@@ -658,7 +658,7 @@ discard block |
||
| 658 | 658 | ); |
| 659 | 659 | }); |
| 660 | 660 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
| 661 | - $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 661 | + $this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) { |
|
| 662 | 662 | $eventLogger = new EventLogger(); |
| 663 | 663 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 664 | 664 | // In debug mode, module is being activated by default |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | }); |
| 669 | 669 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
| 670 | 670 | |
| 671 | - $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 671 | + $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) { |
|
| 672 | 672 | $queryLogger = new QueryLogger(); |
| 673 | 673 | if ($c->getSystemConfig()->getValue('debug', false)) { |
| 674 | 674 | // In debug mode, module is being activated by default |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | }); |
| 679 | 679 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
| 680 | 680 | |
| 681 | - $this->registerService(TempManager::class, function (Server $c) { |
|
| 681 | + $this->registerService(TempManager::class, function(Server $c) { |
|
| 682 | 682 | return new TempManager( |
| 683 | 683 | $c->getLogger(), |
| 684 | 684 | $c->getConfig() |
@@ -687,7 +687,7 @@ discard block |
||
| 687 | 687 | $this->registerAlias('TempManager', TempManager::class); |
| 688 | 688 | $this->registerAlias(ITempManager::class, TempManager::class); |
| 689 | 689 | |
| 690 | - $this->registerService(AppManager::class, function (Server $c) { |
|
| 690 | + $this->registerService(AppManager::class, function(Server $c) { |
|
| 691 | 691 | return new \OC\App\AppManager( |
| 692 | 692 | $c->getUserSession(), |
| 693 | 693 | $c->query(\OC\AppConfig::class), |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | $this->registerAlias('AppManager', AppManager::class); |
| 700 | 700 | $this->registerAlias(IAppManager::class, AppManager::class); |
| 701 | 701 | |
| 702 | - $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
|
| 702 | + $this->registerService(\OCP\IDateTimeZone::class, function(Server $c) { |
|
| 703 | 703 | return new DateTimeZone( |
| 704 | 704 | $c->getConfig(), |
| 705 | 705 | $c->getSession() |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | }); |
| 708 | 708 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
| 709 | 709 | |
| 710 | - $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
|
| 710 | + $this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) { |
|
| 711 | 711 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
| 712 | 712 | |
| 713 | 713 | return new DateTimeFormatter( |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | }); |
| 718 | 718 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
| 719 | 719 | |
| 720 | - $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
|
| 720 | + $this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) { |
|
| 721 | 721 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
| 722 | 722 | $listener = new UserMountCacheListener($mountCache); |
| 723 | 723 | $listener->listen($c->getUserManager()); |
@@ -725,7 +725,7 @@ discard block |
||
| 725 | 725 | }); |
| 726 | 726 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
| 727 | 727 | |
| 728 | - $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
|
| 728 | + $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) { |
|
| 729 | 729 | $loader = \OC\Files\Filesystem::getLoader(); |
| 730 | 730 | $mountCache = $c->query('UserMountCache'); |
| 731 | 731 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -741,10 +741,10 @@ discard block |
||
| 741 | 741 | }); |
| 742 | 742 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
| 743 | 743 | |
| 744 | - $this->registerService('IniWrapper', function ($c) { |
|
| 744 | + $this->registerService('IniWrapper', function($c) { |
|
| 745 | 745 | return new IniGetWrapper(); |
| 746 | 746 | }); |
| 747 | - $this->registerService('AsyncCommandBus', function (Server $c) { |
|
| 747 | + $this->registerService('AsyncCommandBus', function(Server $c) { |
|
| 748 | 748 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
| 749 | 749 | if ($busClass) { |
| 750 | 750 | list($app, $class) = explode('::', $busClass, 2); |
@@ -759,10 +759,10 @@ discard block |
||
| 759 | 759 | return new CronBus($jobList); |
| 760 | 760 | } |
| 761 | 761 | }); |
| 762 | - $this->registerService('TrustedDomainHelper', function ($c) { |
|
| 762 | + $this->registerService('TrustedDomainHelper', function($c) { |
|
| 763 | 763 | return new TrustedDomainHelper($this->getConfig()); |
| 764 | 764 | }); |
| 765 | - $this->registerService(Throttler::class, function (Server $c) { |
|
| 765 | + $this->registerService(Throttler::class, function(Server $c) { |
|
| 766 | 766 | return new Throttler( |
| 767 | 767 | $c->getDatabaseConnection(), |
| 768 | 768 | new TimeFactory(), |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | ); |
| 772 | 772 | }); |
| 773 | 773 | $this->registerAlias('Throttler', Throttler::class); |
| 774 | - $this->registerService('IntegrityCodeChecker', function (Server $c) { |
|
| 774 | + $this->registerService('IntegrityCodeChecker', function(Server $c) { |
|
| 775 | 775 | // IConfig and IAppManager requires a working database. This code |
| 776 | 776 | // might however be called when ownCloud is not yet setup. |
| 777 | 777 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | $c->getTempManager() |
| 793 | 793 | ); |
| 794 | 794 | }); |
| 795 | - $this->registerService(\OCP\IRequest::class, function ($c) { |
|
| 795 | + $this->registerService(\OCP\IRequest::class, function($c) { |
|
| 796 | 796 | if (isset($this['urlParams'])) { |
| 797 | 797 | $urlParams = $this['urlParams']; |
| 798 | 798 | } else { |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | }); |
| 829 | 829 | $this->registerAlias('Request', \OCP\IRequest::class); |
| 830 | 830 | |
| 831 | - $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
|
| 831 | + $this->registerService(\OCP\Mail\IMailer::class, function(Server $c) { |
|
| 832 | 832 | return new Mailer( |
| 833 | 833 | $c->getConfig(), |
| 834 | 834 | $c->getLogger(), |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | }); |
| 840 | 840 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
| 841 | 841 | |
| 842 | - $this->registerService('LDAPProvider', function (Server $c) { |
|
| 842 | + $this->registerService('LDAPProvider', function(Server $c) { |
|
| 843 | 843 | $config = $c->getConfig(); |
| 844 | 844 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
| 845 | 845 | if (is_null($factoryClass)) { |
@@ -849,7 +849,7 @@ discard block |
||
| 849 | 849 | $factory = new $factoryClass($this); |
| 850 | 850 | return $factory->getLDAPProvider(); |
| 851 | 851 | }); |
| 852 | - $this->registerService(ILockingProvider::class, function (Server $c) { |
|
| 852 | + $this->registerService(ILockingProvider::class, function(Server $c) { |
|
| 853 | 853 | $ini = $c->getIniWrapper(); |
| 854 | 854 | $config = $c->getConfig(); |
| 855 | 855 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -872,49 +872,49 @@ discard block |
||
| 872 | 872 | }); |
| 873 | 873 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
| 874 | 874 | |
| 875 | - $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
|
| 875 | + $this->registerService(\OCP\Files\Mount\IMountManager::class, function() { |
|
| 876 | 876 | return new \OC\Files\Mount\Manager(); |
| 877 | 877 | }); |
| 878 | 878 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
| 879 | 879 | |
| 880 | - $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
|
| 880 | + $this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) { |
|
| 881 | 881 | return new \OC\Files\Type\Detection( |
| 882 | 882 | $c->getURLGenerator(), |
| 883 | 883 | \OC::$configDir, |
| 884 | - \OC::$SERVERROOT . '/resources/config/' |
|
| 884 | + \OC::$SERVERROOT.'/resources/config/' |
|
| 885 | 885 | ); |
| 886 | 886 | }); |
| 887 | 887 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
| 888 | 888 | |
| 889 | - $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
|
| 889 | + $this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) { |
|
| 890 | 890 | return new \OC\Files\Type\Loader( |
| 891 | 891 | $c->getDatabaseConnection() |
| 892 | 892 | ); |
| 893 | 893 | }); |
| 894 | 894 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
| 895 | - $this->registerService(BundleFetcher::class, function () { |
|
| 895 | + $this->registerService(BundleFetcher::class, function() { |
|
| 896 | 896 | return new BundleFetcher($this->getL10N('lib')); |
| 897 | 897 | }); |
| 898 | - $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
|
| 898 | + $this->registerService(\OCP\Notification\IManager::class, function(Server $c) { |
|
| 899 | 899 | return new Manager( |
| 900 | 900 | $c->query(IValidator::class) |
| 901 | 901 | ); |
| 902 | 902 | }); |
| 903 | 903 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
| 904 | 904 | |
| 905 | - $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
|
| 905 | + $this->registerService(\OC\CapabilitiesManager::class, function(Server $c) { |
|
| 906 | 906 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
| 907 | - $manager->registerCapability(function () use ($c) { |
|
| 907 | + $manager->registerCapability(function() use ($c) { |
|
| 908 | 908 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
| 909 | 909 | }); |
| 910 | - $manager->registerCapability(function () use ($c) { |
|
| 910 | + $manager->registerCapability(function() use ($c) { |
|
| 911 | 911 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
| 912 | 912 | }); |
| 913 | 913 | return $manager; |
| 914 | 914 | }); |
| 915 | 915 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
| 916 | 916 | |
| 917 | - $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
|
| 917 | + $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) { |
|
| 918 | 918 | $config = $c->getConfig(); |
| 919 | 919 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
| 920 | 920 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
| 925 | 925 | $manager = $c->getUserManager(); |
| 926 | 926 | $user = $manager->get($id); |
| 927 | - if(is_null($user)) { |
|
| 927 | + if (is_null($user)) { |
|
| 928 | 928 | $l = $c->getL10N('core'); |
| 929 | 929 | $displayName = $l->t('Unknown user'); |
| 930 | 930 | } else { |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | }); |
| 938 | 938 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
| 939 | 939 | |
| 940 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
| 940 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
| 941 | 941 | /* |
| 942 | 942 | * Dark magic for autoloader. |
| 943 | 943 | * If we do a class_exists it will try to load the class which will |
@@ -965,7 +965,7 @@ discard block |
||
| 965 | 965 | } |
| 966 | 966 | return new \OC_Defaults(); |
| 967 | 967 | }); |
| 968 | - $this->registerService(SCSSCacher::class, function (Server $c) { |
|
| 968 | + $this->registerService(SCSSCacher::class, function(Server $c) { |
|
| 969 | 969 | return new SCSSCacher( |
| 970 | 970 | $c->getLogger(), |
| 971 | 971 | $c->query(\OC\Files\AppData\Factory::class), |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | new TimeFactory() |
| 979 | 979 | ); |
| 980 | 980 | }); |
| 981 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
| 981 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
| 982 | 982 | return new JSCombiner( |
| 983 | 983 | $c->getAppDataDir('js'), |
| 984 | 984 | $c->getURLGenerator(), |
@@ -991,7 +991,7 @@ discard block |
||
| 991 | 991 | $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
| 992 | 992 | $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
| 993 | 993 | |
| 994 | - $this->registerService('CryptoWrapper', function (Server $c) { |
|
| 994 | + $this->registerService('CryptoWrapper', function(Server $c) { |
|
| 995 | 995 | // FIXME: Instantiiated here due to cyclic dependency |
| 996 | 996 | $request = new Request( |
| 997 | 997 | [ |
@@ -1016,7 +1016,7 @@ discard block |
||
| 1016 | 1016 | $request |
| 1017 | 1017 | ); |
| 1018 | 1018 | }); |
| 1019 | - $this->registerService('CsrfTokenManager', function (Server $c) { |
|
| 1019 | + $this->registerService('CsrfTokenManager', function(Server $c) { |
|
| 1020 | 1020 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
| 1021 | 1021 | |
| 1022 | 1022 | return new CsrfTokenManager( |
@@ -1024,22 +1024,22 @@ discard block |
||
| 1024 | 1024 | $c->query(SessionStorage::class) |
| 1025 | 1025 | ); |
| 1026 | 1026 | }); |
| 1027 | - $this->registerService(SessionStorage::class, function (Server $c) { |
|
| 1027 | + $this->registerService(SessionStorage::class, function(Server $c) { |
|
| 1028 | 1028 | return new SessionStorage($c->getSession()); |
| 1029 | 1029 | }); |
| 1030 | - $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
|
| 1030 | + $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) { |
|
| 1031 | 1031 | return new ContentSecurityPolicyManager(); |
| 1032 | 1032 | }); |
| 1033 | 1033 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
| 1034 | 1034 | |
| 1035 | - $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
|
| 1035 | + $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
|
| 1036 | 1036 | return new ContentSecurityPolicyNonceManager( |
| 1037 | 1037 | $c->getCsrfTokenManager(), |
| 1038 | 1038 | $c->getRequest() |
| 1039 | 1039 | ); |
| 1040 | 1040 | }); |
| 1041 | 1041 | |
| 1042 | - $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
|
| 1042 | + $this->registerService(\OCP\Share\IManager::class, function(Server $c) { |
|
| 1043 | 1043 | $config = $c->getConfig(); |
| 1044 | 1044 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
| 1045 | 1045 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1086,7 +1086,7 @@ discard block |
||
| 1086 | 1086 | |
| 1087 | 1087 | $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
| 1088 | 1088 | |
| 1089 | - $this->registerService('SettingsManager', function (Server $c) { |
|
| 1089 | + $this->registerService('SettingsManager', function(Server $c) { |
|
| 1090 | 1090 | $manager = new \OC\Settings\Manager( |
| 1091 | 1091 | $c->getLogger(), |
| 1092 | 1092 | $c->getL10NFactory(), |
@@ -1095,36 +1095,36 @@ discard block |
||
| 1095 | 1095 | ); |
| 1096 | 1096 | return $manager; |
| 1097 | 1097 | }); |
| 1098 | - $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
|
| 1098 | + $this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) { |
|
| 1099 | 1099 | return new \OC\Files\AppData\Factory( |
| 1100 | 1100 | $c->getRootFolder(), |
| 1101 | 1101 | $c->getSystemConfig() |
| 1102 | 1102 | ); |
| 1103 | 1103 | }); |
| 1104 | 1104 | |
| 1105 | - $this->registerService('LockdownManager', function (Server $c) { |
|
| 1106 | - return new LockdownManager(function () use ($c) { |
|
| 1105 | + $this->registerService('LockdownManager', function(Server $c) { |
|
| 1106 | + return new LockdownManager(function() use ($c) { |
|
| 1107 | 1107 | return $c->getSession(); |
| 1108 | 1108 | }); |
| 1109 | 1109 | }); |
| 1110 | 1110 | |
| 1111 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
|
| 1111 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) { |
|
| 1112 | 1112 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
| 1113 | 1113 | }); |
| 1114 | 1114 | |
| 1115 | - $this->registerService(ICloudIdManager::class, function (Server $c) { |
|
| 1115 | + $this->registerService(ICloudIdManager::class, function(Server $c) { |
|
| 1116 | 1116 | return new CloudIdManager(); |
| 1117 | 1117 | }); |
| 1118 | 1118 | |
| 1119 | - $this->registerService(IConfig::class, function (Server $c) { |
|
| 1119 | + $this->registerService(IConfig::class, function(Server $c) { |
|
| 1120 | 1120 | return new GlobalScale\Config($c->getConfig()); |
| 1121 | 1121 | }); |
| 1122 | 1122 | |
| 1123 | - $this->registerService(ICloudFederationProviderManager::class, function (Server $c) { |
|
| 1123 | + $this->registerService(ICloudFederationProviderManager::class, function(Server $c) { |
|
| 1124 | 1124 | return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger()); |
| 1125 | 1125 | }); |
| 1126 | 1126 | |
| 1127 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
| 1127 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
| 1128 | 1128 | return new CloudFederationFactory(); |
| 1129 | 1129 | }); |
| 1130 | 1130 | |
@@ -1134,18 +1134,18 @@ discard block |
||
| 1134 | 1134 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
| 1135 | 1135 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
| 1136 | 1136 | |
| 1137 | - $this->registerService(Defaults::class, function (Server $c) { |
|
| 1137 | + $this->registerService(Defaults::class, function(Server $c) { |
|
| 1138 | 1138 | return new Defaults( |
| 1139 | 1139 | $c->getThemingDefaults() |
| 1140 | 1140 | ); |
| 1141 | 1141 | }); |
| 1142 | 1142 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
| 1143 | 1143 | |
| 1144 | - $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
|
| 1144 | + $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) { |
|
| 1145 | 1145 | return $c->query(\OCP\IUserSession::class)->getSession(); |
| 1146 | 1146 | }); |
| 1147 | 1147 | |
| 1148 | - $this->registerService(IShareHelper::class, function (Server $c) { |
|
| 1148 | + $this->registerService(IShareHelper::class, function(Server $c) { |
|
| 1149 | 1149 | return new ShareHelper( |
| 1150 | 1150 | $c->query(\OCP\Share\IManager::class) |
| 1151 | 1151 | ); |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
| 1189 | 1189 | $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
| 1190 | 1190 | |
| 1191 | - $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) { |
|
| 1191 | + $this->registerService(\OC\Security\IdentityProof\Manager::class, function(Server $c) { |
|
| 1192 | 1192 | return new \OC\Security\IdentityProof\Manager( |
| 1193 | 1193 | $c->query(\OC\Files\AppData\Factory::class), |
| 1194 | 1194 | $c->getCrypto(), |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | // no avatar to remove |
| 1242 | 1242 | } catch (\Exception $e) { |
| 1243 | 1243 | // Ignore exceptions |
| 1244 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
| 1244 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
| 1245 | 1245 | } |
| 1246 | 1246 | }); |
| 1247 | 1247 | |
| 1248 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
| 1248 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
| 1249 | 1249 | $manager = $this->getAvatarManager(); |
| 1250 | 1250 | /** @var IUser $user */ |
| 1251 | 1251 | $user = $e->getSubject(); |
@@ -1401,7 +1401,7 @@ discard block |
||
| 1401 | 1401 | * @deprecated since 9.2.0 use IAppData |
| 1402 | 1402 | */ |
| 1403 | 1403 | public function getAppFolder() { |
| 1404 | - $dir = '/' . \OC_App::getCurrentApp(); |
|
| 1404 | + $dir = '/'.\OC_App::getCurrentApp(); |
|
| 1405 | 1405 | $root = $this->getRootFolder(); |
| 1406 | 1406 | if (!$root->nodeExists($dir)) { |
| 1407 | 1407 | $folder = $root->newFolder($dir); |
@@ -1976,7 +1976,7 @@ discard block |
||
| 1976 | 1976 | /** |
| 1977 | 1977 | * @return \OCP\Collaboration\AutoComplete\IManager |
| 1978 | 1978 | */ |
| 1979 | - public function getAutoCompleteManager(){ |
|
| 1979 | + public function getAutoCompleteManager() { |
|
| 1980 | 1980 | return $this->query(IManager::class); |
| 1981 | 1981 | } |
| 1982 | 1982 | |
@@ -74,405 +74,405 @@ |
||
| 74 | 74 | * Class for user management in a SQL Database (e.g. MySQL, SQLite) |
| 75 | 75 | */ |
| 76 | 76 | class Database extends ABackend |
| 77 | - implements ICreateUserBackend, |
|
| 78 | - ISetPasswordBackend, |
|
| 79 | - ISetDisplayNameBackend, |
|
| 80 | - IGetDisplayNameBackend, |
|
| 81 | - ICheckPasswordBackend, |
|
| 82 | - IGetHomeBackend, |
|
| 83 | - ICountUsersBackend { |
|
| 84 | - /** @var CappedMemoryCache */ |
|
| 85 | - private $cache; |
|
| 86 | - |
|
| 87 | - /** @var EventDispatcherInterface */ |
|
| 88 | - private $eventDispatcher; |
|
| 89 | - |
|
| 90 | - /** @var IDBConnection */ |
|
| 91 | - private $dbConn; |
|
| 92 | - |
|
| 93 | - /** @var string */ |
|
| 94 | - private $table; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * \OC\User\Database constructor. |
|
| 98 | - * |
|
| 99 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 100 | - * @param string $table |
|
| 101 | - */ |
|
| 102 | - public function __construct($eventDispatcher = null, $table = 'users') { |
|
| 103 | - $this->cache = new CappedMemoryCache(); |
|
| 104 | - $this->table = $table; |
|
| 105 | - $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->getEventDispatcher(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * FIXME: This function should not be required! |
|
| 110 | - */ |
|
| 111 | - private function fixDI() { |
|
| 112 | - if ($this->dbConn === null) { |
|
| 113 | - $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Create a new user |
|
| 119 | - * |
|
| 120 | - * @param string $uid The username of the user to create |
|
| 121 | - * @param string $password The password of the new user |
|
| 122 | - * @return bool |
|
| 123 | - * |
|
| 124 | - * Creates a new user. Basic checking of username is done in OC_User |
|
| 125 | - * itself, not in its subclasses. |
|
| 126 | - */ |
|
| 127 | - public function createUser(string $uid, string $password): bool { |
|
| 128 | - $this->fixDI(); |
|
| 129 | - |
|
| 130 | - if (!$this->userExists($uid)) { |
|
| 131 | - $event = new GenericEvent($password); |
|
| 132 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
| 133 | - |
|
| 134 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 135 | - $qb->insert($this->table) |
|
| 136 | - ->values([ |
|
| 137 | - 'uid' => $qb->createNamedParameter($uid), |
|
| 138 | - 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)), |
|
| 139 | - 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)), |
|
| 140 | - ]); |
|
| 141 | - |
|
| 142 | - $result = $qb->execute(); |
|
| 143 | - |
|
| 144 | - // Clear cache |
|
| 145 | - unset($this->cache[$uid]); |
|
| 146 | - |
|
| 147 | - return $result ? true : false; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return false; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * delete a user |
|
| 155 | - * |
|
| 156 | - * @param string $uid The username of the user to delete |
|
| 157 | - * @return bool |
|
| 158 | - * |
|
| 159 | - * Deletes a user |
|
| 160 | - */ |
|
| 161 | - public function deleteUser($uid) { |
|
| 162 | - $this->fixDI(); |
|
| 163 | - |
|
| 164 | - // Delete user-group-relation |
|
| 165 | - $query = $this->dbConn->getQueryBuilder(); |
|
| 166 | - $query->delete($this->table) |
|
| 167 | - ->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid)))); |
|
| 168 | - $result = $query->execute(); |
|
| 169 | - |
|
| 170 | - if (isset($this->cache[$uid])) { |
|
| 171 | - unset($this->cache[$uid]); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return $result ? true : false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - private function updatePassword(string $uid, string $passwordHash): bool { |
|
| 178 | - $query = $this->dbConn->getQueryBuilder(); |
|
| 179 | - $query->update($this->table) |
|
| 180 | - ->set('password', $query->createNamedParameter($passwordHash)) |
|
| 181 | - ->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid)))); |
|
| 182 | - $result = $query->execute(); |
|
| 183 | - |
|
| 184 | - return $result ? true : false; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Set password |
|
| 189 | - * |
|
| 190 | - * @param string $uid The username |
|
| 191 | - * @param string $password The new password |
|
| 192 | - * @return bool |
|
| 193 | - * |
|
| 194 | - * Change the password of a user |
|
| 195 | - */ |
|
| 196 | - public function setPassword(string $uid, string $password): bool { |
|
| 197 | - $this->fixDI(); |
|
| 198 | - |
|
| 199 | - if ($this->userExists($uid)) { |
|
| 200 | - $event = new GenericEvent($password); |
|
| 201 | - $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
| 202 | - |
|
| 203 | - $hasher = \OC::$server->getHasher(); |
|
| 204 | - $hashedPassword = $hasher->hash($password); |
|
| 205 | - |
|
| 206 | - return $this->updatePassword($uid, $hashedPassword); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Set display name |
|
| 214 | - * |
|
| 215 | - * @param string $uid The username |
|
| 216 | - * @param string $displayName The new display name |
|
| 217 | - * @return bool |
|
| 218 | - * |
|
| 219 | - * Change the display name of a user |
|
| 220 | - */ |
|
| 221 | - public function setDisplayName(string $uid, string $displayName): bool { |
|
| 222 | - $this->fixDI(); |
|
| 223 | - |
|
| 224 | - if ($this->userExists($uid)) { |
|
| 225 | - $query = $this->dbConn->getQueryBuilder(); |
|
| 226 | - $query->update($this->table) |
|
| 227 | - ->set('displayname', $query->createNamedParameter($displayName)) |
|
| 228 | - ->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid)))); |
|
| 229 | - $query->execute(); |
|
| 230 | - |
|
| 231 | - $this->cache[$uid]['displayname'] = $displayName; |
|
| 232 | - |
|
| 233 | - return true; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return false; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * get display name of the user |
|
| 241 | - * |
|
| 242 | - * @param string $uid user ID of the user |
|
| 243 | - * @return string display name |
|
| 244 | - */ |
|
| 245 | - public function getDisplayName($uid): string { |
|
| 246 | - $uid = (string)$uid; |
|
| 247 | - $this->loadUser($uid); |
|
| 248 | - return empty($this->cache[$uid]['displayname']) ? $uid : $this->cache[$uid]['displayname']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Get a list of all display names and user ids. |
|
| 253 | - * |
|
| 254 | - * @param string $search |
|
| 255 | - * @param string|null $limit |
|
| 256 | - * @param string|null $offset |
|
| 257 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 258 | - */ |
|
| 259 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 260 | - $this->fixDI(); |
|
| 261 | - |
|
| 262 | - $query = $this->dbConn->getQueryBuilder(); |
|
| 263 | - |
|
| 264 | - $query->select('uid', 'displayname') |
|
| 265 | - ->from($this->table, 'u') |
|
| 266 | - ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( |
|
| 267 | - $query->expr()->eq('userid', 'uid'), |
|
| 268 | - $query->expr()->eq('appid', $query->expr()->literal('settings')), |
|
| 269 | - $query->expr()->eq('configkey', $query->expr()->literal('email'))) |
|
| 270 | - ) |
|
| 271 | - // sqlite doesn't like re-using a single named parameter here |
|
| 272 | - ->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
| 273 | - ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
| 274 | - ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
| 275 | - ->orderBy($query->func()->lower('displayname'), 'ASC') |
|
| 276 | - ->orderBy('uid_lower', 'ASC') |
|
| 277 | - ->setMaxResults($limit) |
|
| 278 | - ->setFirstResult($offset); |
|
| 279 | - |
|
| 280 | - $result = $query->execute(); |
|
| 281 | - $displayNames = []; |
|
| 282 | - while ($row = $result->fetch()) { |
|
| 283 | - $displayNames[(string)$row['uid']] = (string)$row['displayname']; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - return $displayNames; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Check if the password is correct |
|
| 291 | - * |
|
| 292 | - * @param string $uid The username |
|
| 293 | - * @param string $password The password |
|
| 294 | - * @return string |
|
| 295 | - * |
|
| 296 | - * Check if the password is correct without logging in the user |
|
| 297 | - * returns the user id or false |
|
| 298 | - */ |
|
| 299 | - public function checkPassword(string $uid, string $password) { |
|
| 300 | - $this->fixDI(); |
|
| 301 | - |
|
| 302 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 303 | - $qb->select('uid', 'password') |
|
| 304 | - ->from($this->table) |
|
| 305 | - ->where( |
|
| 306 | - $qb->expr()->eq( |
|
| 307 | - 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
| 308 | - ) |
|
| 309 | - ); |
|
| 310 | - $result = $qb->execute(); |
|
| 311 | - $row = $result->fetch(); |
|
| 312 | - $result->closeCursor(); |
|
| 313 | - |
|
| 314 | - if ($row) { |
|
| 315 | - $storedHash = $row['password']; |
|
| 316 | - $newHash = ''; |
|
| 317 | - if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) { |
|
| 318 | - if (!empty($newHash)) { |
|
| 319 | - $this->updatePassword($uid, $newHash); |
|
| 320 | - } |
|
| 321 | - return (string)$row['uid']; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Load an user in the cache |
|
| 331 | - * |
|
| 332 | - * @param string $uid the username |
|
| 333 | - * @return boolean true if user was found, false otherwise |
|
| 334 | - */ |
|
| 335 | - private function loadUser($uid) { |
|
| 336 | - $this->fixDI(); |
|
| 337 | - |
|
| 338 | - $uid = (string)$uid; |
|
| 339 | - if (!isset($this->cache[$uid])) { |
|
| 340 | - //guests $uid could be NULL or '' |
|
| 341 | - if ($uid === '') { |
|
| 342 | - $this->cache[$uid] = false; |
|
| 343 | - return true; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - $qb = $this->dbConn->getQueryBuilder(); |
|
| 347 | - $qb->select('uid', 'displayname') |
|
| 348 | - ->from($this->table) |
|
| 349 | - ->where( |
|
| 350 | - $qb->expr()->eq( |
|
| 351 | - 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
| 352 | - ) |
|
| 353 | - ); |
|
| 354 | - $result = $qb->execute(); |
|
| 355 | - $row = $result->fetch(); |
|
| 356 | - $result->closeCursor(); |
|
| 357 | - |
|
| 358 | - $this->cache[$uid] = false; |
|
| 359 | - |
|
| 360 | - // "uid" is primary key, so there can only be a single result |
|
| 361 | - if ($row !== false) { |
|
| 362 | - $this->cache[$uid]['uid'] = (string)$row['uid']; |
|
| 363 | - $this->cache[$uid]['displayname'] = (string)$row['displayname']; |
|
| 364 | - } else { |
|
| 365 | - return false; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - return true; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Get a list of all users |
|
| 374 | - * |
|
| 375 | - * @param string $search |
|
| 376 | - * @param null|int $limit |
|
| 377 | - * @param null|int $offset |
|
| 378 | - * @return string[] an array of all uids |
|
| 379 | - */ |
|
| 380 | - public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 381 | - $users = $this->getDisplayNames($search, $limit, $offset); |
|
| 382 | - $userIds = array_map(function ($uid) { |
|
| 383 | - return (string)$uid; |
|
| 384 | - }, array_keys($users)); |
|
| 385 | - sort($userIds, SORT_STRING | SORT_FLAG_CASE); |
|
| 386 | - return $userIds; |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * check if a user exists |
|
| 391 | - * |
|
| 392 | - * @param string $uid the username |
|
| 393 | - * @return boolean |
|
| 394 | - */ |
|
| 395 | - public function userExists($uid) { |
|
| 396 | - $this->loadUser($uid); |
|
| 397 | - return $this->cache[$uid] !== false; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * get the user's home directory |
|
| 402 | - * |
|
| 403 | - * @param string $uid the username |
|
| 404 | - * @return string|false |
|
| 405 | - */ |
|
| 406 | - public function getHome(string $uid) { |
|
| 407 | - if ($this->userExists($uid)) { |
|
| 408 | - return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - return false; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - /** |
|
| 415 | - * @return bool |
|
| 416 | - */ |
|
| 417 | - public function hasUserListings() { |
|
| 418 | - return true; |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * counts the users in the database |
|
| 423 | - * |
|
| 424 | - * @return int|bool |
|
| 425 | - */ |
|
| 426 | - public function countUsers() { |
|
| 427 | - $this->fixDI(); |
|
| 428 | - |
|
| 429 | - $query = $this->dbConn->getQueryBuilder(); |
|
| 430 | - $query->select($query->func()->count('uid')) |
|
| 431 | - ->from($this->table); |
|
| 432 | - $result = $query->execute(); |
|
| 433 | - |
|
| 434 | - return $result->fetchColumn(); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * returns the username for the given login name in the correct casing |
|
| 439 | - * |
|
| 440 | - * @param string $loginName |
|
| 441 | - * @return string|false |
|
| 442 | - */ |
|
| 443 | - public function loginName2UserName($loginName) { |
|
| 444 | - if ($this->userExists($loginName)) { |
|
| 445 | - return $this->cache[$loginName]['uid']; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return false; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Backend name to be shown in user management |
|
| 453 | - * |
|
| 454 | - * @return string the name of the backend to be shown |
|
| 455 | - */ |
|
| 456 | - public function getBackendName() { |
|
| 457 | - return 'Database'; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - public static function preLoginNameUsedAsUserName($param) { |
|
| 461 | - if (!isset($param['uid'])) { |
|
| 462 | - throw new \Exception('key uid is expected to be set in $param'); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - $backends = \OC::$server->getUserManager()->getBackends(); |
|
| 466 | - foreach ($backends as $backend) { |
|
| 467 | - if ($backend instanceof Database) { |
|
| 468 | - /** @var \OC\User\Database $backend */ |
|
| 469 | - $uid = $backend->loginName2UserName($param['uid']); |
|
| 470 | - if ($uid !== false) { |
|
| 471 | - $param['uid'] = $uid; |
|
| 472 | - return; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - } |
|
| 77 | + implements ICreateUserBackend, |
|
| 78 | + ISetPasswordBackend, |
|
| 79 | + ISetDisplayNameBackend, |
|
| 80 | + IGetDisplayNameBackend, |
|
| 81 | + ICheckPasswordBackend, |
|
| 82 | + IGetHomeBackend, |
|
| 83 | + ICountUsersBackend { |
|
| 84 | + /** @var CappedMemoryCache */ |
|
| 85 | + private $cache; |
|
| 86 | + |
|
| 87 | + /** @var EventDispatcherInterface */ |
|
| 88 | + private $eventDispatcher; |
|
| 89 | + |
|
| 90 | + /** @var IDBConnection */ |
|
| 91 | + private $dbConn; |
|
| 92 | + |
|
| 93 | + /** @var string */ |
|
| 94 | + private $table; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * \OC\User\Database constructor. |
|
| 98 | + * |
|
| 99 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 100 | + * @param string $table |
|
| 101 | + */ |
|
| 102 | + public function __construct($eventDispatcher = null, $table = 'users') { |
|
| 103 | + $this->cache = new CappedMemoryCache(); |
|
| 104 | + $this->table = $table; |
|
| 105 | + $this->eventDispatcher = $eventDispatcher ? $eventDispatcher : \OC::$server->getEventDispatcher(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * FIXME: This function should not be required! |
|
| 110 | + */ |
|
| 111 | + private function fixDI() { |
|
| 112 | + if ($this->dbConn === null) { |
|
| 113 | + $this->dbConn = \OC::$server->getDatabaseConnection(); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Create a new user |
|
| 119 | + * |
|
| 120 | + * @param string $uid The username of the user to create |
|
| 121 | + * @param string $password The password of the new user |
|
| 122 | + * @return bool |
|
| 123 | + * |
|
| 124 | + * Creates a new user. Basic checking of username is done in OC_User |
|
| 125 | + * itself, not in its subclasses. |
|
| 126 | + */ |
|
| 127 | + public function createUser(string $uid, string $password): bool { |
|
| 128 | + $this->fixDI(); |
|
| 129 | + |
|
| 130 | + if (!$this->userExists($uid)) { |
|
| 131 | + $event = new GenericEvent($password); |
|
| 132 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
| 133 | + |
|
| 134 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 135 | + $qb->insert($this->table) |
|
| 136 | + ->values([ |
|
| 137 | + 'uid' => $qb->createNamedParameter($uid), |
|
| 138 | + 'password' => $qb->createNamedParameter(\OC::$server->getHasher()->hash($password)), |
|
| 139 | + 'uid_lower' => $qb->createNamedParameter(mb_strtolower($uid)), |
|
| 140 | + ]); |
|
| 141 | + |
|
| 142 | + $result = $qb->execute(); |
|
| 143 | + |
|
| 144 | + // Clear cache |
|
| 145 | + unset($this->cache[$uid]); |
|
| 146 | + |
|
| 147 | + return $result ? true : false; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return false; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * delete a user |
|
| 155 | + * |
|
| 156 | + * @param string $uid The username of the user to delete |
|
| 157 | + * @return bool |
|
| 158 | + * |
|
| 159 | + * Deletes a user |
|
| 160 | + */ |
|
| 161 | + public function deleteUser($uid) { |
|
| 162 | + $this->fixDI(); |
|
| 163 | + |
|
| 164 | + // Delete user-group-relation |
|
| 165 | + $query = $this->dbConn->getQueryBuilder(); |
|
| 166 | + $query->delete($this->table) |
|
| 167 | + ->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid)))); |
|
| 168 | + $result = $query->execute(); |
|
| 169 | + |
|
| 170 | + if (isset($this->cache[$uid])) { |
|
| 171 | + unset($this->cache[$uid]); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return $result ? true : false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + private function updatePassword(string $uid, string $passwordHash): bool { |
|
| 178 | + $query = $this->dbConn->getQueryBuilder(); |
|
| 179 | + $query->update($this->table) |
|
| 180 | + ->set('password', $query->createNamedParameter($passwordHash)) |
|
| 181 | + ->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid)))); |
|
| 182 | + $result = $query->execute(); |
|
| 183 | + |
|
| 184 | + return $result ? true : false; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Set password |
|
| 189 | + * |
|
| 190 | + * @param string $uid The username |
|
| 191 | + * @param string $password The new password |
|
| 192 | + * @return bool |
|
| 193 | + * |
|
| 194 | + * Change the password of a user |
|
| 195 | + */ |
|
| 196 | + public function setPassword(string $uid, string $password): bool { |
|
| 197 | + $this->fixDI(); |
|
| 198 | + |
|
| 199 | + if ($this->userExists($uid)) { |
|
| 200 | + $event = new GenericEvent($password); |
|
| 201 | + $this->eventDispatcher->dispatch('OCP\PasswordPolicy::validate', $event); |
|
| 202 | + |
|
| 203 | + $hasher = \OC::$server->getHasher(); |
|
| 204 | + $hashedPassword = $hasher->hash($password); |
|
| 205 | + |
|
| 206 | + return $this->updatePassword($uid, $hashedPassword); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Set display name |
|
| 214 | + * |
|
| 215 | + * @param string $uid The username |
|
| 216 | + * @param string $displayName The new display name |
|
| 217 | + * @return bool |
|
| 218 | + * |
|
| 219 | + * Change the display name of a user |
|
| 220 | + */ |
|
| 221 | + public function setDisplayName(string $uid, string $displayName): bool { |
|
| 222 | + $this->fixDI(); |
|
| 223 | + |
|
| 224 | + if ($this->userExists($uid)) { |
|
| 225 | + $query = $this->dbConn->getQueryBuilder(); |
|
| 226 | + $query->update($this->table) |
|
| 227 | + ->set('displayname', $query->createNamedParameter($displayName)) |
|
| 228 | + ->where($query->expr()->eq('uid_lower', $query->createNamedParameter(mb_strtolower($uid)))); |
|
| 229 | + $query->execute(); |
|
| 230 | + |
|
| 231 | + $this->cache[$uid]['displayname'] = $displayName; |
|
| 232 | + |
|
| 233 | + return true; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return false; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * get display name of the user |
|
| 241 | + * |
|
| 242 | + * @param string $uid user ID of the user |
|
| 243 | + * @return string display name |
|
| 244 | + */ |
|
| 245 | + public function getDisplayName($uid): string { |
|
| 246 | + $uid = (string)$uid; |
|
| 247 | + $this->loadUser($uid); |
|
| 248 | + return empty($this->cache[$uid]['displayname']) ? $uid : $this->cache[$uid]['displayname']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Get a list of all display names and user ids. |
|
| 253 | + * |
|
| 254 | + * @param string $search |
|
| 255 | + * @param string|null $limit |
|
| 256 | + * @param string|null $offset |
|
| 257 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
| 258 | + */ |
|
| 259 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
| 260 | + $this->fixDI(); |
|
| 261 | + |
|
| 262 | + $query = $this->dbConn->getQueryBuilder(); |
|
| 263 | + |
|
| 264 | + $query->select('uid', 'displayname') |
|
| 265 | + ->from($this->table, 'u') |
|
| 266 | + ->leftJoin('u', 'preferences', 'p', $query->expr()->andX( |
|
| 267 | + $query->expr()->eq('userid', 'uid'), |
|
| 268 | + $query->expr()->eq('appid', $query->expr()->literal('settings')), |
|
| 269 | + $query->expr()->eq('configkey', $query->expr()->literal('email'))) |
|
| 270 | + ) |
|
| 271 | + // sqlite doesn't like re-using a single named parameter here |
|
| 272 | + ->where($query->expr()->iLike('uid', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
| 273 | + ->orWhere($query->expr()->iLike('displayname', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
| 274 | + ->orWhere($query->expr()->iLike('configvalue', $query->createPositionalParameter('%' . $this->dbConn->escapeLikeParameter($search) . '%'))) |
|
| 275 | + ->orderBy($query->func()->lower('displayname'), 'ASC') |
|
| 276 | + ->orderBy('uid_lower', 'ASC') |
|
| 277 | + ->setMaxResults($limit) |
|
| 278 | + ->setFirstResult($offset); |
|
| 279 | + |
|
| 280 | + $result = $query->execute(); |
|
| 281 | + $displayNames = []; |
|
| 282 | + while ($row = $result->fetch()) { |
|
| 283 | + $displayNames[(string)$row['uid']] = (string)$row['displayname']; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + return $displayNames; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Check if the password is correct |
|
| 291 | + * |
|
| 292 | + * @param string $uid The username |
|
| 293 | + * @param string $password The password |
|
| 294 | + * @return string |
|
| 295 | + * |
|
| 296 | + * Check if the password is correct without logging in the user |
|
| 297 | + * returns the user id or false |
|
| 298 | + */ |
|
| 299 | + public function checkPassword(string $uid, string $password) { |
|
| 300 | + $this->fixDI(); |
|
| 301 | + |
|
| 302 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 303 | + $qb->select('uid', 'password') |
|
| 304 | + ->from($this->table) |
|
| 305 | + ->where( |
|
| 306 | + $qb->expr()->eq( |
|
| 307 | + 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
| 308 | + ) |
|
| 309 | + ); |
|
| 310 | + $result = $qb->execute(); |
|
| 311 | + $row = $result->fetch(); |
|
| 312 | + $result->closeCursor(); |
|
| 313 | + |
|
| 314 | + if ($row) { |
|
| 315 | + $storedHash = $row['password']; |
|
| 316 | + $newHash = ''; |
|
| 317 | + if (\OC::$server->getHasher()->verify($password, $storedHash, $newHash)) { |
|
| 318 | + if (!empty($newHash)) { |
|
| 319 | + $this->updatePassword($uid, $newHash); |
|
| 320 | + } |
|
| 321 | + return (string)$row['uid']; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Load an user in the cache |
|
| 331 | + * |
|
| 332 | + * @param string $uid the username |
|
| 333 | + * @return boolean true if user was found, false otherwise |
|
| 334 | + */ |
|
| 335 | + private function loadUser($uid) { |
|
| 336 | + $this->fixDI(); |
|
| 337 | + |
|
| 338 | + $uid = (string)$uid; |
|
| 339 | + if (!isset($this->cache[$uid])) { |
|
| 340 | + //guests $uid could be NULL or '' |
|
| 341 | + if ($uid === '') { |
|
| 342 | + $this->cache[$uid] = false; |
|
| 343 | + return true; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + $qb = $this->dbConn->getQueryBuilder(); |
|
| 347 | + $qb->select('uid', 'displayname') |
|
| 348 | + ->from($this->table) |
|
| 349 | + ->where( |
|
| 350 | + $qb->expr()->eq( |
|
| 351 | + 'uid_lower', $qb->createNamedParameter(mb_strtolower($uid)) |
|
| 352 | + ) |
|
| 353 | + ); |
|
| 354 | + $result = $qb->execute(); |
|
| 355 | + $row = $result->fetch(); |
|
| 356 | + $result->closeCursor(); |
|
| 357 | + |
|
| 358 | + $this->cache[$uid] = false; |
|
| 359 | + |
|
| 360 | + // "uid" is primary key, so there can only be a single result |
|
| 361 | + if ($row !== false) { |
|
| 362 | + $this->cache[$uid]['uid'] = (string)$row['uid']; |
|
| 363 | + $this->cache[$uid]['displayname'] = (string)$row['displayname']; |
|
| 364 | + } else { |
|
| 365 | + return false; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + return true; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Get a list of all users |
|
| 374 | + * |
|
| 375 | + * @param string $search |
|
| 376 | + * @param null|int $limit |
|
| 377 | + * @param null|int $offset |
|
| 378 | + * @return string[] an array of all uids |
|
| 379 | + */ |
|
| 380 | + public function getUsers($search = '', $limit = null, $offset = null) { |
|
| 381 | + $users = $this->getDisplayNames($search, $limit, $offset); |
|
| 382 | + $userIds = array_map(function ($uid) { |
|
| 383 | + return (string)$uid; |
|
| 384 | + }, array_keys($users)); |
|
| 385 | + sort($userIds, SORT_STRING | SORT_FLAG_CASE); |
|
| 386 | + return $userIds; |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * check if a user exists |
|
| 391 | + * |
|
| 392 | + * @param string $uid the username |
|
| 393 | + * @return boolean |
|
| 394 | + */ |
|
| 395 | + public function userExists($uid) { |
|
| 396 | + $this->loadUser($uid); |
|
| 397 | + return $this->cache[$uid] !== false; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * get the user's home directory |
|
| 402 | + * |
|
| 403 | + * @param string $uid the username |
|
| 404 | + * @return string|false |
|
| 405 | + */ |
|
| 406 | + public function getHome(string $uid) { |
|
| 407 | + if ($this->userExists($uid)) { |
|
| 408 | + return \OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $uid; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + return false; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + /** |
|
| 415 | + * @return bool |
|
| 416 | + */ |
|
| 417 | + public function hasUserListings() { |
|
| 418 | + return true; |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * counts the users in the database |
|
| 423 | + * |
|
| 424 | + * @return int|bool |
|
| 425 | + */ |
|
| 426 | + public function countUsers() { |
|
| 427 | + $this->fixDI(); |
|
| 428 | + |
|
| 429 | + $query = $this->dbConn->getQueryBuilder(); |
|
| 430 | + $query->select($query->func()->count('uid')) |
|
| 431 | + ->from($this->table); |
|
| 432 | + $result = $query->execute(); |
|
| 433 | + |
|
| 434 | + return $result->fetchColumn(); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * returns the username for the given login name in the correct casing |
|
| 439 | + * |
|
| 440 | + * @param string $loginName |
|
| 441 | + * @return string|false |
|
| 442 | + */ |
|
| 443 | + public function loginName2UserName($loginName) { |
|
| 444 | + if ($this->userExists($loginName)) { |
|
| 445 | + return $this->cache[$loginName]['uid']; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return false; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Backend name to be shown in user management |
|
| 453 | + * |
|
| 454 | + * @return string the name of the backend to be shown |
|
| 455 | + */ |
|
| 456 | + public function getBackendName() { |
|
| 457 | + return 'Database'; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + public static function preLoginNameUsedAsUserName($param) { |
|
| 461 | + if (!isset($param['uid'])) { |
|
| 462 | + throw new \Exception('key uid is expected to be set in $param'); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + $backends = \OC::$server->getUserManager()->getBackends(); |
|
| 466 | + foreach ($backends as $backend) { |
|
| 467 | + if ($backend instanceof Database) { |
|
| 468 | + /** @var \OC\User\Database $backend */ |
|
| 469 | + $uid = $backend->loginName2UserName($param['uid']); |
|
| 470 | + if ($uid !== false) { |
|
| 471 | + $param['uid'] = $uid; |
|
| 472 | + return; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + } |
|
| 478 | 478 | } |
@@ -44,272 +44,272 @@ |
||
| 44 | 44 | |
| 45 | 45 | class Migrator { |
| 46 | 46 | |
| 47 | - /** @var \Doctrine\DBAL\Connection */ |
|
| 48 | - protected $connection; |
|
| 49 | - |
|
| 50 | - /** @var ISecureRandom */ |
|
| 51 | - private $random; |
|
| 52 | - |
|
| 53 | - /** @var IConfig */ |
|
| 54 | - protected $config; |
|
| 55 | - |
|
| 56 | - /** @var EventDispatcherInterface */ |
|
| 57 | - private $dispatcher; |
|
| 58 | - |
|
| 59 | - /** @var bool */ |
|
| 60 | - private $noEmit = false; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param \Doctrine\DBAL\Connection|Connection $connection |
|
| 64 | - * @param ISecureRandom $random |
|
| 65 | - * @param IConfig $config |
|
| 66 | - * @param EventDispatcherInterface $dispatcher |
|
| 67 | - */ |
|
| 68 | - public function __construct(\Doctrine\DBAL\Connection $connection, |
|
| 69 | - ISecureRandom $random, |
|
| 70 | - IConfig $config, |
|
| 71 | - EventDispatcherInterface $dispatcher = null) { |
|
| 72 | - $this->connection = $connection; |
|
| 73 | - $this->random = $random; |
|
| 74 | - $this->config = $config; |
|
| 75 | - $this->dispatcher = $dispatcher; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 80 | - */ |
|
| 81 | - public function migrate(Schema $targetSchema) { |
|
| 82 | - $this->noEmit = true; |
|
| 83 | - $this->applySchema($targetSchema); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public function generateChangeScript(Schema $targetSchema) { |
|
| 91 | - $schemaDiff = $this->getDiff($targetSchema, $this->connection); |
|
| 92 | - |
|
| 93 | - $script = ''; |
|
| 94 | - $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); |
|
| 95 | - foreach ($sqls as $sql) { |
|
| 96 | - $script .= $this->convertStatementToScript($sql); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $script; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param Schema $targetSchema |
|
| 104 | - * @throws \OC\DB\MigrationException |
|
| 105 | - */ |
|
| 106 | - public function checkMigrate(Schema $targetSchema) { |
|
| 107 | - $this->noEmit = true; |
|
| 108 | - /**@var \Doctrine\DBAL\Schema\Table[] $tables */ |
|
| 109 | - $tables = $targetSchema->getTables(); |
|
| 110 | - $filterExpression = $this->getFilterExpression(); |
|
| 111 | - $this->connection->getConfiguration()-> |
|
| 112 | - setFilterSchemaAssetsExpression($filterExpression); |
|
| 113 | - $existingTables = $this->connection->getSchemaManager()->listTableNames(); |
|
| 114 | - |
|
| 115 | - $step = 0; |
|
| 116 | - foreach ($tables as $table) { |
|
| 117 | - if (strpos($table->getName(), '.')) { |
|
| 118 | - list(, $tableName) = explode('.', $table->getName()); |
|
| 119 | - } else { |
|
| 120 | - $tableName = $table->getName(); |
|
| 121 | - } |
|
| 122 | - $this->emitCheckStep($tableName, $step++, count($tables)); |
|
| 123 | - // don't need to check for new tables |
|
| 124 | - if (array_search($tableName, $existingTables) !== false) { |
|
| 125 | - $this->checkTableMigrate($table); |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Create a unique name for the temporary table |
|
| 132 | - * |
|
| 133 | - * @param string $name |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - protected function generateTemporaryTableName($name) { |
|
| 137 | - return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Check the migration of a table on a copy so we can detect errors before messing with the real table |
|
| 142 | - * |
|
| 143 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 144 | - * @throws \OC\DB\MigrationException |
|
| 145 | - */ |
|
| 146 | - protected function checkTableMigrate(Table $table) { |
|
| 147 | - $name = $table->getName(); |
|
| 148 | - $tmpName = $this->generateTemporaryTableName($name); |
|
| 149 | - |
|
| 150 | - $this->copyTable($name, $tmpName); |
|
| 151 | - |
|
| 152 | - //create the migration schema for the temporary table |
|
| 153 | - $tmpTable = $this->renameTableSchema($table, $tmpName); |
|
| 154 | - $schemaConfig = new SchemaConfig(); |
|
| 155 | - $schemaConfig->setName($this->connection->getDatabase()); |
|
| 156 | - $schema = new Schema(array($tmpTable), array(), $schemaConfig); |
|
| 157 | - |
|
| 158 | - try { |
|
| 159 | - $this->applySchema($schema); |
|
| 160 | - $this->dropTable($tmpName); |
|
| 161 | - } catch (DBALException $e) { |
|
| 162 | - // pgsql needs to commit it's failed transaction before doing anything else |
|
| 163 | - if ($this->connection->isTransactionActive()) { |
|
| 164 | - $this->connection->commit(); |
|
| 165 | - } |
|
| 166 | - $this->dropTable($tmpName); |
|
| 167 | - throw new MigrationException($table->getName(), $e->getMessage()); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param \Doctrine\DBAL\Schema\Table $table |
|
| 173 | - * @param string $newName |
|
| 174 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 175 | - */ |
|
| 176 | - protected function renameTableSchema(Table $table, $newName) { |
|
| 177 | - /** |
|
| 178 | - * @var \Doctrine\DBAL\Schema\Index[] $indexes |
|
| 179 | - */ |
|
| 180 | - $indexes = $table->getIndexes(); |
|
| 181 | - $newIndexes = array(); |
|
| 182 | - foreach ($indexes as $index) { |
|
| 183 | - if ($index->isPrimary()) { |
|
| 184 | - // do not rename primary key |
|
| 185 | - $indexName = $index->getName(); |
|
| 186 | - } else { |
|
| 187 | - // avoid conflicts in index names |
|
| 188 | - $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 189 | - } |
|
| 190 | - $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // foreign keys are not supported so we just set it to an empty array |
|
| 194 | - return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions()); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - public function createSchema() { |
|
| 198 | - $filterExpression = $this->getFilterExpression(); |
|
| 199 | - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 200 | - return $this->connection->getSchemaManager()->createSchema(); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param Schema $targetSchema |
|
| 205 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 206 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 207 | - * @throws DBALException |
|
| 208 | - */ |
|
| 209 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 210 | - // adjust varchar columns with a length higher then getVarcharMaxLength to clob |
|
| 211 | - foreach ($targetSchema->getTables() as $table) { |
|
| 212 | - foreach ($table->getColumns() as $column) { |
|
| 213 | - if ($column->getType() instanceof StringType) { |
|
| 214 | - if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { |
|
| 215 | - $column->setType(Type::getType('text')); |
|
| 216 | - $column->setLength(null); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $filterExpression = $this->getFilterExpression(); |
|
| 223 | - $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 224 | - $sourceSchema = $connection->getSchemaManager()->createSchema(); |
|
| 225 | - |
|
| 226 | - // remove tables we don't know about |
|
| 227 | - /** @var $table \Doctrine\DBAL\Schema\Table */ |
|
| 228 | - foreach ($sourceSchema->getTables() as $table) { |
|
| 229 | - if (!$targetSchema->hasTable($table->getName())) { |
|
| 230 | - $sourceSchema->dropTable($table->getName()); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - // remove sequences we don't know about |
|
| 234 | - foreach ($sourceSchema->getSequences() as $table) { |
|
| 235 | - if (!$targetSchema->hasSequence($table->getName())) { |
|
| 236 | - $sourceSchema->dropSequence($table->getName()); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - $comparator = new Comparator(); |
|
| 241 | - return $comparator->compare($sourceSchema, $targetSchema); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 246 | - * @param \Doctrine\DBAL\Connection $connection |
|
| 247 | - */ |
|
| 248 | - protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { |
|
| 249 | - if (is_null($connection)) { |
|
| 250 | - $connection = $this->connection; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - $schemaDiff = $this->getDiff($targetSchema, $connection); |
|
| 254 | - |
|
| 255 | - $connection->beginTransaction(); |
|
| 256 | - $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); |
|
| 257 | - $step = 0; |
|
| 258 | - foreach ($sqls as $sql) { |
|
| 259 | - $this->emit($sql, $step++, count($sqls)); |
|
| 260 | - $connection->query($sql); |
|
| 261 | - } |
|
| 262 | - $connection->commit(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @param string $sourceName |
|
| 267 | - * @param string $targetName |
|
| 268 | - */ |
|
| 269 | - protected function copyTable($sourceName, $targetName) { |
|
| 270 | - $quotedSource = $this->connection->quoteIdentifier($sourceName); |
|
| 271 | - $quotedTarget = $this->connection->quoteIdentifier($targetName); |
|
| 272 | - |
|
| 273 | - $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 274 | - $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @param string $name |
|
| 279 | - */ |
|
| 280 | - protected function dropTable($name) { |
|
| 281 | - $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * @param $statement |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - protected function convertStatementToScript($statement) { |
|
| 289 | - $script = $statement . ';'; |
|
| 290 | - $script .= PHP_EOL; |
|
| 291 | - $script .= PHP_EOL; |
|
| 292 | - return $script; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - protected function getFilterExpression() { |
|
| 296 | - return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - protected function emit($sql, $step, $max) { |
|
| 300 | - if ($this->noEmit) { |
|
| 301 | - return; |
|
| 302 | - } |
|
| 303 | - if(is_null($this->dispatcher)) { |
|
| 304 | - return; |
|
| 305 | - } |
|
| 306 | - $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - private function emitCheckStep($tableName, $step, $max) { |
|
| 310 | - if(is_null($this->dispatcher)) { |
|
| 311 | - return; |
|
| 312 | - } |
|
| 313 | - $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 314 | - } |
|
| 47 | + /** @var \Doctrine\DBAL\Connection */ |
|
| 48 | + protected $connection; |
|
| 49 | + |
|
| 50 | + /** @var ISecureRandom */ |
|
| 51 | + private $random; |
|
| 52 | + |
|
| 53 | + /** @var IConfig */ |
|
| 54 | + protected $config; |
|
| 55 | + |
|
| 56 | + /** @var EventDispatcherInterface */ |
|
| 57 | + private $dispatcher; |
|
| 58 | + |
|
| 59 | + /** @var bool */ |
|
| 60 | + private $noEmit = false; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param \Doctrine\DBAL\Connection|Connection $connection |
|
| 64 | + * @param ISecureRandom $random |
|
| 65 | + * @param IConfig $config |
|
| 66 | + * @param EventDispatcherInterface $dispatcher |
|
| 67 | + */ |
|
| 68 | + public function __construct(\Doctrine\DBAL\Connection $connection, |
|
| 69 | + ISecureRandom $random, |
|
| 70 | + IConfig $config, |
|
| 71 | + EventDispatcherInterface $dispatcher = null) { |
|
| 72 | + $this->connection = $connection; |
|
| 73 | + $this->random = $random; |
|
| 74 | + $this->config = $config; |
|
| 75 | + $this->dispatcher = $dispatcher; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 80 | + */ |
|
| 81 | + public function migrate(Schema $targetSchema) { |
|
| 82 | + $this->noEmit = true; |
|
| 83 | + $this->applySchema($targetSchema); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public function generateChangeScript(Schema $targetSchema) { |
|
| 91 | + $schemaDiff = $this->getDiff($targetSchema, $this->connection); |
|
| 92 | + |
|
| 93 | + $script = ''; |
|
| 94 | + $sqls = $schemaDiff->toSql($this->connection->getDatabasePlatform()); |
|
| 95 | + foreach ($sqls as $sql) { |
|
| 96 | + $script .= $this->convertStatementToScript($sql); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $script; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param Schema $targetSchema |
|
| 104 | + * @throws \OC\DB\MigrationException |
|
| 105 | + */ |
|
| 106 | + public function checkMigrate(Schema $targetSchema) { |
|
| 107 | + $this->noEmit = true; |
|
| 108 | + /**@var \Doctrine\DBAL\Schema\Table[] $tables */ |
|
| 109 | + $tables = $targetSchema->getTables(); |
|
| 110 | + $filterExpression = $this->getFilterExpression(); |
|
| 111 | + $this->connection->getConfiguration()-> |
|
| 112 | + setFilterSchemaAssetsExpression($filterExpression); |
|
| 113 | + $existingTables = $this->connection->getSchemaManager()->listTableNames(); |
|
| 114 | + |
|
| 115 | + $step = 0; |
|
| 116 | + foreach ($tables as $table) { |
|
| 117 | + if (strpos($table->getName(), '.')) { |
|
| 118 | + list(, $tableName) = explode('.', $table->getName()); |
|
| 119 | + } else { |
|
| 120 | + $tableName = $table->getName(); |
|
| 121 | + } |
|
| 122 | + $this->emitCheckStep($tableName, $step++, count($tables)); |
|
| 123 | + // don't need to check for new tables |
|
| 124 | + if (array_search($tableName, $existingTables) !== false) { |
|
| 125 | + $this->checkTableMigrate($table); |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Create a unique name for the temporary table |
|
| 132 | + * |
|
| 133 | + * @param string $name |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + protected function generateTemporaryTableName($name) { |
|
| 137 | + return $this->config->getSystemValue('dbtableprefix', 'oc_') . $name . '_' . $this->random->generate(13, ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_DIGITS); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Check the migration of a table on a copy so we can detect errors before messing with the real table |
|
| 142 | + * |
|
| 143 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 144 | + * @throws \OC\DB\MigrationException |
|
| 145 | + */ |
|
| 146 | + protected function checkTableMigrate(Table $table) { |
|
| 147 | + $name = $table->getName(); |
|
| 148 | + $tmpName = $this->generateTemporaryTableName($name); |
|
| 149 | + |
|
| 150 | + $this->copyTable($name, $tmpName); |
|
| 151 | + |
|
| 152 | + //create the migration schema for the temporary table |
|
| 153 | + $tmpTable = $this->renameTableSchema($table, $tmpName); |
|
| 154 | + $schemaConfig = new SchemaConfig(); |
|
| 155 | + $schemaConfig->setName($this->connection->getDatabase()); |
|
| 156 | + $schema = new Schema(array($tmpTable), array(), $schemaConfig); |
|
| 157 | + |
|
| 158 | + try { |
|
| 159 | + $this->applySchema($schema); |
|
| 160 | + $this->dropTable($tmpName); |
|
| 161 | + } catch (DBALException $e) { |
|
| 162 | + // pgsql needs to commit it's failed transaction before doing anything else |
|
| 163 | + if ($this->connection->isTransactionActive()) { |
|
| 164 | + $this->connection->commit(); |
|
| 165 | + } |
|
| 166 | + $this->dropTable($tmpName); |
|
| 167 | + throw new MigrationException($table->getName(), $e->getMessage()); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param \Doctrine\DBAL\Schema\Table $table |
|
| 173 | + * @param string $newName |
|
| 174 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 175 | + */ |
|
| 176 | + protected function renameTableSchema(Table $table, $newName) { |
|
| 177 | + /** |
|
| 178 | + * @var \Doctrine\DBAL\Schema\Index[] $indexes |
|
| 179 | + */ |
|
| 180 | + $indexes = $table->getIndexes(); |
|
| 181 | + $newIndexes = array(); |
|
| 182 | + foreach ($indexes as $index) { |
|
| 183 | + if ($index->isPrimary()) { |
|
| 184 | + // do not rename primary key |
|
| 185 | + $indexName = $index->getName(); |
|
| 186 | + } else { |
|
| 187 | + // avoid conflicts in index names |
|
| 188 | + $indexName = $this->config->getSystemValue('dbtableprefix', 'oc_') . $this->random->generate(13, ISecureRandom::CHAR_LOWER); |
|
| 189 | + } |
|
| 190 | + $newIndexes[] = new Index($indexName, $index->getColumns(), $index->isUnique(), $index->isPrimary()); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // foreign keys are not supported so we just set it to an empty array |
|
| 194 | + return new Table($newName, $table->getColumns(), $newIndexes, array(), 0, $table->getOptions()); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + public function createSchema() { |
|
| 198 | + $filterExpression = $this->getFilterExpression(); |
|
| 199 | + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 200 | + return $this->connection->getSchemaManager()->createSchema(); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param Schema $targetSchema |
|
| 205 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 206 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
| 207 | + * @throws DBALException |
|
| 208 | + */ |
|
| 209 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
| 210 | + // adjust varchar columns with a length higher then getVarcharMaxLength to clob |
|
| 211 | + foreach ($targetSchema->getTables() as $table) { |
|
| 212 | + foreach ($table->getColumns() as $column) { |
|
| 213 | + if ($column->getType() instanceof StringType) { |
|
| 214 | + if ($column->getLength() > $connection->getDatabasePlatform()->getVarcharMaxLength()) { |
|
| 215 | + $column->setType(Type::getType('text')); |
|
| 216 | + $column->setLength(null); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $filterExpression = $this->getFilterExpression(); |
|
| 223 | + $this->connection->getConfiguration()->setFilterSchemaAssetsExpression($filterExpression); |
|
| 224 | + $sourceSchema = $connection->getSchemaManager()->createSchema(); |
|
| 225 | + |
|
| 226 | + // remove tables we don't know about |
|
| 227 | + /** @var $table \Doctrine\DBAL\Schema\Table */ |
|
| 228 | + foreach ($sourceSchema->getTables() as $table) { |
|
| 229 | + if (!$targetSchema->hasTable($table->getName())) { |
|
| 230 | + $sourceSchema->dropTable($table->getName()); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + // remove sequences we don't know about |
|
| 234 | + foreach ($sourceSchema->getSequences() as $table) { |
|
| 235 | + if (!$targetSchema->hasSequence($table->getName())) { |
|
| 236 | + $sourceSchema->dropSequence($table->getName()); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + $comparator = new Comparator(); |
|
| 241 | + return $comparator->compare($sourceSchema, $targetSchema); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * @param \Doctrine\DBAL\Schema\Schema $targetSchema |
|
| 246 | + * @param \Doctrine\DBAL\Connection $connection |
|
| 247 | + */ |
|
| 248 | + protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) { |
|
| 249 | + if (is_null($connection)) { |
|
| 250 | + $connection = $this->connection; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + $schemaDiff = $this->getDiff($targetSchema, $connection); |
|
| 254 | + |
|
| 255 | + $connection->beginTransaction(); |
|
| 256 | + $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); |
|
| 257 | + $step = 0; |
|
| 258 | + foreach ($sqls as $sql) { |
|
| 259 | + $this->emit($sql, $step++, count($sqls)); |
|
| 260 | + $connection->query($sql); |
|
| 261 | + } |
|
| 262 | + $connection->commit(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @param string $sourceName |
|
| 267 | + * @param string $targetName |
|
| 268 | + */ |
|
| 269 | + protected function copyTable($sourceName, $targetName) { |
|
| 270 | + $quotedSource = $this->connection->quoteIdentifier($sourceName); |
|
| 271 | + $quotedTarget = $this->connection->quoteIdentifier($targetName); |
|
| 272 | + |
|
| 273 | + $this->connection->exec('CREATE TABLE ' . $quotedTarget . ' (LIKE ' . $quotedSource . ')'); |
|
| 274 | + $this->connection->exec('INSERT INTO ' . $quotedTarget . ' SELECT * FROM ' . $quotedSource); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * @param string $name |
|
| 279 | + */ |
|
| 280 | + protected function dropTable($name) { |
|
| 281 | + $this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($name)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * @param $statement |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + protected function convertStatementToScript($statement) { |
|
| 289 | + $script = $statement . ';'; |
|
| 290 | + $script .= PHP_EOL; |
|
| 291 | + $script .= PHP_EOL; |
|
| 292 | + return $script; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + protected function getFilterExpression() { |
|
| 296 | + return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + protected function emit($sql, $step, $max) { |
|
| 300 | + if ($this->noEmit) { |
|
| 301 | + return; |
|
| 302 | + } |
|
| 303 | + if(is_null($this->dispatcher)) { |
|
| 304 | + return; |
|
| 305 | + } |
|
| 306 | + $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + private function emitCheckStep($tableName, $step, $max) { |
|
| 310 | + if(is_null($this->dispatcher)) { |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | + $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); |
|
| 314 | + } |
|
| 315 | 315 | } |