Completed
Pull Request — master (#362)
by Maxence
01:55 queued 11s
created

CircleUpdate::manage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 3
nc 3
nop 1
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 OCA\Circles\Exceptions\CircleAlreadyExistsException;
34
use OCA\Circles\Exceptions\CircleDoesNotExistException;
35
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
36
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
37
use OCA\Circles\Exceptions\GlobalScaleEventException;
38
use OCA\Circles\Model\GlobalScale\GSEvent;
39
use OCA\Circles\Model\Member;
40
41
42
/**
43
 * Class CircleUpdate
44
 *
45
 * @package OCA\Circles\GlobalScale
46
 */
47
class CircleUpdate extends AGlobalScaleEvent {
48
49
50
	/**
51
	 * @param GSEvent $event
52
	 * @param bool $localCheck
53
	 * @param bool $mustBeChecked
54
	 *
55
	 * @throws CircleDoesNotExistException
56
	 * @throws ConfigNoCircleAvailableException
57
	 * @throws GlobalScaleDSyncException
58
	 * @throws GlobalScaleEventException
59
	 */
60
	public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
61
		parent::verify($event, $localCheck, true);
62
63
		$circle = $event->getCircle();
64
		$data = $event->getData();
65
		$viewer = $circle->getHigherViewer();
66
		if (!$data->gBool('local_admin') && $viewer->getLevel() !== Member::LEVEL_OWNER) {
67
			throw new GlobalScaleDSyncException('Member is not Owner');
68
		}
69
	}
70
71
72
	/**
73
	 * @param GSEvent $event
74
	 *
75
	 * @throws CircleAlreadyExistsException
76
	 */
77
	public function manage(GSEvent $event): void {
78
		if (!$event->hasCircle()) {
79
			return;
80
		}
81
82
		$circle = $event->getCircle();
83
		$settings = $event->getData()
84
						  ->gArray('settings');
85
		$ak = array_keys($settings);
86
		foreach ($ak AS $k) {
87
			$circle->setSetting($k, $settings[$k]);
88
		}
89
90
		$owner = $circle->getHigherViewer();
91
		$this->circlesRequest->updateCircle($circle, $owner->getUserId());
92
93
		$oldSettings = array_merge(
94
			$circle->getSettings(),
95
			[
96
				'circle_name' => $circle->getName(),
97
				'circle_desc' => $circle->getDescription(),
98
			]
99
		);
100
101
		$this->eventsService->onSettingsChange($circle, $oldSettings);
102
	}
103
104
105
	/**
106
	 * @param GSEvent[] $events
107
	 */
108
	public function result(array $events): void {
109
	}
110
}
111
112