Completed
Pull Request — master (#362)
by Maxence
01:50
created

GSDownstreamService::onNewEvent()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 4
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\Service;
31
32
33
use Exception;
34
use OCA\Circles\Db\CirclesRequest;
35
use OCA\Circles\Db\GSEventsRequest;
36
use OCA\Circles\Exceptions\CircleDoesNotExistException;
37
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
38
use OCA\Circles\Exceptions\GlobalScaleDSyncException;
39
use OCA\Circles\Exceptions\GlobalScaleEventException;
40
use OCA\Circles\Exceptions\GSKeyException;
41
use OCA\Circles\Exceptions\GSStatusException;
42
use OCA\Circles\Model\GlobalScale\GSEvent;
43
use OCP\IURLGenerator;
44
45
46
/**
47
 * Class GSDownstreamService
48
 *
49
 * @package OCA\Circles\Service
50
 */
51
class GSDownstreamService {
52
53
54
	/** @var string */
55
	private $userId = '';
56
57
	/** @var IURLGenerator */
58
	private $urlGenerator;
59
60
	/** @var GSEventsRequest */
61
	private $gsEventsRequest;
62
63
	/** @var CirclesRequest */
64
	private $circlesRequest;
65
66
	/** @var GlobalScaleService */
67
	private $globalScaleService;
68
69
	/** @var ConfigService */
70
	private $configService;
71
72
	/** @var MiscService */
73
	private $miscService;
74
75
76
	/**
77
	 * GSUpstreamService constructor.
78
	 *
79
	 * @param $userId
80
	 * @param IURLGenerator $urlGenerator
81
	 * @param GSEventsRequest $gsEventsRequest
82
	 * @param CirclesRequest $circlesRequest
83
	 * @param GlobalScaleService $globalScaleService
84
	 * @param ConfigService $configService
85
	 * @param MiscService $miscService
86
	 */
87 View Code Duplication
	public function __construct(
88
		$userId,
89
		IURLGenerator $urlGenerator,
90
		GSEventsRequest $gsEventsRequest,
91
		CirclesRequest $circlesRequest,
92
		GlobalScaleService $globalScaleService,
93
		ConfigService $configService,
94
		MiscService $miscService
95
	) {
96
		$this->userId = $userId;
97
		$this->urlGenerator = $urlGenerator;
98
		$this->gsEventsRequest = $gsEventsRequest;
99
		$this->circlesRequest = $circlesRequest;
100
		$this->globalScaleService = $globalScaleService;
101
		$this->configService = $configService;
102
		$this->miscService = $miscService;
103
	}
104
105
106
	/**
107
	 * @param GSEvent $event
108
	 *
109
	 * @throws GSKeyException
110
	 * @throws GSStatusException
111
	 * @throws GlobalScaleEventException
112
	 * @throws CircleDoesNotExistException
113
	 * @throws ConfigNoCircleAvailableException
114
	 * @throws GlobalScaleDSyncException
115
	 */
116
	public function requestedEvent(GSEvent $event) {
117
		$this->globalScaleService->checkEvent($event);
118
119
		$gs = $this->globalScaleService->getGlobalScaleEvent($event);
120
		$gs->verify($event, true);
121
		$gs->manage($event);
122
123
		$this->globalScaleService->asyncBroadcast($event);
124
	}
125
126
127
	/**
128
	 * @param GSEvent $event
129
	 */
130
	public function onNewEvent(GSEvent $event) {
131
		try {
132
			$this->globalScaleService->checkEvent($event);
133
134
			$gs = $this->globalScaleService->getGlobalScaleEvent($event);
135
			$gs->manage($event);
136
		} catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
137
		}
138
	}
139
140
}
141
142