1 | <?php |
||
20 | class DissociateUserFromOrganization extends Action |
||
21 | { |
||
22 | use DeleteRecordTrait, LookupAssociationTrait; |
||
23 | |||
24 | /** |
||
25 | * @param string $user |
||
26 | * @param string $organization |
||
27 | * @return null|\yii\base\Model|\yii\web\Response |
||
28 | * @throws HttpException |
||
29 | */ |
||
30 | public function run( |
||
31 | string $user, |
||
32 | string $organization |
||
33 | ) { |
||
34 | if (null === ($user = $this->findUser($user))) { |
||
35 | return $this->handleNotFoundResponse(); |
||
36 | } |
||
37 | |||
38 | if (null === ($organization = $this->findOrganization($organization))) { |
||
39 | return $this->handleNotFoundResponse(); |
||
40 | } |
||
41 | |||
42 | return $this->runInternal( |
||
43 | $organization->getUsers()->findOrCreate($user) |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @param UserAssociation $association |
||
49 | * @return bool |
||
50 | * @throws \Throwable |
||
51 | * @throws \yii\db\StaleObjectException |
||
52 | */ |
||
53 | protected function performAction(UserAssociation $association): bool |
||
57 | } |
||
58 |