Skip to content

Commit 8b6f21b

Browse files
committed
new listeners
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 3918b21 commit 8b6f21b

File tree

5 files changed

+173
-113
lines changed

5 files changed

+173
-113
lines changed

lib/AppInfo/Application.php

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
use OCA\Circles\Api\v1\Circles;
4040
use OCA\Circles\Exceptions\GSStatusException;
4141
use OCA\Circles\GlobalScale\GSMount\MountProvider;
42+
use OCA\Circles\Listeners\GroupDeleted;
43+
use OCA\Circles\Listeners\UserDeleted;
4244
use OCA\Circles\Notification\Notifier;
4345
use OCA\Circles\Service\ConfigService;
4446
use OCA\Circles\Service\DavService;
@@ -50,8 +52,11 @@
5052
use OCP\AppFramework\Bootstrap\IRegistrationContext;
5153
use OCP\AppFramework\IAppContainer;
5254
use OCP\AppFramework\QueryException;
55+
use OCP\Group\Events\GroupDeletedEvent;
5356
use OCP\IServerContainer;
57+
use OCP\User\Events\UserDeletedEvent;
5458
use OCP\Util;
59+
use Throwable;
5560

5661

5762
require_once __DIR__ . '/../../vendor/autoload.php';
@@ -90,13 +95,15 @@ public function __construct(array $params = array()) {
9095
* @param IRegistrationContext $context
9196
*/
9297
public function register(IRegistrationContext $context): void {
98+
$context->registerEventListener(UserDeletedEvent::class, UserDeleted::class);
99+
$context->registerEventListener(GroupDeletedEvent::class, GroupDeleted::class);
93100
}
94101

95102

96103
/**
97104
* @param IBootContext $context
98105
*
99-
* @throws \Throwable
106+
* @throws Throwable
100107
*/
101108
public function boot(IBootContext $context): void {
102109
$manager = $context->getServerContainer()
@@ -107,7 +114,6 @@ public function boot(IBootContext $context): void {
107114
->get(ConfigService::class);
108115

109116
$context->injectFn(Closure::fromCallable([$this, 'registerMountProvider']));
110-
$context->injectFn(Closure::fromCallable([$this, 'registerHooks']));
111117
$context->injectFn(Closure::fromCallable([$this, 'registerDavHooks']));
112118

113119
$context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
@@ -131,19 +137,7 @@ public function registerMountProvider(IServerContainer $container) {
131137
}
132138

133139

134-
/**
135-
* Register Hooks
136-
*/
137-
public function registerHooks() {
138-
Util::connectHook('OC_User', 'post_deleteUser', '\OCA\Circles\Hooks\UserHooks', 'onUserDeleted');
139-
Util::connectHook('OC_User', 'post_deleteGroup', '\OCA\Circles\Hooks\UserHooks', 'onGroupDeleted');
140-
}
141-
142-
143140
public function registerDavHooks(IServerContainer $container) {
144-
// /** @var ConfigService $configService */
145-
//
146-
// $configService = OC::$server->query(ConfigService::class);
147141
if (!$this->configService->isContactsBackend()) {
148142
return;
149143
}

lib/Events/UserEvents.php

Lines changed: 0 additions & 67 deletions
This file was deleted.

lib/Hooks/UserHooks.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

lib/Listeners/GroupDeleted.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@pontapreta.net>
13+
* @copyright 2020
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Circles\Listeners;
33+
34+
use OCA\Circles\Service\GroupsService;
35+
use OCP\EventDispatcher\Event;
36+
use OCP\EventDispatcher\IEventListener;
37+
use OCP\Group\Events\GroupDeletedEvent;
38+
39+
40+
/**
41+
* Class GroupDeleted
42+
*
43+
* @package OCA\Circles\Events
44+
*/
45+
class GroupDeleted implements IEventListener {
46+
47+
48+
/** @var GroupsService */
49+
private $groupsService;
50+
51+
52+
/**
53+
* GroupDeleted constructor.
54+
*
55+
* @param GroupsService $groupsService
56+
*/
57+
public function __construct(GroupsService $groupsService) {
58+
$this->groupsService = $groupsService;
59+
}
60+
61+
62+
/**
63+
* @param Event $event
64+
*/
65+
public function handle(Event $event): void {
66+
if (!($event instanceof GroupDeletedEvent)) {
67+
return;
68+
}
69+
70+
$group = $event->getGroup();
71+
$groupId = $group->getGID();
72+
$this->groupsService->onGroupRemoved($groupId);
73+
}
74+
75+
}
76+

lib/Listeners/UserDeleted.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@pontapreta.net>
13+
* @copyright 2020
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Circles\Listeners;
33+
34+
use OCA\Circles\Service\MembersService;
35+
use OCA\Circles\Service\MiscService;
36+
use OCP\EventDispatcher\Event;
37+
use OCP\EventDispatcher\IEventListener;
38+
use OCP\User\Events\UserDeletedEvent;
39+
40+
41+
/**
42+
* Class UserDeleted
43+
*
44+
* @package OCA\Circles\Events
45+
*/
46+
class UserDeleted implements IEventListener {
47+
48+
49+
/** @var MembersService */
50+
private $membersService;
51+
52+
/** @var MiscService */
53+
private $miscService;
54+
55+
56+
/**
57+
* UserDeleted constructor.
58+
*
59+
* @param MembersService $membersService
60+
* @param MiscService $miscService
61+
*/
62+
public function __construct(MembersService $membersService, MiscService $miscService) {
63+
$this->membersService = $membersService;
64+
$this->miscService = $miscService;
65+
}
66+
67+
68+
/**
69+
* @param Event $event
70+
*/
71+
public function handle(Event $event): void {
72+
if (!($event instanceof UserDeletedEvent)) {
73+
return;
74+
}
75+
76+
$user = $event->getUser();
77+
if ($user === null) {
78+
return;
79+
}
80+
81+
try {
82+
$this->membersService->onUserRemoved($user->getUID());
83+
} catch (\Exception $e) {
84+
$this->miscService->e($e);
85+
}
86+
}
87+
88+
}
89+

0 commit comments

Comments
 (0)