@@ -79,279 +79,279 @@ |
||
79 | 79 | |
80 | 80 | class Server { |
81 | 81 | |
82 | - /** @var IRequest */ |
|
83 | - private $request; |
|
84 | - |
|
85 | - /** @var string */ |
|
86 | - private $baseUri; |
|
87 | - |
|
88 | - /** @var Connector\Sabre\Server */ |
|
89 | - public $server; |
|
90 | - |
|
91 | - public function __construct(IRequest $request, $baseUri) { |
|
92 | - $this->request = $request; |
|
93 | - $this->baseUri = $baseUri; |
|
94 | - $logger = \OC::$server->getLogger(); |
|
95 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
96 | - /** @var IEventDispatcher $newDispatcher */ |
|
97 | - $newDispatcher = \OC::$server->query(IEventDispatcher::class); |
|
98 | - |
|
99 | - $root = new RootCollection(); |
|
100 | - $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
101 | - |
|
102 | - // Add maintenance plugin |
|
103 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); |
|
104 | - |
|
105 | - // Backends |
|
106 | - $authBackend = new Auth( |
|
107 | - \OC::$server->getSession(), |
|
108 | - \OC::$server->getUserSession(), |
|
109 | - \OC::$server->getRequest(), |
|
110 | - \OC::$server->getTwoFactorAuthManager(), |
|
111 | - \OC::$server->getBruteForceThrottler() |
|
112 | - ); |
|
113 | - |
|
114 | - // Set URL explicitly due to reverse-proxy situations |
|
115 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
116 | - $this->server->setBaseUri($this->baseUri); |
|
117 | - |
|
118 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
119 | - $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
120 | - $authPlugin = new Plugin(); |
|
121 | - $authPlugin->addBackend(new PublicAuth()); |
|
122 | - $this->server->addPlugin($authPlugin); |
|
123 | - |
|
124 | - // allow setup of additional auth backends |
|
125 | - $event = new SabrePluginEvent($this->server); |
|
126 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
127 | - |
|
128 | - $newAuthEvent = new SabrePluginAuthInitEvent($this->server); |
|
129 | - $newDispatcher->dispatchTyped($newAuthEvent); |
|
130 | - |
|
131 | - $bearerAuthBackend = new BearerAuth( |
|
132 | - \OC::$server->getUserSession(), |
|
133 | - \OC::$server->getSession(), |
|
134 | - \OC::$server->getRequest() |
|
135 | - ); |
|
136 | - $authPlugin->addBackend($bearerAuthBackend); |
|
137 | - // because we are throwing exceptions this plugin has to be the last one |
|
138 | - $authPlugin->addBackend($authBackend); |
|
139 | - |
|
140 | - // debugging |
|
141 | - if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
142 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
143 | - } else { |
|
144 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
145 | - } |
|
146 | - |
|
147 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
148 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
149 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
150 | - |
|
151 | - // acl |
|
152 | - $acl = new DavAclPlugin(); |
|
153 | - $acl->principalCollectionSet = [ |
|
154 | - 'principals/users', |
|
155 | - 'principals/groups', |
|
156 | - 'principals/calendar-resources', |
|
157 | - 'principals/calendar-rooms', |
|
158 | - ]; |
|
159 | - $this->server->addPlugin($acl); |
|
160 | - |
|
161 | - // calendar plugins |
|
162 | - if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
163 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
164 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
165 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); |
|
166 | - if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
167 | - $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
168 | - } |
|
169 | - |
|
170 | - $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); |
|
171 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request)); |
|
172 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
173 | - |
|
174 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
175 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
176 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
177 | - \OC::$server->getConfig(), |
|
178 | - \OC::$server->getURLGenerator() |
|
179 | - )); |
|
180 | - } |
|
181 | - |
|
182 | - // addressbook plugins |
|
183 | - if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
184 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
185 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
186 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
187 | - $this->server->addPlugin(new MultiGetExportPlugin()); |
|
188 | - $this->server->addPlugin(new HasPhotoPlugin()); |
|
189 | - $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
190 | - \OC::$server->getAppDataDir('dav-photocache'), |
|
191 | - \OC::$server->getLogger()) |
|
192 | - )); |
|
193 | - } |
|
194 | - |
|
195 | - // system tags plugins |
|
196 | - $this->server->addPlugin(new SystemTagPlugin( |
|
197 | - \OC::$server->getSystemTagManager(), |
|
198 | - \OC::$server->getGroupManager(), |
|
199 | - \OC::$server->getUserSession() |
|
200 | - )); |
|
201 | - |
|
202 | - // comments plugin |
|
203 | - $this->server->addPlugin(new CommentsPlugin( |
|
204 | - \OC::$server->getCommentsManager(), |
|
205 | - \OC::$server->getUserSession() |
|
206 | - )); |
|
207 | - |
|
208 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
209 | - $this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class))); |
|
210 | - $this->server->addPlugin(new ChunkingPlugin()); |
|
211 | - |
|
212 | - // allow setup of additional plugins |
|
213 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
214 | - |
|
215 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
216 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
217 | - if ($request->isUserAgent([ |
|
218 | - '/WebDAVFS/', |
|
219 | - '/OneNote/', |
|
220 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
221 | - ])) { |
|
222 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
223 | - } |
|
224 | - |
|
225 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
226 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
227 | - } |
|
228 | - |
|
229 | - $lazySearchBackend = new LazySearchBackend(); |
|
230 | - $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
231 | - |
|
232 | - // wait with registering these until auth is handled and the filesystem is setup |
|
233 | - $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
234 | - // custom properties plugin must be the last one |
|
235 | - $userSession = \OC::$server->getUserSession(); |
|
236 | - $user = $userSession->getUser(); |
|
237 | - if ($user !== null) { |
|
238 | - $view = \OC\Files\Filesystem::getView(); |
|
239 | - $this->server->addPlugin( |
|
240 | - new FilesPlugin( |
|
241 | - $this->server->tree, |
|
242 | - \OC::$server->getConfig(), |
|
243 | - $this->request, |
|
244 | - \OC::$server->getPreviewManager(), |
|
245 | - \OC::$server->getUserSession(), |
|
246 | - false, |
|
247 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
248 | - ) |
|
249 | - ); |
|
250 | - |
|
251 | - $this->server->addPlugin( |
|
252 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
253 | - new CustomPropertiesBackend( |
|
254 | - $this->server->tree, |
|
255 | - \OC::$server->getDatabaseConnection(), |
|
256 | - \OC::$server->getUserSession()->getUser() |
|
257 | - ) |
|
258 | - ) |
|
259 | - ); |
|
260 | - if ($view !== null) { |
|
261 | - $this->server->addPlugin( |
|
262 | - new QuotaPlugin($view)); |
|
263 | - } |
|
264 | - $this->server->addPlugin( |
|
265 | - new TagsPlugin( |
|
266 | - $this->server->tree, \OC::$server->getTagManager() |
|
267 | - ) |
|
268 | - ); |
|
269 | - // TODO: switch to LazyUserFolder |
|
270 | - $userFolder = \OC::$server->getUserFolder(); |
|
271 | - $this->server->addPlugin(new SharesPlugin( |
|
272 | - $this->server->tree, |
|
273 | - $userSession, |
|
274 | - $userFolder, |
|
275 | - \OC::$server->getShareManager() |
|
276 | - )); |
|
277 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
278 | - \OC::$server->getCommentsManager(), |
|
279 | - $userSession |
|
280 | - )); |
|
281 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
282 | - if ($view !== null) { |
|
283 | - $this->server->addPlugin(new FilesReportPlugin( |
|
284 | - $this->server->tree, |
|
285 | - $view, |
|
286 | - \OC::$server->getSystemTagManager(), |
|
287 | - \OC::$server->getSystemTagObjectMapper(), |
|
288 | - \OC::$server->getTagManager(), |
|
289 | - $userSession, |
|
290 | - \OC::$server->getGroupManager(), |
|
291 | - $userFolder, |
|
292 | - \OC::$server->getAppManager() |
|
293 | - )); |
|
294 | - $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
295 | - $this->server->tree, |
|
296 | - $user, |
|
297 | - \OC::$server->getRootFolder(), |
|
298 | - \OC::$server->getShareManager(), |
|
299 | - $view |
|
300 | - )); |
|
301 | - $logger = \OC::$server->get(LoggerInterface::class); |
|
302 | - $this->server->addPlugin( |
|
303 | - new BulkUploadPlugin($userFolder, $logger) |
|
304 | - ); |
|
305 | - } |
|
306 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
307 | - \OC::$server->getConfig(), |
|
308 | - \OC::$server->query(BirthdayService::class) |
|
309 | - )); |
|
310 | - $this->server->addPlugin(new AppleProvisioningPlugin( |
|
311 | - \OC::$server->getUserSession(), |
|
312 | - \OC::$server->getURLGenerator(), |
|
313 | - \OC::$server->getThemingDefaults(), |
|
314 | - \OC::$server->getRequest(), |
|
315 | - \OC::$server->getL10N('dav'), |
|
316 | - function () { |
|
317 | - return UUIDUtil::getUUID(); |
|
318 | - } |
|
319 | - )); |
|
320 | - } |
|
321 | - |
|
322 | - // register plugins from apps |
|
323 | - $pluginManager = new PluginManager( |
|
324 | - \OC::$server, |
|
325 | - \OC::$server->getAppManager() |
|
326 | - ); |
|
327 | - foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
328 | - $this->server->addPlugin($appPlugin); |
|
329 | - } |
|
330 | - foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
331 | - $root->addChild($appCollection); |
|
332 | - } |
|
333 | - }); |
|
334 | - |
|
335 | - $this->server->addPlugin( |
|
336 | - new PropfindCompressionPlugin() |
|
337 | - ); |
|
338 | - } |
|
339 | - |
|
340 | - public function exec() { |
|
341 | - /** @var IEventLogger $eventLogger */ |
|
342 | - $eventLogger = \OC::$server->get(IEventLogger::class); |
|
343 | - $eventLogger->start('dav_server_exec', ''); |
|
344 | - $this->server->exec(); |
|
345 | - $eventLogger->end('dav_server_exec'); |
|
346 | - } |
|
347 | - |
|
348 | - private function requestIsForSubtree(array $subTrees): bool { |
|
349 | - foreach ($subTrees as $subTree) { |
|
350 | - $subTree = trim($subTree, ' /'); |
|
351 | - if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
352 | - return true; |
|
353 | - } |
|
354 | - } |
|
355 | - return false; |
|
356 | - } |
|
82 | + /** @var IRequest */ |
|
83 | + private $request; |
|
84 | + |
|
85 | + /** @var string */ |
|
86 | + private $baseUri; |
|
87 | + |
|
88 | + /** @var Connector\Sabre\Server */ |
|
89 | + public $server; |
|
90 | + |
|
91 | + public function __construct(IRequest $request, $baseUri) { |
|
92 | + $this->request = $request; |
|
93 | + $this->baseUri = $baseUri; |
|
94 | + $logger = \OC::$server->getLogger(); |
|
95 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
96 | + /** @var IEventDispatcher $newDispatcher */ |
|
97 | + $newDispatcher = \OC::$server->query(IEventDispatcher::class); |
|
98 | + |
|
99 | + $root = new RootCollection(); |
|
100 | + $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root)); |
|
101 | + |
|
102 | + // Add maintenance plugin |
|
103 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig(), \OC::$server->getL10N('dav'))); |
|
104 | + |
|
105 | + // Backends |
|
106 | + $authBackend = new Auth( |
|
107 | + \OC::$server->getSession(), |
|
108 | + \OC::$server->getUserSession(), |
|
109 | + \OC::$server->getRequest(), |
|
110 | + \OC::$server->getTwoFactorAuthManager(), |
|
111 | + \OC::$server->getBruteForceThrottler() |
|
112 | + ); |
|
113 | + |
|
114 | + // Set URL explicitly due to reverse-proxy situations |
|
115 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
116 | + $this->server->setBaseUri($this->baseUri); |
|
117 | + |
|
118 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
119 | + $this->server->addPlugin(new AnonymousOptionsPlugin()); |
|
120 | + $authPlugin = new Plugin(); |
|
121 | + $authPlugin->addBackend(new PublicAuth()); |
|
122 | + $this->server->addPlugin($authPlugin); |
|
123 | + |
|
124 | + // allow setup of additional auth backends |
|
125 | + $event = new SabrePluginEvent($this->server); |
|
126 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
127 | + |
|
128 | + $newAuthEvent = new SabrePluginAuthInitEvent($this->server); |
|
129 | + $newDispatcher->dispatchTyped($newAuthEvent); |
|
130 | + |
|
131 | + $bearerAuthBackend = new BearerAuth( |
|
132 | + \OC::$server->getUserSession(), |
|
133 | + \OC::$server->getSession(), |
|
134 | + \OC::$server->getRequest() |
|
135 | + ); |
|
136 | + $authPlugin->addBackend($bearerAuthBackend); |
|
137 | + // because we are throwing exceptions this plugin has to be the last one |
|
138 | + $authPlugin->addBackend($authBackend); |
|
139 | + |
|
140 | + // debugging |
|
141 | + if (\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
142 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
143 | + } else { |
|
144 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
145 | + } |
|
146 | + |
|
147 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
148 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
149 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
150 | + |
|
151 | + // acl |
|
152 | + $acl = new DavAclPlugin(); |
|
153 | + $acl->principalCollectionSet = [ |
|
154 | + 'principals/users', |
|
155 | + 'principals/groups', |
|
156 | + 'principals/calendar-resources', |
|
157 | + 'principals/calendar-rooms', |
|
158 | + ]; |
|
159 | + $this->server->addPlugin($acl); |
|
160 | + |
|
161 | + // calendar plugins |
|
162 | + if ($this->requestIsForSubtree(['calendars', 'public-calendars', 'system-calendars', 'principals'])) { |
|
163 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
164 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\ICSExportPlugin\ICSExportPlugin(\OC::$server->getConfig(), \OC::$server->getLogger())); |
|
165 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin(\OC::$server->getConfig())); |
|
166 | + if (\OC::$server->getConfig()->getAppValue('dav', 'sendInvitations', 'yes') === 'yes') { |
|
167 | + $this->server->addPlugin(\OC::$server->query(\OCA\DAV\CalDAV\Schedule\IMipPlugin::class)); |
|
168 | + } |
|
169 | + |
|
170 | + $this->server->addPlugin(\OC::$server->get(\OCA\DAV\CalDAV\Trashbin\Plugin::class)); |
|
171 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\WebcalCaching\Plugin($request)); |
|
172 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
173 | + |
|
174 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
175 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
176 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
177 | + \OC::$server->getConfig(), |
|
178 | + \OC::$server->getURLGenerator() |
|
179 | + )); |
|
180 | + } |
|
181 | + |
|
182 | + // addressbook plugins |
|
183 | + if ($this->requestIsForSubtree(['addressbooks', 'principals'])) { |
|
184 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest(), \OC::$server->getConfig())); |
|
185 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
186 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
187 | + $this->server->addPlugin(new MultiGetExportPlugin()); |
|
188 | + $this->server->addPlugin(new HasPhotoPlugin()); |
|
189 | + $this->server->addPlugin(new ImageExportPlugin(new PhotoCache( |
|
190 | + \OC::$server->getAppDataDir('dav-photocache'), |
|
191 | + \OC::$server->getLogger()) |
|
192 | + )); |
|
193 | + } |
|
194 | + |
|
195 | + // system tags plugins |
|
196 | + $this->server->addPlugin(new SystemTagPlugin( |
|
197 | + \OC::$server->getSystemTagManager(), |
|
198 | + \OC::$server->getGroupManager(), |
|
199 | + \OC::$server->getUserSession() |
|
200 | + )); |
|
201 | + |
|
202 | + // comments plugin |
|
203 | + $this->server->addPlugin(new CommentsPlugin( |
|
204 | + \OC::$server->getCommentsManager(), |
|
205 | + \OC::$server->getUserSession() |
|
206 | + )); |
|
207 | + |
|
208 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
209 | + $this->server->addPlugin(new RequestIdHeaderPlugin(\OC::$server->get(IRequest::class))); |
|
210 | + $this->server->addPlugin(new ChunkingPlugin()); |
|
211 | + |
|
212 | + // allow setup of additional plugins |
|
213 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event); |
|
214 | + |
|
215 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
216 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
217 | + if ($request->isUserAgent([ |
|
218 | + '/WebDAVFS/', |
|
219 | + '/OneNote/', |
|
220 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
221 | + ])) { |
|
222 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
223 | + } |
|
224 | + |
|
225 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
226 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
227 | + } |
|
228 | + |
|
229 | + $lazySearchBackend = new LazySearchBackend(); |
|
230 | + $this->server->addPlugin(new SearchPlugin($lazySearchBackend)); |
|
231 | + |
|
232 | + // wait with registering these until auth is handled and the filesystem is setup |
|
233 | + $this->server->on('beforeMethod:*', function () use ($root, $lazySearchBackend) { |
|
234 | + // custom properties plugin must be the last one |
|
235 | + $userSession = \OC::$server->getUserSession(); |
|
236 | + $user = $userSession->getUser(); |
|
237 | + if ($user !== null) { |
|
238 | + $view = \OC\Files\Filesystem::getView(); |
|
239 | + $this->server->addPlugin( |
|
240 | + new FilesPlugin( |
|
241 | + $this->server->tree, |
|
242 | + \OC::$server->getConfig(), |
|
243 | + $this->request, |
|
244 | + \OC::$server->getPreviewManager(), |
|
245 | + \OC::$server->getUserSession(), |
|
246 | + false, |
|
247 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
248 | + ) |
|
249 | + ); |
|
250 | + |
|
251 | + $this->server->addPlugin( |
|
252 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
253 | + new CustomPropertiesBackend( |
|
254 | + $this->server->tree, |
|
255 | + \OC::$server->getDatabaseConnection(), |
|
256 | + \OC::$server->getUserSession()->getUser() |
|
257 | + ) |
|
258 | + ) |
|
259 | + ); |
|
260 | + if ($view !== null) { |
|
261 | + $this->server->addPlugin( |
|
262 | + new QuotaPlugin($view)); |
|
263 | + } |
|
264 | + $this->server->addPlugin( |
|
265 | + new TagsPlugin( |
|
266 | + $this->server->tree, \OC::$server->getTagManager() |
|
267 | + ) |
|
268 | + ); |
|
269 | + // TODO: switch to LazyUserFolder |
|
270 | + $userFolder = \OC::$server->getUserFolder(); |
|
271 | + $this->server->addPlugin(new SharesPlugin( |
|
272 | + $this->server->tree, |
|
273 | + $userSession, |
|
274 | + $userFolder, |
|
275 | + \OC::$server->getShareManager() |
|
276 | + )); |
|
277 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
278 | + \OC::$server->getCommentsManager(), |
|
279 | + $userSession |
|
280 | + )); |
|
281 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
282 | + if ($view !== null) { |
|
283 | + $this->server->addPlugin(new FilesReportPlugin( |
|
284 | + $this->server->tree, |
|
285 | + $view, |
|
286 | + \OC::$server->getSystemTagManager(), |
|
287 | + \OC::$server->getSystemTagObjectMapper(), |
|
288 | + \OC::$server->getTagManager(), |
|
289 | + $userSession, |
|
290 | + \OC::$server->getGroupManager(), |
|
291 | + $userFolder, |
|
292 | + \OC::$server->getAppManager() |
|
293 | + )); |
|
294 | + $lazySearchBackend->setBackend(new \OCA\DAV\Files\FileSearchBackend( |
|
295 | + $this->server->tree, |
|
296 | + $user, |
|
297 | + \OC::$server->getRootFolder(), |
|
298 | + \OC::$server->getShareManager(), |
|
299 | + $view |
|
300 | + )); |
|
301 | + $logger = \OC::$server->get(LoggerInterface::class); |
|
302 | + $this->server->addPlugin( |
|
303 | + new BulkUploadPlugin($userFolder, $logger) |
|
304 | + ); |
|
305 | + } |
|
306 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\BirthdayCalendar\EnablePlugin( |
|
307 | + \OC::$server->getConfig(), |
|
308 | + \OC::$server->query(BirthdayService::class) |
|
309 | + )); |
|
310 | + $this->server->addPlugin(new AppleProvisioningPlugin( |
|
311 | + \OC::$server->getUserSession(), |
|
312 | + \OC::$server->getURLGenerator(), |
|
313 | + \OC::$server->getThemingDefaults(), |
|
314 | + \OC::$server->getRequest(), |
|
315 | + \OC::$server->getL10N('dav'), |
|
316 | + function () { |
|
317 | + return UUIDUtil::getUUID(); |
|
318 | + } |
|
319 | + )); |
|
320 | + } |
|
321 | + |
|
322 | + // register plugins from apps |
|
323 | + $pluginManager = new PluginManager( |
|
324 | + \OC::$server, |
|
325 | + \OC::$server->getAppManager() |
|
326 | + ); |
|
327 | + foreach ($pluginManager->getAppPlugins() as $appPlugin) { |
|
328 | + $this->server->addPlugin($appPlugin); |
|
329 | + } |
|
330 | + foreach ($pluginManager->getAppCollections() as $appCollection) { |
|
331 | + $root->addChild($appCollection); |
|
332 | + } |
|
333 | + }); |
|
334 | + |
|
335 | + $this->server->addPlugin( |
|
336 | + new PropfindCompressionPlugin() |
|
337 | + ); |
|
338 | + } |
|
339 | + |
|
340 | + public function exec() { |
|
341 | + /** @var IEventLogger $eventLogger */ |
|
342 | + $eventLogger = \OC::$server->get(IEventLogger::class); |
|
343 | + $eventLogger->start('dav_server_exec', ''); |
|
344 | + $this->server->exec(); |
|
345 | + $eventLogger->end('dav_server_exec'); |
|
346 | + } |
|
347 | + |
|
348 | + private function requestIsForSubtree(array $subTrees): bool { |
|
349 | + foreach ($subTrees as $subTree) { |
|
350 | + $subTree = trim($subTree, ' /'); |
|
351 | + if (strpos($this->server->getRequestUri(), $subTree.'/') === 0) { |
|
352 | + return true; |
|
353 | + } |
|
354 | + } |
|
355 | + return false; |
|
356 | + } |
|
357 | 357 | } |
@@ -70,1141 +70,1141 @@ |
||
70 | 70 | * upgrading and removing apps. |
71 | 71 | */ |
72 | 72 | class OC_App { |
73 | - private static $adminForms = []; |
|
74 | - private static $personalForms = []; |
|
75 | - private static $appTypes = []; |
|
76 | - private static $loadedApps = []; |
|
77 | - private static $altLogin = []; |
|
78 | - private static $alreadyRegistered = []; |
|
79 | - public const supportedApp = 300; |
|
80 | - public const officialApp = 200; |
|
81 | - |
|
82 | - /** |
|
83 | - * clean the appId |
|
84 | - * |
|
85 | - * @psalm-taint-escape file |
|
86 | - * @psalm-taint-escape include |
|
87 | - * |
|
88 | - * @param string $app AppId that needs to be cleaned |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public static function cleanAppId(string $app): string { |
|
92 | - return str_replace(['\0', '/', '\\', '..'], '', $app); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Check if an app is loaded |
|
97 | - * |
|
98 | - * @param string $app |
|
99 | - * @return bool |
|
100 | - */ |
|
101 | - public static function isAppLoaded(string $app): bool { |
|
102 | - return isset(self::$loadedApps[$app]); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * loads all apps |
|
107 | - * |
|
108 | - * @param string[] $types |
|
109 | - * @return bool |
|
110 | - * |
|
111 | - * This function walks through the ownCloud directory and loads all apps |
|
112 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
113 | - * exists. |
|
114 | - * |
|
115 | - * if $types is set to non-empty array, only apps of those types will be loaded |
|
116 | - */ |
|
117 | - public static function loadApps(array $types = []): bool { |
|
118 | - if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
119 | - return false; |
|
120 | - } |
|
121 | - // Load the enabled apps here |
|
122 | - $apps = self::getEnabledApps(); |
|
123 | - |
|
124 | - // Add each apps' folder as allowed class path |
|
125 | - foreach ($apps as $app) { |
|
126 | - // If the app is already loaded then autoloading it makes no sense |
|
127 | - if (!isset(self::$loadedApps[$app])) { |
|
128 | - $path = self::getAppPath($app); |
|
129 | - if ($path !== false) { |
|
130 | - self::registerAutoloading($app, $path); |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - // prevent app.php from printing output |
|
136 | - ob_start(); |
|
137 | - foreach ($apps as $app) { |
|
138 | - if (!isset(self::$loadedApps[$app]) && ($types === [] || self::isType($app, $types))) { |
|
139 | - try { |
|
140 | - self::loadApp($app); |
|
141 | - } catch (\Throwable $e) { |
|
142 | - \OC::$server->get(LoggerInterface::class)->emergency('Error during app loading: ' . $e->getMessage(), [ |
|
143 | - 'exception' => $e, |
|
144 | - 'app' => $app, |
|
145 | - ]); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - ob_end_clean(); |
|
150 | - |
|
151 | - return true; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * load a single app |
|
156 | - * |
|
157 | - * @param string $app |
|
158 | - * @throws Exception |
|
159 | - */ |
|
160 | - public static function loadApp(string $app) { |
|
161 | - self::$loadedApps[$app] = true; |
|
162 | - $appPath = self::getAppPath($app); |
|
163 | - if ($appPath === false) { |
|
164 | - return; |
|
165 | - } |
|
166 | - |
|
167 | - // in case someone calls loadApp() directly |
|
168 | - self::registerAutoloading($app, $appPath); |
|
169 | - |
|
170 | - /** @var Coordinator $coordinator */ |
|
171 | - $coordinator = \OC::$server->query(Coordinator::class); |
|
172 | - $isBootable = $coordinator->isBootable($app); |
|
173 | - |
|
174 | - $hasAppPhpFile = is_file($appPath . '/appinfo/app.php'); |
|
175 | - |
|
176 | - \OC::$server->getEventLogger()->start('bootstrap:load_app_' . $app, 'Load app: ' . $app); |
|
177 | - if ($isBootable && $hasAppPhpFile) { |
|
178 | - \OC::$server->getLogger()->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [ |
|
179 | - 'app' => $app, |
|
180 | - ]); |
|
181 | - } elseif ($hasAppPhpFile) { |
|
182 | - \OC::$server->getLogger()->debug('/appinfo/app.php is deprecated, use \OCP\AppFramework\Bootstrap\IBootstrap on the application class instead.', [ |
|
183 | - 'app' => $app, |
|
184 | - ]); |
|
185 | - try { |
|
186 | - self::requireAppFile($app); |
|
187 | - } catch (Throwable $ex) { |
|
188 | - if ($ex instanceof ServerNotAvailableException) { |
|
189 | - throw $ex; |
|
190 | - } |
|
191 | - if (!\OC::$server->getAppManager()->isShipped($app) && !self::isType($app, ['authentication'])) { |
|
192 | - \OC::$server->getLogger()->logException($ex, [ |
|
193 | - 'message' => "App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(), |
|
194 | - ]); |
|
195 | - |
|
196 | - // Only disable apps which are not shipped and that are not authentication apps |
|
197 | - \OC::$server->getAppManager()->disableApp($app, true); |
|
198 | - } else { |
|
199 | - \OC::$server->getLogger()->logException($ex, [ |
|
200 | - 'message' => "App $app threw an error during app.php load: " . $ex->getMessage(), |
|
201 | - ]); |
|
202 | - } |
|
203 | - } |
|
204 | - } |
|
205 | - \OC::$server->getEventLogger()->end('bootstrap:load_app_' . $app); |
|
206 | - |
|
207 | - $coordinator->bootApp($app); |
|
208 | - |
|
209 | - $info = self::getAppInfo($app); |
|
210 | - if (!empty($info['activity']['filters'])) { |
|
211 | - foreach ($info['activity']['filters'] as $filter) { |
|
212 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
213 | - } |
|
214 | - } |
|
215 | - if (!empty($info['activity']['settings'])) { |
|
216 | - foreach ($info['activity']['settings'] as $setting) { |
|
217 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
218 | - } |
|
219 | - } |
|
220 | - if (!empty($info['activity']['providers'])) { |
|
221 | - foreach ($info['activity']['providers'] as $provider) { |
|
222 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - if (!empty($info['settings']['admin'])) { |
|
227 | - foreach ($info['settings']['admin'] as $setting) { |
|
228 | - \OC::$server->get(ISettingsManager::class)->registerSetting('admin', $setting); |
|
229 | - } |
|
230 | - } |
|
231 | - if (!empty($info['settings']['admin-section'])) { |
|
232 | - foreach ($info['settings']['admin-section'] as $section) { |
|
233 | - \OC::$server->get(ISettingsManager::class)->registerSection('admin', $section); |
|
234 | - } |
|
235 | - } |
|
236 | - if (!empty($info['settings']['personal'])) { |
|
237 | - foreach ($info['settings']['personal'] as $setting) { |
|
238 | - \OC::$server->get(ISettingsManager::class)->registerSetting('personal', $setting); |
|
239 | - } |
|
240 | - } |
|
241 | - if (!empty($info['settings']['personal-section'])) { |
|
242 | - foreach ($info['settings']['personal-section'] as $section) { |
|
243 | - \OC::$server->get(ISettingsManager::class)->registerSection('personal', $section); |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - if (!empty($info['collaboration']['plugins'])) { |
|
248 | - // deal with one or many plugin entries |
|
249 | - $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
250 | - [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
251 | - foreach ($plugins as $plugin) { |
|
252 | - if ($plugin['@attributes']['type'] === 'collaborator-search') { |
|
253 | - $pluginInfo = [ |
|
254 | - 'shareType' => $plugin['@attributes']['share-type'], |
|
255 | - 'class' => $plugin['@value'], |
|
256 | - ]; |
|
257 | - \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
258 | - } elseif ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
259 | - \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
260 | - } |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * @internal |
|
267 | - * @param string $app |
|
268 | - * @param string $path |
|
269 | - * @param bool $force |
|
270 | - */ |
|
271 | - public static function registerAutoloading(string $app, string $path, bool $force = false) { |
|
272 | - $key = $app . '-' . $path; |
|
273 | - if (!$force && isset(self::$alreadyRegistered[$key])) { |
|
274 | - return; |
|
275 | - } |
|
276 | - |
|
277 | - self::$alreadyRegistered[$key] = true; |
|
278 | - |
|
279 | - // Register on PSR-4 composer autoloader |
|
280 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
281 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
282 | - |
|
283 | - if (file_exists($path . '/composer/autoload.php')) { |
|
284 | - require_once $path . '/composer/autoload.php'; |
|
285 | - } else { |
|
286 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
287 | - // Register on legacy autoloader |
|
288 | - \OC::$loader->addValidRoot($path); |
|
289 | - } |
|
290 | - |
|
291 | - // Register Test namespace only when testing |
|
292 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
293 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Load app.php from the given app |
|
299 | - * |
|
300 | - * @param string $app app name |
|
301 | - * @throws Error |
|
302 | - */ |
|
303 | - private static function requireAppFile(string $app) { |
|
304 | - // encapsulated here to avoid variable scope conflicts |
|
305 | - require_once $app . '/appinfo/app.php'; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * check if an app is of a specific type |
|
310 | - * |
|
311 | - * @param string $app |
|
312 | - * @param array $types |
|
313 | - * @return bool |
|
314 | - */ |
|
315 | - public static function isType(string $app, array $types): bool { |
|
316 | - $appTypes = self::getAppTypes($app); |
|
317 | - foreach ($types as $type) { |
|
318 | - if (array_search($type, $appTypes) !== false) { |
|
319 | - return true; |
|
320 | - } |
|
321 | - } |
|
322 | - return false; |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * get the types of an app |
|
327 | - * |
|
328 | - * @param string $app |
|
329 | - * @return array |
|
330 | - */ |
|
331 | - private static function getAppTypes(string $app): array { |
|
332 | - //load the cache |
|
333 | - if (count(self::$appTypes) == 0) { |
|
334 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
335 | - } |
|
336 | - |
|
337 | - if (isset(self::$appTypes[$app])) { |
|
338 | - return explode(',', self::$appTypes[$app]); |
|
339 | - } |
|
340 | - |
|
341 | - return []; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * read app types from info.xml and cache them in the database |
|
346 | - */ |
|
347 | - public static function setAppTypes(string $app) { |
|
348 | - $appManager = \OC::$server->getAppManager(); |
|
349 | - $appData = $appManager->getAppInfo($app); |
|
350 | - if (!is_array($appData)) { |
|
351 | - return; |
|
352 | - } |
|
353 | - |
|
354 | - if (isset($appData['types'])) { |
|
355 | - $appTypes = implode(',', $appData['types']); |
|
356 | - } else { |
|
357 | - $appTypes = ''; |
|
358 | - $appData['types'] = []; |
|
359 | - } |
|
360 | - |
|
361 | - $config = \OC::$server->getConfig(); |
|
362 | - $config->setAppValue($app, 'types', $appTypes); |
|
363 | - |
|
364 | - if ($appManager->hasProtectedAppType($appData['types'])) { |
|
365 | - $enabled = $config->getAppValue($app, 'enabled', 'yes'); |
|
366 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
367 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Returns apps enabled for the current user. |
|
374 | - * |
|
375 | - * @param bool $forceRefresh whether to refresh the cache |
|
376 | - * @param bool $all whether to return apps for all users, not only the |
|
377 | - * currently logged in one |
|
378 | - * @return string[] |
|
379 | - */ |
|
380 | - public static function getEnabledApps(bool $forceRefresh = false, bool $all = false): array { |
|
381 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
382 | - return []; |
|
383 | - } |
|
384 | - // in incognito mode or when logged out, $user will be false, |
|
385 | - // which is also the case during an upgrade |
|
386 | - $appManager = \OC::$server->getAppManager(); |
|
387 | - if ($all) { |
|
388 | - $user = null; |
|
389 | - } else { |
|
390 | - $user = \OC::$server->getUserSession()->getUser(); |
|
391 | - } |
|
392 | - |
|
393 | - if (is_null($user)) { |
|
394 | - $apps = $appManager->getInstalledApps(); |
|
395 | - } else { |
|
396 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
397 | - } |
|
398 | - $apps = array_filter($apps, function ($app) { |
|
399 | - return $app !== 'files';//we add this manually |
|
400 | - }); |
|
401 | - sort($apps); |
|
402 | - array_unshift($apps, 'files'); |
|
403 | - return $apps; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * checks whether or not an app is enabled |
|
408 | - * |
|
409 | - * @param string $app app |
|
410 | - * @return bool |
|
411 | - * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
412 | - * |
|
413 | - * This function checks whether or not an app is enabled. |
|
414 | - */ |
|
415 | - public static function isEnabled(string $app): bool { |
|
416 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * enables an app |
|
421 | - * |
|
422 | - * @param string $appId |
|
423 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
424 | - * @throws \Exception |
|
425 | - * @return void |
|
426 | - * |
|
427 | - * This function set an app as enabled in appconfig. |
|
428 | - */ |
|
429 | - public function enable(string $appId, |
|
430 | - array $groups = []) { |
|
431 | - |
|
432 | - // Check if app is already downloaded |
|
433 | - /** @var Installer $installer */ |
|
434 | - $installer = \OC::$server->query(Installer::class); |
|
435 | - $isDownloaded = $installer->isDownloaded($appId); |
|
436 | - |
|
437 | - if (!$isDownloaded) { |
|
438 | - $installer->downloadApp($appId); |
|
439 | - } |
|
440 | - |
|
441 | - $installer->installApp($appId); |
|
442 | - |
|
443 | - $appManager = \OC::$server->getAppManager(); |
|
444 | - if ($groups !== []) { |
|
445 | - $groupManager = \OC::$server->getGroupManager(); |
|
446 | - $groupsList = []; |
|
447 | - foreach ($groups as $group) { |
|
448 | - $groupItem = $groupManager->get($group); |
|
449 | - if ($groupItem instanceof \OCP\IGroup) { |
|
450 | - $groupsList[] = $groupManager->get($group); |
|
451 | - } |
|
452 | - } |
|
453 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
454 | - } else { |
|
455 | - $appManager->enableApp($appId); |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get the path where to install apps |
|
461 | - * |
|
462 | - * @return string|false |
|
463 | - */ |
|
464 | - public static function getInstallPath() { |
|
465 | - foreach (OC::$APPSROOTS as $dir) { |
|
466 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
467 | - return $dir['path']; |
|
468 | - } |
|
469 | - } |
|
470 | - |
|
471 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR); |
|
472 | - return null; |
|
473 | - } |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * search for an app in all app-directories |
|
478 | - * |
|
479 | - * @param string $appId |
|
480 | - * @return false|string |
|
481 | - */ |
|
482 | - public static function findAppInDirectories(string $appId) { |
|
483 | - $sanitizedAppId = self::cleanAppId($appId); |
|
484 | - if ($sanitizedAppId !== $appId) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - static $app_dir = []; |
|
488 | - |
|
489 | - if (isset($app_dir[$appId])) { |
|
490 | - return $app_dir[$appId]; |
|
491 | - } |
|
492 | - |
|
493 | - $possibleApps = []; |
|
494 | - foreach (OC::$APPSROOTS as $dir) { |
|
495 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
496 | - $possibleApps[] = $dir; |
|
497 | - } |
|
498 | - } |
|
499 | - |
|
500 | - if (empty($possibleApps)) { |
|
501 | - return false; |
|
502 | - } elseif (count($possibleApps) === 1) { |
|
503 | - $dir = array_shift($possibleApps); |
|
504 | - $app_dir[$appId] = $dir; |
|
505 | - return $dir; |
|
506 | - } else { |
|
507 | - $versionToLoad = []; |
|
508 | - foreach ($possibleApps as $possibleApp) { |
|
509 | - $version = self::getAppVersionByPath($possibleApp['path'] . '/' . $appId); |
|
510 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
511 | - $versionToLoad = [ |
|
512 | - 'dir' => $possibleApp, |
|
513 | - 'version' => $version, |
|
514 | - ]; |
|
515 | - } |
|
516 | - } |
|
517 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
518 | - return $versionToLoad['dir']; |
|
519 | - //TODO - write test |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - /** |
|
524 | - * Get the directory for the given app. |
|
525 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
526 | - * |
|
527 | - * @psalm-taint-specialize |
|
528 | - * |
|
529 | - * @param string $appId |
|
530 | - * @return string|false |
|
531 | - * @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath() |
|
532 | - */ |
|
533 | - public static function getAppPath(string $appId) { |
|
534 | - if ($appId === null || trim($appId) === '') { |
|
535 | - return false; |
|
536 | - } |
|
537 | - |
|
538 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
539 | - return $dir['path'] . '/' . $appId; |
|
540 | - } |
|
541 | - return false; |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * Get the path for the given app on the access |
|
546 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
547 | - * |
|
548 | - * @param string $appId |
|
549 | - * @return string|false |
|
550 | - * @deprecated 18.0.0 use \OC::$server->getAppManager()->getAppWebPath() |
|
551 | - */ |
|
552 | - public static function getAppWebPath(string $appId) { |
|
553 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
554 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
555 | - } |
|
556 | - return false; |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * get the last version of the app from appinfo/info.xml |
|
561 | - * |
|
562 | - * @param string $appId |
|
563 | - * @param bool $useCache |
|
564 | - * @return string |
|
565 | - * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion() |
|
566 | - */ |
|
567 | - public static function getAppVersion(string $appId, bool $useCache = true): string { |
|
568 | - return \OC::$server->getAppManager()->getAppVersion($appId, $useCache); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * get app's version based on it's path |
|
573 | - * |
|
574 | - * @param string $path |
|
575 | - * @return string |
|
576 | - */ |
|
577 | - public static function getAppVersionByPath(string $path): string { |
|
578 | - $infoFile = $path . '/appinfo/info.xml'; |
|
579 | - $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); |
|
580 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
581 | - } |
|
582 | - |
|
583 | - |
|
584 | - /** |
|
585 | - * Read all app metadata from the info.xml file |
|
586 | - * |
|
587 | - * @param string $appId id of the app or the path of the info.xml file |
|
588 | - * @param bool $path |
|
589 | - * @param string $lang |
|
590 | - * @return array|null |
|
591 | - * @note all data is read from info.xml, not just pre-defined fields |
|
592 | - * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo() |
|
593 | - */ |
|
594 | - public static function getAppInfo(string $appId, bool $path = false, string $lang = null) { |
|
595 | - return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang); |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * Returns the navigation |
|
600 | - * |
|
601 | - * @return array |
|
602 | - * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll() |
|
603 | - * |
|
604 | - * This function returns an array containing all entries added. The |
|
605 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
606 | - * given for each app the following keys exist: |
|
607 | - * - active: boolean, signals if the user is on this navigation entry |
|
608 | - */ |
|
609 | - public static function getNavigation(): array { |
|
610 | - return OC::$server->getNavigationManager()->getAll(); |
|
611 | - } |
|
612 | - |
|
613 | - /** |
|
614 | - * Returns the Settings Navigation |
|
615 | - * |
|
616 | - * @return string[] |
|
617 | - * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings') |
|
618 | - * |
|
619 | - * This function returns an array containing all settings pages added. The |
|
620 | - * entries are sorted by the key 'order' ascending. |
|
621 | - */ |
|
622 | - public static function getSettingsNavigation(): array { |
|
623 | - return OC::$server->getNavigationManager()->getAll('settings'); |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * get the id of loaded app |
|
628 | - * |
|
629 | - * @return string |
|
630 | - */ |
|
631 | - public static function getCurrentApp(): string { |
|
632 | - $request = \OC::$server->getRequest(); |
|
633 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
634 | - $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
635 | - if (empty($topFolder)) { |
|
636 | - $path_info = $request->getPathInfo(); |
|
637 | - if ($path_info) { |
|
638 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
639 | - } |
|
640 | - } |
|
641 | - if ($topFolder == 'apps') { |
|
642 | - $length = strlen($topFolder); |
|
643 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1) ?: ''; |
|
644 | - } else { |
|
645 | - return $topFolder; |
|
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - /** |
|
650 | - * @param string $type |
|
651 | - * @return array |
|
652 | - */ |
|
653 | - public static function getForms(string $type): array { |
|
654 | - $forms = []; |
|
655 | - switch ($type) { |
|
656 | - case 'admin': |
|
657 | - $source = self::$adminForms; |
|
658 | - break; |
|
659 | - case 'personal': |
|
660 | - $source = self::$personalForms; |
|
661 | - break; |
|
662 | - default: |
|
663 | - return []; |
|
664 | - } |
|
665 | - foreach ($source as $form) { |
|
666 | - $forms[] = include $form; |
|
667 | - } |
|
668 | - return $forms; |
|
669 | - } |
|
670 | - |
|
671 | - /** |
|
672 | - * register an admin form to be shown |
|
673 | - * |
|
674 | - * @param string $app |
|
675 | - * @param string $page |
|
676 | - */ |
|
677 | - public static function registerAdmin(string $app, string $page) { |
|
678 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * register a personal form to be shown |
|
683 | - * @param string $app |
|
684 | - * @param string $page |
|
685 | - */ |
|
686 | - public static function registerPersonal(string $app, string $page) { |
|
687 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * @param array $entry |
|
692 | - * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface |
|
693 | - */ |
|
694 | - public static function registerLogIn(array $entry) { |
|
695 | - \OC::$server->getLogger()->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface'); |
|
696 | - self::$altLogin[] = $entry; |
|
697 | - } |
|
698 | - |
|
699 | - /** |
|
700 | - * @return array |
|
701 | - */ |
|
702 | - public static function getAlternativeLogIns(): array { |
|
703 | - /** @var Coordinator $bootstrapCoordinator */ |
|
704 | - $bootstrapCoordinator = \OC::$server->query(Coordinator::class); |
|
705 | - |
|
706 | - foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) { |
|
707 | - if (!in_array(IAlternativeLogin::class, class_implements($registration->getService()), true)) { |
|
708 | - \OC::$server->getLogger()->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [ |
|
709 | - 'option' => $registration->getService(), |
|
710 | - 'interface' => IAlternativeLogin::class, |
|
711 | - 'app' => $registration->getAppId(), |
|
712 | - ]); |
|
713 | - continue; |
|
714 | - } |
|
715 | - |
|
716 | - try { |
|
717 | - /** @var IAlternativeLogin $provider */ |
|
718 | - $provider = \OC::$server->query($registration->getService()); |
|
719 | - } catch (QueryException $e) { |
|
720 | - \OC::$server->getLogger()->logException($e, [ |
|
721 | - 'message' => 'Alternative login option {option} can not be initialised.', |
|
722 | - 'option' => $registration->getService(), |
|
723 | - 'app' => $registration->getAppId(), |
|
724 | - ]); |
|
725 | - } |
|
726 | - |
|
727 | - try { |
|
728 | - $provider->load(); |
|
729 | - |
|
730 | - self::$altLogin[] = [ |
|
731 | - 'name' => $provider->getLabel(), |
|
732 | - 'href' => $provider->getLink(), |
|
733 | - 'style' => $provider->getClass(), |
|
734 | - ]; |
|
735 | - } catch (Throwable $e) { |
|
736 | - \OC::$server->getLogger()->logException($e, [ |
|
737 | - 'message' => 'Alternative login option {option} had an error while loading.', |
|
738 | - 'option' => $registration->getService(), |
|
739 | - 'app' => $registration->getAppId(), |
|
740 | - ]); |
|
741 | - } |
|
742 | - } |
|
743 | - |
|
744 | - return self::$altLogin; |
|
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * get a list of all apps in the apps folder |
|
749 | - * |
|
750 | - * @return string[] an array of app names (string IDs) |
|
751 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
752 | - */ |
|
753 | - public static function getAllApps(): array { |
|
754 | - $apps = []; |
|
755 | - |
|
756 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
757 | - if (!is_readable($apps_dir['path'])) { |
|
758 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN); |
|
759 | - continue; |
|
760 | - } |
|
761 | - $dh = opendir($apps_dir['path']); |
|
762 | - |
|
763 | - if (is_resource($dh)) { |
|
764 | - while (($file = readdir($dh)) !== false) { |
|
765 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
766 | - $apps[] = $file; |
|
767 | - } |
|
768 | - } |
|
769 | - } |
|
770 | - } |
|
771 | - |
|
772 | - $apps = array_unique($apps); |
|
773 | - |
|
774 | - return $apps; |
|
775 | - } |
|
776 | - |
|
777 | - /** |
|
778 | - * List all supported apps |
|
779 | - * |
|
780 | - * @return array |
|
781 | - */ |
|
782 | - public function getSupportedApps(): array { |
|
783 | - /** @var \OCP\Support\Subscription\IRegistry $subscriptionRegistry */ |
|
784 | - $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
785 | - $supportedApps = $subscriptionRegistry->delegateGetSupportedApps(); |
|
786 | - return $supportedApps; |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * List all apps, this is used in apps.php |
|
791 | - * |
|
792 | - * @return array |
|
793 | - */ |
|
794 | - public function listAllApps(): array { |
|
795 | - $installedApps = OC_App::getAllApps(); |
|
796 | - |
|
797 | - $appManager = \OC::$server->getAppManager(); |
|
798 | - //we don't want to show configuration for these |
|
799 | - $blacklist = $appManager->getAlwaysEnabledApps(); |
|
800 | - $appList = []; |
|
801 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
802 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
803 | - $supportedApps = $this->getSupportedApps(); |
|
804 | - |
|
805 | - foreach ($installedApps as $app) { |
|
806 | - if (array_search($app, $blacklist) === false) { |
|
807 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
808 | - if (!is_array($info)) { |
|
809 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR); |
|
810 | - continue; |
|
811 | - } |
|
812 | - |
|
813 | - if (!isset($info['name'])) { |
|
814 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR); |
|
815 | - continue; |
|
816 | - } |
|
817 | - |
|
818 | - $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no'); |
|
819 | - $info['groups'] = null; |
|
820 | - if ($enabled === 'yes') { |
|
821 | - $active = true; |
|
822 | - } elseif ($enabled === 'no') { |
|
823 | - $active = false; |
|
824 | - } else { |
|
825 | - $active = true; |
|
826 | - $info['groups'] = $enabled; |
|
827 | - } |
|
828 | - |
|
829 | - $info['active'] = $active; |
|
830 | - |
|
831 | - if ($appManager->isShipped($app)) { |
|
832 | - $info['internal'] = true; |
|
833 | - $info['level'] = self::officialApp; |
|
834 | - $info['removable'] = false; |
|
835 | - } else { |
|
836 | - $info['internal'] = false; |
|
837 | - $info['removable'] = true; |
|
838 | - } |
|
839 | - |
|
840 | - if (in_array($app, $supportedApps)) { |
|
841 | - $info['level'] = self::supportedApp; |
|
842 | - } |
|
843 | - |
|
844 | - $appPath = self::getAppPath($app); |
|
845 | - if ($appPath !== false) { |
|
846 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
847 | - if (file_exists($appIcon)) { |
|
848 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
849 | - $info['previewAsIcon'] = true; |
|
850 | - } else { |
|
851 | - $appIcon = $appPath . '/img/app.svg'; |
|
852 | - if (file_exists($appIcon)) { |
|
853 | - $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
854 | - $info['previewAsIcon'] = true; |
|
855 | - } |
|
856 | - } |
|
857 | - } |
|
858 | - // fix documentation |
|
859 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
860 | - foreach ($info['documentation'] as $key => $url) { |
|
861 | - // If it is not an absolute URL we assume it is a key |
|
862 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
863 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
864 | - $url = $urlGenerator->linkToDocs($url); |
|
865 | - } |
|
866 | - |
|
867 | - $info['documentation'][$key] = $url; |
|
868 | - } |
|
869 | - } |
|
870 | - |
|
871 | - $info['version'] = OC_App::getAppVersion($app); |
|
872 | - $appList[] = $info; |
|
873 | - } |
|
874 | - } |
|
875 | - |
|
876 | - return $appList; |
|
877 | - } |
|
878 | - |
|
879 | - public static function shouldUpgrade(string $app): bool { |
|
880 | - $versions = self::getAppVersions(); |
|
881 | - $currentVersion = OC_App::getAppVersion($app); |
|
882 | - if ($currentVersion && isset($versions[$app])) { |
|
883 | - $installedVersion = $versions[$app]; |
|
884 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
885 | - return true; |
|
886 | - } |
|
887 | - } |
|
888 | - return false; |
|
889 | - } |
|
890 | - |
|
891 | - /** |
|
892 | - * Adjust the number of version parts of $version1 to match |
|
893 | - * the number of version parts of $version2. |
|
894 | - * |
|
895 | - * @param string $version1 version to adjust |
|
896 | - * @param string $version2 version to take the number of parts from |
|
897 | - * @return string shortened $version1 |
|
898 | - */ |
|
899 | - private static function adjustVersionParts(string $version1, string $version2): string { |
|
900 | - $version1 = explode('.', $version1); |
|
901 | - $version2 = explode('.', $version2); |
|
902 | - // reduce $version1 to match the number of parts in $version2 |
|
903 | - while (count($version1) > count($version2)) { |
|
904 | - array_pop($version1); |
|
905 | - } |
|
906 | - // if $version1 does not have enough parts, add some |
|
907 | - while (count($version1) < count($version2)) { |
|
908 | - $version1[] = '0'; |
|
909 | - } |
|
910 | - return implode('.', $version1); |
|
911 | - } |
|
912 | - |
|
913 | - /** |
|
914 | - * Check whether the current ownCloud version matches the given |
|
915 | - * application's version requirements. |
|
916 | - * |
|
917 | - * The comparison is made based on the number of parts that the |
|
918 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
919 | - * app info version is expecting version 6.0, the comparison is |
|
920 | - * made on the first two parts of the ownCloud version. |
|
921 | - * This means that it's possible to specify "requiremin" => 6 |
|
922 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
923 | - * |
|
924 | - * @param string $ocVersion ownCloud version to check against |
|
925 | - * @param array $appInfo app info (from xml) |
|
926 | - * |
|
927 | - * @return boolean true if compatible, otherwise false |
|
928 | - */ |
|
929 | - public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool { |
|
930 | - $requireMin = ''; |
|
931 | - $requireMax = ''; |
|
932 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
933 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
934 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
935 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
936 | - } elseif (isset($appInfo['requiremin'])) { |
|
937 | - $requireMin = $appInfo['requiremin']; |
|
938 | - } elseif (isset($appInfo['require'])) { |
|
939 | - $requireMin = $appInfo['require']; |
|
940 | - } |
|
941 | - |
|
942 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
943 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
944 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
945 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
946 | - } elseif (isset($appInfo['requiremax'])) { |
|
947 | - $requireMax = $appInfo['requiremax']; |
|
948 | - } |
|
949 | - |
|
950 | - if (!empty($requireMin) |
|
951 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
952 | - ) { |
|
953 | - return false; |
|
954 | - } |
|
955 | - |
|
956 | - if (!$ignoreMax && !empty($requireMax) |
|
957 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
958 | - ) { |
|
959 | - return false; |
|
960 | - } |
|
961 | - |
|
962 | - return true; |
|
963 | - } |
|
964 | - |
|
965 | - /** |
|
966 | - * get the installed version of all apps |
|
967 | - */ |
|
968 | - public static function getAppVersions() { |
|
969 | - static $versions; |
|
970 | - |
|
971 | - if (!$versions) { |
|
972 | - $appConfig = \OC::$server->getAppConfig(); |
|
973 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
974 | - } |
|
975 | - return $versions; |
|
976 | - } |
|
977 | - |
|
978 | - /** |
|
979 | - * update the database for the app and call the update script |
|
980 | - * |
|
981 | - * @param string $appId |
|
982 | - * @return bool |
|
983 | - */ |
|
984 | - public static function updateApp(string $appId): bool { |
|
985 | - $appPath = self::getAppPath($appId); |
|
986 | - if ($appPath === false) { |
|
987 | - return false; |
|
988 | - } |
|
989 | - |
|
990 | - if (is_file($appPath . '/appinfo/database.xml')) { |
|
991 | - \OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId); |
|
992 | - return false; |
|
993 | - } |
|
994 | - |
|
995 | - \OC::$server->getAppManager()->clearAppsCache(); |
|
996 | - $l = \OC::$server->getL10N('core'); |
|
997 | - $appData = self::getAppInfo($appId, false, $l->getLanguageCode()); |
|
998 | - |
|
999 | - $ignoreMaxApps = \OC::$server->getConfig()->getSystemValue('app_install_overwrite', []); |
|
1000 | - $ignoreMax = in_array($appId, $ignoreMaxApps, true); |
|
1001 | - \OC_App::checkAppDependencies( |
|
1002 | - \OC::$server->getConfig(), |
|
1003 | - $l, |
|
1004 | - $appData, |
|
1005 | - $ignoreMax |
|
1006 | - ); |
|
1007 | - |
|
1008 | - self::registerAutoloading($appId, $appPath, true); |
|
1009 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1010 | - |
|
1011 | - $ms = new MigrationService($appId, \OC::$server->get(\OC\DB\Connection::class)); |
|
1012 | - $ms->migrate(); |
|
1013 | - |
|
1014 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1015 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1016 | - // update appversion in app manager |
|
1017 | - \OC::$server->getAppManager()->clearAppsCache(); |
|
1018 | - \OC::$server->getAppManager()->getAppVersion($appId, false); |
|
1019 | - |
|
1020 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1021 | - |
|
1022 | - //set remote/public handlers |
|
1023 | - if (array_key_exists('ocsid', $appData)) { |
|
1024 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1025 | - } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1026 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1027 | - } |
|
1028 | - foreach ($appData['remote'] as $name => $path) { |
|
1029 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1030 | - } |
|
1031 | - foreach ($appData['public'] as $name => $path) { |
|
1032 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1033 | - } |
|
1034 | - |
|
1035 | - self::setAppTypes($appId); |
|
1036 | - |
|
1037 | - $version = \OC_App::getAppVersion($appId); |
|
1038 | - \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); |
|
1039 | - |
|
1040 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1041 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1042 | - )); |
|
1043 | - |
|
1044 | - return true; |
|
1045 | - } |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * @param string $appId |
|
1049 | - * @param string[] $steps |
|
1050 | - * @throws \OC\NeedsUpdateException |
|
1051 | - */ |
|
1052 | - public static function executeRepairSteps(string $appId, array $steps) { |
|
1053 | - if (empty($steps)) { |
|
1054 | - return; |
|
1055 | - } |
|
1056 | - // load the app |
|
1057 | - self::loadApp($appId); |
|
1058 | - |
|
1059 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1060 | - |
|
1061 | - // load the steps |
|
1062 | - $r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class)); |
|
1063 | - foreach ($steps as $step) { |
|
1064 | - try { |
|
1065 | - $r->addStep($step); |
|
1066 | - } catch (Exception $ex) { |
|
1067 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1068 | - \OC::$server->getLogger()->logException($ex); |
|
1069 | - } |
|
1070 | - } |
|
1071 | - // run the steps |
|
1072 | - $r->run(); |
|
1073 | - } |
|
1074 | - |
|
1075 | - public static function setupBackgroundJobs(array $jobs) { |
|
1076 | - $queue = \OC::$server->getJobList(); |
|
1077 | - foreach ($jobs as $job) { |
|
1078 | - $queue->add($job); |
|
1079 | - } |
|
1080 | - } |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * @param string $appId |
|
1084 | - * @param string[] $steps |
|
1085 | - */ |
|
1086 | - private static function setupLiveMigrations(string $appId, array $steps) { |
|
1087 | - $queue = \OC::$server->getJobList(); |
|
1088 | - foreach ($steps as $step) { |
|
1089 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1090 | - 'app' => $appId, |
|
1091 | - 'step' => $step]); |
|
1092 | - } |
|
1093 | - } |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * @param string $appId |
|
1097 | - * @return \OC\Files\View|false |
|
1098 | - */ |
|
1099 | - public static function getStorage(string $appId) { |
|
1100 | - if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
1101 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1102 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1103 | - if (!$view->file_exists($appId)) { |
|
1104 | - $view->mkdir($appId); |
|
1105 | - } |
|
1106 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1107 | - } else { |
|
1108 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR); |
|
1109 | - return false; |
|
1110 | - } |
|
1111 | - } else { |
|
1112 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR); |
|
1113 | - return false; |
|
1114 | - } |
|
1115 | - } |
|
1116 | - |
|
1117 | - protected static function findBestL10NOption(array $options, string $lang): string { |
|
1118 | - // only a single option |
|
1119 | - if (isset($options['@value'])) { |
|
1120 | - return $options['@value']; |
|
1121 | - } |
|
1122 | - |
|
1123 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1124 | - |
|
1125 | - $lang = strtolower($lang); |
|
1126 | - $similarLang = $lang; |
|
1127 | - if (strpos($similarLang, '_')) { |
|
1128 | - // For "de_DE" we want to find "de" and the other way around |
|
1129 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1130 | - } |
|
1131 | - |
|
1132 | - foreach ($options as $option) { |
|
1133 | - if (is_array($option)) { |
|
1134 | - if ($fallback === false) { |
|
1135 | - $fallback = $option['@value']; |
|
1136 | - } |
|
1137 | - |
|
1138 | - if (!isset($option['@attributes']['lang'])) { |
|
1139 | - continue; |
|
1140 | - } |
|
1141 | - |
|
1142 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1143 | - if ($attributeLang === $lang) { |
|
1144 | - return $option['@value']; |
|
1145 | - } |
|
1146 | - |
|
1147 | - if ($attributeLang === $similarLang) { |
|
1148 | - $similarLangFallback = $option['@value']; |
|
1149 | - } elseif (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1150 | - if ($similarLangFallback === false) { |
|
1151 | - $similarLangFallback = $option['@value']; |
|
1152 | - } |
|
1153 | - } |
|
1154 | - } else { |
|
1155 | - $englishFallback = $option; |
|
1156 | - } |
|
1157 | - } |
|
1158 | - |
|
1159 | - if ($similarLangFallback !== false) { |
|
1160 | - return $similarLangFallback; |
|
1161 | - } elseif ($englishFallback !== false) { |
|
1162 | - return $englishFallback; |
|
1163 | - } |
|
1164 | - return (string) $fallback; |
|
1165 | - } |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * parses the app data array and enhanced the 'description' value |
|
1169 | - * |
|
1170 | - * @param array $data the app data |
|
1171 | - * @param string $lang |
|
1172 | - * @return array improved app data |
|
1173 | - */ |
|
1174 | - public static function parseAppInfo(array $data, $lang = null): array { |
|
1175 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1176 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1177 | - } |
|
1178 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1179 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1180 | - } |
|
1181 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1182 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1183 | - } elseif (isset($data['description']) && is_string($data['description'])) { |
|
1184 | - $data['description'] = trim($data['description']); |
|
1185 | - } else { |
|
1186 | - $data['description'] = ''; |
|
1187 | - } |
|
1188 | - |
|
1189 | - return $data; |
|
1190 | - } |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * @param \OCP\IConfig $config |
|
1194 | - * @param \OCP\IL10N $l |
|
1195 | - * @param array $info |
|
1196 | - * @throws \Exception |
|
1197 | - */ |
|
1198 | - public static function checkAppDependencies(\OCP\IConfig $config, \OCP\IL10N $l, array $info, bool $ignoreMax) { |
|
1199 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1200 | - $missing = $dependencyAnalyzer->analyze($info, $ignoreMax); |
|
1201 | - if (!empty($missing)) { |
|
1202 | - $missingMsg = implode(PHP_EOL, $missing); |
|
1203 | - throw new \Exception( |
|
1204 | - $l->t('App "%1$s" cannot be installed because the following dependencies are not fulfilled: %2$s', |
|
1205 | - [$info['name'], $missingMsg] |
|
1206 | - ) |
|
1207 | - ); |
|
1208 | - } |
|
1209 | - } |
|
73 | + private static $adminForms = []; |
|
74 | + private static $personalForms = []; |
|
75 | + private static $appTypes = []; |
|
76 | + private static $loadedApps = []; |
|
77 | + private static $altLogin = []; |
|
78 | + private static $alreadyRegistered = []; |
|
79 | + public const supportedApp = 300; |
|
80 | + public const officialApp = 200; |
|
81 | + |
|
82 | + /** |
|
83 | + * clean the appId |
|
84 | + * |
|
85 | + * @psalm-taint-escape file |
|
86 | + * @psalm-taint-escape include |
|
87 | + * |
|
88 | + * @param string $app AppId that needs to be cleaned |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public static function cleanAppId(string $app): string { |
|
92 | + return str_replace(['\0', '/', '\\', '..'], '', $app); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Check if an app is loaded |
|
97 | + * |
|
98 | + * @param string $app |
|
99 | + * @return bool |
|
100 | + */ |
|
101 | + public static function isAppLoaded(string $app): bool { |
|
102 | + return isset(self::$loadedApps[$app]); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * loads all apps |
|
107 | + * |
|
108 | + * @param string[] $types |
|
109 | + * @return bool |
|
110 | + * |
|
111 | + * This function walks through the ownCloud directory and loads all apps |
|
112 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
113 | + * exists. |
|
114 | + * |
|
115 | + * if $types is set to non-empty array, only apps of those types will be loaded |
|
116 | + */ |
|
117 | + public static function loadApps(array $types = []): bool { |
|
118 | + if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
119 | + return false; |
|
120 | + } |
|
121 | + // Load the enabled apps here |
|
122 | + $apps = self::getEnabledApps(); |
|
123 | + |
|
124 | + // Add each apps' folder as allowed class path |
|
125 | + foreach ($apps as $app) { |
|
126 | + // If the app is already loaded then autoloading it makes no sense |
|
127 | + if (!isset(self::$loadedApps[$app])) { |
|
128 | + $path = self::getAppPath($app); |
|
129 | + if ($path !== false) { |
|
130 | + self::registerAutoloading($app, $path); |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + // prevent app.php from printing output |
|
136 | + ob_start(); |
|
137 | + foreach ($apps as $app) { |
|
138 | + if (!isset(self::$loadedApps[$app]) && ($types === [] || self::isType($app, $types))) { |
|
139 | + try { |
|
140 | + self::loadApp($app); |
|
141 | + } catch (\Throwable $e) { |
|
142 | + \OC::$server->get(LoggerInterface::class)->emergency('Error during app loading: ' . $e->getMessage(), [ |
|
143 | + 'exception' => $e, |
|
144 | + 'app' => $app, |
|
145 | + ]); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + ob_end_clean(); |
|
150 | + |
|
151 | + return true; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * load a single app |
|
156 | + * |
|
157 | + * @param string $app |
|
158 | + * @throws Exception |
|
159 | + */ |
|
160 | + public static function loadApp(string $app) { |
|
161 | + self::$loadedApps[$app] = true; |
|
162 | + $appPath = self::getAppPath($app); |
|
163 | + if ($appPath === false) { |
|
164 | + return; |
|
165 | + } |
|
166 | + |
|
167 | + // in case someone calls loadApp() directly |
|
168 | + self::registerAutoloading($app, $appPath); |
|
169 | + |
|
170 | + /** @var Coordinator $coordinator */ |
|
171 | + $coordinator = \OC::$server->query(Coordinator::class); |
|
172 | + $isBootable = $coordinator->isBootable($app); |
|
173 | + |
|
174 | + $hasAppPhpFile = is_file($appPath . '/appinfo/app.php'); |
|
175 | + |
|
176 | + \OC::$server->getEventLogger()->start('bootstrap:load_app_' . $app, 'Load app: ' . $app); |
|
177 | + if ($isBootable && $hasAppPhpFile) { |
|
178 | + \OC::$server->getLogger()->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [ |
|
179 | + 'app' => $app, |
|
180 | + ]); |
|
181 | + } elseif ($hasAppPhpFile) { |
|
182 | + \OC::$server->getLogger()->debug('/appinfo/app.php is deprecated, use \OCP\AppFramework\Bootstrap\IBootstrap on the application class instead.', [ |
|
183 | + 'app' => $app, |
|
184 | + ]); |
|
185 | + try { |
|
186 | + self::requireAppFile($app); |
|
187 | + } catch (Throwable $ex) { |
|
188 | + if ($ex instanceof ServerNotAvailableException) { |
|
189 | + throw $ex; |
|
190 | + } |
|
191 | + if (!\OC::$server->getAppManager()->isShipped($app) && !self::isType($app, ['authentication'])) { |
|
192 | + \OC::$server->getLogger()->logException($ex, [ |
|
193 | + 'message' => "App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(), |
|
194 | + ]); |
|
195 | + |
|
196 | + // Only disable apps which are not shipped and that are not authentication apps |
|
197 | + \OC::$server->getAppManager()->disableApp($app, true); |
|
198 | + } else { |
|
199 | + \OC::$server->getLogger()->logException($ex, [ |
|
200 | + 'message' => "App $app threw an error during app.php load: " . $ex->getMessage(), |
|
201 | + ]); |
|
202 | + } |
|
203 | + } |
|
204 | + } |
|
205 | + \OC::$server->getEventLogger()->end('bootstrap:load_app_' . $app); |
|
206 | + |
|
207 | + $coordinator->bootApp($app); |
|
208 | + |
|
209 | + $info = self::getAppInfo($app); |
|
210 | + if (!empty($info['activity']['filters'])) { |
|
211 | + foreach ($info['activity']['filters'] as $filter) { |
|
212 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
213 | + } |
|
214 | + } |
|
215 | + if (!empty($info['activity']['settings'])) { |
|
216 | + foreach ($info['activity']['settings'] as $setting) { |
|
217 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
218 | + } |
|
219 | + } |
|
220 | + if (!empty($info['activity']['providers'])) { |
|
221 | + foreach ($info['activity']['providers'] as $provider) { |
|
222 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + if (!empty($info['settings']['admin'])) { |
|
227 | + foreach ($info['settings']['admin'] as $setting) { |
|
228 | + \OC::$server->get(ISettingsManager::class)->registerSetting('admin', $setting); |
|
229 | + } |
|
230 | + } |
|
231 | + if (!empty($info['settings']['admin-section'])) { |
|
232 | + foreach ($info['settings']['admin-section'] as $section) { |
|
233 | + \OC::$server->get(ISettingsManager::class)->registerSection('admin', $section); |
|
234 | + } |
|
235 | + } |
|
236 | + if (!empty($info['settings']['personal'])) { |
|
237 | + foreach ($info['settings']['personal'] as $setting) { |
|
238 | + \OC::$server->get(ISettingsManager::class)->registerSetting('personal', $setting); |
|
239 | + } |
|
240 | + } |
|
241 | + if (!empty($info['settings']['personal-section'])) { |
|
242 | + foreach ($info['settings']['personal-section'] as $section) { |
|
243 | + \OC::$server->get(ISettingsManager::class)->registerSection('personal', $section); |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + if (!empty($info['collaboration']['plugins'])) { |
|
248 | + // deal with one or many plugin entries |
|
249 | + $plugins = isset($info['collaboration']['plugins']['plugin']['@value']) ? |
|
250 | + [$info['collaboration']['plugins']['plugin']] : $info['collaboration']['plugins']['plugin']; |
|
251 | + foreach ($plugins as $plugin) { |
|
252 | + if ($plugin['@attributes']['type'] === 'collaborator-search') { |
|
253 | + $pluginInfo = [ |
|
254 | + 'shareType' => $plugin['@attributes']['share-type'], |
|
255 | + 'class' => $plugin['@value'], |
|
256 | + ]; |
|
257 | + \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); |
|
258 | + } elseif ($plugin['@attributes']['type'] === 'autocomplete-sort') { |
|
259 | + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); |
|
260 | + } |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * @internal |
|
267 | + * @param string $app |
|
268 | + * @param string $path |
|
269 | + * @param bool $force |
|
270 | + */ |
|
271 | + public static function registerAutoloading(string $app, string $path, bool $force = false) { |
|
272 | + $key = $app . '-' . $path; |
|
273 | + if (!$force && isset(self::$alreadyRegistered[$key])) { |
|
274 | + return; |
|
275 | + } |
|
276 | + |
|
277 | + self::$alreadyRegistered[$key] = true; |
|
278 | + |
|
279 | + // Register on PSR-4 composer autoloader |
|
280 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
281 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
282 | + |
|
283 | + if (file_exists($path . '/composer/autoload.php')) { |
|
284 | + require_once $path . '/composer/autoload.php'; |
|
285 | + } else { |
|
286 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
287 | + // Register on legacy autoloader |
|
288 | + \OC::$loader->addValidRoot($path); |
|
289 | + } |
|
290 | + |
|
291 | + // Register Test namespace only when testing |
|
292 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
293 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Load app.php from the given app |
|
299 | + * |
|
300 | + * @param string $app app name |
|
301 | + * @throws Error |
|
302 | + */ |
|
303 | + private static function requireAppFile(string $app) { |
|
304 | + // encapsulated here to avoid variable scope conflicts |
|
305 | + require_once $app . '/appinfo/app.php'; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * check if an app is of a specific type |
|
310 | + * |
|
311 | + * @param string $app |
|
312 | + * @param array $types |
|
313 | + * @return bool |
|
314 | + */ |
|
315 | + public static function isType(string $app, array $types): bool { |
|
316 | + $appTypes = self::getAppTypes($app); |
|
317 | + foreach ($types as $type) { |
|
318 | + if (array_search($type, $appTypes) !== false) { |
|
319 | + return true; |
|
320 | + } |
|
321 | + } |
|
322 | + return false; |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * get the types of an app |
|
327 | + * |
|
328 | + * @param string $app |
|
329 | + * @return array |
|
330 | + */ |
|
331 | + private static function getAppTypes(string $app): array { |
|
332 | + //load the cache |
|
333 | + if (count(self::$appTypes) == 0) { |
|
334 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
335 | + } |
|
336 | + |
|
337 | + if (isset(self::$appTypes[$app])) { |
|
338 | + return explode(',', self::$appTypes[$app]); |
|
339 | + } |
|
340 | + |
|
341 | + return []; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * read app types from info.xml and cache them in the database |
|
346 | + */ |
|
347 | + public static function setAppTypes(string $app) { |
|
348 | + $appManager = \OC::$server->getAppManager(); |
|
349 | + $appData = $appManager->getAppInfo($app); |
|
350 | + if (!is_array($appData)) { |
|
351 | + return; |
|
352 | + } |
|
353 | + |
|
354 | + if (isset($appData['types'])) { |
|
355 | + $appTypes = implode(',', $appData['types']); |
|
356 | + } else { |
|
357 | + $appTypes = ''; |
|
358 | + $appData['types'] = []; |
|
359 | + } |
|
360 | + |
|
361 | + $config = \OC::$server->getConfig(); |
|
362 | + $config->setAppValue($app, 'types', $appTypes); |
|
363 | + |
|
364 | + if ($appManager->hasProtectedAppType($appData['types'])) { |
|
365 | + $enabled = $config->getAppValue($app, 'enabled', 'yes'); |
|
366 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
367 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Returns apps enabled for the current user. |
|
374 | + * |
|
375 | + * @param bool $forceRefresh whether to refresh the cache |
|
376 | + * @param bool $all whether to return apps for all users, not only the |
|
377 | + * currently logged in one |
|
378 | + * @return string[] |
|
379 | + */ |
|
380 | + public static function getEnabledApps(bool $forceRefresh = false, bool $all = false): array { |
|
381 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
382 | + return []; |
|
383 | + } |
|
384 | + // in incognito mode or when logged out, $user will be false, |
|
385 | + // which is also the case during an upgrade |
|
386 | + $appManager = \OC::$server->getAppManager(); |
|
387 | + if ($all) { |
|
388 | + $user = null; |
|
389 | + } else { |
|
390 | + $user = \OC::$server->getUserSession()->getUser(); |
|
391 | + } |
|
392 | + |
|
393 | + if (is_null($user)) { |
|
394 | + $apps = $appManager->getInstalledApps(); |
|
395 | + } else { |
|
396 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
397 | + } |
|
398 | + $apps = array_filter($apps, function ($app) { |
|
399 | + return $app !== 'files';//we add this manually |
|
400 | + }); |
|
401 | + sort($apps); |
|
402 | + array_unshift($apps, 'files'); |
|
403 | + return $apps; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * checks whether or not an app is enabled |
|
408 | + * |
|
409 | + * @param string $app app |
|
410 | + * @return bool |
|
411 | + * @deprecated 13.0.0 use \OC::$server->getAppManager()->isEnabledForUser($appId) |
|
412 | + * |
|
413 | + * This function checks whether or not an app is enabled. |
|
414 | + */ |
|
415 | + public static function isEnabled(string $app): bool { |
|
416 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * enables an app |
|
421 | + * |
|
422 | + * @param string $appId |
|
423 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
424 | + * @throws \Exception |
|
425 | + * @return void |
|
426 | + * |
|
427 | + * This function set an app as enabled in appconfig. |
|
428 | + */ |
|
429 | + public function enable(string $appId, |
|
430 | + array $groups = []) { |
|
431 | + |
|
432 | + // Check if app is already downloaded |
|
433 | + /** @var Installer $installer */ |
|
434 | + $installer = \OC::$server->query(Installer::class); |
|
435 | + $isDownloaded = $installer->isDownloaded($appId); |
|
436 | + |
|
437 | + if (!$isDownloaded) { |
|
438 | + $installer->downloadApp($appId); |
|
439 | + } |
|
440 | + |
|
441 | + $installer->installApp($appId); |
|
442 | + |
|
443 | + $appManager = \OC::$server->getAppManager(); |
|
444 | + if ($groups !== []) { |
|
445 | + $groupManager = \OC::$server->getGroupManager(); |
|
446 | + $groupsList = []; |
|
447 | + foreach ($groups as $group) { |
|
448 | + $groupItem = $groupManager->get($group); |
|
449 | + if ($groupItem instanceof \OCP\IGroup) { |
|
450 | + $groupsList[] = $groupManager->get($group); |
|
451 | + } |
|
452 | + } |
|
453 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
454 | + } else { |
|
455 | + $appManager->enableApp($appId); |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get the path where to install apps |
|
461 | + * |
|
462 | + * @return string|false |
|
463 | + */ |
|
464 | + public static function getInstallPath() { |
|
465 | + foreach (OC::$APPSROOTS as $dir) { |
|
466 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
467 | + return $dir['path']; |
|
468 | + } |
|
469 | + } |
|
470 | + |
|
471 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR); |
|
472 | + return null; |
|
473 | + } |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * search for an app in all app-directories |
|
478 | + * |
|
479 | + * @param string $appId |
|
480 | + * @return false|string |
|
481 | + */ |
|
482 | + public static function findAppInDirectories(string $appId) { |
|
483 | + $sanitizedAppId = self::cleanAppId($appId); |
|
484 | + if ($sanitizedAppId !== $appId) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + static $app_dir = []; |
|
488 | + |
|
489 | + if (isset($app_dir[$appId])) { |
|
490 | + return $app_dir[$appId]; |
|
491 | + } |
|
492 | + |
|
493 | + $possibleApps = []; |
|
494 | + foreach (OC::$APPSROOTS as $dir) { |
|
495 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
496 | + $possibleApps[] = $dir; |
|
497 | + } |
|
498 | + } |
|
499 | + |
|
500 | + if (empty($possibleApps)) { |
|
501 | + return false; |
|
502 | + } elseif (count($possibleApps) === 1) { |
|
503 | + $dir = array_shift($possibleApps); |
|
504 | + $app_dir[$appId] = $dir; |
|
505 | + return $dir; |
|
506 | + } else { |
|
507 | + $versionToLoad = []; |
|
508 | + foreach ($possibleApps as $possibleApp) { |
|
509 | + $version = self::getAppVersionByPath($possibleApp['path'] . '/' . $appId); |
|
510 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
511 | + $versionToLoad = [ |
|
512 | + 'dir' => $possibleApp, |
|
513 | + 'version' => $version, |
|
514 | + ]; |
|
515 | + } |
|
516 | + } |
|
517 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
518 | + return $versionToLoad['dir']; |
|
519 | + //TODO - write test |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + /** |
|
524 | + * Get the directory for the given app. |
|
525 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
526 | + * |
|
527 | + * @psalm-taint-specialize |
|
528 | + * |
|
529 | + * @param string $appId |
|
530 | + * @return string|false |
|
531 | + * @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath() |
|
532 | + */ |
|
533 | + public static function getAppPath(string $appId) { |
|
534 | + if ($appId === null || trim($appId) === '') { |
|
535 | + return false; |
|
536 | + } |
|
537 | + |
|
538 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
539 | + return $dir['path'] . '/' . $appId; |
|
540 | + } |
|
541 | + return false; |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * Get the path for the given app on the access |
|
546 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
547 | + * |
|
548 | + * @param string $appId |
|
549 | + * @return string|false |
|
550 | + * @deprecated 18.0.0 use \OC::$server->getAppManager()->getAppWebPath() |
|
551 | + */ |
|
552 | + public static function getAppWebPath(string $appId) { |
|
553 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
554 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
555 | + } |
|
556 | + return false; |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * get the last version of the app from appinfo/info.xml |
|
561 | + * |
|
562 | + * @param string $appId |
|
563 | + * @param bool $useCache |
|
564 | + * @return string |
|
565 | + * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppVersion() |
|
566 | + */ |
|
567 | + public static function getAppVersion(string $appId, bool $useCache = true): string { |
|
568 | + return \OC::$server->getAppManager()->getAppVersion($appId, $useCache); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * get app's version based on it's path |
|
573 | + * |
|
574 | + * @param string $path |
|
575 | + * @return string |
|
576 | + */ |
|
577 | + public static function getAppVersionByPath(string $path): string { |
|
578 | + $infoFile = $path . '/appinfo/info.xml'; |
|
579 | + $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); |
|
580 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
581 | + } |
|
582 | + |
|
583 | + |
|
584 | + /** |
|
585 | + * Read all app metadata from the info.xml file |
|
586 | + * |
|
587 | + * @param string $appId id of the app or the path of the info.xml file |
|
588 | + * @param bool $path |
|
589 | + * @param string $lang |
|
590 | + * @return array|null |
|
591 | + * @note all data is read from info.xml, not just pre-defined fields |
|
592 | + * @deprecated 14.0.0 use \OC::$server->getAppManager()->getAppInfo() |
|
593 | + */ |
|
594 | + public static function getAppInfo(string $appId, bool $path = false, string $lang = null) { |
|
595 | + return \OC::$server->getAppManager()->getAppInfo($appId, $path, $lang); |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * Returns the navigation |
|
600 | + * |
|
601 | + * @return array |
|
602 | + * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll() |
|
603 | + * |
|
604 | + * This function returns an array containing all entries added. The |
|
605 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
606 | + * given for each app the following keys exist: |
|
607 | + * - active: boolean, signals if the user is on this navigation entry |
|
608 | + */ |
|
609 | + public static function getNavigation(): array { |
|
610 | + return OC::$server->getNavigationManager()->getAll(); |
|
611 | + } |
|
612 | + |
|
613 | + /** |
|
614 | + * Returns the Settings Navigation |
|
615 | + * |
|
616 | + * @return string[] |
|
617 | + * @deprecated 14.0.0 use \OC::$server->getNavigationManager()->getAll('settings') |
|
618 | + * |
|
619 | + * This function returns an array containing all settings pages added. The |
|
620 | + * entries are sorted by the key 'order' ascending. |
|
621 | + */ |
|
622 | + public static function getSettingsNavigation(): array { |
|
623 | + return OC::$server->getNavigationManager()->getAll('settings'); |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * get the id of loaded app |
|
628 | + * |
|
629 | + * @return string |
|
630 | + */ |
|
631 | + public static function getCurrentApp(): string { |
|
632 | + $request = \OC::$server->getRequest(); |
|
633 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
634 | + $topFolder = substr($script, 0, strpos($script, '/') ?: 0); |
|
635 | + if (empty($topFolder)) { |
|
636 | + $path_info = $request->getPathInfo(); |
|
637 | + if ($path_info) { |
|
638 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
639 | + } |
|
640 | + } |
|
641 | + if ($topFolder == 'apps') { |
|
642 | + $length = strlen($topFolder); |
|
643 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1) ?: ''; |
|
644 | + } else { |
|
645 | + return $topFolder; |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + /** |
|
650 | + * @param string $type |
|
651 | + * @return array |
|
652 | + */ |
|
653 | + public static function getForms(string $type): array { |
|
654 | + $forms = []; |
|
655 | + switch ($type) { |
|
656 | + case 'admin': |
|
657 | + $source = self::$adminForms; |
|
658 | + break; |
|
659 | + case 'personal': |
|
660 | + $source = self::$personalForms; |
|
661 | + break; |
|
662 | + default: |
|
663 | + return []; |
|
664 | + } |
|
665 | + foreach ($source as $form) { |
|
666 | + $forms[] = include $form; |
|
667 | + } |
|
668 | + return $forms; |
|
669 | + } |
|
670 | + |
|
671 | + /** |
|
672 | + * register an admin form to be shown |
|
673 | + * |
|
674 | + * @param string $app |
|
675 | + * @param string $page |
|
676 | + */ |
|
677 | + public static function registerAdmin(string $app, string $page) { |
|
678 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * register a personal form to be shown |
|
683 | + * @param string $app |
|
684 | + * @param string $page |
|
685 | + */ |
|
686 | + public static function registerPersonal(string $app, string $page) { |
|
687 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * @param array $entry |
|
692 | + * @deprecated 20.0.0 Please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface |
|
693 | + */ |
|
694 | + public static function registerLogIn(array $entry) { |
|
695 | + \OC::$server->getLogger()->debug('OC_App::registerLogIn() is deprecated, please register your alternative login option using the registerAlternativeLogin() on the RegistrationContext in your Application class implementing the OCP\Authentication\IAlternativeLogin interface'); |
|
696 | + self::$altLogin[] = $entry; |
|
697 | + } |
|
698 | + |
|
699 | + /** |
|
700 | + * @return array |
|
701 | + */ |
|
702 | + public static function getAlternativeLogIns(): array { |
|
703 | + /** @var Coordinator $bootstrapCoordinator */ |
|
704 | + $bootstrapCoordinator = \OC::$server->query(Coordinator::class); |
|
705 | + |
|
706 | + foreach ($bootstrapCoordinator->getRegistrationContext()->getAlternativeLogins() as $registration) { |
|
707 | + if (!in_array(IAlternativeLogin::class, class_implements($registration->getService()), true)) { |
|
708 | + \OC::$server->getLogger()->error('Alternative login option {option} does not implement {interface} and is therefore ignored.', [ |
|
709 | + 'option' => $registration->getService(), |
|
710 | + 'interface' => IAlternativeLogin::class, |
|
711 | + 'app' => $registration->getAppId(), |
|
712 | + ]); |
|
713 | + continue; |
|
714 | + } |
|
715 | + |
|
716 | + try { |
|
717 | + /** @var IAlternativeLogin $provider */ |
|
718 | + $provider = \OC::$server->query($registration->getService()); |
|
719 | + } catch (QueryException $e) { |
|
720 | + \OC::$server->getLogger()->logException($e, [ |
|
721 | + 'message' => 'Alternative login option {option} can not be initialised.', |
|
722 | + 'option' => $registration->getService(), |
|
723 | + 'app' => $registration->getAppId(), |
|
724 | + ]); |
|
725 | + } |
|
726 | + |
|
727 | + try { |
|
728 | + $provider->load(); |
|
729 | + |
|
730 | + self::$altLogin[] = [ |
|
731 | + 'name' => $provider->getLabel(), |
|
732 | + 'href' => $provider->getLink(), |
|
733 | + 'style' => $provider->getClass(), |
|
734 | + ]; |
|
735 | + } catch (Throwable $e) { |
|
736 | + \OC::$server->getLogger()->logException($e, [ |
|
737 | + 'message' => 'Alternative login option {option} had an error while loading.', |
|
738 | + 'option' => $registration->getService(), |
|
739 | + 'app' => $registration->getAppId(), |
|
740 | + ]); |
|
741 | + } |
|
742 | + } |
|
743 | + |
|
744 | + return self::$altLogin; |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * get a list of all apps in the apps folder |
|
749 | + * |
|
750 | + * @return string[] an array of app names (string IDs) |
|
751 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
752 | + */ |
|
753 | + public static function getAllApps(): array { |
|
754 | + $apps = []; |
|
755 | + |
|
756 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
757 | + if (!is_readable($apps_dir['path'])) { |
|
758 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN); |
|
759 | + continue; |
|
760 | + } |
|
761 | + $dh = opendir($apps_dir['path']); |
|
762 | + |
|
763 | + if (is_resource($dh)) { |
|
764 | + while (($file = readdir($dh)) !== false) { |
|
765 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
766 | + $apps[] = $file; |
|
767 | + } |
|
768 | + } |
|
769 | + } |
|
770 | + } |
|
771 | + |
|
772 | + $apps = array_unique($apps); |
|
773 | + |
|
774 | + return $apps; |
|
775 | + } |
|
776 | + |
|
777 | + /** |
|
778 | + * List all supported apps |
|
779 | + * |
|
780 | + * @return array |
|
781 | + */ |
|
782 | + public function getSupportedApps(): array { |
|
783 | + /** @var \OCP\Support\Subscription\IRegistry $subscriptionRegistry */ |
|
784 | + $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
785 | + $supportedApps = $subscriptionRegistry->delegateGetSupportedApps(); |
|
786 | + return $supportedApps; |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * List all apps, this is used in apps.php |
|
791 | + * |
|
792 | + * @return array |
|
793 | + */ |
|
794 | + public function listAllApps(): array { |
|
795 | + $installedApps = OC_App::getAllApps(); |
|
796 | + |
|
797 | + $appManager = \OC::$server->getAppManager(); |
|
798 | + //we don't want to show configuration for these |
|
799 | + $blacklist = $appManager->getAlwaysEnabledApps(); |
|
800 | + $appList = []; |
|
801 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
802 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
803 | + $supportedApps = $this->getSupportedApps(); |
|
804 | + |
|
805 | + foreach ($installedApps as $app) { |
|
806 | + if (array_search($app, $blacklist) === false) { |
|
807 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
808 | + if (!is_array($info)) { |
|
809 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR); |
|
810 | + continue; |
|
811 | + } |
|
812 | + |
|
813 | + if (!isset($info['name'])) { |
|
814 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR); |
|
815 | + continue; |
|
816 | + } |
|
817 | + |
|
818 | + $enabled = \OC::$server->getConfig()->getAppValue($app, 'enabled', 'no'); |
|
819 | + $info['groups'] = null; |
|
820 | + if ($enabled === 'yes') { |
|
821 | + $active = true; |
|
822 | + } elseif ($enabled === 'no') { |
|
823 | + $active = false; |
|
824 | + } else { |
|
825 | + $active = true; |
|
826 | + $info['groups'] = $enabled; |
|
827 | + } |
|
828 | + |
|
829 | + $info['active'] = $active; |
|
830 | + |
|
831 | + if ($appManager->isShipped($app)) { |
|
832 | + $info['internal'] = true; |
|
833 | + $info['level'] = self::officialApp; |
|
834 | + $info['removable'] = false; |
|
835 | + } else { |
|
836 | + $info['internal'] = false; |
|
837 | + $info['removable'] = true; |
|
838 | + } |
|
839 | + |
|
840 | + if (in_array($app, $supportedApps)) { |
|
841 | + $info['level'] = self::supportedApp; |
|
842 | + } |
|
843 | + |
|
844 | + $appPath = self::getAppPath($app); |
|
845 | + if ($appPath !== false) { |
|
846 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
847 | + if (file_exists($appIcon)) { |
|
848 | + $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
849 | + $info['previewAsIcon'] = true; |
|
850 | + } else { |
|
851 | + $appIcon = $appPath . '/img/app.svg'; |
|
852 | + if (file_exists($appIcon)) { |
|
853 | + $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
|
854 | + $info['previewAsIcon'] = true; |
|
855 | + } |
|
856 | + } |
|
857 | + } |
|
858 | + // fix documentation |
|
859 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
860 | + foreach ($info['documentation'] as $key => $url) { |
|
861 | + // If it is not an absolute URL we assume it is a key |
|
862 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
863 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
864 | + $url = $urlGenerator->linkToDocs($url); |
|
865 | + } |
|
866 | + |
|
867 | + $info['documentation'][$key] = $url; |
|
868 | + } |
|
869 | + } |
|
870 | + |
|
871 | + $info['version'] = OC_App::getAppVersion($app); |
|
872 | + $appList[] = $info; |
|
873 | + } |
|
874 | + } |
|
875 | + |
|
876 | + return $appList; |
|
877 | + } |
|
878 | + |
|
879 | + public static function shouldUpgrade(string $app): bool { |
|
880 | + $versions = self::getAppVersions(); |
|
881 | + $currentVersion = OC_App::getAppVersion($app); |
|
882 | + if ($currentVersion && isset($versions[$app])) { |
|
883 | + $installedVersion = $versions[$app]; |
|
884 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
885 | + return true; |
|
886 | + } |
|
887 | + } |
|
888 | + return false; |
|
889 | + } |
|
890 | + |
|
891 | + /** |
|
892 | + * Adjust the number of version parts of $version1 to match |
|
893 | + * the number of version parts of $version2. |
|
894 | + * |
|
895 | + * @param string $version1 version to adjust |
|
896 | + * @param string $version2 version to take the number of parts from |
|
897 | + * @return string shortened $version1 |
|
898 | + */ |
|
899 | + private static function adjustVersionParts(string $version1, string $version2): string { |
|
900 | + $version1 = explode('.', $version1); |
|
901 | + $version2 = explode('.', $version2); |
|
902 | + // reduce $version1 to match the number of parts in $version2 |
|
903 | + while (count($version1) > count($version2)) { |
|
904 | + array_pop($version1); |
|
905 | + } |
|
906 | + // if $version1 does not have enough parts, add some |
|
907 | + while (count($version1) < count($version2)) { |
|
908 | + $version1[] = '0'; |
|
909 | + } |
|
910 | + return implode('.', $version1); |
|
911 | + } |
|
912 | + |
|
913 | + /** |
|
914 | + * Check whether the current ownCloud version matches the given |
|
915 | + * application's version requirements. |
|
916 | + * |
|
917 | + * The comparison is made based on the number of parts that the |
|
918 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
919 | + * app info version is expecting version 6.0, the comparison is |
|
920 | + * made on the first two parts of the ownCloud version. |
|
921 | + * This means that it's possible to specify "requiremin" => 6 |
|
922 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
923 | + * |
|
924 | + * @param string $ocVersion ownCloud version to check against |
|
925 | + * @param array $appInfo app info (from xml) |
|
926 | + * |
|
927 | + * @return boolean true if compatible, otherwise false |
|
928 | + */ |
|
929 | + public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ignoreMax = false): bool { |
|
930 | + $requireMin = ''; |
|
931 | + $requireMax = ''; |
|
932 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
933 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
934 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
935 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
936 | + } elseif (isset($appInfo['requiremin'])) { |
|
937 | + $requireMin = $appInfo['requiremin']; |
|
938 | + } elseif (isset($appInfo['require'])) { |
|
939 | + $requireMin = $appInfo['require']; |
|
940 | + } |
|
941 | + |
|
942 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
943 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
944 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
945 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
946 | + } elseif (isset($appInfo['requiremax'])) { |
|
947 | + $requireMax = $appInfo['requiremax']; |
|
948 | + } |
|
949 | + |
|
950 | + if (!empty($requireMin) |
|
951 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
952 | + ) { |
|
953 | + return false; |
|
954 | + } |
|
955 | + |
|
956 | + if (!$ignoreMax && !empty($requireMax) |
|
957 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
958 | + ) { |
|
959 | + return false; |
|
960 | + } |
|
961 | + |
|
962 | + return true; |
|
963 | + } |
|
964 | + |
|
965 | + /** |
|
966 | + * get the installed version of all apps |
|
967 | + */ |
|
968 | + public static function getAppVersions() { |
|
969 | + static $versions; |
|
970 | + |
|
971 | + if (!$versions) { |
|
972 | + $appConfig = \OC::$server->getAppConfig(); |
|
973 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
974 | + } |
|
975 | + return $versions; |
|
976 | + } |
|
977 | + |
|
978 | + /** |
|
979 | + * update the database for the app and call the update script |
|
980 | + * |
|
981 | + * @param string $appId |
|
982 | + * @return bool |
|
983 | + */ |
|
984 | + public static function updateApp(string $appId): bool { |
|
985 | + $appPath = self::getAppPath($appId); |
|
986 | + if ($appPath === false) { |
|
987 | + return false; |
|
988 | + } |
|
989 | + |
|
990 | + if (is_file($appPath . '/appinfo/database.xml')) { |
|
991 | + \OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId); |
|
992 | + return false; |
|
993 | + } |
|
994 | + |
|
995 | + \OC::$server->getAppManager()->clearAppsCache(); |
|
996 | + $l = \OC::$server->getL10N('core'); |
|
997 | + $appData = self::getAppInfo($appId, false, $l->getLanguageCode()); |
|
998 | + |
|
999 | + $ignoreMaxApps = \OC::$server->getConfig()->getSystemValue('app_install_overwrite', []); |
|
1000 | + $ignoreMax = in_array($appId, $ignoreMaxApps, true); |
|
1001 | + \OC_App::checkAppDependencies( |
|
1002 | + \OC::$server->getConfig(), |
|
1003 | + $l, |
|
1004 | + $appData, |
|
1005 | + $ignoreMax |
|
1006 | + ); |
|
1007 | + |
|
1008 | + self::registerAutoloading($appId, $appPath, true); |
|
1009 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1010 | + |
|
1011 | + $ms = new MigrationService($appId, \OC::$server->get(\OC\DB\Connection::class)); |
|
1012 | + $ms->migrate(); |
|
1013 | + |
|
1014 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1015 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1016 | + // update appversion in app manager |
|
1017 | + \OC::$server->getAppManager()->clearAppsCache(); |
|
1018 | + \OC::$server->getAppManager()->getAppVersion($appId, false); |
|
1019 | + |
|
1020 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1021 | + |
|
1022 | + //set remote/public handlers |
|
1023 | + if (array_key_exists('ocsid', $appData)) { |
|
1024 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1025 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1026 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1027 | + } |
|
1028 | + foreach ($appData['remote'] as $name => $path) { |
|
1029 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1030 | + } |
|
1031 | + foreach ($appData['public'] as $name => $path) { |
|
1032 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1033 | + } |
|
1034 | + |
|
1035 | + self::setAppTypes($appId); |
|
1036 | + |
|
1037 | + $version = \OC_App::getAppVersion($appId); |
|
1038 | + \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); |
|
1039 | + |
|
1040 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1041 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1042 | + )); |
|
1043 | + |
|
1044 | + return true; |
|
1045 | + } |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * @param string $appId |
|
1049 | + * @param string[] $steps |
|
1050 | + * @throws \OC\NeedsUpdateException |
|
1051 | + */ |
|
1052 | + public static function executeRepairSteps(string $appId, array $steps) { |
|
1053 | + if (empty($steps)) { |
|
1054 | + return; |
|
1055 | + } |
|
1056 | + // load the app |
|
1057 | + self::loadApp($appId); |
|
1058 | + |
|
1059 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1060 | + |
|
1061 | + // load the steps |
|
1062 | + $r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class)); |
|
1063 | + foreach ($steps as $step) { |
|
1064 | + try { |
|
1065 | + $r->addStep($step); |
|
1066 | + } catch (Exception $ex) { |
|
1067 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1068 | + \OC::$server->getLogger()->logException($ex); |
|
1069 | + } |
|
1070 | + } |
|
1071 | + // run the steps |
|
1072 | + $r->run(); |
|
1073 | + } |
|
1074 | + |
|
1075 | + public static function setupBackgroundJobs(array $jobs) { |
|
1076 | + $queue = \OC::$server->getJobList(); |
|
1077 | + foreach ($jobs as $job) { |
|
1078 | + $queue->add($job); |
|
1079 | + } |
|
1080 | + } |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * @param string $appId |
|
1084 | + * @param string[] $steps |
|
1085 | + */ |
|
1086 | + private static function setupLiveMigrations(string $appId, array $steps) { |
|
1087 | + $queue = \OC::$server->getJobList(); |
|
1088 | + foreach ($steps as $step) { |
|
1089 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1090 | + 'app' => $appId, |
|
1091 | + 'step' => $step]); |
|
1092 | + } |
|
1093 | + } |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * @param string $appId |
|
1097 | + * @return \OC\Files\View|false |
|
1098 | + */ |
|
1099 | + public static function getStorage(string $appId) { |
|
1100 | + if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
|
1101 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1102 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1103 | + if (!$view->file_exists($appId)) { |
|
1104 | + $view->mkdir($appId); |
|
1105 | + } |
|
1106 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1107 | + } else { |
|
1108 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR); |
|
1109 | + return false; |
|
1110 | + } |
|
1111 | + } else { |
|
1112 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR); |
|
1113 | + return false; |
|
1114 | + } |
|
1115 | + } |
|
1116 | + |
|
1117 | + protected static function findBestL10NOption(array $options, string $lang): string { |
|
1118 | + // only a single option |
|
1119 | + if (isset($options['@value'])) { |
|
1120 | + return $options['@value']; |
|
1121 | + } |
|
1122 | + |
|
1123 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1124 | + |
|
1125 | + $lang = strtolower($lang); |
|
1126 | + $similarLang = $lang; |
|
1127 | + if (strpos($similarLang, '_')) { |
|
1128 | + // For "de_DE" we want to find "de" and the other way around |
|
1129 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1130 | + } |
|
1131 | + |
|
1132 | + foreach ($options as $option) { |
|
1133 | + if (is_array($option)) { |
|
1134 | + if ($fallback === false) { |
|
1135 | + $fallback = $option['@value']; |
|
1136 | + } |
|
1137 | + |
|
1138 | + if (!isset($option['@attributes']['lang'])) { |
|
1139 | + continue; |
|
1140 | + } |
|
1141 | + |
|
1142 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1143 | + if ($attributeLang === $lang) { |
|
1144 | + return $option['@value']; |
|
1145 | + } |
|
1146 | + |
|
1147 | + if ($attributeLang === $similarLang) { |
|
1148 | + $similarLangFallback = $option['@value']; |
|
1149 | + } elseif (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1150 | + if ($similarLangFallback === false) { |
|
1151 | + $similarLangFallback = $option['@value']; |
|
1152 | + } |
|
1153 | + } |
|
1154 | + } else { |
|
1155 | + $englishFallback = $option; |
|
1156 | + } |
|
1157 | + } |
|
1158 | + |
|
1159 | + if ($similarLangFallback !== false) { |
|
1160 | + return $similarLangFallback; |
|
1161 | + } elseif ($englishFallback !== false) { |
|
1162 | + return $englishFallback; |
|
1163 | + } |
|
1164 | + return (string) $fallback; |
|
1165 | + } |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * parses the app data array and enhanced the 'description' value |
|
1169 | + * |
|
1170 | + * @param array $data the app data |
|
1171 | + * @param string $lang |
|
1172 | + * @return array improved app data |
|
1173 | + */ |
|
1174 | + public static function parseAppInfo(array $data, $lang = null): array { |
|
1175 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1176 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1177 | + } |
|
1178 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1179 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1180 | + } |
|
1181 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1182 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1183 | + } elseif (isset($data['description']) && is_string($data['description'])) { |
|
1184 | + $data['description'] = trim($data['description']); |
|
1185 | + } else { |
|
1186 | + $data['description'] = ''; |
|
1187 | + } |
|
1188 | + |
|
1189 | + return $data; |
|
1190 | + } |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * @param \OCP\IConfig $config |
|
1194 | + * @param \OCP\IL10N $l |
|
1195 | + * @param array $info |
|
1196 | + * @throws \Exception |
|
1197 | + */ |
|
1198 | + public static function checkAppDependencies(\OCP\IConfig $config, \OCP\IL10N $l, array $info, bool $ignoreMax) { |
|
1199 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1200 | + $missing = $dependencyAnalyzer->analyze($info, $ignoreMax); |
|
1201 | + if (!empty($missing)) { |
|
1202 | + $missingMsg = implode(PHP_EOL, $missing); |
|
1203 | + throw new \Exception( |
|
1204 | + $l->t('App "%1$s" cannot be installed because the following dependencies are not fulfilled: %2$s', |
|
1205 | + [$info['name'], $missingMsg] |
|
1206 | + ) |
|
1207 | + ); |
|
1208 | + } |
|
1209 | + } |
|
1210 | 1210 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | try { |
140 | 140 | self::loadApp($app); |
141 | 141 | } catch (\Throwable $e) { |
142 | - \OC::$server->get(LoggerInterface::class)->emergency('Error during app loading: ' . $e->getMessage(), [ |
|
142 | + \OC::$server->get(LoggerInterface::class)->emergency('Error during app loading: '.$e->getMessage(), [ |
|
143 | 143 | 'exception' => $e, |
144 | 144 | 'app' => $app, |
145 | 145 | ]); |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | $coordinator = \OC::$server->query(Coordinator::class); |
172 | 172 | $isBootable = $coordinator->isBootable($app); |
173 | 173 | |
174 | - $hasAppPhpFile = is_file($appPath . '/appinfo/app.php'); |
|
174 | + $hasAppPhpFile = is_file($appPath.'/appinfo/app.php'); |
|
175 | 175 | |
176 | - \OC::$server->getEventLogger()->start('bootstrap:load_app_' . $app, 'Load app: ' . $app); |
|
176 | + \OC::$server->getEventLogger()->start('bootstrap:load_app_'.$app, 'Load app: '.$app); |
|
177 | 177 | if ($isBootable && $hasAppPhpFile) { |
178 | 178 | \OC::$server->getLogger()->error('/appinfo/app.php is not loaded when \OCP\AppFramework\Bootstrap\IBootstrap on the application class is used. Migrate everything from app.php to the Application class.', [ |
179 | 179 | 'app' => $app, |
@@ -190,19 +190,19 @@ discard block |
||
190 | 190 | } |
191 | 191 | if (!\OC::$server->getAppManager()->isShipped($app) && !self::isType($app, ['authentication'])) { |
192 | 192 | \OC::$server->getLogger()->logException($ex, [ |
193 | - 'message' => "App $app threw an error during app.php load and will be disabled: " . $ex->getMessage(), |
|
193 | + 'message' => "App $app threw an error during app.php load and will be disabled: ".$ex->getMessage(), |
|
194 | 194 | ]); |
195 | 195 | |
196 | 196 | // Only disable apps which are not shipped and that are not authentication apps |
197 | 197 | \OC::$server->getAppManager()->disableApp($app, true); |
198 | 198 | } else { |
199 | 199 | \OC::$server->getLogger()->logException($ex, [ |
200 | - 'message' => "App $app threw an error during app.php load: " . $ex->getMessage(), |
|
200 | + 'message' => "App $app threw an error during app.php load: ".$ex->getMessage(), |
|
201 | 201 | ]); |
202 | 202 | } |
203 | 203 | } |
204 | 204 | } |
205 | - \OC::$server->getEventLogger()->end('bootstrap:load_app_' . $app); |
|
205 | + \OC::$server->getEventLogger()->end('bootstrap:load_app_'.$app); |
|
206 | 206 | |
207 | 207 | $coordinator->bootApp($app); |
208 | 208 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | * @param bool $force |
270 | 270 | */ |
271 | 271 | public static function registerAutoloading(string $app, string $path, bool $force = false) { |
272 | - $key = $app . '-' . $path; |
|
272 | + $key = $app.'-'.$path; |
|
273 | 273 | if (!$force && isset(self::$alreadyRegistered[$key])) { |
274 | 274 | return; |
275 | 275 | } |
@@ -280,17 +280,17 @@ discard block |
||
280 | 280 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
281 | 281 | \OC::$server->registerNamespace($app, $appNamespace); |
282 | 282 | |
283 | - if (file_exists($path . '/composer/autoload.php')) { |
|
284 | - require_once $path . '/composer/autoload.php'; |
|
283 | + if (file_exists($path.'/composer/autoload.php')) { |
|
284 | + require_once $path.'/composer/autoload.php'; |
|
285 | 285 | } else { |
286 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
286 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
287 | 287 | // Register on legacy autoloader |
288 | 288 | \OC::$loader->addValidRoot($path); |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Register Test namespace only when testing |
292 | 292 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
293 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
293 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 | |
@@ -302,7 +302,7 @@ discard block |
||
302 | 302 | */ |
303 | 303 | private static function requireAppFile(string $app) { |
304 | 304 | // encapsulated here to avoid variable scope conflicts |
305 | - require_once $app . '/appinfo/app.php'; |
|
305 | + require_once $app.'/appinfo/app.php'; |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -395,8 +395,8 @@ discard block |
||
395 | 395 | } else { |
396 | 396 | $apps = $appManager->getEnabledAppsForUser($user); |
397 | 397 | } |
398 | - $apps = array_filter($apps, function ($app) { |
|
399 | - return $app !== 'files';//we add this manually |
|
398 | + $apps = array_filter($apps, function($app) { |
|
399 | + return $app !== 'files'; //we add this manually |
|
400 | 400 | }); |
401 | 401 | sort($apps); |
402 | 402 | array_unshift($apps, 'files'); |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | $possibleApps = []; |
494 | 494 | foreach (OC::$APPSROOTS as $dir) { |
495 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
495 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
496 | 496 | $possibleApps[] = $dir; |
497 | 497 | } |
498 | 498 | } |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | } else { |
507 | 507 | $versionToLoad = []; |
508 | 508 | foreach ($possibleApps as $possibleApp) { |
509 | - $version = self::getAppVersionByPath($possibleApp['path'] . '/' . $appId); |
|
509 | + $version = self::getAppVersionByPath($possibleApp['path'].'/'.$appId); |
|
510 | 510 | if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
511 | 511 | $versionToLoad = [ |
512 | 512 | 'dir' => $possibleApp, |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | } |
537 | 537 | |
538 | 538 | if (($dir = self::findAppInDirectories($appId)) != false) { |
539 | - return $dir['path'] . '/' . $appId; |
|
539 | + return $dir['path'].'/'.$appId; |
|
540 | 540 | } |
541 | 541 | return false; |
542 | 542 | } |
@@ -551,7 +551,7 @@ discard block |
||
551 | 551 | */ |
552 | 552 | public static function getAppWebPath(string $appId) { |
553 | 553 | if (($dir = self::findAppInDirectories($appId)) != false) { |
554 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
554 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
555 | 555 | } |
556 | 556 | return false; |
557 | 557 | } |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * @return string |
576 | 576 | */ |
577 | 577 | public static function getAppVersionByPath(string $path): string { |
578 | - $infoFile = $path . '/appinfo/info.xml'; |
|
578 | + $infoFile = $path.'/appinfo/info.xml'; |
|
579 | 579 | $appData = \OC::$server->getAppManager()->getAppInfo($infoFile, true); |
580 | 580 | return isset($appData['version']) ? $appData['version'] : ''; |
581 | 581 | } |
@@ -675,7 +675,7 @@ discard block |
||
675 | 675 | * @param string $page |
676 | 676 | */ |
677 | 677 | public static function registerAdmin(string $app, string $page) { |
678 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
678 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | * @param string $page |
685 | 685 | */ |
686 | 686 | public static function registerPersonal(string $app, string $page) { |
687 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
687 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
688 | 688 | } |
689 | 689 | |
690 | 690 | /** |
@@ -755,14 +755,14 @@ discard block |
||
755 | 755 | |
756 | 756 | foreach (OC::$APPSROOTS as $apps_dir) { |
757 | 757 | if (!is_readable($apps_dir['path'])) { |
758 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN); |
|
758 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], ILogger::WARN); |
|
759 | 759 | continue; |
760 | 760 | } |
761 | 761 | $dh = opendir($apps_dir['path']); |
762 | 762 | |
763 | 763 | if (is_resource($dh)) { |
764 | 764 | while (($file = readdir($dh)) !== false) { |
765 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
765 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
766 | 766 | $apps[] = $file; |
767 | 767 | } |
768 | 768 | } |
@@ -806,12 +806,12 @@ discard block |
||
806 | 806 | if (array_search($app, $blacklist) === false) { |
807 | 807 | $info = OC_App::getAppInfo($app, false, $langCode); |
808 | 808 | if (!is_array($info)) { |
809 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR); |
|
809 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', ILogger::ERROR); |
|
810 | 810 | continue; |
811 | 811 | } |
812 | 812 | |
813 | 813 | if (!isset($info['name'])) { |
814 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR); |
|
814 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', ILogger::ERROR); |
|
815 | 815 | continue; |
816 | 816 | } |
817 | 817 | |
@@ -843,12 +843,12 @@ discard block |
||
843 | 843 | |
844 | 844 | $appPath = self::getAppPath($app); |
845 | 845 | if ($appPath !== false) { |
846 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
846 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
847 | 847 | if (file_exists($appIcon)) { |
848 | - $info['preview'] = $urlGenerator->imagePath($app, $app . '.svg'); |
|
848 | + $info['preview'] = $urlGenerator->imagePath($app, $app.'.svg'); |
|
849 | 849 | $info['previewAsIcon'] = true; |
850 | 850 | } else { |
851 | - $appIcon = $appPath . '/img/app.svg'; |
|
851 | + $appIcon = $appPath.'/img/app.svg'; |
|
852 | 852 | if (file_exists($appIcon)) { |
853 | 853 | $info['preview'] = $urlGenerator->imagePath($app, 'app.svg'); |
854 | 854 | $info['previewAsIcon'] = true; |
@@ -987,8 +987,8 @@ discard block |
||
987 | 987 | return false; |
988 | 988 | } |
989 | 989 | |
990 | - if (is_file($appPath . '/appinfo/database.xml')) { |
|
991 | - \OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId); |
|
990 | + if (is_file($appPath.'/appinfo/database.xml')) { |
|
991 | + \OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in '.$appId); |
|
992 | 992 | return false; |
993 | 993 | } |
994 | 994 | |
@@ -1026,10 +1026,10 @@ discard block |
||
1026 | 1026 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
1027 | 1027 | } |
1028 | 1028 | foreach ($appData['remote'] as $name => $path) { |
1029 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1029 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
1030 | 1030 | } |
1031 | 1031 | foreach ($appData['public'] as $name => $path) { |
1032 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1032 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
1033 | 1033 | } |
1034 | 1034 | |
1035 | 1035 | self::setAppTypes($appId); |
@@ -1099,17 +1099,17 @@ discard block |
||
1099 | 1099 | public static function getStorage(string $appId) { |
1100 | 1100 | if (\OC::$server->getAppManager()->isEnabledForUser($appId)) { //sanity check |
1101 | 1101 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
1102 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1102 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
1103 | 1103 | if (!$view->file_exists($appId)) { |
1104 | 1104 | $view->mkdir($appId); |
1105 | 1105 | } |
1106 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1106 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
1107 | 1107 | } else { |
1108 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR); |
|
1108 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', ILogger::ERROR); |
|
1109 | 1109 | return false; |
1110 | 1110 | } |
1111 | 1111 | } else { |
1112 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR); |
|
1112 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', ILogger::ERROR); |
|
1113 | 1113 | return false; |
1114 | 1114 | } |
1115 | 1115 | } |
@@ -1146,7 +1146,7 @@ discard block |
||
1146 | 1146 | |
1147 | 1147 | if ($attributeLang === $similarLang) { |
1148 | 1148 | $similarLangFallback = $option['@value']; |
1149 | - } elseif (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1149 | + } elseif (strpos($attributeLang, $similarLang.'_') === 0) { |
|
1150 | 1150 | if ($similarLangFallback === false) { |
1151 | 1151 | $similarLangFallback = $option['@value']; |
1152 | 1152 | } |
@@ -56,530 +56,530 @@ |
||
56 | 56 | use OCP\PreConditionNotMetException; |
57 | 57 | |
58 | 58 | class Connection extends \Doctrine\DBAL\Connection { |
59 | - /** @var string */ |
|
60 | - protected $tablePrefix; |
|
61 | - |
|
62 | - /** @var \OC\DB\Adapter $adapter */ |
|
63 | - protected $adapter; |
|
64 | - |
|
65 | - /** @var SystemConfig */ |
|
66 | - private $systemConfig; |
|
67 | - |
|
68 | - /** @var ILogger */ |
|
69 | - private $logger; |
|
70 | - |
|
71 | - protected $lockedTable = null; |
|
72 | - |
|
73 | - /** @var int */ |
|
74 | - protected $queriesBuilt = 0; |
|
75 | - |
|
76 | - /** @var int */ |
|
77 | - protected $queriesExecuted = 0; |
|
78 | - |
|
79 | - /** |
|
80 | - * @throws Exception |
|
81 | - */ |
|
82 | - public function connect() { |
|
83 | - try { |
|
84 | - if ($this->_conn) { |
|
85 | - return parent::connect(); |
|
86 | - } |
|
87 | - |
|
88 | - // Only trigger the event logger for the initial connect call |
|
89 | - $eventLogger = \OC::$server->getEventLogger(); |
|
90 | - $eventLogger->start('connect:db', 'db connection opened'); |
|
91 | - $status = parent::connect(); |
|
92 | - $eventLogger->end('connect:db'); |
|
93 | - |
|
94 | - return $status; |
|
95 | - } catch (Exception $e) { |
|
96 | - // throw a new exception to prevent leaking info from the stacktrace |
|
97 | - throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - public function getStats(): array { |
|
102 | - return [ |
|
103 | - 'built' => $this->queriesBuilt, |
|
104 | - 'executed' => $this->queriesExecuted, |
|
105 | - ]; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns a QueryBuilder for the connection. |
|
110 | - */ |
|
111 | - public function getQueryBuilder(): IQueryBuilder { |
|
112 | - $this->queriesBuilt++; |
|
113 | - return new QueryBuilder( |
|
114 | - new ConnectionAdapter($this), |
|
115 | - $this->systemConfig, |
|
116 | - $this->logger |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Gets the QueryBuilder for the connection. |
|
122 | - * |
|
123 | - * @return \Doctrine\DBAL\Query\QueryBuilder |
|
124 | - * @deprecated please use $this->getQueryBuilder() instead |
|
125 | - */ |
|
126 | - public function createQueryBuilder() { |
|
127 | - $backtrace = $this->getCallerBacktrace(); |
|
128 | - \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
129 | - $this->queriesBuilt++; |
|
130 | - return parent::createQueryBuilder(); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Gets the ExpressionBuilder for the connection. |
|
135 | - * |
|
136 | - * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
|
137 | - * @deprecated please use $this->getQueryBuilder()->expr() instead |
|
138 | - */ |
|
139 | - public function getExpressionBuilder() { |
|
140 | - $backtrace = $this->getCallerBacktrace(); |
|
141 | - \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
142 | - $this->queriesBuilt++; |
|
143 | - return parent::getExpressionBuilder(); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get the file and line that called the method where `getCallerBacktrace()` was used |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - protected function getCallerBacktrace() { |
|
152 | - $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
153 | - |
|
154 | - // 0 is the method where we use `getCallerBacktrace` |
|
155 | - // 1 is the target method which uses the method we want to log |
|
156 | - if (isset($traces[1])) { |
|
157 | - return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
158 | - } |
|
159 | - |
|
160 | - return ''; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return string |
|
165 | - */ |
|
166 | - public function getPrefix() { |
|
167 | - return $this->tablePrefix; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Initializes a new instance of the Connection class. |
|
172 | - * |
|
173 | - * @param array $params The connection parameters. |
|
174 | - * @param \Doctrine\DBAL\Driver $driver |
|
175 | - * @param \Doctrine\DBAL\Configuration $config |
|
176 | - * @param \Doctrine\Common\EventManager $eventManager |
|
177 | - * @throws \Exception |
|
178 | - */ |
|
179 | - public function __construct(array $params, Driver $driver, Configuration $config = null, |
|
180 | - EventManager $eventManager = null) { |
|
181 | - if (!isset($params['adapter'])) { |
|
182 | - throw new \Exception('adapter not set'); |
|
183 | - } |
|
184 | - if (!isset($params['tablePrefix'])) { |
|
185 | - throw new \Exception('tablePrefix not set'); |
|
186 | - } |
|
187 | - /** |
|
188 | - * @psalm-suppress InternalMethod |
|
189 | - */ |
|
190 | - parent::__construct($params, $driver, $config, $eventManager); |
|
191 | - $this->adapter = new $params['adapter']($this); |
|
192 | - $this->tablePrefix = $params['tablePrefix']; |
|
193 | - |
|
194 | - $this->systemConfig = \OC::$server->getSystemConfig(); |
|
195 | - $this->logger = \OC::$server->getLogger(); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Prepares an SQL statement. |
|
200 | - * |
|
201 | - * @param string $statement The SQL statement to prepare. |
|
202 | - * @param int|null $limit |
|
203 | - * @param int|null $offset |
|
204 | - * |
|
205 | - * @return Statement The prepared statement. |
|
206 | - * @throws Exception |
|
207 | - */ |
|
208 | - public function prepare($statement, $limit = null, $offset = null): Statement { |
|
209 | - if ($limit === -1 || $limit === null) { |
|
210 | - $limit = null; |
|
211 | - } else { |
|
212 | - $limit = (int) $limit; |
|
213 | - } |
|
214 | - if ($offset !== null) { |
|
215 | - $offset = (int) $offset; |
|
216 | - } |
|
217 | - if (!is_null($limit)) { |
|
218 | - $platform = $this->getDatabasePlatform(); |
|
219 | - $statement = $platform->modifyLimitQuery($statement, $limit, $offset); |
|
220 | - } |
|
221 | - $statement = $this->replaceTablePrefix($statement); |
|
222 | - $statement = $this->adapter->fixupStatement($statement); |
|
223 | - |
|
224 | - return parent::prepare($statement); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Executes an, optionally parametrized, SQL query. |
|
229 | - * |
|
230 | - * If the query is parametrized, a prepared statement is used. |
|
231 | - * If an SQLLogger is configured, the execution is logged. |
|
232 | - * |
|
233 | - * @param string $sql The SQL query to execute. |
|
234 | - * @param array $params The parameters to bind to the query, if any. |
|
235 | - * @param array $types The types the previous parameters are in. |
|
236 | - * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
|
237 | - * |
|
238 | - * @return Result The executed statement. |
|
239 | - * |
|
240 | - * @throws \Doctrine\DBAL\Exception |
|
241 | - */ |
|
242 | - public function executeQuery(string $sql, array $params = [], $types = [], QueryCacheProfile $qcp = null): Result { |
|
243 | - $sql = $this->replaceTablePrefix($sql); |
|
244 | - $sql = $this->adapter->fixupStatement($sql); |
|
245 | - $this->queriesExecuted++; |
|
246 | - $this->logQueryToFile($sql); |
|
247 | - return parent::executeQuery($sql, $params, $types, $qcp); |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @throws Exception |
|
252 | - */ |
|
253 | - public function executeUpdate(string $sql, array $params = [], array $types = []): int { |
|
254 | - $sql = $this->replaceTablePrefix($sql); |
|
255 | - $sql = $this->adapter->fixupStatement($sql); |
|
256 | - $this->queriesExecuted++; |
|
257 | - $this->logQueryToFile($sql); |
|
258 | - return parent::executeUpdate($sql, $params, $types); |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
263 | - * and returns the number of affected rows. |
|
264 | - * |
|
265 | - * This method supports PDO binding types as well as DBAL mapping types. |
|
266 | - * |
|
267 | - * @param string $sql The SQL query. |
|
268 | - * @param array $params The query parameters. |
|
269 | - * @param array $types The parameter types. |
|
270 | - * |
|
271 | - * @return int The number of affected rows. |
|
272 | - * |
|
273 | - * @throws \Doctrine\DBAL\Exception |
|
274 | - */ |
|
275 | - public function executeStatement($sql, array $params = [], array $types = []): int { |
|
276 | - $sql = $this->replaceTablePrefix($sql); |
|
277 | - $sql = $this->adapter->fixupStatement($sql); |
|
278 | - $this->queriesExecuted++; |
|
279 | - $this->logQueryToFile($sql); |
|
280 | - return parent::executeStatement($sql, $params, $types); |
|
281 | - } |
|
282 | - |
|
283 | - protected function logQueryToFile(string $sql): void { |
|
284 | - $logFile = $this->systemConfig->getValue('query_log_file', ''); |
|
285 | - if ($logFile !== '' && is_writable(dirname($logFile)) && (!file_exists($logFile) || is_writable($logFile))) { |
|
286 | - file_put_contents( |
|
287 | - $this->systemConfig->getValue('query_log_file', ''), |
|
288 | - $sql . "\n", |
|
289 | - FILE_APPEND |
|
290 | - ); |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Returns the ID of the last inserted row, or the last value from a sequence object, |
|
296 | - * depending on the underlying driver. |
|
297 | - * |
|
298 | - * Note: This method may not return a meaningful or consistent result across different drivers, |
|
299 | - * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
|
300 | - * columns or sequences. |
|
301 | - * |
|
302 | - * @param string $seqName Name of the sequence object from which the ID should be returned. |
|
303 | - * |
|
304 | - * @return string the last inserted ID. |
|
305 | - * @throws Exception |
|
306 | - */ |
|
307 | - public function lastInsertId($seqName = null) { |
|
308 | - if ($seqName) { |
|
309 | - $seqName = $this->replaceTablePrefix($seqName); |
|
310 | - } |
|
311 | - return $this->adapter->lastInsertId($seqName); |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * @internal |
|
316 | - * @throws Exception |
|
317 | - */ |
|
318 | - public function realLastInsertId($seqName = null) { |
|
319 | - return parent::lastInsertId($seqName); |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
324 | - * it is needed that there is also a unique constraint on the values. Then this method will |
|
325 | - * catch the exception and return 0. |
|
326 | - * |
|
327 | - * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
328 | - * @param array $input data that should be inserted into the table (column name => value) |
|
329 | - * @param array|null $compare List of values that should be checked for "if not exists" |
|
330 | - * If this is null or an empty array, all keys of $input will be compared |
|
331 | - * Please note: text fields (clob) must not be used in the compare array |
|
332 | - * @return int number of inserted rows |
|
333 | - * @throws \Doctrine\DBAL\Exception |
|
334 | - * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
335 | - */ |
|
336 | - public function insertIfNotExist($table, $input, array $compare = null) { |
|
337 | - return $this->adapter->insertIfNotExist($table, $input, $compare); |
|
338 | - } |
|
339 | - |
|
340 | - public function insertIgnoreConflict(string $table, array $values) : int { |
|
341 | - return $this->adapter->insertIgnoreConflict($table, $values); |
|
342 | - } |
|
343 | - |
|
344 | - private function getType($value) { |
|
345 | - if (is_bool($value)) { |
|
346 | - return IQueryBuilder::PARAM_BOOL; |
|
347 | - } elseif (is_int($value)) { |
|
348 | - return IQueryBuilder::PARAM_INT; |
|
349 | - } else { |
|
350 | - return IQueryBuilder::PARAM_STR; |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Insert or update a row value |
|
356 | - * |
|
357 | - * @param string $table |
|
358 | - * @param array $keys (column name => value) |
|
359 | - * @param array $values (column name => value) |
|
360 | - * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
361 | - * @return int number of new rows |
|
362 | - * @throws \Doctrine\DBAL\Exception |
|
363 | - * @throws PreConditionNotMetException |
|
364 | - */ |
|
365 | - public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { |
|
366 | - try { |
|
367 | - $insertQb = $this->getQueryBuilder(); |
|
368 | - $insertQb->insert($table) |
|
369 | - ->values( |
|
370 | - array_map(function ($value) use ($insertQb) { |
|
371 | - return $insertQb->createNamedParameter($value, $this->getType($value)); |
|
372 | - }, array_merge($keys, $values)) |
|
373 | - ); |
|
374 | - return $insertQb->execute(); |
|
375 | - } catch (NotNullConstraintViolationException $e) { |
|
376 | - throw $e; |
|
377 | - } catch (ConstraintViolationException $e) { |
|
378 | - // value already exists, try update |
|
379 | - $updateQb = $this->getQueryBuilder(); |
|
380 | - $updateQb->update($table); |
|
381 | - foreach ($values as $name => $value) { |
|
382 | - $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value))); |
|
383 | - } |
|
384 | - $where = $updateQb->expr()->andX(); |
|
385 | - $whereValues = array_merge($keys, $updatePreconditionValues); |
|
386 | - foreach ($whereValues as $name => $value) { |
|
387 | - if ($value === '') { |
|
388 | - $where->add($updateQb->expr()->emptyString( |
|
389 | - $name |
|
390 | - )); |
|
391 | - } else { |
|
392 | - $where->add($updateQb->expr()->eq( |
|
393 | - $name, |
|
394 | - $updateQb->createNamedParameter($value, $this->getType($value)), |
|
395 | - $this->getType($value) |
|
396 | - )); |
|
397 | - } |
|
398 | - } |
|
399 | - $updateQb->where($where); |
|
400 | - $affected = $updateQb->execute(); |
|
401 | - |
|
402 | - if ($affected === 0 && !empty($updatePreconditionValues)) { |
|
403 | - throw new PreConditionNotMetException(); |
|
404 | - } |
|
405 | - |
|
406 | - return 0; |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Create an exclusive read+write lock on a table |
|
412 | - * |
|
413 | - * @param string $tableName |
|
414 | - * |
|
415 | - * @throws \BadMethodCallException When trying to acquire a second lock |
|
416 | - * @throws Exception |
|
417 | - * @since 9.1.0 |
|
418 | - */ |
|
419 | - public function lockTable($tableName) { |
|
420 | - if ($this->lockedTable !== null) { |
|
421 | - throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
|
422 | - } |
|
423 | - |
|
424 | - $tableName = $this->tablePrefix . $tableName; |
|
425 | - $this->lockedTable = $tableName; |
|
426 | - $this->adapter->lockTable($tableName); |
|
427 | - } |
|
428 | - |
|
429 | - /** |
|
430 | - * Release a previous acquired lock again |
|
431 | - * |
|
432 | - * @throws Exception |
|
433 | - * @since 9.1.0 |
|
434 | - */ |
|
435 | - public function unlockTable() { |
|
436 | - $this->adapter->unlockTable(); |
|
437 | - $this->lockedTable = null; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * returns the error code and message as a string for logging |
|
442 | - * works with DoctrineException |
|
443 | - * @return string |
|
444 | - */ |
|
445 | - public function getError() { |
|
446 | - $msg = $this->errorCode() . ': '; |
|
447 | - $errorInfo = $this->errorInfo(); |
|
448 | - if (!empty($errorInfo)) { |
|
449 | - $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
450 | - $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
451 | - $msg .= 'Driver Message = '.$errorInfo[2]; |
|
452 | - } |
|
453 | - return $msg; |
|
454 | - } |
|
455 | - |
|
456 | - public function errorCode() { |
|
457 | - return -1; |
|
458 | - } |
|
459 | - |
|
460 | - public function errorInfo() { |
|
461 | - return []; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Drop a table from the database if it exists |
|
466 | - * |
|
467 | - * @param string $table table name without the prefix |
|
468 | - * |
|
469 | - * @throws Exception |
|
470 | - */ |
|
471 | - public function dropTable($table) { |
|
472 | - $table = $this->tablePrefix . trim($table); |
|
473 | - $schema = $this->getSchemaManager(); |
|
474 | - if ($schema->tablesExist([$table])) { |
|
475 | - $schema->dropTable($table); |
|
476 | - } |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Check if a table exists |
|
481 | - * |
|
482 | - * @param string $table table name without the prefix |
|
483 | - * |
|
484 | - * @return bool |
|
485 | - * @throws Exception |
|
486 | - */ |
|
487 | - public function tableExists($table) { |
|
488 | - $table = $this->tablePrefix . trim($table); |
|
489 | - $schema = $this->getSchemaManager(); |
|
490 | - return $schema->tablesExist([$table]); |
|
491 | - } |
|
492 | - |
|
493 | - // internal use |
|
494 | - /** |
|
495 | - * @param string $statement |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - protected function replaceTablePrefix($statement) { |
|
499 | - return str_replace('*PREFIX*', $this->tablePrefix, $statement); |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Check if a transaction is active |
|
504 | - * |
|
505 | - * @return bool |
|
506 | - * @since 8.2.0 |
|
507 | - */ |
|
508 | - public function inTransaction() { |
|
509 | - return $this->getTransactionNestingLevel() > 0; |
|
510 | - } |
|
511 | - |
|
512 | - /** |
|
513 | - * Escape a parameter to be used in a LIKE query |
|
514 | - * |
|
515 | - * @param string $param |
|
516 | - * @return string |
|
517 | - */ |
|
518 | - public function escapeLikeParameter($param) { |
|
519 | - return addcslashes($param, '\\_%'); |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Check whether or not the current database support 4byte wide unicode |
|
524 | - * |
|
525 | - * @return bool |
|
526 | - * @since 11.0.0 |
|
527 | - */ |
|
528 | - public function supports4ByteText() { |
|
529 | - if (!$this->getDatabasePlatform() instanceof MySQLPlatform) { |
|
530 | - return true; |
|
531 | - } |
|
532 | - return $this->getParams()['charset'] === 'utf8mb4'; |
|
533 | - } |
|
534 | - |
|
535 | - |
|
536 | - /** |
|
537 | - * Create the schema of the connected database |
|
538 | - * |
|
539 | - * @return Schema |
|
540 | - * @throws Exception |
|
541 | - */ |
|
542 | - public function createSchema() { |
|
543 | - $migrator = $this->getMigrator(); |
|
544 | - return $migrator->createSchema(); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Migrate the database to the given schema |
|
549 | - * |
|
550 | - * @param Schema $toSchema |
|
551 | - * @param bool $dryRun If true, will return the sql queries instead of running them. |
|
552 | - * |
|
553 | - * @throws Exception |
|
554 | - * |
|
555 | - * @return string|null Returns a string only if $dryRun is true. |
|
556 | - */ |
|
557 | - public function migrateToSchema(Schema $toSchema, bool $dryRun = false) { |
|
558 | - $migrator = $this->getMigrator(); |
|
559 | - |
|
560 | - if ($dryRun) { |
|
561 | - return $migrator->generateChangeScript($toSchema); |
|
562 | - } else { |
|
563 | - $migrator->migrate($toSchema); |
|
564 | - } |
|
565 | - } |
|
566 | - |
|
567 | - private function getMigrator() { |
|
568 | - // TODO properly inject those dependencies |
|
569 | - $random = \OC::$server->getSecureRandom(); |
|
570 | - $platform = $this->getDatabasePlatform(); |
|
571 | - $config = \OC::$server->getConfig(); |
|
572 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
573 | - if ($platform instanceof SqlitePlatform) { |
|
574 | - return new SQLiteMigrator($this, $config, $dispatcher); |
|
575 | - } elseif ($platform instanceof OraclePlatform) { |
|
576 | - return new OracleMigrator($this, $config, $dispatcher); |
|
577 | - } elseif ($platform instanceof MySQLPlatform) { |
|
578 | - return new MySQLMigrator($this, $config, $dispatcher); |
|
579 | - } elseif ($platform instanceof PostgreSQL94Platform) { |
|
580 | - return new PostgreSqlMigrator($this, $config, $dispatcher); |
|
581 | - } else { |
|
582 | - return new Migrator($this, $config, $dispatcher); |
|
583 | - } |
|
584 | - } |
|
59 | + /** @var string */ |
|
60 | + protected $tablePrefix; |
|
61 | + |
|
62 | + /** @var \OC\DB\Adapter $adapter */ |
|
63 | + protected $adapter; |
|
64 | + |
|
65 | + /** @var SystemConfig */ |
|
66 | + private $systemConfig; |
|
67 | + |
|
68 | + /** @var ILogger */ |
|
69 | + private $logger; |
|
70 | + |
|
71 | + protected $lockedTable = null; |
|
72 | + |
|
73 | + /** @var int */ |
|
74 | + protected $queriesBuilt = 0; |
|
75 | + |
|
76 | + /** @var int */ |
|
77 | + protected $queriesExecuted = 0; |
|
78 | + |
|
79 | + /** |
|
80 | + * @throws Exception |
|
81 | + */ |
|
82 | + public function connect() { |
|
83 | + try { |
|
84 | + if ($this->_conn) { |
|
85 | + return parent::connect(); |
|
86 | + } |
|
87 | + |
|
88 | + // Only trigger the event logger for the initial connect call |
|
89 | + $eventLogger = \OC::$server->getEventLogger(); |
|
90 | + $eventLogger->start('connect:db', 'db connection opened'); |
|
91 | + $status = parent::connect(); |
|
92 | + $eventLogger->end('connect:db'); |
|
93 | + |
|
94 | + return $status; |
|
95 | + } catch (Exception $e) { |
|
96 | + // throw a new exception to prevent leaking info from the stacktrace |
|
97 | + throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + public function getStats(): array { |
|
102 | + return [ |
|
103 | + 'built' => $this->queriesBuilt, |
|
104 | + 'executed' => $this->queriesExecuted, |
|
105 | + ]; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns a QueryBuilder for the connection. |
|
110 | + */ |
|
111 | + public function getQueryBuilder(): IQueryBuilder { |
|
112 | + $this->queriesBuilt++; |
|
113 | + return new QueryBuilder( |
|
114 | + new ConnectionAdapter($this), |
|
115 | + $this->systemConfig, |
|
116 | + $this->logger |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Gets the QueryBuilder for the connection. |
|
122 | + * |
|
123 | + * @return \Doctrine\DBAL\Query\QueryBuilder |
|
124 | + * @deprecated please use $this->getQueryBuilder() instead |
|
125 | + */ |
|
126 | + public function createQueryBuilder() { |
|
127 | + $backtrace = $this->getCallerBacktrace(); |
|
128 | + \OC::$server->getLogger()->debug('Doctrine QueryBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
129 | + $this->queriesBuilt++; |
|
130 | + return parent::createQueryBuilder(); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Gets the ExpressionBuilder for the connection. |
|
135 | + * |
|
136 | + * @return \Doctrine\DBAL\Query\Expression\ExpressionBuilder |
|
137 | + * @deprecated please use $this->getQueryBuilder()->expr() instead |
|
138 | + */ |
|
139 | + public function getExpressionBuilder() { |
|
140 | + $backtrace = $this->getCallerBacktrace(); |
|
141 | + \OC::$server->getLogger()->debug('Doctrine ExpressionBuilder retrieved in {backtrace}', ['app' => 'core', 'backtrace' => $backtrace]); |
|
142 | + $this->queriesBuilt++; |
|
143 | + return parent::getExpressionBuilder(); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get the file and line that called the method where `getCallerBacktrace()` was used |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + protected function getCallerBacktrace() { |
|
152 | + $traces = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); |
|
153 | + |
|
154 | + // 0 is the method where we use `getCallerBacktrace` |
|
155 | + // 1 is the target method which uses the method we want to log |
|
156 | + if (isset($traces[1])) { |
|
157 | + return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
158 | + } |
|
159 | + |
|
160 | + return ''; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return string |
|
165 | + */ |
|
166 | + public function getPrefix() { |
|
167 | + return $this->tablePrefix; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Initializes a new instance of the Connection class. |
|
172 | + * |
|
173 | + * @param array $params The connection parameters. |
|
174 | + * @param \Doctrine\DBAL\Driver $driver |
|
175 | + * @param \Doctrine\DBAL\Configuration $config |
|
176 | + * @param \Doctrine\Common\EventManager $eventManager |
|
177 | + * @throws \Exception |
|
178 | + */ |
|
179 | + public function __construct(array $params, Driver $driver, Configuration $config = null, |
|
180 | + EventManager $eventManager = null) { |
|
181 | + if (!isset($params['adapter'])) { |
|
182 | + throw new \Exception('adapter not set'); |
|
183 | + } |
|
184 | + if (!isset($params['tablePrefix'])) { |
|
185 | + throw new \Exception('tablePrefix not set'); |
|
186 | + } |
|
187 | + /** |
|
188 | + * @psalm-suppress InternalMethod |
|
189 | + */ |
|
190 | + parent::__construct($params, $driver, $config, $eventManager); |
|
191 | + $this->adapter = new $params['adapter']($this); |
|
192 | + $this->tablePrefix = $params['tablePrefix']; |
|
193 | + |
|
194 | + $this->systemConfig = \OC::$server->getSystemConfig(); |
|
195 | + $this->logger = \OC::$server->getLogger(); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Prepares an SQL statement. |
|
200 | + * |
|
201 | + * @param string $statement The SQL statement to prepare. |
|
202 | + * @param int|null $limit |
|
203 | + * @param int|null $offset |
|
204 | + * |
|
205 | + * @return Statement The prepared statement. |
|
206 | + * @throws Exception |
|
207 | + */ |
|
208 | + public function prepare($statement, $limit = null, $offset = null): Statement { |
|
209 | + if ($limit === -1 || $limit === null) { |
|
210 | + $limit = null; |
|
211 | + } else { |
|
212 | + $limit = (int) $limit; |
|
213 | + } |
|
214 | + if ($offset !== null) { |
|
215 | + $offset = (int) $offset; |
|
216 | + } |
|
217 | + if (!is_null($limit)) { |
|
218 | + $platform = $this->getDatabasePlatform(); |
|
219 | + $statement = $platform->modifyLimitQuery($statement, $limit, $offset); |
|
220 | + } |
|
221 | + $statement = $this->replaceTablePrefix($statement); |
|
222 | + $statement = $this->adapter->fixupStatement($statement); |
|
223 | + |
|
224 | + return parent::prepare($statement); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Executes an, optionally parametrized, SQL query. |
|
229 | + * |
|
230 | + * If the query is parametrized, a prepared statement is used. |
|
231 | + * If an SQLLogger is configured, the execution is logged. |
|
232 | + * |
|
233 | + * @param string $sql The SQL query to execute. |
|
234 | + * @param array $params The parameters to bind to the query, if any. |
|
235 | + * @param array $types The types the previous parameters are in. |
|
236 | + * @param \Doctrine\DBAL\Cache\QueryCacheProfile|null $qcp The query cache profile, optional. |
|
237 | + * |
|
238 | + * @return Result The executed statement. |
|
239 | + * |
|
240 | + * @throws \Doctrine\DBAL\Exception |
|
241 | + */ |
|
242 | + public function executeQuery(string $sql, array $params = [], $types = [], QueryCacheProfile $qcp = null): Result { |
|
243 | + $sql = $this->replaceTablePrefix($sql); |
|
244 | + $sql = $this->adapter->fixupStatement($sql); |
|
245 | + $this->queriesExecuted++; |
|
246 | + $this->logQueryToFile($sql); |
|
247 | + return parent::executeQuery($sql, $params, $types, $qcp); |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @throws Exception |
|
252 | + */ |
|
253 | + public function executeUpdate(string $sql, array $params = [], array $types = []): int { |
|
254 | + $sql = $this->replaceTablePrefix($sql); |
|
255 | + $sql = $this->adapter->fixupStatement($sql); |
|
256 | + $this->queriesExecuted++; |
|
257 | + $this->logQueryToFile($sql); |
|
258 | + return parent::executeUpdate($sql, $params, $types); |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Executes an SQL INSERT/UPDATE/DELETE query with the given parameters |
|
263 | + * and returns the number of affected rows. |
|
264 | + * |
|
265 | + * This method supports PDO binding types as well as DBAL mapping types. |
|
266 | + * |
|
267 | + * @param string $sql The SQL query. |
|
268 | + * @param array $params The query parameters. |
|
269 | + * @param array $types The parameter types. |
|
270 | + * |
|
271 | + * @return int The number of affected rows. |
|
272 | + * |
|
273 | + * @throws \Doctrine\DBAL\Exception |
|
274 | + */ |
|
275 | + public function executeStatement($sql, array $params = [], array $types = []): int { |
|
276 | + $sql = $this->replaceTablePrefix($sql); |
|
277 | + $sql = $this->adapter->fixupStatement($sql); |
|
278 | + $this->queriesExecuted++; |
|
279 | + $this->logQueryToFile($sql); |
|
280 | + return parent::executeStatement($sql, $params, $types); |
|
281 | + } |
|
282 | + |
|
283 | + protected function logQueryToFile(string $sql): void { |
|
284 | + $logFile = $this->systemConfig->getValue('query_log_file', ''); |
|
285 | + if ($logFile !== '' && is_writable(dirname($logFile)) && (!file_exists($logFile) || is_writable($logFile))) { |
|
286 | + file_put_contents( |
|
287 | + $this->systemConfig->getValue('query_log_file', ''), |
|
288 | + $sql . "\n", |
|
289 | + FILE_APPEND |
|
290 | + ); |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Returns the ID of the last inserted row, or the last value from a sequence object, |
|
296 | + * depending on the underlying driver. |
|
297 | + * |
|
298 | + * Note: This method may not return a meaningful or consistent result across different drivers, |
|
299 | + * because the underlying database may not even support the notion of AUTO_INCREMENT/IDENTITY |
|
300 | + * columns or sequences. |
|
301 | + * |
|
302 | + * @param string $seqName Name of the sequence object from which the ID should be returned. |
|
303 | + * |
|
304 | + * @return string the last inserted ID. |
|
305 | + * @throws Exception |
|
306 | + */ |
|
307 | + public function lastInsertId($seqName = null) { |
|
308 | + if ($seqName) { |
|
309 | + $seqName = $this->replaceTablePrefix($seqName); |
|
310 | + } |
|
311 | + return $this->adapter->lastInsertId($seqName); |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * @internal |
|
316 | + * @throws Exception |
|
317 | + */ |
|
318 | + public function realLastInsertId($seqName = null) { |
|
319 | + return parent::lastInsertId($seqName); |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Insert a row if the matching row does not exists. To accomplish proper race condition avoidance |
|
324 | + * it is needed that there is also a unique constraint on the values. Then this method will |
|
325 | + * catch the exception and return 0. |
|
326 | + * |
|
327 | + * @param string $table The table name (will replace *PREFIX* with the actual prefix) |
|
328 | + * @param array $input data that should be inserted into the table (column name => value) |
|
329 | + * @param array|null $compare List of values that should be checked for "if not exists" |
|
330 | + * If this is null or an empty array, all keys of $input will be compared |
|
331 | + * Please note: text fields (clob) must not be used in the compare array |
|
332 | + * @return int number of inserted rows |
|
333 | + * @throws \Doctrine\DBAL\Exception |
|
334 | + * @deprecated 15.0.0 - use unique index and "try { $db->insert() } catch (UniqueConstraintViolationException $e) {}" instead, because it is more reliable and does not have the risk for deadlocks - see https://github.com/nextcloud/server/pull/12371 |
|
335 | + */ |
|
336 | + public function insertIfNotExist($table, $input, array $compare = null) { |
|
337 | + return $this->adapter->insertIfNotExist($table, $input, $compare); |
|
338 | + } |
|
339 | + |
|
340 | + public function insertIgnoreConflict(string $table, array $values) : int { |
|
341 | + return $this->adapter->insertIgnoreConflict($table, $values); |
|
342 | + } |
|
343 | + |
|
344 | + private function getType($value) { |
|
345 | + if (is_bool($value)) { |
|
346 | + return IQueryBuilder::PARAM_BOOL; |
|
347 | + } elseif (is_int($value)) { |
|
348 | + return IQueryBuilder::PARAM_INT; |
|
349 | + } else { |
|
350 | + return IQueryBuilder::PARAM_STR; |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Insert or update a row value |
|
356 | + * |
|
357 | + * @param string $table |
|
358 | + * @param array $keys (column name => value) |
|
359 | + * @param array $values (column name => value) |
|
360 | + * @param array $updatePreconditionValues ensure values match preconditions (column name => value) |
|
361 | + * @return int number of new rows |
|
362 | + * @throws \Doctrine\DBAL\Exception |
|
363 | + * @throws PreConditionNotMetException |
|
364 | + */ |
|
365 | + public function setValues($table, array $keys, array $values, array $updatePreconditionValues = []) { |
|
366 | + try { |
|
367 | + $insertQb = $this->getQueryBuilder(); |
|
368 | + $insertQb->insert($table) |
|
369 | + ->values( |
|
370 | + array_map(function ($value) use ($insertQb) { |
|
371 | + return $insertQb->createNamedParameter($value, $this->getType($value)); |
|
372 | + }, array_merge($keys, $values)) |
|
373 | + ); |
|
374 | + return $insertQb->execute(); |
|
375 | + } catch (NotNullConstraintViolationException $e) { |
|
376 | + throw $e; |
|
377 | + } catch (ConstraintViolationException $e) { |
|
378 | + // value already exists, try update |
|
379 | + $updateQb = $this->getQueryBuilder(); |
|
380 | + $updateQb->update($table); |
|
381 | + foreach ($values as $name => $value) { |
|
382 | + $updateQb->set($name, $updateQb->createNamedParameter($value, $this->getType($value))); |
|
383 | + } |
|
384 | + $where = $updateQb->expr()->andX(); |
|
385 | + $whereValues = array_merge($keys, $updatePreconditionValues); |
|
386 | + foreach ($whereValues as $name => $value) { |
|
387 | + if ($value === '') { |
|
388 | + $where->add($updateQb->expr()->emptyString( |
|
389 | + $name |
|
390 | + )); |
|
391 | + } else { |
|
392 | + $where->add($updateQb->expr()->eq( |
|
393 | + $name, |
|
394 | + $updateQb->createNamedParameter($value, $this->getType($value)), |
|
395 | + $this->getType($value) |
|
396 | + )); |
|
397 | + } |
|
398 | + } |
|
399 | + $updateQb->where($where); |
|
400 | + $affected = $updateQb->execute(); |
|
401 | + |
|
402 | + if ($affected === 0 && !empty($updatePreconditionValues)) { |
|
403 | + throw new PreConditionNotMetException(); |
|
404 | + } |
|
405 | + |
|
406 | + return 0; |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Create an exclusive read+write lock on a table |
|
412 | + * |
|
413 | + * @param string $tableName |
|
414 | + * |
|
415 | + * @throws \BadMethodCallException When trying to acquire a second lock |
|
416 | + * @throws Exception |
|
417 | + * @since 9.1.0 |
|
418 | + */ |
|
419 | + public function lockTable($tableName) { |
|
420 | + if ($this->lockedTable !== null) { |
|
421 | + throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
|
422 | + } |
|
423 | + |
|
424 | + $tableName = $this->tablePrefix . $tableName; |
|
425 | + $this->lockedTable = $tableName; |
|
426 | + $this->adapter->lockTable($tableName); |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Release a previous acquired lock again |
|
431 | + * |
|
432 | + * @throws Exception |
|
433 | + * @since 9.1.0 |
|
434 | + */ |
|
435 | + public function unlockTable() { |
|
436 | + $this->adapter->unlockTable(); |
|
437 | + $this->lockedTable = null; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * returns the error code and message as a string for logging |
|
442 | + * works with DoctrineException |
|
443 | + * @return string |
|
444 | + */ |
|
445 | + public function getError() { |
|
446 | + $msg = $this->errorCode() . ': '; |
|
447 | + $errorInfo = $this->errorInfo(); |
|
448 | + if (!empty($errorInfo)) { |
|
449 | + $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
450 | + $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
451 | + $msg .= 'Driver Message = '.$errorInfo[2]; |
|
452 | + } |
|
453 | + return $msg; |
|
454 | + } |
|
455 | + |
|
456 | + public function errorCode() { |
|
457 | + return -1; |
|
458 | + } |
|
459 | + |
|
460 | + public function errorInfo() { |
|
461 | + return []; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * Drop a table from the database if it exists |
|
466 | + * |
|
467 | + * @param string $table table name without the prefix |
|
468 | + * |
|
469 | + * @throws Exception |
|
470 | + */ |
|
471 | + public function dropTable($table) { |
|
472 | + $table = $this->tablePrefix . trim($table); |
|
473 | + $schema = $this->getSchemaManager(); |
|
474 | + if ($schema->tablesExist([$table])) { |
|
475 | + $schema->dropTable($table); |
|
476 | + } |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Check if a table exists |
|
481 | + * |
|
482 | + * @param string $table table name without the prefix |
|
483 | + * |
|
484 | + * @return bool |
|
485 | + * @throws Exception |
|
486 | + */ |
|
487 | + public function tableExists($table) { |
|
488 | + $table = $this->tablePrefix . trim($table); |
|
489 | + $schema = $this->getSchemaManager(); |
|
490 | + return $schema->tablesExist([$table]); |
|
491 | + } |
|
492 | + |
|
493 | + // internal use |
|
494 | + /** |
|
495 | + * @param string $statement |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + protected function replaceTablePrefix($statement) { |
|
499 | + return str_replace('*PREFIX*', $this->tablePrefix, $statement); |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Check if a transaction is active |
|
504 | + * |
|
505 | + * @return bool |
|
506 | + * @since 8.2.0 |
|
507 | + */ |
|
508 | + public function inTransaction() { |
|
509 | + return $this->getTransactionNestingLevel() > 0; |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * Escape a parameter to be used in a LIKE query |
|
514 | + * |
|
515 | + * @param string $param |
|
516 | + * @return string |
|
517 | + */ |
|
518 | + public function escapeLikeParameter($param) { |
|
519 | + return addcslashes($param, '\\_%'); |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Check whether or not the current database support 4byte wide unicode |
|
524 | + * |
|
525 | + * @return bool |
|
526 | + * @since 11.0.0 |
|
527 | + */ |
|
528 | + public function supports4ByteText() { |
|
529 | + if (!$this->getDatabasePlatform() instanceof MySQLPlatform) { |
|
530 | + return true; |
|
531 | + } |
|
532 | + return $this->getParams()['charset'] === 'utf8mb4'; |
|
533 | + } |
|
534 | + |
|
535 | + |
|
536 | + /** |
|
537 | + * Create the schema of the connected database |
|
538 | + * |
|
539 | + * @return Schema |
|
540 | + * @throws Exception |
|
541 | + */ |
|
542 | + public function createSchema() { |
|
543 | + $migrator = $this->getMigrator(); |
|
544 | + return $migrator->createSchema(); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Migrate the database to the given schema |
|
549 | + * |
|
550 | + * @param Schema $toSchema |
|
551 | + * @param bool $dryRun If true, will return the sql queries instead of running them. |
|
552 | + * |
|
553 | + * @throws Exception |
|
554 | + * |
|
555 | + * @return string|null Returns a string only if $dryRun is true. |
|
556 | + */ |
|
557 | + public function migrateToSchema(Schema $toSchema, bool $dryRun = false) { |
|
558 | + $migrator = $this->getMigrator(); |
|
559 | + |
|
560 | + if ($dryRun) { |
|
561 | + return $migrator->generateChangeScript($toSchema); |
|
562 | + } else { |
|
563 | + $migrator->migrate($toSchema); |
|
564 | + } |
|
565 | + } |
|
566 | + |
|
567 | + private function getMigrator() { |
|
568 | + // TODO properly inject those dependencies |
|
569 | + $random = \OC::$server->getSecureRandom(); |
|
570 | + $platform = $this->getDatabasePlatform(); |
|
571 | + $config = \OC::$server->getConfig(); |
|
572 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
573 | + if ($platform instanceof SqlitePlatform) { |
|
574 | + return new SQLiteMigrator($this, $config, $dispatcher); |
|
575 | + } elseif ($platform instanceof OraclePlatform) { |
|
576 | + return new OracleMigrator($this, $config, $dispatcher); |
|
577 | + } elseif ($platform instanceof MySQLPlatform) { |
|
578 | + return new MySQLMigrator($this, $config, $dispatcher); |
|
579 | + } elseif ($platform instanceof PostgreSQL94Platform) { |
|
580 | + return new PostgreSqlMigrator($this, $config, $dispatcher); |
|
581 | + } else { |
|
582 | + return new Migrator($this, $config, $dispatcher); |
|
583 | + } |
|
584 | + } |
|
585 | 585 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | return $status; |
95 | 95 | } catch (Exception $e) { |
96 | 96 | // throw a new exception to prevent leaking info from the stacktrace |
97 | - throw new Exception('Failed to connect to the database: ' . $e->getMessage(), $e->getCode()); |
|
97 | + throw new Exception('Failed to connect to the database: '.$e->getMessage(), $e->getCode()); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | // 0 is the method where we use `getCallerBacktrace` |
155 | 155 | // 1 is the target method which uses the method we want to log |
156 | 156 | if (isset($traces[1])) { |
157 | - return $traces[1]['file'] . ':' . $traces[1]['line']; |
|
157 | + return $traces[1]['file'].':'.$traces[1]['line']; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return ''; |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | if ($logFile !== '' && is_writable(dirname($logFile)) && (!file_exists($logFile) || is_writable($logFile))) { |
286 | 286 | file_put_contents( |
287 | 287 | $this->systemConfig->getValue('query_log_file', ''), |
288 | - $sql . "\n", |
|
288 | + $sql."\n", |
|
289 | 289 | FILE_APPEND |
290 | 290 | ); |
291 | 291 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | $insertQb = $this->getQueryBuilder(); |
368 | 368 | $insertQb->insert($table) |
369 | 369 | ->values( |
370 | - array_map(function ($value) use ($insertQb) { |
|
370 | + array_map(function($value) use ($insertQb) { |
|
371 | 371 | return $insertQb->createNamedParameter($value, $this->getType($value)); |
372 | 372 | }, array_merge($keys, $values)) |
373 | 373 | ); |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | throw new \BadMethodCallException('Can not lock a new table until the previous lock is released.'); |
422 | 422 | } |
423 | 423 | |
424 | - $tableName = $this->tablePrefix . $tableName; |
|
424 | + $tableName = $this->tablePrefix.$tableName; |
|
425 | 425 | $this->lockedTable = $tableName; |
426 | 426 | $this->adapter->lockTable($tableName); |
427 | 427 | } |
@@ -443,11 +443,11 @@ discard block |
||
443 | 443 | * @return string |
444 | 444 | */ |
445 | 445 | public function getError() { |
446 | - $msg = $this->errorCode() . ': '; |
|
446 | + $msg = $this->errorCode().': '; |
|
447 | 447 | $errorInfo = $this->errorInfo(); |
448 | 448 | if (!empty($errorInfo)) { |
449 | - $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; |
|
450 | - $msg .= 'Driver Code = '.$errorInfo[1] . ', '; |
|
449 | + $msg .= 'SQLSTATE = '.$errorInfo[0].', '; |
|
450 | + $msg .= 'Driver Code = '.$errorInfo[1].', '; |
|
451 | 451 | $msg .= 'Driver Message = '.$errorInfo[2]; |
452 | 452 | } |
453 | 453 | return $msg; |
@@ -469,7 +469,7 @@ discard block |
||
469 | 469 | * @throws Exception |
470 | 470 | */ |
471 | 471 | public function dropTable($table) { |
472 | - $table = $this->tablePrefix . trim($table); |
|
472 | + $table = $this->tablePrefix.trim($table); |
|
473 | 473 | $schema = $this->getSchemaManager(); |
474 | 474 | if ($schema->tablesExist([$table])) { |
475 | 475 | $schema->dropTable($table); |
@@ -485,7 +485,7 @@ discard block |
||
485 | 485 | * @throws Exception |
486 | 486 | */ |
487 | 487 | public function tableExists($table) { |
488 | - $table = $this->tablePrefix . trim($table); |
|
488 | + $table = $this->tablePrefix.trim($table); |
|
489 | 489 | $schema = $this->getSchemaManager(); |
490 | 490 | return $schema->tablesExist([$table]); |
491 | 491 | } |
@@ -263,2088 +263,2088 @@ |
||
263 | 263 | */ |
264 | 264 | class Server extends ServerContainer implements IServerContainer { |
265 | 265 | |
266 | - /** @var string */ |
|
267 | - private $webRoot; |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $webRoot |
|
271 | - * @param \OC\Config $config |
|
272 | - */ |
|
273 | - public function __construct($webRoot, \OC\Config $config) { |
|
274 | - parent::__construct(); |
|
275 | - $this->webRoot = $webRoot; |
|
276 | - |
|
277 | - // To find out if we are running from CLI or not |
|
278 | - $this->registerParameter('isCLI', \OC::$CLI); |
|
279 | - $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
280 | - |
|
281 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
282 | - return $c; |
|
283 | - }); |
|
284 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
285 | - return $c; |
|
286 | - }); |
|
287 | - |
|
288 | - $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
289 | - /** @deprecated 19.0.0 */ |
|
290 | - $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
291 | - |
|
292 | - $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
293 | - /** @deprecated 19.0.0 */ |
|
294 | - $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
295 | - |
|
296 | - $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
297 | - /** @deprecated 19.0.0 */ |
|
298 | - $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
299 | - |
|
300 | - $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
301 | - /** @deprecated 19.0.0 */ |
|
302 | - $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
303 | - |
|
304 | - $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
305 | - $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
306 | - |
|
307 | - $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
308 | - |
|
309 | - $this->registerService(View::class, function (Server $c) { |
|
310 | - return new View(); |
|
311 | - }, false); |
|
312 | - |
|
313 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
314 | - return new PreviewManager( |
|
315 | - $c->get(\OCP\IConfig::class), |
|
316 | - $c->get(IRootFolder::class), |
|
317 | - new \OC\Preview\Storage\Root( |
|
318 | - $c->get(IRootFolder::class), |
|
319 | - $c->get(SystemConfig::class) |
|
320 | - ), |
|
321 | - $c->get(SymfonyAdapter::class), |
|
322 | - $c->get(GeneratorHelper::class), |
|
323 | - $c->get(ISession::class)->get('user_id'), |
|
324 | - $c->get(Coordinator::class), |
|
325 | - $c->get(IServerContainer::class) |
|
326 | - ); |
|
327 | - }); |
|
328 | - /** @deprecated 19.0.0 */ |
|
329 | - $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
330 | - |
|
331 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
332 | - return new \OC\Preview\Watcher( |
|
333 | - new \OC\Preview\Storage\Root( |
|
334 | - $c->get(IRootFolder::class), |
|
335 | - $c->get(SystemConfig::class) |
|
336 | - ) |
|
337 | - ); |
|
338 | - }); |
|
339 | - |
|
340 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
341 | - $view = new View(); |
|
342 | - $util = new Encryption\Util( |
|
343 | - $view, |
|
344 | - $c->get(IUserManager::class), |
|
345 | - $c->get(IGroupManager::class), |
|
346 | - $c->get(\OCP\IConfig::class) |
|
347 | - ); |
|
348 | - return new Encryption\Manager( |
|
349 | - $c->get(\OCP\IConfig::class), |
|
350 | - $c->get(ILogger::class), |
|
351 | - $c->getL10N('core'), |
|
352 | - new View(), |
|
353 | - $util, |
|
354 | - new ArrayCache() |
|
355 | - ); |
|
356 | - }); |
|
357 | - /** @deprecated 19.0.0 */ |
|
358 | - $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
359 | - |
|
360 | - /** @deprecated 21.0.0 */ |
|
361 | - $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
362 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
363 | - $util = new Encryption\Util( |
|
364 | - new View(), |
|
365 | - $c->get(IUserManager::class), |
|
366 | - $c->get(IGroupManager::class), |
|
367 | - $c->get(\OCP\IConfig::class) |
|
368 | - ); |
|
369 | - return new Encryption\File( |
|
370 | - $util, |
|
371 | - $c->get(IRootFolder::class), |
|
372 | - $c->get(\OCP\Share\IManager::class) |
|
373 | - ); |
|
374 | - }); |
|
375 | - |
|
376 | - /** @deprecated 21.0.0 */ |
|
377 | - $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
378 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
379 | - $view = new View(); |
|
380 | - $util = new Encryption\Util( |
|
381 | - $view, |
|
382 | - $c->get(IUserManager::class), |
|
383 | - $c->get(IGroupManager::class), |
|
384 | - $c->get(\OCP\IConfig::class) |
|
385 | - ); |
|
386 | - |
|
387 | - return new Encryption\Keys\Storage( |
|
388 | - $view, |
|
389 | - $util, |
|
390 | - $c->get(ICrypto::class), |
|
391 | - $c->get(\OCP\IConfig::class) |
|
392 | - ); |
|
393 | - }); |
|
394 | - /** @deprecated 20.0.0 */ |
|
395 | - $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
396 | - |
|
397 | - $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
398 | - /** @deprecated 19.0.0 */ |
|
399 | - $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
400 | - |
|
401 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
402 | - /** @var \OCP\IConfig $config */ |
|
403 | - $config = $c->get(\OCP\IConfig::class); |
|
404 | - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
405 | - return new $factoryClass($this); |
|
406 | - }); |
|
407 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
408 | - return $c->get('SystemTagManagerFactory')->getManager(); |
|
409 | - }); |
|
410 | - /** @deprecated 19.0.0 */ |
|
411 | - $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
412 | - |
|
413 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
414 | - return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
415 | - }); |
|
416 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
417 | - $manager = \OC\Files\Filesystem::getMountManager(null); |
|
418 | - $view = new View(); |
|
419 | - $root = new Root( |
|
420 | - $manager, |
|
421 | - $view, |
|
422 | - null, |
|
423 | - $c->get(IUserMountCache::class), |
|
424 | - $this->get(ILogger::class), |
|
425 | - $this->get(IUserManager::class) |
|
426 | - ); |
|
427 | - |
|
428 | - $previewConnector = new \OC\Preview\WatcherConnector( |
|
429 | - $root, |
|
430 | - $c->get(SystemConfig::class) |
|
431 | - ); |
|
432 | - $previewConnector->connectWatcher(); |
|
433 | - |
|
434 | - return $root; |
|
435 | - }); |
|
436 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
437 | - return new HookConnector( |
|
438 | - $c->get(IRootFolder::class), |
|
439 | - new View(), |
|
440 | - $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
441 | - $c->get(IEventDispatcher::class) |
|
442 | - ); |
|
443 | - }); |
|
444 | - |
|
445 | - /** @deprecated 19.0.0 */ |
|
446 | - $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
447 | - |
|
448 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
449 | - return new LazyRoot(function () use ($c) { |
|
450 | - return $c->get('RootFolder'); |
|
451 | - }); |
|
452 | - }); |
|
453 | - /** @deprecated 19.0.0 */ |
|
454 | - $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
455 | - |
|
456 | - /** @deprecated 19.0.0 */ |
|
457 | - $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
458 | - $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
459 | - |
|
460 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
461 | - $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
462 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
463 | - /** @var IEventDispatcher $dispatcher */ |
|
464 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
465 | - $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
466 | - }); |
|
467 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
468 | - /** @var IEventDispatcher $dispatcher */ |
|
469 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
470 | - $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
471 | - }); |
|
472 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
473 | - /** @var IEventDispatcher $dispatcher */ |
|
474 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
475 | - $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
476 | - }); |
|
477 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
478 | - /** @var IEventDispatcher $dispatcher */ |
|
479 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
480 | - $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
481 | - }); |
|
482 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
483 | - /** @var IEventDispatcher $dispatcher */ |
|
484 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
485 | - $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
486 | - }); |
|
487 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
488 | - /** @var IEventDispatcher $dispatcher */ |
|
489 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
490 | - $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
491 | - }); |
|
492 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
493 | - /** @var IEventDispatcher $dispatcher */ |
|
494 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
495 | - $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
496 | - }); |
|
497 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
498 | - /** @var IEventDispatcher $dispatcher */ |
|
499 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
500 | - $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
501 | - }); |
|
502 | - return $groupManager; |
|
503 | - }); |
|
504 | - /** @deprecated 19.0.0 */ |
|
505 | - $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
506 | - |
|
507 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
508 | - $session = $c->get(ISession::class); |
|
509 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
510 | - $tokenProvider = $c->get(IProvider::class); |
|
511 | - } else { |
|
512 | - $tokenProvider = null; |
|
513 | - } |
|
514 | - $logger = $c->get(LoggerInterface::class); |
|
515 | - return new Store($session, $logger, $tokenProvider); |
|
516 | - }); |
|
517 | - $this->registerAlias(IStore::class, Store::class); |
|
518 | - $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
519 | - |
|
520 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
521 | - $manager = $c->get(IUserManager::class); |
|
522 | - $session = new \OC\Session\Memory(''); |
|
523 | - $timeFactory = new TimeFactory(); |
|
524 | - // Token providers might require a working database. This code |
|
525 | - // might however be called when Nextcloud is not yet setup. |
|
526 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
527 | - $provider = $c->get(IProvider::class); |
|
528 | - } else { |
|
529 | - $provider = null; |
|
530 | - } |
|
531 | - |
|
532 | - $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
533 | - |
|
534 | - $userSession = new \OC\User\Session( |
|
535 | - $manager, |
|
536 | - $session, |
|
537 | - $timeFactory, |
|
538 | - $provider, |
|
539 | - $c->get(\OCP\IConfig::class), |
|
540 | - $c->get(ISecureRandom::class), |
|
541 | - $c->getLockdownManager(), |
|
542 | - $c->get(ILogger::class), |
|
543 | - $c->get(IEventDispatcher::class) |
|
544 | - ); |
|
545 | - /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
546 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
547 | - \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
548 | - }); |
|
549 | - /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
550 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
551 | - /** @var \OC\User\User $user */ |
|
552 | - \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
553 | - }); |
|
554 | - /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
555 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
556 | - /** @var \OC\User\User $user */ |
|
557 | - \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
558 | - $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
559 | - }); |
|
560 | - /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
561 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
562 | - /** @var \OC\User\User $user */ |
|
563 | - \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
564 | - }); |
|
565 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
566 | - /** @var \OC\User\User $user */ |
|
567 | - \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
568 | - |
|
569 | - /** @var IEventDispatcher $dispatcher */ |
|
570 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
571 | - $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
572 | - }); |
|
573 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
574 | - /** @var \OC\User\User $user */ |
|
575 | - \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
576 | - |
|
577 | - /** @var IEventDispatcher $dispatcher */ |
|
578 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
579 | - $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
580 | - }); |
|
581 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
582 | - \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
583 | - |
|
584 | - /** @var IEventDispatcher $dispatcher */ |
|
585 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
586 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
587 | - }); |
|
588 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
589 | - /** @var \OC\User\User $user */ |
|
590 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
591 | - |
|
592 | - /** @var IEventDispatcher $dispatcher */ |
|
593 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
594 | - $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
595 | - }); |
|
596 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
597 | - /** @var IEventDispatcher $dispatcher */ |
|
598 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
599 | - $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
600 | - }); |
|
601 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
602 | - /** @var \OC\User\User $user */ |
|
603 | - \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
604 | - |
|
605 | - /** @var IEventDispatcher $dispatcher */ |
|
606 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
607 | - $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
608 | - }); |
|
609 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
610 | - \OC_Hook::emit('OC_User', 'logout', []); |
|
611 | - |
|
612 | - /** @var IEventDispatcher $dispatcher */ |
|
613 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
614 | - $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
615 | - }); |
|
616 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
617 | - /** @var IEventDispatcher $dispatcher */ |
|
618 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
619 | - $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
620 | - }); |
|
621 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
622 | - /** @var \OC\User\User $user */ |
|
623 | - \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
624 | - |
|
625 | - /** @var IEventDispatcher $dispatcher */ |
|
626 | - $dispatcher = $this->get(IEventDispatcher::class); |
|
627 | - $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
628 | - }); |
|
629 | - return $userSession; |
|
630 | - }); |
|
631 | - $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
632 | - /** @deprecated 19.0.0 */ |
|
633 | - $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
634 | - |
|
635 | - $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
636 | - |
|
637 | - $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
638 | - /** @deprecated 19.0.0 */ |
|
639 | - $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
640 | - |
|
641 | - /** @deprecated 19.0.0 */ |
|
642 | - $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
643 | - $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
644 | - |
|
645 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
646 | - return new \OC\SystemConfig($config); |
|
647 | - }); |
|
648 | - /** @deprecated 19.0.0 */ |
|
649 | - $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
650 | - |
|
651 | - /** @deprecated 19.0.0 */ |
|
652 | - $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
653 | - $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
654 | - |
|
655 | - $this->registerService(IFactory::class, function (Server $c) { |
|
656 | - return new \OC\L10N\Factory( |
|
657 | - $c->get(\OCP\IConfig::class), |
|
658 | - $c->getRequest(), |
|
659 | - $c->get(IUserSession::class), |
|
660 | - \OC::$SERVERROOT |
|
661 | - ); |
|
662 | - }); |
|
663 | - /** @deprecated 19.0.0 */ |
|
664 | - $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
665 | - |
|
666 | - $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
667 | - /** @deprecated 19.0.0 */ |
|
668 | - $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
669 | - |
|
670 | - /** @deprecated 19.0.0 */ |
|
671 | - $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
672 | - /** @deprecated 19.0.0 */ |
|
673 | - $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
674 | - |
|
675 | - $this->registerService(ICache::class, function ($c) { |
|
676 | - return new Cache\File(); |
|
677 | - }); |
|
678 | - /** @deprecated 19.0.0 */ |
|
679 | - $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
680 | - |
|
681 | - $this->registerService(Factory::class, function (Server $c) { |
|
682 | - $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
683 | - ArrayCache::class, |
|
684 | - ArrayCache::class, |
|
685 | - ArrayCache::class |
|
686 | - ); |
|
687 | - /** @var \OCP\IConfig $config */ |
|
688 | - $config = $c->get(\OCP\IConfig::class); |
|
689 | - |
|
690 | - if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
691 | - if (!$config->getSystemValueBool('log_query')) { |
|
692 | - $v = \OC_App::getAppVersions(); |
|
693 | - } else { |
|
694 | - // If the log_query is enabled, we can not get the app versions |
|
695 | - // as that does a query, which will be logged and the logging |
|
696 | - // depends on redis and here we are back again in the same function. |
|
697 | - $v = [ |
|
698 | - 'log_query' => 'enabled', |
|
699 | - ]; |
|
700 | - } |
|
701 | - $v['core'] = implode(',', \OC_Util::getVersion()); |
|
702 | - $version = implode(',', $v); |
|
703 | - $instanceId = \OC_Util::getInstanceId(); |
|
704 | - $path = \OC::$SERVERROOT; |
|
705 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
706 | - return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
707 | - $config->getSystemValue('memcache.local', null), |
|
708 | - $config->getSystemValue('memcache.distributed', null), |
|
709 | - $config->getSystemValue('memcache.locking', null), |
|
710 | - $config->getSystemValueString('redis_log_file') |
|
711 | - ); |
|
712 | - } |
|
713 | - return $arrayCacheFactory; |
|
714 | - }); |
|
715 | - /** @deprecated 19.0.0 */ |
|
716 | - $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
717 | - $this->registerAlias(ICacheFactory::class, Factory::class); |
|
718 | - |
|
719 | - $this->registerService('RedisFactory', function (Server $c) { |
|
720 | - $systemConfig = $c->get(SystemConfig::class); |
|
721 | - return new RedisFactory($systemConfig, $c->getEventLogger()); |
|
722 | - }); |
|
723 | - |
|
724 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
725 | - $l10n = $this->get(IFactory::class)->get('lib'); |
|
726 | - return new \OC\Activity\Manager( |
|
727 | - $c->getRequest(), |
|
728 | - $c->get(IUserSession::class), |
|
729 | - $c->get(\OCP\IConfig::class), |
|
730 | - $c->get(IValidator::class), |
|
731 | - $l10n |
|
732 | - ); |
|
733 | - }); |
|
734 | - /** @deprecated 19.0.0 */ |
|
735 | - $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
736 | - |
|
737 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
738 | - return new \OC\Activity\EventMerger( |
|
739 | - $c->getL10N('lib') |
|
740 | - ); |
|
741 | - }); |
|
742 | - $this->registerAlias(IValidator::class, Validator::class); |
|
743 | - |
|
744 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
745 | - return new AvatarManager( |
|
746 | - $c->get(IUserSession::class), |
|
747 | - $c->get(\OC\User\Manager::class), |
|
748 | - $c->getAppDataDir('avatar'), |
|
749 | - $c->getL10N('lib'), |
|
750 | - $c->get(LoggerInterface::class), |
|
751 | - $c->get(\OCP\IConfig::class), |
|
752 | - $c->get(IAccountManager::class), |
|
753 | - $c->get(KnownUserService::class) |
|
754 | - ); |
|
755 | - }); |
|
756 | - $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
757 | - /** @deprecated 19.0.0 */ |
|
758 | - $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
759 | - |
|
760 | - $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
761 | - $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
762 | - |
|
763 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
764 | - $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
765 | - $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
766 | - $logger = $factory->get($logType); |
|
767 | - $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
768 | - |
|
769 | - return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
770 | - }); |
|
771 | - $this->registerAlias(ILogger::class, \OC\Log::class); |
|
772 | - /** @deprecated 19.0.0 */ |
|
773 | - $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
774 | - // PSR-3 logger |
|
775 | - $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
776 | - |
|
777 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
778 | - return new LogFactory($c, $this->get(SystemConfig::class)); |
|
779 | - }); |
|
780 | - |
|
781 | - $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
782 | - /** @deprecated 19.0.0 */ |
|
783 | - $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
784 | - |
|
785 | - $this->registerService(Router::class, function (Server $c) { |
|
786 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
787 | - $logger = $c->get(ILogger::class); |
|
788 | - if ($cacheFactory->isLocalCacheAvailable()) { |
|
789 | - $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
790 | - } else { |
|
791 | - $router = new \OC\Route\Router($logger); |
|
792 | - } |
|
793 | - return $router; |
|
794 | - }); |
|
795 | - $this->registerAlias(IRouter::class, Router::class); |
|
796 | - /** @deprecated 19.0.0 */ |
|
797 | - $this->registerDeprecatedAlias('Router', IRouter::class); |
|
798 | - |
|
799 | - $this->registerAlias(ISearch::class, Search::class); |
|
800 | - /** @deprecated 19.0.0 */ |
|
801 | - $this->registerDeprecatedAlias('Search', ISearch::class); |
|
802 | - |
|
803 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
804 | - $cacheFactory = $c->get(ICacheFactory::class); |
|
805 | - if ($cacheFactory->isAvailable()) { |
|
806 | - $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
807 | - $this->get(ICacheFactory::class), |
|
808 | - new \OC\AppFramework\Utility\TimeFactory() |
|
809 | - ); |
|
810 | - } else { |
|
811 | - $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
812 | - $c->get(IDBConnection::class), |
|
813 | - new \OC\AppFramework\Utility\TimeFactory() |
|
814 | - ); |
|
815 | - } |
|
816 | - |
|
817 | - return $backend; |
|
818 | - }); |
|
819 | - |
|
820 | - $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
821 | - /** @deprecated 19.0.0 */ |
|
822 | - $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
823 | - |
|
824 | - $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
825 | - |
|
826 | - $this->registerAlias(ICrypto::class, Crypto::class); |
|
827 | - /** @deprecated 19.0.0 */ |
|
828 | - $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
829 | - |
|
830 | - $this->registerAlias(IHasher::class, Hasher::class); |
|
831 | - /** @deprecated 19.0.0 */ |
|
832 | - $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
833 | - |
|
834 | - $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
835 | - /** @deprecated 19.0.0 */ |
|
836 | - $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
837 | - |
|
838 | - $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
839 | - $this->registerService(Connection::class, function (Server $c) { |
|
840 | - $systemConfig = $c->get(SystemConfig::class); |
|
841 | - $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
842 | - $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
843 | - if (!$factory->isValidType($type)) { |
|
844 | - throw new \OC\DatabaseException('Invalid database type'); |
|
845 | - } |
|
846 | - $connectionParams = $factory->createConnectionParams(); |
|
847 | - $connection = $factory->getConnection($type, $connectionParams); |
|
848 | - $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
849 | - return $connection; |
|
850 | - }); |
|
851 | - /** @deprecated 19.0.0 */ |
|
852 | - $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
853 | - |
|
854 | - $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
855 | - $this->registerAlias(IClientService::class, ClientService::class); |
|
856 | - $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
857 | - return new LocalAddressChecker( |
|
858 | - $c->get(ILogger::class), |
|
859 | - ); |
|
860 | - }); |
|
861 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
862 | - return new NegativeDnsCache( |
|
863 | - $c->get(ICacheFactory::class), |
|
864 | - ); |
|
865 | - }); |
|
866 | - $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
867 | - return new DnsPinMiddleware( |
|
868 | - $c->get(NegativeDnsCache::class), |
|
869 | - $c->get(LocalAddressChecker::class) |
|
870 | - ); |
|
871 | - }); |
|
872 | - $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
873 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
874 | - return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
875 | - }); |
|
876 | - /** @deprecated 19.0.0 */ |
|
877 | - $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
878 | - |
|
879 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
880 | - $queryLogger = new QueryLogger(); |
|
881 | - if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
882 | - // In debug mode, module is being activated by default |
|
883 | - $queryLogger->activate(); |
|
884 | - } |
|
885 | - return $queryLogger; |
|
886 | - }); |
|
887 | - /** @deprecated 19.0.0 */ |
|
888 | - $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
889 | - |
|
890 | - /** @deprecated 19.0.0 */ |
|
891 | - $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
892 | - $this->registerAlias(ITempManager::class, TempManager::class); |
|
893 | - |
|
894 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
895 | - // TODO: use auto-wiring |
|
896 | - return new \OC\App\AppManager( |
|
897 | - $c->get(IUserSession::class), |
|
898 | - $c->get(\OCP\IConfig::class), |
|
899 | - $c->get(\OC\AppConfig::class), |
|
900 | - $c->get(IGroupManager::class), |
|
901 | - $c->get(ICacheFactory::class), |
|
902 | - $c->get(SymfonyAdapter::class), |
|
903 | - $c->get(LoggerInterface::class) |
|
904 | - ); |
|
905 | - }); |
|
906 | - /** @deprecated 19.0.0 */ |
|
907 | - $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
908 | - $this->registerAlias(IAppManager::class, AppManager::class); |
|
909 | - |
|
910 | - $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
911 | - /** @deprecated 19.0.0 */ |
|
912 | - $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
913 | - |
|
914 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
915 | - $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
916 | - |
|
917 | - return new DateTimeFormatter( |
|
918 | - $c->get(IDateTimeZone::class)->getTimeZone(), |
|
919 | - $c->getL10N('lib', $language) |
|
920 | - ); |
|
921 | - }); |
|
922 | - /** @deprecated 19.0.0 */ |
|
923 | - $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
924 | - |
|
925 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
926 | - $mountCache = new UserMountCache( |
|
927 | - $c->get(IDBConnection::class), |
|
928 | - $c->get(IUserManager::class), |
|
929 | - $c->get(ILogger::class) |
|
930 | - ); |
|
931 | - $listener = new UserMountCacheListener($mountCache); |
|
932 | - $listener->listen($c->get(IUserManager::class)); |
|
933 | - return $mountCache; |
|
934 | - }); |
|
935 | - /** @deprecated 19.0.0 */ |
|
936 | - $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
937 | - |
|
938 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
939 | - $loader = \OC\Files\Filesystem::getLoader(); |
|
940 | - $mountCache = $c->get(IUserMountCache::class); |
|
941 | - $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
942 | - |
|
943 | - // builtin providers |
|
944 | - |
|
945 | - $config = $c->get(\OCP\IConfig::class); |
|
946 | - $logger = $c->get(ILogger::class); |
|
947 | - $manager->registerProvider(new CacheMountProvider($config)); |
|
948 | - $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
949 | - $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
950 | - $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
951 | - |
|
952 | - return $manager; |
|
953 | - }); |
|
954 | - /** @deprecated 19.0.0 */ |
|
955 | - $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
956 | - |
|
957 | - /** @deprecated 20.0.0 */ |
|
958 | - $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
959 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
960 | - $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
961 | - if ($busClass) { |
|
962 | - [$app, $class] = explode('::', $busClass, 2); |
|
963 | - if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
964 | - \OC_App::loadApp($app); |
|
965 | - return $c->get($class); |
|
966 | - } else { |
|
967 | - throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
968 | - } |
|
969 | - } else { |
|
970 | - $jobList = $c->get(IJobList::class); |
|
971 | - return new CronBus($jobList); |
|
972 | - } |
|
973 | - }); |
|
974 | - $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
975 | - /** @deprecated 20.0.0 */ |
|
976 | - $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
977 | - $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
978 | - /** @deprecated 19.0.0 */ |
|
979 | - $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
980 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
981 | - // IConfig and IAppManager requires a working database. This code |
|
982 | - // might however be called when ownCloud is not yet setup. |
|
983 | - if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
984 | - $config = $c->get(\OCP\IConfig::class); |
|
985 | - $appManager = $c->get(IAppManager::class); |
|
986 | - } else { |
|
987 | - $config = null; |
|
988 | - $appManager = null; |
|
989 | - } |
|
990 | - |
|
991 | - return new Checker( |
|
992 | - new EnvironmentHelper(), |
|
993 | - new FileAccessHelper(), |
|
994 | - new AppLocator(), |
|
995 | - $config, |
|
996 | - $c->get(ICacheFactory::class), |
|
997 | - $appManager, |
|
998 | - $c->get(IMimeTypeDetector::class) |
|
999 | - ); |
|
1000 | - }); |
|
1001 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
1002 | - if (isset($this['urlParams'])) { |
|
1003 | - $urlParams = $this['urlParams']; |
|
1004 | - } else { |
|
1005 | - $urlParams = []; |
|
1006 | - } |
|
1007 | - |
|
1008 | - if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
1009 | - && in_array('fakeinput', stream_get_wrappers()) |
|
1010 | - ) { |
|
1011 | - $stream = 'fakeinput://data'; |
|
1012 | - } else { |
|
1013 | - $stream = 'php://input'; |
|
1014 | - } |
|
1015 | - |
|
1016 | - return new Request( |
|
1017 | - [ |
|
1018 | - 'get' => $_GET, |
|
1019 | - 'post' => $_POST, |
|
1020 | - 'files' => $_FILES, |
|
1021 | - 'server' => $_SERVER, |
|
1022 | - 'env' => $_ENV, |
|
1023 | - 'cookies' => $_COOKIE, |
|
1024 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1025 | - ? $_SERVER['REQUEST_METHOD'] |
|
1026 | - : '', |
|
1027 | - 'urlParams' => $urlParams, |
|
1028 | - ], |
|
1029 | - $this->get(ISecureRandom::class), |
|
1030 | - $this->get(\OCP\IConfig::class), |
|
1031 | - $this->get(CsrfTokenManager::class), |
|
1032 | - $stream |
|
1033 | - ); |
|
1034 | - }); |
|
1035 | - /** @deprecated 19.0.0 */ |
|
1036 | - $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
1037 | - |
|
1038 | - $this->registerService(IMailer::class, function (Server $c) { |
|
1039 | - return new Mailer( |
|
1040 | - $c->get(\OCP\IConfig::class), |
|
1041 | - $c->get(ILogger::class), |
|
1042 | - $c->get(Defaults::class), |
|
1043 | - $c->get(IURLGenerator::class), |
|
1044 | - $c->getL10N('lib'), |
|
1045 | - $c->get(IEventDispatcher::class), |
|
1046 | - $c->get(IFactory::class) |
|
1047 | - ); |
|
1048 | - }); |
|
1049 | - /** @deprecated 19.0.0 */ |
|
1050 | - $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1051 | - |
|
1052 | - /** @deprecated 21.0.0 */ |
|
1053 | - $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
1054 | - |
|
1055 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1056 | - $config = $c->get(\OCP\IConfig::class); |
|
1057 | - $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1058 | - if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
1059 | - return new NullLDAPProviderFactory($this); |
|
1060 | - } |
|
1061 | - /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1062 | - return new $factoryClass($this); |
|
1063 | - }); |
|
1064 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1065 | - $factory = $c->get(ILDAPProviderFactory::class); |
|
1066 | - return $factory->getLDAPProvider(); |
|
1067 | - }); |
|
1068 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1069 | - $ini = $c->get(IniGetWrapper::class); |
|
1070 | - $config = $c->get(\OCP\IConfig::class); |
|
1071 | - $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1072 | - if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1073 | - /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1074 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1075 | - $memcache = $memcacheFactory->createLocking('lock'); |
|
1076 | - if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1077 | - return new MemcacheLockingProvider($memcache, $ttl); |
|
1078 | - } |
|
1079 | - return new DBLockingProvider( |
|
1080 | - $c->get(IDBConnection::class), |
|
1081 | - $c->get(ILogger::class), |
|
1082 | - new TimeFactory(), |
|
1083 | - $ttl, |
|
1084 | - !\OC::$CLI |
|
1085 | - ); |
|
1086 | - } |
|
1087 | - return new NoopLockingProvider(); |
|
1088 | - }); |
|
1089 | - /** @deprecated 19.0.0 */ |
|
1090 | - $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1091 | - |
|
1092 | - $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1093 | - /** @deprecated 19.0.0 */ |
|
1094 | - $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1095 | - |
|
1096 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1097 | - return new \OC\Files\Type\Detection( |
|
1098 | - $c->get(IURLGenerator::class), |
|
1099 | - $c->get(ILogger::class), |
|
1100 | - \OC::$configDir, |
|
1101 | - \OC::$SERVERROOT . '/resources/config/' |
|
1102 | - ); |
|
1103 | - }); |
|
1104 | - /** @deprecated 19.0.0 */ |
|
1105 | - $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1106 | - |
|
1107 | - $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1108 | - /** @deprecated 19.0.0 */ |
|
1109 | - $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1110 | - $this->registerService(BundleFetcher::class, function () { |
|
1111 | - return new BundleFetcher($this->getL10N('lib')); |
|
1112 | - }); |
|
1113 | - $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1114 | - /** @deprecated 19.0.0 */ |
|
1115 | - $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1116 | - |
|
1117 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1118 | - $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
1119 | - $manager->registerCapability(function () use ($c) { |
|
1120 | - return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1121 | - }); |
|
1122 | - $manager->registerCapability(function () use ($c) { |
|
1123 | - return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1124 | - }); |
|
1125 | - return $manager; |
|
1126 | - }); |
|
1127 | - /** @deprecated 19.0.0 */ |
|
1128 | - $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1129 | - |
|
1130 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1131 | - $config = $c->get(\OCP\IConfig::class); |
|
1132 | - $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1133 | - /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1134 | - $factory = new $factoryClass($this); |
|
1135 | - $manager = $factory->getManager(); |
|
1136 | - |
|
1137 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1138 | - $manager = $c->get(IUserManager::class); |
|
1139 | - $user = $manager->get($id); |
|
1140 | - if (is_null($user)) { |
|
1141 | - $l = $c->getL10N('core'); |
|
1142 | - $displayName = $l->t('Unknown user'); |
|
1143 | - } else { |
|
1144 | - $displayName = $user->getDisplayName(); |
|
1145 | - } |
|
1146 | - return $displayName; |
|
1147 | - }); |
|
1148 | - |
|
1149 | - return $manager; |
|
1150 | - }); |
|
1151 | - /** @deprecated 19.0.0 */ |
|
1152 | - $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1153 | - |
|
1154 | - $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1155 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1156 | - /* |
|
266 | + /** @var string */ |
|
267 | + private $webRoot; |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $webRoot |
|
271 | + * @param \OC\Config $config |
|
272 | + */ |
|
273 | + public function __construct($webRoot, \OC\Config $config) { |
|
274 | + parent::__construct(); |
|
275 | + $this->webRoot = $webRoot; |
|
276 | + |
|
277 | + // To find out if we are running from CLI or not |
|
278 | + $this->registerParameter('isCLI', \OC::$CLI); |
|
279 | + $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
|
280 | + |
|
281 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
282 | + return $c; |
|
283 | + }); |
|
284 | + $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
285 | + return $c; |
|
286 | + }); |
|
287 | + |
|
288 | + $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
|
289 | + /** @deprecated 19.0.0 */ |
|
290 | + $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class); |
|
291 | + |
|
292 | + $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class); |
|
293 | + /** @deprecated 19.0.0 */ |
|
294 | + $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class); |
|
295 | + |
|
296 | + $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class); |
|
297 | + /** @deprecated 19.0.0 */ |
|
298 | + $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class); |
|
299 | + |
|
300 | + $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
|
301 | + /** @deprecated 19.0.0 */ |
|
302 | + $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class); |
|
303 | + |
|
304 | + $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); |
|
305 | + $this->registerAlias(ITemplateManager::class, TemplateManager::class); |
|
306 | + |
|
307 | + $this->registerAlias(IActionFactory::class, ActionFactory::class); |
|
308 | + |
|
309 | + $this->registerService(View::class, function (Server $c) { |
|
310 | + return new View(); |
|
311 | + }, false); |
|
312 | + |
|
313 | + $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
314 | + return new PreviewManager( |
|
315 | + $c->get(\OCP\IConfig::class), |
|
316 | + $c->get(IRootFolder::class), |
|
317 | + new \OC\Preview\Storage\Root( |
|
318 | + $c->get(IRootFolder::class), |
|
319 | + $c->get(SystemConfig::class) |
|
320 | + ), |
|
321 | + $c->get(SymfonyAdapter::class), |
|
322 | + $c->get(GeneratorHelper::class), |
|
323 | + $c->get(ISession::class)->get('user_id'), |
|
324 | + $c->get(Coordinator::class), |
|
325 | + $c->get(IServerContainer::class) |
|
326 | + ); |
|
327 | + }); |
|
328 | + /** @deprecated 19.0.0 */ |
|
329 | + $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
|
330 | + |
|
331 | + $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
332 | + return new \OC\Preview\Watcher( |
|
333 | + new \OC\Preview\Storage\Root( |
|
334 | + $c->get(IRootFolder::class), |
|
335 | + $c->get(SystemConfig::class) |
|
336 | + ) |
|
337 | + ); |
|
338 | + }); |
|
339 | + |
|
340 | + $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
341 | + $view = new View(); |
|
342 | + $util = new Encryption\Util( |
|
343 | + $view, |
|
344 | + $c->get(IUserManager::class), |
|
345 | + $c->get(IGroupManager::class), |
|
346 | + $c->get(\OCP\IConfig::class) |
|
347 | + ); |
|
348 | + return new Encryption\Manager( |
|
349 | + $c->get(\OCP\IConfig::class), |
|
350 | + $c->get(ILogger::class), |
|
351 | + $c->getL10N('core'), |
|
352 | + new View(), |
|
353 | + $util, |
|
354 | + new ArrayCache() |
|
355 | + ); |
|
356 | + }); |
|
357 | + /** @deprecated 19.0.0 */ |
|
358 | + $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class); |
|
359 | + |
|
360 | + /** @deprecated 21.0.0 */ |
|
361 | + $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
|
362 | + $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
363 | + $util = new Encryption\Util( |
|
364 | + new View(), |
|
365 | + $c->get(IUserManager::class), |
|
366 | + $c->get(IGroupManager::class), |
|
367 | + $c->get(\OCP\IConfig::class) |
|
368 | + ); |
|
369 | + return new Encryption\File( |
|
370 | + $util, |
|
371 | + $c->get(IRootFolder::class), |
|
372 | + $c->get(\OCP\Share\IManager::class) |
|
373 | + ); |
|
374 | + }); |
|
375 | + |
|
376 | + /** @deprecated 21.0.0 */ |
|
377 | + $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
|
378 | + $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
379 | + $view = new View(); |
|
380 | + $util = new Encryption\Util( |
|
381 | + $view, |
|
382 | + $c->get(IUserManager::class), |
|
383 | + $c->get(IGroupManager::class), |
|
384 | + $c->get(\OCP\IConfig::class) |
|
385 | + ); |
|
386 | + |
|
387 | + return new Encryption\Keys\Storage( |
|
388 | + $view, |
|
389 | + $util, |
|
390 | + $c->get(ICrypto::class), |
|
391 | + $c->get(\OCP\IConfig::class) |
|
392 | + ); |
|
393 | + }); |
|
394 | + /** @deprecated 20.0.0 */ |
|
395 | + $this->registerDeprecatedAlias('TagMapper', TagMapper::class); |
|
396 | + |
|
397 | + $this->registerAlias(\OCP\ITagManager::class, TagManager::class); |
|
398 | + /** @deprecated 19.0.0 */ |
|
399 | + $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
|
400 | + |
|
401 | + $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
402 | + /** @var \OCP\IConfig $config */ |
|
403 | + $config = $c->get(\OCP\IConfig::class); |
|
404 | + $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
|
405 | + return new $factoryClass($this); |
|
406 | + }); |
|
407 | + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
408 | + return $c->get('SystemTagManagerFactory')->getManager(); |
|
409 | + }); |
|
410 | + /** @deprecated 19.0.0 */ |
|
411 | + $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
|
412 | + |
|
413 | + $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
414 | + return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
|
415 | + }); |
|
416 | + $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
417 | + $manager = \OC\Files\Filesystem::getMountManager(null); |
|
418 | + $view = new View(); |
|
419 | + $root = new Root( |
|
420 | + $manager, |
|
421 | + $view, |
|
422 | + null, |
|
423 | + $c->get(IUserMountCache::class), |
|
424 | + $this->get(ILogger::class), |
|
425 | + $this->get(IUserManager::class) |
|
426 | + ); |
|
427 | + |
|
428 | + $previewConnector = new \OC\Preview\WatcherConnector( |
|
429 | + $root, |
|
430 | + $c->get(SystemConfig::class) |
|
431 | + ); |
|
432 | + $previewConnector->connectWatcher(); |
|
433 | + |
|
434 | + return $root; |
|
435 | + }); |
|
436 | + $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
437 | + return new HookConnector( |
|
438 | + $c->get(IRootFolder::class), |
|
439 | + new View(), |
|
440 | + $c->get(\OC\EventDispatcher\SymfonyAdapter::class), |
|
441 | + $c->get(IEventDispatcher::class) |
|
442 | + ); |
|
443 | + }); |
|
444 | + |
|
445 | + /** @deprecated 19.0.0 */ |
|
446 | + $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
|
447 | + |
|
448 | + $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
449 | + return new LazyRoot(function () use ($c) { |
|
450 | + return $c->get('RootFolder'); |
|
451 | + }); |
|
452 | + }); |
|
453 | + /** @deprecated 19.0.0 */ |
|
454 | + $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class); |
|
455 | + |
|
456 | + /** @deprecated 19.0.0 */ |
|
457 | + $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
|
458 | + $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
|
459 | + |
|
460 | + $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
461 | + $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
|
462 | + $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
463 | + /** @var IEventDispatcher $dispatcher */ |
|
464 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
465 | + $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
|
466 | + }); |
|
467 | + $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
468 | + /** @var IEventDispatcher $dispatcher */ |
|
469 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
470 | + $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
|
471 | + }); |
|
472 | + $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
473 | + /** @var IEventDispatcher $dispatcher */ |
|
474 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
475 | + $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
|
476 | + }); |
|
477 | + $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
478 | + /** @var IEventDispatcher $dispatcher */ |
|
479 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
480 | + $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
|
481 | + }); |
|
482 | + $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
483 | + /** @var IEventDispatcher $dispatcher */ |
|
484 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
485 | + $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
|
486 | + }); |
|
487 | + $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
488 | + /** @var IEventDispatcher $dispatcher */ |
|
489 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
490 | + $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
|
491 | + }); |
|
492 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
493 | + /** @var IEventDispatcher $dispatcher */ |
|
494 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
495 | + $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
|
496 | + }); |
|
497 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
498 | + /** @var IEventDispatcher $dispatcher */ |
|
499 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
500 | + $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
|
501 | + }); |
|
502 | + return $groupManager; |
|
503 | + }); |
|
504 | + /** @deprecated 19.0.0 */ |
|
505 | + $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
|
506 | + |
|
507 | + $this->registerService(Store::class, function (ContainerInterface $c) { |
|
508 | + $session = $c->get(ISession::class); |
|
509 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
510 | + $tokenProvider = $c->get(IProvider::class); |
|
511 | + } else { |
|
512 | + $tokenProvider = null; |
|
513 | + } |
|
514 | + $logger = $c->get(LoggerInterface::class); |
|
515 | + return new Store($session, $logger, $tokenProvider); |
|
516 | + }); |
|
517 | + $this->registerAlias(IStore::class, Store::class); |
|
518 | + $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
|
519 | + |
|
520 | + $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
521 | + $manager = $c->get(IUserManager::class); |
|
522 | + $session = new \OC\Session\Memory(''); |
|
523 | + $timeFactory = new TimeFactory(); |
|
524 | + // Token providers might require a working database. This code |
|
525 | + // might however be called when Nextcloud is not yet setup. |
|
526 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
527 | + $provider = $c->get(IProvider::class); |
|
528 | + } else { |
|
529 | + $provider = null; |
|
530 | + } |
|
531 | + |
|
532 | + $legacyDispatcher = $c->get(SymfonyAdapter::class); |
|
533 | + |
|
534 | + $userSession = new \OC\User\Session( |
|
535 | + $manager, |
|
536 | + $session, |
|
537 | + $timeFactory, |
|
538 | + $provider, |
|
539 | + $c->get(\OCP\IConfig::class), |
|
540 | + $c->get(ISecureRandom::class), |
|
541 | + $c->getLockdownManager(), |
|
542 | + $c->get(ILogger::class), |
|
543 | + $c->get(IEventDispatcher::class) |
|
544 | + ); |
|
545 | + /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
|
546 | + $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
547 | + \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
548 | + }); |
|
549 | + /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
|
550 | + $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
551 | + /** @var \OC\User\User $user */ |
|
552 | + \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
|
553 | + }); |
|
554 | + /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
|
555 | + $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
556 | + /** @var \OC\User\User $user */ |
|
557 | + \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
|
558 | + $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
|
559 | + }); |
|
560 | + /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
|
561 | + $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
562 | + /** @var \OC\User\User $user */ |
|
563 | + \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
|
564 | + }); |
|
565 | + $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
566 | + /** @var \OC\User\User $user */ |
|
567 | + \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
568 | + |
|
569 | + /** @var IEventDispatcher $dispatcher */ |
|
570 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
571 | + $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
572 | + }); |
|
573 | + $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
574 | + /** @var \OC\User\User $user */ |
|
575 | + \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
|
576 | + |
|
577 | + /** @var IEventDispatcher $dispatcher */ |
|
578 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
579 | + $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
|
580 | + }); |
|
581 | + $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
582 | + \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
|
583 | + |
|
584 | + /** @var IEventDispatcher $dispatcher */ |
|
585 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
586 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
|
587 | + }); |
|
588 | + $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
589 | + /** @var \OC\User\User $user */ |
|
590 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
|
591 | + |
|
592 | + /** @var IEventDispatcher $dispatcher */ |
|
593 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
594 | + $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
|
595 | + }); |
|
596 | + $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
597 | + /** @var IEventDispatcher $dispatcher */ |
|
598 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
599 | + $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
|
600 | + }); |
|
601 | + $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
602 | + /** @var \OC\User\User $user */ |
|
603 | + \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
|
604 | + |
|
605 | + /** @var IEventDispatcher $dispatcher */ |
|
606 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
607 | + $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
|
608 | + }); |
|
609 | + $userSession->listen('\OC\User', 'logout', function ($user) { |
|
610 | + \OC_Hook::emit('OC_User', 'logout', []); |
|
611 | + |
|
612 | + /** @var IEventDispatcher $dispatcher */ |
|
613 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
614 | + $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
|
615 | + }); |
|
616 | + $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
617 | + /** @var IEventDispatcher $dispatcher */ |
|
618 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
619 | + $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
|
620 | + }); |
|
621 | + $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
622 | + /** @var \OC\User\User $user */ |
|
623 | + \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
|
624 | + |
|
625 | + /** @var IEventDispatcher $dispatcher */ |
|
626 | + $dispatcher = $this->get(IEventDispatcher::class); |
|
627 | + $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue)); |
|
628 | + }); |
|
629 | + return $userSession; |
|
630 | + }); |
|
631 | + $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class); |
|
632 | + /** @deprecated 19.0.0 */ |
|
633 | + $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class); |
|
634 | + |
|
635 | + $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class); |
|
636 | + |
|
637 | + $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class); |
|
638 | + /** @deprecated 19.0.0 */ |
|
639 | + $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class); |
|
640 | + |
|
641 | + /** @deprecated 19.0.0 */ |
|
642 | + $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
|
643 | + $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
|
644 | + |
|
645 | + $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
646 | + return new \OC\SystemConfig($config); |
|
647 | + }); |
|
648 | + /** @deprecated 19.0.0 */ |
|
649 | + $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class); |
|
650 | + |
|
651 | + /** @deprecated 19.0.0 */ |
|
652 | + $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
|
653 | + $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
|
654 | + |
|
655 | + $this->registerService(IFactory::class, function (Server $c) { |
|
656 | + return new \OC\L10N\Factory( |
|
657 | + $c->get(\OCP\IConfig::class), |
|
658 | + $c->getRequest(), |
|
659 | + $c->get(IUserSession::class), |
|
660 | + \OC::$SERVERROOT |
|
661 | + ); |
|
662 | + }); |
|
663 | + /** @deprecated 19.0.0 */ |
|
664 | + $this->registerDeprecatedAlias('L10NFactory', IFactory::class); |
|
665 | + |
|
666 | + $this->registerAlias(IURLGenerator::class, URLGenerator::class); |
|
667 | + /** @deprecated 19.0.0 */ |
|
668 | + $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class); |
|
669 | + |
|
670 | + /** @deprecated 19.0.0 */ |
|
671 | + $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class); |
|
672 | + /** @deprecated 19.0.0 */ |
|
673 | + $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
|
674 | + |
|
675 | + $this->registerService(ICache::class, function ($c) { |
|
676 | + return new Cache\File(); |
|
677 | + }); |
|
678 | + /** @deprecated 19.0.0 */ |
|
679 | + $this->registerDeprecatedAlias('UserCache', ICache::class); |
|
680 | + |
|
681 | + $this->registerService(Factory::class, function (Server $c) { |
|
682 | + $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
|
683 | + ArrayCache::class, |
|
684 | + ArrayCache::class, |
|
685 | + ArrayCache::class |
|
686 | + ); |
|
687 | + /** @var \OCP\IConfig $config */ |
|
688 | + $config = $c->get(\OCP\IConfig::class); |
|
689 | + |
|
690 | + if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
691 | + if (!$config->getSystemValueBool('log_query')) { |
|
692 | + $v = \OC_App::getAppVersions(); |
|
693 | + } else { |
|
694 | + // If the log_query is enabled, we can not get the app versions |
|
695 | + // as that does a query, which will be logged and the logging |
|
696 | + // depends on redis and here we are back again in the same function. |
|
697 | + $v = [ |
|
698 | + 'log_query' => 'enabled', |
|
699 | + ]; |
|
700 | + } |
|
701 | + $v['core'] = implode(',', \OC_Util::getVersion()); |
|
702 | + $version = implode(',', $v); |
|
703 | + $instanceId = \OC_Util::getInstanceId(); |
|
704 | + $path = \OC::$SERVERROOT; |
|
705 | + $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
706 | + return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
|
707 | + $config->getSystemValue('memcache.local', null), |
|
708 | + $config->getSystemValue('memcache.distributed', null), |
|
709 | + $config->getSystemValue('memcache.locking', null), |
|
710 | + $config->getSystemValueString('redis_log_file') |
|
711 | + ); |
|
712 | + } |
|
713 | + return $arrayCacheFactory; |
|
714 | + }); |
|
715 | + /** @deprecated 19.0.0 */ |
|
716 | + $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
|
717 | + $this->registerAlias(ICacheFactory::class, Factory::class); |
|
718 | + |
|
719 | + $this->registerService('RedisFactory', function (Server $c) { |
|
720 | + $systemConfig = $c->get(SystemConfig::class); |
|
721 | + return new RedisFactory($systemConfig, $c->getEventLogger()); |
|
722 | + }); |
|
723 | + |
|
724 | + $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
725 | + $l10n = $this->get(IFactory::class)->get('lib'); |
|
726 | + return new \OC\Activity\Manager( |
|
727 | + $c->getRequest(), |
|
728 | + $c->get(IUserSession::class), |
|
729 | + $c->get(\OCP\IConfig::class), |
|
730 | + $c->get(IValidator::class), |
|
731 | + $l10n |
|
732 | + ); |
|
733 | + }); |
|
734 | + /** @deprecated 19.0.0 */ |
|
735 | + $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
|
736 | + |
|
737 | + $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
738 | + return new \OC\Activity\EventMerger( |
|
739 | + $c->getL10N('lib') |
|
740 | + ); |
|
741 | + }); |
|
742 | + $this->registerAlias(IValidator::class, Validator::class); |
|
743 | + |
|
744 | + $this->registerService(AvatarManager::class, function (Server $c) { |
|
745 | + return new AvatarManager( |
|
746 | + $c->get(IUserSession::class), |
|
747 | + $c->get(\OC\User\Manager::class), |
|
748 | + $c->getAppDataDir('avatar'), |
|
749 | + $c->getL10N('lib'), |
|
750 | + $c->get(LoggerInterface::class), |
|
751 | + $c->get(\OCP\IConfig::class), |
|
752 | + $c->get(IAccountManager::class), |
|
753 | + $c->get(KnownUserService::class) |
|
754 | + ); |
|
755 | + }); |
|
756 | + $this->registerAlias(IAvatarManager::class, AvatarManager::class); |
|
757 | + /** @deprecated 19.0.0 */ |
|
758 | + $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class); |
|
759 | + |
|
760 | + $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
|
761 | + $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
|
762 | + |
|
763 | + $this->registerService(\OC\Log::class, function (Server $c) { |
|
764 | + $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
|
765 | + $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
|
766 | + $logger = $factory->get($logType); |
|
767 | + $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class); |
|
768 | + |
|
769 | + return new Log($logger, $this->get(SystemConfig::class), null, $registry); |
|
770 | + }); |
|
771 | + $this->registerAlias(ILogger::class, \OC\Log::class); |
|
772 | + /** @deprecated 19.0.0 */ |
|
773 | + $this->registerDeprecatedAlias('Logger', \OC\Log::class); |
|
774 | + // PSR-3 logger |
|
775 | + $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
|
776 | + |
|
777 | + $this->registerService(ILogFactory::class, function (Server $c) { |
|
778 | + return new LogFactory($c, $this->get(SystemConfig::class)); |
|
779 | + }); |
|
780 | + |
|
781 | + $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class); |
|
782 | + /** @deprecated 19.0.0 */ |
|
783 | + $this->registerDeprecatedAlias('JobList', IJobList::class); |
|
784 | + |
|
785 | + $this->registerService(Router::class, function (Server $c) { |
|
786 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
787 | + $logger = $c->get(ILogger::class); |
|
788 | + if ($cacheFactory->isLocalCacheAvailable()) { |
|
789 | + $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
|
790 | + } else { |
|
791 | + $router = new \OC\Route\Router($logger); |
|
792 | + } |
|
793 | + return $router; |
|
794 | + }); |
|
795 | + $this->registerAlias(IRouter::class, Router::class); |
|
796 | + /** @deprecated 19.0.0 */ |
|
797 | + $this->registerDeprecatedAlias('Router', IRouter::class); |
|
798 | + |
|
799 | + $this->registerAlias(ISearch::class, Search::class); |
|
800 | + /** @deprecated 19.0.0 */ |
|
801 | + $this->registerDeprecatedAlias('Search', ISearch::class); |
|
802 | + |
|
803 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
804 | + $cacheFactory = $c->get(ICacheFactory::class); |
|
805 | + if ($cacheFactory->isAvailable()) { |
|
806 | + $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
|
807 | + $this->get(ICacheFactory::class), |
|
808 | + new \OC\AppFramework\Utility\TimeFactory() |
|
809 | + ); |
|
810 | + } else { |
|
811 | + $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend( |
|
812 | + $c->get(IDBConnection::class), |
|
813 | + new \OC\AppFramework\Utility\TimeFactory() |
|
814 | + ); |
|
815 | + } |
|
816 | + |
|
817 | + return $backend; |
|
818 | + }); |
|
819 | + |
|
820 | + $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class); |
|
821 | + /** @deprecated 19.0.0 */ |
|
822 | + $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
|
823 | + |
|
824 | + $this->registerAlias(IVerificationToken::class, VerificationToken::class); |
|
825 | + |
|
826 | + $this->registerAlias(ICrypto::class, Crypto::class); |
|
827 | + /** @deprecated 19.0.0 */ |
|
828 | + $this->registerDeprecatedAlias('Crypto', ICrypto::class); |
|
829 | + |
|
830 | + $this->registerAlias(IHasher::class, Hasher::class); |
|
831 | + /** @deprecated 19.0.0 */ |
|
832 | + $this->registerDeprecatedAlias('Hasher', IHasher::class); |
|
833 | + |
|
834 | + $this->registerAlias(ICredentialsManager::class, CredentialsManager::class); |
|
835 | + /** @deprecated 19.0.0 */ |
|
836 | + $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
|
837 | + |
|
838 | + $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
|
839 | + $this->registerService(Connection::class, function (Server $c) { |
|
840 | + $systemConfig = $c->get(SystemConfig::class); |
|
841 | + $factory = new \OC\DB\ConnectionFactory($systemConfig); |
|
842 | + $type = $systemConfig->getValue('dbtype', 'sqlite'); |
|
843 | + if (!$factory->isValidType($type)) { |
|
844 | + throw new \OC\DatabaseException('Invalid database type'); |
|
845 | + } |
|
846 | + $connectionParams = $factory->createConnectionParams(); |
|
847 | + $connection = $factory->getConnection($type, $connectionParams); |
|
848 | + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
|
849 | + return $connection; |
|
850 | + }); |
|
851 | + /** @deprecated 19.0.0 */ |
|
852 | + $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class); |
|
853 | + |
|
854 | + $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
|
855 | + $this->registerAlias(IClientService::class, ClientService::class); |
|
856 | + $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
857 | + return new LocalAddressChecker( |
|
858 | + $c->get(ILogger::class), |
|
859 | + ); |
|
860 | + }); |
|
861 | + $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
862 | + return new NegativeDnsCache( |
|
863 | + $c->get(ICacheFactory::class), |
|
864 | + ); |
|
865 | + }); |
|
866 | + $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
867 | + return new DnsPinMiddleware( |
|
868 | + $c->get(NegativeDnsCache::class), |
|
869 | + $c->get(LocalAddressChecker::class) |
|
870 | + ); |
|
871 | + }); |
|
872 | + $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
|
873 | + $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
874 | + return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
|
875 | + }); |
|
876 | + /** @deprecated 19.0.0 */ |
|
877 | + $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
|
878 | + |
|
879 | + $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
880 | + $queryLogger = new QueryLogger(); |
|
881 | + if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
|
882 | + // In debug mode, module is being activated by default |
|
883 | + $queryLogger->activate(); |
|
884 | + } |
|
885 | + return $queryLogger; |
|
886 | + }); |
|
887 | + /** @deprecated 19.0.0 */ |
|
888 | + $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class); |
|
889 | + |
|
890 | + /** @deprecated 19.0.0 */ |
|
891 | + $this->registerDeprecatedAlias('TempManager', TempManager::class); |
|
892 | + $this->registerAlias(ITempManager::class, TempManager::class); |
|
893 | + |
|
894 | + $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
895 | + // TODO: use auto-wiring |
|
896 | + return new \OC\App\AppManager( |
|
897 | + $c->get(IUserSession::class), |
|
898 | + $c->get(\OCP\IConfig::class), |
|
899 | + $c->get(\OC\AppConfig::class), |
|
900 | + $c->get(IGroupManager::class), |
|
901 | + $c->get(ICacheFactory::class), |
|
902 | + $c->get(SymfonyAdapter::class), |
|
903 | + $c->get(LoggerInterface::class) |
|
904 | + ); |
|
905 | + }); |
|
906 | + /** @deprecated 19.0.0 */ |
|
907 | + $this->registerDeprecatedAlias('AppManager', AppManager::class); |
|
908 | + $this->registerAlias(IAppManager::class, AppManager::class); |
|
909 | + |
|
910 | + $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); |
|
911 | + /** @deprecated 19.0.0 */ |
|
912 | + $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
|
913 | + |
|
914 | + $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
915 | + $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
|
916 | + |
|
917 | + return new DateTimeFormatter( |
|
918 | + $c->get(IDateTimeZone::class)->getTimeZone(), |
|
919 | + $c->getL10N('lib', $language) |
|
920 | + ); |
|
921 | + }); |
|
922 | + /** @deprecated 19.0.0 */ |
|
923 | + $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
|
924 | + |
|
925 | + $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
926 | + $mountCache = new UserMountCache( |
|
927 | + $c->get(IDBConnection::class), |
|
928 | + $c->get(IUserManager::class), |
|
929 | + $c->get(ILogger::class) |
|
930 | + ); |
|
931 | + $listener = new UserMountCacheListener($mountCache); |
|
932 | + $listener->listen($c->get(IUserManager::class)); |
|
933 | + return $mountCache; |
|
934 | + }); |
|
935 | + /** @deprecated 19.0.0 */ |
|
936 | + $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
|
937 | + |
|
938 | + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
939 | + $loader = \OC\Files\Filesystem::getLoader(); |
|
940 | + $mountCache = $c->get(IUserMountCache::class); |
|
941 | + $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
|
942 | + |
|
943 | + // builtin providers |
|
944 | + |
|
945 | + $config = $c->get(\OCP\IConfig::class); |
|
946 | + $logger = $c->get(ILogger::class); |
|
947 | + $manager->registerProvider(new CacheMountProvider($config)); |
|
948 | + $manager->registerHomeProvider(new LocalHomeMountProvider()); |
|
949 | + $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
|
950 | + $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config)); |
|
951 | + |
|
952 | + return $manager; |
|
953 | + }); |
|
954 | + /** @deprecated 19.0.0 */ |
|
955 | + $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class); |
|
956 | + |
|
957 | + /** @deprecated 20.0.0 */ |
|
958 | + $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
|
959 | + $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
960 | + $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
|
961 | + if ($busClass) { |
|
962 | + [$app, $class] = explode('::', $busClass, 2); |
|
963 | + if ($c->get(IAppManager::class)->isInstalled($app)) { |
|
964 | + \OC_App::loadApp($app); |
|
965 | + return $c->get($class); |
|
966 | + } else { |
|
967 | + throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
|
968 | + } |
|
969 | + } else { |
|
970 | + $jobList = $c->get(IJobList::class); |
|
971 | + return new CronBus($jobList); |
|
972 | + } |
|
973 | + }); |
|
974 | + $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class); |
|
975 | + /** @deprecated 20.0.0 */ |
|
976 | + $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class); |
|
977 | + $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
|
978 | + /** @deprecated 19.0.0 */ |
|
979 | + $this->registerDeprecatedAlias('Throttler', Throttler::class); |
|
980 | + $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
981 | + // IConfig and IAppManager requires a working database. This code |
|
982 | + // might however be called when ownCloud is not yet setup. |
|
983 | + if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
|
984 | + $config = $c->get(\OCP\IConfig::class); |
|
985 | + $appManager = $c->get(IAppManager::class); |
|
986 | + } else { |
|
987 | + $config = null; |
|
988 | + $appManager = null; |
|
989 | + } |
|
990 | + |
|
991 | + return new Checker( |
|
992 | + new EnvironmentHelper(), |
|
993 | + new FileAccessHelper(), |
|
994 | + new AppLocator(), |
|
995 | + $config, |
|
996 | + $c->get(ICacheFactory::class), |
|
997 | + $appManager, |
|
998 | + $c->get(IMimeTypeDetector::class) |
|
999 | + ); |
|
1000 | + }); |
|
1001 | + $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
1002 | + if (isset($this['urlParams'])) { |
|
1003 | + $urlParams = $this['urlParams']; |
|
1004 | + } else { |
|
1005 | + $urlParams = []; |
|
1006 | + } |
|
1007 | + |
|
1008 | + if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
|
1009 | + && in_array('fakeinput', stream_get_wrappers()) |
|
1010 | + ) { |
|
1011 | + $stream = 'fakeinput://data'; |
|
1012 | + } else { |
|
1013 | + $stream = 'php://input'; |
|
1014 | + } |
|
1015 | + |
|
1016 | + return new Request( |
|
1017 | + [ |
|
1018 | + 'get' => $_GET, |
|
1019 | + 'post' => $_POST, |
|
1020 | + 'files' => $_FILES, |
|
1021 | + 'server' => $_SERVER, |
|
1022 | + 'env' => $_ENV, |
|
1023 | + 'cookies' => $_COOKIE, |
|
1024 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1025 | + ? $_SERVER['REQUEST_METHOD'] |
|
1026 | + : '', |
|
1027 | + 'urlParams' => $urlParams, |
|
1028 | + ], |
|
1029 | + $this->get(ISecureRandom::class), |
|
1030 | + $this->get(\OCP\IConfig::class), |
|
1031 | + $this->get(CsrfTokenManager::class), |
|
1032 | + $stream |
|
1033 | + ); |
|
1034 | + }); |
|
1035 | + /** @deprecated 19.0.0 */ |
|
1036 | + $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
|
1037 | + |
|
1038 | + $this->registerService(IMailer::class, function (Server $c) { |
|
1039 | + return new Mailer( |
|
1040 | + $c->get(\OCP\IConfig::class), |
|
1041 | + $c->get(ILogger::class), |
|
1042 | + $c->get(Defaults::class), |
|
1043 | + $c->get(IURLGenerator::class), |
|
1044 | + $c->getL10N('lib'), |
|
1045 | + $c->get(IEventDispatcher::class), |
|
1046 | + $c->get(IFactory::class) |
|
1047 | + ); |
|
1048 | + }); |
|
1049 | + /** @deprecated 19.0.0 */ |
|
1050 | + $this->registerDeprecatedAlias('Mailer', IMailer::class); |
|
1051 | + |
|
1052 | + /** @deprecated 21.0.0 */ |
|
1053 | + $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
|
1054 | + |
|
1055 | + $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1056 | + $config = $c->get(\OCP\IConfig::class); |
|
1057 | + $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
|
1058 | + if (is_null($factoryClass) || !class_exists($factoryClass)) { |
|
1059 | + return new NullLDAPProviderFactory($this); |
|
1060 | + } |
|
1061 | + /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
|
1062 | + return new $factoryClass($this); |
|
1063 | + }); |
|
1064 | + $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1065 | + $factory = $c->get(ILDAPProviderFactory::class); |
|
1066 | + return $factory->getLDAPProvider(); |
|
1067 | + }); |
|
1068 | + $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1069 | + $ini = $c->get(IniGetWrapper::class); |
|
1070 | + $config = $c->get(\OCP\IConfig::class); |
|
1071 | + $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
|
1072 | + if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
|
1073 | + /** @var \OC\Memcache\Factory $memcacheFactory */ |
|
1074 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1075 | + $memcache = $memcacheFactory->createLocking('lock'); |
|
1076 | + if (!($memcache instanceof \OC\Memcache\NullCache)) { |
|
1077 | + return new MemcacheLockingProvider($memcache, $ttl); |
|
1078 | + } |
|
1079 | + return new DBLockingProvider( |
|
1080 | + $c->get(IDBConnection::class), |
|
1081 | + $c->get(ILogger::class), |
|
1082 | + new TimeFactory(), |
|
1083 | + $ttl, |
|
1084 | + !\OC::$CLI |
|
1085 | + ); |
|
1086 | + } |
|
1087 | + return new NoopLockingProvider(); |
|
1088 | + }); |
|
1089 | + /** @deprecated 19.0.0 */ |
|
1090 | + $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class); |
|
1091 | + |
|
1092 | + $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class); |
|
1093 | + /** @deprecated 19.0.0 */ |
|
1094 | + $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
|
1095 | + |
|
1096 | + $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1097 | + return new \OC\Files\Type\Detection( |
|
1098 | + $c->get(IURLGenerator::class), |
|
1099 | + $c->get(ILogger::class), |
|
1100 | + \OC::$configDir, |
|
1101 | + \OC::$SERVERROOT . '/resources/config/' |
|
1102 | + ); |
|
1103 | + }); |
|
1104 | + /** @deprecated 19.0.0 */ |
|
1105 | + $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class); |
|
1106 | + |
|
1107 | + $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
|
1108 | + /** @deprecated 19.0.0 */ |
|
1109 | + $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
|
1110 | + $this->registerService(BundleFetcher::class, function () { |
|
1111 | + return new BundleFetcher($this->getL10N('lib')); |
|
1112 | + }); |
|
1113 | + $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
|
1114 | + /** @deprecated 19.0.0 */ |
|
1115 | + $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
|
1116 | + |
|
1117 | + $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1118 | + $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
|
1119 | + $manager->registerCapability(function () use ($c) { |
|
1120 | + return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
|
1121 | + }); |
|
1122 | + $manager->registerCapability(function () use ($c) { |
|
1123 | + return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
|
1124 | + }); |
|
1125 | + return $manager; |
|
1126 | + }); |
|
1127 | + /** @deprecated 19.0.0 */ |
|
1128 | + $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
|
1129 | + |
|
1130 | + $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1131 | + $config = $c->get(\OCP\IConfig::class); |
|
1132 | + $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
|
1133 | + /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
|
1134 | + $factory = new $factoryClass($this); |
|
1135 | + $manager = $factory->getManager(); |
|
1136 | + |
|
1137 | + $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1138 | + $manager = $c->get(IUserManager::class); |
|
1139 | + $user = $manager->get($id); |
|
1140 | + if (is_null($user)) { |
|
1141 | + $l = $c->getL10N('core'); |
|
1142 | + $displayName = $l->t('Unknown user'); |
|
1143 | + } else { |
|
1144 | + $displayName = $user->getDisplayName(); |
|
1145 | + } |
|
1146 | + return $displayName; |
|
1147 | + }); |
|
1148 | + |
|
1149 | + return $manager; |
|
1150 | + }); |
|
1151 | + /** @deprecated 19.0.0 */ |
|
1152 | + $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
|
1153 | + |
|
1154 | + $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
|
1155 | + $this->registerService('ThemingDefaults', function (Server $c) { |
|
1156 | + /* |
|
1157 | 1157 | * Dark magic for autoloader. |
1158 | 1158 | * If we do a class_exists it will try to load the class which will |
1159 | 1159 | * make composer cache the result. Resulting in errors when enabling |
1160 | 1160 | * the theming app. |
1161 | 1161 | */ |
1162 | - $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1163 | - if (isset($prefixes['OCA\\Theming\\'])) { |
|
1164 | - $classExists = true; |
|
1165 | - } else { |
|
1166 | - $classExists = false; |
|
1167 | - } |
|
1168 | - |
|
1169 | - if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1170 | - return new ThemingDefaults( |
|
1171 | - $c->get(\OCP\IConfig::class), |
|
1172 | - $c->getL10N('theming'), |
|
1173 | - $c->get(IURLGenerator::class), |
|
1174 | - $c->get(ICacheFactory::class), |
|
1175 | - new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
1176 | - new ImageManager( |
|
1177 | - $c->get(\OCP\IConfig::class), |
|
1178 | - $c->getAppDataDir('theming'), |
|
1179 | - $c->get(IURLGenerator::class), |
|
1180 | - $this->get(ICacheFactory::class), |
|
1181 | - $this->get(ILogger::class), |
|
1182 | - $this->get(ITempManager::class) |
|
1183 | - ), |
|
1184 | - $c->get(IAppManager::class), |
|
1185 | - $c->get(INavigationManager::class) |
|
1186 | - ); |
|
1187 | - } |
|
1188 | - return new \OC_Defaults(); |
|
1189 | - }); |
|
1190 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1191 | - return new JSCombiner( |
|
1192 | - $c->getAppDataDir('js'), |
|
1193 | - $c->get(IURLGenerator::class), |
|
1194 | - $this->get(ICacheFactory::class), |
|
1195 | - $c->get(SystemConfig::class), |
|
1196 | - $c->get(ILogger::class) |
|
1197 | - ); |
|
1198 | - }); |
|
1199 | - $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1200 | - /** @deprecated 19.0.0 */ |
|
1201 | - $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1202 | - $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1203 | - |
|
1204 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1205 | - // FIXME: Instantiiated here due to cyclic dependency |
|
1206 | - $request = new Request( |
|
1207 | - [ |
|
1208 | - 'get' => $_GET, |
|
1209 | - 'post' => $_POST, |
|
1210 | - 'files' => $_FILES, |
|
1211 | - 'server' => $_SERVER, |
|
1212 | - 'env' => $_ENV, |
|
1213 | - 'cookies' => $_COOKIE, |
|
1214 | - 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1215 | - ? $_SERVER['REQUEST_METHOD'] |
|
1216 | - : null, |
|
1217 | - ], |
|
1218 | - $c->get(ISecureRandom::class), |
|
1219 | - $c->get(\OCP\IConfig::class) |
|
1220 | - ); |
|
1221 | - |
|
1222 | - return new CryptoWrapper( |
|
1223 | - $c->get(\OCP\IConfig::class), |
|
1224 | - $c->get(ICrypto::class), |
|
1225 | - $c->get(ISecureRandom::class), |
|
1226 | - $request |
|
1227 | - ); |
|
1228 | - }); |
|
1229 | - /** @deprecated 19.0.0 */ |
|
1230 | - $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1231 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1232 | - return new SessionStorage($c->get(ISession::class)); |
|
1233 | - }); |
|
1234 | - $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1235 | - /** @deprecated 19.0.0 */ |
|
1236 | - $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1237 | - |
|
1238 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1239 | - $config = $c->get(\OCP\IConfig::class); |
|
1240 | - $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1241 | - /** @var \OCP\Share\IProviderFactory $factory */ |
|
1242 | - $factory = new $factoryClass($this); |
|
1243 | - |
|
1244 | - $manager = new \OC\Share20\Manager( |
|
1245 | - $c->get(ILogger::class), |
|
1246 | - $c->get(\OCP\IConfig::class), |
|
1247 | - $c->get(ISecureRandom::class), |
|
1248 | - $c->get(IHasher::class), |
|
1249 | - $c->get(IMountManager::class), |
|
1250 | - $c->get(IGroupManager::class), |
|
1251 | - $c->getL10N('lib'), |
|
1252 | - $c->get(IFactory::class), |
|
1253 | - $factory, |
|
1254 | - $c->get(IUserManager::class), |
|
1255 | - $c->get(IRootFolder::class), |
|
1256 | - $c->get(SymfonyAdapter::class), |
|
1257 | - $c->get(IMailer::class), |
|
1258 | - $c->get(IURLGenerator::class), |
|
1259 | - $c->get('ThemingDefaults'), |
|
1260 | - $c->get(IEventDispatcher::class), |
|
1261 | - $c->get(IUserSession::class), |
|
1262 | - $c->get(KnownUserService::class) |
|
1263 | - ); |
|
1264 | - |
|
1265 | - return $manager; |
|
1266 | - }); |
|
1267 | - /** @deprecated 19.0.0 */ |
|
1268 | - $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1269 | - |
|
1270 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1271 | - $instance = new Collaboration\Collaborators\Search($c); |
|
1272 | - |
|
1273 | - // register default plugins |
|
1274 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1275 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1276 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1277 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1278 | - $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1279 | - |
|
1280 | - return $instance; |
|
1281 | - }); |
|
1282 | - /** @deprecated 19.0.0 */ |
|
1283 | - $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1284 | - $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1285 | - |
|
1286 | - $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1287 | - |
|
1288 | - $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1289 | - $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1290 | - |
|
1291 | - $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1292 | - $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1293 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1294 | - return new \OC\Files\AppData\Factory( |
|
1295 | - $c->get(IRootFolder::class), |
|
1296 | - $c->get(SystemConfig::class) |
|
1297 | - ); |
|
1298 | - }); |
|
1299 | - |
|
1300 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1301 | - return new LockdownManager(function () use ($c) { |
|
1302 | - return $c->get(ISession::class); |
|
1303 | - }); |
|
1304 | - }); |
|
1305 | - |
|
1306 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1307 | - return new DiscoveryService( |
|
1308 | - $c->get(ICacheFactory::class), |
|
1309 | - $c->get(IClientService::class) |
|
1310 | - ); |
|
1311 | - }); |
|
1312 | - |
|
1313 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1314 | - return new CloudIdManager($c->get(\OCP\Contacts\IManager::class), $c->get(IURLGenerator::class), $c->get(IUserManager::class)); |
|
1315 | - }); |
|
1316 | - |
|
1317 | - $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1318 | - |
|
1319 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1320 | - return new CloudFederationProviderManager( |
|
1321 | - $c->get(IAppManager::class), |
|
1322 | - $c->get(IClientService::class), |
|
1323 | - $c->get(ICloudIdManager::class), |
|
1324 | - $c->get(ILogger::class) |
|
1325 | - ); |
|
1326 | - }); |
|
1327 | - |
|
1328 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1329 | - return new CloudFederationFactory(); |
|
1330 | - }); |
|
1331 | - |
|
1332 | - $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1333 | - /** @deprecated 19.0.0 */ |
|
1334 | - $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1335 | - |
|
1336 | - $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1337 | - /** @deprecated 19.0.0 */ |
|
1338 | - $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1339 | - |
|
1340 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1341 | - return new Defaults( |
|
1342 | - $c->getThemingDefaults() |
|
1343 | - ); |
|
1344 | - }); |
|
1345 | - /** @deprecated 19.0.0 */ |
|
1346 | - $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1347 | - |
|
1348 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1349 | - return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1350 | - }, false); |
|
1351 | - |
|
1352 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1353 | - return new ShareHelper( |
|
1354 | - $c->get(\OCP\Share\IManager::class) |
|
1355 | - ); |
|
1356 | - }); |
|
1357 | - |
|
1358 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1359 | - return new Installer( |
|
1360 | - $c->get(AppFetcher::class), |
|
1361 | - $c->get(IClientService::class), |
|
1362 | - $c->get(ITempManager::class), |
|
1363 | - $c->get(LoggerInterface::class), |
|
1364 | - $c->get(\OCP\IConfig::class), |
|
1365 | - \OC::$CLI |
|
1366 | - ); |
|
1367 | - }); |
|
1368 | - |
|
1369 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1370 | - return new ApiFactory($c->get(IClientService::class)); |
|
1371 | - }); |
|
1372 | - |
|
1373 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1374 | - $memcacheFactory = $c->get(ICacheFactory::class); |
|
1375 | - return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1376 | - }); |
|
1377 | - |
|
1378 | - $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1379 | - $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1380 | - |
|
1381 | - $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1382 | - |
|
1383 | - $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1384 | - $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1385 | - $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1386 | - |
|
1387 | - $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1388 | - |
|
1389 | - $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1390 | - |
|
1391 | - $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1392 | - |
|
1393 | - $this->connectDispatcher(); |
|
1394 | - } |
|
1395 | - |
|
1396 | - public function boot() { |
|
1397 | - /** @var HookConnector $hookConnector */ |
|
1398 | - $hookConnector = $this->get(HookConnector::class); |
|
1399 | - $hookConnector->viewToNode(); |
|
1400 | - } |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * @return \OCP\Calendar\IManager |
|
1404 | - * @deprecated 20.0.0 |
|
1405 | - */ |
|
1406 | - public function getCalendarManager() { |
|
1407 | - return $this->get(\OC\Calendar\Manager::class); |
|
1408 | - } |
|
1409 | - |
|
1410 | - /** |
|
1411 | - * @return \OCP\Calendar\Resource\IManager |
|
1412 | - * @deprecated 20.0.0 |
|
1413 | - */ |
|
1414 | - public function getCalendarResourceBackendManager() { |
|
1415 | - return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1416 | - } |
|
1417 | - |
|
1418 | - /** |
|
1419 | - * @return \OCP\Calendar\Room\IManager |
|
1420 | - * @deprecated 20.0.0 |
|
1421 | - */ |
|
1422 | - public function getCalendarRoomBackendManager() { |
|
1423 | - return $this->get(\OC\Calendar\Room\Manager::class); |
|
1424 | - } |
|
1425 | - |
|
1426 | - private function connectDispatcher() { |
|
1427 | - $dispatcher = $this->get(SymfonyAdapter::class); |
|
1428 | - |
|
1429 | - // Delete avatar on user deletion |
|
1430 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1431 | - $logger = $this->get(ILogger::class); |
|
1432 | - $manager = $this->getAvatarManager(); |
|
1433 | - /** @var IUser $user */ |
|
1434 | - $user = $e->getSubject(); |
|
1435 | - |
|
1436 | - try { |
|
1437 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1438 | - $avatar->remove(); |
|
1439 | - } catch (NotFoundException $e) { |
|
1440 | - // no avatar to remove |
|
1441 | - } catch (\Exception $e) { |
|
1442 | - // Ignore exceptions |
|
1443 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1444 | - } |
|
1445 | - }); |
|
1446 | - |
|
1447 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1448 | - $manager = $this->getAvatarManager(); |
|
1449 | - /** @var IUser $user */ |
|
1450 | - $user = $e->getSubject(); |
|
1451 | - $feature = $e->getArgument('feature'); |
|
1452 | - $oldValue = $e->getArgument('oldValue'); |
|
1453 | - $value = $e->getArgument('value'); |
|
1454 | - |
|
1455 | - // We only change the avatar on display name changes |
|
1456 | - if ($feature !== 'displayName') { |
|
1457 | - return; |
|
1458 | - } |
|
1459 | - |
|
1460 | - try { |
|
1461 | - $avatar = $manager->getAvatar($user->getUID()); |
|
1462 | - $avatar->userChanged($feature, $oldValue, $value); |
|
1463 | - } catch (NotFoundException $e) { |
|
1464 | - // no avatar to remove |
|
1465 | - } |
|
1466 | - }); |
|
1467 | - |
|
1468 | - /** @var IEventDispatcher $eventDispatched */ |
|
1469 | - $eventDispatched = $this->get(IEventDispatcher::class); |
|
1470 | - $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1471 | - $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1472 | - } |
|
1473 | - |
|
1474 | - /** |
|
1475 | - * @return \OCP\Contacts\IManager |
|
1476 | - * @deprecated 20.0.0 |
|
1477 | - */ |
|
1478 | - public function getContactsManager() { |
|
1479 | - return $this->get(\OCP\Contacts\IManager::class); |
|
1480 | - } |
|
1481 | - |
|
1482 | - /** |
|
1483 | - * @return \OC\Encryption\Manager |
|
1484 | - * @deprecated 20.0.0 |
|
1485 | - */ |
|
1486 | - public function getEncryptionManager() { |
|
1487 | - return $this->get(\OCP\Encryption\IManager::class); |
|
1488 | - } |
|
1489 | - |
|
1490 | - /** |
|
1491 | - * @return \OC\Encryption\File |
|
1492 | - * @deprecated 20.0.0 |
|
1493 | - */ |
|
1494 | - public function getEncryptionFilesHelper() { |
|
1495 | - return $this->get(IFile::class); |
|
1496 | - } |
|
1497 | - |
|
1498 | - /** |
|
1499 | - * @return \OCP\Encryption\Keys\IStorage |
|
1500 | - * @deprecated 20.0.0 |
|
1501 | - */ |
|
1502 | - public function getEncryptionKeyStorage() { |
|
1503 | - return $this->get(IStorage::class); |
|
1504 | - } |
|
1505 | - |
|
1506 | - /** |
|
1507 | - * The current request object holding all information about the request |
|
1508 | - * currently being processed is returned from this method. |
|
1509 | - * In case the current execution was not initiated by a web request null is returned |
|
1510 | - * |
|
1511 | - * @return \OCP\IRequest |
|
1512 | - * @deprecated 20.0.0 |
|
1513 | - */ |
|
1514 | - public function getRequest() { |
|
1515 | - return $this->get(IRequest::class); |
|
1516 | - } |
|
1517 | - |
|
1518 | - /** |
|
1519 | - * Returns the preview manager which can create preview images for a given file |
|
1520 | - * |
|
1521 | - * @return IPreview |
|
1522 | - * @deprecated 20.0.0 |
|
1523 | - */ |
|
1524 | - public function getPreviewManager() { |
|
1525 | - return $this->get(IPreview::class); |
|
1526 | - } |
|
1527 | - |
|
1528 | - /** |
|
1529 | - * Returns the tag manager which can get and set tags for different object types |
|
1530 | - * |
|
1531 | - * @see \OCP\ITagManager::load() |
|
1532 | - * @return ITagManager |
|
1533 | - * @deprecated 20.0.0 |
|
1534 | - */ |
|
1535 | - public function getTagManager() { |
|
1536 | - return $this->get(ITagManager::class); |
|
1537 | - } |
|
1538 | - |
|
1539 | - /** |
|
1540 | - * Returns the system-tag manager |
|
1541 | - * |
|
1542 | - * @return ISystemTagManager |
|
1543 | - * |
|
1544 | - * @since 9.0.0 |
|
1545 | - * @deprecated 20.0.0 |
|
1546 | - */ |
|
1547 | - public function getSystemTagManager() { |
|
1548 | - return $this->get(ISystemTagManager::class); |
|
1549 | - } |
|
1550 | - |
|
1551 | - /** |
|
1552 | - * Returns the system-tag object mapper |
|
1553 | - * |
|
1554 | - * @return ISystemTagObjectMapper |
|
1555 | - * |
|
1556 | - * @since 9.0.0 |
|
1557 | - * @deprecated 20.0.0 |
|
1558 | - */ |
|
1559 | - public function getSystemTagObjectMapper() { |
|
1560 | - return $this->get(ISystemTagObjectMapper::class); |
|
1561 | - } |
|
1562 | - |
|
1563 | - /** |
|
1564 | - * Returns the avatar manager, used for avatar functionality |
|
1565 | - * |
|
1566 | - * @return IAvatarManager |
|
1567 | - * @deprecated 20.0.0 |
|
1568 | - */ |
|
1569 | - public function getAvatarManager() { |
|
1570 | - return $this->get(IAvatarManager::class); |
|
1571 | - } |
|
1572 | - |
|
1573 | - /** |
|
1574 | - * Returns the root folder of ownCloud's data directory |
|
1575 | - * |
|
1576 | - * @return IRootFolder |
|
1577 | - * @deprecated 20.0.0 |
|
1578 | - */ |
|
1579 | - public function getRootFolder() { |
|
1580 | - return $this->get(IRootFolder::class); |
|
1581 | - } |
|
1582 | - |
|
1583 | - /** |
|
1584 | - * Returns the root folder of ownCloud's data directory |
|
1585 | - * This is the lazy variant so this gets only initialized once it |
|
1586 | - * is actually used. |
|
1587 | - * |
|
1588 | - * @return IRootFolder |
|
1589 | - * @deprecated 20.0.0 |
|
1590 | - */ |
|
1591 | - public function getLazyRootFolder() { |
|
1592 | - return $this->get(IRootFolder::class); |
|
1593 | - } |
|
1594 | - |
|
1595 | - /** |
|
1596 | - * Returns a view to ownCloud's files folder |
|
1597 | - * |
|
1598 | - * @param string $userId user ID |
|
1599 | - * @return \OCP\Files\Folder|null |
|
1600 | - * @deprecated 20.0.0 |
|
1601 | - */ |
|
1602 | - public function getUserFolder($userId = null) { |
|
1603 | - if ($userId === null) { |
|
1604 | - $user = $this->get(IUserSession::class)->getUser(); |
|
1605 | - if (!$user) { |
|
1606 | - return null; |
|
1607 | - } |
|
1608 | - $userId = $user->getUID(); |
|
1609 | - } |
|
1610 | - $root = $this->get(IRootFolder::class); |
|
1611 | - return $root->getUserFolder($userId); |
|
1612 | - } |
|
1613 | - |
|
1614 | - /** |
|
1615 | - * @return \OC\User\Manager |
|
1616 | - * @deprecated 20.0.0 |
|
1617 | - */ |
|
1618 | - public function getUserManager() { |
|
1619 | - return $this->get(IUserManager::class); |
|
1620 | - } |
|
1621 | - |
|
1622 | - /** |
|
1623 | - * @return \OC\Group\Manager |
|
1624 | - * @deprecated 20.0.0 |
|
1625 | - */ |
|
1626 | - public function getGroupManager() { |
|
1627 | - return $this->get(IGroupManager::class); |
|
1628 | - } |
|
1629 | - |
|
1630 | - /** |
|
1631 | - * @return \OC\User\Session |
|
1632 | - * @deprecated 20.0.0 |
|
1633 | - */ |
|
1634 | - public function getUserSession() { |
|
1635 | - return $this->get(IUserSession::class); |
|
1636 | - } |
|
1637 | - |
|
1638 | - /** |
|
1639 | - * @return \OCP\ISession |
|
1640 | - * @deprecated 20.0.0 |
|
1641 | - */ |
|
1642 | - public function getSession() { |
|
1643 | - return $this->get(IUserSession::class)->getSession(); |
|
1644 | - } |
|
1645 | - |
|
1646 | - /** |
|
1647 | - * @param \OCP\ISession $session |
|
1648 | - */ |
|
1649 | - public function setSession(\OCP\ISession $session) { |
|
1650 | - $this->get(SessionStorage::class)->setSession($session); |
|
1651 | - $this->get(IUserSession::class)->setSession($session); |
|
1652 | - $this->get(Store::class)->setSession($session); |
|
1653 | - } |
|
1654 | - |
|
1655 | - /** |
|
1656 | - * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1657 | - * @deprecated 20.0.0 |
|
1658 | - */ |
|
1659 | - public function getTwoFactorAuthManager() { |
|
1660 | - return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1661 | - } |
|
1662 | - |
|
1663 | - /** |
|
1664 | - * @return \OC\NavigationManager |
|
1665 | - * @deprecated 20.0.0 |
|
1666 | - */ |
|
1667 | - public function getNavigationManager() { |
|
1668 | - return $this->get(INavigationManager::class); |
|
1669 | - } |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * @return \OCP\IConfig |
|
1673 | - * @deprecated 20.0.0 |
|
1674 | - */ |
|
1675 | - public function getConfig() { |
|
1676 | - return $this->get(AllConfig::class); |
|
1677 | - } |
|
1678 | - |
|
1679 | - /** |
|
1680 | - * @return \OC\SystemConfig |
|
1681 | - * @deprecated 20.0.0 |
|
1682 | - */ |
|
1683 | - public function getSystemConfig() { |
|
1684 | - return $this->get(SystemConfig::class); |
|
1685 | - } |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * Returns the app config manager |
|
1689 | - * |
|
1690 | - * @return IAppConfig |
|
1691 | - * @deprecated 20.0.0 |
|
1692 | - */ |
|
1693 | - public function getAppConfig() { |
|
1694 | - return $this->get(IAppConfig::class); |
|
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * @return IFactory |
|
1699 | - * @deprecated 20.0.0 |
|
1700 | - */ |
|
1701 | - public function getL10NFactory() { |
|
1702 | - return $this->get(IFactory::class); |
|
1703 | - } |
|
1704 | - |
|
1705 | - /** |
|
1706 | - * get an L10N instance |
|
1707 | - * |
|
1708 | - * @param string $app appid |
|
1709 | - * @param string $lang |
|
1710 | - * @return IL10N |
|
1711 | - * @deprecated 20.0.0 |
|
1712 | - */ |
|
1713 | - public function getL10N($app, $lang = null) { |
|
1714 | - return $this->get(IFactory::class)->get($app, $lang); |
|
1715 | - } |
|
1716 | - |
|
1717 | - /** |
|
1718 | - * @return IURLGenerator |
|
1719 | - * @deprecated 20.0.0 |
|
1720 | - */ |
|
1721 | - public function getURLGenerator() { |
|
1722 | - return $this->get(IURLGenerator::class); |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * @return AppFetcher |
|
1727 | - * @deprecated 20.0.0 |
|
1728 | - */ |
|
1729 | - public function getAppFetcher() { |
|
1730 | - return $this->get(AppFetcher::class); |
|
1731 | - } |
|
1732 | - |
|
1733 | - /** |
|
1734 | - * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1735 | - * getMemCacheFactory() instead. |
|
1736 | - * |
|
1737 | - * @return ICache |
|
1738 | - * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1739 | - */ |
|
1740 | - public function getCache() { |
|
1741 | - return $this->get(ICache::class); |
|
1742 | - } |
|
1743 | - |
|
1744 | - /** |
|
1745 | - * Returns an \OCP\CacheFactory instance |
|
1746 | - * |
|
1747 | - * @return \OCP\ICacheFactory |
|
1748 | - * @deprecated 20.0.0 |
|
1749 | - */ |
|
1750 | - public function getMemCacheFactory() { |
|
1751 | - return $this->get(ICacheFactory::class); |
|
1752 | - } |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * Returns an \OC\RedisFactory instance |
|
1756 | - * |
|
1757 | - * @return \OC\RedisFactory |
|
1758 | - * @deprecated 20.0.0 |
|
1759 | - */ |
|
1760 | - public function getGetRedisFactory() { |
|
1761 | - return $this->get('RedisFactory'); |
|
1762 | - } |
|
1763 | - |
|
1764 | - |
|
1765 | - /** |
|
1766 | - * Returns the current session |
|
1767 | - * |
|
1768 | - * @return \OCP\IDBConnection |
|
1769 | - * @deprecated 20.0.0 |
|
1770 | - */ |
|
1771 | - public function getDatabaseConnection() { |
|
1772 | - return $this->get(IDBConnection::class); |
|
1773 | - } |
|
1774 | - |
|
1775 | - /** |
|
1776 | - * Returns the activity manager |
|
1777 | - * |
|
1778 | - * @return \OCP\Activity\IManager |
|
1779 | - * @deprecated 20.0.0 |
|
1780 | - */ |
|
1781 | - public function getActivityManager() { |
|
1782 | - return $this->get(\OCP\Activity\IManager::class); |
|
1783 | - } |
|
1784 | - |
|
1785 | - /** |
|
1786 | - * Returns an job list for controlling background jobs |
|
1787 | - * |
|
1788 | - * @return IJobList |
|
1789 | - * @deprecated 20.0.0 |
|
1790 | - */ |
|
1791 | - public function getJobList() { |
|
1792 | - return $this->get(IJobList::class); |
|
1793 | - } |
|
1794 | - |
|
1795 | - /** |
|
1796 | - * Returns a logger instance |
|
1797 | - * |
|
1798 | - * @return ILogger |
|
1799 | - * @deprecated 20.0.0 |
|
1800 | - */ |
|
1801 | - public function getLogger() { |
|
1802 | - return $this->get(ILogger::class); |
|
1803 | - } |
|
1804 | - |
|
1805 | - /** |
|
1806 | - * @return ILogFactory |
|
1807 | - * @throws \OCP\AppFramework\QueryException |
|
1808 | - * @deprecated 20.0.0 |
|
1809 | - */ |
|
1810 | - public function getLogFactory() { |
|
1811 | - return $this->get(ILogFactory::class); |
|
1812 | - } |
|
1813 | - |
|
1814 | - /** |
|
1815 | - * Returns a router for generating and matching urls |
|
1816 | - * |
|
1817 | - * @return IRouter |
|
1818 | - * @deprecated 20.0.0 |
|
1819 | - */ |
|
1820 | - public function getRouter() { |
|
1821 | - return $this->get(IRouter::class); |
|
1822 | - } |
|
1823 | - |
|
1824 | - /** |
|
1825 | - * Returns a search instance |
|
1826 | - * |
|
1827 | - * @return ISearch |
|
1828 | - * @deprecated 20.0.0 |
|
1829 | - */ |
|
1830 | - public function getSearch() { |
|
1831 | - return $this->get(ISearch::class); |
|
1832 | - } |
|
1833 | - |
|
1834 | - /** |
|
1835 | - * Returns a SecureRandom instance |
|
1836 | - * |
|
1837 | - * @return \OCP\Security\ISecureRandom |
|
1838 | - * @deprecated 20.0.0 |
|
1839 | - */ |
|
1840 | - public function getSecureRandom() { |
|
1841 | - return $this->get(ISecureRandom::class); |
|
1842 | - } |
|
1843 | - |
|
1844 | - /** |
|
1845 | - * Returns a Crypto instance |
|
1846 | - * |
|
1847 | - * @return ICrypto |
|
1848 | - * @deprecated 20.0.0 |
|
1849 | - */ |
|
1850 | - public function getCrypto() { |
|
1851 | - return $this->get(ICrypto::class); |
|
1852 | - } |
|
1853 | - |
|
1854 | - /** |
|
1855 | - * Returns a Hasher instance |
|
1856 | - * |
|
1857 | - * @return IHasher |
|
1858 | - * @deprecated 20.0.0 |
|
1859 | - */ |
|
1860 | - public function getHasher() { |
|
1861 | - return $this->get(IHasher::class); |
|
1862 | - } |
|
1863 | - |
|
1864 | - /** |
|
1865 | - * Returns a CredentialsManager instance |
|
1866 | - * |
|
1867 | - * @return ICredentialsManager |
|
1868 | - * @deprecated 20.0.0 |
|
1869 | - */ |
|
1870 | - public function getCredentialsManager() { |
|
1871 | - return $this->get(ICredentialsManager::class); |
|
1872 | - } |
|
1873 | - |
|
1874 | - /** |
|
1875 | - * Get the certificate manager |
|
1876 | - * |
|
1877 | - * @return \OCP\ICertificateManager |
|
1878 | - */ |
|
1879 | - public function getCertificateManager() { |
|
1880 | - return $this->get(ICertificateManager::class); |
|
1881 | - } |
|
1882 | - |
|
1883 | - /** |
|
1884 | - * Returns an instance of the HTTP client service |
|
1885 | - * |
|
1886 | - * @return IClientService |
|
1887 | - * @deprecated 20.0.0 |
|
1888 | - */ |
|
1889 | - public function getHTTPClientService() { |
|
1890 | - return $this->get(IClientService::class); |
|
1891 | - } |
|
1892 | - |
|
1893 | - /** |
|
1894 | - * Create a new event source |
|
1895 | - * |
|
1896 | - * @return \OCP\IEventSource |
|
1897 | - * @deprecated 20.0.0 |
|
1898 | - */ |
|
1899 | - public function createEventSource() { |
|
1900 | - return new \OC_EventSource(); |
|
1901 | - } |
|
1902 | - |
|
1903 | - /** |
|
1904 | - * Get the active event logger |
|
1905 | - * |
|
1906 | - * The returned logger only logs data when debug mode is enabled |
|
1907 | - * |
|
1908 | - * @return IEventLogger |
|
1909 | - * @deprecated 20.0.0 |
|
1910 | - */ |
|
1911 | - public function getEventLogger() { |
|
1912 | - return $this->get(IEventLogger::class); |
|
1913 | - } |
|
1914 | - |
|
1915 | - /** |
|
1916 | - * Get the active query logger |
|
1917 | - * |
|
1918 | - * The returned logger only logs data when debug mode is enabled |
|
1919 | - * |
|
1920 | - * @return IQueryLogger |
|
1921 | - * @deprecated 20.0.0 |
|
1922 | - */ |
|
1923 | - public function getQueryLogger() { |
|
1924 | - return $this->get(IQueryLogger::class); |
|
1925 | - } |
|
1926 | - |
|
1927 | - /** |
|
1928 | - * Get the manager for temporary files and folders |
|
1929 | - * |
|
1930 | - * @return \OCP\ITempManager |
|
1931 | - * @deprecated 20.0.0 |
|
1932 | - */ |
|
1933 | - public function getTempManager() { |
|
1934 | - return $this->get(ITempManager::class); |
|
1935 | - } |
|
1936 | - |
|
1937 | - /** |
|
1938 | - * Get the app manager |
|
1939 | - * |
|
1940 | - * @return \OCP\App\IAppManager |
|
1941 | - * @deprecated 20.0.0 |
|
1942 | - */ |
|
1943 | - public function getAppManager() { |
|
1944 | - return $this->get(IAppManager::class); |
|
1945 | - } |
|
1946 | - |
|
1947 | - /** |
|
1948 | - * Creates a new mailer |
|
1949 | - * |
|
1950 | - * @return IMailer |
|
1951 | - * @deprecated 20.0.0 |
|
1952 | - */ |
|
1953 | - public function getMailer() { |
|
1954 | - return $this->get(IMailer::class); |
|
1955 | - } |
|
1956 | - |
|
1957 | - /** |
|
1958 | - * Get the webroot |
|
1959 | - * |
|
1960 | - * @return string |
|
1961 | - * @deprecated 20.0.0 |
|
1962 | - */ |
|
1963 | - public function getWebRoot() { |
|
1964 | - return $this->webRoot; |
|
1965 | - } |
|
1966 | - |
|
1967 | - /** |
|
1968 | - * @return \OC\OCSClient |
|
1969 | - * @deprecated 20.0.0 |
|
1970 | - */ |
|
1971 | - public function getOcsClient() { |
|
1972 | - return $this->get('OcsClient'); |
|
1973 | - } |
|
1974 | - |
|
1975 | - /** |
|
1976 | - * @return IDateTimeZone |
|
1977 | - * @deprecated 20.0.0 |
|
1978 | - */ |
|
1979 | - public function getDateTimeZone() { |
|
1980 | - return $this->get(IDateTimeZone::class); |
|
1981 | - } |
|
1982 | - |
|
1983 | - /** |
|
1984 | - * @return IDateTimeFormatter |
|
1985 | - * @deprecated 20.0.0 |
|
1986 | - */ |
|
1987 | - public function getDateTimeFormatter() { |
|
1988 | - return $this->get(IDateTimeFormatter::class); |
|
1989 | - } |
|
1990 | - |
|
1991 | - /** |
|
1992 | - * @return IMountProviderCollection |
|
1993 | - * @deprecated 20.0.0 |
|
1994 | - */ |
|
1995 | - public function getMountProviderCollection() { |
|
1996 | - return $this->get(IMountProviderCollection::class); |
|
1997 | - } |
|
1998 | - |
|
1999 | - /** |
|
2000 | - * Get the IniWrapper |
|
2001 | - * |
|
2002 | - * @return IniGetWrapper |
|
2003 | - * @deprecated 20.0.0 |
|
2004 | - */ |
|
2005 | - public function getIniWrapper() { |
|
2006 | - return $this->get(IniGetWrapper::class); |
|
2007 | - } |
|
2008 | - |
|
2009 | - /** |
|
2010 | - * @return \OCP\Command\IBus |
|
2011 | - * @deprecated 20.0.0 |
|
2012 | - */ |
|
2013 | - public function getCommandBus() { |
|
2014 | - return $this->get(IBus::class); |
|
2015 | - } |
|
2016 | - |
|
2017 | - /** |
|
2018 | - * Get the trusted domain helper |
|
2019 | - * |
|
2020 | - * @return TrustedDomainHelper |
|
2021 | - * @deprecated 20.0.0 |
|
2022 | - */ |
|
2023 | - public function getTrustedDomainHelper() { |
|
2024 | - return $this->get(TrustedDomainHelper::class); |
|
2025 | - } |
|
2026 | - |
|
2027 | - /** |
|
2028 | - * Get the locking provider |
|
2029 | - * |
|
2030 | - * @return ILockingProvider |
|
2031 | - * @since 8.1.0 |
|
2032 | - * @deprecated 20.0.0 |
|
2033 | - */ |
|
2034 | - public function getLockingProvider() { |
|
2035 | - return $this->get(ILockingProvider::class); |
|
2036 | - } |
|
2037 | - |
|
2038 | - /** |
|
2039 | - * @return IMountManager |
|
2040 | - * @deprecated 20.0.0 |
|
2041 | - **/ |
|
2042 | - public function getMountManager() { |
|
2043 | - return $this->get(IMountManager::class); |
|
2044 | - } |
|
2045 | - |
|
2046 | - /** |
|
2047 | - * @return IUserMountCache |
|
2048 | - * @deprecated 20.0.0 |
|
2049 | - */ |
|
2050 | - public function getUserMountCache() { |
|
2051 | - return $this->get(IUserMountCache::class); |
|
2052 | - } |
|
2053 | - |
|
2054 | - /** |
|
2055 | - * Get the MimeTypeDetector |
|
2056 | - * |
|
2057 | - * @return IMimeTypeDetector |
|
2058 | - * @deprecated 20.0.0 |
|
2059 | - */ |
|
2060 | - public function getMimeTypeDetector() { |
|
2061 | - return $this->get(IMimeTypeDetector::class); |
|
2062 | - } |
|
2063 | - |
|
2064 | - /** |
|
2065 | - * Get the MimeTypeLoader |
|
2066 | - * |
|
2067 | - * @return IMimeTypeLoader |
|
2068 | - * @deprecated 20.0.0 |
|
2069 | - */ |
|
2070 | - public function getMimeTypeLoader() { |
|
2071 | - return $this->get(IMimeTypeLoader::class); |
|
2072 | - } |
|
2073 | - |
|
2074 | - /** |
|
2075 | - * Get the manager of all the capabilities |
|
2076 | - * |
|
2077 | - * @return CapabilitiesManager |
|
2078 | - * @deprecated 20.0.0 |
|
2079 | - */ |
|
2080 | - public function getCapabilitiesManager() { |
|
2081 | - return $this->get(CapabilitiesManager::class); |
|
2082 | - } |
|
2083 | - |
|
2084 | - /** |
|
2085 | - * Get the EventDispatcher |
|
2086 | - * |
|
2087 | - * @return EventDispatcherInterface |
|
2088 | - * @since 8.2.0 |
|
2089 | - * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2090 | - */ |
|
2091 | - public function getEventDispatcher() { |
|
2092 | - return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2093 | - } |
|
2094 | - |
|
2095 | - /** |
|
2096 | - * Get the Notification Manager |
|
2097 | - * |
|
2098 | - * @return \OCP\Notification\IManager |
|
2099 | - * @since 8.2.0 |
|
2100 | - * @deprecated 20.0.0 |
|
2101 | - */ |
|
2102 | - public function getNotificationManager() { |
|
2103 | - return $this->get(\OCP\Notification\IManager::class); |
|
2104 | - } |
|
2105 | - |
|
2106 | - /** |
|
2107 | - * @return ICommentsManager |
|
2108 | - * @deprecated 20.0.0 |
|
2109 | - */ |
|
2110 | - public function getCommentsManager() { |
|
2111 | - return $this->get(ICommentsManager::class); |
|
2112 | - } |
|
2113 | - |
|
2114 | - /** |
|
2115 | - * @return \OCA\Theming\ThemingDefaults |
|
2116 | - * @deprecated 20.0.0 |
|
2117 | - */ |
|
2118 | - public function getThemingDefaults() { |
|
2119 | - return $this->get('ThemingDefaults'); |
|
2120 | - } |
|
2121 | - |
|
2122 | - /** |
|
2123 | - * @return \OC\IntegrityCheck\Checker |
|
2124 | - * @deprecated 20.0.0 |
|
2125 | - */ |
|
2126 | - public function getIntegrityCodeChecker() { |
|
2127 | - return $this->get('IntegrityCodeChecker'); |
|
2128 | - } |
|
2129 | - |
|
2130 | - /** |
|
2131 | - * @return \OC\Session\CryptoWrapper |
|
2132 | - * @deprecated 20.0.0 |
|
2133 | - */ |
|
2134 | - public function getSessionCryptoWrapper() { |
|
2135 | - return $this->get('CryptoWrapper'); |
|
2136 | - } |
|
2137 | - |
|
2138 | - /** |
|
2139 | - * @return CsrfTokenManager |
|
2140 | - * @deprecated 20.0.0 |
|
2141 | - */ |
|
2142 | - public function getCsrfTokenManager() { |
|
2143 | - return $this->get(CsrfTokenManager::class); |
|
2144 | - } |
|
2145 | - |
|
2146 | - /** |
|
2147 | - * @return Throttler |
|
2148 | - * @deprecated 20.0.0 |
|
2149 | - */ |
|
2150 | - public function getBruteForceThrottler() { |
|
2151 | - return $this->get(Throttler::class); |
|
2152 | - } |
|
2153 | - |
|
2154 | - /** |
|
2155 | - * @return IContentSecurityPolicyManager |
|
2156 | - * @deprecated 20.0.0 |
|
2157 | - */ |
|
2158 | - public function getContentSecurityPolicyManager() { |
|
2159 | - return $this->get(ContentSecurityPolicyManager::class); |
|
2160 | - } |
|
2161 | - |
|
2162 | - /** |
|
2163 | - * @return ContentSecurityPolicyNonceManager |
|
2164 | - * @deprecated 20.0.0 |
|
2165 | - */ |
|
2166 | - public function getContentSecurityPolicyNonceManager() { |
|
2167 | - return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2168 | - } |
|
2169 | - |
|
2170 | - /** |
|
2171 | - * Not a public API as of 8.2, wait for 9.0 |
|
2172 | - * |
|
2173 | - * @return \OCA\Files_External\Service\BackendService |
|
2174 | - * @deprecated 20.0.0 |
|
2175 | - */ |
|
2176 | - public function getStoragesBackendService() { |
|
2177 | - return $this->get(BackendService::class); |
|
2178 | - } |
|
2179 | - |
|
2180 | - /** |
|
2181 | - * Not a public API as of 8.2, wait for 9.0 |
|
2182 | - * |
|
2183 | - * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2184 | - * @deprecated 20.0.0 |
|
2185 | - */ |
|
2186 | - public function getGlobalStoragesService() { |
|
2187 | - return $this->get(GlobalStoragesService::class); |
|
2188 | - } |
|
2189 | - |
|
2190 | - /** |
|
2191 | - * Not a public API as of 8.2, wait for 9.0 |
|
2192 | - * |
|
2193 | - * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2194 | - * @deprecated 20.0.0 |
|
2195 | - */ |
|
2196 | - public function getUserGlobalStoragesService() { |
|
2197 | - return $this->get(UserGlobalStoragesService::class); |
|
2198 | - } |
|
2199 | - |
|
2200 | - /** |
|
2201 | - * Not a public API as of 8.2, wait for 9.0 |
|
2202 | - * |
|
2203 | - * @return \OCA\Files_External\Service\UserStoragesService |
|
2204 | - * @deprecated 20.0.0 |
|
2205 | - */ |
|
2206 | - public function getUserStoragesService() { |
|
2207 | - return $this->get(UserStoragesService::class); |
|
2208 | - } |
|
2209 | - |
|
2210 | - /** |
|
2211 | - * @return \OCP\Share\IManager |
|
2212 | - * @deprecated 20.0.0 |
|
2213 | - */ |
|
2214 | - public function getShareManager() { |
|
2215 | - return $this->get(\OCP\Share\IManager::class); |
|
2216 | - } |
|
2217 | - |
|
2218 | - /** |
|
2219 | - * @return \OCP\Collaboration\Collaborators\ISearch |
|
2220 | - * @deprecated 20.0.0 |
|
2221 | - */ |
|
2222 | - public function getCollaboratorSearch() { |
|
2223 | - return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2224 | - } |
|
2225 | - |
|
2226 | - /** |
|
2227 | - * @return \OCP\Collaboration\AutoComplete\IManager |
|
2228 | - * @deprecated 20.0.0 |
|
2229 | - */ |
|
2230 | - public function getAutoCompleteManager() { |
|
2231 | - return $this->get(IManager::class); |
|
2232 | - } |
|
2233 | - |
|
2234 | - /** |
|
2235 | - * Returns the LDAP Provider |
|
2236 | - * |
|
2237 | - * @return \OCP\LDAP\ILDAPProvider |
|
2238 | - * @deprecated 20.0.0 |
|
2239 | - */ |
|
2240 | - public function getLDAPProvider() { |
|
2241 | - return $this->get('LDAPProvider'); |
|
2242 | - } |
|
2243 | - |
|
2244 | - /** |
|
2245 | - * @return \OCP\Settings\IManager |
|
2246 | - * @deprecated 20.0.0 |
|
2247 | - */ |
|
2248 | - public function getSettingsManager() { |
|
2249 | - return $this->get(\OC\Settings\Manager::class); |
|
2250 | - } |
|
2251 | - |
|
2252 | - /** |
|
2253 | - * @return \OCP\Files\IAppData |
|
2254 | - * @deprecated 20.0.0 |
|
2255 | - */ |
|
2256 | - public function getAppDataDir($app) { |
|
2257 | - /** @var \OC\Files\AppData\Factory $factory */ |
|
2258 | - $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2259 | - return $factory->get($app); |
|
2260 | - } |
|
2261 | - |
|
2262 | - /** |
|
2263 | - * @return \OCP\Lockdown\ILockdownManager |
|
2264 | - * @deprecated 20.0.0 |
|
2265 | - */ |
|
2266 | - public function getLockdownManager() { |
|
2267 | - return $this->get('LockdownManager'); |
|
2268 | - } |
|
2269 | - |
|
2270 | - /** |
|
2271 | - * @return \OCP\Federation\ICloudIdManager |
|
2272 | - * @deprecated 20.0.0 |
|
2273 | - */ |
|
2274 | - public function getCloudIdManager() { |
|
2275 | - return $this->get(ICloudIdManager::class); |
|
2276 | - } |
|
2277 | - |
|
2278 | - /** |
|
2279 | - * @return \OCP\GlobalScale\IConfig |
|
2280 | - * @deprecated 20.0.0 |
|
2281 | - */ |
|
2282 | - public function getGlobalScaleConfig() { |
|
2283 | - return $this->get(IConfig::class); |
|
2284 | - } |
|
2285 | - |
|
2286 | - /** |
|
2287 | - * @return \OCP\Federation\ICloudFederationProviderManager |
|
2288 | - * @deprecated 20.0.0 |
|
2289 | - */ |
|
2290 | - public function getCloudFederationProviderManager() { |
|
2291 | - return $this->get(ICloudFederationProviderManager::class); |
|
2292 | - } |
|
2293 | - |
|
2294 | - /** |
|
2295 | - * @return \OCP\Remote\Api\IApiFactory |
|
2296 | - * @deprecated 20.0.0 |
|
2297 | - */ |
|
2298 | - public function getRemoteApiFactory() { |
|
2299 | - return $this->get(IApiFactory::class); |
|
2300 | - } |
|
2301 | - |
|
2302 | - /** |
|
2303 | - * @return \OCP\Federation\ICloudFederationFactory |
|
2304 | - * @deprecated 20.0.0 |
|
2305 | - */ |
|
2306 | - public function getCloudFederationFactory() { |
|
2307 | - return $this->get(ICloudFederationFactory::class); |
|
2308 | - } |
|
2309 | - |
|
2310 | - /** |
|
2311 | - * @return \OCP\Remote\IInstanceFactory |
|
2312 | - * @deprecated 20.0.0 |
|
2313 | - */ |
|
2314 | - public function getRemoteInstanceFactory() { |
|
2315 | - return $this->get(IInstanceFactory::class); |
|
2316 | - } |
|
2317 | - |
|
2318 | - /** |
|
2319 | - * @return IStorageFactory |
|
2320 | - * @deprecated 20.0.0 |
|
2321 | - */ |
|
2322 | - public function getStorageFactory() { |
|
2323 | - return $this->get(IStorageFactory::class); |
|
2324 | - } |
|
2325 | - |
|
2326 | - /** |
|
2327 | - * Get the Preview GeneratorHelper |
|
2328 | - * |
|
2329 | - * @return GeneratorHelper |
|
2330 | - * @since 17.0.0 |
|
2331 | - * @deprecated 20.0.0 |
|
2332 | - */ |
|
2333 | - public function getGeneratorHelper() { |
|
2334 | - return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2335 | - } |
|
2336 | - |
|
2337 | - private function registerDeprecatedAlias(string $alias, string $target) { |
|
2338 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2339 | - try { |
|
2340 | - /** @var ILogger $logger */ |
|
2341 | - $logger = $container->get(ILogger::class); |
|
2342 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2343 | - } catch (ContainerExceptionInterface $e) { |
|
2344 | - // Could not get logger. Continue |
|
2345 | - } |
|
2346 | - |
|
2347 | - return $container->get($target); |
|
2348 | - }, false); |
|
2349 | - } |
|
1162 | + $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
|
1163 | + if (isset($prefixes['OCA\\Theming\\'])) { |
|
1164 | + $classExists = true; |
|
1165 | + } else { |
|
1166 | + $classExists = false; |
|
1167 | + } |
|
1168 | + |
|
1169 | + if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
|
1170 | + return new ThemingDefaults( |
|
1171 | + $c->get(\OCP\IConfig::class), |
|
1172 | + $c->getL10N('theming'), |
|
1173 | + $c->get(IURLGenerator::class), |
|
1174 | + $c->get(ICacheFactory::class), |
|
1175 | + new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')), |
|
1176 | + new ImageManager( |
|
1177 | + $c->get(\OCP\IConfig::class), |
|
1178 | + $c->getAppDataDir('theming'), |
|
1179 | + $c->get(IURLGenerator::class), |
|
1180 | + $this->get(ICacheFactory::class), |
|
1181 | + $this->get(ILogger::class), |
|
1182 | + $this->get(ITempManager::class) |
|
1183 | + ), |
|
1184 | + $c->get(IAppManager::class), |
|
1185 | + $c->get(INavigationManager::class) |
|
1186 | + ); |
|
1187 | + } |
|
1188 | + return new \OC_Defaults(); |
|
1189 | + }); |
|
1190 | + $this->registerService(JSCombiner::class, function (Server $c) { |
|
1191 | + return new JSCombiner( |
|
1192 | + $c->getAppDataDir('js'), |
|
1193 | + $c->get(IURLGenerator::class), |
|
1194 | + $this->get(ICacheFactory::class), |
|
1195 | + $c->get(SystemConfig::class), |
|
1196 | + $c->get(ILogger::class) |
|
1197 | + ); |
|
1198 | + }); |
|
1199 | + $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class); |
|
1200 | + /** @deprecated 19.0.0 */ |
|
1201 | + $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
|
1202 | + $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
|
1203 | + |
|
1204 | + $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1205 | + // FIXME: Instantiiated here due to cyclic dependency |
|
1206 | + $request = new Request( |
|
1207 | + [ |
|
1208 | + 'get' => $_GET, |
|
1209 | + 'post' => $_POST, |
|
1210 | + 'files' => $_FILES, |
|
1211 | + 'server' => $_SERVER, |
|
1212 | + 'env' => $_ENV, |
|
1213 | + 'cookies' => $_COOKIE, |
|
1214 | + 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
|
1215 | + ? $_SERVER['REQUEST_METHOD'] |
|
1216 | + : null, |
|
1217 | + ], |
|
1218 | + $c->get(ISecureRandom::class), |
|
1219 | + $c->get(\OCP\IConfig::class) |
|
1220 | + ); |
|
1221 | + |
|
1222 | + return new CryptoWrapper( |
|
1223 | + $c->get(\OCP\IConfig::class), |
|
1224 | + $c->get(ICrypto::class), |
|
1225 | + $c->get(ISecureRandom::class), |
|
1226 | + $request |
|
1227 | + ); |
|
1228 | + }); |
|
1229 | + /** @deprecated 19.0.0 */ |
|
1230 | + $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
|
1231 | + $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1232 | + return new SessionStorage($c->get(ISession::class)); |
|
1233 | + }); |
|
1234 | + $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
|
1235 | + /** @deprecated 19.0.0 */ |
|
1236 | + $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
|
1237 | + |
|
1238 | + $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1239 | + $config = $c->get(\OCP\IConfig::class); |
|
1240 | + $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
|
1241 | + /** @var \OCP\Share\IProviderFactory $factory */ |
|
1242 | + $factory = new $factoryClass($this); |
|
1243 | + |
|
1244 | + $manager = new \OC\Share20\Manager( |
|
1245 | + $c->get(ILogger::class), |
|
1246 | + $c->get(\OCP\IConfig::class), |
|
1247 | + $c->get(ISecureRandom::class), |
|
1248 | + $c->get(IHasher::class), |
|
1249 | + $c->get(IMountManager::class), |
|
1250 | + $c->get(IGroupManager::class), |
|
1251 | + $c->getL10N('lib'), |
|
1252 | + $c->get(IFactory::class), |
|
1253 | + $factory, |
|
1254 | + $c->get(IUserManager::class), |
|
1255 | + $c->get(IRootFolder::class), |
|
1256 | + $c->get(SymfonyAdapter::class), |
|
1257 | + $c->get(IMailer::class), |
|
1258 | + $c->get(IURLGenerator::class), |
|
1259 | + $c->get('ThemingDefaults'), |
|
1260 | + $c->get(IEventDispatcher::class), |
|
1261 | + $c->get(IUserSession::class), |
|
1262 | + $c->get(KnownUserService::class) |
|
1263 | + ); |
|
1264 | + |
|
1265 | + return $manager; |
|
1266 | + }); |
|
1267 | + /** @deprecated 19.0.0 */ |
|
1268 | + $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
|
1269 | + |
|
1270 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1271 | + $instance = new Collaboration\Collaborators\Search($c); |
|
1272 | + |
|
1273 | + // register default plugins |
|
1274 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
|
1275 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
|
1276 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
|
1277 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
|
1278 | + $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]); |
|
1279 | + |
|
1280 | + return $instance; |
|
1281 | + }); |
|
1282 | + /** @deprecated 19.0.0 */ |
|
1283 | + $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
|
1284 | + $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class); |
|
1285 | + |
|
1286 | + $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
|
1287 | + |
|
1288 | + $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class); |
|
1289 | + $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class); |
|
1290 | + |
|
1291 | + $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
|
1292 | + $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
|
1293 | + $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1294 | + return new \OC\Files\AppData\Factory( |
|
1295 | + $c->get(IRootFolder::class), |
|
1296 | + $c->get(SystemConfig::class) |
|
1297 | + ); |
|
1298 | + }); |
|
1299 | + |
|
1300 | + $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1301 | + return new LockdownManager(function () use ($c) { |
|
1302 | + return $c->get(ISession::class); |
|
1303 | + }); |
|
1304 | + }); |
|
1305 | + |
|
1306 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1307 | + return new DiscoveryService( |
|
1308 | + $c->get(ICacheFactory::class), |
|
1309 | + $c->get(IClientService::class) |
|
1310 | + ); |
|
1311 | + }); |
|
1312 | + |
|
1313 | + $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1314 | + return new CloudIdManager($c->get(\OCP\Contacts\IManager::class), $c->get(IURLGenerator::class), $c->get(IUserManager::class)); |
|
1315 | + }); |
|
1316 | + |
|
1317 | + $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
|
1318 | + |
|
1319 | + $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1320 | + return new CloudFederationProviderManager( |
|
1321 | + $c->get(IAppManager::class), |
|
1322 | + $c->get(IClientService::class), |
|
1323 | + $c->get(ICloudIdManager::class), |
|
1324 | + $c->get(ILogger::class) |
|
1325 | + ); |
|
1326 | + }); |
|
1327 | + |
|
1328 | + $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1329 | + return new CloudFederationFactory(); |
|
1330 | + }); |
|
1331 | + |
|
1332 | + $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
|
1333 | + /** @deprecated 19.0.0 */ |
|
1334 | + $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
|
1335 | + |
|
1336 | + $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
|
1337 | + /** @deprecated 19.0.0 */ |
|
1338 | + $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
|
1339 | + |
|
1340 | + $this->registerService(Defaults::class, function (Server $c) { |
|
1341 | + return new Defaults( |
|
1342 | + $c->getThemingDefaults() |
|
1343 | + ); |
|
1344 | + }); |
|
1345 | + /** @deprecated 19.0.0 */ |
|
1346 | + $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
|
1347 | + |
|
1348 | + $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1349 | + return $c->get(\OCP\IUserSession::class)->getSession(); |
|
1350 | + }, false); |
|
1351 | + |
|
1352 | + $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1353 | + return new ShareHelper( |
|
1354 | + $c->get(\OCP\Share\IManager::class) |
|
1355 | + ); |
|
1356 | + }); |
|
1357 | + |
|
1358 | + $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1359 | + return new Installer( |
|
1360 | + $c->get(AppFetcher::class), |
|
1361 | + $c->get(IClientService::class), |
|
1362 | + $c->get(ITempManager::class), |
|
1363 | + $c->get(LoggerInterface::class), |
|
1364 | + $c->get(\OCP\IConfig::class), |
|
1365 | + \OC::$CLI |
|
1366 | + ); |
|
1367 | + }); |
|
1368 | + |
|
1369 | + $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1370 | + return new ApiFactory($c->get(IClientService::class)); |
|
1371 | + }); |
|
1372 | + |
|
1373 | + $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1374 | + $memcacheFactory = $c->get(ICacheFactory::class); |
|
1375 | + return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
|
1376 | + }); |
|
1377 | + |
|
1378 | + $this->registerAlias(IContactsStore::class, ContactsStore::class); |
|
1379 | + $this->registerAlias(IAccountManager::class, AccountManager::class); |
|
1380 | + |
|
1381 | + $this->registerAlias(IStorageFactory::class, StorageFactory::class); |
|
1382 | + |
|
1383 | + $this->registerAlias(IDashboardManager::class, DashboardManager::class); |
|
1384 | + $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class); |
|
1385 | + $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class); |
|
1386 | + |
|
1387 | + $this->registerAlias(ISubAdmin::class, SubAdmin::class); |
|
1388 | + |
|
1389 | + $this->registerAlias(IInitialStateService::class, InitialStateService::class); |
|
1390 | + |
|
1391 | + $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class); |
|
1392 | + |
|
1393 | + $this->connectDispatcher(); |
|
1394 | + } |
|
1395 | + |
|
1396 | + public function boot() { |
|
1397 | + /** @var HookConnector $hookConnector */ |
|
1398 | + $hookConnector = $this->get(HookConnector::class); |
|
1399 | + $hookConnector->viewToNode(); |
|
1400 | + } |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * @return \OCP\Calendar\IManager |
|
1404 | + * @deprecated 20.0.0 |
|
1405 | + */ |
|
1406 | + public function getCalendarManager() { |
|
1407 | + return $this->get(\OC\Calendar\Manager::class); |
|
1408 | + } |
|
1409 | + |
|
1410 | + /** |
|
1411 | + * @return \OCP\Calendar\Resource\IManager |
|
1412 | + * @deprecated 20.0.0 |
|
1413 | + */ |
|
1414 | + public function getCalendarResourceBackendManager() { |
|
1415 | + return $this->get(\OC\Calendar\Resource\Manager::class); |
|
1416 | + } |
|
1417 | + |
|
1418 | + /** |
|
1419 | + * @return \OCP\Calendar\Room\IManager |
|
1420 | + * @deprecated 20.0.0 |
|
1421 | + */ |
|
1422 | + public function getCalendarRoomBackendManager() { |
|
1423 | + return $this->get(\OC\Calendar\Room\Manager::class); |
|
1424 | + } |
|
1425 | + |
|
1426 | + private function connectDispatcher() { |
|
1427 | + $dispatcher = $this->get(SymfonyAdapter::class); |
|
1428 | + |
|
1429 | + // Delete avatar on user deletion |
|
1430 | + $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1431 | + $logger = $this->get(ILogger::class); |
|
1432 | + $manager = $this->getAvatarManager(); |
|
1433 | + /** @var IUser $user */ |
|
1434 | + $user = $e->getSubject(); |
|
1435 | + |
|
1436 | + try { |
|
1437 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1438 | + $avatar->remove(); |
|
1439 | + } catch (NotFoundException $e) { |
|
1440 | + // no avatar to remove |
|
1441 | + } catch (\Exception $e) { |
|
1442 | + // Ignore exceptions |
|
1443 | + $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1444 | + } |
|
1445 | + }); |
|
1446 | + |
|
1447 | + $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1448 | + $manager = $this->getAvatarManager(); |
|
1449 | + /** @var IUser $user */ |
|
1450 | + $user = $e->getSubject(); |
|
1451 | + $feature = $e->getArgument('feature'); |
|
1452 | + $oldValue = $e->getArgument('oldValue'); |
|
1453 | + $value = $e->getArgument('value'); |
|
1454 | + |
|
1455 | + // We only change the avatar on display name changes |
|
1456 | + if ($feature !== 'displayName') { |
|
1457 | + return; |
|
1458 | + } |
|
1459 | + |
|
1460 | + try { |
|
1461 | + $avatar = $manager->getAvatar($user->getUID()); |
|
1462 | + $avatar->userChanged($feature, $oldValue, $value); |
|
1463 | + } catch (NotFoundException $e) { |
|
1464 | + // no avatar to remove |
|
1465 | + } |
|
1466 | + }); |
|
1467 | + |
|
1468 | + /** @var IEventDispatcher $eventDispatched */ |
|
1469 | + $eventDispatched = $this->get(IEventDispatcher::class); |
|
1470 | + $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class); |
|
1471 | + $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class); |
|
1472 | + } |
|
1473 | + |
|
1474 | + /** |
|
1475 | + * @return \OCP\Contacts\IManager |
|
1476 | + * @deprecated 20.0.0 |
|
1477 | + */ |
|
1478 | + public function getContactsManager() { |
|
1479 | + return $this->get(\OCP\Contacts\IManager::class); |
|
1480 | + } |
|
1481 | + |
|
1482 | + /** |
|
1483 | + * @return \OC\Encryption\Manager |
|
1484 | + * @deprecated 20.0.0 |
|
1485 | + */ |
|
1486 | + public function getEncryptionManager() { |
|
1487 | + return $this->get(\OCP\Encryption\IManager::class); |
|
1488 | + } |
|
1489 | + |
|
1490 | + /** |
|
1491 | + * @return \OC\Encryption\File |
|
1492 | + * @deprecated 20.0.0 |
|
1493 | + */ |
|
1494 | + public function getEncryptionFilesHelper() { |
|
1495 | + return $this->get(IFile::class); |
|
1496 | + } |
|
1497 | + |
|
1498 | + /** |
|
1499 | + * @return \OCP\Encryption\Keys\IStorage |
|
1500 | + * @deprecated 20.0.0 |
|
1501 | + */ |
|
1502 | + public function getEncryptionKeyStorage() { |
|
1503 | + return $this->get(IStorage::class); |
|
1504 | + } |
|
1505 | + |
|
1506 | + /** |
|
1507 | + * The current request object holding all information about the request |
|
1508 | + * currently being processed is returned from this method. |
|
1509 | + * In case the current execution was not initiated by a web request null is returned |
|
1510 | + * |
|
1511 | + * @return \OCP\IRequest |
|
1512 | + * @deprecated 20.0.0 |
|
1513 | + */ |
|
1514 | + public function getRequest() { |
|
1515 | + return $this->get(IRequest::class); |
|
1516 | + } |
|
1517 | + |
|
1518 | + /** |
|
1519 | + * Returns the preview manager which can create preview images for a given file |
|
1520 | + * |
|
1521 | + * @return IPreview |
|
1522 | + * @deprecated 20.0.0 |
|
1523 | + */ |
|
1524 | + public function getPreviewManager() { |
|
1525 | + return $this->get(IPreview::class); |
|
1526 | + } |
|
1527 | + |
|
1528 | + /** |
|
1529 | + * Returns the tag manager which can get and set tags for different object types |
|
1530 | + * |
|
1531 | + * @see \OCP\ITagManager::load() |
|
1532 | + * @return ITagManager |
|
1533 | + * @deprecated 20.0.0 |
|
1534 | + */ |
|
1535 | + public function getTagManager() { |
|
1536 | + return $this->get(ITagManager::class); |
|
1537 | + } |
|
1538 | + |
|
1539 | + /** |
|
1540 | + * Returns the system-tag manager |
|
1541 | + * |
|
1542 | + * @return ISystemTagManager |
|
1543 | + * |
|
1544 | + * @since 9.0.0 |
|
1545 | + * @deprecated 20.0.0 |
|
1546 | + */ |
|
1547 | + public function getSystemTagManager() { |
|
1548 | + return $this->get(ISystemTagManager::class); |
|
1549 | + } |
|
1550 | + |
|
1551 | + /** |
|
1552 | + * Returns the system-tag object mapper |
|
1553 | + * |
|
1554 | + * @return ISystemTagObjectMapper |
|
1555 | + * |
|
1556 | + * @since 9.0.0 |
|
1557 | + * @deprecated 20.0.0 |
|
1558 | + */ |
|
1559 | + public function getSystemTagObjectMapper() { |
|
1560 | + return $this->get(ISystemTagObjectMapper::class); |
|
1561 | + } |
|
1562 | + |
|
1563 | + /** |
|
1564 | + * Returns the avatar manager, used for avatar functionality |
|
1565 | + * |
|
1566 | + * @return IAvatarManager |
|
1567 | + * @deprecated 20.0.0 |
|
1568 | + */ |
|
1569 | + public function getAvatarManager() { |
|
1570 | + return $this->get(IAvatarManager::class); |
|
1571 | + } |
|
1572 | + |
|
1573 | + /** |
|
1574 | + * Returns the root folder of ownCloud's data directory |
|
1575 | + * |
|
1576 | + * @return IRootFolder |
|
1577 | + * @deprecated 20.0.0 |
|
1578 | + */ |
|
1579 | + public function getRootFolder() { |
|
1580 | + return $this->get(IRootFolder::class); |
|
1581 | + } |
|
1582 | + |
|
1583 | + /** |
|
1584 | + * Returns the root folder of ownCloud's data directory |
|
1585 | + * This is the lazy variant so this gets only initialized once it |
|
1586 | + * is actually used. |
|
1587 | + * |
|
1588 | + * @return IRootFolder |
|
1589 | + * @deprecated 20.0.0 |
|
1590 | + */ |
|
1591 | + public function getLazyRootFolder() { |
|
1592 | + return $this->get(IRootFolder::class); |
|
1593 | + } |
|
1594 | + |
|
1595 | + /** |
|
1596 | + * Returns a view to ownCloud's files folder |
|
1597 | + * |
|
1598 | + * @param string $userId user ID |
|
1599 | + * @return \OCP\Files\Folder|null |
|
1600 | + * @deprecated 20.0.0 |
|
1601 | + */ |
|
1602 | + public function getUserFolder($userId = null) { |
|
1603 | + if ($userId === null) { |
|
1604 | + $user = $this->get(IUserSession::class)->getUser(); |
|
1605 | + if (!$user) { |
|
1606 | + return null; |
|
1607 | + } |
|
1608 | + $userId = $user->getUID(); |
|
1609 | + } |
|
1610 | + $root = $this->get(IRootFolder::class); |
|
1611 | + return $root->getUserFolder($userId); |
|
1612 | + } |
|
1613 | + |
|
1614 | + /** |
|
1615 | + * @return \OC\User\Manager |
|
1616 | + * @deprecated 20.0.0 |
|
1617 | + */ |
|
1618 | + public function getUserManager() { |
|
1619 | + return $this->get(IUserManager::class); |
|
1620 | + } |
|
1621 | + |
|
1622 | + /** |
|
1623 | + * @return \OC\Group\Manager |
|
1624 | + * @deprecated 20.0.0 |
|
1625 | + */ |
|
1626 | + public function getGroupManager() { |
|
1627 | + return $this->get(IGroupManager::class); |
|
1628 | + } |
|
1629 | + |
|
1630 | + /** |
|
1631 | + * @return \OC\User\Session |
|
1632 | + * @deprecated 20.0.0 |
|
1633 | + */ |
|
1634 | + public function getUserSession() { |
|
1635 | + return $this->get(IUserSession::class); |
|
1636 | + } |
|
1637 | + |
|
1638 | + /** |
|
1639 | + * @return \OCP\ISession |
|
1640 | + * @deprecated 20.0.0 |
|
1641 | + */ |
|
1642 | + public function getSession() { |
|
1643 | + return $this->get(IUserSession::class)->getSession(); |
|
1644 | + } |
|
1645 | + |
|
1646 | + /** |
|
1647 | + * @param \OCP\ISession $session |
|
1648 | + */ |
|
1649 | + public function setSession(\OCP\ISession $session) { |
|
1650 | + $this->get(SessionStorage::class)->setSession($session); |
|
1651 | + $this->get(IUserSession::class)->setSession($session); |
|
1652 | + $this->get(Store::class)->setSession($session); |
|
1653 | + } |
|
1654 | + |
|
1655 | + /** |
|
1656 | + * @return \OC\Authentication\TwoFactorAuth\Manager |
|
1657 | + * @deprecated 20.0.0 |
|
1658 | + */ |
|
1659 | + public function getTwoFactorAuthManager() { |
|
1660 | + return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class); |
|
1661 | + } |
|
1662 | + |
|
1663 | + /** |
|
1664 | + * @return \OC\NavigationManager |
|
1665 | + * @deprecated 20.0.0 |
|
1666 | + */ |
|
1667 | + public function getNavigationManager() { |
|
1668 | + return $this->get(INavigationManager::class); |
|
1669 | + } |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * @return \OCP\IConfig |
|
1673 | + * @deprecated 20.0.0 |
|
1674 | + */ |
|
1675 | + public function getConfig() { |
|
1676 | + return $this->get(AllConfig::class); |
|
1677 | + } |
|
1678 | + |
|
1679 | + /** |
|
1680 | + * @return \OC\SystemConfig |
|
1681 | + * @deprecated 20.0.0 |
|
1682 | + */ |
|
1683 | + public function getSystemConfig() { |
|
1684 | + return $this->get(SystemConfig::class); |
|
1685 | + } |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * Returns the app config manager |
|
1689 | + * |
|
1690 | + * @return IAppConfig |
|
1691 | + * @deprecated 20.0.0 |
|
1692 | + */ |
|
1693 | + public function getAppConfig() { |
|
1694 | + return $this->get(IAppConfig::class); |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * @return IFactory |
|
1699 | + * @deprecated 20.0.0 |
|
1700 | + */ |
|
1701 | + public function getL10NFactory() { |
|
1702 | + return $this->get(IFactory::class); |
|
1703 | + } |
|
1704 | + |
|
1705 | + /** |
|
1706 | + * get an L10N instance |
|
1707 | + * |
|
1708 | + * @param string $app appid |
|
1709 | + * @param string $lang |
|
1710 | + * @return IL10N |
|
1711 | + * @deprecated 20.0.0 |
|
1712 | + */ |
|
1713 | + public function getL10N($app, $lang = null) { |
|
1714 | + return $this->get(IFactory::class)->get($app, $lang); |
|
1715 | + } |
|
1716 | + |
|
1717 | + /** |
|
1718 | + * @return IURLGenerator |
|
1719 | + * @deprecated 20.0.0 |
|
1720 | + */ |
|
1721 | + public function getURLGenerator() { |
|
1722 | + return $this->get(IURLGenerator::class); |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * @return AppFetcher |
|
1727 | + * @deprecated 20.0.0 |
|
1728 | + */ |
|
1729 | + public function getAppFetcher() { |
|
1730 | + return $this->get(AppFetcher::class); |
|
1731 | + } |
|
1732 | + |
|
1733 | + /** |
|
1734 | + * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
|
1735 | + * getMemCacheFactory() instead. |
|
1736 | + * |
|
1737 | + * @return ICache |
|
1738 | + * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
|
1739 | + */ |
|
1740 | + public function getCache() { |
|
1741 | + return $this->get(ICache::class); |
|
1742 | + } |
|
1743 | + |
|
1744 | + /** |
|
1745 | + * Returns an \OCP\CacheFactory instance |
|
1746 | + * |
|
1747 | + * @return \OCP\ICacheFactory |
|
1748 | + * @deprecated 20.0.0 |
|
1749 | + */ |
|
1750 | + public function getMemCacheFactory() { |
|
1751 | + return $this->get(ICacheFactory::class); |
|
1752 | + } |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * Returns an \OC\RedisFactory instance |
|
1756 | + * |
|
1757 | + * @return \OC\RedisFactory |
|
1758 | + * @deprecated 20.0.0 |
|
1759 | + */ |
|
1760 | + public function getGetRedisFactory() { |
|
1761 | + return $this->get('RedisFactory'); |
|
1762 | + } |
|
1763 | + |
|
1764 | + |
|
1765 | + /** |
|
1766 | + * Returns the current session |
|
1767 | + * |
|
1768 | + * @return \OCP\IDBConnection |
|
1769 | + * @deprecated 20.0.0 |
|
1770 | + */ |
|
1771 | + public function getDatabaseConnection() { |
|
1772 | + return $this->get(IDBConnection::class); |
|
1773 | + } |
|
1774 | + |
|
1775 | + /** |
|
1776 | + * Returns the activity manager |
|
1777 | + * |
|
1778 | + * @return \OCP\Activity\IManager |
|
1779 | + * @deprecated 20.0.0 |
|
1780 | + */ |
|
1781 | + public function getActivityManager() { |
|
1782 | + return $this->get(\OCP\Activity\IManager::class); |
|
1783 | + } |
|
1784 | + |
|
1785 | + /** |
|
1786 | + * Returns an job list for controlling background jobs |
|
1787 | + * |
|
1788 | + * @return IJobList |
|
1789 | + * @deprecated 20.0.0 |
|
1790 | + */ |
|
1791 | + public function getJobList() { |
|
1792 | + return $this->get(IJobList::class); |
|
1793 | + } |
|
1794 | + |
|
1795 | + /** |
|
1796 | + * Returns a logger instance |
|
1797 | + * |
|
1798 | + * @return ILogger |
|
1799 | + * @deprecated 20.0.0 |
|
1800 | + */ |
|
1801 | + public function getLogger() { |
|
1802 | + return $this->get(ILogger::class); |
|
1803 | + } |
|
1804 | + |
|
1805 | + /** |
|
1806 | + * @return ILogFactory |
|
1807 | + * @throws \OCP\AppFramework\QueryException |
|
1808 | + * @deprecated 20.0.0 |
|
1809 | + */ |
|
1810 | + public function getLogFactory() { |
|
1811 | + return $this->get(ILogFactory::class); |
|
1812 | + } |
|
1813 | + |
|
1814 | + /** |
|
1815 | + * Returns a router for generating and matching urls |
|
1816 | + * |
|
1817 | + * @return IRouter |
|
1818 | + * @deprecated 20.0.0 |
|
1819 | + */ |
|
1820 | + public function getRouter() { |
|
1821 | + return $this->get(IRouter::class); |
|
1822 | + } |
|
1823 | + |
|
1824 | + /** |
|
1825 | + * Returns a search instance |
|
1826 | + * |
|
1827 | + * @return ISearch |
|
1828 | + * @deprecated 20.0.0 |
|
1829 | + */ |
|
1830 | + public function getSearch() { |
|
1831 | + return $this->get(ISearch::class); |
|
1832 | + } |
|
1833 | + |
|
1834 | + /** |
|
1835 | + * Returns a SecureRandom instance |
|
1836 | + * |
|
1837 | + * @return \OCP\Security\ISecureRandom |
|
1838 | + * @deprecated 20.0.0 |
|
1839 | + */ |
|
1840 | + public function getSecureRandom() { |
|
1841 | + return $this->get(ISecureRandom::class); |
|
1842 | + } |
|
1843 | + |
|
1844 | + /** |
|
1845 | + * Returns a Crypto instance |
|
1846 | + * |
|
1847 | + * @return ICrypto |
|
1848 | + * @deprecated 20.0.0 |
|
1849 | + */ |
|
1850 | + public function getCrypto() { |
|
1851 | + return $this->get(ICrypto::class); |
|
1852 | + } |
|
1853 | + |
|
1854 | + /** |
|
1855 | + * Returns a Hasher instance |
|
1856 | + * |
|
1857 | + * @return IHasher |
|
1858 | + * @deprecated 20.0.0 |
|
1859 | + */ |
|
1860 | + public function getHasher() { |
|
1861 | + return $this->get(IHasher::class); |
|
1862 | + } |
|
1863 | + |
|
1864 | + /** |
|
1865 | + * Returns a CredentialsManager instance |
|
1866 | + * |
|
1867 | + * @return ICredentialsManager |
|
1868 | + * @deprecated 20.0.0 |
|
1869 | + */ |
|
1870 | + public function getCredentialsManager() { |
|
1871 | + return $this->get(ICredentialsManager::class); |
|
1872 | + } |
|
1873 | + |
|
1874 | + /** |
|
1875 | + * Get the certificate manager |
|
1876 | + * |
|
1877 | + * @return \OCP\ICertificateManager |
|
1878 | + */ |
|
1879 | + public function getCertificateManager() { |
|
1880 | + return $this->get(ICertificateManager::class); |
|
1881 | + } |
|
1882 | + |
|
1883 | + /** |
|
1884 | + * Returns an instance of the HTTP client service |
|
1885 | + * |
|
1886 | + * @return IClientService |
|
1887 | + * @deprecated 20.0.0 |
|
1888 | + */ |
|
1889 | + public function getHTTPClientService() { |
|
1890 | + return $this->get(IClientService::class); |
|
1891 | + } |
|
1892 | + |
|
1893 | + /** |
|
1894 | + * Create a new event source |
|
1895 | + * |
|
1896 | + * @return \OCP\IEventSource |
|
1897 | + * @deprecated 20.0.0 |
|
1898 | + */ |
|
1899 | + public function createEventSource() { |
|
1900 | + return new \OC_EventSource(); |
|
1901 | + } |
|
1902 | + |
|
1903 | + /** |
|
1904 | + * Get the active event logger |
|
1905 | + * |
|
1906 | + * The returned logger only logs data when debug mode is enabled |
|
1907 | + * |
|
1908 | + * @return IEventLogger |
|
1909 | + * @deprecated 20.0.0 |
|
1910 | + */ |
|
1911 | + public function getEventLogger() { |
|
1912 | + return $this->get(IEventLogger::class); |
|
1913 | + } |
|
1914 | + |
|
1915 | + /** |
|
1916 | + * Get the active query logger |
|
1917 | + * |
|
1918 | + * The returned logger only logs data when debug mode is enabled |
|
1919 | + * |
|
1920 | + * @return IQueryLogger |
|
1921 | + * @deprecated 20.0.0 |
|
1922 | + */ |
|
1923 | + public function getQueryLogger() { |
|
1924 | + return $this->get(IQueryLogger::class); |
|
1925 | + } |
|
1926 | + |
|
1927 | + /** |
|
1928 | + * Get the manager for temporary files and folders |
|
1929 | + * |
|
1930 | + * @return \OCP\ITempManager |
|
1931 | + * @deprecated 20.0.0 |
|
1932 | + */ |
|
1933 | + public function getTempManager() { |
|
1934 | + return $this->get(ITempManager::class); |
|
1935 | + } |
|
1936 | + |
|
1937 | + /** |
|
1938 | + * Get the app manager |
|
1939 | + * |
|
1940 | + * @return \OCP\App\IAppManager |
|
1941 | + * @deprecated 20.0.0 |
|
1942 | + */ |
|
1943 | + public function getAppManager() { |
|
1944 | + return $this->get(IAppManager::class); |
|
1945 | + } |
|
1946 | + |
|
1947 | + /** |
|
1948 | + * Creates a new mailer |
|
1949 | + * |
|
1950 | + * @return IMailer |
|
1951 | + * @deprecated 20.0.0 |
|
1952 | + */ |
|
1953 | + public function getMailer() { |
|
1954 | + return $this->get(IMailer::class); |
|
1955 | + } |
|
1956 | + |
|
1957 | + /** |
|
1958 | + * Get the webroot |
|
1959 | + * |
|
1960 | + * @return string |
|
1961 | + * @deprecated 20.0.0 |
|
1962 | + */ |
|
1963 | + public function getWebRoot() { |
|
1964 | + return $this->webRoot; |
|
1965 | + } |
|
1966 | + |
|
1967 | + /** |
|
1968 | + * @return \OC\OCSClient |
|
1969 | + * @deprecated 20.0.0 |
|
1970 | + */ |
|
1971 | + public function getOcsClient() { |
|
1972 | + return $this->get('OcsClient'); |
|
1973 | + } |
|
1974 | + |
|
1975 | + /** |
|
1976 | + * @return IDateTimeZone |
|
1977 | + * @deprecated 20.0.0 |
|
1978 | + */ |
|
1979 | + public function getDateTimeZone() { |
|
1980 | + return $this->get(IDateTimeZone::class); |
|
1981 | + } |
|
1982 | + |
|
1983 | + /** |
|
1984 | + * @return IDateTimeFormatter |
|
1985 | + * @deprecated 20.0.0 |
|
1986 | + */ |
|
1987 | + public function getDateTimeFormatter() { |
|
1988 | + return $this->get(IDateTimeFormatter::class); |
|
1989 | + } |
|
1990 | + |
|
1991 | + /** |
|
1992 | + * @return IMountProviderCollection |
|
1993 | + * @deprecated 20.0.0 |
|
1994 | + */ |
|
1995 | + public function getMountProviderCollection() { |
|
1996 | + return $this->get(IMountProviderCollection::class); |
|
1997 | + } |
|
1998 | + |
|
1999 | + /** |
|
2000 | + * Get the IniWrapper |
|
2001 | + * |
|
2002 | + * @return IniGetWrapper |
|
2003 | + * @deprecated 20.0.0 |
|
2004 | + */ |
|
2005 | + public function getIniWrapper() { |
|
2006 | + return $this->get(IniGetWrapper::class); |
|
2007 | + } |
|
2008 | + |
|
2009 | + /** |
|
2010 | + * @return \OCP\Command\IBus |
|
2011 | + * @deprecated 20.0.0 |
|
2012 | + */ |
|
2013 | + public function getCommandBus() { |
|
2014 | + return $this->get(IBus::class); |
|
2015 | + } |
|
2016 | + |
|
2017 | + /** |
|
2018 | + * Get the trusted domain helper |
|
2019 | + * |
|
2020 | + * @return TrustedDomainHelper |
|
2021 | + * @deprecated 20.0.0 |
|
2022 | + */ |
|
2023 | + public function getTrustedDomainHelper() { |
|
2024 | + return $this->get(TrustedDomainHelper::class); |
|
2025 | + } |
|
2026 | + |
|
2027 | + /** |
|
2028 | + * Get the locking provider |
|
2029 | + * |
|
2030 | + * @return ILockingProvider |
|
2031 | + * @since 8.1.0 |
|
2032 | + * @deprecated 20.0.0 |
|
2033 | + */ |
|
2034 | + public function getLockingProvider() { |
|
2035 | + return $this->get(ILockingProvider::class); |
|
2036 | + } |
|
2037 | + |
|
2038 | + /** |
|
2039 | + * @return IMountManager |
|
2040 | + * @deprecated 20.0.0 |
|
2041 | + **/ |
|
2042 | + public function getMountManager() { |
|
2043 | + return $this->get(IMountManager::class); |
|
2044 | + } |
|
2045 | + |
|
2046 | + /** |
|
2047 | + * @return IUserMountCache |
|
2048 | + * @deprecated 20.0.0 |
|
2049 | + */ |
|
2050 | + public function getUserMountCache() { |
|
2051 | + return $this->get(IUserMountCache::class); |
|
2052 | + } |
|
2053 | + |
|
2054 | + /** |
|
2055 | + * Get the MimeTypeDetector |
|
2056 | + * |
|
2057 | + * @return IMimeTypeDetector |
|
2058 | + * @deprecated 20.0.0 |
|
2059 | + */ |
|
2060 | + public function getMimeTypeDetector() { |
|
2061 | + return $this->get(IMimeTypeDetector::class); |
|
2062 | + } |
|
2063 | + |
|
2064 | + /** |
|
2065 | + * Get the MimeTypeLoader |
|
2066 | + * |
|
2067 | + * @return IMimeTypeLoader |
|
2068 | + * @deprecated 20.0.0 |
|
2069 | + */ |
|
2070 | + public function getMimeTypeLoader() { |
|
2071 | + return $this->get(IMimeTypeLoader::class); |
|
2072 | + } |
|
2073 | + |
|
2074 | + /** |
|
2075 | + * Get the manager of all the capabilities |
|
2076 | + * |
|
2077 | + * @return CapabilitiesManager |
|
2078 | + * @deprecated 20.0.0 |
|
2079 | + */ |
|
2080 | + public function getCapabilitiesManager() { |
|
2081 | + return $this->get(CapabilitiesManager::class); |
|
2082 | + } |
|
2083 | + |
|
2084 | + /** |
|
2085 | + * Get the EventDispatcher |
|
2086 | + * |
|
2087 | + * @return EventDispatcherInterface |
|
2088 | + * @since 8.2.0 |
|
2089 | + * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher |
|
2090 | + */ |
|
2091 | + public function getEventDispatcher() { |
|
2092 | + return $this->get(\OC\EventDispatcher\SymfonyAdapter::class); |
|
2093 | + } |
|
2094 | + |
|
2095 | + /** |
|
2096 | + * Get the Notification Manager |
|
2097 | + * |
|
2098 | + * @return \OCP\Notification\IManager |
|
2099 | + * @since 8.2.0 |
|
2100 | + * @deprecated 20.0.0 |
|
2101 | + */ |
|
2102 | + public function getNotificationManager() { |
|
2103 | + return $this->get(\OCP\Notification\IManager::class); |
|
2104 | + } |
|
2105 | + |
|
2106 | + /** |
|
2107 | + * @return ICommentsManager |
|
2108 | + * @deprecated 20.0.0 |
|
2109 | + */ |
|
2110 | + public function getCommentsManager() { |
|
2111 | + return $this->get(ICommentsManager::class); |
|
2112 | + } |
|
2113 | + |
|
2114 | + /** |
|
2115 | + * @return \OCA\Theming\ThemingDefaults |
|
2116 | + * @deprecated 20.0.0 |
|
2117 | + */ |
|
2118 | + public function getThemingDefaults() { |
|
2119 | + return $this->get('ThemingDefaults'); |
|
2120 | + } |
|
2121 | + |
|
2122 | + /** |
|
2123 | + * @return \OC\IntegrityCheck\Checker |
|
2124 | + * @deprecated 20.0.0 |
|
2125 | + */ |
|
2126 | + public function getIntegrityCodeChecker() { |
|
2127 | + return $this->get('IntegrityCodeChecker'); |
|
2128 | + } |
|
2129 | + |
|
2130 | + /** |
|
2131 | + * @return \OC\Session\CryptoWrapper |
|
2132 | + * @deprecated 20.0.0 |
|
2133 | + */ |
|
2134 | + public function getSessionCryptoWrapper() { |
|
2135 | + return $this->get('CryptoWrapper'); |
|
2136 | + } |
|
2137 | + |
|
2138 | + /** |
|
2139 | + * @return CsrfTokenManager |
|
2140 | + * @deprecated 20.0.0 |
|
2141 | + */ |
|
2142 | + public function getCsrfTokenManager() { |
|
2143 | + return $this->get(CsrfTokenManager::class); |
|
2144 | + } |
|
2145 | + |
|
2146 | + /** |
|
2147 | + * @return Throttler |
|
2148 | + * @deprecated 20.0.0 |
|
2149 | + */ |
|
2150 | + public function getBruteForceThrottler() { |
|
2151 | + return $this->get(Throttler::class); |
|
2152 | + } |
|
2153 | + |
|
2154 | + /** |
|
2155 | + * @return IContentSecurityPolicyManager |
|
2156 | + * @deprecated 20.0.0 |
|
2157 | + */ |
|
2158 | + public function getContentSecurityPolicyManager() { |
|
2159 | + return $this->get(ContentSecurityPolicyManager::class); |
|
2160 | + } |
|
2161 | + |
|
2162 | + /** |
|
2163 | + * @return ContentSecurityPolicyNonceManager |
|
2164 | + * @deprecated 20.0.0 |
|
2165 | + */ |
|
2166 | + public function getContentSecurityPolicyNonceManager() { |
|
2167 | + return $this->get(ContentSecurityPolicyNonceManager::class); |
|
2168 | + } |
|
2169 | + |
|
2170 | + /** |
|
2171 | + * Not a public API as of 8.2, wait for 9.0 |
|
2172 | + * |
|
2173 | + * @return \OCA\Files_External\Service\BackendService |
|
2174 | + * @deprecated 20.0.0 |
|
2175 | + */ |
|
2176 | + public function getStoragesBackendService() { |
|
2177 | + return $this->get(BackendService::class); |
|
2178 | + } |
|
2179 | + |
|
2180 | + /** |
|
2181 | + * Not a public API as of 8.2, wait for 9.0 |
|
2182 | + * |
|
2183 | + * @return \OCA\Files_External\Service\GlobalStoragesService |
|
2184 | + * @deprecated 20.0.0 |
|
2185 | + */ |
|
2186 | + public function getGlobalStoragesService() { |
|
2187 | + return $this->get(GlobalStoragesService::class); |
|
2188 | + } |
|
2189 | + |
|
2190 | + /** |
|
2191 | + * Not a public API as of 8.2, wait for 9.0 |
|
2192 | + * |
|
2193 | + * @return \OCA\Files_External\Service\UserGlobalStoragesService |
|
2194 | + * @deprecated 20.0.0 |
|
2195 | + */ |
|
2196 | + public function getUserGlobalStoragesService() { |
|
2197 | + return $this->get(UserGlobalStoragesService::class); |
|
2198 | + } |
|
2199 | + |
|
2200 | + /** |
|
2201 | + * Not a public API as of 8.2, wait for 9.0 |
|
2202 | + * |
|
2203 | + * @return \OCA\Files_External\Service\UserStoragesService |
|
2204 | + * @deprecated 20.0.0 |
|
2205 | + */ |
|
2206 | + public function getUserStoragesService() { |
|
2207 | + return $this->get(UserStoragesService::class); |
|
2208 | + } |
|
2209 | + |
|
2210 | + /** |
|
2211 | + * @return \OCP\Share\IManager |
|
2212 | + * @deprecated 20.0.0 |
|
2213 | + */ |
|
2214 | + public function getShareManager() { |
|
2215 | + return $this->get(\OCP\Share\IManager::class); |
|
2216 | + } |
|
2217 | + |
|
2218 | + /** |
|
2219 | + * @return \OCP\Collaboration\Collaborators\ISearch |
|
2220 | + * @deprecated 20.0.0 |
|
2221 | + */ |
|
2222 | + public function getCollaboratorSearch() { |
|
2223 | + return $this->get(\OCP\Collaboration\Collaborators\ISearch::class); |
|
2224 | + } |
|
2225 | + |
|
2226 | + /** |
|
2227 | + * @return \OCP\Collaboration\AutoComplete\IManager |
|
2228 | + * @deprecated 20.0.0 |
|
2229 | + */ |
|
2230 | + public function getAutoCompleteManager() { |
|
2231 | + return $this->get(IManager::class); |
|
2232 | + } |
|
2233 | + |
|
2234 | + /** |
|
2235 | + * Returns the LDAP Provider |
|
2236 | + * |
|
2237 | + * @return \OCP\LDAP\ILDAPProvider |
|
2238 | + * @deprecated 20.0.0 |
|
2239 | + */ |
|
2240 | + public function getLDAPProvider() { |
|
2241 | + return $this->get('LDAPProvider'); |
|
2242 | + } |
|
2243 | + |
|
2244 | + /** |
|
2245 | + * @return \OCP\Settings\IManager |
|
2246 | + * @deprecated 20.0.0 |
|
2247 | + */ |
|
2248 | + public function getSettingsManager() { |
|
2249 | + return $this->get(\OC\Settings\Manager::class); |
|
2250 | + } |
|
2251 | + |
|
2252 | + /** |
|
2253 | + * @return \OCP\Files\IAppData |
|
2254 | + * @deprecated 20.0.0 |
|
2255 | + */ |
|
2256 | + public function getAppDataDir($app) { |
|
2257 | + /** @var \OC\Files\AppData\Factory $factory */ |
|
2258 | + $factory = $this->get(\OC\Files\AppData\Factory::class); |
|
2259 | + return $factory->get($app); |
|
2260 | + } |
|
2261 | + |
|
2262 | + /** |
|
2263 | + * @return \OCP\Lockdown\ILockdownManager |
|
2264 | + * @deprecated 20.0.0 |
|
2265 | + */ |
|
2266 | + public function getLockdownManager() { |
|
2267 | + return $this->get('LockdownManager'); |
|
2268 | + } |
|
2269 | + |
|
2270 | + /** |
|
2271 | + * @return \OCP\Federation\ICloudIdManager |
|
2272 | + * @deprecated 20.0.0 |
|
2273 | + */ |
|
2274 | + public function getCloudIdManager() { |
|
2275 | + return $this->get(ICloudIdManager::class); |
|
2276 | + } |
|
2277 | + |
|
2278 | + /** |
|
2279 | + * @return \OCP\GlobalScale\IConfig |
|
2280 | + * @deprecated 20.0.0 |
|
2281 | + */ |
|
2282 | + public function getGlobalScaleConfig() { |
|
2283 | + return $this->get(IConfig::class); |
|
2284 | + } |
|
2285 | + |
|
2286 | + /** |
|
2287 | + * @return \OCP\Federation\ICloudFederationProviderManager |
|
2288 | + * @deprecated 20.0.0 |
|
2289 | + */ |
|
2290 | + public function getCloudFederationProviderManager() { |
|
2291 | + return $this->get(ICloudFederationProviderManager::class); |
|
2292 | + } |
|
2293 | + |
|
2294 | + /** |
|
2295 | + * @return \OCP\Remote\Api\IApiFactory |
|
2296 | + * @deprecated 20.0.0 |
|
2297 | + */ |
|
2298 | + public function getRemoteApiFactory() { |
|
2299 | + return $this->get(IApiFactory::class); |
|
2300 | + } |
|
2301 | + |
|
2302 | + /** |
|
2303 | + * @return \OCP\Federation\ICloudFederationFactory |
|
2304 | + * @deprecated 20.0.0 |
|
2305 | + */ |
|
2306 | + public function getCloudFederationFactory() { |
|
2307 | + return $this->get(ICloudFederationFactory::class); |
|
2308 | + } |
|
2309 | + |
|
2310 | + /** |
|
2311 | + * @return \OCP\Remote\IInstanceFactory |
|
2312 | + * @deprecated 20.0.0 |
|
2313 | + */ |
|
2314 | + public function getRemoteInstanceFactory() { |
|
2315 | + return $this->get(IInstanceFactory::class); |
|
2316 | + } |
|
2317 | + |
|
2318 | + /** |
|
2319 | + * @return IStorageFactory |
|
2320 | + * @deprecated 20.0.0 |
|
2321 | + */ |
|
2322 | + public function getStorageFactory() { |
|
2323 | + return $this->get(IStorageFactory::class); |
|
2324 | + } |
|
2325 | + |
|
2326 | + /** |
|
2327 | + * Get the Preview GeneratorHelper |
|
2328 | + * |
|
2329 | + * @return GeneratorHelper |
|
2330 | + * @since 17.0.0 |
|
2331 | + * @deprecated 20.0.0 |
|
2332 | + */ |
|
2333 | + public function getGeneratorHelper() { |
|
2334 | + return $this->get(\OC\Preview\GeneratorHelper::class); |
|
2335 | + } |
|
2336 | + |
|
2337 | + private function registerDeprecatedAlias(string $alias, string $target) { |
|
2338 | + $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2339 | + try { |
|
2340 | + /** @var ILogger $logger */ |
|
2341 | + $logger = $container->get(ILogger::class); |
|
2342 | + $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2343 | + } catch (ContainerExceptionInterface $e) { |
|
2344 | + // Could not get logger. Continue |
|
2345 | + } |
|
2346 | + |
|
2347 | + return $container->get($target); |
|
2348 | + }, false); |
|
2349 | + } |
|
2350 | 2350 | } |
@@ -278,10 +278,10 @@ discard block |
||
278 | 278 | $this->registerParameter('isCLI', \OC::$CLI); |
279 | 279 | $this->registerParameter('serverRoot', \OC::$SERVERROOT); |
280 | 280 | |
281 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
281 | + $this->registerService(ContainerInterface::class, function(ContainerInterface $c) { |
|
282 | 282 | return $c; |
283 | 283 | }); |
284 | - $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) { |
|
284 | + $this->registerService(\OCP\IServerContainer::class, function(ContainerInterface $c) { |
|
285 | 285 | return $c; |
286 | 286 | }); |
287 | 287 | |
@@ -306,11 +306,11 @@ discard block |
||
306 | 306 | |
307 | 307 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
308 | 308 | |
309 | - $this->registerService(View::class, function (Server $c) { |
|
309 | + $this->registerService(View::class, function(Server $c) { |
|
310 | 310 | return new View(); |
311 | 311 | }, false); |
312 | 312 | |
313 | - $this->registerService(IPreview::class, function (ContainerInterface $c) { |
|
313 | + $this->registerService(IPreview::class, function(ContainerInterface $c) { |
|
314 | 314 | return new PreviewManager( |
315 | 315 | $c->get(\OCP\IConfig::class), |
316 | 316 | $c->get(IRootFolder::class), |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | /** @deprecated 19.0.0 */ |
329 | 329 | $this->registerDeprecatedAlias('PreviewManager', IPreview::class); |
330 | 330 | |
331 | - $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) { |
|
331 | + $this->registerService(\OC\Preview\Watcher::class, function(ContainerInterface $c) { |
|
332 | 332 | return new \OC\Preview\Watcher( |
333 | 333 | new \OC\Preview\Storage\Root( |
334 | 334 | $c->get(IRootFolder::class), |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | ); |
338 | 338 | }); |
339 | 339 | |
340 | - $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) { |
|
340 | + $this->registerService(\OCP\Encryption\IManager::class, function(Server $c) { |
|
341 | 341 | $view = new View(); |
342 | 342 | $util = new Encryption\Util( |
343 | 343 | $view, |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | |
360 | 360 | /** @deprecated 21.0.0 */ |
361 | 361 | $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class); |
362 | - $this->registerService(IFile::class, function (ContainerInterface $c) { |
|
362 | + $this->registerService(IFile::class, function(ContainerInterface $c) { |
|
363 | 363 | $util = new Encryption\Util( |
364 | 364 | new View(), |
365 | 365 | $c->get(IUserManager::class), |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | |
376 | 376 | /** @deprecated 21.0.0 */ |
377 | 377 | $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class); |
378 | - $this->registerService(IStorage::class, function (ContainerInterface $c) { |
|
378 | + $this->registerService(IStorage::class, function(ContainerInterface $c) { |
|
379 | 379 | $view = new View(); |
380 | 380 | $util = new Encryption\Util( |
381 | 381 | $view, |
@@ -398,22 +398,22 @@ discard block |
||
398 | 398 | /** @deprecated 19.0.0 */ |
399 | 399 | $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class); |
400 | 400 | |
401 | - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { |
|
401 | + $this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) { |
|
402 | 402 | /** @var \OCP\IConfig $config */ |
403 | 403 | $config = $c->get(\OCP\IConfig::class); |
404 | 404 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
405 | 405 | return new $factoryClass($this); |
406 | 406 | }); |
407 | - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { |
|
407 | + $this->registerService(ISystemTagManager::class, function(ContainerInterface $c) { |
|
408 | 408 | return $c->get('SystemTagManagerFactory')->getManager(); |
409 | 409 | }); |
410 | 410 | /** @deprecated 19.0.0 */ |
411 | 411 | $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); |
412 | 412 | |
413 | - $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { |
|
413 | + $this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) { |
|
414 | 414 | return $c->get('SystemTagManagerFactory')->getObjectMapper(); |
415 | 415 | }); |
416 | - $this->registerService('RootFolder', function (ContainerInterface $c) { |
|
416 | + $this->registerService('RootFolder', function(ContainerInterface $c) { |
|
417 | 417 | $manager = \OC\Files\Filesystem::getMountManager(null); |
418 | 418 | $view = new View(); |
419 | 419 | $root = new Root( |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | |
434 | 434 | return $root; |
435 | 435 | }); |
436 | - $this->registerService(HookConnector::class, function (ContainerInterface $c) { |
|
436 | + $this->registerService(HookConnector::class, function(ContainerInterface $c) { |
|
437 | 437 | return new HookConnector( |
438 | 438 | $c->get(IRootFolder::class), |
439 | 439 | new View(), |
@@ -445,8 +445,8 @@ discard block |
||
445 | 445 | /** @deprecated 19.0.0 */ |
446 | 446 | $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class); |
447 | 447 | |
448 | - $this->registerService(IRootFolder::class, function (ContainerInterface $c) { |
|
449 | - return new LazyRoot(function () use ($c) { |
|
448 | + $this->registerService(IRootFolder::class, function(ContainerInterface $c) { |
|
449 | + return new LazyRoot(function() use ($c) { |
|
450 | 450 | return $c->get('RootFolder'); |
451 | 451 | }); |
452 | 452 | }); |
@@ -457,44 +457,44 @@ discard block |
||
457 | 457 | $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class); |
458 | 458 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
459 | 459 | |
460 | - $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) { |
|
460 | + $this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) { |
|
461 | 461 | $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class)); |
462 | - $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
|
462 | + $groupManager->listen('\OC\Group', 'preCreate', function($gid) { |
|
463 | 463 | /** @var IEventDispatcher $dispatcher */ |
464 | 464 | $dispatcher = $this->get(IEventDispatcher::class); |
465 | 465 | $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid)); |
466 | 466 | }); |
467 | - $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) { |
|
467 | + $groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $group) { |
|
468 | 468 | /** @var IEventDispatcher $dispatcher */ |
469 | 469 | $dispatcher = $this->get(IEventDispatcher::class); |
470 | 470 | $dispatcher->dispatchTyped(new GroupCreatedEvent($group)); |
471 | 471 | }); |
472 | - $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
|
472 | + $groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) { |
|
473 | 473 | /** @var IEventDispatcher $dispatcher */ |
474 | 474 | $dispatcher = $this->get(IEventDispatcher::class); |
475 | 475 | $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group)); |
476 | 476 | }); |
477 | - $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
|
477 | + $groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) { |
|
478 | 478 | /** @var IEventDispatcher $dispatcher */ |
479 | 479 | $dispatcher = $this->get(IEventDispatcher::class); |
480 | 480 | $dispatcher->dispatchTyped(new GroupDeletedEvent($group)); |
481 | 481 | }); |
482 | - $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
482 | + $groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
483 | 483 | /** @var IEventDispatcher $dispatcher */ |
484 | 484 | $dispatcher = $this->get(IEventDispatcher::class); |
485 | 485 | $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user)); |
486 | 486 | }); |
487 | - $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
487 | + $groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
488 | 488 | /** @var IEventDispatcher $dispatcher */ |
489 | 489 | $dispatcher = $this->get(IEventDispatcher::class); |
490 | 490 | $dispatcher->dispatchTyped(new UserAddedEvent($group, $user)); |
491 | 491 | }); |
492 | - $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
492 | + $groupManager->listen('\OC\Group', 'preRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
493 | 493 | /** @var IEventDispatcher $dispatcher */ |
494 | 494 | $dispatcher = $this->get(IEventDispatcher::class); |
495 | 495 | $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user)); |
496 | 496 | }); |
497 | - $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
|
497 | + $groupManager->listen('\OC\Group', 'postRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) { |
|
498 | 498 | /** @var IEventDispatcher $dispatcher */ |
499 | 499 | $dispatcher = $this->get(IEventDispatcher::class); |
500 | 500 | $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user)); |
@@ -504,7 +504,7 @@ discard block |
||
504 | 504 | /** @deprecated 19.0.0 */ |
505 | 505 | $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class); |
506 | 506 | |
507 | - $this->registerService(Store::class, function (ContainerInterface $c) { |
|
507 | + $this->registerService(Store::class, function(ContainerInterface $c) { |
|
508 | 508 | $session = $c->get(ISession::class); |
509 | 509 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
510 | 510 | $tokenProvider = $c->get(IProvider::class); |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | $this->registerAlias(IStore::class, Store::class); |
518 | 518 | $this->registerAlias(IProvider::class, Authentication\Token\Manager::class); |
519 | 519 | |
520 | - $this->registerService(\OC\User\Session::class, function (Server $c) { |
|
520 | + $this->registerService(\OC\User\Session::class, function(Server $c) { |
|
521 | 521 | $manager = $c->get(IUserManager::class); |
522 | 522 | $session = new \OC\Session\Memory(''); |
523 | 523 | $timeFactory = new TimeFactory(); |
@@ -543,26 +543,26 @@ discard block |
||
543 | 543 | $c->get(IEventDispatcher::class) |
544 | 544 | ); |
545 | 545 | /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */ |
546 | - $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
|
546 | + $userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) { |
|
547 | 547 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
548 | 548 | }); |
549 | 549 | /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */ |
550 | - $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
|
550 | + $userSession->listen('\OC\User', 'postCreateUser', function($user, $password) { |
|
551 | 551 | /** @var \OC\User\User $user */ |
552 | 552 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
553 | 553 | }); |
554 | 554 | /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */ |
555 | - $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) { |
|
555 | + $userSession->listen('\OC\User', 'preDelete', function($user) use ($legacyDispatcher) { |
|
556 | 556 | /** @var \OC\User\User $user */ |
557 | 557 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
558 | 558 | $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
559 | 559 | }); |
560 | 560 | /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */ |
561 | - $userSession->listen('\OC\User', 'postDelete', function ($user) { |
|
561 | + $userSession->listen('\OC\User', 'postDelete', function($user) { |
|
562 | 562 | /** @var \OC\User\User $user */ |
563 | 563 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
564 | 564 | }); |
565 | - $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
565 | + $userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) { |
|
566 | 566 | /** @var \OC\User\User $user */ |
567 | 567 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
568 | 568 | |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | $dispatcher = $this->get(IEventDispatcher::class); |
571 | 571 | $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword)); |
572 | 572 | }); |
573 | - $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
573 | + $userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) { |
|
574 | 574 | /** @var \OC\User\User $user */ |
575 | 575 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
576 | 576 | |
@@ -578,14 +578,14 @@ discard block |
||
578 | 578 | $dispatcher = $this->get(IEventDispatcher::class); |
579 | 579 | $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword)); |
580 | 580 | }); |
581 | - $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
|
581 | + $userSession->listen('\OC\User', 'preLogin', function($uid, $password) { |
|
582 | 582 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
583 | 583 | |
584 | 584 | /** @var IEventDispatcher $dispatcher */ |
585 | 585 | $dispatcher = $this->get(IEventDispatcher::class); |
586 | 586 | $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password)); |
587 | 587 | }); |
588 | - $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) { |
|
588 | + $userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) { |
|
589 | 589 | /** @var \OC\User\User $user */ |
590 | 590 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]); |
591 | 591 | |
@@ -593,12 +593,12 @@ discard block |
||
593 | 593 | $dispatcher = $this->get(IEventDispatcher::class); |
594 | 594 | $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin)); |
595 | 595 | }); |
596 | - $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) { |
|
596 | + $userSession->listen('\OC\User', 'preRememberedLogin', function($uid) { |
|
597 | 597 | /** @var IEventDispatcher $dispatcher */ |
598 | 598 | $dispatcher = $this->get(IEventDispatcher::class); |
599 | 599 | $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid)); |
600 | 600 | }); |
601 | - $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
601 | + $userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) { |
|
602 | 602 | /** @var \OC\User\User $user */ |
603 | 603 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
604 | 604 | |
@@ -606,19 +606,19 @@ discard block |
||
606 | 606 | $dispatcher = $this->get(IEventDispatcher::class); |
607 | 607 | $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password)); |
608 | 608 | }); |
609 | - $userSession->listen('\OC\User', 'logout', function ($user) { |
|
609 | + $userSession->listen('\OC\User', 'logout', function($user) { |
|
610 | 610 | \OC_Hook::emit('OC_User', 'logout', []); |
611 | 611 | |
612 | 612 | /** @var IEventDispatcher $dispatcher */ |
613 | 613 | $dispatcher = $this->get(IEventDispatcher::class); |
614 | 614 | $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user)); |
615 | 615 | }); |
616 | - $userSession->listen('\OC\User', 'postLogout', function ($user) { |
|
616 | + $userSession->listen('\OC\User', 'postLogout', function($user) { |
|
617 | 617 | /** @var IEventDispatcher $dispatcher */ |
618 | 618 | $dispatcher = $this->get(IEventDispatcher::class); |
619 | 619 | $dispatcher->dispatchTyped(new UserLoggedOutEvent($user)); |
620 | 620 | }); |
621 | - $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) { |
|
621 | + $userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) { |
|
622 | 622 | /** @var \OC\User\User $user */ |
623 | 623 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]); |
624 | 624 | |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class); |
643 | 643 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
644 | 644 | |
645 | - $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) { |
|
645 | + $this->registerService(\OC\SystemConfig::class, function($c) use ($config) { |
|
646 | 646 | return new \OC\SystemConfig($config); |
647 | 647 | }); |
648 | 648 | /** @deprecated 19.0.0 */ |
@@ -652,7 +652,7 @@ discard block |
||
652 | 652 | $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class); |
653 | 653 | $this->registerAlias(IAppConfig::class, \OC\AppConfig::class); |
654 | 654 | |
655 | - $this->registerService(IFactory::class, function (Server $c) { |
|
655 | + $this->registerService(IFactory::class, function(Server $c) { |
|
656 | 656 | return new \OC\L10N\Factory( |
657 | 657 | $c->get(\OCP\IConfig::class), |
658 | 658 | $c->getRequest(), |
@@ -672,13 +672,13 @@ discard block |
||
672 | 672 | /** @deprecated 19.0.0 */ |
673 | 673 | $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class); |
674 | 674 | |
675 | - $this->registerService(ICache::class, function ($c) { |
|
675 | + $this->registerService(ICache::class, function($c) { |
|
676 | 676 | return new Cache\File(); |
677 | 677 | }); |
678 | 678 | /** @deprecated 19.0.0 */ |
679 | 679 | $this->registerDeprecatedAlias('UserCache', ICache::class); |
680 | 680 | |
681 | - $this->registerService(Factory::class, function (Server $c) { |
|
681 | + $this->registerService(Factory::class, function(Server $c) { |
|
682 | 682 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class), |
683 | 683 | ArrayCache::class, |
684 | 684 | ArrayCache::class, |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | $version = implode(',', $v); |
703 | 703 | $instanceId = \OC_Util::getInstanceId(); |
704 | 704 | $path = \OC::$SERVERROOT; |
705 | - $prefix = md5($instanceId . '-' . $version . '-' . $path); |
|
705 | + $prefix = md5($instanceId.'-'.$version.'-'.$path); |
|
706 | 706 | return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class), |
707 | 707 | $config->getSystemValue('memcache.local', null), |
708 | 708 | $config->getSystemValue('memcache.distributed', null), |
@@ -716,12 +716,12 @@ discard block |
||
716 | 716 | $this->registerDeprecatedAlias('MemCacheFactory', Factory::class); |
717 | 717 | $this->registerAlias(ICacheFactory::class, Factory::class); |
718 | 718 | |
719 | - $this->registerService('RedisFactory', function (Server $c) { |
|
719 | + $this->registerService('RedisFactory', function(Server $c) { |
|
720 | 720 | $systemConfig = $c->get(SystemConfig::class); |
721 | 721 | return new RedisFactory($systemConfig, $c->getEventLogger()); |
722 | 722 | }); |
723 | 723 | |
724 | - $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
|
724 | + $this->registerService(\OCP\Activity\IManager::class, function(Server $c) { |
|
725 | 725 | $l10n = $this->get(IFactory::class)->get('lib'); |
726 | 726 | return new \OC\Activity\Manager( |
727 | 727 | $c->getRequest(), |
@@ -734,14 +734,14 @@ discard block |
||
734 | 734 | /** @deprecated 19.0.0 */ |
735 | 735 | $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class); |
736 | 736 | |
737 | - $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
|
737 | + $this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) { |
|
738 | 738 | return new \OC\Activity\EventMerger( |
739 | 739 | $c->getL10N('lib') |
740 | 740 | ); |
741 | 741 | }); |
742 | 742 | $this->registerAlias(IValidator::class, Validator::class); |
743 | 743 | |
744 | - $this->registerService(AvatarManager::class, function (Server $c) { |
|
744 | + $this->registerService(AvatarManager::class, function(Server $c) { |
|
745 | 745 | return new AvatarManager( |
746 | 746 | $c->get(IUserSession::class), |
747 | 747 | $c->get(\OC\User\Manager::class), |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
761 | 761 | $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class); |
762 | 762 | |
763 | - $this->registerService(\OC\Log::class, function (Server $c) { |
|
763 | + $this->registerService(\OC\Log::class, function(Server $c) { |
|
764 | 764 | $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file'); |
765 | 765 | $factory = new LogFactory($c, $this->get(SystemConfig::class)); |
766 | 766 | $logger = $factory->get($logType); |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | // PSR-3 logger |
775 | 775 | $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); |
776 | 776 | |
777 | - $this->registerService(ILogFactory::class, function (Server $c) { |
|
777 | + $this->registerService(ILogFactory::class, function(Server $c) { |
|
778 | 778 | return new LogFactory($c, $this->get(SystemConfig::class)); |
779 | 779 | }); |
780 | 780 | |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | /** @deprecated 19.0.0 */ |
783 | 783 | $this->registerDeprecatedAlias('JobList', IJobList::class); |
784 | 784 | |
785 | - $this->registerService(Router::class, function (Server $c) { |
|
785 | + $this->registerService(Router::class, function(Server $c) { |
|
786 | 786 | $cacheFactory = $c->get(ICacheFactory::class); |
787 | 787 | $logger = $c->get(ILogger::class); |
788 | 788 | if ($cacheFactory->isLocalCacheAvailable()) { |
@@ -800,7 +800,7 @@ discard block |
||
800 | 800 | /** @deprecated 19.0.0 */ |
801 | 801 | $this->registerDeprecatedAlias('Search', ISearch::class); |
802 | 802 | |
803 | - $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
|
803 | + $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) { |
|
804 | 804 | $cacheFactory = $c->get(ICacheFactory::class); |
805 | 805 | if ($cacheFactory->isAvailable()) { |
806 | 806 | $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend( |
@@ -836,7 +836,7 @@ discard block |
||
836 | 836 | $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class); |
837 | 837 | |
838 | 838 | $this->registerAlias(IDBConnection::class, ConnectionAdapter::class); |
839 | - $this->registerService(Connection::class, function (Server $c) { |
|
839 | + $this->registerService(Connection::class, function(Server $c) { |
|
840 | 840 | $systemConfig = $c->get(SystemConfig::class); |
841 | 841 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
842 | 842 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
@@ -853,30 +853,30 @@ discard block |
||
853 | 853 | |
854 | 854 | $this->registerAlias(ICertificateManager::class, CertificateManager::class); |
855 | 855 | $this->registerAlias(IClientService::class, ClientService::class); |
856 | - $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) { |
|
856 | + $this->registerService(LocalAddressChecker::class, function(ContainerInterface $c) { |
|
857 | 857 | return new LocalAddressChecker( |
858 | 858 | $c->get(ILogger::class), |
859 | 859 | ); |
860 | 860 | }); |
861 | - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { |
|
861 | + $this->registerService(NegativeDnsCache::class, function(ContainerInterface $c) { |
|
862 | 862 | return new NegativeDnsCache( |
863 | 863 | $c->get(ICacheFactory::class), |
864 | 864 | ); |
865 | 865 | }); |
866 | - $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) { |
|
866 | + $this->registerService(DnsPinMiddleware::class, function(ContainerInterface $c) { |
|
867 | 867 | return new DnsPinMiddleware( |
868 | 868 | $c->get(NegativeDnsCache::class), |
869 | 869 | $c->get(LocalAddressChecker::class) |
870 | 870 | ); |
871 | 871 | }); |
872 | 872 | $this->registerDeprecatedAlias('HttpClientService', IClientService::class); |
873 | - $this->registerService(IEventLogger::class, function (ContainerInterface $c) { |
|
873 | + $this->registerService(IEventLogger::class, function(ContainerInterface $c) { |
|
874 | 874 | return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); |
875 | 875 | }); |
876 | 876 | /** @deprecated 19.0.0 */ |
877 | 877 | $this->registerDeprecatedAlias('EventLogger', IEventLogger::class); |
878 | 878 | |
879 | - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { |
|
879 | + $this->registerService(IQueryLogger::class, function(ContainerInterface $c) { |
|
880 | 880 | $queryLogger = new QueryLogger(); |
881 | 881 | if ($c->get(SystemConfig::class)->getValue('debug', false)) { |
882 | 882 | // In debug mode, module is being activated by default |
@@ -891,7 +891,7 @@ discard block |
||
891 | 891 | $this->registerDeprecatedAlias('TempManager', TempManager::class); |
892 | 892 | $this->registerAlias(ITempManager::class, TempManager::class); |
893 | 893 | |
894 | - $this->registerService(AppManager::class, function (ContainerInterface $c) { |
|
894 | + $this->registerService(AppManager::class, function(ContainerInterface $c) { |
|
895 | 895 | // TODO: use auto-wiring |
896 | 896 | return new \OC\App\AppManager( |
897 | 897 | $c->get(IUserSession::class), |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | /** @deprecated 19.0.0 */ |
912 | 912 | $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class); |
913 | 913 | |
914 | - $this->registerService(IDateTimeFormatter::class, function (Server $c) { |
|
914 | + $this->registerService(IDateTimeFormatter::class, function(Server $c) { |
|
915 | 915 | $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null); |
916 | 916 | |
917 | 917 | return new DateTimeFormatter( |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | /** @deprecated 19.0.0 */ |
923 | 923 | $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class); |
924 | 924 | |
925 | - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { |
|
925 | + $this->registerService(IUserMountCache::class, function(ContainerInterface $c) { |
|
926 | 926 | $mountCache = new UserMountCache( |
927 | 927 | $c->get(IDBConnection::class), |
928 | 928 | $c->get(IUserManager::class), |
@@ -935,7 +935,7 @@ discard block |
||
935 | 935 | /** @deprecated 19.0.0 */ |
936 | 936 | $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class); |
937 | 937 | |
938 | - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { |
|
938 | + $this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) { |
|
939 | 939 | $loader = \OC\Files\Filesystem::getLoader(); |
940 | 940 | $mountCache = $c->get(IUserMountCache::class); |
941 | 941 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | |
957 | 957 | /** @deprecated 20.0.0 */ |
958 | 958 | $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class); |
959 | - $this->registerService(IBus::class, function (ContainerInterface $c) { |
|
959 | + $this->registerService(IBus::class, function(ContainerInterface $c) { |
|
960 | 960 | $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus'); |
961 | 961 | if ($busClass) { |
962 | 962 | [$app, $class] = explode('::', $busClass, 2); |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class); |
978 | 978 | /** @deprecated 19.0.0 */ |
979 | 979 | $this->registerDeprecatedAlias('Throttler', Throttler::class); |
980 | - $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) { |
|
980 | + $this->registerService('IntegrityCodeChecker', function(ContainerInterface $c) { |
|
981 | 981 | // IConfig and IAppManager requires a working database. This code |
982 | 982 | // might however be called when ownCloud is not yet setup. |
983 | 983 | if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $c->get(IMimeTypeDetector::class) |
999 | 999 | ); |
1000 | 1000 | }); |
1001 | - $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) { |
|
1001 | + $this->registerService(\OCP\IRequest::class, function(ContainerInterface $c) { |
|
1002 | 1002 | if (isset($this['urlParams'])) { |
1003 | 1003 | $urlParams = $this['urlParams']; |
1004 | 1004 | } else { |
@@ -1035,7 +1035,7 @@ discard block |
||
1035 | 1035 | /** @deprecated 19.0.0 */ |
1036 | 1036 | $this->registerDeprecatedAlias('Request', \OCP\IRequest::class); |
1037 | 1037 | |
1038 | - $this->registerService(IMailer::class, function (Server $c) { |
|
1038 | + $this->registerService(IMailer::class, function(Server $c) { |
|
1039 | 1039 | return new Mailer( |
1040 | 1040 | $c->get(\OCP\IConfig::class), |
1041 | 1041 | $c->get(ILogger::class), |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | /** @deprecated 21.0.0 */ |
1053 | 1053 | $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class); |
1054 | 1054 | |
1055 | - $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) { |
|
1055 | + $this->registerService(ILDAPProviderFactory::class, function(ContainerInterface $c) { |
|
1056 | 1056 | $config = $c->get(\OCP\IConfig::class); |
1057 | 1057 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
1058 | 1058 | if (is_null($factoryClass) || !class_exists($factoryClass)) { |
@@ -1061,11 +1061,11 @@ discard block |
||
1061 | 1061 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
1062 | 1062 | return new $factoryClass($this); |
1063 | 1063 | }); |
1064 | - $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) { |
|
1064 | + $this->registerService(ILDAPProvider::class, function(ContainerInterface $c) { |
|
1065 | 1065 | $factory = $c->get(ILDAPProviderFactory::class); |
1066 | 1066 | return $factory->getLDAPProvider(); |
1067 | 1067 | }); |
1068 | - $this->registerService(ILockingProvider::class, function (ContainerInterface $c) { |
|
1068 | + $this->registerService(ILockingProvider::class, function(ContainerInterface $c) { |
|
1069 | 1069 | $ini = $c->get(IniGetWrapper::class); |
1070 | 1070 | $config = $c->get(\OCP\IConfig::class); |
1071 | 1071 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
@@ -1093,12 +1093,12 @@ discard block |
||
1093 | 1093 | /** @deprecated 19.0.0 */ |
1094 | 1094 | $this->registerDeprecatedAlias('MountManager', IMountManager::class); |
1095 | 1095 | |
1096 | - $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) { |
|
1096 | + $this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) { |
|
1097 | 1097 | return new \OC\Files\Type\Detection( |
1098 | 1098 | $c->get(IURLGenerator::class), |
1099 | 1099 | $c->get(ILogger::class), |
1100 | 1100 | \OC::$configDir, |
1101 | - \OC::$SERVERROOT . '/resources/config/' |
|
1101 | + \OC::$SERVERROOT.'/resources/config/' |
|
1102 | 1102 | ); |
1103 | 1103 | }); |
1104 | 1104 | /** @deprecated 19.0.0 */ |
@@ -1107,19 +1107,19 @@ discard block |
||
1107 | 1107 | $this->registerAlias(IMimeTypeLoader::class, Loader::class); |
1108 | 1108 | /** @deprecated 19.0.0 */ |
1109 | 1109 | $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class); |
1110 | - $this->registerService(BundleFetcher::class, function () { |
|
1110 | + $this->registerService(BundleFetcher::class, function() { |
|
1111 | 1111 | return new BundleFetcher($this->getL10N('lib')); |
1112 | 1112 | }); |
1113 | 1113 | $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); |
1114 | 1114 | /** @deprecated 19.0.0 */ |
1115 | 1115 | $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class); |
1116 | 1116 | |
1117 | - $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { |
|
1117 | + $this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) { |
|
1118 | 1118 | $manager = new CapabilitiesManager($c->get(LoggerInterface::class)); |
1119 | - $manager->registerCapability(function () use ($c) { |
|
1119 | + $manager->registerCapability(function() use ($c) { |
|
1120 | 1120 | return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class)); |
1121 | 1121 | }); |
1122 | - $manager->registerCapability(function () use ($c) { |
|
1122 | + $manager->registerCapability(function() use ($c) { |
|
1123 | 1123 | return $c->get(\OC\Security\Bruteforce\Capabilities::class); |
1124 | 1124 | }); |
1125 | 1125 | return $manager; |
@@ -1127,14 +1127,14 @@ discard block |
||
1127 | 1127 | /** @deprecated 19.0.0 */ |
1128 | 1128 | $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class); |
1129 | 1129 | |
1130 | - $this->registerService(ICommentsManager::class, function (Server $c) { |
|
1130 | + $this->registerService(ICommentsManager::class, function(Server $c) { |
|
1131 | 1131 | $config = $c->get(\OCP\IConfig::class); |
1132 | 1132 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
1133 | 1133 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
1134 | 1134 | $factory = new $factoryClass($this); |
1135 | 1135 | $manager = $factory->getManager(); |
1136 | 1136 | |
1137 | - $manager->registerDisplayNameResolver('user', function ($id) use ($c) { |
|
1137 | + $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
|
1138 | 1138 | $manager = $c->get(IUserManager::class); |
1139 | 1139 | $user = $manager->get($id); |
1140 | 1140 | if (is_null($user)) { |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class); |
1153 | 1153 | |
1154 | 1154 | $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults'); |
1155 | - $this->registerService('ThemingDefaults', function (Server $c) { |
|
1155 | + $this->registerService('ThemingDefaults', function(Server $c) { |
|
1156 | 1156 | /* |
1157 | 1157 | * Dark magic for autoloader. |
1158 | 1158 | * If we do a class_exists it will try to load the class which will |
@@ -1187,7 +1187,7 @@ discard block |
||
1187 | 1187 | } |
1188 | 1188 | return new \OC_Defaults(); |
1189 | 1189 | }); |
1190 | - $this->registerService(JSCombiner::class, function (Server $c) { |
|
1190 | + $this->registerService(JSCombiner::class, function(Server $c) { |
|
1191 | 1191 | return new JSCombiner( |
1192 | 1192 | $c->getAppDataDir('js'), |
1193 | 1193 | $c->get(IURLGenerator::class), |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class); |
1202 | 1202 | $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class); |
1203 | 1203 | |
1204 | - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { |
|
1204 | + $this->registerService('CryptoWrapper', function(ContainerInterface $c) { |
|
1205 | 1205 | // FIXME: Instantiiated here due to cyclic dependency |
1206 | 1206 | $request = new Request( |
1207 | 1207 | [ |
@@ -1228,14 +1228,14 @@ discard block |
||
1228 | 1228 | }); |
1229 | 1229 | /** @deprecated 19.0.0 */ |
1230 | 1230 | $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class); |
1231 | - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { |
|
1231 | + $this->registerService(SessionStorage::class, function(ContainerInterface $c) { |
|
1232 | 1232 | return new SessionStorage($c->get(ISession::class)); |
1233 | 1233 | }); |
1234 | 1234 | $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); |
1235 | 1235 | /** @deprecated 19.0.0 */ |
1236 | 1236 | $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class); |
1237 | 1237 | |
1238 | - $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) { |
|
1238 | + $this->registerService(\OCP\Share\IManager::class, function(IServerContainer $c) { |
|
1239 | 1239 | $config = $c->get(\OCP\IConfig::class); |
1240 | 1240 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
1241 | 1241 | /** @var \OCP\Share\IProviderFactory $factory */ |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | /** @deprecated 19.0.0 */ |
1268 | 1268 | $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class); |
1269 | 1269 | |
1270 | - $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) { |
|
1270 | + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
|
1271 | 1271 | $instance = new Collaboration\Collaborators\Search($c); |
1272 | 1272 | |
1273 | 1273 | // register default plugins |
@@ -1290,33 +1290,33 @@ discard block |
||
1290 | 1290 | |
1291 | 1291 | $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); |
1292 | 1292 | $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); |
1293 | - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { |
|
1293 | + $this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) { |
|
1294 | 1294 | return new \OC\Files\AppData\Factory( |
1295 | 1295 | $c->get(IRootFolder::class), |
1296 | 1296 | $c->get(SystemConfig::class) |
1297 | 1297 | ); |
1298 | 1298 | }); |
1299 | 1299 | |
1300 | - $this->registerService('LockdownManager', function (ContainerInterface $c) { |
|
1301 | - return new LockdownManager(function () use ($c) { |
|
1300 | + $this->registerService('LockdownManager', function(ContainerInterface $c) { |
|
1301 | + return new LockdownManager(function() use ($c) { |
|
1302 | 1302 | return $c->get(ISession::class); |
1303 | 1303 | }); |
1304 | 1304 | }); |
1305 | 1305 | |
1306 | - $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) { |
|
1306 | + $this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) { |
|
1307 | 1307 | return new DiscoveryService( |
1308 | 1308 | $c->get(ICacheFactory::class), |
1309 | 1309 | $c->get(IClientService::class) |
1310 | 1310 | ); |
1311 | 1311 | }); |
1312 | 1312 | |
1313 | - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { |
|
1313 | + $this->registerService(ICloudIdManager::class, function(ContainerInterface $c) { |
|
1314 | 1314 | return new CloudIdManager($c->get(\OCP\Contacts\IManager::class), $c->get(IURLGenerator::class), $c->get(IUserManager::class)); |
1315 | 1315 | }); |
1316 | 1316 | |
1317 | 1317 | $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); |
1318 | 1318 | |
1319 | - $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) { |
|
1319 | + $this->registerService(ICloudFederationProviderManager::class, function(ContainerInterface $c) { |
|
1320 | 1320 | return new CloudFederationProviderManager( |
1321 | 1321 | $c->get(IAppManager::class), |
1322 | 1322 | $c->get(IClientService::class), |
@@ -1325,7 +1325,7 @@ discard block |
||
1325 | 1325 | ); |
1326 | 1326 | }); |
1327 | 1327 | |
1328 | - $this->registerService(ICloudFederationFactory::class, function (Server $c) { |
|
1328 | + $this->registerService(ICloudFederationFactory::class, function(Server $c) { |
|
1329 | 1329 | return new CloudFederationFactory(); |
1330 | 1330 | }); |
1331 | 1331 | |
@@ -1337,7 +1337,7 @@ discard block |
||
1337 | 1337 | /** @deprecated 19.0.0 */ |
1338 | 1338 | $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
1339 | 1339 | |
1340 | - $this->registerService(Defaults::class, function (Server $c) { |
|
1340 | + $this->registerService(Defaults::class, function(Server $c) { |
|
1341 | 1341 | return new Defaults( |
1342 | 1342 | $c->getThemingDefaults() |
1343 | 1343 | ); |
@@ -1345,17 +1345,17 @@ discard block |
||
1345 | 1345 | /** @deprecated 19.0.0 */ |
1346 | 1346 | $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class); |
1347 | 1347 | |
1348 | - $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) { |
|
1348 | + $this->registerService(\OCP\ISession::class, function(ContainerInterface $c) { |
|
1349 | 1349 | return $c->get(\OCP\IUserSession::class)->getSession(); |
1350 | 1350 | }, false); |
1351 | 1351 | |
1352 | - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { |
|
1352 | + $this->registerService(IShareHelper::class, function(ContainerInterface $c) { |
|
1353 | 1353 | return new ShareHelper( |
1354 | 1354 | $c->get(\OCP\Share\IManager::class) |
1355 | 1355 | ); |
1356 | 1356 | }); |
1357 | 1357 | |
1358 | - $this->registerService(Installer::class, function (ContainerInterface $c) { |
|
1358 | + $this->registerService(Installer::class, function(ContainerInterface $c) { |
|
1359 | 1359 | return new Installer( |
1360 | 1360 | $c->get(AppFetcher::class), |
1361 | 1361 | $c->get(IClientService::class), |
@@ -1366,11 +1366,11 @@ discard block |
||
1366 | 1366 | ); |
1367 | 1367 | }); |
1368 | 1368 | |
1369 | - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { |
|
1369 | + $this->registerService(IApiFactory::class, function(ContainerInterface $c) { |
|
1370 | 1370 | return new ApiFactory($c->get(IClientService::class)); |
1371 | 1371 | }); |
1372 | 1372 | |
1373 | - $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { |
|
1373 | + $this->registerService(IInstanceFactory::class, function(ContainerInterface $c) { |
|
1374 | 1374 | $memcacheFactory = $c->get(ICacheFactory::class); |
1375 | 1375 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class)); |
1376 | 1376 | }); |
@@ -1427,7 +1427,7 @@ discard block |
||
1427 | 1427 | $dispatcher = $this->get(SymfonyAdapter::class); |
1428 | 1428 | |
1429 | 1429 | // Delete avatar on user deletion |
1430 | - $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) { |
|
1430 | + $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
|
1431 | 1431 | $logger = $this->get(ILogger::class); |
1432 | 1432 | $manager = $this->getAvatarManager(); |
1433 | 1433 | /** @var IUser $user */ |
@@ -1440,11 +1440,11 @@ discard block |
||
1440 | 1440 | // no avatar to remove |
1441 | 1441 | } catch (\Exception $e) { |
1442 | 1442 | // Ignore exceptions |
1443 | - $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
|
1443 | + $logger->info('Could not cleanup avatar of '.$user->getUID()); |
|
1444 | 1444 | } |
1445 | 1445 | }); |
1446 | 1446 | |
1447 | - $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
|
1447 | + $dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) { |
|
1448 | 1448 | $manager = $this->getAvatarManager(); |
1449 | 1449 | /** @var IUser $user */ |
1450 | 1450 | $user = $e->getSubject(); |
@@ -2335,11 +2335,11 @@ discard block |
||
2335 | 2335 | } |
2336 | 2336 | |
2337 | 2337 | private function registerDeprecatedAlias(string $alias, string $target) { |
2338 | - $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) { |
|
2338 | + $this->registerService($alias, function(ContainerInterface $container) use ($target, $alias) { |
|
2339 | 2339 | try { |
2340 | 2340 | /** @var ILogger $logger */ |
2341 | 2341 | $logger = $container->get(ILogger::class); |
2342 | - $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2342 | + $logger->debug('The requested alias "'.$alias.'" is deprecated. Please request "'.$target.'" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']); |
|
2343 | 2343 | } catch (ContainerExceptionInterface $e) { |
2344 | 2344 | // Could not get logger. Continue |
2345 | 2345 | } |
@@ -25,83 +25,83 @@ |
||
25 | 25 | use OCP\Diagnostics\IEvent; |
26 | 26 | |
27 | 27 | class Event implements IEvent { |
28 | - /** |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $id; |
|
28 | + /** |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $id; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var float |
|
35 | - */ |
|
36 | - protected $start; |
|
33 | + /** |
|
34 | + * @var float |
|
35 | + */ |
|
36 | + protected $start; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var float |
|
40 | - */ |
|
41 | - protected $end; |
|
38 | + /** |
|
39 | + * @var float |
|
40 | + */ |
|
41 | + protected $end; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $description; |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $description; |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $id |
|
50 | - * @param string $description |
|
51 | - * @param float $start |
|
52 | - */ |
|
53 | - public function __construct($id, $description, $start) { |
|
54 | - $this->id = $id; |
|
55 | - $this->description = $description; |
|
56 | - $this->start = $start; |
|
57 | - } |
|
48 | + /** |
|
49 | + * @param string $id |
|
50 | + * @param string $description |
|
51 | + * @param float $start |
|
52 | + */ |
|
53 | + public function __construct($id, $description, $start) { |
|
54 | + $this->id = $id; |
|
55 | + $this->description = $description; |
|
56 | + $this->start = $start; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @param float $time |
|
61 | - */ |
|
62 | - public function end($time) { |
|
63 | - $this->end = $time; |
|
64 | - } |
|
59 | + /** |
|
60 | + * @param float $time |
|
61 | + */ |
|
62 | + public function end($time) { |
|
63 | + $this->end = $time; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return float |
|
68 | - */ |
|
69 | - public function getStart() { |
|
70 | - return $this->start; |
|
71 | - } |
|
66 | + /** |
|
67 | + * @return float |
|
68 | + */ |
|
69 | + public function getStart() { |
|
70 | + return $this->start; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function getId() { |
|
77 | - return $this->id; |
|
78 | - } |
|
73 | + /** |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function getId() { |
|
77 | + return $this->id; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function getDescription() { |
|
84 | - return $this->description; |
|
85 | - } |
|
80 | + /** |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function getDescription() { |
|
84 | + return $this->description; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return float |
|
89 | - */ |
|
90 | - public function getEnd() { |
|
91 | - return $this->end; |
|
92 | - } |
|
87 | + /** |
|
88 | + * @return float |
|
89 | + */ |
|
90 | + public function getEnd() { |
|
91 | + return $this->end; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * @return float |
|
96 | - */ |
|
97 | - public function getDuration() { |
|
98 | - if (!$this->end) { |
|
99 | - $this->end = microtime(true); |
|
100 | - } |
|
101 | - return $this->end - $this->start; |
|
102 | - } |
|
94 | + /** |
|
95 | + * @return float |
|
96 | + */ |
|
97 | + public function getDuration() { |
|
98 | + if (!$this->end) { |
|
99 | + $this->end = microtime(true); |
|
100 | + } |
|
101 | + return $this->end - $this->start; |
|
102 | + } |
|
103 | 103 | |
104 | - public function __toString() { |
|
105 | - return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration(); |
|
106 | - } |
|
104 | + public function __toString() { |
|
105 | + return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration(); |
|
106 | + } |
|
107 | 107 | } |
@@ -102,6 +102,6 @@ |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | public function __toString() { |
105 | - return $this->getId() . ' ' . $this->getDescription() . ' ' . $this->getDuration(); |
|
105 | + return $this->getId().' '.$this->getDescription().' '.$this->getDuration(); |
|
106 | 106 | } |
107 | 107 | } |
@@ -32,104 +32,104 @@ |
||
32 | 32 | |
33 | 33 | class EventLogger implements IEventLogger { |
34 | 34 | |
35 | - /** @var Event[] */ |
|
36 | - private $events = []; |
|
37 | - |
|
38 | - /** @var SystemConfig */ |
|
39 | - private $config; |
|
40 | - |
|
41 | - /** @var LoggerInterface */ |
|
42 | - private $logger; |
|
43 | - |
|
44 | - /** @var Log */ |
|
45 | - private $internalLogger; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var bool - Module needs to be activated by some app |
|
49 | - */ |
|
50 | - private $activated = false; |
|
51 | - |
|
52 | - public function __construct(SystemConfig $config, LoggerInterface $logger, Log $internalLogger) { |
|
53 | - $this->config = $config; |
|
54 | - $this->logger = $logger; |
|
55 | - $this->internalLogger = $internalLogger; |
|
56 | - |
|
57 | - if ($this->isLoggingActivated()) { |
|
58 | - $this->activate(); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - public function isLoggingActivated(): bool { |
|
63 | - if ($this->config->getValue('debug', false)) { |
|
64 | - return true; |
|
65 | - } |
|
66 | - |
|
67 | - $isDebugLevel = $this->internalLogger->getLogLevel([]) === Log::DEBUG; |
|
68 | - $systemValue = (bool)$this->config->getValue('diagnostics.logging', false); |
|
69 | - return $systemValue && $isDebugLevel; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @inheritdoc |
|
74 | - */ |
|
75 | - public function start($id, $description = '') { |
|
76 | - if ($this->activated) { |
|
77 | - $this->events[$id] = new Event($id, $description, microtime(true)); |
|
78 | - $this->writeLog($this->events[$id]); |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @inheritdoc |
|
84 | - */ |
|
85 | - public function end($id) { |
|
86 | - if ($this->activated && isset($this->events[$id])) { |
|
87 | - $timing = $this->events[$id]; |
|
88 | - $timing->end(microtime(true)); |
|
89 | - $this->writeLog($timing); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @inheritdoc |
|
95 | - */ |
|
96 | - public function log($id, $description, $start, $end) { |
|
97 | - if ($this->activated) { |
|
98 | - $this->events[$id] = new Event($id, $description, $start); |
|
99 | - $this->events[$id]->end($end); |
|
100 | - $this->writeLog($this->events[$id]); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @inheritdoc |
|
106 | - */ |
|
107 | - public function getEvents() { |
|
108 | - return $this->events; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @inheritdoc |
|
113 | - */ |
|
114 | - public function activate() { |
|
115 | - $this->activated = true; |
|
116 | - } |
|
117 | - |
|
118 | - private function writeLog(IEvent $event) { |
|
119 | - if ($this->activated) { |
|
120 | - if ($event->getEnd() === null) { |
|
121 | - return; |
|
122 | - } |
|
123 | - $duration = $event->getDuration(); |
|
124 | - $timeInMs = round($duration * 1000, 4); |
|
125 | - |
|
126 | - $loggingMinimum = (int)$this->config->getValue('diagnostics.logging.threshold', 0); |
|
127 | - if ($loggingMinimum > 0 && $timeInMs < $loggingMinimum) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $message = microtime() . ' - ' . $event->getId() . ': ' . $timeInMs . ' (' . $event->getDescription() . ')'; |
|
132 | - $this->logger->debug($message, ['app' => 'diagnostics']); |
|
133 | - } |
|
134 | - } |
|
35 | + /** @var Event[] */ |
|
36 | + private $events = []; |
|
37 | + |
|
38 | + /** @var SystemConfig */ |
|
39 | + private $config; |
|
40 | + |
|
41 | + /** @var LoggerInterface */ |
|
42 | + private $logger; |
|
43 | + |
|
44 | + /** @var Log */ |
|
45 | + private $internalLogger; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var bool - Module needs to be activated by some app |
|
49 | + */ |
|
50 | + private $activated = false; |
|
51 | + |
|
52 | + public function __construct(SystemConfig $config, LoggerInterface $logger, Log $internalLogger) { |
|
53 | + $this->config = $config; |
|
54 | + $this->logger = $logger; |
|
55 | + $this->internalLogger = $internalLogger; |
|
56 | + |
|
57 | + if ($this->isLoggingActivated()) { |
|
58 | + $this->activate(); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + public function isLoggingActivated(): bool { |
|
63 | + if ($this->config->getValue('debug', false)) { |
|
64 | + return true; |
|
65 | + } |
|
66 | + |
|
67 | + $isDebugLevel = $this->internalLogger->getLogLevel([]) === Log::DEBUG; |
|
68 | + $systemValue = (bool)$this->config->getValue('diagnostics.logging', false); |
|
69 | + return $systemValue && $isDebugLevel; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @inheritdoc |
|
74 | + */ |
|
75 | + public function start($id, $description = '') { |
|
76 | + if ($this->activated) { |
|
77 | + $this->events[$id] = new Event($id, $description, microtime(true)); |
|
78 | + $this->writeLog($this->events[$id]); |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @inheritdoc |
|
84 | + */ |
|
85 | + public function end($id) { |
|
86 | + if ($this->activated && isset($this->events[$id])) { |
|
87 | + $timing = $this->events[$id]; |
|
88 | + $timing->end(microtime(true)); |
|
89 | + $this->writeLog($timing); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @inheritdoc |
|
95 | + */ |
|
96 | + public function log($id, $description, $start, $end) { |
|
97 | + if ($this->activated) { |
|
98 | + $this->events[$id] = new Event($id, $description, $start); |
|
99 | + $this->events[$id]->end($end); |
|
100 | + $this->writeLog($this->events[$id]); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @inheritdoc |
|
106 | + */ |
|
107 | + public function getEvents() { |
|
108 | + return $this->events; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @inheritdoc |
|
113 | + */ |
|
114 | + public function activate() { |
|
115 | + $this->activated = true; |
|
116 | + } |
|
117 | + |
|
118 | + private function writeLog(IEvent $event) { |
|
119 | + if ($this->activated) { |
|
120 | + if ($event->getEnd() === null) { |
|
121 | + return; |
|
122 | + } |
|
123 | + $duration = $event->getDuration(); |
|
124 | + $timeInMs = round($duration * 1000, 4); |
|
125 | + |
|
126 | + $loggingMinimum = (int)$this->config->getValue('diagnostics.logging.threshold', 0); |
|
127 | + if ($loggingMinimum > 0 && $timeInMs < $loggingMinimum) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $message = microtime() . ' - ' . $event->getId() . ': ' . $timeInMs . ' (' . $event->getDescription() . ')'; |
|
132 | + $this->logger->debug($message, ['app' => 'diagnostics']); |
|
133 | + } |
|
134 | + } |
|
135 | 135 | } |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | $isDebugLevel = $this->internalLogger->getLogLevel([]) === Log::DEBUG; |
68 | - $systemValue = (bool)$this->config->getValue('diagnostics.logging', false); |
|
68 | + $systemValue = (bool) $this->config->getValue('diagnostics.logging', false); |
|
69 | 69 | return $systemValue && $isDebugLevel; |
70 | 70 | } |
71 | 71 | |
@@ -123,12 +123,12 @@ discard block |
||
123 | 123 | $duration = $event->getDuration(); |
124 | 124 | $timeInMs = round($duration * 1000, 4); |
125 | 125 | |
126 | - $loggingMinimum = (int)$this->config->getValue('diagnostics.logging.threshold', 0); |
|
126 | + $loggingMinimum = (int) $this->config->getValue('diagnostics.logging.threshold', 0); |
|
127 | 127 | if ($loggingMinimum > 0 && $timeInMs < $loggingMinimum) { |
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
131 | - $message = microtime() . ' - ' . $event->getId() . ': ' . $timeInMs . ' (' . $event->getDescription() . ')'; |
|
131 | + $message = microtime().' - '.$event->getId().': '.$timeInMs.' ('.$event->getDescription().')'; |
|
132 | 132 | $this->logger->debug($message, ['app' => 'diagnostics']); |
133 | 133 | } |
134 | 134 | } |
@@ -47,164 +47,164 @@ |
||
47 | 47 | |
48 | 48 | class Coordinator { |
49 | 49 | |
50 | - /** @var IServerContainer */ |
|
51 | - private $serverContainer; |
|
52 | - |
|
53 | - /** @var Registry */ |
|
54 | - private $registry; |
|
55 | - |
|
56 | - /** @var IManager */ |
|
57 | - private $dashboardManager; |
|
58 | - |
|
59 | - /** @var IEventDispatcher */ |
|
60 | - private $eventDispatcher; |
|
61 | - |
|
62 | - /** @var IEventLogger */ |
|
63 | - private $eventLogger; |
|
64 | - |
|
65 | - /** @var LoggerInterface */ |
|
66 | - private $logger; |
|
67 | - |
|
68 | - /** @var RegistrationContext|null */ |
|
69 | - private $registrationContext; |
|
70 | - |
|
71 | - /** @var string[] */ |
|
72 | - private $bootedApps = []; |
|
73 | - |
|
74 | - public function __construct( |
|
75 | - IServerContainer $container, |
|
76 | - Registry $registry, |
|
77 | - IManager $dashboardManager, |
|
78 | - IEventDispatcher $eventListener, |
|
79 | - IEventLogger $eventLogger, |
|
80 | - LoggerInterface $logger |
|
81 | - ) { |
|
82 | - $this->serverContainer = $container; |
|
83 | - $this->registry = $registry; |
|
84 | - $this->dashboardManager = $dashboardManager; |
|
85 | - $this->eventDispatcher = $eventListener; |
|
86 | - $this->eventLogger = $eventLogger; |
|
87 | - $this->logger = $logger; |
|
88 | - } |
|
89 | - |
|
90 | - public function runInitialRegistration(): void { |
|
91 | - $this->registerApps(OC_App::getEnabledApps()); |
|
92 | - } |
|
93 | - |
|
94 | - public function runLazyRegistration(string $appId): void { |
|
95 | - $this->registerApps([$appId]); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string[] $appIds |
|
100 | - */ |
|
101 | - private function registerApps(array $appIds): void { |
|
102 | - if ($this->registrationContext === null) { |
|
103 | - $this->registrationContext = new RegistrationContext($this->logger); |
|
104 | - } |
|
105 | - $apps = []; |
|
106 | - foreach ($appIds as $appId) { |
|
107 | - /* |
|
50 | + /** @var IServerContainer */ |
|
51 | + private $serverContainer; |
|
52 | + |
|
53 | + /** @var Registry */ |
|
54 | + private $registry; |
|
55 | + |
|
56 | + /** @var IManager */ |
|
57 | + private $dashboardManager; |
|
58 | + |
|
59 | + /** @var IEventDispatcher */ |
|
60 | + private $eventDispatcher; |
|
61 | + |
|
62 | + /** @var IEventLogger */ |
|
63 | + private $eventLogger; |
|
64 | + |
|
65 | + /** @var LoggerInterface */ |
|
66 | + private $logger; |
|
67 | + |
|
68 | + /** @var RegistrationContext|null */ |
|
69 | + private $registrationContext; |
|
70 | + |
|
71 | + /** @var string[] */ |
|
72 | + private $bootedApps = []; |
|
73 | + |
|
74 | + public function __construct( |
|
75 | + IServerContainer $container, |
|
76 | + Registry $registry, |
|
77 | + IManager $dashboardManager, |
|
78 | + IEventDispatcher $eventListener, |
|
79 | + IEventLogger $eventLogger, |
|
80 | + LoggerInterface $logger |
|
81 | + ) { |
|
82 | + $this->serverContainer = $container; |
|
83 | + $this->registry = $registry; |
|
84 | + $this->dashboardManager = $dashboardManager; |
|
85 | + $this->eventDispatcher = $eventListener; |
|
86 | + $this->eventLogger = $eventLogger; |
|
87 | + $this->logger = $logger; |
|
88 | + } |
|
89 | + |
|
90 | + public function runInitialRegistration(): void { |
|
91 | + $this->registerApps(OC_App::getEnabledApps()); |
|
92 | + } |
|
93 | + |
|
94 | + public function runLazyRegistration(string $appId): void { |
|
95 | + $this->registerApps([$appId]); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string[] $appIds |
|
100 | + */ |
|
101 | + private function registerApps(array $appIds): void { |
|
102 | + if ($this->registrationContext === null) { |
|
103 | + $this->registrationContext = new RegistrationContext($this->logger); |
|
104 | + } |
|
105 | + $apps = []; |
|
106 | + foreach ($appIds as $appId) { |
|
107 | + /* |
|
108 | 108 | * First, we have to enable the app's autoloader |
109 | 109 | * |
110 | 110 | * @todo use $this->appManager->getAppPath($appId) here |
111 | 111 | */ |
112 | - $path = OC_App::getAppPath($appId); |
|
113 | - if ($path === false) { |
|
114 | - // Ignore |
|
115 | - continue; |
|
116 | - } |
|
117 | - OC_App::registerAutoloading($appId, $path); |
|
118 | - |
|
119 | - /* |
|
112 | + $path = OC_App::getAppPath($appId); |
|
113 | + if ($path === false) { |
|
114 | + // Ignore |
|
115 | + continue; |
|
116 | + } |
|
117 | + OC_App::registerAutoloading($appId, $path); |
|
118 | + |
|
119 | + /* |
|
120 | 120 | * Next we check if there is an application class and it implements |
121 | 121 | * the \OCP\AppFramework\Bootstrap\IBootstrap interface |
122 | 122 | */ |
123 | - $appNameSpace = App::buildAppNamespace($appId); |
|
124 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
125 | - try { |
|
126 | - if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
|
127 | - try { |
|
128 | - /** @var IBootstrap|App $application */ |
|
129 | - $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); |
|
130 | - } catch (QueryException $e) { |
|
131 | - // Weird, but ok |
|
132 | - continue; |
|
133 | - } |
|
134 | - |
|
135 | - $this->eventLogger->start('bootstrap:register_app_' . $appId, ''); |
|
136 | - $application->register($this->registrationContext->for($appId)); |
|
137 | - $this->eventLogger->end('bootstrap:register_app_' . $appId); |
|
138 | - } |
|
139 | - } catch (Throwable $e) { |
|
140 | - $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ |
|
141 | - 'exception' => $e, |
|
142 | - 'app' => $appId, |
|
143 | - ]); |
|
144 | - continue; |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Now that all register methods have been called, we can delegate the registrations |
|
150 | - * to the actual services |
|
151 | - */ |
|
152 | - $this->registrationContext->delegateCapabilityRegistrations($apps); |
|
153 | - $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); |
|
154 | - $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager); |
|
155 | - $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); |
|
156 | - $this->registrationContext->delegateContainerRegistrations($apps); |
|
157 | - $this->registrationContext->delegateMiddlewareRegistrations($apps); |
|
158 | - } |
|
159 | - |
|
160 | - public function getRegistrationContext(): ?RegistrationContext { |
|
161 | - return $this->registrationContext; |
|
162 | - } |
|
163 | - |
|
164 | - public function bootApp(string $appId): void { |
|
165 | - if (isset($this->bootedApps[$appId])) { |
|
166 | - return; |
|
167 | - } |
|
168 | - $this->bootedApps[$appId] = true; |
|
169 | - |
|
170 | - $appNameSpace = App::buildAppNamespace($appId); |
|
171 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
172 | - if (!class_exists($applicationClassName)) { |
|
173 | - // Nothing to boot |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - /* |
|
123 | + $appNameSpace = App::buildAppNamespace($appId); |
|
124 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
125 | + try { |
|
126 | + if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
|
127 | + try { |
|
128 | + /** @var IBootstrap|App $application */ |
|
129 | + $apps[$appId] = $application = $this->serverContainer->query($applicationClassName); |
|
130 | + } catch (QueryException $e) { |
|
131 | + // Weird, but ok |
|
132 | + continue; |
|
133 | + } |
|
134 | + |
|
135 | + $this->eventLogger->start('bootstrap:register_app_' . $appId, ''); |
|
136 | + $application->register($this->registrationContext->for($appId)); |
|
137 | + $this->eventLogger->end('bootstrap:register_app_' . $appId); |
|
138 | + } |
|
139 | + } catch (Throwable $e) { |
|
140 | + $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ |
|
141 | + 'exception' => $e, |
|
142 | + 'app' => $appId, |
|
143 | + ]); |
|
144 | + continue; |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Now that all register methods have been called, we can delegate the registrations |
|
150 | + * to the actual services |
|
151 | + */ |
|
152 | + $this->registrationContext->delegateCapabilityRegistrations($apps); |
|
153 | + $this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry); |
|
154 | + $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager); |
|
155 | + $this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher); |
|
156 | + $this->registrationContext->delegateContainerRegistrations($apps); |
|
157 | + $this->registrationContext->delegateMiddlewareRegistrations($apps); |
|
158 | + } |
|
159 | + |
|
160 | + public function getRegistrationContext(): ?RegistrationContext { |
|
161 | + return $this->registrationContext; |
|
162 | + } |
|
163 | + |
|
164 | + public function bootApp(string $appId): void { |
|
165 | + if (isset($this->bootedApps[$appId])) { |
|
166 | + return; |
|
167 | + } |
|
168 | + $this->bootedApps[$appId] = true; |
|
169 | + |
|
170 | + $appNameSpace = App::buildAppNamespace($appId); |
|
171 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
172 | + if (!class_exists($applicationClassName)) { |
|
173 | + // Nothing to boot |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + /* |
|
178 | 178 | * Now it is time to fetch an instance of the App class. For classes |
179 | 179 | * that implement \OCP\AppFramework\Bootstrap\IBootstrap this means |
180 | 180 | * the instance was already created for register, but any other |
181 | 181 | * (legacy) code will now do their magic via the constructor. |
182 | 182 | */ |
183 | - $this->eventLogger->start('bootstrap:boot_app_' . $appId, ''); |
|
184 | - try { |
|
185 | - /** @var App $application */ |
|
186 | - $application = $this->serverContainer->query($applicationClassName); |
|
187 | - if ($application instanceof IBootstrap) { |
|
188 | - /** @var BootContext $context */ |
|
189 | - $context = new BootContext($application->getContainer()); |
|
190 | - $application->boot($context); |
|
191 | - } |
|
192 | - } catch (QueryException $e) { |
|
193 | - $this->logger->error("Could not boot $appId: " . $e->getMessage(), [ |
|
194 | - 'exception' => $e, |
|
195 | - ]); |
|
196 | - } catch (Throwable $e) { |
|
197 | - $this->logger->emergency("Could not boot $appId: " . $e->getMessage(), [ |
|
198 | - 'exception' => $e, |
|
199 | - ]); |
|
200 | - } |
|
201 | - $this->eventLogger->end('bootstrap:boot_app_' . $appId); |
|
202 | - } |
|
203 | - |
|
204 | - public function isBootable(string $appId) { |
|
205 | - $appNameSpace = App::buildAppNamespace($appId); |
|
206 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
207 | - return class_exists($applicationClassName) && |
|
208 | - in_array(IBootstrap::class, class_implements($applicationClassName), true); |
|
209 | - } |
|
183 | + $this->eventLogger->start('bootstrap:boot_app_' . $appId, ''); |
|
184 | + try { |
|
185 | + /** @var App $application */ |
|
186 | + $application = $this->serverContainer->query($applicationClassName); |
|
187 | + if ($application instanceof IBootstrap) { |
|
188 | + /** @var BootContext $context */ |
|
189 | + $context = new BootContext($application->getContainer()); |
|
190 | + $application->boot($context); |
|
191 | + } |
|
192 | + } catch (QueryException $e) { |
|
193 | + $this->logger->error("Could not boot $appId: " . $e->getMessage(), [ |
|
194 | + 'exception' => $e, |
|
195 | + ]); |
|
196 | + } catch (Throwable $e) { |
|
197 | + $this->logger->emergency("Could not boot $appId: " . $e->getMessage(), [ |
|
198 | + 'exception' => $e, |
|
199 | + ]); |
|
200 | + } |
|
201 | + $this->eventLogger->end('bootstrap:boot_app_' . $appId); |
|
202 | + } |
|
203 | + |
|
204 | + public function isBootable(string $appId) { |
|
205 | + $appNameSpace = App::buildAppNamespace($appId); |
|
206 | + $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
207 | + return class_exists($applicationClassName) && |
|
208 | + in_array(IBootstrap::class, class_implements($applicationClassName), true); |
|
209 | + } |
|
210 | 210 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * the \OCP\AppFramework\Bootstrap\IBootstrap interface |
122 | 122 | */ |
123 | 123 | $appNameSpace = App::buildAppNamespace($appId); |
124 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
124 | + $applicationClassName = $appNameSpace.'\\AppInfo\\Application'; |
|
125 | 125 | try { |
126 | 126 | if (class_exists($applicationClassName) && in_array(IBootstrap::class, class_implements($applicationClassName), true)) { |
127 | 127 | try { |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | continue; |
133 | 133 | } |
134 | 134 | |
135 | - $this->eventLogger->start('bootstrap:register_app_' . $appId, ''); |
|
135 | + $this->eventLogger->start('bootstrap:register_app_'.$appId, ''); |
|
136 | 136 | $application->register($this->registrationContext->for($appId)); |
137 | - $this->eventLogger->end('bootstrap:register_app_' . $appId); |
|
137 | + $this->eventLogger->end('bootstrap:register_app_'.$appId); |
|
138 | 138 | } |
139 | 139 | } catch (Throwable $e) { |
140 | - $this->logger->emergency('Error during app service registration: ' . $e->getMessage(), [ |
|
140 | + $this->logger->emergency('Error during app service registration: '.$e->getMessage(), [ |
|
141 | 141 | 'exception' => $e, |
142 | 142 | 'app' => $appId, |
143 | 143 | ]); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $this->bootedApps[$appId] = true; |
169 | 169 | |
170 | 170 | $appNameSpace = App::buildAppNamespace($appId); |
171 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
171 | + $applicationClassName = $appNameSpace.'\\AppInfo\\Application'; |
|
172 | 172 | if (!class_exists($applicationClassName)) { |
173 | 173 | // Nothing to boot |
174 | 174 | return; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | * the instance was already created for register, but any other |
181 | 181 | * (legacy) code will now do their magic via the constructor. |
182 | 182 | */ |
183 | - $this->eventLogger->start('bootstrap:boot_app_' . $appId, ''); |
|
183 | + $this->eventLogger->start('bootstrap:boot_app_'.$appId, ''); |
|
184 | 184 | try { |
185 | 185 | /** @var App $application */ |
186 | 186 | $application = $this->serverContainer->query($applicationClassName); |
@@ -190,20 +190,20 @@ discard block |
||
190 | 190 | $application->boot($context); |
191 | 191 | } |
192 | 192 | } catch (QueryException $e) { |
193 | - $this->logger->error("Could not boot $appId: " . $e->getMessage(), [ |
|
193 | + $this->logger->error("Could not boot $appId: ".$e->getMessage(), [ |
|
194 | 194 | 'exception' => $e, |
195 | 195 | ]); |
196 | 196 | } catch (Throwable $e) { |
197 | - $this->logger->emergency("Could not boot $appId: " . $e->getMessage(), [ |
|
197 | + $this->logger->emergency("Could not boot $appId: ".$e->getMessage(), [ |
|
198 | 198 | 'exception' => $e, |
199 | 199 | ]); |
200 | 200 | } |
201 | - $this->eventLogger->end('bootstrap:boot_app_' . $appId); |
|
201 | + $this->eventLogger->end('bootstrap:boot_app_'.$appId); |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | public function isBootable(string $appId) { |
205 | 205 | $appNameSpace = App::buildAppNamespace($appId); |
206 | - $applicationClassName = $appNameSpace . '\\AppInfo\\Application'; |
|
206 | + $applicationClassName = $appNameSpace.'\\AppInfo\\Application'; |
|
207 | 207 | return class_exists($applicationClassName) && |
208 | 208 | in_array(IBootstrap::class, class_implements($applicationClassName), true); |
209 | 209 | } |
@@ -49,201 +49,201 @@ |
||
49 | 49 | */ |
50 | 50 | class Dispatcher { |
51 | 51 | |
52 | - /** @var MiddlewareDispatcher */ |
|
53 | - private $middlewareDispatcher; |
|
54 | - |
|
55 | - /** @var Http */ |
|
56 | - private $protocol; |
|
57 | - |
|
58 | - /** @var ControllerMethodReflector */ |
|
59 | - private $reflector; |
|
60 | - |
|
61 | - /** @var IRequest */ |
|
62 | - private $request; |
|
63 | - |
|
64 | - /** @var IConfig */ |
|
65 | - private $config; |
|
66 | - |
|
67 | - /** @var ConnectionAdapter */ |
|
68 | - private $connection; |
|
69 | - |
|
70 | - /** @var LoggerInterface */ |
|
71 | - private $logger; |
|
72 | - |
|
73 | - /** @var IEventLogger */ |
|
74 | - private $eventLogger; |
|
75 | - |
|
76 | - /** |
|
77 | - * @param Http $protocol the http protocol with contains all status headers |
|
78 | - * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
79 | - * runs the middleware |
|
80 | - * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
81 | - * the arguments for the controller |
|
82 | - * @param IRequest $request the incoming request |
|
83 | - * @param IConfig $config |
|
84 | - * @param ConnectionAdapter $connection |
|
85 | - * @param LoggerInterface $logger |
|
86 | - * @param IEventLogger $eventLogger |
|
87 | - */ |
|
88 | - public function __construct(Http $protocol, |
|
89 | - MiddlewareDispatcher $middlewareDispatcher, |
|
90 | - ControllerMethodReflector $reflector, |
|
91 | - IRequest $request, |
|
92 | - IConfig $config, |
|
93 | - ConnectionAdapter $connection, |
|
94 | - LoggerInterface $logger, |
|
95 | - IEventLogger $eventLogger) { |
|
96 | - $this->protocol = $protocol; |
|
97 | - $this->middlewareDispatcher = $middlewareDispatcher; |
|
98 | - $this->reflector = $reflector; |
|
99 | - $this->request = $request; |
|
100 | - $this->config = $config; |
|
101 | - $this->connection = $connection; |
|
102 | - $this->logger = $logger; |
|
103 | - $this->eventLogger = $eventLogger; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Handles a request and calls the dispatcher on the controller |
|
109 | - * @param Controller $controller the controller which will be called |
|
110 | - * @param string $methodName the method name which will be called on |
|
111 | - * the controller |
|
112 | - * @return array $array[0] contains a string with the http main header, |
|
113 | - * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
114 | - * the response output |
|
115 | - * @throws \Exception |
|
116 | - */ |
|
117 | - public function dispatch(Controller $controller, string $methodName): array { |
|
118 | - $out = [null, [], null]; |
|
119 | - |
|
120 | - try { |
|
121 | - // prefill reflector with everything thats needed for the |
|
122 | - // middlewares |
|
123 | - $this->reflector->reflect($controller, $methodName); |
|
124 | - |
|
125 | - $this->middlewareDispatcher->beforeController($controller, |
|
126 | - $methodName); |
|
127 | - |
|
128 | - $databaseStatsBefore = []; |
|
129 | - if ($this->config->getSystemValueBool('debug', false)) { |
|
130 | - $databaseStatsBefore = $this->connection->getInner()->getStats(); |
|
131 | - } |
|
132 | - |
|
133 | - $response = $this->executeController($controller, $methodName); |
|
134 | - |
|
135 | - if (!empty($databaseStatsBefore)) { |
|
136 | - $databaseStatsAfter = $this->connection->getInner()->getStats(); |
|
137 | - $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built']; |
|
138 | - $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; |
|
139 | - |
|
140 | - if ($numBuilt > 50) { |
|
141 | - $this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.', [ |
|
142 | - 'class' => get_class($controller), |
|
143 | - 'method' => $methodName, |
|
144 | - 'count' => $numBuilt, |
|
145 | - ]); |
|
146 | - } |
|
147 | - |
|
148 | - if ($numExecuted > 100) { |
|
149 | - $this->logger->warning('Controller {class}::{method} executed {count} queries.', [ |
|
150 | - 'class' => get_class($controller), |
|
151 | - 'method' => $methodName, |
|
152 | - 'count' => $numExecuted, |
|
153 | - ]); |
|
154 | - } |
|
155 | - } |
|
156 | - |
|
157 | - // if an exception appears, the middleware checks if it can handle the |
|
158 | - // exception and creates a response. If no response is created, it is |
|
159 | - // assumed that theres no middleware who can handle it and the error is |
|
160 | - // thrown again |
|
161 | - } catch (\Exception $exception) { |
|
162 | - $response = $this->middlewareDispatcher->afterException( |
|
163 | - $controller, $methodName, $exception); |
|
164 | - } catch (\Throwable $throwable) { |
|
165 | - $exception = new \Exception($throwable->getMessage() . ' in file \'' . $throwable->getFile() . '\' line ' . $throwable->getLine(), $throwable->getCode(), $throwable); |
|
166 | - $response = $this->middlewareDispatcher->afterException( |
|
167 | - $controller, $methodName, $exception); |
|
168 | - } |
|
169 | - |
|
170 | - $response = $this->middlewareDispatcher->afterController( |
|
171 | - $controller, $methodName, $response); |
|
172 | - |
|
173 | - // depending on the cache object the headers need to be changed |
|
174 | - $out[0] = $this->protocol->getStatusHeader($response->getStatus()); |
|
175 | - $out[1] = array_merge($response->getHeaders()); |
|
176 | - $out[2] = $response->getCookies(); |
|
177 | - $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
178 | - $controller, $methodName, $response->render() |
|
179 | - ); |
|
180 | - $out[4] = $response; |
|
181 | - |
|
182 | - return $out; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Uses the reflected parameters, types and request parameters to execute |
|
188 | - * the controller |
|
189 | - * @param Controller $controller the controller to be executed |
|
190 | - * @param string $methodName the method on the controller that should be executed |
|
191 | - * @return Response |
|
192 | - */ |
|
193 | - private function executeController(Controller $controller, string $methodName): Response { |
|
194 | - $arguments = []; |
|
195 | - |
|
196 | - // valid types that will be casted |
|
197 | - $types = ['int', 'integer', 'bool', 'boolean', 'float']; |
|
198 | - |
|
199 | - foreach ($this->reflector->getParameters() as $param => $default) { |
|
200 | - |
|
201 | - // try to get the parameter from the request object and cast |
|
202 | - // it to the type annotated in the @param annotation |
|
203 | - $value = $this->request->getParam($param, $default); |
|
204 | - $type = $this->reflector->getType($param); |
|
205 | - |
|
206 | - // if this is submitted using GET or a POST form, 'false' should be |
|
207 | - // converted to false |
|
208 | - if (($type === 'bool' || $type === 'boolean') && |
|
209 | - $value === 'false' && |
|
210 | - ( |
|
211 | - $this->request->method === 'GET' || |
|
212 | - strpos($this->request->getHeader('Content-Type'), |
|
213 | - 'application/x-www-form-urlencoded') !== false |
|
214 | - ) |
|
215 | - ) { |
|
216 | - $value = false; |
|
217 | - } elseif ($value !== null && \in_array($type, $types, true)) { |
|
218 | - settype($value, $type); |
|
219 | - } |
|
220 | - |
|
221 | - $arguments[] = $value; |
|
222 | - } |
|
223 | - |
|
224 | - $this->eventLogger->start('controller:' . get_class($controller) . '::' . $methodName, 'App framework controller execution'); |
|
225 | - $response = \call_user_func_array([$controller, $methodName], $arguments); |
|
226 | - $this->eventLogger->end('controller:' . get_class($controller) . '::' . $methodName); |
|
227 | - |
|
228 | - // format response |
|
229 | - if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
230 | - |
|
231 | - // get format from the url format or request format parameter |
|
232 | - $format = $this->request->getParam('format'); |
|
233 | - |
|
234 | - // if none is given try the first Accept header |
|
235 | - if ($format === null) { |
|
236 | - $headers = $this->request->getHeader('Accept'); |
|
237 | - $format = $controller->getResponderByHTTPHeader($headers, null); |
|
238 | - } |
|
239 | - |
|
240 | - if ($format !== null) { |
|
241 | - $response = $controller->buildResponse($response, $format); |
|
242 | - } else { |
|
243 | - $response = $controller->buildResponse($response); |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - return $response; |
|
248 | - } |
|
52 | + /** @var MiddlewareDispatcher */ |
|
53 | + private $middlewareDispatcher; |
|
54 | + |
|
55 | + /** @var Http */ |
|
56 | + private $protocol; |
|
57 | + |
|
58 | + /** @var ControllerMethodReflector */ |
|
59 | + private $reflector; |
|
60 | + |
|
61 | + /** @var IRequest */ |
|
62 | + private $request; |
|
63 | + |
|
64 | + /** @var IConfig */ |
|
65 | + private $config; |
|
66 | + |
|
67 | + /** @var ConnectionAdapter */ |
|
68 | + private $connection; |
|
69 | + |
|
70 | + /** @var LoggerInterface */ |
|
71 | + private $logger; |
|
72 | + |
|
73 | + /** @var IEventLogger */ |
|
74 | + private $eventLogger; |
|
75 | + |
|
76 | + /** |
|
77 | + * @param Http $protocol the http protocol with contains all status headers |
|
78 | + * @param MiddlewareDispatcher $middlewareDispatcher the dispatcher which |
|
79 | + * runs the middleware |
|
80 | + * @param ControllerMethodReflector $reflector the reflector that is used to inject |
|
81 | + * the arguments for the controller |
|
82 | + * @param IRequest $request the incoming request |
|
83 | + * @param IConfig $config |
|
84 | + * @param ConnectionAdapter $connection |
|
85 | + * @param LoggerInterface $logger |
|
86 | + * @param IEventLogger $eventLogger |
|
87 | + */ |
|
88 | + public function __construct(Http $protocol, |
|
89 | + MiddlewareDispatcher $middlewareDispatcher, |
|
90 | + ControllerMethodReflector $reflector, |
|
91 | + IRequest $request, |
|
92 | + IConfig $config, |
|
93 | + ConnectionAdapter $connection, |
|
94 | + LoggerInterface $logger, |
|
95 | + IEventLogger $eventLogger) { |
|
96 | + $this->protocol = $protocol; |
|
97 | + $this->middlewareDispatcher = $middlewareDispatcher; |
|
98 | + $this->reflector = $reflector; |
|
99 | + $this->request = $request; |
|
100 | + $this->config = $config; |
|
101 | + $this->connection = $connection; |
|
102 | + $this->logger = $logger; |
|
103 | + $this->eventLogger = $eventLogger; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Handles a request and calls the dispatcher on the controller |
|
109 | + * @param Controller $controller the controller which will be called |
|
110 | + * @param string $methodName the method name which will be called on |
|
111 | + * the controller |
|
112 | + * @return array $array[0] contains a string with the http main header, |
|
113 | + * $array[1] contains headers in the form: $key => value, $array[2] contains |
|
114 | + * the response output |
|
115 | + * @throws \Exception |
|
116 | + */ |
|
117 | + public function dispatch(Controller $controller, string $methodName): array { |
|
118 | + $out = [null, [], null]; |
|
119 | + |
|
120 | + try { |
|
121 | + // prefill reflector with everything thats needed for the |
|
122 | + // middlewares |
|
123 | + $this->reflector->reflect($controller, $methodName); |
|
124 | + |
|
125 | + $this->middlewareDispatcher->beforeController($controller, |
|
126 | + $methodName); |
|
127 | + |
|
128 | + $databaseStatsBefore = []; |
|
129 | + if ($this->config->getSystemValueBool('debug', false)) { |
|
130 | + $databaseStatsBefore = $this->connection->getInner()->getStats(); |
|
131 | + } |
|
132 | + |
|
133 | + $response = $this->executeController($controller, $methodName); |
|
134 | + |
|
135 | + if (!empty($databaseStatsBefore)) { |
|
136 | + $databaseStatsAfter = $this->connection->getInner()->getStats(); |
|
137 | + $numBuilt = $databaseStatsAfter['built'] - $databaseStatsBefore['built']; |
|
138 | + $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; |
|
139 | + |
|
140 | + if ($numBuilt > 50) { |
|
141 | + $this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.', [ |
|
142 | + 'class' => get_class($controller), |
|
143 | + 'method' => $methodName, |
|
144 | + 'count' => $numBuilt, |
|
145 | + ]); |
|
146 | + } |
|
147 | + |
|
148 | + if ($numExecuted > 100) { |
|
149 | + $this->logger->warning('Controller {class}::{method} executed {count} queries.', [ |
|
150 | + 'class' => get_class($controller), |
|
151 | + 'method' => $methodName, |
|
152 | + 'count' => $numExecuted, |
|
153 | + ]); |
|
154 | + } |
|
155 | + } |
|
156 | + |
|
157 | + // if an exception appears, the middleware checks if it can handle the |
|
158 | + // exception and creates a response. If no response is created, it is |
|
159 | + // assumed that theres no middleware who can handle it and the error is |
|
160 | + // thrown again |
|
161 | + } catch (\Exception $exception) { |
|
162 | + $response = $this->middlewareDispatcher->afterException( |
|
163 | + $controller, $methodName, $exception); |
|
164 | + } catch (\Throwable $throwable) { |
|
165 | + $exception = new \Exception($throwable->getMessage() . ' in file \'' . $throwable->getFile() . '\' line ' . $throwable->getLine(), $throwable->getCode(), $throwable); |
|
166 | + $response = $this->middlewareDispatcher->afterException( |
|
167 | + $controller, $methodName, $exception); |
|
168 | + } |
|
169 | + |
|
170 | + $response = $this->middlewareDispatcher->afterController( |
|
171 | + $controller, $methodName, $response); |
|
172 | + |
|
173 | + // depending on the cache object the headers need to be changed |
|
174 | + $out[0] = $this->protocol->getStatusHeader($response->getStatus()); |
|
175 | + $out[1] = array_merge($response->getHeaders()); |
|
176 | + $out[2] = $response->getCookies(); |
|
177 | + $out[3] = $this->middlewareDispatcher->beforeOutput( |
|
178 | + $controller, $methodName, $response->render() |
|
179 | + ); |
|
180 | + $out[4] = $response; |
|
181 | + |
|
182 | + return $out; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Uses the reflected parameters, types and request parameters to execute |
|
188 | + * the controller |
|
189 | + * @param Controller $controller the controller to be executed |
|
190 | + * @param string $methodName the method on the controller that should be executed |
|
191 | + * @return Response |
|
192 | + */ |
|
193 | + private function executeController(Controller $controller, string $methodName): Response { |
|
194 | + $arguments = []; |
|
195 | + |
|
196 | + // valid types that will be casted |
|
197 | + $types = ['int', 'integer', 'bool', 'boolean', 'float']; |
|
198 | + |
|
199 | + foreach ($this->reflector->getParameters() as $param => $default) { |
|
200 | + |
|
201 | + // try to get the parameter from the request object and cast |
|
202 | + // it to the type annotated in the @param annotation |
|
203 | + $value = $this->request->getParam($param, $default); |
|
204 | + $type = $this->reflector->getType($param); |
|
205 | + |
|
206 | + // if this is submitted using GET or a POST form, 'false' should be |
|
207 | + // converted to false |
|
208 | + if (($type === 'bool' || $type === 'boolean') && |
|
209 | + $value === 'false' && |
|
210 | + ( |
|
211 | + $this->request->method === 'GET' || |
|
212 | + strpos($this->request->getHeader('Content-Type'), |
|
213 | + 'application/x-www-form-urlencoded') !== false |
|
214 | + ) |
|
215 | + ) { |
|
216 | + $value = false; |
|
217 | + } elseif ($value !== null && \in_array($type, $types, true)) { |
|
218 | + settype($value, $type); |
|
219 | + } |
|
220 | + |
|
221 | + $arguments[] = $value; |
|
222 | + } |
|
223 | + |
|
224 | + $this->eventLogger->start('controller:' . get_class($controller) . '::' . $methodName, 'App framework controller execution'); |
|
225 | + $response = \call_user_func_array([$controller, $methodName], $arguments); |
|
226 | + $this->eventLogger->end('controller:' . get_class($controller) . '::' . $methodName); |
|
227 | + |
|
228 | + // format response |
|
229 | + if ($response instanceof DataResponse || !($response instanceof Response)) { |
|
230 | + |
|
231 | + // get format from the url format or request format parameter |
|
232 | + $format = $this->request->getParam('format'); |
|
233 | + |
|
234 | + // if none is given try the first Accept header |
|
235 | + if ($format === null) { |
|
236 | + $headers = $this->request->getHeader('Accept'); |
|
237 | + $format = $controller->getResponderByHTTPHeader($headers, null); |
|
238 | + } |
|
239 | + |
|
240 | + if ($format !== null) { |
|
241 | + $response = $controller->buildResponse($response, $format); |
|
242 | + } else { |
|
243 | + $response = $controller->buildResponse($response); |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + return $response; |
|
248 | + } |
|
249 | 249 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $response = $this->middlewareDispatcher->afterException( |
163 | 163 | $controller, $methodName, $exception); |
164 | 164 | } catch (\Throwable $throwable) { |
165 | - $exception = new \Exception($throwable->getMessage() . ' in file \'' . $throwable->getFile() . '\' line ' . $throwable->getLine(), $throwable->getCode(), $throwable); |
|
165 | + $exception = new \Exception($throwable->getMessage().' in file \''.$throwable->getFile().'\' line '.$throwable->getLine(), $throwable->getCode(), $throwable); |
|
166 | 166 | $response = $this->middlewareDispatcher->afterException( |
167 | 167 | $controller, $methodName, $exception); |
168 | 168 | } |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | $arguments[] = $value; |
222 | 222 | } |
223 | 223 | |
224 | - $this->eventLogger->start('controller:' . get_class($controller) . '::' . $methodName, 'App framework controller execution'); |
|
224 | + $this->eventLogger->start('controller:'.get_class($controller).'::'.$methodName, 'App framework controller execution'); |
|
225 | 225 | $response = \call_user_func_array([$controller, $methodName], $arguments); |
226 | - $this->eventLogger->end('controller:' . get_class($controller) . '::' . $methodName); |
|
226 | + $this->eventLogger->end('controller:'.get_class($controller).'::'.$methodName); |
|
227 | 227 | |
228 | 228 | // format response |
229 | 229 | if ($response instanceof DataResponse || !($response instanceof Response)) { |
@@ -80,392 +80,392 @@ |
||
80 | 80 | */ |
81 | 81 | class DIContainer extends SimpleContainer implements IAppContainer { |
82 | 82 | |
83 | - /** |
|
84 | - * @var array |
|
85 | - */ |
|
86 | - private $middleWares = []; |
|
87 | - |
|
88 | - /** @var ServerContainer */ |
|
89 | - private $server; |
|
90 | - |
|
91 | - /** |
|
92 | - * Put your class dependencies in here |
|
93 | - * @param string $appName the name of the app |
|
94 | - * @param array $urlParams |
|
95 | - * @param ServerContainer|null $server |
|
96 | - */ |
|
97 | - public function __construct($appName, $urlParams = [], ServerContainer $server = null) { |
|
98 | - parent::__construct(); |
|
99 | - $this['AppName'] = $appName; |
|
100 | - $this['urlParams'] = $urlParams; |
|
101 | - |
|
102 | - $this->registerAlias('Request', IRequest::class); |
|
103 | - |
|
104 | - /** @var \OC\ServerContainer $server */ |
|
105 | - if ($server === null) { |
|
106 | - $server = \OC::$server; |
|
107 | - } |
|
108 | - $this->server = $server; |
|
109 | - $this->server->registerAppContainer($appName, $this); |
|
110 | - |
|
111 | - // aliases |
|
112 | - $this->registerAlias('appName', 'AppName'); |
|
113 | - $this->registerAlias('webRoot', 'WebRoot'); |
|
114 | - $this->registerAlias('userId', 'UserId'); |
|
115 | - |
|
116 | - /** |
|
117 | - * Core services |
|
118 | - */ |
|
119 | - $this->registerService(IOutput::class, function () { |
|
120 | - return new Output($this->getServer()->getWebRoot()); |
|
121 | - }); |
|
122 | - |
|
123 | - $this->registerService(Folder::class, function () { |
|
124 | - return $this->getServer()->getUserFolder(); |
|
125 | - }); |
|
126 | - |
|
127 | - $this->registerService(IAppData::class, function (ContainerInterface $c) { |
|
128 | - return $this->getServer()->getAppDataDir($c->get('AppName')); |
|
129 | - }); |
|
130 | - |
|
131 | - $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
132 | - return $this->getServer()->getL10N($c->get('AppName')); |
|
133 | - }); |
|
134 | - |
|
135 | - // Log wrappers |
|
136 | - $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
137 | - return new ScopedPsrLogger( |
|
138 | - $c->get(PsrLoggerAdapter::class), |
|
139 | - $c->get('AppName') |
|
140 | - ); |
|
141 | - }); |
|
142 | - $this->registerService(ILogger::class, function (ContainerInterface $c) { |
|
143 | - return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); |
|
144 | - }); |
|
145 | - |
|
146 | - $this->registerService(IServerContainer::class, function () { |
|
147 | - return $this->getServer(); |
|
148 | - }); |
|
149 | - $this->registerAlias('ServerContainer', IServerContainer::class); |
|
150 | - |
|
151 | - $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { |
|
152 | - return $c->get(Manager::class); |
|
153 | - }); |
|
154 | - |
|
155 | - $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
156 | - return $c; |
|
157 | - }); |
|
158 | - $this->registerAlias(IAppContainer::class, ContainerInterface::class); |
|
159 | - |
|
160 | - // commonly used attributes |
|
161 | - $this->registerService('UserId', function (ContainerInterface $c) { |
|
162 | - return $c->get(IUserSession::class)->getSession()->get('user_id'); |
|
163 | - }); |
|
164 | - |
|
165 | - $this->registerService('WebRoot', function (ContainerInterface $c) { |
|
166 | - return $c->get(IServerContainer::class)->getWebRoot(); |
|
167 | - }); |
|
168 | - |
|
169 | - $this->registerService('OC_Defaults', function (ContainerInterface $c) { |
|
170 | - return $c->get(IServerContainer::class)->getThemingDefaults(); |
|
171 | - }); |
|
172 | - |
|
173 | - $this->registerService('Protocol', function (ContainerInterface $c) { |
|
174 | - /** @var \OC\Server $server */ |
|
175 | - $server = $c->get(IServerContainer::class); |
|
176 | - $protocol = $server->getRequest()->getHttpProtocol(); |
|
177 | - return new Http($_SERVER, $protocol); |
|
178 | - }); |
|
179 | - |
|
180 | - $this->registerService('Dispatcher', function (ContainerInterface $c) { |
|
181 | - return new Dispatcher( |
|
182 | - $c->get('Protocol'), |
|
183 | - $c->get(MiddlewareDispatcher::class), |
|
184 | - $c->get(IControllerMethodReflector::class), |
|
185 | - $c->get(IRequest::class), |
|
186 | - $c->get(IConfig::class), |
|
187 | - $c->get(IDBConnection::class), |
|
188 | - $c->get(LoggerInterface::class), |
|
189 | - $c->get(EventLogger::class) |
|
190 | - ); |
|
191 | - }); |
|
192 | - |
|
193 | - /** |
|
194 | - * App Framework default arguments |
|
195 | - */ |
|
196 | - $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
197 | - $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
198 | - $this->registerParameter('corsMaxAge', 1728000); |
|
199 | - |
|
200 | - /** |
|
201 | - * Middleware |
|
202 | - */ |
|
203 | - $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
|
204 | - $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
205 | - $server = $this->getServer(); |
|
206 | - |
|
207 | - $dispatcher = new MiddlewareDispatcher(); |
|
208 | - |
|
209 | - $dispatcher->registerMiddleware( |
|
210 | - $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) |
|
211 | - ); |
|
212 | - |
|
213 | - $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); |
|
214 | - |
|
215 | - $dispatcher->registerMiddleware( |
|
216 | - $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
|
217 | - ); |
|
218 | - |
|
219 | - $dispatcher->registerMiddleware( |
|
220 | - new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
221 | - $c->get(IRequest::class), |
|
222 | - $c->get(IControllerMethodReflector::class) |
|
223 | - ) |
|
224 | - ); |
|
225 | - $dispatcher->registerMiddleware( |
|
226 | - new CORSMiddleware( |
|
227 | - $c->get(IRequest::class), |
|
228 | - $c->get(IControllerMethodReflector::class), |
|
229 | - $c->get(IUserSession::class), |
|
230 | - $c->get(OC\Security\Bruteforce\Throttler::class) |
|
231 | - ) |
|
232 | - ); |
|
233 | - $dispatcher->registerMiddleware( |
|
234 | - new OCSMiddleware( |
|
235 | - $c->get(IRequest::class) |
|
236 | - ) |
|
237 | - ); |
|
238 | - |
|
239 | - |
|
240 | - |
|
241 | - $securityMiddleware = new SecurityMiddleware( |
|
242 | - $c->get(IRequest::class), |
|
243 | - $c->get(IControllerMethodReflector::class), |
|
244 | - $c->get(INavigationManager::class), |
|
245 | - $c->get(IURLGenerator::class), |
|
246 | - $server->get(LoggerInterface::class), |
|
247 | - $c->get('AppName'), |
|
248 | - $server->getUserSession()->isLoggedIn(), |
|
249 | - $this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()), |
|
250 | - $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
|
251 | - $server->getAppManager(), |
|
252 | - $server->getL10N('lib'), |
|
253 | - $c->get(AuthorizedGroupMapper::class), |
|
254 | - $server->get(IUserSession::class) |
|
255 | - ); |
|
256 | - $dispatcher->registerMiddleware($securityMiddleware); |
|
257 | - $dispatcher->registerMiddleware( |
|
258 | - new OC\AppFramework\Middleware\Security\CSPMiddleware( |
|
259 | - $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
|
260 | - $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
|
261 | - $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
|
262 | - ) |
|
263 | - ); |
|
264 | - $dispatcher->registerMiddleware( |
|
265 | - $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
|
266 | - ); |
|
267 | - $dispatcher->registerMiddleware( |
|
268 | - new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
269 | - $c->get(IControllerMethodReflector::class), |
|
270 | - $c->get(ISession::class), |
|
271 | - $c->get(IUserSession::class), |
|
272 | - $c->get(ITimeFactory::class) |
|
273 | - ) |
|
274 | - ); |
|
275 | - $dispatcher->registerMiddleware( |
|
276 | - new TwoFactorMiddleware( |
|
277 | - $c->get(OC\Authentication\TwoFactorAuth\Manager::class), |
|
278 | - $c->get(IUserSession::class), |
|
279 | - $c->get(ISession::class), |
|
280 | - $c->get(IURLGenerator::class), |
|
281 | - $c->get(IControllerMethodReflector::class), |
|
282 | - $c->get(IRequest::class) |
|
283 | - ) |
|
284 | - ); |
|
285 | - $dispatcher->registerMiddleware( |
|
286 | - new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
287 | - $c->get(IControllerMethodReflector::class), |
|
288 | - $c->get(OC\Security\Bruteforce\Throttler::class), |
|
289 | - $c->get(IRequest::class) |
|
290 | - ) |
|
291 | - ); |
|
292 | - $dispatcher->registerMiddleware( |
|
293 | - new RateLimitingMiddleware( |
|
294 | - $c->get(IRequest::class), |
|
295 | - $c->get(IUserSession::class), |
|
296 | - $c->get(IControllerMethodReflector::class), |
|
297 | - $c->get(OC\Security\RateLimiting\Limiter::class) |
|
298 | - ) |
|
299 | - ); |
|
300 | - $dispatcher->registerMiddleware( |
|
301 | - new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
302 | - $c->get(IRequest::class), |
|
303 | - $c->get(ISession::class), |
|
304 | - $c->get(\OCP\IConfig::class) |
|
305 | - ) |
|
306 | - ); |
|
307 | - $dispatcher->registerMiddleware( |
|
308 | - $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
309 | - ); |
|
310 | - |
|
311 | - foreach ($this->middleWares as $middleWare) { |
|
312 | - $dispatcher->registerMiddleware($c->get($middleWare)); |
|
313 | - } |
|
314 | - |
|
315 | - $dispatcher->registerMiddleware( |
|
316 | - new SessionMiddleware( |
|
317 | - $c->get(IControllerMethodReflector::class), |
|
318 | - $c->get(ISession::class) |
|
319 | - ) |
|
320 | - ); |
|
321 | - return $dispatcher; |
|
322 | - }); |
|
323 | - |
|
324 | - $this->registerService(IAppConfig::class, function (ContainerInterface $c) { |
|
325 | - return new OC\AppFramework\Services\AppConfig( |
|
326 | - $c->get(IConfig::class), |
|
327 | - $c->get('AppName') |
|
328 | - ); |
|
329 | - }); |
|
330 | - $this->registerService(IInitialState::class, function (ContainerInterface $c) { |
|
331 | - return new OC\AppFramework\Services\InitialState( |
|
332 | - $c->get(IInitialStateService::class), |
|
333 | - $c->get('AppName') |
|
334 | - ); |
|
335 | - }); |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * @return \OCP\IServerContainer |
|
340 | - */ |
|
341 | - public function getServer() { |
|
342 | - return $this->server; |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * @param string $middleWare |
|
347 | - * @return boolean|null |
|
348 | - */ |
|
349 | - public function registerMiddleWare($middleWare) { |
|
350 | - if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
351 | - return false; |
|
352 | - } |
|
353 | - $this->middleWares[] = $middleWare; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * used to return the appname of the set application |
|
358 | - * @return string the name of your application |
|
359 | - */ |
|
360 | - public function getAppName() { |
|
361 | - return $this->query('AppName'); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * @deprecated use IUserSession->isLoggedIn() |
|
366 | - * @return boolean |
|
367 | - */ |
|
368 | - public function isLoggedIn() { |
|
369 | - return \OC::$server->getUserSession()->isLoggedIn(); |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @deprecated use IGroupManager->isAdmin($userId) |
|
374 | - * @return boolean |
|
375 | - */ |
|
376 | - public function isAdminUser() { |
|
377 | - $uid = $this->getUserId(); |
|
378 | - return \OC_User::isAdminUser($uid); |
|
379 | - } |
|
380 | - |
|
381 | - private function getUserId() { |
|
382 | - return $this->getServer()->getSession()->get('user_id'); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * @deprecated use the ILogger instead |
|
387 | - * @param string $message |
|
388 | - * @param string $level |
|
389 | - * @return mixed |
|
390 | - */ |
|
391 | - public function log($message, $level) { |
|
392 | - switch ($level) { |
|
393 | - case 'debug': |
|
394 | - $level = ILogger::DEBUG; |
|
395 | - break; |
|
396 | - case 'info': |
|
397 | - $level = ILogger::INFO; |
|
398 | - break; |
|
399 | - case 'warn': |
|
400 | - $level = ILogger::WARN; |
|
401 | - break; |
|
402 | - case 'fatal': |
|
403 | - $level = ILogger::FATAL; |
|
404 | - break; |
|
405 | - default: |
|
406 | - $level = ILogger::ERROR; |
|
407 | - break; |
|
408 | - } |
|
409 | - \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Register a capability |
|
414 | - * |
|
415 | - * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
416 | - */ |
|
417 | - public function registerCapability($serviceName) { |
|
418 | - $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
419 | - return $this->query($serviceName); |
|
420 | - }); |
|
421 | - } |
|
422 | - |
|
423 | - public function has($id): bool { |
|
424 | - if (parent::has($id)) { |
|
425 | - return true; |
|
426 | - } |
|
427 | - |
|
428 | - if ($this->server->has($id, true)) { |
|
429 | - return true; |
|
430 | - } |
|
431 | - |
|
432 | - return false; |
|
433 | - } |
|
434 | - |
|
435 | - public function query(string $name, bool $autoload = true) { |
|
436 | - try { |
|
437 | - return $this->queryNoFallback($name); |
|
438 | - } catch (QueryException $firstException) { |
|
439 | - try { |
|
440 | - return $this->getServer()->query($name, $autoload); |
|
441 | - } catch (QueryException $secondException) { |
|
442 | - if ($firstException->getCode() === 1) { |
|
443 | - throw $secondException; |
|
444 | - } |
|
445 | - throw $firstException; |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * @param string $name |
|
452 | - * @return mixed |
|
453 | - * @throws QueryException if the query could not be resolved |
|
454 | - */ |
|
455 | - public function queryNoFallback($name) { |
|
456 | - $name = $this->sanitizeName($name); |
|
457 | - |
|
458 | - if ($this->offsetExists($name)) { |
|
459 | - return parent::query($name); |
|
460 | - } elseif ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
461 | - return parent::query($name); |
|
462 | - } elseif ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
463 | - return parent::query($name); |
|
464 | - } elseif (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
465 | - return parent::query($name); |
|
466 | - } |
|
467 | - |
|
468 | - throw new QueryException('Could not resolve ' . $name . '!' . |
|
469 | - ' Class can not be instantiated', 1); |
|
470 | - } |
|
83 | + /** |
|
84 | + * @var array |
|
85 | + */ |
|
86 | + private $middleWares = []; |
|
87 | + |
|
88 | + /** @var ServerContainer */ |
|
89 | + private $server; |
|
90 | + |
|
91 | + /** |
|
92 | + * Put your class dependencies in here |
|
93 | + * @param string $appName the name of the app |
|
94 | + * @param array $urlParams |
|
95 | + * @param ServerContainer|null $server |
|
96 | + */ |
|
97 | + public function __construct($appName, $urlParams = [], ServerContainer $server = null) { |
|
98 | + parent::__construct(); |
|
99 | + $this['AppName'] = $appName; |
|
100 | + $this['urlParams'] = $urlParams; |
|
101 | + |
|
102 | + $this->registerAlias('Request', IRequest::class); |
|
103 | + |
|
104 | + /** @var \OC\ServerContainer $server */ |
|
105 | + if ($server === null) { |
|
106 | + $server = \OC::$server; |
|
107 | + } |
|
108 | + $this->server = $server; |
|
109 | + $this->server->registerAppContainer($appName, $this); |
|
110 | + |
|
111 | + // aliases |
|
112 | + $this->registerAlias('appName', 'AppName'); |
|
113 | + $this->registerAlias('webRoot', 'WebRoot'); |
|
114 | + $this->registerAlias('userId', 'UserId'); |
|
115 | + |
|
116 | + /** |
|
117 | + * Core services |
|
118 | + */ |
|
119 | + $this->registerService(IOutput::class, function () { |
|
120 | + return new Output($this->getServer()->getWebRoot()); |
|
121 | + }); |
|
122 | + |
|
123 | + $this->registerService(Folder::class, function () { |
|
124 | + return $this->getServer()->getUserFolder(); |
|
125 | + }); |
|
126 | + |
|
127 | + $this->registerService(IAppData::class, function (ContainerInterface $c) { |
|
128 | + return $this->getServer()->getAppDataDir($c->get('AppName')); |
|
129 | + }); |
|
130 | + |
|
131 | + $this->registerService(IL10N::class, function (ContainerInterface $c) { |
|
132 | + return $this->getServer()->getL10N($c->get('AppName')); |
|
133 | + }); |
|
134 | + |
|
135 | + // Log wrappers |
|
136 | + $this->registerService(LoggerInterface::class, function (ContainerInterface $c) { |
|
137 | + return new ScopedPsrLogger( |
|
138 | + $c->get(PsrLoggerAdapter::class), |
|
139 | + $c->get('AppName') |
|
140 | + ); |
|
141 | + }); |
|
142 | + $this->registerService(ILogger::class, function (ContainerInterface $c) { |
|
143 | + return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->get('AppName')); |
|
144 | + }); |
|
145 | + |
|
146 | + $this->registerService(IServerContainer::class, function () { |
|
147 | + return $this->getServer(); |
|
148 | + }); |
|
149 | + $this->registerAlias('ServerContainer', IServerContainer::class); |
|
150 | + |
|
151 | + $this->registerService(\OCP\WorkflowEngine\IManager::class, function (ContainerInterface $c) { |
|
152 | + return $c->get(Manager::class); |
|
153 | + }); |
|
154 | + |
|
155 | + $this->registerService(ContainerInterface::class, function (ContainerInterface $c) { |
|
156 | + return $c; |
|
157 | + }); |
|
158 | + $this->registerAlias(IAppContainer::class, ContainerInterface::class); |
|
159 | + |
|
160 | + // commonly used attributes |
|
161 | + $this->registerService('UserId', function (ContainerInterface $c) { |
|
162 | + return $c->get(IUserSession::class)->getSession()->get('user_id'); |
|
163 | + }); |
|
164 | + |
|
165 | + $this->registerService('WebRoot', function (ContainerInterface $c) { |
|
166 | + return $c->get(IServerContainer::class)->getWebRoot(); |
|
167 | + }); |
|
168 | + |
|
169 | + $this->registerService('OC_Defaults', function (ContainerInterface $c) { |
|
170 | + return $c->get(IServerContainer::class)->getThemingDefaults(); |
|
171 | + }); |
|
172 | + |
|
173 | + $this->registerService('Protocol', function (ContainerInterface $c) { |
|
174 | + /** @var \OC\Server $server */ |
|
175 | + $server = $c->get(IServerContainer::class); |
|
176 | + $protocol = $server->getRequest()->getHttpProtocol(); |
|
177 | + return new Http($_SERVER, $protocol); |
|
178 | + }); |
|
179 | + |
|
180 | + $this->registerService('Dispatcher', function (ContainerInterface $c) { |
|
181 | + return new Dispatcher( |
|
182 | + $c->get('Protocol'), |
|
183 | + $c->get(MiddlewareDispatcher::class), |
|
184 | + $c->get(IControllerMethodReflector::class), |
|
185 | + $c->get(IRequest::class), |
|
186 | + $c->get(IConfig::class), |
|
187 | + $c->get(IDBConnection::class), |
|
188 | + $c->get(LoggerInterface::class), |
|
189 | + $c->get(EventLogger::class) |
|
190 | + ); |
|
191 | + }); |
|
192 | + |
|
193 | + /** |
|
194 | + * App Framework default arguments |
|
195 | + */ |
|
196 | + $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH'); |
|
197 | + $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept'); |
|
198 | + $this->registerParameter('corsMaxAge', 1728000); |
|
199 | + |
|
200 | + /** |
|
201 | + * Middleware |
|
202 | + */ |
|
203 | + $this->registerAlias('MiddlewareDispatcher', MiddlewareDispatcher::class); |
|
204 | + $this->registerService(MiddlewareDispatcher::class, function (ContainerInterface $c) { |
|
205 | + $server = $this->getServer(); |
|
206 | + |
|
207 | + $dispatcher = new MiddlewareDispatcher(); |
|
208 | + |
|
209 | + $dispatcher->registerMiddleware( |
|
210 | + $c->get(OC\AppFramework\Middleware\CompressionMiddleware::class) |
|
211 | + ); |
|
212 | + |
|
213 | + $dispatcher->registerMiddleware($c->get(OC\AppFramework\Middleware\NotModifiedMiddleware::class)); |
|
214 | + |
|
215 | + $dispatcher->registerMiddleware( |
|
216 | + $c->get(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class) |
|
217 | + ); |
|
218 | + |
|
219 | + $dispatcher->registerMiddleware( |
|
220 | + new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware( |
|
221 | + $c->get(IRequest::class), |
|
222 | + $c->get(IControllerMethodReflector::class) |
|
223 | + ) |
|
224 | + ); |
|
225 | + $dispatcher->registerMiddleware( |
|
226 | + new CORSMiddleware( |
|
227 | + $c->get(IRequest::class), |
|
228 | + $c->get(IControllerMethodReflector::class), |
|
229 | + $c->get(IUserSession::class), |
|
230 | + $c->get(OC\Security\Bruteforce\Throttler::class) |
|
231 | + ) |
|
232 | + ); |
|
233 | + $dispatcher->registerMiddleware( |
|
234 | + new OCSMiddleware( |
|
235 | + $c->get(IRequest::class) |
|
236 | + ) |
|
237 | + ); |
|
238 | + |
|
239 | + |
|
240 | + |
|
241 | + $securityMiddleware = new SecurityMiddleware( |
|
242 | + $c->get(IRequest::class), |
|
243 | + $c->get(IControllerMethodReflector::class), |
|
244 | + $c->get(INavigationManager::class), |
|
245 | + $c->get(IURLGenerator::class), |
|
246 | + $server->get(LoggerInterface::class), |
|
247 | + $c->get('AppName'), |
|
248 | + $server->getUserSession()->isLoggedIn(), |
|
249 | + $this->getUserId() !== null && $server->getGroupManager()->isAdmin($this->getUserId()), |
|
250 | + $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()), |
|
251 | + $server->getAppManager(), |
|
252 | + $server->getL10N('lib'), |
|
253 | + $c->get(AuthorizedGroupMapper::class), |
|
254 | + $server->get(IUserSession::class) |
|
255 | + ); |
|
256 | + $dispatcher->registerMiddleware($securityMiddleware); |
|
257 | + $dispatcher->registerMiddleware( |
|
258 | + new OC\AppFramework\Middleware\Security\CSPMiddleware( |
|
259 | + $server->query(OC\Security\CSP\ContentSecurityPolicyManager::class), |
|
260 | + $server->query(OC\Security\CSP\ContentSecurityPolicyNonceManager::class), |
|
261 | + $server->query(OC\Security\CSRF\CsrfTokenManager::class) |
|
262 | + ) |
|
263 | + ); |
|
264 | + $dispatcher->registerMiddleware( |
|
265 | + $server->query(OC\AppFramework\Middleware\Security\FeaturePolicyMiddleware::class) |
|
266 | + ); |
|
267 | + $dispatcher->registerMiddleware( |
|
268 | + new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware( |
|
269 | + $c->get(IControllerMethodReflector::class), |
|
270 | + $c->get(ISession::class), |
|
271 | + $c->get(IUserSession::class), |
|
272 | + $c->get(ITimeFactory::class) |
|
273 | + ) |
|
274 | + ); |
|
275 | + $dispatcher->registerMiddleware( |
|
276 | + new TwoFactorMiddleware( |
|
277 | + $c->get(OC\Authentication\TwoFactorAuth\Manager::class), |
|
278 | + $c->get(IUserSession::class), |
|
279 | + $c->get(ISession::class), |
|
280 | + $c->get(IURLGenerator::class), |
|
281 | + $c->get(IControllerMethodReflector::class), |
|
282 | + $c->get(IRequest::class) |
|
283 | + ) |
|
284 | + ); |
|
285 | + $dispatcher->registerMiddleware( |
|
286 | + new OC\AppFramework\Middleware\Security\BruteForceMiddleware( |
|
287 | + $c->get(IControllerMethodReflector::class), |
|
288 | + $c->get(OC\Security\Bruteforce\Throttler::class), |
|
289 | + $c->get(IRequest::class) |
|
290 | + ) |
|
291 | + ); |
|
292 | + $dispatcher->registerMiddleware( |
|
293 | + new RateLimitingMiddleware( |
|
294 | + $c->get(IRequest::class), |
|
295 | + $c->get(IUserSession::class), |
|
296 | + $c->get(IControllerMethodReflector::class), |
|
297 | + $c->get(OC\Security\RateLimiting\Limiter::class) |
|
298 | + ) |
|
299 | + ); |
|
300 | + $dispatcher->registerMiddleware( |
|
301 | + new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware( |
|
302 | + $c->get(IRequest::class), |
|
303 | + $c->get(ISession::class), |
|
304 | + $c->get(\OCP\IConfig::class) |
|
305 | + ) |
|
306 | + ); |
|
307 | + $dispatcher->registerMiddleware( |
|
308 | + $c->get(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class) |
|
309 | + ); |
|
310 | + |
|
311 | + foreach ($this->middleWares as $middleWare) { |
|
312 | + $dispatcher->registerMiddleware($c->get($middleWare)); |
|
313 | + } |
|
314 | + |
|
315 | + $dispatcher->registerMiddleware( |
|
316 | + new SessionMiddleware( |
|
317 | + $c->get(IControllerMethodReflector::class), |
|
318 | + $c->get(ISession::class) |
|
319 | + ) |
|
320 | + ); |
|
321 | + return $dispatcher; |
|
322 | + }); |
|
323 | + |
|
324 | + $this->registerService(IAppConfig::class, function (ContainerInterface $c) { |
|
325 | + return new OC\AppFramework\Services\AppConfig( |
|
326 | + $c->get(IConfig::class), |
|
327 | + $c->get('AppName') |
|
328 | + ); |
|
329 | + }); |
|
330 | + $this->registerService(IInitialState::class, function (ContainerInterface $c) { |
|
331 | + return new OC\AppFramework\Services\InitialState( |
|
332 | + $c->get(IInitialStateService::class), |
|
333 | + $c->get('AppName') |
|
334 | + ); |
|
335 | + }); |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * @return \OCP\IServerContainer |
|
340 | + */ |
|
341 | + public function getServer() { |
|
342 | + return $this->server; |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * @param string $middleWare |
|
347 | + * @return boolean|null |
|
348 | + */ |
|
349 | + public function registerMiddleWare($middleWare) { |
|
350 | + if (in_array($middleWare, $this->middleWares, true) !== false) { |
|
351 | + return false; |
|
352 | + } |
|
353 | + $this->middleWares[] = $middleWare; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * used to return the appname of the set application |
|
358 | + * @return string the name of your application |
|
359 | + */ |
|
360 | + public function getAppName() { |
|
361 | + return $this->query('AppName'); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * @deprecated use IUserSession->isLoggedIn() |
|
366 | + * @return boolean |
|
367 | + */ |
|
368 | + public function isLoggedIn() { |
|
369 | + return \OC::$server->getUserSession()->isLoggedIn(); |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @deprecated use IGroupManager->isAdmin($userId) |
|
374 | + * @return boolean |
|
375 | + */ |
|
376 | + public function isAdminUser() { |
|
377 | + $uid = $this->getUserId(); |
|
378 | + return \OC_User::isAdminUser($uid); |
|
379 | + } |
|
380 | + |
|
381 | + private function getUserId() { |
|
382 | + return $this->getServer()->getSession()->get('user_id'); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * @deprecated use the ILogger instead |
|
387 | + * @param string $message |
|
388 | + * @param string $level |
|
389 | + * @return mixed |
|
390 | + */ |
|
391 | + public function log($message, $level) { |
|
392 | + switch ($level) { |
|
393 | + case 'debug': |
|
394 | + $level = ILogger::DEBUG; |
|
395 | + break; |
|
396 | + case 'info': |
|
397 | + $level = ILogger::INFO; |
|
398 | + break; |
|
399 | + case 'warn': |
|
400 | + $level = ILogger::WARN; |
|
401 | + break; |
|
402 | + case 'fatal': |
|
403 | + $level = ILogger::FATAL; |
|
404 | + break; |
|
405 | + default: |
|
406 | + $level = ILogger::ERROR; |
|
407 | + break; |
|
408 | + } |
|
409 | + \OCP\Util::writeLog($this->getAppName(), $message, $level); |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Register a capability |
|
414 | + * |
|
415 | + * @param string $serviceName e.g. 'OCA\Files\Capabilities' |
|
416 | + */ |
|
417 | + public function registerCapability($serviceName) { |
|
418 | + $this->query('OC\CapabilitiesManager')->registerCapability(function () use ($serviceName) { |
|
419 | + return $this->query($serviceName); |
|
420 | + }); |
|
421 | + } |
|
422 | + |
|
423 | + public function has($id): bool { |
|
424 | + if (parent::has($id)) { |
|
425 | + return true; |
|
426 | + } |
|
427 | + |
|
428 | + if ($this->server->has($id, true)) { |
|
429 | + return true; |
|
430 | + } |
|
431 | + |
|
432 | + return false; |
|
433 | + } |
|
434 | + |
|
435 | + public function query(string $name, bool $autoload = true) { |
|
436 | + try { |
|
437 | + return $this->queryNoFallback($name); |
|
438 | + } catch (QueryException $firstException) { |
|
439 | + try { |
|
440 | + return $this->getServer()->query($name, $autoload); |
|
441 | + } catch (QueryException $secondException) { |
|
442 | + if ($firstException->getCode() === 1) { |
|
443 | + throw $secondException; |
|
444 | + } |
|
445 | + throw $firstException; |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * @param string $name |
|
452 | + * @return mixed |
|
453 | + * @throws QueryException if the query could not be resolved |
|
454 | + */ |
|
455 | + public function queryNoFallback($name) { |
|
456 | + $name = $this->sanitizeName($name); |
|
457 | + |
|
458 | + if ($this->offsetExists($name)) { |
|
459 | + return parent::query($name); |
|
460 | + } elseif ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) { |
|
461 | + return parent::query($name); |
|
462 | + } elseif ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) { |
|
463 | + return parent::query($name); |
|
464 | + } elseif (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) { |
|
465 | + return parent::query($name); |
|
466 | + } |
|
467 | + |
|
468 | + throw new QueryException('Could not resolve ' . $name . '!' . |
|
469 | + ' Class can not be instantiated', 1); |
|
470 | + } |
|
471 | 471 | } |