|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Circles - Bring cloud-users closer together. |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
8
|
|
|
* later. See the COPYING file. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Maxence Lange <[email protected]> |
|
11
|
|
|
* @copyright 2017 |
|
12
|
|
|
* @license GNU AGPL version 3 or any later version |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
16
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
17
|
|
|
* License, or (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
namespace OCA\Circles\GlobalScale; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
use daita\MySmallPhpTools\Model\SimpleDataStore; |
|
34
|
|
|
use OC\User\NoUserException; |
|
35
|
|
|
use OCA\Circles\Exceptions\CircleDoesNotExistException; |
|
36
|
|
|
use OCA\Circles\Exceptions\CircleTypeNotValidException; |
|
37
|
|
|
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException; |
|
38
|
|
|
use OCA\Circles\Exceptions\EmailAccountInvalidFormatException; |
|
39
|
|
|
use OCA\Circles\Exceptions\GlobalScaleDSyncException; |
|
40
|
|
|
use OCA\Circles\Exceptions\GlobalScaleEventException; |
|
41
|
|
|
use OCA\Circles\Exceptions\MemberAlreadyExistsException; |
|
42
|
|
|
use OCA\Circles\Exceptions\MemberCantJoinCircleException; |
|
43
|
|
|
use OCA\Circles\Exceptions\MemberIsNotModeratorException; |
|
44
|
|
|
use OCA\Circles\Exceptions\MembersLimitException; |
|
45
|
|
|
use OCA\Circles\Model\GlobalScale\GSEvent; |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Class MemberAdd |
|
50
|
|
|
* |
|
51
|
|
|
* @package OCA\Circles\GlobalScale |
|
52
|
|
|
*/ |
|
53
|
|
|
class MemberAdd extends AGlobalScaleEvent { |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param GSEvent $event |
|
58
|
|
|
* @param bool $localCheck |
|
59
|
|
|
* @param bool $mustBeChecked |
|
60
|
|
|
* |
|
61
|
|
|
* @throws CircleDoesNotExistException |
|
62
|
|
|
* @throws ConfigNoCircleAvailableException |
|
63
|
|
|
* @throws EmailAccountInvalidFormatException |
|
64
|
|
|
* @throws GlobalScaleDSyncException |
|
65
|
|
|
* @throws GlobalScaleEventException |
|
66
|
|
|
* @throws MemberAlreadyExistsException |
|
67
|
|
|
* @throws MemberCantJoinCircleException |
|
68
|
|
|
* @throws MembersLimitException |
|
69
|
|
|
* @throws NoUserException |
|
70
|
|
|
* @throws CircleTypeNotValidException |
|
71
|
|
|
* @throws MemberIsNotModeratorException |
|
72
|
|
|
*/ |
|
73
|
|
|
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void { |
|
74
|
|
|
parent::verify($event, $localCheck, true); |
|
75
|
|
|
|
|
76
|
|
|
$eventMember = $event->getMember(); |
|
77
|
|
|
$this->cleanMember($eventMember); |
|
78
|
|
|
|
|
79
|
|
|
if ($eventMember->getInstance() === '') { |
|
80
|
|
|
$eventMember->setInstance($event->getSource()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$ident = $eventMember->getUserId(); |
|
84
|
|
|
$this->membersService->verifyIdentBasedOnItsType( |
|
85
|
|
|
$ident, $eventMember->getType(), $eventMember->getInstance() |
|
86
|
|
|
); |
|
87
|
|
|
|
|
88
|
|
|
$circle = $event->getCircle(); |
|
89
|
|
|
if (!$event->isForced()) { |
|
90
|
|
|
$circle->getHigherViewer() |
|
91
|
|
|
->hasToBeModerator(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$member = $this->membersRequest->getFreshNewMember( |
|
95
|
|
|
$circle->getUniqueId(), $ident, $eventMember->getType(), $eventMember->getInstance() |
|
96
|
|
|
); |
|
97
|
|
|
$member->hasToBeInviteAble(); |
|
98
|
|
|
|
|
99
|
|
|
$this->circlesService->checkThatCircleIsNotFull($circle); |
|
100
|
|
|
$this->membersService->addMemberBasedOnItsType($circle, $member); |
|
101
|
|
|
|
|
102
|
|
|
$event->setMember($member); |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @param GSEvent $event |
|
109
|
|
|
* |
|
110
|
|
|
* @throws MemberAlreadyExistsException |
|
111
|
|
|
*/ |
|
112
|
|
View Code Duplication |
public function manage(GSEvent $event): void { |
|
|
|
|
|
|
113
|
|
|
$circle = $event->getCircle(); |
|
114
|
|
|
$member = $event->getMember(); |
|
115
|
|
|
if ($member->getJoined() === '') { |
|
116
|
|
|
$this->membersRequest->createMember($member); |
|
117
|
|
|
} else { |
|
118
|
|
|
$this->membersRequest->updateMember($member); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
$this->eventsService->onMemberNew($circle, $member); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param GSEvent[] $events |
|
127
|
|
|
*/ |
|
128
|
|
|
public function result(array $events): void { |
|
129
|
|
|
// $instances = array_keys($events); |
|
130
|
|
|
// foreach ($instances as $instance) { |
|
131
|
|
|
// $event = $events[$instance]; |
|
132
|
|
|
// $this->miscService->log('---- ' . $instance . ' -- ' . json_encode($event->getResult())); |
|
133
|
|
|
// } |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.