@@ -14,42 +14,42 @@ discard block |
||
14 | 14 | |
15 | 15 | class OAuthToken extends DataObject |
16 | 16 | { |
17 | - /** @var int */ |
|
18 | - private $user; |
|
19 | - /** @var string */ |
|
20 | - private $token; |
|
21 | - /** @var string */ |
|
22 | - private $secret; |
|
23 | - /** @var string */ |
|
24 | - private $type; |
|
25 | - /** @var string */ |
|
26 | - private $expiry; |
|
27 | - |
|
28 | - public function save() |
|
29 | - { |
|
30 | - if ($this->isNew()) { |
|
31 | - // insert |
|
32 | - $statement = $this->dbObject->prepare(<<<SQL |
|
17 | + /** @var int */ |
|
18 | + private $user; |
|
19 | + /** @var string */ |
|
20 | + private $token; |
|
21 | + /** @var string */ |
|
22 | + private $secret; |
|
23 | + /** @var string */ |
|
24 | + private $type; |
|
25 | + /** @var string */ |
|
26 | + private $expiry; |
|
27 | + |
|
28 | + public function save() |
|
29 | + { |
|
30 | + if ($this->isNew()) { |
|
31 | + // insert |
|
32 | + $statement = $this->dbObject->prepare(<<<SQL |
|
33 | 33 | INSERT INTO oauthtoken ( user, token, secret, type, expiry ) |
34 | 34 | VALUES ( :user, :token, :secret, :type, :expiry ); |
35 | 35 | SQL |
36 | - ); |
|
37 | - $statement->bindValue(":user", $this->user); |
|
38 | - $statement->bindValue(":token", $this->token); |
|
39 | - $statement->bindValue(":secret", $this->secret); |
|
40 | - $statement->bindValue(":type", $this->type); |
|
41 | - $statement->bindValue(":expiry", $this->expiry); |
|
42 | - |
|
43 | - if ($statement->execute()) { |
|
44 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
45 | - } |
|
46 | - else { |
|
47 | - throw new Exception($statement->errorInfo()); |
|
48 | - } |
|
49 | - } |
|
50 | - else { |
|
51 | - // update |
|
52 | - $statement = $this->dbObject->prepare(<<<SQL |
|
36 | + ); |
|
37 | + $statement->bindValue(":user", $this->user); |
|
38 | + $statement->bindValue(":token", $this->token); |
|
39 | + $statement->bindValue(":secret", $this->secret); |
|
40 | + $statement->bindValue(":type", $this->type); |
|
41 | + $statement->bindValue(":expiry", $this->expiry); |
|
42 | + |
|
43 | + if ($statement->execute()) { |
|
44 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
45 | + } |
|
46 | + else { |
|
47 | + throw new Exception($statement->errorInfo()); |
|
48 | + } |
|
49 | + } |
|
50 | + else { |
|
51 | + // update |
|
52 | + $statement = $this->dbObject->prepare(<<<SQL |
|
53 | 53 | UPDATE oauthtoken |
54 | 54 | SET token = :token |
55 | 55 | , secret = :secret |
@@ -58,109 +58,109 @@ discard block |
||
58 | 58 | , updateversion = updateversion + 1 |
59 | 59 | WHERE id = :id AND updateversion = :updateversion; |
60 | 60 | SQL |
61 | - ); |
|
62 | - |
|
63 | - $statement->bindValue(':id', $this->id); |
|
64 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
65 | - |
|
66 | - $statement->bindValue(":token", $this->token); |
|
67 | - $statement->bindValue(":secret", $this->secret); |
|
68 | - $statement->bindValue(":type", $this->type); |
|
69 | - $statement->bindValue(":expiry", $this->expiry); |
|
70 | - |
|
71 | - if (!$statement->execute()) { |
|
72 | - throw new Exception($statement->errorInfo()); |
|
73 | - } |
|
74 | - |
|
75 | - if ($statement->rowCount() !== 1) { |
|
76 | - throw new OptimisticLockFailedException(); |
|
77 | - } |
|
78 | - |
|
79 | - $this->updateversion++; |
|
80 | - } |
|
81 | - } |
|
82 | - |
|
83 | - #region properties |
|
84 | - |
|
85 | - /** |
|
86 | - * @return mixed |
|
87 | - */ |
|
88 | - public function getUserId() |
|
89 | - { |
|
90 | - return $this->user; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @param mixed $user |
|
95 | - */ |
|
96 | - public function setUserId($user) |
|
97 | - { |
|
98 | - $this->user = $user; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @return mixed |
|
103 | - */ |
|
104 | - public function getToken() |
|
105 | - { |
|
106 | - return $this->token; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @param mixed $token |
|
111 | - */ |
|
112 | - public function setToken($token) |
|
113 | - { |
|
114 | - $this->token = $token; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - public function getSecret() |
|
121 | - { |
|
122 | - return $this->secret; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param mixed $secret |
|
127 | - */ |
|
128 | - public function setSecret($secret) |
|
129 | - { |
|
130 | - $this->secret = $secret; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @return mixed |
|
135 | - */ |
|
136 | - public function getType() |
|
137 | - { |
|
138 | - return $this->type; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @param mixed $type |
|
143 | - */ |
|
144 | - public function setType($type) |
|
145 | - { |
|
146 | - $this->type = $type; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function getExpiry() |
|
153 | - { |
|
154 | - return $this->expiry; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @param string $expiry |
|
159 | - */ |
|
160 | - public function setExpiry($expiry) |
|
161 | - { |
|
162 | - $this->expiry = $expiry; |
|
163 | - } |
|
164 | - #endregion |
|
61 | + ); |
|
62 | + |
|
63 | + $statement->bindValue(':id', $this->id); |
|
64 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
65 | + |
|
66 | + $statement->bindValue(":token", $this->token); |
|
67 | + $statement->bindValue(":secret", $this->secret); |
|
68 | + $statement->bindValue(":type", $this->type); |
|
69 | + $statement->bindValue(":expiry", $this->expiry); |
|
70 | + |
|
71 | + if (!$statement->execute()) { |
|
72 | + throw new Exception($statement->errorInfo()); |
|
73 | + } |
|
74 | + |
|
75 | + if ($statement->rowCount() !== 1) { |
|
76 | + throw new OptimisticLockFailedException(); |
|
77 | + } |
|
78 | + |
|
79 | + $this->updateversion++; |
|
80 | + } |
|
81 | + } |
|
82 | + |
|
83 | + #region properties |
|
84 | + |
|
85 | + /** |
|
86 | + * @return mixed |
|
87 | + */ |
|
88 | + public function getUserId() |
|
89 | + { |
|
90 | + return $this->user; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @param mixed $user |
|
95 | + */ |
|
96 | + public function setUserId($user) |
|
97 | + { |
|
98 | + $this->user = $user; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @return mixed |
|
103 | + */ |
|
104 | + public function getToken() |
|
105 | + { |
|
106 | + return $this->token; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @param mixed $token |
|
111 | + */ |
|
112 | + public function setToken($token) |
|
113 | + { |
|
114 | + $this->token = $token; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + public function getSecret() |
|
121 | + { |
|
122 | + return $this->secret; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param mixed $secret |
|
127 | + */ |
|
128 | + public function setSecret($secret) |
|
129 | + { |
|
130 | + $this->secret = $secret; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @return mixed |
|
135 | + */ |
|
136 | + public function getType() |
|
137 | + { |
|
138 | + return $this->type; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @param mixed $type |
|
143 | + */ |
|
144 | + public function setType($type) |
|
145 | + { |
|
146 | + $this->type = $type; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function getExpiry() |
|
153 | + { |
|
154 | + return $this->expiry; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @param string $expiry |
|
159 | + */ |
|
160 | + public function setExpiry($expiry) |
|
161 | + { |
|
162 | + $this->expiry = $expiry; |
|
163 | + } |
|
164 | + #endregion |
|
165 | 165 | |
166 | 166 | } |
167 | 167 | \ No newline at end of file |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | class JobQueue extends DataObject |
19 | 19 | { |
20 | - /* |
|
20 | + /* |
|
21 | 21 | * Status workflow is this: |
22 | 22 | * |
23 | 23 | * 1) Ready. The job has been added to the queue |
@@ -26,78 +26,78 @@ discard block |
||
26 | 26 | * 3) Complete / Failed. The job has been processed |
27 | 27 | * |
28 | 28 | */ |
29 | - const STATUS_READY = 'ready'; |
|
30 | - const STATUS_WAITING = 'waiting'; |
|
31 | - const STATUS_RUNNING = 'running'; |
|
32 | - const STATUS_COMPLETE = 'complete'; |
|
33 | - const STATUS_CANCELLED = 'cancelled'; |
|
34 | - const STATUS_FAILED = 'failed'; |
|
35 | - const STATUS_HELD = 'held'; |
|
36 | - |
|
37 | - /** @var string */ |
|
38 | - private $task; |
|
39 | - /** @var int */ |
|
40 | - private $user; |
|
41 | - /** @var int */ |
|
42 | - private $request; |
|
43 | - /** @var int */ |
|
44 | - private $emailtemplate; |
|
45 | - /** @var string */ |
|
46 | - private $status; |
|
47 | - /** @var string */ |
|
48 | - private $enqueue; |
|
49 | - /** @var string */ |
|
50 | - private $parameters; |
|
51 | - /** @var string */ |
|
52 | - private $error; |
|
53 | - /** @var int */ |
|
54 | - private $acknowledged; |
|
55 | - /** @var int */ |
|
56 | - private $parent; |
|
57 | - |
|
58 | - /** |
|
59 | - * This feels like the least bad place to put this method. |
|
60 | - */ |
|
61 | - public static function getTaskDescriptions() { |
|
62 | - return array( |
|
63 | - BotCreationTask::class => 'Create account (via bot)', |
|
64 | - UserCreationTask::class => 'Create account (via OAuth)', |
|
65 | - WelcomeUserTask::class => 'Welcome user', |
|
66 | - ); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Saves a data object to the database, either updating or inserting a record. |
|
71 | - * @return void |
|
72 | - * @throws Exception |
|
73 | - * @throws OptimisticLockFailedException |
|
74 | - */ |
|
75 | - public function save() |
|
76 | - { |
|
77 | - if ($this->isNew()) { |
|
78 | - // insert |
|
79 | - $statement = $this->dbObject->prepare(<<<SQL |
|
29 | + const STATUS_READY = 'ready'; |
|
30 | + const STATUS_WAITING = 'waiting'; |
|
31 | + const STATUS_RUNNING = 'running'; |
|
32 | + const STATUS_COMPLETE = 'complete'; |
|
33 | + const STATUS_CANCELLED = 'cancelled'; |
|
34 | + const STATUS_FAILED = 'failed'; |
|
35 | + const STATUS_HELD = 'held'; |
|
36 | + |
|
37 | + /** @var string */ |
|
38 | + private $task; |
|
39 | + /** @var int */ |
|
40 | + private $user; |
|
41 | + /** @var int */ |
|
42 | + private $request; |
|
43 | + /** @var int */ |
|
44 | + private $emailtemplate; |
|
45 | + /** @var string */ |
|
46 | + private $status; |
|
47 | + /** @var string */ |
|
48 | + private $enqueue; |
|
49 | + /** @var string */ |
|
50 | + private $parameters; |
|
51 | + /** @var string */ |
|
52 | + private $error; |
|
53 | + /** @var int */ |
|
54 | + private $acknowledged; |
|
55 | + /** @var int */ |
|
56 | + private $parent; |
|
57 | + |
|
58 | + /** |
|
59 | + * This feels like the least bad place to put this method. |
|
60 | + */ |
|
61 | + public static function getTaskDescriptions() { |
|
62 | + return array( |
|
63 | + BotCreationTask::class => 'Create account (via bot)', |
|
64 | + UserCreationTask::class => 'Create account (via OAuth)', |
|
65 | + WelcomeUserTask::class => 'Welcome user', |
|
66 | + ); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Saves a data object to the database, either updating or inserting a record. |
|
71 | + * @return void |
|
72 | + * @throws Exception |
|
73 | + * @throws OptimisticLockFailedException |
|
74 | + */ |
|
75 | + public function save() |
|
76 | + { |
|
77 | + if ($this->isNew()) { |
|
78 | + // insert |
|
79 | + $statement = $this->dbObject->prepare(<<<SQL |
|
80 | 80 | INSERT INTO jobqueue (task, user, request, emailtemplate, parameters, parent) |
81 | 81 | VALUES (:task, :user, :request, :emailtemplate, :parameters, :parent) |
82 | 82 | SQL |
83 | - ); |
|
84 | - $statement->bindValue(":task", $this->task); |
|
85 | - $statement->bindValue(":user", $this->user); |
|
86 | - $statement->bindValue(":request", $this->request); |
|
87 | - $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
88 | - $statement->bindValue(":parameters", $this->parameters); |
|
89 | - $statement->bindValue(":parent", $this->parent); |
|
90 | - |
|
91 | - if ($statement->execute()) { |
|
92 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
93 | - } |
|
94 | - else { |
|
95 | - throw new Exception($statement->errorInfo()); |
|
96 | - } |
|
97 | - } |
|
98 | - else { |
|
99 | - // update |
|
100 | - $statement = $this->dbObject->prepare(<<<SQL |
|
83 | + ); |
|
84 | + $statement->bindValue(":task", $this->task); |
|
85 | + $statement->bindValue(":user", $this->user); |
|
86 | + $statement->bindValue(":request", $this->request); |
|
87 | + $statement->bindValue(":emailtemplate", $this->emailtemplate); |
|
88 | + $statement->bindValue(":parameters", $this->parameters); |
|
89 | + $statement->bindValue(":parent", $this->parent); |
|
90 | + |
|
91 | + if ($statement->execute()) { |
|
92 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
93 | + } |
|
94 | + else { |
|
95 | + throw new Exception($statement->errorInfo()); |
|
96 | + } |
|
97 | + } |
|
98 | + else { |
|
99 | + // update |
|
100 | + $statement = $this->dbObject->prepare(<<<SQL |
|
101 | 101 | UPDATE jobqueue SET |
102 | 102 | status = :status |
103 | 103 | , error = :error |
@@ -105,187 +105,187 @@ discard block |
||
105 | 105 | , updateversion = updateversion + 1 |
106 | 106 | WHERE id = :id AND updateversion = :updateversion; |
107 | 107 | SQL |
108 | - ); |
|
109 | - |
|
110 | - $statement->bindValue(":id", $this->id); |
|
111 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
112 | - |
|
113 | - $statement->bindValue(":status", $this->status); |
|
114 | - $statement->bindValue(":error", $this->error); |
|
115 | - $statement->bindValue(":ack", $this->acknowledged); |
|
116 | - |
|
117 | - if (!$statement->execute()) { |
|
118 | - throw new Exception($statement->errorInfo()); |
|
119 | - } |
|
120 | - |
|
121 | - if ($statement->rowCount() !== 1) { |
|
122 | - throw new OptimisticLockFailedException(); |
|
123 | - } |
|
124 | - |
|
125 | - $this->updateversion++; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - #region Properties |
|
130 | - |
|
131 | - /** |
|
132 | - * @return string |
|
133 | - */ |
|
134 | - public function getTask() |
|
135 | - { |
|
136 | - return $this->task; |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $task |
|
141 | - */ |
|
142 | - public function setTask($task) |
|
143 | - { |
|
144 | - $this->task = $task; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return int |
|
149 | - */ |
|
150 | - public function getTriggerUserId() |
|
151 | - { |
|
152 | - return $this->user; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @param int $user |
|
157 | - */ |
|
158 | - public function setTriggerUserId($user) |
|
159 | - { |
|
160 | - $this->user = $user; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @return int |
|
165 | - */ |
|
166 | - public function getRequest() |
|
167 | - { |
|
168 | - return $this->request; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param int $request |
|
173 | - */ |
|
174 | - public function setRequest($request) |
|
175 | - { |
|
176 | - $this->request = $request; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function getStatus() |
|
183 | - { |
|
184 | - return $this->status; |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param string $status |
|
189 | - */ |
|
190 | - public function setStatus($status) |
|
191 | - { |
|
192 | - $this->status = $status; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function getEnqueue() |
|
199 | - { |
|
200 | - return $this->enqueue; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param string $enqueue |
|
205 | - */ |
|
206 | - public function setEnqueue($enqueue) |
|
207 | - { |
|
208 | - $this->enqueue = $enqueue; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function getParameters() |
|
215 | - { |
|
216 | - return $this->parameters; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @param string $parameters |
|
221 | - */ |
|
222 | - public function setParameters($parameters) |
|
223 | - { |
|
224 | - $this->parameters = $parameters; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @return mixed |
|
229 | - */ |
|
230 | - public function getError() |
|
231 | - { |
|
232 | - return $this->error; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @param mixed $error |
|
237 | - */ |
|
238 | - public function setError($error) |
|
239 | - { |
|
240 | - $this->error = $error; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @return int |
|
245 | - */ |
|
246 | - public function getAcknowledged() |
|
247 | - { |
|
248 | - return $this->acknowledged; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @param int $acknowledged |
|
253 | - */ |
|
254 | - public function setAcknowledged($acknowledged) |
|
255 | - { |
|
256 | - $this->acknowledged = $acknowledged; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @return int |
|
261 | - */ |
|
262 | - public function getParent() |
|
263 | - { |
|
264 | - return $this->parent; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @param int $parent |
|
269 | - */ |
|
270 | - public function setParent($parent) |
|
271 | - { |
|
272 | - $this->parent = $parent; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @return int |
|
277 | - */ |
|
278 | - public function getEmailTemplate() |
|
279 | - { |
|
280 | - return $this->emailtemplate; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * @param int $emailTemplate |
|
285 | - */ |
|
286 | - public function setEmailTemplate($emailTemplate) |
|
287 | - { |
|
288 | - $this->emailtemplate = $emailTemplate; |
|
289 | - } |
|
290 | - #endregion |
|
108 | + ); |
|
109 | + |
|
110 | + $statement->bindValue(":id", $this->id); |
|
111 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
112 | + |
|
113 | + $statement->bindValue(":status", $this->status); |
|
114 | + $statement->bindValue(":error", $this->error); |
|
115 | + $statement->bindValue(":ack", $this->acknowledged); |
|
116 | + |
|
117 | + if (!$statement->execute()) { |
|
118 | + throw new Exception($statement->errorInfo()); |
|
119 | + } |
|
120 | + |
|
121 | + if ($statement->rowCount() !== 1) { |
|
122 | + throw new OptimisticLockFailedException(); |
|
123 | + } |
|
124 | + |
|
125 | + $this->updateversion++; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + #region Properties |
|
130 | + |
|
131 | + /** |
|
132 | + * @return string |
|
133 | + */ |
|
134 | + public function getTask() |
|
135 | + { |
|
136 | + return $this->task; |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $task |
|
141 | + */ |
|
142 | + public function setTask($task) |
|
143 | + { |
|
144 | + $this->task = $task; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return int |
|
149 | + */ |
|
150 | + public function getTriggerUserId() |
|
151 | + { |
|
152 | + return $this->user; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @param int $user |
|
157 | + */ |
|
158 | + public function setTriggerUserId($user) |
|
159 | + { |
|
160 | + $this->user = $user; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @return int |
|
165 | + */ |
|
166 | + public function getRequest() |
|
167 | + { |
|
168 | + return $this->request; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param int $request |
|
173 | + */ |
|
174 | + public function setRequest($request) |
|
175 | + { |
|
176 | + $this->request = $request; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function getStatus() |
|
183 | + { |
|
184 | + return $this->status; |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param string $status |
|
189 | + */ |
|
190 | + public function setStatus($status) |
|
191 | + { |
|
192 | + $this->status = $status; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function getEnqueue() |
|
199 | + { |
|
200 | + return $this->enqueue; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param string $enqueue |
|
205 | + */ |
|
206 | + public function setEnqueue($enqueue) |
|
207 | + { |
|
208 | + $this->enqueue = $enqueue; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function getParameters() |
|
215 | + { |
|
216 | + return $this->parameters; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @param string $parameters |
|
221 | + */ |
|
222 | + public function setParameters($parameters) |
|
223 | + { |
|
224 | + $this->parameters = $parameters; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @return mixed |
|
229 | + */ |
|
230 | + public function getError() |
|
231 | + { |
|
232 | + return $this->error; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @param mixed $error |
|
237 | + */ |
|
238 | + public function setError($error) |
|
239 | + { |
|
240 | + $this->error = $error; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @return int |
|
245 | + */ |
|
246 | + public function getAcknowledged() |
|
247 | + { |
|
248 | + return $this->acknowledged; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @param int $acknowledged |
|
253 | + */ |
|
254 | + public function setAcknowledged($acknowledged) |
|
255 | + { |
|
256 | + $this->acknowledged = $acknowledged; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @return int |
|
261 | + */ |
|
262 | + public function getParent() |
|
263 | + { |
|
264 | + return $this->parent; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @param int $parent |
|
269 | + */ |
|
270 | + public function setParent($parent) |
|
271 | + { |
|
272 | + $this->parent = $parent; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @return int |
|
277 | + */ |
|
278 | + public function getEmailTemplate() |
|
279 | + { |
|
280 | + return $this->emailtemplate; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * @param int $emailTemplate |
|
285 | + */ |
|
286 | + public function setEmailTemplate($emailTemplate) |
|
287 | + { |
|
288 | + $this->emailtemplate = $emailTemplate; |
|
289 | + } |
|
290 | + #endregion |
|
291 | 291 | } |
292 | 292 | \ No newline at end of file |
@@ -58,7 +58,8 @@ |
||
58 | 58 | /** |
59 | 59 | * This feels like the least bad place to put this method. |
60 | 60 | */ |
61 | - public static function getTaskDescriptions() { |
|
61 | + public static function getTaskDescriptions() |
|
62 | + { |
|
62 | 63 | return array( |
63 | 64 | BotCreationTask::class => 'Create account (via bot)', |
64 | 65 | UserCreationTask::class => 'Create account (via OAuth)', |
@@ -25,155 +25,155 @@ |
||
25 | 25 | |
26 | 26 | abstract class ApplicationBase |
27 | 27 | { |
28 | - private $configuration; |
|
29 | - |
|
30 | - public function __construct(SiteConfiguration $configuration) |
|
31 | - { |
|
32 | - $this->configuration = $configuration; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Application entry point. |
|
37 | - * |
|
38 | - * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
39 | - */ |
|
40 | - public function run() |
|
41 | - { |
|
42 | - try { |
|
43 | - if ($this->setupEnvironment()) { |
|
44 | - $this->main(); |
|
45 | - } |
|
46 | - } |
|
47 | - catch (Exception $ex) { |
|
48 | - print $ex->getMessage(); |
|
49 | - } |
|
50 | - finally { |
|
51 | - $this->cleanupEnvironment(); |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Environment setup |
|
57 | - * |
|
58 | - * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
59 | - * and shut down prematurely. |
|
60 | - * |
|
61 | - * @return bool |
|
62 | - * @throws EnvironmentException |
|
63 | - */ |
|
64 | - protected function setupEnvironment() |
|
65 | - { |
|
66 | - $this->setupDatabase(); |
|
67 | - |
|
68 | - return true; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return PdoDatabase |
|
73 | - * @throws EnvironmentException |
|
74 | - * @throws Exception |
|
75 | - */ |
|
76 | - protected function setupDatabase() |
|
77 | - { |
|
78 | - // check the schema version |
|
79 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
80 | - |
|
81 | - /** @var int $actualVersion */ |
|
82 | - $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
83 | - if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
84 | - throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
85 | - } |
|
86 | - |
|
87 | - return $database; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @return SiteConfiguration |
|
92 | - */ |
|
93 | - public function getConfiguration() |
|
94 | - { |
|
95 | - return $this->configuration; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Main application logic |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - abstract protected function main(); |
|
103 | - |
|
104 | - /** |
|
105 | - * Any cleanup tasks should go here |
|
106 | - * |
|
107 | - * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
108 | - * This should *only* be for cleaning up, no logic should go here. |
|
109 | - * |
|
110 | - * @return void |
|
111 | - */ |
|
112 | - abstract protected function cleanupEnvironment(); |
|
113 | - |
|
114 | - /** |
|
115 | - * @param ITask $page |
|
116 | - * @param SiteConfiguration $siteConfiguration |
|
117 | - * @param PdoDatabase $database |
|
118 | - * @param PdoDatabase $notificationsDatabase |
|
119 | - * |
|
120 | - * @return void |
|
121 | - */ |
|
122 | - protected function setupHelpers( |
|
123 | - ITask $page, |
|
124 | - SiteConfiguration $siteConfiguration, |
|
125 | - PdoDatabase $database, |
|
126 | - PdoDatabase $notificationsDatabase = null |
|
127 | - ) { |
|
128 | - $page->setSiteConfiguration($siteConfiguration); |
|
129 | - |
|
130 | - // setup the global database object |
|
131 | - $page->setDatabase($database); |
|
132 | - |
|
133 | - // set up helpers and inject them into the page. |
|
134 | - $httpHelper = new HttpHelper( |
|
135 | - $siteConfiguration->getUserAgent(), |
|
136 | - $siteConfiguration->getCurlDisableVerifyPeer() |
|
137 | - ); |
|
138 | - |
|
139 | - $page->setEmailHelper(new EmailHelper()); |
|
140 | - $page->setHttpHelper($httpHelper); |
|
141 | - $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
142 | - |
|
143 | - if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
144 | - $page->setLocationProvider(new FakeLocationProvider()); |
|
145 | - } |
|
146 | - else { |
|
147 | - $page->setLocationProvider( |
|
148 | - new IpLocationProvider( |
|
149 | - $database, |
|
150 | - $siteConfiguration->getLocationProviderApiKey(), |
|
151 | - $httpHelper |
|
152 | - )); |
|
153 | - } |
|
154 | - |
|
155 | - $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
156 | - |
|
157 | - $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
158 | - |
|
159 | - $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
160 | - $database, |
|
161 | - $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
162 | - $httpHelper)); |
|
163 | - |
|
164 | - $page->setOAuthProtocolHelper(new OAuthProtocolHelper( |
|
165 | - $siteConfiguration->getOAuthBaseUrl(), |
|
166 | - $siteConfiguration->getOAuthConsumerToken(), |
|
167 | - $siteConfiguration->getOAuthConsumerSecret(), |
|
168 | - $httpHelper, |
|
169 | - $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
170 | - )); |
|
171 | - |
|
172 | - $page->setNotificationHelper(new IrcNotificationHelper( |
|
173 | - $siteConfiguration, |
|
174 | - $database, |
|
175 | - $notificationsDatabase)); |
|
176 | - |
|
177 | - $page->setTorExitProvider(new TorExitProvider($database)); |
|
178 | - } |
|
28 | + private $configuration; |
|
29 | + |
|
30 | + public function __construct(SiteConfiguration $configuration) |
|
31 | + { |
|
32 | + $this->configuration = $configuration; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Application entry point. |
|
37 | + * |
|
38 | + * Sets up the environment and runs the application, performing any global cleanup operations when done. |
|
39 | + */ |
|
40 | + public function run() |
|
41 | + { |
|
42 | + try { |
|
43 | + if ($this->setupEnvironment()) { |
|
44 | + $this->main(); |
|
45 | + } |
|
46 | + } |
|
47 | + catch (Exception $ex) { |
|
48 | + print $ex->getMessage(); |
|
49 | + } |
|
50 | + finally { |
|
51 | + $this->cleanupEnvironment(); |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Environment setup |
|
57 | + * |
|
58 | + * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false |
|
59 | + * and shut down prematurely. |
|
60 | + * |
|
61 | + * @return bool |
|
62 | + * @throws EnvironmentException |
|
63 | + */ |
|
64 | + protected function setupEnvironment() |
|
65 | + { |
|
66 | + $this->setupDatabase(); |
|
67 | + |
|
68 | + return true; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return PdoDatabase |
|
73 | + * @throws EnvironmentException |
|
74 | + * @throws Exception |
|
75 | + */ |
|
76 | + protected function setupDatabase() |
|
77 | + { |
|
78 | + // check the schema version |
|
79 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
80 | + |
|
81 | + /** @var int $actualVersion */ |
|
82 | + $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn(); |
|
83 | + if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) { |
|
84 | + throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.'); |
|
85 | + } |
|
86 | + |
|
87 | + return $database; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @return SiteConfiguration |
|
92 | + */ |
|
93 | + public function getConfiguration() |
|
94 | + { |
|
95 | + return $this->configuration; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Main application logic |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + abstract protected function main(); |
|
103 | + |
|
104 | + /** |
|
105 | + * Any cleanup tasks should go here |
|
106 | + * |
|
107 | + * Note that we need to be very careful here, as exceptions may have been thrown and handled. |
|
108 | + * This should *only* be for cleaning up, no logic should go here. |
|
109 | + * |
|
110 | + * @return void |
|
111 | + */ |
|
112 | + abstract protected function cleanupEnvironment(); |
|
113 | + |
|
114 | + /** |
|
115 | + * @param ITask $page |
|
116 | + * @param SiteConfiguration $siteConfiguration |
|
117 | + * @param PdoDatabase $database |
|
118 | + * @param PdoDatabase $notificationsDatabase |
|
119 | + * |
|
120 | + * @return void |
|
121 | + */ |
|
122 | + protected function setupHelpers( |
|
123 | + ITask $page, |
|
124 | + SiteConfiguration $siteConfiguration, |
|
125 | + PdoDatabase $database, |
|
126 | + PdoDatabase $notificationsDatabase = null |
|
127 | + ) { |
|
128 | + $page->setSiteConfiguration($siteConfiguration); |
|
129 | + |
|
130 | + // setup the global database object |
|
131 | + $page->setDatabase($database); |
|
132 | + |
|
133 | + // set up helpers and inject them into the page. |
|
134 | + $httpHelper = new HttpHelper( |
|
135 | + $siteConfiguration->getUserAgent(), |
|
136 | + $siteConfiguration->getCurlDisableVerifyPeer() |
|
137 | + ); |
|
138 | + |
|
139 | + $page->setEmailHelper(new EmailHelper()); |
|
140 | + $page->setHttpHelper($httpHelper); |
|
141 | + $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper())); |
|
142 | + |
|
143 | + if ($siteConfiguration->getLocationProviderApiKey() === null) { |
|
144 | + $page->setLocationProvider(new FakeLocationProvider()); |
|
145 | + } |
|
146 | + else { |
|
147 | + $page->setLocationProvider( |
|
148 | + new IpLocationProvider( |
|
149 | + $database, |
|
150 | + $siteConfiguration->getLocationProviderApiKey(), |
|
151 | + $httpHelper |
|
152 | + )); |
|
153 | + } |
|
154 | + |
|
155 | + $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database)); |
|
156 | + |
|
157 | + $page->setRdnsProvider(new CachedRDnsLookupProvider($database)); |
|
158 | + |
|
159 | + $page->setAntiSpoofProvider(new CachedApiAntispoofProvider( |
|
160 | + $database, |
|
161 | + $this->getConfiguration()->getMediawikiWebServiceEndpoint(), |
|
162 | + $httpHelper)); |
|
163 | + |
|
164 | + $page->setOAuthProtocolHelper(new OAuthProtocolHelper( |
|
165 | + $siteConfiguration->getOAuthBaseUrl(), |
|
166 | + $siteConfiguration->getOAuthConsumerToken(), |
|
167 | + $siteConfiguration->getOAuthConsumerSecret(), |
|
168 | + $httpHelper, |
|
169 | + $siteConfiguration->getMediawikiWebServiceEndpoint() |
|
170 | + )); |
|
171 | + |
|
172 | + $page->setNotificationHelper(new IrcNotificationHelper( |
|
173 | + $siteConfiguration, |
|
174 | + $database, |
|
175 | + $notificationsDatabase)); |
|
176 | + |
|
177 | + $page->setTorExitProvider(new TorExitProvider($database)); |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | \ No newline at end of file |
@@ -15,74 +15,74 @@ |
||
15 | 15 | |
16 | 16 | class ConsoleStart extends ApplicationBase |
17 | 17 | { |
18 | - /** |
|
19 | - * @var ConsoleTaskBase |
|
20 | - */ |
|
21 | - private $consoleTask; |
|
18 | + /** |
|
19 | + * @var ConsoleTaskBase |
|
20 | + */ |
|
21 | + private $consoleTask; |
|
22 | 22 | |
23 | - /** |
|
24 | - * ConsoleStart constructor. |
|
25 | - * |
|
26 | - * @param SiteConfiguration $configuration |
|
27 | - * @param ConsoleTaskBase $consoleTask |
|
28 | - */ |
|
29 | - public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | - { |
|
31 | - parent::__construct($configuration); |
|
32 | - $this->consoleTask = $consoleTask; |
|
33 | - } |
|
23 | + /** |
|
24 | + * ConsoleStart constructor. |
|
25 | + * |
|
26 | + * @param SiteConfiguration $configuration |
|
27 | + * @param ConsoleTaskBase $consoleTask |
|
28 | + */ |
|
29 | + public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask) |
|
30 | + { |
|
31 | + parent::__construct($configuration); |
|
32 | + $this->consoleTask = $consoleTask; |
|
33 | + } |
|
34 | 34 | |
35 | - protected function setupEnvironment() |
|
36 | - { |
|
37 | - // initialise super-global providers |
|
38 | - WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
35 | + protected function setupEnvironment() |
|
36 | + { |
|
37 | + // initialise super-global providers |
|
38 | + WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider()); |
|
39 | 39 | |
40 | - if (WebRequest::method() !== null) { |
|
41 | - throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | - } |
|
40 | + if (WebRequest::method() !== null) { |
|
41 | + throw new EnvironmentException('This is a console task, which cannot be executed via the web.'); |
|
42 | + } |
|
43 | 43 | |
44 | - return parent::setupEnvironment(); |
|
45 | - } |
|
44 | + return parent::setupEnvironment(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function cleanupEnvironment() |
|
48 | - { |
|
49 | - } |
|
47 | + protected function cleanupEnvironment() |
|
48 | + { |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Main application logic |
|
53 | - */ |
|
54 | - protected function main() |
|
55 | - { |
|
56 | - $database = PdoDatabase::getDatabaseConnection('acc'); |
|
51 | + /** |
|
52 | + * Main application logic |
|
53 | + */ |
|
54 | + protected function main() |
|
55 | + { |
|
56 | + $database = PdoDatabase::getDatabaseConnection('acc'); |
|
57 | 57 | |
58 | - if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
|
59 | - $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
60 | - } |
|
61 | - else { |
|
62 | - // pass through null |
|
63 | - $notificationsDatabase = null; |
|
64 | - } |
|
58 | + if ($this->getConfiguration()->getIrcNotificationsEnabled()) { |
|
59 | + $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications'); |
|
60 | + } |
|
61 | + else { |
|
62 | + // pass through null |
|
63 | + $notificationsDatabase = null; |
|
64 | + } |
|
65 | 65 | |
66 | - $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase); |
|
66 | + $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase); |
|
67 | 67 | |
68 | - // initialise a database transaction |
|
69 | - if (!$database->beginTransaction()) { |
|
70 | - throw new Exception('Failed to start transaction on primary database.'); |
|
71 | - } |
|
68 | + // initialise a database transaction |
|
69 | + if (!$database->beginTransaction()) { |
|
70 | + throw new Exception('Failed to start transaction on primary database.'); |
|
71 | + } |
|
72 | 72 | |
73 | - try { |
|
74 | - // run the task |
|
75 | - $this->consoleTask->execute(); |
|
73 | + try { |
|
74 | + // run the task |
|
75 | + $this->consoleTask->execute(); |
|
76 | 76 | |
77 | - if ($database->hasActiveTransaction()) { |
|
78 | - $database->commit(); |
|
79 | - } |
|
80 | - } |
|
81 | - finally { |
|
82 | - // Catch any hanging on transactions |
|
83 | - if ($database->hasActiveTransaction()) { |
|
84 | - $database->rollBack(); |
|
85 | - } |
|
86 | - } |
|
87 | - } |
|
77 | + if ($database->hasActiveTransaction()) { |
|
78 | + $database->commit(); |
|
79 | + } |
|
80 | + } |
|
81 | + finally { |
|
82 | + // Catch any hanging on transactions |
|
83 | + if ($database->hasActiveTransaction()) { |
|
84 | + $database->rollBack(); |
|
85 | + } |
|
86 | + } |
|
87 | + } |
|
88 | 88 | } |
89 | 89 | \ No newline at end of file |
@@ -17,35 +17,35 @@ |
||
17 | 17 | |
18 | 18 | class RefreshOAuthDataTask extends ConsoleTaskBase |
19 | 19 | { |
20 | - public function execute() |
|
21 | - { |
|
22 | - $database = $this->getDatabase(); |
|
23 | - |
|
24 | - $idList = $database |
|
25 | - ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL') |
|
26 | - ->fetchAll(PDO::FETCH_COLUMN); |
|
27 | - |
|
28 | - if (count($idList) > 0) { |
|
29 | - /** @var User[] $users */ |
|
30 | - $users = UserSearchHelper::get($database)->inIds($idList)->fetch(); |
|
31 | - |
|
32 | - $expiredStatement = $database |
|
33 | - ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\''); |
|
34 | - |
|
35 | - foreach ($users as $u) { |
|
36 | - $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), |
|
37 | - $this->getSiteConfiguration()); |
|
38 | - |
|
39 | - try { |
|
40 | - $oauth->refreshIdentity(); |
|
41 | - } |
|
42 | - catch (OAuthException $ex) { |
|
43 | - $expiredStatement->execute(array(':u' => $u->getId())); |
|
44 | - } |
|
45 | - } |
|
46 | - } |
|
47 | - |
|
48 | - $this->getDatabase() |
|
49 | - ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\''); |
|
50 | - } |
|
20 | + public function execute() |
|
21 | + { |
|
22 | + $database = $this->getDatabase(); |
|
23 | + |
|
24 | + $idList = $database |
|
25 | + ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL') |
|
26 | + ->fetchAll(PDO::FETCH_COLUMN); |
|
27 | + |
|
28 | + if (count($idList) > 0) { |
|
29 | + /** @var User[] $users */ |
|
30 | + $users = UserSearchHelper::get($database)->inIds($idList)->fetch(); |
|
31 | + |
|
32 | + $expiredStatement = $database |
|
33 | + ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\''); |
|
34 | + |
|
35 | + foreach ($users as $u) { |
|
36 | + $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), |
|
37 | + $this->getSiteConfiguration()); |
|
38 | + |
|
39 | + try { |
|
40 | + $oauth->refreshIdentity(); |
|
41 | + } |
|
42 | + catch (OAuthException $ex) { |
|
43 | + $expiredStatement->execute(array(':u' => $u->getId())); |
|
44 | + } |
|
45 | + } |
|
46 | + } |
|
47 | + |
|
48 | + $this->getDatabase() |
|
49 | + ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\''); |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | \ No newline at end of file |
@@ -14,19 +14,19 @@ |
||
14 | 14 | |
15 | 15 | class ClearOAuthDataTask extends ConsoleTaskBase |
16 | 16 | { |
17 | - public function execute() |
|
18 | - { |
|
19 | - $database = $this->getDatabase(); |
|
17 | + public function execute() |
|
18 | + { |
|
19 | + $database = $this->getDatabase(); |
|
20 | 20 | |
21 | - $users = UserSearchHelper::get($database)->inIds( |
|
22 | - $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
|
21 | + $users = UserSearchHelper::get($database)->inIds( |
|
22 | + $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
|
23 | 23 | |
24 | - foreach ($users as $u){ |
|
25 | - $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
26 | - $oauth->detach(); |
|
27 | - } |
|
24 | + foreach ($users as $u){ |
|
25 | + $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
26 | + $oauth->detach(); |
|
27 | + } |
|
28 | 28 | |
29 | - $database->exec('DELETE FROM oauthtoken'); |
|
30 | - $database->exec('DELETE FROM oauthidentity'); |
|
31 | - } |
|
29 | + $database->exec('DELETE FROM oauthtoken'); |
|
30 | + $database->exec('DELETE FROM oauthidentity'); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
21 | 21 | $users = UserSearchHelper::get($database)->inIds( |
22 | 22 | $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
23 | 23 | |
24 | - foreach ($users as $u){ |
|
24 | + foreach ($users as $u) { |
|
25 | 25 | $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
26 | 26 | $oauth->detach(); |
27 | 27 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | $users = UserSearchHelper::get($database)->inIds( |
22 | 22 | $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn()); |
23 | 23 | |
24 | - foreach ($users as $u){ |
|
24 | + foreach ($users as $u) { |
|
25 | 25 | $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
26 | 26 | $oauth->detach(); |
27 | 27 | } |
@@ -19,54 +19,54 @@ |
||
19 | 19 | |
20 | 20 | abstract class RequestActionBase extends InternalPageBase |
21 | 21 | { |
22 | - /** |
|
23 | - * @param PdoDatabase $database |
|
24 | - * |
|
25 | - * @return Request |
|
26 | - * @throws ApplicationLogicException |
|
27 | - */ |
|
28 | - protected function getRequest(PdoDatabase $database) |
|
29 | - { |
|
30 | - $requestId = WebRequest::postInt('request'); |
|
31 | - if ($requestId === null) { |
|
32 | - throw new ApplicationLogicException('Request ID not found'); |
|
33 | - } |
|
22 | + /** |
|
23 | + * @param PdoDatabase $database |
|
24 | + * |
|
25 | + * @return Request |
|
26 | + * @throws ApplicationLogicException |
|
27 | + */ |
|
28 | + protected function getRequest(PdoDatabase $database) |
|
29 | + { |
|
30 | + $requestId = WebRequest::postInt('request'); |
|
31 | + if ($requestId === null) { |
|
32 | + throw new ApplicationLogicException('Request ID not found'); |
|
33 | + } |
|
34 | 34 | |
35 | - /** @var Request $request */ |
|
36 | - $request = Request::getById($requestId, $database); |
|
35 | + /** @var Request $request */ |
|
36 | + $request = Request::getById($requestId, $database); |
|
37 | 37 | |
38 | - if ($request === false) { |
|
39 | - throw new ApplicationLogicException('Request not found'); |
|
40 | - } |
|
38 | + if ($request === false) { |
|
39 | + throw new ApplicationLogicException('Request not found'); |
|
40 | + } |
|
41 | 41 | |
42 | - return $request; |
|
43 | - } |
|
42 | + return $request; |
|
43 | + } |
|
44 | 44 | |
45 | - final protected function checkPosted() |
|
46 | - { |
|
47 | - // if the request was not posted, send the user away. |
|
48 | - if (!WebRequest::wasPosted()) { |
|
49 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
50 | - } |
|
45 | + final protected function checkPosted() |
|
46 | + { |
|
47 | + // if the request was not posted, send the user away. |
|
48 | + if (!WebRequest::wasPosted()) { |
|
49 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
50 | + } |
|
51 | 51 | |
52 | - // validate the CSRF token |
|
53 | - $this->validateCSRFToken(); |
|
54 | - } |
|
52 | + // validate the CSRF token |
|
53 | + $this->validateCSRFToken(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * @param Request $request |
|
58 | - * @param $parentTaskId |
|
59 | - * @param User $user |
|
60 | - * @param PdoDatabase $database |
|
61 | - */ |
|
62 | - protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
|
63 | - { |
|
64 | - $welcomeTask = new JobQueue(); |
|
65 | - $welcomeTask->setTask(WelcomeUserTask::class); |
|
66 | - $welcomeTask->setRequest($request->getId()); |
|
67 | - $welcomeTask->setParent($parentTaskId); |
|
68 | - $welcomeTask->setTriggerUserId($user->getId()); |
|
69 | - $welcomeTask->setDatabase($database); |
|
70 | - $welcomeTask->save(); |
|
71 | - } |
|
56 | + /** |
|
57 | + * @param Request $request |
|
58 | + * @param $parentTaskId |
|
59 | + * @param User $user |
|
60 | + * @param PdoDatabase $database |
|
61 | + */ |
|
62 | + protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
|
63 | + { |
|
64 | + $welcomeTask = new JobQueue(); |
|
65 | + $welcomeTask->setTask(WelcomeUserTask::class); |
|
66 | + $welcomeTask->setRequest($request->getId()); |
|
67 | + $welcomeTask->setParent($parentTaskId); |
|
68 | + $welcomeTask->setTriggerUserId($user->getId()); |
|
69 | + $welcomeTask->setDatabase($database); |
|
70 | + $welcomeTask->save(); |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | \ No newline at end of file |
@@ -15,22 +15,22 @@ |
||
15 | 15 | |
16 | 16 | class PageDropRequest extends PageCloseRequest |
17 | 17 | { |
18 | - protected function getTemplate(PdoDatabase $database) |
|
19 | - { |
|
20 | - return EmailTemplate::getDroppedTemplate(); |
|
21 | - } |
|
18 | + protected function getTemplate(PdoDatabase $database) |
|
19 | + { |
|
20 | + return EmailTemplate::getDroppedTemplate(); |
|
21 | + } |
|
22 | 22 | |
23 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
24 | - { |
|
25 | - return false; |
|
26 | - } |
|
23 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
24 | + { |
|
25 | + return false; |
|
26 | + } |
|
27 | 27 | |
28 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
29 | - { |
|
30 | - return false; |
|
31 | - } |
|
28 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
29 | + { |
|
30 | + return false; |
|
31 | + } |
|
32 | 32 | |
33 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
34 | - { |
|
35 | - } |
|
33 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
34 | + { |
|
35 | + } |
|
36 | 36 | } |
37 | 37 | \ No newline at end of file |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | $results = $search->getRecordCount($requestCount)->fetch(); |
113 | 113 | |
114 | - if($requestCount > 0) { |
|
114 | + if ($requestCount > 0) { |
|
115 | 115 | $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
116 | 116 | 'requests' => $results, |
117 | 117 | 'total' => $requestCount, |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $results = $search->getRecordCount($requestCount)->fetch(); |
145 | 145 | |
146 | - if($requestCount > 0) { |
|
146 | + if ($requestCount > 0) { |
|
147 | 147 | $requestSectionData['Requests queued in the Job Queue'] = array( |
148 | 148 | 'requests' => $results, |
149 | 149 | 'total' => $requestCount, |
@@ -20,65 +20,65 @@ discard block |
||
20 | 20 | |
21 | 21 | class PageMain extends InternalPageBase |
22 | 22 | { |
23 | - /** |
|
24 | - * Main function for this page, when no actions are called. |
|
25 | - */ |
|
26 | - protected function main() |
|
27 | - { |
|
28 | - $this->assignCSRFToken(); |
|
29 | - |
|
30 | - $config = $this->getSiteConfiguration(); |
|
31 | - $database = $this->getDatabase(); |
|
32 | - $currentUser = User::getCurrent($database); |
|
33 | - |
|
34 | - // general template configuration |
|
35 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
36 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
37 | - |
|
38 | - // Get map of possible usernames |
|
39 | - $userList = UserSearchHelper::get($database)->withReservedRequest(); |
|
40 | - $this->assign('userList', $userList); |
|
41 | - |
|
42 | - $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class); |
|
43 | - $this->assign('showPrivateData', $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')); |
|
44 | - $this->assign('xff', $this->getXffTrustProvider()); |
|
45 | - |
|
46 | - $this->assign('dataClearEmail', $config->getDataClearEmail()); |
|
47 | - $this->assign('dataClearIp', $config->getDataClearIp()); |
|
48 | - |
|
49 | - // Fetch request data |
|
50 | - $requestSectionData = array(); |
|
51 | - if ($seeAllRequests) { |
|
52 | - $this->setupStatusSections($database, $config, $requestSectionData); |
|
53 | - $this->setupHospitalQueue($database, $config, $requestSectionData); |
|
54 | - $this->setupJobQueue($database, $config, $requestSectionData); |
|
55 | - } |
|
56 | - $this->setupLastFiveClosedData($database, $seeAllRequests); |
|
57 | - |
|
58 | - // Assign data to template |
|
59 | - $this->assign('requestSectionData', $requestSectionData); |
|
60 | - |
|
61 | - // Extra rights |
|
62 | - $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
63 | - $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
64 | - |
|
65 | - $this->setTemplate('mainpage/mainpage.tpl'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @param PdoDatabase $database |
|
70 | - * @param bool $seeAllRequests |
|
71 | - * |
|
72 | - * @internal param User $currentUser |
|
73 | - */ |
|
74 | - private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests) |
|
75 | - { |
|
76 | - $this->assign('showLastFive', $seeAllRequests); |
|
77 | - if (!$seeAllRequests) { |
|
78 | - return; |
|
79 | - } |
|
80 | - |
|
81 | - $query = <<<SQL |
|
23 | + /** |
|
24 | + * Main function for this page, when no actions are called. |
|
25 | + */ |
|
26 | + protected function main() |
|
27 | + { |
|
28 | + $this->assignCSRFToken(); |
|
29 | + |
|
30 | + $config = $this->getSiteConfiguration(); |
|
31 | + $database = $this->getDatabase(); |
|
32 | + $currentUser = User::getCurrent($database); |
|
33 | + |
|
34 | + // general template configuration |
|
35 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
36 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
37 | + |
|
38 | + // Get map of possible usernames |
|
39 | + $userList = UserSearchHelper::get($database)->withReservedRequest(); |
|
40 | + $this->assign('userList', $userList); |
|
41 | + |
|
42 | + $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class); |
|
43 | + $this->assign('showPrivateData', $this->barrierTest('alwaysSeePrivateData', $currentUser, 'RequestData')); |
|
44 | + $this->assign('xff', $this->getXffTrustProvider()); |
|
45 | + |
|
46 | + $this->assign('dataClearEmail', $config->getDataClearEmail()); |
|
47 | + $this->assign('dataClearIp', $config->getDataClearIp()); |
|
48 | + |
|
49 | + // Fetch request data |
|
50 | + $requestSectionData = array(); |
|
51 | + if ($seeAllRequests) { |
|
52 | + $this->setupStatusSections($database, $config, $requestSectionData); |
|
53 | + $this->setupHospitalQueue($database, $config, $requestSectionData); |
|
54 | + $this->setupJobQueue($database, $config, $requestSectionData); |
|
55 | + } |
|
56 | + $this->setupLastFiveClosedData($database, $seeAllRequests); |
|
57 | + |
|
58 | + // Assign data to template |
|
59 | + $this->assign('requestSectionData', $requestSectionData); |
|
60 | + |
|
61 | + // Extra rights |
|
62 | + $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
63 | + $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class)); |
|
64 | + |
|
65 | + $this->setTemplate('mainpage/mainpage.tpl'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @param PdoDatabase $database |
|
70 | + * @param bool $seeAllRequests |
|
71 | + * |
|
72 | + * @internal param User $currentUser |
|
73 | + */ |
|
74 | + private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests) |
|
75 | + { |
|
76 | + $this->assign('showLastFive', $seeAllRequests); |
|
77 | + if (!$seeAllRequests) { |
|
78 | + return; |
|
79 | + } |
|
80 | + |
|
81 | + $query = <<<SQL |
|
82 | 82 | SELECT request.id, request.name, request.updateversion |
83 | 83 | FROM request /* PageMain::main() */ |
84 | 84 | JOIN log ON log.objectid = request.id AND log.objecttype = 'Request' |
@@ -87,140 +87,140 @@ discard block |
||
87 | 87 | LIMIT 5; |
88 | 88 | SQL; |
89 | 89 | |
90 | - $statement = $database->prepare($query); |
|
91 | - $statement->execute(); |
|
92 | - |
|
93 | - $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
94 | - |
|
95 | - $this->assign('lastFive', $last5result); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param PdoDatabase $database |
|
100 | - * @param SiteConfiguration $config |
|
101 | - * @param $requestSectionData |
|
102 | - */ |
|
103 | - private function setupHospitalQueue( |
|
104 | - PdoDatabase $database, |
|
105 | - SiteConfiguration $config, |
|
106 | - &$requestSectionData |
|
107 | - ) { |
|
108 | - $search = RequestSearchHelper::get($database) |
|
109 | - ->limit($config->getMiserModeLimit()) |
|
110 | - ->excludingStatus('Closed') |
|
111 | - ->isHospitalised(); |
|
112 | - |
|
113 | - if ($config->getEmailConfirmationEnabled()) { |
|
114 | - $search->withConfirmedEmail(); |
|
115 | - } |
|
116 | - |
|
117 | - $results = $search->getRecordCount($requestCount)->fetch(); |
|
118 | - |
|
119 | - if($requestCount > 0) { |
|
120 | - $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
|
121 | - 'requests' => $results, |
|
122 | - 'total' => $requestCount, |
|
123 | - 'api' => 'hospital', |
|
124 | - 'type' => 'hospital', |
|
125 | - 'special' => 'Job Queue', |
|
126 | - 'help' => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.' |
|
127 | - ); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * @param PdoDatabase $database |
|
133 | - * @param SiteConfiguration $config |
|
134 | - * @param $requestSectionData |
|
135 | - */ |
|
136 | - private function setupJobQueue( |
|
137 | - PdoDatabase $database, |
|
138 | - SiteConfiguration $config, |
|
139 | - &$requestSectionData |
|
140 | - ) { |
|
141 | - $search = RequestSearchHelper::get($database) |
|
142 | - ->limit($config->getMiserModeLimit()) |
|
143 | - ->byStatus(RequestStatus::JOBQUEUE); |
|
144 | - |
|
145 | - if ($config->getEmailConfirmationEnabled()) { |
|
146 | - $search->withConfirmedEmail(); |
|
147 | - } |
|
148 | - |
|
149 | - $results = $search->getRecordCount($requestCount)->fetch(); |
|
150 | - |
|
151 | - if($requestCount > 0) { |
|
152 | - $requestSectionData['Requests queued in the Job Queue'] = array( |
|
153 | - 'requests' => $results, |
|
154 | - 'total' => $requestCount, |
|
155 | - 'api' => 'JobQueue', |
|
156 | - 'type' => 'JobQueue', |
|
157 | - 'special' => 'Job Queue', |
|
158 | - 'help' => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.' |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param PdoDatabase $database |
|
165 | - * @param SiteConfiguration $config |
|
166 | - * @param $requestSectionData |
|
167 | - */ |
|
168 | - private function setupStatusSections( |
|
169 | - PdoDatabase $database, |
|
170 | - SiteConfiguration $config, |
|
171 | - &$requestSectionData |
|
172 | - ) { |
|
173 | - $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised(); |
|
174 | - |
|
175 | - if ($config->getEmailConfirmationEnabled()) { |
|
176 | - $search->withConfirmedEmail(); |
|
177 | - } |
|
178 | - |
|
179 | - $allRequestStates = $config->getRequestStates(); |
|
180 | - $requestsByStatus = $search->fetchByStatus(array_keys($allRequestStates)); |
|
181 | - |
|
182 | - foreach ($allRequestStates as $requestState => $requestStateConfig) { |
|
183 | - |
|
184 | - $requestTrustedIp = []; |
|
185 | - $relatedEmailRequests = []; |
|
186 | - $relatedIpRequests = []; |
|
187 | - foreach ($requestsByStatus[$requestState]['data'] as $request) { |
|
188 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
189 | - $request->getIp(), |
|
190 | - $request->getForwardedIp() |
|
191 | - ); |
|
192 | - |
|
193 | - RequestSearchHelper::get($database) |
|
194 | - ->byIp($trustedIp) |
|
195 | - ->withConfirmedEmail() |
|
196 | - ->excludingPurgedData($config) |
|
197 | - ->excludingRequest($request->getId()) |
|
198 | - ->getRecordCount($ipCount); |
|
199 | - |
|
200 | - RequestSearchHelper::get($database) |
|
201 | - ->byEmailAddress($request->getEmail()) |
|
202 | - ->withConfirmedEmail() |
|
203 | - ->excludingPurgedData($config) |
|
204 | - ->excludingRequest($request->getId()) |
|
205 | - ->getRecordCount($emailCount); |
|
206 | - |
|
207 | - $requestTrustedIp[$request->getId()] = $trustedIp; |
|
208 | - $relatedEmailRequests[$request->getId()] = $emailCount; |
|
209 | - $relatedIpRequests[$request->getId()] = $ipCount; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - $requestSectionData[$requestStateConfig['header']] = array( |
|
214 | - 'requests' => $requestsByStatus[$requestState]['data'], |
|
215 | - 'total' => $requestsByStatus[$requestState]['count'], |
|
216 | - 'api' => $requestStateConfig['api'], |
|
217 | - 'type' => $requestState, |
|
218 | - 'special' => null, |
|
219 | - 'help' => $requestStateConfig['queuehelp'], |
|
220 | - 'requestTrustedIp' => $requestTrustedIp, |
|
221 | - 'relatedEmailRequests' => $relatedEmailRequests, |
|
222 | - 'relatedIpRequests' => $relatedIpRequests |
|
223 | - ); |
|
224 | - } |
|
225 | - } |
|
90 | + $statement = $database->prepare($query); |
|
91 | + $statement->execute(); |
|
92 | + |
|
93 | + $last5result = $statement->fetchAll(PDO::FETCH_ASSOC); |
|
94 | + |
|
95 | + $this->assign('lastFive', $last5result); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param PdoDatabase $database |
|
100 | + * @param SiteConfiguration $config |
|
101 | + * @param $requestSectionData |
|
102 | + */ |
|
103 | + private function setupHospitalQueue( |
|
104 | + PdoDatabase $database, |
|
105 | + SiteConfiguration $config, |
|
106 | + &$requestSectionData |
|
107 | + ) { |
|
108 | + $search = RequestSearchHelper::get($database) |
|
109 | + ->limit($config->getMiserModeLimit()) |
|
110 | + ->excludingStatus('Closed') |
|
111 | + ->isHospitalised(); |
|
112 | + |
|
113 | + if ($config->getEmailConfirmationEnabled()) { |
|
114 | + $search->withConfirmedEmail(); |
|
115 | + } |
|
116 | + |
|
117 | + $results = $search->getRecordCount($requestCount)->fetch(); |
|
118 | + |
|
119 | + if($requestCount > 0) { |
|
120 | + $requestSectionData['Hospital - Requests failed auto-creation'] = array( |
|
121 | + 'requests' => $results, |
|
122 | + 'total' => $requestCount, |
|
123 | + 'api' => 'hospital', |
|
124 | + 'type' => 'hospital', |
|
125 | + 'special' => 'Job Queue', |
|
126 | + 'help' => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.' |
|
127 | + ); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * @param PdoDatabase $database |
|
133 | + * @param SiteConfiguration $config |
|
134 | + * @param $requestSectionData |
|
135 | + */ |
|
136 | + private function setupJobQueue( |
|
137 | + PdoDatabase $database, |
|
138 | + SiteConfiguration $config, |
|
139 | + &$requestSectionData |
|
140 | + ) { |
|
141 | + $search = RequestSearchHelper::get($database) |
|
142 | + ->limit($config->getMiserModeLimit()) |
|
143 | + ->byStatus(RequestStatus::JOBQUEUE); |
|
144 | + |
|
145 | + if ($config->getEmailConfirmationEnabled()) { |
|
146 | + $search->withConfirmedEmail(); |
|
147 | + } |
|
148 | + |
|
149 | + $results = $search->getRecordCount($requestCount)->fetch(); |
|
150 | + |
|
151 | + if($requestCount > 0) { |
|
152 | + $requestSectionData['Requests queued in the Job Queue'] = array( |
|
153 | + 'requests' => $results, |
|
154 | + 'total' => $requestCount, |
|
155 | + 'api' => 'JobQueue', |
|
156 | + 'type' => 'JobQueue', |
|
157 | + 'special' => 'Job Queue', |
|
158 | + 'help' => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.' |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param PdoDatabase $database |
|
165 | + * @param SiteConfiguration $config |
|
166 | + * @param $requestSectionData |
|
167 | + */ |
|
168 | + private function setupStatusSections( |
|
169 | + PdoDatabase $database, |
|
170 | + SiteConfiguration $config, |
|
171 | + &$requestSectionData |
|
172 | + ) { |
|
173 | + $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised(); |
|
174 | + |
|
175 | + if ($config->getEmailConfirmationEnabled()) { |
|
176 | + $search->withConfirmedEmail(); |
|
177 | + } |
|
178 | + |
|
179 | + $allRequestStates = $config->getRequestStates(); |
|
180 | + $requestsByStatus = $search->fetchByStatus(array_keys($allRequestStates)); |
|
181 | + |
|
182 | + foreach ($allRequestStates as $requestState => $requestStateConfig) { |
|
183 | + |
|
184 | + $requestTrustedIp = []; |
|
185 | + $relatedEmailRequests = []; |
|
186 | + $relatedIpRequests = []; |
|
187 | + foreach ($requestsByStatus[$requestState]['data'] as $request) { |
|
188 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
189 | + $request->getIp(), |
|
190 | + $request->getForwardedIp() |
|
191 | + ); |
|
192 | + |
|
193 | + RequestSearchHelper::get($database) |
|
194 | + ->byIp($trustedIp) |
|
195 | + ->withConfirmedEmail() |
|
196 | + ->excludingPurgedData($config) |
|
197 | + ->excludingRequest($request->getId()) |
|
198 | + ->getRecordCount($ipCount); |
|
199 | + |
|
200 | + RequestSearchHelper::get($database) |
|
201 | + ->byEmailAddress($request->getEmail()) |
|
202 | + ->withConfirmedEmail() |
|
203 | + ->excludingPurgedData($config) |
|
204 | + ->excludingRequest($request->getId()) |
|
205 | + ->getRecordCount($emailCount); |
|
206 | + |
|
207 | + $requestTrustedIp[$request->getId()] = $trustedIp; |
|
208 | + $relatedEmailRequests[$request->getId()] = $emailCount; |
|
209 | + $relatedIpRequests[$request->getId()] = $ipCount; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + $requestSectionData[$requestStateConfig['header']] = array( |
|
214 | + 'requests' => $requestsByStatus[$requestState]['data'], |
|
215 | + 'total' => $requestsByStatus[$requestState]['count'], |
|
216 | + 'api' => $requestStateConfig['api'], |
|
217 | + 'type' => $requestState, |
|
218 | + 'special' => null, |
|
219 | + 'help' => $requestStateConfig['queuehelp'], |
|
220 | + 'requestTrustedIp' => $requestTrustedIp, |
|
221 | + 'relatedEmailRequests' => $relatedEmailRequests, |
|
222 | + 'relatedIpRequests' => $relatedIpRequests |
|
223 | + ); |
|
224 | + } |
|
225 | + } |
|
226 | 226 | } |