Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
UserAccountService | |
100.00% |
10 / 10 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
purgeUserData | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | /** |
4 | * User account service |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2024 |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Account |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org Main Page |
28 | */ |
29 | |
30 | namespace VuFind\Account; |
31 | |
32 | use VuFind\Db\Entity\UserEntityInterface; |
33 | use VuFind\Db\Service\CommentsServiceInterface; |
34 | use VuFind\Db\Service\DbServiceAwareInterface; |
35 | use VuFind\Db\Service\DbServiceAwareTrait; |
36 | use VuFind\Db\Service\RatingsServiceInterface; |
37 | use VuFind\Db\Service\ResourceTagsServiceInterface; |
38 | use VuFind\Db\Service\UserListServiceInterface; |
39 | use VuFind\Db\Service\UserServiceInterface; |
40 | use VuFind\Favorites\FavoritesService; |
41 | |
42 | /** |
43 | * User account service |
44 | * |
45 | * @category VuFind |
46 | * @package Account |
47 | * @author Demian Katz <demian.katz@villanova.edu> |
48 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
49 | * @link https://vufind.org Main Page |
50 | */ |
51 | class UserAccountService implements DbServiceAwareInterface |
52 | { |
53 | use DbServiceAwareTrait; |
54 | |
55 | /** |
56 | * Constructor |
57 | * |
58 | * @param FavoritesService $favoritesService Favorites service |
59 | */ |
60 | public function __construct(protected FavoritesService $favoritesService) |
61 | { |
62 | } |
63 | |
64 | /** |
65 | * Destroy the user. |
66 | * |
67 | * @param UserEntityInterface $user User to delete |
68 | * @param bool $removeComments Whether to remove user's comments |
69 | * @param bool $removeRatings Whether to remove user's ratings |
70 | * |
71 | * @return void |
72 | */ |
73 | public function purgeUserData( |
74 | UserEntityInterface $user, |
75 | bool $removeComments = true, |
76 | bool $removeRatings = true |
77 | ): void { |
78 | // Remove all lists owned by the user: |
79 | $listService = $this->getDbService(UserListServiceInterface::class); |
80 | foreach ($listService->getUserListsByUser($user) as $current) { |
81 | $this->favoritesService->destroyList($current, $user, true); |
82 | } |
83 | $this->getDbService(ResourceTagsServiceInterface::class)->destroyResourceTagsLinksForUser(null, $user); |
84 | if ($removeComments) { |
85 | $this->getDbService(CommentsServiceInterface::class)->deleteByUser($user); |
86 | } |
87 | if ($removeRatings) { |
88 | $this->getDbService(RatingsServiceInterface::class)->deleteByUser($user); |
89 | } |
90 | $this->getDbService(UserServiceInterface::class)->deleteUser($user); |
91 | } |
92 | } |