|
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\Controller; |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
use daita\MySmallPhpTools\Traits\TAsync; |
|
34
|
|
|
use daita\MySmallPhpTools\Traits\TStringTools; |
|
35
|
|
|
use Exception; |
|
36
|
|
|
use OCA\Circles\Exceptions\GSStatusException; |
|
37
|
|
|
use OCA\Circles\Model\GlobalScale\GSEvent; |
|
38
|
|
|
use OCP\AppFramework\Http\DataResponse; |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Class GlobalScaleController |
|
43
|
|
|
* |
|
44
|
|
|
* @package OCA\Circles\Controller |
|
45
|
|
|
*/ |
|
46
|
|
|
class GlobalScaleController extends BaseController { |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
|
|
use TStringTools; |
|
50
|
|
|
use TAsync; |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Event is generated by any instance of GS and sent to the instance that owns the Circles, that |
|
55
|
|
|
* will broadcast the event to other if ok |
|
56
|
|
|
* |
|
57
|
|
|
* |
|
58
|
|
|
* @PublicPage |
|
59
|
|
|
* @NoCSRFRequired |
|
60
|
|
|
* |
|
61
|
|
|
* @param string $data |
|
|
|
|
|
|
62
|
|
|
* |
|
63
|
|
|
* @return DataResponse |
|
64
|
|
|
*/ |
|
65
|
|
View Code Duplication |
public function event(): DataResponse { |
|
|
|
|
|
|
66
|
|
|
$data = file_get_contents('php://input'); |
|
67
|
|
|
|
|
68
|
|
|
try { |
|
69
|
|
|
$event = new GSevent(); |
|
70
|
|
|
$event->importFromJson($data); |
|
71
|
|
|
$this->gsDownstreamService->requestedEvent($event); |
|
72
|
|
|
|
|
73
|
|
|
return $this->success(['success' => $event]); |
|
74
|
|
|
} catch (Exception $e) { |
|
75
|
|
|
return $this->fail(['data' => $data, 'error' => $e->getMessage()]); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Async process and broadcast the event to every instances of GS |
|
82
|
|
|
* This should be initiated by the instance that owns the Circles. |
|
83
|
|
|
* |
|
84
|
|
|
* @PublicPage |
|
85
|
|
|
* @NoCSRFRequired |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $token |
|
88
|
|
|
*/ |
|
89
|
|
|
public function asyncBroadcast(string $token) { |
|
90
|
|
|
try { |
|
91
|
|
|
$wrapper = $this->gsUpstreamService->getEventByToken($token); |
|
92
|
|
|
} catch (Exception $e) { |
|
93
|
|
|
$this->miscService->log( |
|
94
|
|
|
'exception during async: ' . ['token' => $token, 'error' => $e->getMessage()] |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
$this->async(); |
|
99
|
|
|
try { |
|
100
|
|
|
$this->gsUpstreamService->broadcastEvent( |
|
101
|
|
|
$this->request->getServerProtocol(), $wrapper->getEvent() |
|
102
|
|
|
); |
|
103
|
|
|
} catch (GSStatusException $e) { |
|
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
exit(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Event is sent by instance that owns the Circles. |
|
112
|
|
|
* |
|
113
|
|
|
* @PublicPage |
|
114
|
|
|
* @NoCSRFRequired |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $data |
|
|
|
|
|
|
117
|
|
|
* |
|
118
|
|
|
* @return DataResponse |
|
119
|
|
|
*/ |
|
120
|
|
View Code Duplication |
public function broadcast(): DataResponse { |
|
|
|
|
|
|
121
|
|
|
$data = file_get_contents('php://input'); |
|
122
|
|
|
|
|
123
|
|
|
try { |
|
124
|
|
|
$event = new GSevent(); |
|
125
|
|
|
$event->importFromJson($data); |
|
126
|
|
|
|
|
127
|
|
|
$this->gsDownstreamService->onNewEvent($event); |
|
128
|
|
|
|
|
129
|
|
|
return $this->success([]); |
|
130
|
|
|
} catch (Exception $e) { |
|
131
|
|
|
return $this->fail(['data' => $data, 'error' => $e->getMessage()]); |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.