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 <[email protected]> |
13
|
|
|
* @copyright 2021 |
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\Files; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
use daita\MySmallPhpTools\Traits\TStringTools; |
36
|
|
|
use OCA\Circles\Db\ShareWrapperRequest; |
37
|
|
|
use OCA\Circles\Events\MembershipsRemovedEvent; |
38
|
|
|
use OCA\Circles\Model\Member; |
39
|
|
|
use OCA\Circles\Service\FederatedUserService; |
40
|
|
|
use OCP\EventDispatcher\Event; |
41
|
|
|
use OCP\EventDispatcher\IEventListener; |
42
|
|
|
|
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Class MembershipsRemoved |
46
|
|
|
* |
47
|
|
|
* @package OCA\Circles\Listeners\Files |
48
|
|
|
*/ |
49
|
|
|
class MembershipsRemoved implements IEventListener { |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
use TStringTools; |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** @var ShareWrapperRequest */ |
56
|
|
|
private $shareWrapperRequest; |
57
|
|
|
|
58
|
|
|
/** @var FederatedUserService */ |
59
|
|
|
private $federatedUserService; |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* MembershipsRemoved constructor. |
64
|
|
|
* |
65
|
|
|
* @param ShareWrapperRequest $shareWrapperRequest |
66
|
|
|
* @param FederatedUserService $federatedUserService |
67
|
|
|
*/ |
68
|
|
|
public function __construct( |
69
|
|
|
ShareWrapperRequest $shareWrapperRequest, |
70
|
|
|
FederatedUserService $federatedUserService |
71
|
|
|
) { |
72
|
|
|
$this->shareWrapperRequest = $shareWrapperRequest; |
73
|
|
|
$this->federatedUserService = $federatedUserService; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param Event $event |
79
|
|
|
*/ |
80
|
|
|
public function handle(Event $event): void { |
81
|
|
|
if (!$event instanceof MembershipsRemovedEvent) { |
82
|
|
|
return; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
foreach ($event->getMemberships() as $membership) { |
86
|
|
|
// $this->shareWrapperRequest->removeByMembership($membership); |
87
|
|
|
// deprecated with ShareWrapperRequest::removeByInitiatorAndShareWith() |
88
|
|
|
$federatedUser = $this->federatedUserService->getFederatedUser( |
89
|
|
|
$membership->getSingleId(), |
90
|
|
|
Member::TYPE_SINGLE |
91
|
|
|
); |
92
|
|
|
if ($federatedUser->getUserType() === Member::TYPE_USER) { |
93
|
|
|
$this->shareWrapperRequest->removeByInitiatorAndShareWith( |
|
|
|
|
94
|
|
|
$federatedUser->getUserId(), |
95
|
|
|
$membership->getCircleId() |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.