|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author Pasquale Tripodi <pasquale.tripodi@kiteworks.com> |
| 4 | + * @author Ilja Neumann <ilja.neumann@kiteworks.com> |
| 5 | + * |
| 6 | + * @copyright Copyright (c) 2024, ownCloud GmbH |
| 7 | + * @license AGPL-3.0 |
| 8 | + * |
| 9 | + * This code is free software: you can redistribute it and/or modify |
| 10 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 11 | + * as published by the Free Software Foundation. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 19 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +namespace OCA\CustomGroups; |
| 24 | + |
| 25 | +class Hooks { |
| 26 | + public static function register(): void { |
| 27 | + \OCP\Util::connectHook( |
| 28 | + 'OC_User', |
| 29 | + 'post_deleteUser', |
| 30 | + self::class, |
| 31 | + 'userDelete' |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + public static function userDelete($params) { |
| 36 | + $customGroupsDbHandler = \OC::$server->query(CustomGroupsDatabaseHandler::class); |
| 37 | + foreach ($customGroupsDbHandler->getUserMemberships($params['uid'], null) as $customGroup) { |
| 38 | + $members = $customGroupsDbHandler->getGroupMembers($customGroup['group_id']); |
| 39 | + if (\count($members) === 1 && $members[0]['user_id'] === $params['uid']) { |
| 40 | + // removing custom group as deleted user is the only member/admin left |
| 41 | + $customGroupsDbHandler->deleteGroup($customGroup['group_id']); |
| 42 | + } |
| 43 | + $customGroupsDbHandler->removeFromGroup($params['uid'], $customGroup['group_id']); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments