|
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\Cron; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
use OC\BackgroundJob\TimedJob; |
|
34
|
|
|
use OCA\Circles\AppInfo\Application; |
|
35
|
|
|
use OCA\Circles\Db\CirclesRequest; |
|
36
|
|
|
use OCA\Circles\Db\MembersRequest; |
|
37
|
|
|
use OCA\Circles\Exceptions\GSStatusException; |
|
38
|
|
|
use OCA\Circles\Model\Circle; |
|
39
|
|
|
use OCA\Circles\Service\ConfigService; |
|
40
|
|
|
use OCA\Circles\Service\GSUpstreamService; |
|
41
|
|
|
use OCA\Circles\Service\MiscService; |
|
42
|
|
|
use OCP\AppFramework\QueryException; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Class GlobalSync |
|
47
|
|
|
* |
|
48
|
|
|
* @package OCA\Cicles\Cron |
|
49
|
|
|
*/ |
|
50
|
|
|
class GlobalSync extends TimedJob { |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** @var MembersRequest */ |
|
54
|
|
|
private $membersRequest; |
|
55
|
|
|
|
|
56
|
|
|
/** @var CirclesRequest */ |
|
57
|
|
|
private $circlesRequest; |
|
58
|
|
|
|
|
59
|
|
|
/** @var GSUpstreamService */ |
|
60
|
|
|
private $gsUpstreamService; |
|
61
|
|
|
|
|
62
|
|
|
/** @var ConfigService */ |
|
63
|
|
|
private $configService; |
|
64
|
|
|
|
|
65
|
|
|
/** @var MiscService */ |
|
66
|
|
|
private $miscService; |
|
67
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Cache constructor. |
|
71
|
|
|
*/ |
|
72
|
|
|
public function __construct() { |
|
73
|
|
|
$this->setInterval(1); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param mixed $argument |
|
79
|
|
|
* |
|
80
|
|
|
* @throws QueryException |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function run($argument) { |
|
83
|
|
|
$app = new Application(); |
|
84
|
|
|
$c = $app->getContainer(); |
|
85
|
|
|
|
|
86
|
|
|
$this->circlesRequest = $c->query(CirclesRequest::class); |
|
87
|
|
|
$this->membersRequest = $c->query(MembersRequest::class); |
|
88
|
|
|
$this->gsUpstreamService = $c->query(GSUpstreamService::class); |
|
89
|
|
|
$this->configService = $c->query(ConfigService::class); |
|
90
|
|
|
$this->miscService = $c->query(MiscService::class); |
|
91
|
|
|
|
|
92
|
|
|
try { |
|
93
|
|
|
if (!$this->configService->getGSStatus(ConfigService::GS_ENABLED)) { |
|
94
|
|
|
return; |
|
95
|
|
|
} |
|
96
|
|
|
} catch (GSStatusException $e) { |
|
97
|
|
|
return; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->syncCircles(); |
|
101
|
|
|
$this->removeDeprecatedCircles(); |
|
102
|
|
|
|
|
103
|
|
|
$this->syncEvents(); |
|
|
|
|
|
|
104
|
|
|
$this->removeDeprecatedEvents(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
private function syncCircles() { |
|
109
|
|
|
$circles = $this->circlesRequest->forceGetCircles(); |
|
110
|
|
|
$sync = []; |
|
111
|
|
|
foreach ($circles as $circle) { |
|
112
|
|
|
if ($circle->getOwner() |
|
113
|
|
|
->getInstance() !== '' |
|
114
|
|
|
|| $circle->getType() === Circle::CIRCLES_PERSONAL) { |
|
115
|
|
|
continue; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$members = $this->membersRequest->forceGetMembers($circle->getUniqueId()); |
|
119
|
|
|
$circle->setMembers($members); |
|
120
|
|
|
|
|
121
|
|
|
$sync[] = $circle; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
try { |
|
125
|
|
|
$this->gsUpstreamService->syncCircles($sync); |
|
126
|
|
|
} catch (GSStatusException $e) { |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* |
|
133
|
|
|
*/ |
|
134
|
|
|
private function removeDeprecatedCircles(): void { |
|
135
|
|
|
$knownCircles = $this->circlesRequest->forceGetCircles(); |
|
136
|
|
|
|
|
137
|
|
|
foreach ($knownCircles as $knownItem) { |
|
138
|
|
|
if ($knownItem->getOwner() |
|
139
|
|
|
->getInstance() === '') { |
|
140
|
|
|
continue; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
try { |
|
144
|
|
|
$this->checkCircle($knownItem); |
|
145
|
|
|
} catch (GSStatusException $e) { |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @param Circle $circle |
|
153
|
|
|
* |
|
154
|
|
|
* @throws GSStatusException |
|
155
|
|
|
*/ |
|
156
|
|
|
private function checkCircle(Circle $circle): void { |
|
157
|
|
|
$status = $this->gsUpstreamService->confirmCircleStatus($circle); |
|
158
|
|
|
|
|
159
|
|
|
if (!$status) { |
|
160
|
|
|
$this->circlesRequest->destroyCircle($circle->getUniqueId()); |
|
161
|
|
|
$this->membersRequest->removeAllFromCircle($circle->getUniqueId()); |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* |
|
168
|
|
|
*/ |
|
169
|
|
|
private function syncEvents(): void { |
|
170
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
private function removeDeprecatedEvents(): void { |
|
174
|
|
|
$this->gsUpstreamService->deprecatedEvents(); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: