@@ -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 @@ discard block |
||
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)', |
@@ -90,12 +91,10 @@ discard block |
||
90 | 91 | |
91 | 92 | if ($statement->execute()) { |
92 | 93 | $this->id = (int)$this->dbObject->lastInsertId(); |
93 | - } |
|
94 | - else { |
|
94 | + } else { |
|
95 | 95 | throw new Exception($statement->errorInfo()); |
96 | 96 | } |
97 | - } |
|
98 | - else { |
|
97 | + } else { |
|
99 | 98 | // update |
100 | 99 | $statement = $this->dbObject->prepare(<<<SQL |
101 | 100 | UPDATE jobqueue SET |
@@ -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 |
@@ -42,12 +42,10 @@ |
||
42 | 42 | |
43 | 43 | if ($statement->execute()) { |
44 | 44 | $this->id = (int)$this->dbObject->lastInsertId(); |
45 | - } |
|
46 | - else { |
|
45 | + } else { |
|
47 | 46 | throw new Exception($statement->errorInfo()); |
48 | 47 | } |
49 | - } |
|
50 | - else { |
|
48 | + } else { |
|
51 | 49 | // update |
52 | 50 | $statement = $this->dbObject->prepare(<<<SQL |
53 | 51 | UPDATE oauthtoken |
@@ -21,160 +21,160 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class User extends DataObject |
23 | 23 | { |
24 | - const STATUS_ACTIVE = 'Active'; |
|
25 | - const STATUS_SUSPENDED = 'Suspended'; |
|
26 | - const STATUS_DECLINED = 'Declined'; |
|
27 | - const STATUS_NEW = 'New'; |
|
28 | - const CREATION_MANUAL = 0; |
|
29 | - const CREATION_OAUTH = 1; |
|
30 | - const CREATION_BOT = 2; |
|
31 | - private $username; |
|
32 | - private $email; |
|
33 | - private $status = self::STATUS_NEW; |
|
34 | - private $onwikiname; |
|
35 | - private $welcome_sig = ""; |
|
36 | - private $lastactive = "0000-00-00 00:00:00"; |
|
37 | - private $forcelogout = 0; |
|
38 | - private $forceidentified = null; |
|
39 | - private $welcome_template = 0; |
|
40 | - private $abortpref = 0; |
|
41 | - private $confirmationdiff = 0; |
|
42 | - private $emailsig = ""; |
|
43 | - private $creationmode = 0; |
|
44 | - private $skin = "main"; |
|
45 | - /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
46 | - private static $currentUser; |
|
47 | - #region Object load methods |
|
48 | - |
|
49 | - /** |
|
50 | - * Gets the currently logged in user |
|
51 | - * |
|
52 | - * @param PdoDatabase $database |
|
53 | - * |
|
54 | - * @return User|CommunityUser |
|
55 | - */ |
|
56 | - public static function getCurrent(PdoDatabase $database) |
|
57 | - { |
|
58 | - if (self::$currentUser === null) { |
|
59 | - $sessionId = WebRequest::getSessionUserId(); |
|
60 | - |
|
61 | - if ($sessionId !== null) { |
|
62 | - /** @var User $user */ |
|
63 | - $user = self::getById($sessionId, $database); |
|
64 | - |
|
65 | - if ($user === false) { |
|
66 | - self::$currentUser = new CommunityUser(); |
|
67 | - } |
|
68 | - else { |
|
69 | - self::$currentUser = $user; |
|
70 | - } |
|
71 | - } |
|
72 | - else { |
|
73 | - $anonymousCoward = new CommunityUser(); |
|
74 | - |
|
75 | - self::$currentUser = $anonymousCoward; |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - return self::$currentUser; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Gets a user by their user ID |
|
84 | - * |
|
85 | - * Pass -1 to get the community user. |
|
86 | - * |
|
87 | - * @param int|null $id |
|
88 | - * @param PdoDatabase $database |
|
89 | - * |
|
90 | - * @return User|false |
|
91 | - */ |
|
92 | - public static function getById($id, PdoDatabase $database) |
|
93 | - { |
|
94 | - if ($id === null || $id == -1) { |
|
95 | - return new CommunityUser(); |
|
96 | - } |
|
97 | - |
|
98 | - /** @var User|false $user */ |
|
99 | - $user = parent::getById($id, $database); |
|
100 | - |
|
101 | - return $user; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @return CommunityUser |
|
106 | - */ |
|
107 | - public static function getCommunity() |
|
108 | - { |
|
109 | - return new CommunityUser(); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Gets a user by their username |
|
114 | - * |
|
115 | - * @param string $username |
|
116 | - * @param PdoDatabase $database |
|
117 | - * |
|
118 | - * @return CommunityUser|User|false |
|
119 | - */ |
|
120 | - public static function getByUsername($username, PdoDatabase $database) |
|
121 | - { |
|
122 | - global $communityUsername; |
|
123 | - if ($username == $communityUsername) { |
|
124 | - return new CommunityUser(); |
|
125 | - } |
|
126 | - |
|
127 | - $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
128 | - $statement->bindValue(":id", $username); |
|
129 | - |
|
130 | - $statement->execute(); |
|
131 | - |
|
132 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
133 | - |
|
134 | - if ($resultObject != false) { |
|
135 | - $resultObject->setDatabase($database); |
|
136 | - } |
|
137 | - |
|
138 | - return $resultObject; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Gets a user by their on-wiki username. |
|
143 | - * |
|
144 | - * @param string $username |
|
145 | - * @param PdoDatabase $database |
|
146 | - * |
|
147 | - * @return User|false |
|
148 | - */ |
|
149 | - public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
150 | - { |
|
151 | - $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
152 | - $statement->bindValue(":id", $username); |
|
153 | - $statement->execute(); |
|
154 | - |
|
155 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
156 | - |
|
157 | - if ($resultObject != false) { |
|
158 | - $resultObject->setDatabase($database); |
|
159 | - |
|
160 | - return $resultObject; |
|
161 | - } |
|
162 | - |
|
163 | - return false; |
|
164 | - } |
|
165 | - |
|
166 | - #endregion |
|
167 | - |
|
168 | - /** |
|
169 | - * Saves the current object |
|
170 | - * |
|
171 | - * @throws Exception |
|
172 | - */ |
|
173 | - public function save() |
|
174 | - { |
|
175 | - if ($this->isNew()) { |
|
176 | - // insert |
|
177 | - $statement = $this->dbObject->prepare(<<<SQL |
|
24 | + const STATUS_ACTIVE = 'Active'; |
|
25 | + const STATUS_SUSPENDED = 'Suspended'; |
|
26 | + const STATUS_DECLINED = 'Declined'; |
|
27 | + const STATUS_NEW = 'New'; |
|
28 | + const CREATION_MANUAL = 0; |
|
29 | + const CREATION_OAUTH = 1; |
|
30 | + const CREATION_BOT = 2; |
|
31 | + private $username; |
|
32 | + private $email; |
|
33 | + private $status = self::STATUS_NEW; |
|
34 | + private $onwikiname; |
|
35 | + private $welcome_sig = ""; |
|
36 | + private $lastactive = "0000-00-00 00:00:00"; |
|
37 | + private $forcelogout = 0; |
|
38 | + private $forceidentified = null; |
|
39 | + private $welcome_template = 0; |
|
40 | + private $abortpref = 0; |
|
41 | + private $confirmationdiff = 0; |
|
42 | + private $emailsig = ""; |
|
43 | + private $creationmode = 0; |
|
44 | + private $skin = "main"; |
|
45 | + /** @var User Cache variable of the current user - it's never going to change in the middle of a request. */ |
|
46 | + private static $currentUser; |
|
47 | + #region Object load methods |
|
48 | + |
|
49 | + /** |
|
50 | + * Gets the currently logged in user |
|
51 | + * |
|
52 | + * @param PdoDatabase $database |
|
53 | + * |
|
54 | + * @return User|CommunityUser |
|
55 | + */ |
|
56 | + public static function getCurrent(PdoDatabase $database) |
|
57 | + { |
|
58 | + if (self::$currentUser === null) { |
|
59 | + $sessionId = WebRequest::getSessionUserId(); |
|
60 | + |
|
61 | + if ($sessionId !== null) { |
|
62 | + /** @var User $user */ |
|
63 | + $user = self::getById($sessionId, $database); |
|
64 | + |
|
65 | + if ($user === false) { |
|
66 | + self::$currentUser = new CommunityUser(); |
|
67 | + } |
|
68 | + else { |
|
69 | + self::$currentUser = $user; |
|
70 | + } |
|
71 | + } |
|
72 | + else { |
|
73 | + $anonymousCoward = new CommunityUser(); |
|
74 | + |
|
75 | + self::$currentUser = $anonymousCoward; |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + return self::$currentUser; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Gets a user by their user ID |
|
84 | + * |
|
85 | + * Pass -1 to get the community user. |
|
86 | + * |
|
87 | + * @param int|null $id |
|
88 | + * @param PdoDatabase $database |
|
89 | + * |
|
90 | + * @return User|false |
|
91 | + */ |
|
92 | + public static function getById($id, PdoDatabase $database) |
|
93 | + { |
|
94 | + if ($id === null || $id == -1) { |
|
95 | + return new CommunityUser(); |
|
96 | + } |
|
97 | + |
|
98 | + /** @var User|false $user */ |
|
99 | + $user = parent::getById($id, $database); |
|
100 | + |
|
101 | + return $user; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @return CommunityUser |
|
106 | + */ |
|
107 | + public static function getCommunity() |
|
108 | + { |
|
109 | + return new CommunityUser(); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Gets a user by their username |
|
114 | + * |
|
115 | + * @param string $username |
|
116 | + * @param PdoDatabase $database |
|
117 | + * |
|
118 | + * @return CommunityUser|User|false |
|
119 | + */ |
|
120 | + public static function getByUsername($username, PdoDatabase $database) |
|
121 | + { |
|
122 | + global $communityUsername; |
|
123 | + if ($username == $communityUsername) { |
|
124 | + return new CommunityUser(); |
|
125 | + } |
|
126 | + |
|
127 | + $statement = $database->prepare("SELECT * FROM user WHERE username = :id LIMIT 1;"); |
|
128 | + $statement->bindValue(":id", $username); |
|
129 | + |
|
130 | + $statement->execute(); |
|
131 | + |
|
132 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
133 | + |
|
134 | + if ($resultObject != false) { |
|
135 | + $resultObject->setDatabase($database); |
|
136 | + } |
|
137 | + |
|
138 | + return $resultObject; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Gets a user by their on-wiki username. |
|
143 | + * |
|
144 | + * @param string $username |
|
145 | + * @param PdoDatabase $database |
|
146 | + * |
|
147 | + * @return User|false |
|
148 | + */ |
|
149 | + public static function getByOnWikiUsername($username, PdoDatabase $database) |
|
150 | + { |
|
151 | + $statement = $database->prepare("SELECT * FROM user WHERE onwikiname = :id LIMIT 1;"); |
|
152 | + $statement->bindValue(":id", $username); |
|
153 | + $statement->execute(); |
|
154 | + |
|
155 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
156 | + |
|
157 | + if ($resultObject != false) { |
|
158 | + $resultObject->setDatabase($database); |
|
159 | + |
|
160 | + return $resultObject; |
|
161 | + } |
|
162 | + |
|
163 | + return false; |
|
164 | + } |
|
165 | + |
|
166 | + #endregion |
|
167 | + |
|
168 | + /** |
|
169 | + * Saves the current object |
|
170 | + * |
|
171 | + * @throws Exception |
|
172 | + */ |
|
173 | + public function save() |
|
174 | + { |
|
175 | + if ($this->isNew()) { |
|
176 | + // insert |
|
177 | + $statement = $this->dbObject->prepare(<<<SQL |
|
178 | 178 | INSERT INTO `user` ( |
179 | 179 | username, email, status, onwikiname, welcome_sig, |
180 | 180 | lastactive, forcelogout, forceidentified, |
@@ -185,32 +185,32 @@ discard block |
||
185 | 185 | :welcome_template, :abortpref, :confirmationdiff, :emailsig, :creationmode, :skin |
186 | 186 | ); |
187 | 187 | SQL |
188 | - ); |
|
189 | - $statement->bindValue(":username", $this->username); |
|
190 | - $statement->bindValue(":email", $this->email); |
|
191 | - $statement->bindValue(":status", $this->status); |
|
192 | - $statement->bindValue(":onwikiname", $this->onwikiname); |
|
193 | - $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
194 | - $statement->bindValue(":lastactive", $this->lastactive); |
|
195 | - $statement->bindValue(":forcelogout", $this->forcelogout); |
|
196 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
197 | - $statement->bindValue(":welcome_template", $this->welcome_template); |
|
198 | - $statement->bindValue(":abortpref", $this->abortpref); |
|
199 | - $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
200 | - $statement->bindValue(":emailsig", $this->emailsig); |
|
201 | - $statement->bindValue(":creationmode", $this->creationmode); |
|
202 | - $statement->bindValue(":skin", $this->skin); |
|
203 | - |
|
204 | - if ($statement->execute()) { |
|
205 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
206 | - } |
|
207 | - else { |
|
208 | - throw new Exception($statement->errorInfo()); |
|
209 | - } |
|
210 | - } |
|
211 | - else { |
|
212 | - // update |
|
213 | - $statement = $this->dbObject->prepare(<<<SQL |
|
188 | + ); |
|
189 | + $statement->bindValue(":username", $this->username); |
|
190 | + $statement->bindValue(":email", $this->email); |
|
191 | + $statement->bindValue(":status", $this->status); |
|
192 | + $statement->bindValue(":onwikiname", $this->onwikiname); |
|
193 | + $statement->bindValue(":welcome_sig", $this->welcome_sig); |
|
194 | + $statement->bindValue(":lastactive", $this->lastactive); |
|
195 | + $statement->bindValue(":forcelogout", $this->forcelogout); |
|
196 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
197 | + $statement->bindValue(":welcome_template", $this->welcome_template); |
|
198 | + $statement->bindValue(":abortpref", $this->abortpref); |
|
199 | + $statement->bindValue(":confirmationdiff", $this->confirmationdiff); |
|
200 | + $statement->bindValue(":emailsig", $this->emailsig); |
|
201 | + $statement->bindValue(":creationmode", $this->creationmode); |
|
202 | + $statement->bindValue(":skin", $this->skin); |
|
203 | + |
|
204 | + if ($statement->execute()) { |
|
205 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
206 | + } |
|
207 | + else { |
|
208 | + throw new Exception($statement->errorInfo()); |
|
209 | + } |
|
210 | + } |
|
211 | + else { |
|
212 | + // update |
|
213 | + $statement = $this->dbObject->prepare(<<<SQL |
|
214 | 214 | UPDATE `user` SET |
215 | 215 | username = :username, email = :email, |
216 | 216 | status = :status, |
@@ -223,387 +223,387 @@ discard block |
||
223 | 223 | updateversion = updateversion + 1 |
224 | 224 | WHERE id = :id AND updateversion = :updateversion; |
225 | 225 | SQL |
226 | - ); |
|
227 | - $statement->bindValue(":forceidentified", $this->forceidentified); |
|
228 | - |
|
229 | - $statement->bindValue(':id', $this->id); |
|
230 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
231 | - |
|
232 | - $statement->bindValue(':username', $this->username); |
|
233 | - $statement->bindValue(':email', $this->email); |
|
234 | - $statement->bindValue(':status', $this->status); |
|
235 | - $statement->bindValue(':onwikiname', $this->onwikiname); |
|
236 | - $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
237 | - $statement->bindValue(':lastactive', $this->lastactive); |
|
238 | - $statement->bindValue(':forcelogout', $this->forcelogout); |
|
239 | - $statement->bindValue(':forceidentified', $this->forceidentified); |
|
240 | - $statement->bindValue(':welcome_template', $this->welcome_template); |
|
241 | - $statement->bindValue(':abortpref', $this->abortpref); |
|
242 | - $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
243 | - $statement->bindValue(':emailsig', $this->emailsig); |
|
244 | - $statement->bindValue(':creationmode', $this->creationmode); |
|
245 | - $statement->bindValue(':skin', $this->skin); |
|
246 | - |
|
247 | - if (!$statement->execute()) { |
|
248 | - throw new Exception($statement->errorInfo()); |
|
249 | - } |
|
250 | - |
|
251 | - if ($statement->rowCount() !== 1) { |
|
252 | - throw new OptimisticLockFailedException(); |
|
253 | - } |
|
254 | - |
|
255 | - $this->updateversion++; |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - #region properties |
|
260 | - |
|
261 | - /** |
|
262 | - * Gets the tool username |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function getUsername() |
|
266 | - { |
|
267 | - return $this->username; |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Sets the tool username |
|
272 | - * |
|
273 | - * @param string $username |
|
274 | - */ |
|
275 | - public function setUsername($username) |
|
276 | - { |
|
277 | - $this->username = $username; |
|
278 | - |
|
279 | - // If this isn't a brand new user, then it's a rename, force the logout |
|
280 | - if (!$this->isNew()) { |
|
281 | - $this->forcelogout = 1; |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Gets the user's email address |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function getEmail() |
|
290 | - { |
|
291 | - return $this->email; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Sets the user's email address |
|
296 | - * |
|
297 | - * @param string $email |
|
298 | - */ |
|
299 | - public function setEmail($email) |
|
300 | - { |
|
301 | - $this->email = $email; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function getStatus() |
|
309 | - { |
|
310 | - return $this->status; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * @param string $status |
|
315 | - */ |
|
316 | - public function setStatus($status) |
|
317 | - { |
|
318 | - $this->status = $status; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Gets the user's on-wiki name |
|
323 | - * @return string |
|
324 | - */ |
|
325 | - public function getOnWikiName() |
|
326 | - { |
|
327 | - return $this->onwikiname; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Sets the user's on-wiki name |
|
332 | - * |
|
333 | - * This can have interesting side-effects with OAuth. |
|
334 | - * |
|
335 | - * @param string $onWikiName |
|
336 | - */ |
|
337 | - public function setOnWikiName($onWikiName) |
|
338 | - { |
|
339 | - $this->onwikiname = $onWikiName; |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Gets the welcome signature |
|
344 | - * @return string |
|
345 | - */ |
|
346 | - public function getWelcomeSig() |
|
347 | - { |
|
348 | - return $this->welcome_sig; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * Sets the welcome signature |
|
353 | - * |
|
354 | - * @param string $welcomeSig |
|
355 | - */ |
|
356 | - public function setWelcomeSig($welcomeSig) |
|
357 | - { |
|
358 | - $this->welcome_sig = $welcomeSig; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Gets the last activity date for the user |
|
363 | - * |
|
364 | - * @return string |
|
365 | - * @todo This should probably return an instance of DateTime |
|
366 | - */ |
|
367 | - public function getLastActive() |
|
368 | - { |
|
369 | - return $this->lastactive; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Gets the user's forced logout status |
|
374 | - * |
|
375 | - * @return bool |
|
376 | - */ |
|
377 | - public function getForceLogout() |
|
378 | - { |
|
379 | - return $this->forcelogout == 1; |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * Sets the user's forced logout status |
|
384 | - * |
|
385 | - * @param bool $forceLogout |
|
386 | - */ |
|
387 | - public function setForceLogout($forceLogout) |
|
388 | - { |
|
389 | - $this->forcelogout = $forceLogout ? 1 : 0; |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns the ID of the welcome template used. |
|
394 | - * @return int |
|
395 | - */ |
|
396 | - public function getWelcomeTemplate() |
|
397 | - { |
|
398 | - return $this->welcome_template; |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Sets the ID of the welcome template used. |
|
403 | - * |
|
404 | - * @param int $welcomeTemplate |
|
405 | - */ |
|
406 | - public function setWelcomeTemplate($welcomeTemplate) |
|
407 | - { |
|
408 | - $this->welcome_template = $welcomeTemplate; |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Gets the user's abort preference |
|
413 | - * @todo this is badly named too! Also a bool that's actually an int. |
|
414 | - * @return int |
|
415 | - */ |
|
416 | - public function getAbortPref() |
|
417 | - { |
|
418 | - return $this->abortpref; |
|
419 | - } |
|
420 | - |
|
421 | - /** |
|
422 | - * Sets the user's abort preference |
|
423 | - * @todo rename, retype, and re-comment. |
|
424 | - * |
|
425 | - * @param int $abortPreference |
|
426 | - */ |
|
427 | - public function setAbortPref($abortPreference) |
|
428 | - { |
|
429 | - $this->abortpref = $abortPreference; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
434 | - * @return int the diff ID |
|
435 | - */ |
|
436 | - public function getConfirmationDiff() |
|
437 | - { |
|
438 | - return $this->confirmationdiff; |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Sets the user's confirmation diff. |
|
443 | - * |
|
444 | - * @param int $confirmationDiff |
|
445 | - */ |
|
446 | - public function setConfirmationDiff($confirmationDiff) |
|
447 | - { |
|
448 | - $this->confirmationdiff = $confirmationDiff; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Gets the users' email signature used on outbound mail. |
|
453 | - * @todo rename me! |
|
454 | - * @return string |
|
455 | - */ |
|
456 | - public function getEmailSig() |
|
457 | - { |
|
458 | - return $this->emailsig; |
|
459 | - } |
|
460 | - |
|
461 | - /** |
|
462 | - * Sets the user's email signature for outbound mail. |
|
463 | - * |
|
464 | - * @param string $emailSignature |
|
465 | - */ |
|
466 | - public function setEmailSig($emailSignature) |
|
467 | - { |
|
468 | - $this->emailsig = $emailSignature; |
|
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * @return int |
|
473 | - */ |
|
474 | - public function getCreationMode() |
|
475 | - { |
|
476 | - return $this->creationmode; |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * @param $creationMode int |
|
481 | - */ |
|
482 | - public function setCreationMode($creationMode) |
|
483 | - { |
|
484 | - $this->creationmode = $creationMode; |
|
485 | - } |
|
486 | - |
|
487 | - /** |
|
488 | - * @return boolean |
|
489 | - */ |
|
490 | - public function getUseAlternateSkin() |
|
491 | - { |
|
492 | - return $this->skin === 'alt'; |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - public function getSkin() |
|
499 | - { |
|
500 | - return $this->skin; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * @param $skin string |
|
505 | - */ |
|
506 | - public function setSkin($skin) |
|
507 | - { |
|
508 | - $this->skin = $skin; |
|
509 | - } |
|
510 | - |
|
511 | - #endregion |
|
512 | - |
|
513 | - #region user access checks |
|
514 | - |
|
515 | - public function isActive() |
|
516 | - { |
|
517 | - return $this->status == self::STATUS_ACTIVE; |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Tests if the user is identified |
|
522 | - * |
|
523 | - * @param IdentificationVerifier $iv |
|
524 | - * |
|
525 | - * @return bool |
|
526 | - * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
527 | - * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
528 | - * to play it safe for now. |
|
529 | - * @category Security-Critical |
|
530 | - */ |
|
531 | - public function isIdentified(IdentificationVerifier $iv) |
|
532 | - { |
|
533 | - if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
534 | - // User forced to unidentified in the database. |
|
535 | - return false; |
|
536 | - } |
|
537 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
538 | - // User forced to identified in the database. |
|
539 | - return true; |
|
540 | - } |
|
541 | - else { |
|
542 | - // User not forced to any particular identified status; consult IdentificationVerifier |
|
543 | - return $iv->isUserIdentified($this->getOnWikiName()); |
|
544 | - } |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * DO NOT USE FOR TESTING IDENTIFICATION STATUS. |
|
549 | - * |
|
550 | - * @return bool|null |
|
551 | - */ |
|
552 | - public function getForceIdentified() { |
|
553 | - return $this->forceidentified; |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Tests if the user is suspended |
|
558 | - * @return bool |
|
559 | - * @category Security-Critical |
|
560 | - */ |
|
561 | - public function isSuspended() |
|
562 | - { |
|
563 | - return $this->status == self::STATUS_SUSPENDED; |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Tests if the user is new |
|
568 | - * @return bool |
|
569 | - * @category Security-Critical |
|
570 | - */ |
|
571 | - public function isNewUser() |
|
572 | - { |
|
573 | - return $this->status == self::STATUS_NEW; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Tests if the user has been declined access to the tool |
|
578 | - * @return bool |
|
579 | - * @category Security-Critical |
|
580 | - */ |
|
581 | - public function isDeclined() |
|
582 | - { |
|
583 | - return $this->status == self::STATUS_DECLINED; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * Tests if the user is the community user |
|
588 | - * |
|
589 | - * @todo decide if this means logged out. I think it usually does. |
|
590 | - * @return bool |
|
591 | - * @category Security-Critical |
|
592 | - */ |
|
593 | - public function isCommunityUser() |
|
594 | - { |
|
595 | - return false; |
|
596 | - } |
|
597 | - |
|
598 | - #endregion |
|
599 | - |
|
600 | - /** |
|
601 | - * Gets the approval date of the user |
|
602 | - * @return DateTime|false |
|
603 | - */ |
|
604 | - public function getApprovalDate() |
|
605 | - { |
|
606 | - $query = $this->dbObject->prepare(<<<SQL |
|
226 | + ); |
|
227 | + $statement->bindValue(":forceidentified", $this->forceidentified); |
|
228 | + |
|
229 | + $statement->bindValue(':id', $this->id); |
|
230 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
231 | + |
|
232 | + $statement->bindValue(':username', $this->username); |
|
233 | + $statement->bindValue(':email', $this->email); |
|
234 | + $statement->bindValue(':status', $this->status); |
|
235 | + $statement->bindValue(':onwikiname', $this->onwikiname); |
|
236 | + $statement->bindValue(':welcome_sig', $this->welcome_sig); |
|
237 | + $statement->bindValue(':lastactive', $this->lastactive); |
|
238 | + $statement->bindValue(':forcelogout', $this->forcelogout); |
|
239 | + $statement->bindValue(':forceidentified', $this->forceidentified); |
|
240 | + $statement->bindValue(':welcome_template', $this->welcome_template); |
|
241 | + $statement->bindValue(':abortpref', $this->abortpref); |
|
242 | + $statement->bindValue(':confirmationdiff', $this->confirmationdiff); |
|
243 | + $statement->bindValue(':emailsig', $this->emailsig); |
|
244 | + $statement->bindValue(':creationmode', $this->creationmode); |
|
245 | + $statement->bindValue(':skin', $this->skin); |
|
246 | + |
|
247 | + if (!$statement->execute()) { |
|
248 | + throw new Exception($statement->errorInfo()); |
|
249 | + } |
|
250 | + |
|
251 | + if ($statement->rowCount() !== 1) { |
|
252 | + throw new OptimisticLockFailedException(); |
|
253 | + } |
|
254 | + |
|
255 | + $this->updateversion++; |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + #region properties |
|
260 | + |
|
261 | + /** |
|
262 | + * Gets the tool username |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function getUsername() |
|
266 | + { |
|
267 | + return $this->username; |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Sets the tool username |
|
272 | + * |
|
273 | + * @param string $username |
|
274 | + */ |
|
275 | + public function setUsername($username) |
|
276 | + { |
|
277 | + $this->username = $username; |
|
278 | + |
|
279 | + // If this isn't a brand new user, then it's a rename, force the logout |
|
280 | + if (!$this->isNew()) { |
|
281 | + $this->forcelogout = 1; |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Gets the user's email address |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function getEmail() |
|
290 | + { |
|
291 | + return $this->email; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Sets the user's email address |
|
296 | + * |
|
297 | + * @param string $email |
|
298 | + */ |
|
299 | + public function setEmail($email) |
|
300 | + { |
|
301 | + $this->email = $email; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Gets the status (User, Admin, Suspended, etc - excludes checkuser) of the user. |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function getStatus() |
|
309 | + { |
|
310 | + return $this->status; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * @param string $status |
|
315 | + */ |
|
316 | + public function setStatus($status) |
|
317 | + { |
|
318 | + $this->status = $status; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Gets the user's on-wiki name |
|
323 | + * @return string |
|
324 | + */ |
|
325 | + public function getOnWikiName() |
|
326 | + { |
|
327 | + return $this->onwikiname; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Sets the user's on-wiki name |
|
332 | + * |
|
333 | + * This can have interesting side-effects with OAuth. |
|
334 | + * |
|
335 | + * @param string $onWikiName |
|
336 | + */ |
|
337 | + public function setOnWikiName($onWikiName) |
|
338 | + { |
|
339 | + $this->onwikiname = $onWikiName; |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Gets the welcome signature |
|
344 | + * @return string |
|
345 | + */ |
|
346 | + public function getWelcomeSig() |
|
347 | + { |
|
348 | + return $this->welcome_sig; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * Sets the welcome signature |
|
353 | + * |
|
354 | + * @param string $welcomeSig |
|
355 | + */ |
|
356 | + public function setWelcomeSig($welcomeSig) |
|
357 | + { |
|
358 | + $this->welcome_sig = $welcomeSig; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Gets the last activity date for the user |
|
363 | + * |
|
364 | + * @return string |
|
365 | + * @todo This should probably return an instance of DateTime |
|
366 | + */ |
|
367 | + public function getLastActive() |
|
368 | + { |
|
369 | + return $this->lastactive; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Gets the user's forced logout status |
|
374 | + * |
|
375 | + * @return bool |
|
376 | + */ |
|
377 | + public function getForceLogout() |
|
378 | + { |
|
379 | + return $this->forcelogout == 1; |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * Sets the user's forced logout status |
|
384 | + * |
|
385 | + * @param bool $forceLogout |
|
386 | + */ |
|
387 | + public function setForceLogout($forceLogout) |
|
388 | + { |
|
389 | + $this->forcelogout = $forceLogout ? 1 : 0; |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns the ID of the welcome template used. |
|
394 | + * @return int |
|
395 | + */ |
|
396 | + public function getWelcomeTemplate() |
|
397 | + { |
|
398 | + return $this->welcome_template; |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Sets the ID of the welcome template used. |
|
403 | + * |
|
404 | + * @param int $welcomeTemplate |
|
405 | + */ |
|
406 | + public function setWelcomeTemplate($welcomeTemplate) |
|
407 | + { |
|
408 | + $this->welcome_template = $welcomeTemplate; |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Gets the user's abort preference |
|
413 | + * @todo this is badly named too! Also a bool that's actually an int. |
|
414 | + * @return int |
|
415 | + */ |
|
416 | + public function getAbortPref() |
|
417 | + { |
|
418 | + return $this->abortpref; |
|
419 | + } |
|
420 | + |
|
421 | + /** |
|
422 | + * Sets the user's abort preference |
|
423 | + * @todo rename, retype, and re-comment. |
|
424 | + * |
|
425 | + * @param int $abortPreference |
|
426 | + */ |
|
427 | + public function setAbortPref($abortPreference) |
|
428 | + { |
|
429 | + $this->abortpref = $abortPreference; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Gets the user's confirmation diff. Unused if OAuth is in use. |
|
434 | + * @return int the diff ID |
|
435 | + */ |
|
436 | + public function getConfirmationDiff() |
|
437 | + { |
|
438 | + return $this->confirmationdiff; |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Sets the user's confirmation diff. |
|
443 | + * |
|
444 | + * @param int $confirmationDiff |
|
445 | + */ |
|
446 | + public function setConfirmationDiff($confirmationDiff) |
|
447 | + { |
|
448 | + $this->confirmationdiff = $confirmationDiff; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Gets the users' email signature used on outbound mail. |
|
453 | + * @todo rename me! |
|
454 | + * @return string |
|
455 | + */ |
|
456 | + public function getEmailSig() |
|
457 | + { |
|
458 | + return $this->emailsig; |
|
459 | + } |
|
460 | + |
|
461 | + /** |
|
462 | + * Sets the user's email signature for outbound mail. |
|
463 | + * |
|
464 | + * @param string $emailSignature |
|
465 | + */ |
|
466 | + public function setEmailSig($emailSignature) |
|
467 | + { |
|
468 | + $this->emailsig = $emailSignature; |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * @return int |
|
473 | + */ |
|
474 | + public function getCreationMode() |
|
475 | + { |
|
476 | + return $this->creationmode; |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * @param $creationMode int |
|
481 | + */ |
|
482 | + public function setCreationMode($creationMode) |
|
483 | + { |
|
484 | + $this->creationmode = $creationMode; |
|
485 | + } |
|
486 | + |
|
487 | + /** |
|
488 | + * @return boolean |
|
489 | + */ |
|
490 | + public function getUseAlternateSkin() |
|
491 | + { |
|
492 | + return $this->skin === 'alt'; |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + public function getSkin() |
|
499 | + { |
|
500 | + return $this->skin; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * @param $skin string |
|
505 | + */ |
|
506 | + public function setSkin($skin) |
|
507 | + { |
|
508 | + $this->skin = $skin; |
|
509 | + } |
|
510 | + |
|
511 | + #endregion |
|
512 | + |
|
513 | + #region user access checks |
|
514 | + |
|
515 | + public function isActive() |
|
516 | + { |
|
517 | + return $this->status == self::STATUS_ACTIVE; |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Tests if the user is identified |
|
522 | + * |
|
523 | + * @param IdentificationVerifier $iv |
|
524 | + * |
|
525 | + * @return bool |
|
526 | + * @todo Figure out what on earth is going on with PDO's typecasting here. Apparently, it returns string("0") for |
|
527 | + * the force-unidentified case, and int(1) for the identified case?! This is quite ugly, but probably needed |
|
528 | + * to play it safe for now. |
|
529 | + * @category Security-Critical |
|
530 | + */ |
|
531 | + public function isIdentified(IdentificationVerifier $iv) |
|
532 | + { |
|
533 | + if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
|
534 | + // User forced to unidentified in the database. |
|
535 | + return false; |
|
536 | + } |
|
537 | + elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
538 | + // User forced to identified in the database. |
|
539 | + return true; |
|
540 | + } |
|
541 | + else { |
|
542 | + // User not forced to any particular identified status; consult IdentificationVerifier |
|
543 | + return $iv->isUserIdentified($this->getOnWikiName()); |
|
544 | + } |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * DO NOT USE FOR TESTING IDENTIFICATION STATUS. |
|
549 | + * |
|
550 | + * @return bool|null |
|
551 | + */ |
|
552 | + public function getForceIdentified() { |
|
553 | + return $this->forceidentified; |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * Tests if the user is suspended |
|
558 | + * @return bool |
|
559 | + * @category Security-Critical |
|
560 | + */ |
|
561 | + public function isSuspended() |
|
562 | + { |
|
563 | + return $this->status == self::STATUS_SUSPENDED; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Tests if the user is new |
|
568 | + * @return bool |
|
569 | + * @category Security-Critical |
|
570 | + */ |
|
571 | + public function isNewUser() |
|
572 | + { |
|
573 | + return $this->status == self::STATUS_NEW; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Tests if the user has been declined access to the tool |
|
578 | + * @return bool |
|
579 | + * @category Security-Critical |
|
580 | + */ |
|
581 | + public function isDeclined() |
|
582 | + { |
|
583 | + return $this->status == self::STATUS_DECLINED; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * Tests if the user is the community user |
|
588 | + * |
|
589 | + * @todo decide if this means logged out. I think it usually does. |
|
590 | + * @return bool |
|
591 | + * @category Security-Critical |
|
592 | + */ |
|
593 | + public function isCommunityUser() |
|
594 | + { |
|
595 | + return false; |
|
596 | + } |
|
597 | + |
|
598 | + #endregion |
|
599 | + |
|
600 | + /** |
|
601 | + * Gets the approval date of the user |
|
602 | + * @return DateTime|false |
|
603 | + */ |
|
604 | + public function getApprovalDate() |
|
605 | + { |
|
606 | + $query = $this->dbObject->prepare(<<<SQL |
|
607 | 607 | SELECT timestamp |
608 | 608 | FROM log |
609 | 609 | WHERE objectid = :userid |
@@ -612,12 +612,12 @@ discard block |
||
612 | 612 | ORDER BY id DESC |
613 | 613 | LIMIT 1; |
614 | 614 | SQL |
615 | - ); |
|
616 | - $query->execute(array(":userid" => $this->id)); |
|
615 | + ); |
|
616 | + $query->execute(array(":userid" => $this->id)); |
|
617 | 617 | |
618 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
619 | - $query->closeCursor(); |
|
618 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", $query->fetchColumn()); |
|
619 | + $query->closeCursor(); |
|
620 | 620 | |
621 | - return $data; |
|
622 | - } |
|
621 | + return $data; |
|
622 | + } |
|
623 | 623 | } |
@@ -64,12 +64,10 @@ discard block |
||
64 | 64 | |
65 | 65 | if ($user === false) { |
66 | 66 | self::$currentUser = new CommunityUser(); |
67 | - } |
|
68 | - else { |
|
67 | + } else { |
|
69 | 68 | self::$currentUser = $user; |
70 | 69 | } |
71 | - } |
|
72 | - else { |
|
70 | + } else { |
|
73 | 71 | $anonymousCoward = new CommunityUser(); |
74 | 72 | |
75 | 73 | self::$currentUser = $anonymousCoward; |
@@ -203,12 +201,10 @@ discard block |
||
203 | 201 | |
204 | 202 | if ($statement->execute()) { |
205 | 203 | $this->id = (int)$this->dbObject->lastInsertId(); |
206 | - } |
|
207 | - else { |
|
204 | + } else { |
|
208 | 205 | throw new Exception($statement->errorInfo()); |
209 | 206 | } |
210 | - } |
|
211 | - else { |
|
207 | + } else { |
|
212 | 208 | // update |
213 | 209 | $statement = $this->dbObject->prepare(<<<SQL |
214 | 210 | UPDATE `user` SET |
@@ -533,12 +529,10 @@ discard block |
||
533 | 529 | if ($this->forceidentified === 0 || $this->forceidentified === "0") { |
534 | 530 | // User forced to unidentified in the database. |
535 | 531 | return false; |
536 | - } |
|
537 | - elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
532 | + } elseif ($this->forceidentified === 1 || $this->forceidentified === "1") { |
|
538 | 533 | // User forced to identified in the database. |
539 | 534 | return true; |
540 | - } |
|
541 | - else { |
|
535 | + } else { |
|
542 | 536 | // User not forced to any particular identified status; consult IdentificationVerifier |
543 | 537 | return $iv->isUserIdentified($this->getOnWikiName()); |
544 | 538 | } |
@@ -549,7 +543,8 @@ discard block |
||
549 | 543 | * |
550 | 544 | * @return bool|null |
551 | 545 | */ |
552 | - public function getForceIdentified() { |
|
546 | + public function getForceIdentified() |
|
547 | + { |
|
553 | 548 | return $this->forceidentified; |
554 | 549 | } |
555 | 550 |
@@ -16,167 +16,167 @@ |
||
16 | 16 | */ |
17 | 17 | class CommunityUser extends User |
18 | 18 | { |
19 | - public function getId() |
|
20 | - { |
|
21 | - return -1; |
|
22 | - } |
|
23 | - |
|
24 | - public function save() |
|
25 | - { |
|
26 | - // Do nothing |
|
27 | - } |
|
28 | - |
|
29 | - #region properties |
|
30 | - |
|
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function getUsername() |
|
35 | - { |
|
36 | - global $communityUsername; |
|
37 | - |
|
38 | - return $communityUsername; |
|
39 | - } |
|
40 | - |
|
41 | - public function setUsername($username) |
|
42 | - { |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string |
|
47 | - */ |
|
48 | - public function getEmail() |
|
49 | - { |
|
50 | - global $cDataClearEmail; |
|
51 | - |
|
52 | - return $cDataClearEmail; |
|
53 | - } |
|
54 | - |
|
55 | - public function setEmail($email) |
|
56 | - { |
|
57 | - } |
|
58 | - |
|
59 | - public function getStatus() |
|
60 | - { |
|
61 | - return "Community"; |
|
62 | - } |
|
63 | - |
|
64 | - public function getOnWikiName() |
|
65 | - { |
|
66 | - return "127.0.0.1"; |
|
67 | - } |
|
68 | - |
|
69 | - public function setOnWikiName($onWikiName) |
|
70 | - { |
|
71 | - } |
|
72 | - |
|
73 | - public function getWelcomeSig() |
|
74 | - { |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - public function setWelcomeSig($welcomeSig) |
|
79 | - { |
|
80 | - } |
|
81 | - |
|
82 | - public function getLastActive() |
|
83 | - { |
|
84 | - $now = new DateTime(); |
|
85 | - |
|
86 | - return $now->format("Y-m-d H:i:s"); |
|
87 | - } |
|
88 | - |
|
89 | - public function getForceLogout() |
|
90 | - { |
|
91 | - return true; |
|
92 | - } |
|
93 | - |
|
94 | - public function setForceLogout($forceLogout) |
|
95 | - { |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $status |
|
100 | - */ |
|
101 | - public function setStatus($status) |
|
102 | - { |
|
103 | - } |
|
104 | - |
|
105 | - public function getWelcomeTemplate() |
|
106 | - { |
|
107 | - return 0; |
|
108 | - } |
|
109 | - |
|
110 | - public function setWelcomeTemplate($welcomeTemplate) |
|
111 | - { |
|
112 | - } |
|
113 | - |
|
114 | - public function getAbortPref() |
|
115 | - { |
|
116 | - return 0; |
|
117 | - } |
|
118 | - |
|
119 | - public function setAbortPref($abortPreference) |
|
120 | - { |
|
121 | - } |
|
122 | - |
|
123 | - public function getConfirmationDiff() |
|
124 | - { |
|
125 | - return null; |
|
126 | - } |
|
127 | - |
|
128 | - public function setConfirmationDiff($confirmationDiff) |
|
129 | - { |
|
130 | - } |
|
131 | - |
|
132 | - public function getEmailSig() |
|
133 | - { |
|
134 | - return null; |
|
135 | - } |
|
136 | - |
|
137 | - public function setEmailSig($emailSignature) |
|
138 | - { |
|
139 | - } |
|
140 | - |
|
141 | - public function setUseAlternateSkin($useAlternate) |
|
142 | - { |
|
143 | - } |
|
144 | - |
|
145 | - #endregion |
|
146 | - |
|
147 | - #region user access checks |
|
148 | - |
|
149 | - public function isIdentified(IdentificationVerifier $iv) |
|
150 | - { |
|
151 | - return false; |
|
152 | - } |
|
153 | - |
|
154 | - public function isSuspended() |
|
155 | - { |
|
156 | - return false; |
|
157 | - } |
|
158 | - |
|
159 | - public function isNewUser() |
|
160 | - { |
|
161 | - return false; |
|
162 | - } |
|
163 | - |
|
164 | - public function isDeclined() |
|
165 | - { |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - public function isCommunityUser() |
|
170 | - { |
|
171 | - return true; |
|
172 | - } |
|
173 | - |
|
174 | - #endregion |
|
175 | - |
|
176 | - public function getApprovalDate() |
|
177 | - { |
|
178 | - $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00"); |
|
179 | - |
|
180 | - return $data; |
|
181 | - } |
|
19 | + public function getId() |
|
20 | + { |
|
21 | + return -1; |
|
22 | + } |
|
23 | + |
|
24 | + public function save() |
|
25 | + { |
|
26 | + // Do nothing |
|
27 | + } |
|
28 | + |
|
29 | + #region properties |
|
30 | + |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function getUsername() |
|
35 | + { |
|
36 | + global $communityUsername; |
|
37 | + |
|
38 | + return $communityUsername; |
|
39 | + } |
|
40 | + |
|
41 | + public function setUsername($username) |
|
42 | + { |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string |
|
47 | + */ |
|
48 | + public function getEmail() |
|
49 | + { |
|
50 | + global $cDataClearEmail; |
|
51 | + |
|
52 | + return $cDataClearEmail; |
|
53 | + } |
|
54 | + |
|
55 | + public function setEmail($email) |
|
56 | + { |
|
57 | + } |
|
58 | + |
|
59 | + public function getStatus() |
|
60 | + { |
|
61 | + return "Community"; |
|
62 | + } |
|
63 | + |
|
64 | + public function getOnWikiName() |
|
65 | + { |
|
66 | + return "127.0.0.1"; |
|
67 | + } |
|
68 | + |
|
69 | + public function setOnWikiName($onWikiName) |
|
70 | + { |
|
71 | + } |
|
72 | + |
|
73 | + public function getWelcomeSig() |
|
74 | + { |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + public function setWelcomeSig($welcomeSig) |
|
79 | + { |
|
80 | + } |
|
81 | + |
|
82 | + public function getLastActive() |
|
83 | + { |
|
84 | + $now = new DateTime(); |
|
85 | + |
|
86 | + return $now->format("Y-m-d H:i:s"); |
|
87 | + } |
|
88 | + |
|
89 | + public function getForceLogout() |
|
90 | + { |
|
91 | + return true; |
|
92 | + } |
|
93 | + |
|
94 | + public function setForceLogout($forceLogout) |
|
95 | + { |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $status |
|
100 | + */ |
|
101 | + public function setStatus($status) |
|
102 | + { |
|
103 | + } |
|
104 | + |
|
105 | + public function getWelcomeTemplate() |
|
106 | + { |
|
107 | + return 0; |
|
108 | + } |
|
109 | + |
|
110 | + public function setWelcomeTemplate($welcomeTemplate) |
|
111 | + { |
|
112 | + } |
|
113 | + |
|
114 | + public function getAbortPref() |
|
115 | + { |
|
116 | + return 0; |
|
117 | + } |
|
118 | + |
|
119 | + public function setAbortPref($abortPreference) |
|
120 | + { |
|
121 | + } |
|
122 | + |
|
123 | + public function getConfirmationDiff() |
|
124 | + { |
|
125 | + return null; |
|
126 | + } |
|
127 | + |
|
128 | + public function setConfirmationDiff($confirmationDiff) |
|
129 | + { |
|
130 | + } |
|
131 | + |
|
132 | + public function getEmailSig() |
|
133 | + { |
|
134 | + return null; |
|
135 | + } |
|
136 | + |
|
137 | + public function setEmailSig($emailSignature) |
|
138 | + { |
|
139 | + } |
|
140 | + |
|
141 | + public function setUseAlternateSkin($useAlternate) |
|
142 | + { |
|
143 | + } |
|
144 | + |
|
145 | + #endregion |
|
146 | + |
|
147 | + #region user access checks |
|
148 | + |
|
149 | + public function isIdentified(IdentificationVerifier $iv) |
|
150 | + { |
|
151 | + return false; |
|
152 | + } |
|
153 | + |
|
154 | + public function isSuspended() |
|
155 | + { |
|
156 | + return false; |
|
157 | + } |
|
158 | + |
|
159 | + public function isNewUser() |
|
160 | + { |
|
161 | + return false; |
|
162 | + } |
|
163 | + |
|
164 | + public function isDeclined() |
|
165 | + { |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + public function isCommunityUser() |
|
170 | + { |
|
171 | + return true; |
|
172 | + } |
|
173 | + |
|
174 | + #endregion |
|
175 | + |
|
176 | + public function getApprovalDate() |
|
177 | + { |
|
178 | + $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00"); |
|
179 | + |
|
180 | + return $data; |
|
181 | + } |
|
182 | 182 | } |
@@ -19,274 +19,274 @@ |
||
19 | 19 | */ |
20 | 20 | class Ban extends DataObject |
21 | 21 | { |
22 | - private $type; |
|
23 | - private $target; |
|
24 | - private $user; |
|
25 | - private $reason; |
|
26 | - private $date; |
|
27 | - private $duration; |
|
28 | - private $active; |
|
29 | - |
|
30 | - /** |
|
31 | - * Gets all active bans, filtered by the optional target. |
|
32 | - * |
|
33 | - * @param string|null $target |
|
34 | - * @param PdoDatabase $database |
|
35 | - * |
|
36 | - * @return Ban[] |
|
37 | - */ |
|
38 | - public static function getActiveBans($target, PdoDatabase $database) |
|
39 | - { |
|
40 | - if ($target !== null) { |
|
41 | - $query = <<<SQL |
|
22 | + private $type; |
|
23 | + private $target; |
|
24 | + private $user; |
|
25 | + private $reason; |
|
26 | + private $date; |
|
27 | + private $duration; |
|
28 | + private $active; |
|
29 | + |
|
30 | + /** |
|
31 | + * Gets all active bans, filtered by the optional target. |
|
32 | + * |
|
33 | + * @param string|null $target |
|
34 | + * @param PdoDatabase $database |
|
35 | + * |
|
36 | + * @return Ban[] |
|
37 | + */ |
|
38 | + public static function getActiveBans($target, PdoDatabase $database) |
|
39 | + { |
|
40 | + if ($target !== null) { |
|
41 | + $query = <<<SQL |
|
42 | 42 | SELECT * FROM ban |
43 | 43 | WHERE target = :target |
44 | 44 | AND (duration > UNIX_TIMESTAMP() OR duration is null) |
45 | 45 | AND active = 1; |
46 | 46 | SQL; |
47 | - $statement = $database->prepare($query); |
|
48 | - $statement->bindValue(":target", $target); |
|
49 | - } |
|
50 | - else { |
|
51 | - $query = <<<SQL |
|
47 | + $statement = $database->prepare($query); |
|
48 | + $statement->bindValue(":target", $target); |
|
49 | + } |
|
50 | + else { |
|
51 | + $query = <<<SQL |
|
52 | 52 | SELECT * FROM ban |
53 | 53 | WHERE (duration > UNIX_TIMESTAMP() OR duration is null) |
54 | 54 | AND active = 1; |
55 | 55 | SQL; |
56 | - $statement = $database->prepare($query); |
|
57 | - } |
|
58 | - |
|
59 | - $statement->execute(); |
|
60 | - |
|
61 | - $result = array(); |
|
62 | - |
|
63 | - /** @var Ban $v */ |
|
64 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
65 | - $v->setDatabase($database); |
|
66 | - $result[] = $v; |
|
67 | - } |
|
68 | - |
|
69 | - return $result; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Gets a ban by it's ID if it's currently active. |
|
74 | - * |
|
75 | - * @param integer $id |
|
76 | - * @param PdoDatabase $database |
|
77 | - * |
|
78 | - * @return Ban |
|
79 | - */ |
|
80 | - public static function getActiveId($id, PdoDatabase $database) |
|
81 | - { |
|
82 | - $statement = $database->prepare(<<<SQL |
|
56 | + $statement = $database->prepare($query); |
|
57 | + } |
|
58 | + |
|
59 | + $statement->execute(); |
|
60 | + |
|
61 | + $result = array(); |
|
62 | + |
|
63 | + /** @var Ban $v */ |
|
64 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
65 | + $v->setDatabase($database); |
|
66 | + $result[] = $v; |
|
67 | + } |
|
68 | + |
|
69 | + return $result; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Gets a ban by it's ID if it's currently active. |
|
74 | + * |
|
75 | + * @param integer $id |
|
76 | + * @param PdoDatabase $database |
|
77 | + * |
|
78 | + * @return Ban |
|
79 | + */ |
|
80 | + public static function getActiveId($id, PdoDatabase $database) |
|
81 | + { |
|
82 | + $statement = $database->prepare(<<<SQL |
|
83 | 83 | SELECT * |
84 | 84 | FROM ban |
85 | 85 | WHERE id = :id AND (duration > UNIX_TIMESTAMP() OR duration is null) AND active = 1; |
86 | 86 | SQL |
87 | - ); |
|
88 | - $statement->bindValue(":id", $id); |
|
89 | - |
|
90 | - $statement->execute(); |
|
91 | - |
|
92 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
93 | - |
|
94 | - if ($resultObject != false) { |
|
95 | - $resultObject->setDatabase($database); |
|
96 | - } |
|
97 | - |
|
98 | - return $resultObject; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Get all active bans for a target and type. |
|
103 | - * |
|
104 | - * @param string $target |
|
105 | - * @param string $type |
|
106 | - * @param PdoDatabase $database |
|
107 | - * |
|
108 | - * @return Ban |
|
109 | - */ |
|
110 | - public static function getBanByTarget($target, $type, PdoDatabase $database) |
|
111 | - { |
|
112 | - $query = <<<SQL |
|
87 | + ); |
|
88 | + $statement->bindValue(":id", $id); |
|
89 | + |
|
90 | + $statement->execute(); |
|
91 | + |
|
92 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
93 | + |
|
94 | + if ($resultObject != false) { |
|
95 | + $resultObject->setDatabase($database); |
|
96 | + } |
|
97 | + |
|
98 | + return $resultObject; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Get all active bans for a target and type. |
|
103 | + * |
|
104 | + * @param string $target |
|
105 | + * @param string $type |
|
106 | + * @param PdoDatabase $database |
|
107 | + * |
|
108 | + * @return Ban |
|
109 | + */ |
|
110 | + public static function getBanByTarget($target, $type, PdoDatabase $database) |
|
111 | + { |
|
112 | + $query = <<<SQL |
|
113 | 113 | SELECT * FROM ban |
114 | 114 | WHERE type = :type |
115 | 115 | AND target = :target |
116 | 116 | AND (duration > UNIX_TIMESTAMP() OR duration is null) |
117 | 117 | AND active = 1; |
118 | 118 | SQL; |
119 | - $statement = $database->prepare($query); |
|
120 | - $statement->bindValue(":target", $target); |
|
121 | - $statement->bindValue(":type", $type); |
|
119 | + $statement = $database->prepare($query); |
|
120 | + $statement->bindValue(":target", $target); |
|
121 | + $statement->bindValue(":type", $type); |
|
122 | 122 | |
123 | - $statement->execute(); |
|
123 | + $statement->execute(); |
|
124 | 124 | |
125 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
125 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
126 | 126 | |
127 | - if ($resultObject != false) { |
|
128 | - $resultObject->setDatabase($database); |
|
129 | - } |
|
127 | + if ($resultObject != false) { |
|
128 | + $resultObject->setDatabase($database); |
|
129 | + } |
|
130 | 130 | |
131 | - return $resultObject; |
|
132 | - } |
|
131 | + return $resultObject; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @throws Exception |
|
136 | - */ |
|
137 | - public function save() |
|
138 | - { |
|
139 | - if ($this->isNew()) { |
|
140 | - // insert |
|
141 | - $statement = $this->dbObject->prepare(<<<SQL |
|
134 | + /** |
|
135 | + * @throws Exception |
|
136 | + */ |
|
137 | + public function save() |
|
138 | + { |
|
139 | + if ($this->isNew()) { |
|
140 | + // insert |
|
141 | + $statement = $this->dbObject->prepare(<<<SQL |
|
142 | 142 | INSERT INTO `ban` (type, target, user, reason, date, duration, active) |
143 | 143 | VALUES (:type, :target, :user, :reason, CURRENT_TIMESTAMP(), :duration, :active); |
144 | 144 | SQL |
145 | - ); |
|
146 | - $statement->bindValue(":type", $this->type); |
|
147 | - $statement->bindValue(":target", $this->target); |
|
148 | - $statement->bindValue(":user", $this->user); |
|
149 | - $statement->bindValue(":reason", $this->reason); |
|
150 | - $statement->bindValue(":duration", $this->duration); |
|
151 | - $statement->bindValue(":active", $this->active); |
|
152 | - |
|
153 | - if ($statement->execute()) { |
|
154 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
155 | - } |
|
156 | - else { |
|
157 | - throw new Exception($statement->errorInfo()); |
|
158 | - } |
|
159 | - } |
|
160 | - else { |
|
161 | - // update |
|
162 | - $statement = $this->dbObject->prepare(<<<SQL |
|
145 | + ); |
|
146 | + $statement->bindValue(":type", $this->type); |
|
147 | + $statement->bindValue(":target", $this->target); |
|
148 | + $statement->bindValue(":user", $this->user); |
|
149 | + $statement->bindValue(":reason", $this->reason); |
|
150 | + $statement->bindValue(":duration", $this->duration); |
|
151 | + $statement->bindValue(":active", $this->active); |
|
152 | + |
|
153 | + if ($statement->execute()) { |
|
154 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
155 | + } |
|
156 | + else { |
|
157 | + throw new Exception($statement->errorInfo()); |
|
158 | + } |
|
159 | + } |
|
160 | + else { |
|
161 | + // update |
|
162 | + $statement = $this->dbObject->prepare(<<<SQL |
|
163 | 163 | UPDATE `ban` |
164 | 164 | SET duration = :duration, active = :active, user = :user, updateversion = updateversion + 1 |
165 | 165 | WHERE id = :id AND updateversion = :updateversion; |
166 | 166 | SQL |
167 | - ); |
|
168 | - $statement->bindValue(':id', $this->id); |
|
169 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
170 | - |
|
171 | - $statement->bindValue(':duration', $this->duration); |
|
172 | - $statement->bindValue(':active', $this->active); |
|
173 | - $statement->bindValue(':user', $this->user); |
|
174 | - |
|
175 | - if (!$statement->execute()) { |
|
176 | - throw new Exception($statement->errorInfo()); |
|
177 | - } |
|
178 | - |
|
179 | - if ($statement->rowCount() !== 1) { |
|
180 | - throw new OptimisticLockFailedException(); |
|
181 | - } |
|
182 | - |
|
183 | - $this->updateversion++; |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - public function getType() |
|
191 | - { |
|
192 | - return $this->type; |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * @param string $type |
|
197 | - */ |
|
198 | - public function setType($type) |
|
199 | - { |
|
200 | - $this->type = $type; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @return string |
|
205 | - */ |
|
206 | - public function getTarget() |
|
207 | - { |
|
208 | - return $this->target; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * @param string $target |
|
213 | - */ |
|
214 | - public function setTarget($target) |
|
215 | - { |
|
216 | - $this->target = $target; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @return string |
|
221 | - */ |
|
222 | - public function getReason() |
|
223 | - { |
|
224 | - return $this->reason; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * @param string $reason |
|
229 | - */ |
|
230 | - public function setReason($reason) |
|
231 | - { |
|
232 | - $this->reason = $reason; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @return mixed |
|
237 | - */ |
|
238 | - public function getDate() |
|
239 | - { |
|
240 | - return $this->date; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @return mixed |
|
245 | - */ |
|
246 | - public function getDuration() |
|
247 | - { |
|
248 | - return $this->duration; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @param mixed $duration |
|
253 | - */ |
|
254 | - public function setDuration($duration) |
|
255 | - { |
|
256 | - $this->duration = $duration; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public function isActive() |
|
263 | - { |
|
264 | - return $this->active == 1; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @param bool $active |
|
269 | - */ |
|
270 | - public function setActive($active) |
|
271 | - { |
|
272 | - $this->active = $active ? 1 : 0; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @return int |
|
277 | - */ |
|
278 | - public function getUser() |
|
279 | - { |
|
280 | - return $this->user; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * @param int $user UserID of user who is setting the ban |
|
285 | - * |
|
286 | - * @throws Exception |
|
287 | - */ |
|
288 | - public function setUser($user) |
|
289 | - { |
|
290 | - $this->user = $user; |
|
291 | - } |
|
167 | + ); |
|
168 | + $statement->bindValue(':id', $this->id); |
|
169 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
170 | + |
|
171 | + $statement->bindValue(':duration', $this->duration); |
|
172 | + $statement->bindValue(':active', $this->active); |
|
173 | + $statement->bindValue(':user', $this->user); |
|
174 | + |
|
175 | + if (!$statement->execute()) { |
|
176 | + throw new Exception($statement->errorInfo()); |
|
177 | + } |
|
178 | + |
|
179 | + if ($statement->rowCount() !== 1) { |
|
180 | + throw new OptimisticLockFailedException(); |
|
181 | + } |
|
182 | + |
|
183 | + $this->updateversion++; |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + public function getType() |
|
191 | + { |
|
192 | + return $this->type; |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * @param string $type |
|
197 | + */ |
|
198 | + public function setType($type) |
|
199 | + { |
|
200 | + $this->type = $type; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @return string |
|
205 | + */ |
|
206 | + public function getTarget() |
|
207 | + { |
|
208 | + return $this->target; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * @param string $target |
|
213 | + */ |
|
214 | + public function setTarget($target) |
|
215 | + { |
|
216 | + $this->target = $target; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @return string |
|
221 | + */ |
|
222 | + public function getReason() |
|
223 | + { |
|
224 | + return $this->reason; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * @param string $reason |
|
229 | + */ |
|
230 | + public function setReason($reason) |
|
231 | + { |
|
232 | + $this->reason = $reason; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @return mixed |
|
237 | + */ |
|
238 | + public function getDate() |
|
239 | + { |
|
240 | + return $this->date; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @return mixed |
|
245 | + */ |
|
246 | + public function getDuration() |
|
247 | + { |
|
248 | + return $this->duration; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @param mixed $duration |
|
253 | + */ |
|
254 | + public function setDuration($duration) |
|
255 | + { |
|
256 | + $this->duration = $duration; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public function isActive() |
|
263 | + { |
|
264 | + return $this->active == 1; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @param bool $active |
|
269 | + */ |
|
270 | + public function setActive($active) |
|
271 | + { |
|
272 | + $this->active = $active ? 1 : 0; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @return int |
|
277 | + */ |
|
278 | + public function getUser() |
|
279 | + { |
|
280 | + return $this->user; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * @param int $user UserID of user who is setting the ban |
|
285 | + * |
|
286 | + * @throws Exception |
|
287 | + */ |
|
288 | + public function setUser($user) |
|
289 | + { |
|
290 | + $this->user = $user; |
|
291 | + } |
|
292 | 292 | } |
@@ -46,8 +46,7 @@ discard block |
||
46 | 46 | SQL; |
47 | 47 | $statement = $database->prepare($query); |
48 | 48 | $statement->bindValue(":target", $target); |
49 | - } |
|
50 | - else { |
|
49 | + } else { |
|
51 | 50 | $query = <<<SQL |
52 | 51 | SELECT * FROM ban |
53 | 52 | WHERE (duration > UNIX_TIMESTAMP() OR duration is null) |
@@ -152,12 +151,10 @@ discard block |
||
152 | 151 | |
153 | 152 | if ($statement->execute()) { |
154 | 153 | $this->id = (int)$this->dbObject->lastInsertId(); |
155 | - } |
|
156 | - else { |
|
154 | + } else { |
|
157 | 155 | throw new Exception($statement->errorInfo()); |
158 | 156 | } |
159 | - } |
|
160 | - else { |
|
157 | + } else { |
|
161 | 158 | // update |
162 | 159 | $statement = $this->dbObject->prepare(<<<SQL |
163 | 160 | UPDATE `ban` |
@@ -12,98 +12,98 @@ |
||
12 | 12 | |
13 | 13 | class ValidationError |
14 | 14 | { |
15 | - const NAME_EMPTY = "name_empty"; |
|
16 | - const NAME_EXISTS = "name_exists"; |
|
17 | - const NAME_EXISTS_SUL = "name_exists_sul"; |
|
18 | - const NAME_NUMONLY = "name_numonly"; |
|
19 | - const NAME_INVALIDCHAR = "name_invalidchar"; |
|
20 | - const NAME_SANITISED = "name_sanitised"; |
|
21 | - const EMAIL_EMPTY = "email_empty"; |
|
22 | - const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
23 | - const EMAIL_INVALID = "email_invalid"; |
|
24 | - const EMAIL_MISMATCH = "email_mismatch"; |
|
25 | - const OPEN_REQUEST_NAME = "open_request_name"; |
|
26 | - const BANNED = "banned"; |
|
27 | - const BANNED_TOR = "banned_tor"; |
|
28 | - /** |
|
29 | - * @var array Error text for the above |
|
30 | - */ |
|
31 | - private static $errorText = array( |
|
32 | - self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
33 | - self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
34 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
35 | - . '[[User:example]] would become [[User:Example]].', |
|
36 | - self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
37 | - . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
38 | - . '[[User:example]] would become [[User:Example]].', |
|
39 | - self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
40 | - . 'with a valid username.', |
|
41 | - self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
42 | - . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
43 | - self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
44 | - . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
45 | - self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
46 | - self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
47 | - self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
48 | - self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
49 | - self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
50 | - self::BANNED => 'Sorry, you are currently banned from requesting accounts using this tool.', |
|
51 | - self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
52 | - . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
53 | - ); |
|
54 | - /** |
|
55 | - * Summary of $errorCode |
|
56 | - * @var string |
|
57 | - */ |
|
58 | - private $errorCode; |
|
59 | - /** |
|
60 | - * Summary of $isError |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - private $isError; |
|
15 | + const NAME_EMPTY = "name_empty"; |
|
16 | + const NAME_EXISTS = "name_exists"; |
|
17 | + const NAME_EXISTS_SUL = "name_exists_sul"; |
|
18 | + const NAME_NUMONLY = "name_numonly"; |
|
19 | + const NAME_INVALIDCHAR = "name_invalidchar"; |
|
20 | + const NAME_SANITISED = "name_sanitised"; |
|
21 | + const EMAIL_EMPTY = "email_empty"; |
|
22 | + const EMAIL_WIKIMEDIA = "email_wikimedia"; |
|
23 | + const EMAIL_INVALID = "email_invalid"; |
|
24 | + const EMAIL_MISMATCH = "email_mismatch"; |
|
25 | + const OPEN_REQUEST_NAME = "open_request_name"; |
|
26 | + const BANNED = "banned"; |
|
27 | + const BANNED_TOR = "banned_tor"; |
|
28 | + /** |
|
29 | + * @var array Error text for the above |
|
30 | + */ |
|
31 | + private static $errorText = array( |
|
32 | + self::NAME_EMPTY => 'You\'ve not chosen a username!', |
|
33 | + self::NAME_EXISTS => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
34 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
35 | + . '[[User:example]] would become [[User:Example]].', |
|
36 | + self::NAME_EXISTS_SUL => 'I\'m sorry, but the username you selected is already taken. Please try another. ' |
|
37 | + . 'Please note that Wikipedia automatically capitalizes the first letter of any user name, therefore ' |
|
38 | + . '[[User:example]] would become [[User:Example]].', |
|
39 | + self::NAME_NUMONLY => 'The username you chose is invalid: it consists entirely of numbers. Please retry ' |
|
40 | + . 'with a valid username.', |
|
41 | + self::NAME_INVALIDCHAR => 'There appears to be an invalid character in your username. Please note that the ' |
|
42 | + . 'following characters are not allowed: <code># @ / < > [ ] | { }</code>', |
|
43 | + self::NAME_SANITISED => 'Your requested username has been automatically adjusted due to technical ' |
|
44 | + . 'restrictions. Underscores have been replaced with spaces, and the first character has been capitalised.', |
|
45 | + self::EMAIL_EMPTY => 'You need to supply an email address.', |
|
46 | + self::EMAIL_WIKIMEDIA => 'Please provide your email address here.', |
|
47 | + self::EMAIL_INVALID => 'Invalid E-mail address supplied. Please check you entered it correctly.', |
|
48 | + self::EMAIL_MISMATCH => 'The email addresses you entered do not match. Please try again.', |
|
49 | + self::OPEN_REQUEST_NAME => 'There is already an open request with this name in this system.', |
|
50 | + self::BANNED => 'Sorry, you are currently banned from requesting accounts using this tool.', |
|
51 | + self::BANNED_TOR => 'Tor exit nodes are currently banned from using this tool due to excessive abuse. ' |
|
52 | + . 'Please note that Tor is also currently banned from editing Wikipedia.', |
|
53 | + ); |
|
54 | + /** |
|
55 | + * Summary of $errorCode |
|
56 | + * @var string |
|
57 | + */ |
|
58 | + private $errorCode; |
|
59 | + /** |
|
60 | + * Summary of $isError |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + private $isError; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Summary of __construct |
|
67 | - * |
|
68 | - * @param string $errorCode |
|
69 | - * @param bool $isError |
|
70 | - */ |
|
71 | - public function __construct($errorCode, $isError = true) |
|
72 | - { |
|
73 | - $this->errorCode = $errorCode; |
|
74 | - $this->isError = $isError; |
|
75 | - } |
|
65 | + /** |
|
66 | + * Summary of __construct |
|
67 | + * |
|
68 | + * @param string $errorCode |
|
69 | + * @param bool $isError |
|
70 | + */ |
|
71 | + public function __construct($errorCode, $isError = true) |
|
72 | + { |
|
73 | + $this->errorCode = $errorCode; |
|
74 | + $this->isError = $isError; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Summary of getErrorCode |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function getErrorCode() |
|
82 | - { |
|
83 | - return $this->errorCode; |
|
84 | - } |
|
77 | + /** |
|
78 | + * Summary of getErrorCode |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function getErrorCode() |
|
82 | + { |
|
83 | + return $this->errorCode; |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * @return string |
|
88 | - * @throws Exception |
|
89 | - */ |
|
90 | - public function getErrorMessage() |
|
91 | - { |
|
92 | - $text = self::$errorText[$this->errorCode]; |
|
86 | + /** |
|
87 | + * @return string |
|
88 | + * @throws Exception |
|
89 | + */ |
|
90 | + public function getErrorMessage() |
|
91 | + { |
|
92 | + $text = self::$errorText[$this->errorCode]; |
|
93 | 93 | |
94 | - if ($text == null) { |
|
95 | - throw new Exception('Unknown validation error'); |
|
96 | - } |
|
94 | + if ($text == null) { |
|
95 | + throw new Exception('Unknown validation error'); |
|
96 | + } |
|
97 | 97 | |
98 | - return $text; |
|
99 | - } |
|
98 | + return $text; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Summary of isError |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public function isError() |
|
106 | - { |
|
107 | - return $this->isError; |
|
108 | - } |
|
101 | + /** |
|
102 | + * Summary of isError |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public function isError() |
|
106 | + { |
|
107 | + return $this->isError; |
|
108 | + } |
|
109 | 109 | } |
@@ -20,73 +20,73 @@ |
||
20 | 20 | |
21 | 21 | class WelcomeUserTask extends BackgroundTaskBase |
22 | 22 | { |
23 | - public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
24 | - { |
|
25 | - $job = new JobQueue(); |
|
26 | - $job->setDatabase($database); |
|
27 | - $job->setTask(WelcomeUserTask::class); |
|
28 | - $job->setRequest($request->getId()); |
|
29 | - $job->setTriggerUserId($triggerUser->getId()); |
|
30 | - $job->save(); |
|
31 | - } |
|
32 | - |
|
33 | - public function execute() |
|
34 | - { |
|
35 | - $database = $this->getDatabase(); |
|
36 | - $request = $this->getRequest(); |
|
37 | - $user = $this->getTriggerUser(); |
|
38 | - |
|
39 | - if ($user->getWelcomeTemplate() === null) { |
|
40 | - $this->markFailed('Welcome template not specified'); |
|
41 | - |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - /** @var WelcomeTemplate $template */ |
|
46 | - $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
47 | - |
|
48 | - if ($template === false) { |
|
49 | - $this->markFailed('Welcome template missing'); |
|
50 | - |
|
51 | - return; |
|
52 | - } |
|
53 | - |
|
54 | - $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
55 | - $this->getSiteConfiguration()); |
|
56 | - $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
57 | - |
|
58 | - if ($request->getStatus() !== RequestStatus::CLOSED) { |
|
59 | - $this->markFailed('Request is currently open'); |
|
60 | - |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
65 | - $this->markFailed('Account does not exist!'); |
|
66 | - |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $this->performWelcome($template, $request, $mediaWikiHelper); |
|
71 | - $this->markComplete(); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Performs the welcome |
|
76 | - * |
|
77 | - * @param WelcomeTemplate $template |
|
78 | - * @param Request $request |
|
79 | - * @param MediaWikiHelper $mediaWikiHelper |
|
80 | - */ |
|
81 | - private function performWelcome( |
|
82 | - WelcomeTemplate $template, |
|
83 | - Request $request, |
|
84 | - MediaWikiHelper $mediaWikiHelper |
|
85 | - ) { |
|
86 | - $templateText = $template->getBotCode(); |
|
87 | - $templateText = str_replace('$signature', '~~~~', $templateText); |
|
88 | - $templateText = str_replace('$username', $request->getName(), $templateText); |
|
89 | - |
|
90 | - $mediaWikiHelper->addTalkPageMessage($request->getName(), 'Welcome!', 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
91 | - } |
|
23 | + public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
24 | + { |
|
25 | + $job = new JobQueue(); |
|
26 | + $job->setDatabase($database); |
|
27 | + $job->setTask(WelcomeUserTask::class); |
|
28 | + $job->setRequest($request->getId()); |
|
29 | + $job->setTriggerUserId($triggerUser->getId()); |
|
30 | + $job->save(); |
|
31 | + } |
|
32 | + |
|
33 | + public function execute() |
|
34 | + { |
|
35 | + $database = $this->getDatabase(); |
|
36 | + $request = $this->getRequest(); |
|
37 | + $user = $this->getTriggerUser(); |
|
38 | + |
|
39 | + if ($user->getWelcomeTemplate() === null) { |
|
40 | + $this->markFailed('Welcome template not specified'); |
|
41 | + |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + /** @var WelcomeTemplate $template */ |
|
46 | + $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
47 | + |
|
48 | + if ($template === false) { |
|
49 | + $this->markFailed('Welcome template missing'); |
|
50 | + |
|
51 | + return; |
|
52 | + } |
|
53 | + |
|
54 | + $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
55 | + $this->getSiteConfiguration()); |
|
56 | + $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
57 | + |
|
58 | + if ($request->getStatus() !== RequestStatus::CLOSED) { |
|
59 | + $this->markFailed('Request is currently open'); |
|
60 | + |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
65 | + $this->markFailed('Account does not exist!'); |
|
66 | + |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $this->performWelcome($template, $request, $mediaWikiHelper); |
|
71 | + $this->markComplete(); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Performs the welcome |
|
76 | + * |
|
77 | + * @param WelcomeTemplate $template |
|
78 | + * @param Request $request |
|
79 | + * @param MediaWikiHelper $mediaWikiHelper |
|
80 | + */ |
|
81 | + private function performWelcome( |
|
82 | + WelcomeTemplate $template, |
|
83 | + Request $request, |
|
84 | + MediaWikiHelper $mediaWikiHelper |
|
85 | + ) { |
|
86 | + $templateText = $template->getBotCode(); |
|
87 | + $templateText = str_replace('$signature', '~~~~', $templateText); |
|
88 | + $templateText = str_replace('$username', $request->getName(), $templateText); |
|
89 | + |
|
90 | + $mediaWikiHelper->addTalkPageMessage($request->getName(), 'Welcome!', 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
91 | + } |
|
92 | 92 | } |
93 | 93 | \ No newline at end of file |
@@ -61,7 +61,7 @@ |
||
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())) { |
|
65 | 65 | $this->markFailed('Account does not exist!'); |
66 | 66 | |
67 | 67 | return; |
@@ -61,7 +61,7 @@ |
||
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!$mediaWikiHelper->checkAccountExists($request->getName())){ |
|
64 | + if (!$mediaWikiHelper->checkAccountExists($request->getName())) { |
|
65 | 65 | $this->markFailed('Account does not exist!'); |
66 | 66 | |
67 | 67 | return; |
@@ -14,14 +14,14 @@ |
||
14 | 14 | |
15 | 15 | class UserCreationTask extends CreationTaskBase |
16 | 16 | { |
17 | - /** |
|
18 | - * @return IMediaWikiClient |
|
19 | - */ |
|
20 | - protected function getMediaWikiClient() |
|
21 | - { |
|
22 | - $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
23 | - $this->getSiteConfiguration()); |
|
17 | + /** |
|
18 | + * @return IMediaWikiClient |
|
19 | + */ |
|
20 | + protected function getMediaWikiClient() |
|
21 | + { |
|
22 | + $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
23 | + $this->getSiteConfiguration()); |
|
24 | 24 | |
25 | - return $oauth; |
|
26 | - } |
|
25 | + return $oauth; |
|
26 | + } |
|
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -16,16 +16,16 @@ |
||
16 | 16 | |
17 | 17 | class BotCreationTask extends CreationTaskBase |
18 | 18 | { |
19 | - /** |
|
20 | - * @return IMediaWikiClient |
|
21 | - */ |
|
22 | - protected function getMediaWikiClient() |
|
23 | - { |
|
24 | - return new BotMediaWikiClient($this->getSiteConfiguration()); |
|
25 | - } |
|
19 | + /** |
|
20 | + * @return IMediaWikiClient |
|
21 | + */ |
|
22 | + protected function getMediaWikiClient() |
|
23 | + { |
|
24 | + return new BotMediaWikiClient($this->getSiteConfiguration()); |
|
25 | + } |
|
26 | 26 | |
27 | - protected function getCreationReason(Request $request, User $user) |
|
28 | - { |
|
29 | - return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
30 | - } |
|
27 | + protected function getCreationReason(Request $request, User $user) |
|
28 | + { |
|
29 | + return parent::getCreationReason($request, $user) . ', on behalf of [[User:' . $user->getOnWikiName() . ']]'; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | \ No newline at end of file |