move user/group deleted listeners to new event listener service
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
347c29d758
commit
369e9f50f3
|
@ -32,6 +32,8 @@ namespace OCA\Files_External\AppInfo;
|
|||
|
||||
use OCA\Files_External\Config\ConfigAdapter;
|
||||
use OCA\Files_External\Config\UserPlaceholderHandler;
|
||||
use OCA\Files_External\Listener\GroupDeletedListener;
|
||||
use OCA\Files_External\Listener\UserDeletedListener;
|
||||
use OCA\Files_External\Service\DBConfigService;
|
||||
use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
|
||||
use OCA\Files_External\Lib\Auth\Builtin;
|
||||
|
@ -68,8 +70,10 @@ use OCP\AppFramework\Bootstrap\IBootContext;
|
|||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\Files\Config\IMountProviderCollection;
|
||||
use OCP\Group\Events\GroupDeletedEvent;
|
||||
use OCP\IGroup;
|
||||
use OCP\IUser;
|
||||
use OCP\User\Events\UserDeletedEvent;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||
|
||||
|
@ -104,7 +108,8 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
|
|||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
// TODO: Implement register() method.
|
||||
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
|
||||
$context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
|
@ -124,30 +129,6 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
|
|||
$context->injectFn([$this, 'registerListeners']);
|
||||
}
|
||||
|
||||
|
||||
public function registerListeners(EventDispatcherInterface $dispatcher) {
|
||||
$dispatcher->addListener(
|
||||
IUser::class . '::postDelete',
|
||||
function (GenericEvent $event) {
|
||||
/** @var IUser $user */
|
||||
$user = $event->getSubject();
|
||||
/** @var DBConfigService $config */
|
||||
$config = $this->getContainer()->query(DBConfigService::class);
|
||||
$config->modifyMountsOnUserDelete($user->getUID());
|
||||
}
|
||||
);
|
||||
$dispatcher->addListener(
|
||||
IGroup::class . '::postDelete',
|
||||
function (GenericEvent $event) {
|
||||
/** @var IGroup $group */
|
||||
$group = $event->getSubject();
|
||||
/** @var DBConfigService $config */
|
||||
$config = $this->getContainer()->query(DBConfigService::class);
|
||||
$config->modifyMountsOnGroupDelete($group->getGID());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @{inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
|
||||
*
|
||||
* @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\Files_External\Listener;
|
||||
|
||||
use OCA\Files_External\Service\DBConfigService;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\Group\Events\GroupDeletedEvent;
|
||||
|
||||
class GroupDeletedListener implements IEventListener {
|
||||
/** @var DBConfigService */
|
||||
private $config;
|
||||
|
||||
public function __construct(DBConfigService $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!$event instanceof GroupDeletedEvent) {
|
||||
return;
|
||||
}
|
||||
$this->config->modifyMountsOnGroupDelete($event->getGroup()->getGID());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
|
||||
*
|
||||
* @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\Files_External\Listener;
|
||||
|
||||
use OCA\Files_External\Service\DBConfigService;
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\EventDispatcher\IEventListener;
|
||||
use OCP\User\Events\UserDeletedEvent;
|
||||
|
||||
class UserDeletedListener implements IEventListener {
|
||||
/** @var DBConfigService */
|
||||
private $config;
|
||||
|
||||
public function __construct(DBConfigService $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function handle(Event $event): void {
|
||||
if (!$event instanceof UserDeletedEvent) {
|
||||
return;
|
||||
}
|
||||
$this->config->modifyMountsOnUserDelete($event->getUser()->getUID());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue