Migrate Comments to the new bootstrap mechanism
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
This commit is contained in:
parent
69571fb536
commit
0a24d1f8df
|
@ -16,6 +16,7 @@ return array(
|
||||||
'OCA\\Comments\\Controller\\Notifications' => $baseDir . '/../lib/Controller/Notifications.php',
|
'OCA\\Comments\\Controller\\Notifications' => $baseDir . '/../lib/Controller/Notifications.php',
|
||||||
'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php',
|
'OCA\\Comments\\EventHandler' => $baseDir . '/../lib/EventHandler.php',
|
||||||
'OCA\\Comments\\JSSettingsHelper' => $baseDir . '/../lib/JSSettingsHelper.php',
|
'OCA\\Comments\\JSSettingsHelper' => $baseDir . '/../lib/JSSettingsHelper.php',
|
||||||
|
'OCA\\Comments\\Listener\\CommentsEntityEventListener' => $baseDir . '/../lib/Listener/CommentsEntityEventListener.php',
|
||||||
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php',
|
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => $baseDir . '/../lib/Listener/LoadAdditionalScripts.php',
|
||||||
'OCA\\Comments\\Listener\\LoadSidebarScripts' => $baseDir . '/../lib/Listener/LoadSidebarScripts.php',
|
'OCA\\Comments\\Listener\\LoadSidebarScripts' => $baseDir . '/../lib/Listener/LoadSidebarScripts.php',
|
||||||
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
|
'OCA\\Comments\\Notification\\Listener' => $baseDir . '/../lib/Notification/Listener.php',
|
||||||
|
|
|
@ -31,6 +31,7 @@ class ComposerStaticInitComments
|
||||||
'OCA\\Comments\\Controller\\Notifications' => __DIR__ . '/..' . '/../lib/Controller/Notifications.php',
|
'OCA\\Comments\\Controller\\Notifications' => __DIR__ . '/..' . '/../lib/Controller/Notifications.php',
|
||||||
'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php',
|
'OCA\\Comments\\EventHandler' => __DIR__ . '/..' . '/../lib/EventHandler.php',
|
||||||
'OCA\\Comments\\JSSettingsHelper' => __DIR__ . '/..' . '/../lib/JSSettingsHelper.php',
|
'OCA\\Comments\\JSSettingsHelper' => __DIR__ . '/..' . '/../lib/JSSettingsHelper.php',
|
||||||
|
'OCA\\Comments\\Listener\\CommentsEntityEventListener' => __DIR__ . '/..' . '/../lib/Listener/CommentsEntityEventListener.php',
|
||||||
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php',
|
'OCA\\Comments\\Listener\\LoadAdditionalScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadAdditionalScripts.php',
|
||||||
'OCA\\Comments\\Listener\\LoadSidebarScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarScripts.php',
|
'OCA\\Comments\\Listener\\LoadSidebarScripts' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarScripts.php',
|
||||||
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
|
'OCA\\Comments\\Notification\\Listener' => __DIR__ . '/..' . '/../lib/Notification/Listener.php',
|
||||||
|
|
|
@ -31,6 +31,7 @@ use OCA\Comments\Capabilities;
|
||||||
use OCA\Comments\Controller\Notifications;
|
use OCA\Comments\Controller\Notifications;
|
||||||
use OCA\Comments\EventHandler;
|
use OCA\Comments\EventHandler;
|
||||||
use OCA\Comments\JSSettingsHelper;
|
use OCA\Comments\JSSettingsHelper;
|
||||||
|
use OCA\Comments\Listener\CommentsEntityEventListener;
|
||||||
use OCA\Comments\Listener\LoadAdditionalScripts;
|
use OCA\Comments\Listener\LoadAdditionalScripts;
|
||||||
use OCA\Comments\Listener\LoadSidebarScripts;
|
use OCA\Comments\Listener\LoadSidebarScripts;
|
||||||
use OCA\Comments\Notification\Notifier;
|
use OCA\Comments\Notification\Notifier;
|
||||||
|
@ -38,60 +39,55 @@ use OCA\Comments\Search\Provider;
|
||||||
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
use OCA\Files\Event\LoadAdditionalScriptsEvent;
|
||||||
use OCA\Files\Event\LoadSidebar;
|
use OCA\Files\Event\LoadSidebar;
|
||||||
use OCP\AppFramework\App;
|
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\Comments\CommentsEntityEvent;
|
||||||
use OCP\EventDispatcher\IEventDispatcher;
|
use OCP\IServerContainer;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App implements IBootstrap {
|
||||||
public const APP_ID = 'comments';
|
public const APP_ID = 'comments';
|
||||||
|
|
||||||
public function __construct(array $urlParams = []) {
|
public function __construct(array $urlParams = []) {
|
||||||
parent::__construct(self::APP_ID, $urlParams);
|
parent::__construct(self::APP_ID, $urlParams);
|
||||||
$container = $this->getContainer();
|
}
|
||||||
|
|
||||||
$container->registerAlias('NotificationsController', Notifications::class);
|
public function register(IRegistrationContext $context): void {
|
||||||
|
$context->registerCapability(Capabilities::class);
|
||||||
|
|
||||||
$jsSettingsHelper = new JSSettingsHelper($container->getServer());
|
$context->registerServiceAlias('NotificationsController', Notifications::class);
|
||||||
|
|
||||||
|
$context->registerEventListener(
|
||||||
|
LoadAdditionalScriptsEvent::class,
|
||||||
|
LoadAdditionalScripts::class
|
||||||
|
);
|
||||||
|
$context->registerEventListener(
|
||||||
|
LoadSidebar::class,
|
||||||
|
LoadSidebarScripts::class
|
||||||
|
);
|
||||||
|
$context->registerEventListener(
|
||||||
|
CommentsEntityEvent::EVENT_ENTITY,
|
||||||
|
CommentsEntityEventListener::class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function boot(IBootContext $context): void {
|
||||||
|
$this->registerNotifier($context->getServerContainer());
|
||||||
|
$this->registerCommentsEventHandler($context->getServerContainer());
|
||||||
|
|
||||||
|
$jsSettingsHelper = new JSSettingsHelper($context->getServerContainer());
|
||||||
Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
|
Util::connectHook('\OCP\Config', 'js', $jsSettingsHelper, 'extend');
|
||||||
|
|
||||||
$this->register();
|
$context->getServerContainer()->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function register() {
|
protected function registerNotifier(IServerContainer $container) {
|
||||||
$server = $this->getContainer()->getServer();
|
$container->getNotificationManager()->registerNotifierService(Notifier::class);
|
||||||
|
|
||||||
/** @var IEventDispatcher $newDispatcher */
|
|
||||||
$dispatcher = $server->query(IEventDispatcher::class);
|
|
||||||
|
|
||||||
$this->registerEventsScripts($dispatcher);
|
|
||||||
$this->registerDavEntity($dispatcher);
|
|
||||||
$this->registerNotifier();
|
|
||||||
$this->registerCommentsEventHandler();
|
|
||||||
|
|
||||||
$this->getContainer()->registerCapability(Capabilities::class);
|
|
||||||
$server->getSearch()->registerProvider(Provider::class, ['apps' => ['files']]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function registerEventsScripts(IEventDispatcher $dispatcher) {
|
protected function registerCommentsEventHandler(IServerContainer $container) {
|
||||||
$dispatcher->addServiceListener(LoadAdditionalScriptsEvent::class, LoadAdditionalScripts::class);
|
$container->getCommentsManager()->registerEventHandler(function () {
|
||||||
$dispatcher->addServiceListener(LoadSidebar::class, LoadSidebarScripts::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function registerNotifier() {
|
|
||||||
$this->getContainer()->getServer()->getNotificationManager()->registerNotifierService(Notifier::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function registerCommentsEventHandler() {
|
|
||||||
$this->getContainer()->getServer()->getCommentsManager()->registerEventHandler(function () {
|
|
||||||
return $this->getContainer()->query(EventHandler::class);
|
return $this->getContainer()->query(EventHandler::class);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue