Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-06-05 17:17:22 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-06-17 10:22:21 +0300
commit0a24d1f8df52a1f719e45538de72f034b1f9ff83 (patch)
tree0d35e0286c3b47aefdcce114de3cd86dbafb2c40 /apps/comments/lib
parent69571fb536c7ad231ea4e5d350f8112a5923c6e1 (diff)
Migrate Comments to the new bootstrap mechanism
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'apps/comments/lib')
-rw-r--r--apps/comments/lib/AppInfo/Application.php68
-rw-r--r--apps/comments/lib/Listener/CommentsEntityEventListener.php44
2 files changed, 76 insertions, 36 deletions
diff --git a/apps/comments/lib/AppInfo/Application.php b/apps/comments/lib/AppInfo/Application.php
index 7f3235eb62d..8bcf17b2afe 100644
--- a/apps/comments/lib/AppInfo/Application.php
+++ b/apps/comments/lib/AppInfo/Application.php
@@ -31,6 +31,7 @@ use OCA\Comments\Capabilities;
use OCA\Comments\Controller\Notifications;
use OCA\Comments\EventHandler;
use OCA\Comments\JSSettingsHelper;
+use OCA\Comments\Listener\CommentsEntityEventListener;
use OCA\Comments\Listener\LoadAdditionalScripts;
use OCA\Comments\Listener\LoadSidebarScripts;
use OCA\Comments\Notification\Notifier;
@@ -38,60 +39,55 @@ use OCA\Comments\Search\Provider;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCP\AppFramework\App;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
-use OCP\EventDispatcher\IEventDispatcher;
+use OCP\IServerContainer;
use OCP\Util;
-class Application extends App {
+class Application extends App implements IBootstrap {
public const APP_ID = 'comments';
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);
- $container = $this->getContainer();
-
- $container->registerAlias('NotificationsController', Notifications::class);
-
- $jsSettingsHelper = new JSSettingsHelper($container->getServer());
- Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
-
- $this->register();
}
- private function register() {
- $server = $this->getContainer()->getServer();
-
- /** @var IEventDispatcher $newDispatcher */
- $dispatcher = $server->query(IEventDispatcher::class);
+ public function register(IRegistrationContext $context): void {
+ $context->registerCapability(Capabilities::class);
- $this->registerEventsScripts($dispatcher);
- $this->registerDavEntity($dispatcher);
- $this->registerNotifier();
- $this->registerCommentsEventHandler();
+ $context->registerServiceAlias('NotificationsController', Notifications::class);
- $this->getContainer()->registerCapability(Capabilities::class);
- $server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
+ $context->registerEventListener(
+ LoadAdditionalScriptsEvent::class,
+ LoadAdditionalScripts::class
+ );
+ $context->registerEventListener(
+ LoadSidebar::class,
+ LoadSidebarScripts::class
+ );
+ $context->registerEventListener(
+ CommentsEntityEvent::EVENT_ENTITY,
+ CommentsEntityEventListener::class
+ );
}
- protected function registerEventsScripts(IEventDispatcher $dispatcher) {
- $dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class);
- $dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class);
- }
+ public function boot(IBootContext $context): void {
+ $this->registerNotifier($context->getServerContainer());
+ $this->registerCommentsEventHandler($context->getServerContainer());
- protected function registerDavEntity(IEventDispatcher $dispatcher) {
- $dispatcher->addListener(CommentsEntityEvent::EVENT_ENTITY, function (CommentsEntityEvent $event) {
- $event->addEntityCollection('files', function ($name) {
- $nodes = \OC::$server->getUserFolder()->getById((int)$name);
- return !empty($nodes);
- });
- });
+ $jsSettingsHelper = new JSSettingsHelper($context->getServerContainer());
+ Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
+
+ $context->getServerContainer()->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
}
- protected function registerNotifier() {
- $this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
+ protected function registerNotifier(IServerContainer $container) {
+ $container->getNotificationManager()->registerNotifierService(Notifier::class);
}
- protected function registerCommentsEventHandler() {
- $this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () {
+ protected function registerCommentsEventHandler(IServerContainer $container) {
+ $container->getCommentsManager()->registerEventHandler(function () {
return $this->getContainer()->query(EventHandler::class);
});
}
diff --git a/apps/comments/lib/Listener/CommentsEntityEventListener.php b/apps/comments/lib/Listener/CommentsEntityEventListener.php
new file mode 100644
index 00000000000..c08d992405f
--- /dev/null
+++ b/apps/comments/lib/Listener/CommentsEntityEventListener.php
@@ -0,0 +1,44 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace OCA\Comments\Listener;
+
+use OCP\Comments\CommentsEntityEvent;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+
+class CommentsEntityEventListener implements IEventListener {
+ public function handle(Event $event): void {
+ if (!($event instanceof CommentsEntityEvent)) {
+ // Unrelated
+ return;
+ }
+
+ $event->addEntityCollection('files', function ($name) {
+ $nodes = \OC::$server->getUserFolder()->getById((int)$name);
+ return !empty($nodes);
+ });
+ }
+}