Passed
Push — newinternal-releasecandidate ( 1c5b59...e5ef47 )
by Simon
06:45
created
includes/Helpers/SearchHelpers/JobQueueSearchHelper.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -13,67 +13,67 @@
 block discarded – undo
13 13
 
14 14
 class JobQueueSearchHelper extends SearchHelperBase
15 15
 {
16
-    protected function __construct(PdoDatabase $database)
17
-    {
18
-        parent::__construct($database, 'jobqueue', JobQueue::class, null);
19
-    }
20
-
21
-    /**
22
-     * @param PdoDatabase $database
23
-     *
24
-     * @return JobQueueSearchHelper
25
-     */
26
-    public static function get(PdoDatabase $database) {
27
-        $helper = new JobQueueSearchHelper($database);
28
-        return $helper;
29
-    }
30
-
31
-    /**
32
-     * @param string[] $statuses
33
-     *
34
-     * @return $this
35
-     */
36
-    public function statusIn($statuses) {
37
-        $this->inClause('status', $statuses);
38
-
39
-        return $this;
40
-    }
41
-
42
-    /**
43
-     * @return $this
44
-     */
45
-    public function notAcknowledged() {
46
-        $this->whereClause .= ' AND (acknowledged IS NULL OR acknowledged = 0)';
47
-
48
-        return $this;
49
-    }
50
-
51
-    public function byTask($task) {
52
-        $this->whereClause .= ' AND task = ?';
53
-        $this->parameterList[] = $task;
54
-
55
-        return $this;
56
-    }
57
-
58
-    public function byUser($userId) {
59
-        $this->whereClause .= ' AND user = ?';
60
-        $this->parameterList[] = $userId;
61
-
62
-        return $this;
63
-    }
64
-
65
-    public function byStatus($status) {
66
-        $this->whereClause .= ' AND status = ?';
67
-        $this->parameterList[] = $status;
68
-
69
-        return $this;
70
-    }
71
-
72
-    public function byRequest(int $request) : JobQueueSearchHelper
73
-    {
74
-        $this->whereClause .= ' AND request = ?';
75
-        $this->parameterList[] = $request;
76
-
77
-        return $this;
78
-    }
16
+	protected function __construct(PdoDatabase $database)
17
+	{
18
+		parent::__construct($database, 'jobqueue', JobQueue::class, null);
19
+	}
20
+
21
+	/**
22
+	 * @param PdoDatabase $database
23
+	 *
24
+	 * @return JobQueueSearchHelper
25
+	 */
26
+	public static function get(PdoDatabase $database) {
27
+		$helper = new JobQueueSearchHelper($database);
28
+		return $helper;
29
+	}
30
+
31
+	/**
32
+	 * @param string[] $statuses
33
+	 *
34
+	 * @return $this
35
+	 */
36
+	public function statusIn($statuses) {
37
+		$this->inClause('status', $statuses);
38
+
39
+		return $this;
40
+	}
41
+
42
+	/**
43
+	 * @return $this
44
+	 */
45
+	public function notAcknowledged() {
46
+		$this->whereClause .= ' AND (acknowledged IS NULL OR acknowledged = 0)';
47
+
48
+		return $this;
49
+	}
50
+
51
+	public function byTask($task) {
52
+		$this->whereClause .= ' AND task = ?';
53
+		$this->parameterList[] = $task;
54
+
55
+		return $this;
56
+	}
57
+
58
+	public function byUser($userId) {
59
+		$this->whereClause .= ' AND user = ?';
60
+		$this->parameterList[] = $userId;
61
+
62
+		return $this;
63
+	}
64
+
65
+	public function byStatus($status) {
66
+		$this->whereClause .= ' AND status = ?';
67
+		$this->parameterList[] = $status;
68
+
69
+		return $this;
70
+	}
71
+
72
+	public function byRequest(int $request) : JobQueueSearchHelper
73
+	{
74
+		$this->whereClause .= ' AND request = ?';
75
+		$this->parameterList[] = $request;
76
+
77
+		return $this;
78
+	}
79 79
 }
Please login to merge, or discard this patch.
includes/Helpers/IrcNotificationHelper.php 2 patches
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -26,434 +26,434 @@
 block discarded – undo
26 26
  */
27 27
 class IrcNotificationHelper
28 28
 {
29
-    /** @var PdoDatabase $notificationsDatabase */
30
-    private $notificationsDatabase;
31
-    /** @var PdoDatabase $primaryDatabase */
32
-    private $primaryDatabase;
33
-    /** @var bool $notificationsEnabled */
34
-    private $notificationsEnabled;
35
-    /** @var int $notificationType */
36
-    private $notificationType;
37
-    /** @var User $currentUser */
38
-    private $currentUser;
39
-    /** @var string $instanceName */
40
-    private $instanceName;
41
-    /** @var string */
42
-    private $baseUrl;
43
-    /** @var array */
44
-    private $requestStates;
45
-
46
-    /**
47
-     * IrcNotificationHelper constructor.
48
-     *
49
-     * @param SiteConfiguration $siteConfiguration
50
-     * @param PdoDatabase       $primaryDatabase
51
-     * @param PdoDatabase       $notificationsDatabase
52
-     */
53
-    public function __construct(
54
-        SiteConfiguration $siteConfiguration,
55
-        PdoDatabase $primaryDatabase,
56
-        PdoDatabase $notificationsDatabase = null
57
-    ) {
58
-        $this->primaryDatabase = $primaryDatabase;
59
-
60
-        if ($notificationsDatabase !== null) {
61
-            $this->notificationsDatabase = $notificationsDatabase;
62
-            $this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled();
63
-        }
64
-        else {
65
-            $this->notificationsEnabled = false;
66
-        }
67
-
68
-        $this->notificationType = $siteConfiguration->getIrcNotificationType();
69
-        $this->instanceName = $siteConfiguration->getIrcNotificationsInstance();
70
-        $this->baseUrl = $siteConfiguration->getBaseUrl();
71
-        $this->requestStates = $siteConfiguration->getRequestStates();
72
-
73
-        $this->currentUser = User::getCurrent($primaryDatabase);
74
-    }
75
-
76
-    /**
77
-     * Send a notification
78
-     *
79
-     * @param string $message The text to send
80
-     */
81
-    protected function send($message)
82
-    {
83
-        $instanceName = $this->instanceName;
84
-
85
-        if (!$this->notificationsEnabled) {
86
-            return;
87
-        }
88
-
89
-        $blacklist = array("DCC", "CCTP", "PRIVMSG");
90
-        $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91
-
92
-        $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
93
-
94
-        try {
95
-            $notification = new Notification();
96
-            $notification->setDatabase($this->notificationsDatabase);
97
-            $notification->setType($this->notificationType);
98
-            $notification->setText($msg);
99
-
100
-            $notification->save();
101
-        }
102
-        catch (Exception $ex) {
103
-            // OK, so we failed to send the notification - that db might be down?
104
-            // This is non-critical, so silently fail.
105
-
106
-            // Disable notifications for remainder of request.
107
-            $this->notificationsEnabled = false;
108
-        }
109
-    }
110
-
111
-    #region user management
112
-
113
-    /**
114
-     * send a new user notification
115
-     *
116
-     * @param User $user
117
-     */
118
-    public function userNew(User $user)
119
-    {
120
-        $this->send("New user: {$user->getUsername()}");
121
-    }
122
-
123
-    /**
124
-     * send an approved notification
125
-     *
126
-     * @param User $user
127
-     */
128
-    public function userApproved(User $user)
129
-    {
130
-        $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
131
-    }
132
-
133
-    /**
134
-     * send a declined notification
135
-     *
136
-     * @param User   $user
137
-     * @param string $reason the reason the user was declined
138
-     */
139
-    public function userDeclined(User $user, $reason)
140
-    {
141
-        $this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
142
-    }
143
-
144
-    /**
145
-     * send a suspended notification
146
-     *
147
-     * @param User   $user
148
-     * @param string $reason The reason the user has been suspended
149
-     */
150
-    public function userSuspended(User $user, $reason)
151
-    {
152
-        $this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
153
-    }
154
-
155
-    /**
156
-     * Send a preference change notification
157
-     *
158
-     * @param User $user
159
-     */
160
-    public function userPrefChange(User $user)
161
-    {
162
-        $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
163
-    }
164
-
165
-    /**
166
-     * Send a user renamed notification
167
-     *
168
-     * @param User   $user
169
-     * @param string $old
170
-     */
171
-    public function userRenamed(User $user, $old)
172
-    {
173
-        $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
174
-    }
175
-
176
-    /**
177
-     * @param User   $user
178
-     * @param string $reason
179
-     */
180
-    public function userRolesEdited(User $user, $reason)
181
-    {
182
-        $currentUser = $this->currentUser->getUsername();
183
-        $this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)");
184
-    }
185
-
186
-    #endregion
187
-
188
-    #region Site Notice
189
-
190
-    /**
191
-     * Summary of siteNoticeEdited
192
-     */
193
-    public function siteNoticeEdited()
194
-    {
195
-        $this->send("Site notice edited by " . $this->currentUser->getUsername());
196
-    }
197
-    #endregion
198
-
199
-    #region Welcome Templates
200
-    /**
201
-     * Summary of welcomeTemplateCreated
202
-     *
203
-     * @param WelcomeTemplate $template
204
-     */
205
-    public function welcomeTemplateCreated(WelcomeTemplate $template)
206
-    {
207
-        $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
208
-    }
209
-
210
-    /**
211
-     * Summary of welcomeTemplateDeleted
212
-     *
213
-     * @param int $templateid
214
-     */
215
-    public function welcomeTemplateDeleted($templateid)
216
-    {
217
-        $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
218
-    }
219
-
220
-    /**
221
-     * Summary of welcomeTemplateEdited
222
-     *
223
-     * @param WelcomeTemplate $template
224
-     */
225
-    public function welcomeTemplateEdited(WelcomeTemplate $template)
226
-    {
227
-        $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
228
-    }
229
-
230
-    #endregion
231
-
232
-    #region bans
233
-    /**
234
-     * Summary of banned
235
-     *
236
-     * @param Ban $ban
237
-     */
238
-    public function banned(Ban $ban)
239
-    {
240
-        if ($ban->getDuration() == -1) {
241
-            $duration = "indefinitely";
242
-        }
243
-        else {
244
-            $duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
245
-        }
246
-
247
-        $username = $this->currentUser->getUsername();
248
-
249
-        $this->send("{$ban->getTarget()} banned by {$username} for '{$ban->getReason()}' {$duration}");
250
-    }
251
-
252
-    /**
253
-     * Summary of unbanned
254
-     *
255
-     * @param Ban    $ban
256
-     * @param string $unbanreason
257
-     */
258
-    public function unbanned(Ban $ban, $unbanreason)
259
-    {
260
-        $this->send($ban->getTarget() . " unbanned by " . $this->currentUser
261
-                ->getUsername() . " (" . $unbanreason . ")");
262
-    }
263
-
264
-    #endregion
265
-
266
-    #region request management
267
-
268
-    /**
269
-     * Summary of requestReceived
270
-     *
271
-     * @param Request $request
272
-     */
273
-    public function requestReceived(Request $request)
274
-    {
275
-        $this->send(
276
-            IrcColourCode::DARK_GREY . "[["
277
-            . IrcColourCode::DARK_GREEN . "acc:"
278
-            . IrcColourCode::ORANGE . $request->getId()
279
-            . IrcColourCode::DARK_GREY . "]]"
280
-            . IrcColourCode::RED . " N "
281
-            . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
282
-            . IrcColourCode::DARK_RED . "* "
283
-            . IrcColourCode::DARK_GREEN . $request->getName()
284
-            . IrcColourCode::DARK_RED . " * "
285
-            . IrcColourCode::RESET
286
-        );
287
-    }
288
-
289
-    /**
290
-     * Summary of requestDeferred
291
-     *
292
-     * @param Request $request
293
-     */
294
-    public function requestDeferred(Request $request)
295
-    {
296
-        $availableRequestStates = $this->requestStates;
297
-
298
-        $deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
299
-        $username = $this->currentUser->getUsername();
300
-
301
-        $this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}");
302
-    }
303
-
304
-    /**
305
-     *
306
-     * Summary of requestDeferredWithMail
307
-     *
308
-     * @param Request $request
309
-     */
310
-    public function requestDeferredWithMail(Request $request)
311
-    {
312
-        $availableRequestStates = $this->requestStates;
313
-
314
-        $deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
315
-        $username = $this->currentUser->getUsername();
316
-        $id = $request->getId();
317
-        $name = $request->getName();
318
-
319
-        $this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}");
320
-    }
321
-
322
-    /**
323
-     * Summary of requestClosed
324
-     *
325
-     * @param Request $request
326
-     * @param string  $closetype
327
-     */
328
-    public function requestClosed(Request $request, $closetype)
329
-    {
330
-        $username = $this->currentUser->getUsername();
331
-
332
-        $this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}");
333
-    }
334
-
335
-    /**
336
-     * Summary of sentMail
337
-     *
338
-     * @param Request $request
339
-     */
340
-    public function sentMail(Request $request)
341
-    {
342
-        $this->send($this->currentUser->getUsername()
343
-            . " sent an email related to Request {$request->getId()} ({$request->getName()})");
344
-    }
345
-
346
-    #endregion
347
-
348
-    #region reservations
349
-
350
-    /**
351
-     * Summary of requestReserved
352
-     *
353
-     * @param Request $request
354
-     */
355
-    public function requestReserved(Request $request)
356
-    {
357
-        $username = $this->currentUser->getUsername();
358
-
359
-        $this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}");
360
-    }
361
-
362
-    /**
363
-     * Summary of requestReserveBroken
364
-     *
365
-     * @param Request $request
366
-     */
367
-    public function requestReserveBroken(Request $request)
368
-    {
369
-        $username = $this->currentUser->getUsername();
370
-
371
-        $this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}");
372
-    }
373
-
374
-    /**
375
-     * Summary of requestUnreserved
376
-     *
377
-     * @param Request $request
378
-     */
379
-    public function requestUnreserved(Request $request)
380
-    {
381
-        $this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled.");
382
-    }
383
-
384
-    /**
385
-     * Summary of requestReservationSent
386
-     *
387
-     * @param Request $request
388
-     * @param User    $target
389
-     */
390
-    public function requestReservationSent(Request $request, User $target)
391
-    {
392
-        $username = $this->currentUser->getUsername();
393
-
394
-        $this->send(
395
-            "Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by "
396
-            . $username);
397
-    }
398
-
399
-    #endregion
400
-
401
-    #region comments
402
-
403
-    /**
404
-     * Summary of commentCreated
405
-     *
406
-     * @param Comment $comment
407
-     * @param Request $request
408
-     */
409
-    public function commentCreated(Comment $comment, Request $request)
410
-    {
411
-        $username = $this->currentUser->getUsername();
412
-        $visibility = ($comment->getVisibility() == "admin" ? "private " : "");
413
-
414
-        $this->send("{$username} posted a {$visibility}comment on request {$request->getId()} ({$request->getName()})");
415
-    }
416
-
417
-    /**
418
-     * Summary of commentEdited
419
-     *
420
-     * @param Comment $comment
421
-     * @param Request $request
422
-     */
423
-    public function commentEdited(Comment $comment, Request $request)
424
-    {
425
-        $username = $this->currentUser->getUsername();
426
-
427
-        $this->send(<<<TAG
29
+	/** @var PdoDatabase $notificationsDatabase */
30
+	private $notificationsDatabase;
31
+	/** @var PdoDatabase $primaryDatabase */
32
+	private $primaryDatabase;
33
+	/** @var bool $notificationsEnabled */
34
+	private $notificationsEnabled;
35
+	/** @var int $notificationType */
36
+	private $notificationType;
37
+	/** @var User $currentUser */
38
+	private $currentUser;
39
+	/** @var string $instanceName */
40
+	private $instanceName;
41
+	/** @var string */
42
+	private $baseUrl;
43
+	/** @var array */
44
+	private $requestStates;
45
+
46
+	/**
47
+	 * IrcNotificationHelper constructor.
48
+	 *
49
+	 * @param SiteConfiguration $siteConfiguration
50
+	 * @param PdoDatabase       $primaryDatabase
51
+	 * @param PdoDatabase       $notificationsDatabase
52
+	 */
53
+	public function __construct(
54
+		SiteConfiguration $siteConfiguration,
55
+		PdoDatabase $primaryDatabase,
56
+		PdoDatabase $notificationsDatabase = null
57
+	) {
58
+		$this->primaryDatabase = $primaryDatabase;
59
+
60
+		if ($notificationsDatabase !== null) {
61
+			$this->notificationsDatabase = $notificationsDatabase;
62
+			$this->notificationsEnabled = $siteConfiguration->getIrcNotificationsEnabled();
63
+		}
64
+		else {
65
+			$this->notificationsEnabled = false;
66
+		}
67
+
68
+		$this->notificationType = $siteConfiguration->getIrcNotificationType();
69
+		$this->instanceName = $siteConfiguration->getIrcNotificationsInstance();
70
+		$this->baseUrl = $siteConfiguration->getBaseUrl();
71
+		$this->requestStates = $siteConfiguration->getRequestStates();
72
+
73
+		$this->currentUser = User::getCurrent($primaryDatabase);
74
+	}
75
+
76
+	/**
77
+	 * Send a notification
78
+	 *
79
+	 * @param string $message The text to send
80
+	 */
81
+	protected function send($message)
82
+	{
83
+		$instanceName = $this->instanceName;
84
+
85
+		if (!$this->notificationsEnabled) {
86
+			return;
87
+		}
88
+
89
+		$blacklist = array("DCC", "CCTP", "PRIVMSG");
90
+		$message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91
+
92
+		$msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
93
+
94
+		try {
95
+			$notification = new Notification();
96
+			$notification->setDatabase($this->notificationsDatabase);
97
+			$notification->setType($this->notificationType);
98
+			$notification->setText($msg);
99
+
100
+			$notification->save();
101
+		}
102
+		catch (Exception $ex) {
103
+			// OK, so we failed to send the notification - that db might be down?
104
+			// This is non-critical, so silently fail.
105
+
106
+			// Disable notifications for remainder of request.
107
+			$this->notificationsEnabled = false;
108
+		}
109
+	}
110
+
111
+	#region user management
112
+
113
+	/**
114
+	 * send a new user notification
115
+	 *
116
+	 * @param User $user
117
+	 */
118
+	public function userNew(User $user)
119
+	{
120
+		$this->send("New user: {$user->getUsername()}");
121
+	}
122
+
123
+	/**
124
+	 * send an approved notification
125
+	 *
126
+	 * @param User $user
127
+	 */
128
+	public function userApproved(User $user)
129
+	{
130
+		$this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
131
+	}
132
+
133
+	/**
134
+	 * send a declined notification
135
+	 *
136
+	 * @param User   $user
137
+	 * @param string $reason the reason the user was declined
138
+	 */
139
+	public function userDeclined(User $user, $reason)
140
+	{
141
+		$this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
142
+	}
143
+
144
+	/**
145
+	 * send a suspended notification
146
+	 *
147
+	 * @param User   $user
148
+	 * @param string $reason The reason the user has been suspended
149
+	 */
150
+	public function userSuspended(User $user, $reason)
151
+	{
152
+		$this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
153
+	}
154
+
155
+	/**
156
+	 * Send a preference change notification
157
+	 *
158
+	 * @param User $user
159
+	 */
160
+	public function userPrefChange(User $user)
161
+	{
162
+		$this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
163
+	}
164
+
165
+	/**
166
+	 * Send a user renamed notification
167
+	 *
168
+	 * @param User   $user
169
+	 * @param string $old
170
+	 */
171
+	public function userRenamed(User $user, $old)
172
+	{
173
+		$this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
174
+	}
175
+
176
+	/**
177
+	 * @param User   $user
178
+	 * @param string $reason
179
+	 */
180
+	public function userRolesEdited(User $user, $reason)
181
+	{
182
+		$currentUser = $this->currentUser->getUsername();
183
+		$this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)");
184
+	}
185
+
186
+	#endregion
187
+
188
+	#region Site Notice
189
+
190
+	/**
191
+	 * Summary of siteNoticeEdited
192
+	 */
193
+	public function siteNoticeEdited()
194
+	{
195
+		$this->send("Site notice edited by " . $this->currentUser->getUsername());
196
+	}
197
+	#endregion
198
+
199
+	#region Welcome Templates
200
+	/**
201
+	 * Summary of welcomeTemplateCreated
202
+	 *
203
+	 * @param WelcomeTemplate $template
204
+	 */
205
+	public function welcomeTemplateCreated(WelcomeTemplate $template)
206
+	{
207
+		$this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
208
+	}
209
+
210
+	/**
211
+	 * Summary of welcomeTemplateDeleted
212
+	 *
213
+	 * @param int $templateid
214
+	 */
215
+	public function welcomeTemplateDeleted($templateid)
216
+	{
217
+		$this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
218
+	}
219
+
220
+	/**
221
+	 * Summary of welcomeTemplateEdited
222
+	 *
223
+	 * @param WelcomeTemplate $template
224
+	 */
225
+	public function welcomeTemplateEdited(WelcomeTemplate $template)
226
+	{
227
+		$this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
228
+	}
229
+
230
+	#endregion
231
+
232
+	#region bans
233
+	/**
234
+	 * Summary of banned
235
+	 *
236
+	 * @param Ban $ban
237
+	 */
238
+	public function banned(Ban $ban)
239
+	{
240
+		if ($ban->getDuration() == -1) {
241
+			$duration = "indefinitely";
242
+		}
243
+		else {
244
+			$duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
245
+		}
246
+
247
+		$username = $this->currentUser->getUsername();
248
+
249
+		$this->send("{$ban->getTarget()} banned by {$username} for '{$ban->getReason()}' {$duration}");
250
+	}
251
+
252
+	/**
253
+	 * Summary of unbanned
254
+	 *
255
+	 * @param Ban    $ban
256
+	 * @param string $unbanreason
257
+	 */
258
+	public function unbanned(Ban $ban, $unbanreason)
259
+	{
260
+		$this->send($ban->getTarget() . " unbanned by " . $this->currentUser
261
+				->getUsername() . " (" . $unbanreason . ")");
262
+	}
263
+
264
+	#endregion
265
+
266
+	#region request management
267
+
268
+	/**
269
+	 * Summary of requestReceived
270
+	 *
271
+	 * @param Request $request
272
+	 */
273
+	public function requestReceived(Request $request)
274
+	{
275
+		$this->send(
276
+			IrcColourCode::DARK_GREY . "[["
277
+			. IrcColourCode::DARK_GREEN . "acc:"
278
+			. IrcColourCode::ORANGE . $request->getId()
279
+			. IrcColourCode::DARK_GREY . "]]"
280
+			. IrcColourCode::RED . " N "
281
+			. IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
282
+			. IrcColourCode::DARK_RED . "* "
283
+			. IrcColourCode::DARK_GREEN . $request->getName()
284
+			. IrcColourCode::DARK_RED . " * "
285
+			. IrcColourCode::RESET
286
+		);
287
+	}
288
+
289
+	/**
290
+	 * Summary of requestDeferred
291
+	 *
292
+	 * @param Request $request
293
+	 */
294
+	public function requestDeferred(Request $request)
295
+	{
296
+		$availableRequestStates = $this->requestStates;
297
+
298
+		$deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
299
+		$username = $this->currentUser->getUsername();
300
+
301
+		$this->send("Request {$request->getId()} ({$request->getName()}) deferred to {$deferTo} by {$username}");
302
+	}
303
+
304
+	/**
305
+	 *
306
+	 * Summary of requestDeferredWithMail
307
+	 *
308
+	 * @param Request $request
309
+	 */
310
+	public function requestDeferredWithMail(Request $request)
311
+	{
312
+		$availableRequestStates = $this->requestStates;
313
+
314
+		$deferTo = $availableRequestStates[$request->getStatus()]['deferto'];
315
+		$username = $this->currentUser->getUsername();
316
+		$id = $request->getId();
317
+		$name = $request->getName();
318
+
319
+		$this->send("Request {$id} ({$name}) deferred to {$deferTo} with an email by {$username}");
320
+	}
321
+
322
+	/**
323
+	 * Summary of requestClosed
324
+	 *
325
+	 * @param Request $request
326
+	 * @param string  $closetype
327
+	 */
328
+	public function requestClosed(Request $request, $closetype)
329
+	{
330
+		$username = $this->currentUser->getUsername();
331
+
332
+		$this->send("Request {$request->getId()} ({$request->getName()}) closed ($closetype) by {$username}");
333
+	}
334
+
335
+	/**
336
+	 * Summary of sentMail
337
+	 *
338
+	 * @param Request $request
339
+	 */
340
+	public function sentMail(Request $request)
341
+	{
342
+		$this->send($this->currentUser->getUsername()
343
+			. " sent an email related to Request {$request->getId()} ({$request->getName()})");
344
+	}
345
+
346
+	#endregion
347
+
348
+	#region reservations
349
+
350
+	/**
351
+	 * Summary of requestReserved
352
+	 *
353
+	 * @param Request $request
354
+	 */
355
+	public function requestReserved(Request $request)
356
+	{
357
+		$username = $this->currentUser->getUsername();
358
+
359
+		$this->send("Request {$request->getId()} ({$request->getName()}) reserved by {$username}");
360
+	}
361
+
362
+	/**
363
+	 * Summary of requestReserveBroken
364
+	 *
365
+	 * @param Request $request
366
+	 */
367
+	public function requestReserveBroken(Request $request)
368
+	{
369
+		$username = $this->currentUser->getUsername();
370
+
371
+		$this->send("Reservation on request {$request->getId()} ({$request->getName()}) broken by {$username}");
372
+	}
373
+
374
+	/**
375
+	 * Summary of requestUnreserved
376
+	 *
377
+	 * @param Request $request
378
+	 */
379
+	public function requestUnreserved(Request $request)
380
+	{
381
+		$this->send("Request {$request->getId()} ({$request->getName()}) is no longer being handled.");
382
+	}
383
+
384
+	/**
385
+	 * Summary of requestReservationSent
386
+	 *
387
+	 * @param Request $request
388
+	 * @param User    $target
389
+	 */
390
+	public function requestReservationSent(Request $request, User $target)
391
+	{
392
+		$username = $this->currentUser->getUsername();
393
+
394
+		$this->send(
395
+			"Reservation of request {$request->getId()} ({$request->getName()}) sent to {$target->getUsername()} by "
396
+			. $username);
397
+	}
398
+
399
+	#endregion
400
+
401
+	#region comments
402
+
403
+	/**
404
+	 * Summary of commentCreated
405
+	 *
406
+	 * @param Comment $comment
407
+	 * @param Request $request
408
+	 */
409
+	public function commentCreated(Comment $comment, Request $request)
410
+	{
411
+		$username = $this->currentUser->getUsername();
412
+		$visibility = ($comment->getVisibility() == "admin" ? "private " : "");
413
+
414
+		$this->send("{$username} posted a {$visibility}comment on request {$request->getId()} ({$request->getName()})");
415
+	}
416
+
417
+	/**
418
+	 * Summary of commentEdited
419
+	 *
420
+	 * @param Comment $comment
421
+	 * @param Request $request
422
+	 */
423
+	public function commentEdited(Comment $comment, Request $request)
424
+	{
425
+		$username = $this->currentUser->getUsername();
426
+
427
+		$this->send(<<<TAG
428 428
 Comment {$comment->getId()} on request {$request->getId()} ({$request->getName()}) edited by {$username}
429 429
 TAG
430
-        );
431
-    }
432
-
433
-    #endregion
434
-
435
-    #region email management (close reasons)
436
-
437
-    /**
438
-     * Summary of emailCreated
439
-     *
440
-     * @param EmailTemplate $template
441
-     */
442
-    public function emailCreated(EmailTemplate $template)
443
-    {
444
-        $username = $this->currentUser->getUsername();
445
-        $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
446
-    }
447
-
448
-    /**
449
-     * Summary of emailEdited
450
-     *
451
-     * @param EmailTemplate $template
452
-     */
453
-    public function emailEdited(EmailTemplate $template)
454
-    {
455
-        $username = $this->currentUser->getUsername();
456
-        $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
457
-    }
458
-    #endregion
430
+		);
431
+	}
432
+
433
+	#endregion
434
+
435
+	#region email management (close reasons)
436
+
437
+	/**
438
+	 * Summary of emailCreated
439
+	 *
440
+	 * @param EmailTemplate $template
441
+	 */
442
+	public function emailCreated(EmailTemplate $template)
443
+	{
444
+		$username = $this->currentUser->getUsername();
445
+		$this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
446
+	}
447
+
448
+	/**
449
+	 * Summary of emailEdited
450
+	 *
451
+	 * @param EmailTemplate $template
452
+	 */
453
+	public function emailEdited(EmailTemplate $template)
454
+	{
455
+		$username = $this->currentUser->getUsername();
456
+		$this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
457
+	}
458
+	#endregion
459 459
 }
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $blacklist = array("DCC", "CCTP", "PRIVMSG");
90 90
         $message = str_replace($blacklist, "(IRC Blacklist)", $message); // Lets stop DCC etc
91 91
 
92
-        $msg = IrcColourCode::RESET . IrcColourCode::BOLD . "[$instanceName]" . IrcColourCode::RESET . ": $message";
92
+        $msg = IrcColourCode::RESET.IrcColourCode::BOLD."[$instanceName]".IrcColourCode::RESET.": $message";
93 93
 
94 94
         try {
95 95
             $notification = new Notification();
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function userApproved(User $user)
129 129
     {
130
-        $this->send("{$user->getUsername()} approved by " . $this->currentUser->getUsername());
130
+        $this->send("{$user->getUsername()} approved by ".$this->currentUser->getUsername());
131 131
     }
132 132
 
133 133
     /**
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
      */
139 139
     public function userDeclined(User $user, $reason)
140 140
     {
141
-        $this->send("{$user->getUsername()} declined by " . $this->currentUser->getUsername() . " ($reason)");
141
+        $this->send("{$user->getUsername()} declined by ".$this->currentUser->getUsername()." ($reason)");
142 142
     }
143 143
 
144 144
     /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
      */
150 150
     public function userSuspended(User $user, $reason)
151 151
     {
152
-        $this->send("{$user->getUsername()} suspended by " . $this->currentUser->getUsername() . " ($reason)");
152
+        $this->send("{$user->getUsername()} suspended by ".$this->currentUser->getUsername()." ($reason)");
153 153
     }
154 154
 
155 155
     /**
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
      */
160 160
     public function userPrefChange(User $user)
161 161
     {
162
-        $this->send("{$user->getUsername()}'s preferences were changed by " . $this->currentUser->getUsername());
162
+        $this->send("{$user->getUsername()}'s preferences were changed by ".$this->currentUser->getUsername());
163 163
     }
164 164
 
165 165
     /**
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function userRenamed(User $user, $old)
172 172
     {
173
-        $this->send($this->currentUser->getUsername() . " renamed $old to {$user->getUsername()}");
173
+        $this->send($this->currentUser->getUsername()." renamed $old to {$user->getUsername()}");
174 174
     }
175 175
 
176 176
     /**
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
     public function userRolesEdited(User $user, $reason)
181 181
     {
182 182
         $currentUser = $this->currentUser->getUsername();
183
-        $this->send("Active roles for {$user->getUsername()} changed by " . $currentUser . " ($reason)");
183
+        $this->send("Active roles for {$user->getUsername()} changed by ".$currentUser." ($reason)");
184 184
     }
185 185
 
186 186
     #endregion
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
      */
193 193
     public function siteNoticeEdited()
194 194
     {
195
-        $this->send("Site notice edited by " . $this->currentUser->getUsername());
195
+        $this->send("Site notice edited by ".$this->currentUser->getUsername());
196 196
     }
197 197
     #endregion
198 198
 
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      */
205 205
     public function welcomeTemplateCreated(WelcomeTemplate $template)
206 206
     {
207
-        $this->send("Welcome template {$template->getId()} created by " . $this->currentUser->getUsername());
207
+        $this->send("Welcome template {$template->getId()} created by ".$this->currentUser->getUsername());
208 208
     }
209 209
 
210 210
     /**
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
      */
215 215
     public function welcomeTemplateDeleted($templateid)
216 216
     {
217
-        $this->send("Welcome template {$templateid} deleted by " . $this->currentUser->getUsername());
217
+        $this->send("Welcome template {$templateid} deleted by ".$this->currentUser->getUsername());
218 218
     }
219 219
 
220 220
     /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     public function welcomeTemplateEdited(WelcomeTemplate $template)
226 226
     {
227
-        $this->send("Welcome template {$template->getId()} edited by " . $this->currentUser->getUsername());
227
+        $this->send("Welcome template {$template->getId()} edited by ".$this->currentUser->getUsername());
228 228
     }
229 229
 
230 230
     #endregion
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
             $duration = "indefinitely";
242 242
         }
243 243
         else {
244
-            $duration = "until " . date("F j, Y, g:i a", $ban->getDuration());
244
+            $duration = "until ".date("F j, Y, g:i a", $ban->getDuration());
245 245
         }
246 246
 
247 247
         $username = $this->currentUser->getUsername();
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
      */
258 258
     public function unbanned(Ban $ban, $unbanreason)
259 259
     {
260
-        $this->send($ban->getTarget() . " unbanned by " . $this->currentUser
261
-                ->getUsername() . " (" . $unbanreason . ")");
260
+        $this->send($ban->getTarget()." unbanned by ".$this->currentUser
261
+                ->getUsername()." (".$unbanreason.")");
262 262
     }
263 263
 
264 264
     #endregion
@@ -273,15 +273,15 @@  discard block
 block discarded – undo
273 273
     public function requestReceived(Request $request)
274 274
     {
275 275
         $this->send(
276
-            IrcColourCode::DARK_GREY . "[["
277
-            . IrcColourCode::DARK_GREEN . "acc:"
278
-            . IrcColourCode::ORANGE . $request->getId()
279
-            . IrcColourCode::DARK_GREY . "]]"
280
-            . IrcColourCode::RED . " N "
281
-            . IrcColourCode::DARK_BLUE . $this->baseUrl . "/internal.php/viewRequest?id={$request->getId()} "
282
-            . IrcColourCode::DARK_RED . "* "
283
-            . IrcColourCode::DARK_GREEN . $request->getName()
284
-            . IrcColourCode::DARK_RED . " * "
276
+            IrcColourCode::DARK_GREY."[["
277
+            . IrcColourCode::DARK_GREEN."acc:"
278
+            . IrcColourCode::ORANGE.$request->getId()
279
+            . IrcColourCode::DARK_GREY."]]"
280
+            . IrcColourCode::RED." N "
281
+            . IrcColourCode::DARK_BLUE.$this->baseUrl."/internal.php/viewRequest?id={$request->getId()} "
282
+            . IrcColourCode::DARK_RED."* "
283
+            . IrcColourCode::DARK_GREEN.$request->getName()
284
+            . IrcColourCode::DARK_RED." * "
285 285
             . IrcColourCode::RESET
286 286
         );
287 287
     }
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
     public function emailCreated(EmailTemplate $template)
443 443
     {
444 444
         $username = $this->currentUser->getUsername();
445
-        $this->send("Email {$template->getId()} ({$template->getName()}) created by " . $username);
445
+        $this->send("Email {$template->getId()} ({$template->getName()}) created by ".$username);
446 446
     }
447 447
 
448 448
     /**
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
     public function emailEdited(EmailTemplate $template)
454 454
     {
455 455
         $username = $this->currentUser->getUsername();
456
-        $this->send("Email {$template->getId()} ({$template->getName()}) edited by " . $username);
456
+        $this->send("Email {$template->getId()} ({$template->getName()}) edited by ".$username);
457 457
     }
458 458
     #endregion
459 459
 }
Please login to merge, or discard this patch.
includes/ConsoleTasks/RunJobQueueTask.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -22,124 +22,124 @@
 block discarded – undo
22 22
 
23 23
 class RunJobQueueTask extends ConsoleTaskBase
24 24
 {
25
-    private $taskList = array(
26
-        WelcomeUserTask::class,
27
-        BotCreationTask::class,
28
-        UserCreationTask::class
29
-    );
30
-
31
-    public function execute()
32
-    {
33
-        $database = $this->getDatabase();
34
-
35
-        // ensure we're running inside a tx here.
36
-        if (!$database->hasActiveTransaction()) {
37
-            $database->beginTransaction();
38
-        }
39
-
40
-        $sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim';
41
-        $statement = $database->prepare($sql);
42
-        $statement->execute(array(':status' => JobQueue::STATUS_READY, ':lim' => 10));
43
-        /** @var JobQueue[] $queuedJobs */
44
-        $queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class);
45
-
46
-        // mark all the jobs as running, and commit the txn so we're not holding onto long-running transactions.
47
-        // We'll re-lock the row when we get to it.
48
-        foreach ($queuedJobs as $job) {
49
-            $job->setDatabase($database);
50
-            $job->setStatus(JobQueue::STATUS_WAITING);
51
-            $job->setError(null);
52
-            $job->setAcknowledged(null);
53
-            $job->save();
54
-        }
55
-
56
-        $database->commit();
57
-
58
-        set_error_handler(array(RunJobQueueTask::class, 'errorHandler'), E_ALL);
59
-
60
-        foreach ($queuedJobs as $job) {
61
-            try {
62
-                // refresh from the database
63
-                /** @var JobQueue $job */
64
-                $job = JobQueue::getById($job->getId(), $database);
65
-
66
-                if ($job->getStatus() !== JobQueue::STATUS_WAITING) {
67
-                    continue;
68
-                }
69
-
70
-                $database->beginTransaction();
71
-                $job->setStatus(JobQueue::STATUS_RUNNING);
72
-                $job->save();
73
-                $database->commit();
74
-
75
-                $database->beginTransaction();
76
-
77
-                // re-lock the job
78
-                $job->setStatus(JobQueue::STATUS_RUNNING);
79
-                $job->save();
80
-
81
-                // validate we're allowed to run the requested task (whitelist)
82
-                if (!in_array($job->getTask(), $this->taskList)) {
83
-                    throw new ApplicationLogicException('Job task not registered');
84
-                }
85
-
86
-                // Create a task.
87
-                $taskName = $job->getTask();
88
-
89
-                if(!class_exists($taskName)) {
90
-                    throw new ApplicationLogicException('Job task does not exist');
91
-                }
92
-
93
-                /** @var BackgroundTaskBase $task */
94
-                $task = new $taskName;
95
-
96
-                $this->setupTask($task, $job);
97
-                $task->run();
98
-            }
99
-            catch (Exception $ex) {
100
-                $database->rollBack();
101
-                $database->beginTransaction();
102
-
103
-                /** @var JobQueue $job */
104
-                $job = JobQueue::getById($job->getId(), $database);
105
-                $job->setDatabase($database);
106
-                $job->setStatus(JobQueue::STATUS_FAILED);
107
-                $job->setError($ex->getMessage());
108
-                $job->setAcknowledged(0);
109
-                $job->save();
110
-
111
-                /** @var Request $request */
112
-                $request = Request::getById($job->getRequest(), $database);
113
-                if ($request === false) {
114
-                    $request = null;
115
-                }
116
-
117
-                Logger::backgroundJobIssue($this->getDatabase(), $job);
118
-
119
-                $database->commit();
120
-            }
121
-            finally {
122
-                $database->commit();
123
-            }
124
-        }
125
-    }
126
-
127
-    /**
128
-     * @param BackgroundTaskBase $task
129
-     * @param JobQueue           $job
130
-     */
131
-    private function setupTask(BackgroundTaskBase $task, JobQueue $job)
132
-    {
133
-        $task->setJob($job);
134
-        $task->setDatabase($this->getDatabase());
135
-        $task->setHttpHelper($this->getHttpHelper());
136
-        $task->setOauthProtocolHelper($this->getOAuthProtocolHelper());
137
-        $task->setEmailHelper($this->getEmailHelper());
138
-        $task->setSiteConfiguration($this->getSiteConfiguration());
139
-        $task->setNotificationHelper($this->getNotificationHelper());
140
-    }
141
-
142
-    public static function errorHandler($errno, $errstr, $errfile, $errline) {
143
-        throw new Exception($errfile . "@" . $errline . ": " . $errstr);
144
-    }
25
+	private $taskList = array(
26
+		WelcomeUserTask::class,
27
+		BotCreationTask::class,
28
+		UserCreationTask::class
29
+	);
30
+
31
+	public function execute()
32
+	{
33
+		$database = $this->getDatabase();
34
+
35
+		// ensure we're running inside a tx here.
36
+		if (!$database->hasActiveTransaction()) {
37
+			$database->beginTransaction();
38
+		}
39
+
40
+		$sql = 'SELECT * FROM jobqueue WHERE status = :status ORDER BY enqueue LIMIT :lim';
41
+		$statement = $database->prepare($sql);
42
+		$statement->execute(array(':status' => JobQueue::STATUS_READY, ':lim' => 10));
43
+		/** @var JobQueue[] $queuedJobs */
44
+		$queuedJobs = $statement->fetchAll(PDO::FETCH_CLASS, JobQueue::class);
45
+
46
+		// mark all the jobs as running, and commit the txn so we're not holding onto long-running transactions.
47
+		// We'll re-lock the row when we get to it.
48
+		foreach ($queuedJobs as $job) {
49
+			$job->setDatabase($database);
50
+			$job->setStatus(JobQueue::STATUS_WAITING);
51
+			$job->setError(null);
52
+			$job->setAcknowledged(null);
53
+			$job->save();
54
+		}
55
+
56
+		$database->commit();
57
+
58
+		set_error_handler(array(RunJobQueueTask::class, 'errorHandler'), E_ALL);
59
+
60
+		foreach ($queuedJobs as $job) {
61
+			try {
62
+				// refresh from the database
63
+				/** @var JobQueue $job */
64
+				$job = JobQueue::getById($job->getId(), $database);
65
+
66
+				if ($job->getStatus() !== JobQueue::STATUS_WAITING) {
67
+					continue;
68
+				}
69
+
70
+				$database->beginTransaction();
71
+				$job->setStatus(JobQueue::STATUS_RUNNING);
72
+				$job->save();
73
+				$database->commit();
74
+
75
+				$database->beginTransaction();
76
+
77
+				// re-lock the job
78
+				$job->setStatus(JobQueue::STATUS_RUNNING);
79
+				$job->save();
80
+
81
+				// validate we're allowed to run the requested task (whitelist)
82
+				if (!in_array($job->getTask(), $this->taskList)) {
83
+					throw new ApplicationLogicException('Job task not registered');
84
+				}
85
+
86
+				// Create a task.
87
+				$taskName = $job->getTask();
88
+
89
+				if(!class_exists($taskName)) {
90
+					throw new ApplicationLogicException('Job task does not exist');
91
+				}
92
+
93
+				/** @var BackgroundTaskBase $task */
94
+				$task = new $taskName;
95
+
96
+				$this->setupTask($task, $job);
97
+				$task->run();
98
+			}
99
+			catch (Exception $ex) {
100
+				$database->rollBack();
101
+				$database->beginTransaction();
102
+
103
+				/** @var JobQueue $job */
104
+				$job = JobQueue::getById($job->getId(), $database);
105
+				$job->setDatabase($database);
106
+				$job->setStatus(JobQueue::STATUS_FAILED);
107
+				$job->setError($ex->getMessage());
108
+				$job->setAcknowledged(0);
109
+				$job->save();
110
+
111
+				/** @var Request $request */
112
+				$request = Request::getById($job->getRequest(), $database);
113
+				if ($request === false) {
114
+					$request = null;
115
+				}
116
+
117
+				Logger::backgroundJobIssue($this->getDatabase(), $job);
118
+
119
+				$database->commit();
120
+			}
121
+			finally {
122
+				$database->commit();
123
+			}
124
+		}
125
+	}
126
+
127
+	/**
128
+	 * @param BackgroundTaskBase $task
129
+	 * @param JobQueue           $job
130
+	 */
131
+	private function setupTask(BackgroundTaskBase $task, JobQueue $job)
132
+	{
133
+		$task->setJob($job);
134
+		$task->setDatabase($this->getDatabase());
135
+		$task->setHttpHelper($this->getHttpHelper());
136
+		$task->setOauthProtocolHelper($this->getOAuthProtocolHelper());
137
+		$task->setEmailHelper($this->getEmailHelper());
138
+		$task->setSiteConfiguration($this->getSiteConfiguration());
139
+		$task->setNotificationHelper($this->getNotificationHelper());
140
+	}
141
+
142
+	public static function errorHandler($errno, $errstr, $errfile, $errline) {
143
+		throw new Exception($errfile . "@" . $errline . ": " . $errstr);
144
+	}
145 145
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageDeferRequest.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -20,71 +20,71 @@
 block discarded – undo
20 20
 
21 21
 class PageDeferRequest extends RequestActionBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no specific actions are called.
25
-     * @throws ApplicationLogicException
26
-     */
27
-    protected function main()
28
-    {
29
-        $this->checkPosted();
30
-        $database = $this->getDatabase();
31
-        $request = $this->getRequest($database);
32
-        $currentUser = User::getCurrent($database);
33
-
34
-        $target = WebRequest::postString('target');
35
-        $requestStates = $this->getSiteConfiguration()->getRequestStates();
36
-
37
-        if (!array_key_exists($target, $requestStates)) {
38
-            throw new ApplicationLogicException('Defer target not valid');
39
-        }
40
-
41
-        if ($request->getStatus() == $target) {
42
-            SessionAlert::warning('This request is already in the specified queue.');
43
-            $this->redirect('viewRequest', null, array('id' => $request->getId()));
44
-
45
-            return;
46
-        }
47
-
48
-        $closureDate = $request->getClosureDate();
49
-        $date = new DateTime();
50
-        $date->modify("-7 days");
51
-        $oneweek = $date->format("Y-m-d H:i:s");
52
-
53
-
54
-        if ($request->getStatus() == "Closed" && $closureDate < $oneweek) {
55
-            if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) {
56
-                throw new ApplicationLogicException(
57
-                    "You are not allowed to re-open a request that has been closed for over a week.");
58
-            }
59
-        }
60
-
61
-        if ($request->getStatus() === RequestStatus::JOBQUEUE) {
62
-            /** @var JobQueue[] $pendingJobs */
63
-            $pendingJobs = JobQueueSearchHelper::get($database)->byRequest($request->getId())->statusIn([
64
-                JobQueue::STATUS_READY,
65
-                JobQueue::STATUS_WAITING,
66
-            ])->fetch();
67
-
68
-            foreach ($pendingJobs as $job) {
69
-                $job->setStatus(JobQueue::STATUS_CANCELLED);
70
-                $job->setError('Cancelled by request deferral');
71
-                $job->save();
72
-            }
73
-        }
74
-
75
-        $request->setReserved(null);
76
-        $request->setStatus($target);
77
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
78
-        $request->save();
79
-
80
-        $deto = $requestStates[$target]['deferto'];
81
-        $detolog = $requestStates[$target]['defertolog'];
82
-
83
-        Logger::deferRequest($database, $request, $detolog);
84
-
85
-        $this->getNotificationHelper()->requestDeferred($request);
86
-        SessionAlert::success("Request {$request->getId()} deferred to {$deto}");
87
-
88
-        $this->redirect();
89
-    }
23
+	/**
24
+	 * Main function for this page, when no specific actions are called.
25
+	 * @throws ApplicationLogicException
26
+	 */
27
+	protected function main()
28
+	{
29
+		$this->checkPosted();
30
+		$database = $this->getDatabase();
31
+		$request = $this->getRequest($database);
32
+		$currentUser = User::getCurrent($database);
33
+
34
+		$target = WebRequest::postString('target');
35
+		$requestStates = $this->getSiteConfiguration()->getRequestStates();
36
+
37
+		if (!array_key_exists($target, $requestStates)) {
38
+			throw new ApplicationLogicException('Defer target not valid');
39
+		}
40
+
41
+		if ($request->getStatus() == $target) {
42
+			SessionAlert::warning('This request is already in the specified queue.');
43
+			$this->redirect('viewRequest', null, array('id' => $request->getId()));
44
+
45
+			return;
46
+		}
47
+
48
+		$closureDate = $request->getClosureDate();
49
+		$date = new DateTime();
50
+		$date->modify("-7 days");
51
+		$oneweek = $date->format("Y-m-d H:i:s");
52
+
53
+
54
+		if ($request->getStatus() == "Closed" && $closureDate < $oneweek) {
55
+			if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) {
56
+				throw new ApplicationLogicException(
57
+					"You are not allowed to re-open a request that has been closed for over a week.");
58
+			}
59
+		}
60
+
61
+		if ($request->getStatus() === RequestStatus::JOBQUEUE) {
62
+			/** @var JobQueue[] $pendingJobs */
63
+			$pendingJobs = JobQueueSearchHelper::get($database)->byRequest($request->getId())->statusIn([
64
+				JobQueue::STATUS_READY,
65
+				JobQueue::STATUS_WAITING,
66
+			])->fetch();
67
+
68
+			foreach ($pendingJobs as $job) {
69
+				$job->setStatus(JobQueue::STATUS_CANCELLED);
70
+				$job->setError('Cancelled by request deferral');
71
+				$job->save();
72
+			}
73
+		}
74
+
75
+		$request->setReserved(null);
76
+		$request->setStatus($target);
77
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
78
+		$request->save();
79
+
80
+		$deto = $requestStates[$target]['deferto'];
81
+		$detolog = $requestStates[$target]['defertolog'];
82
+
83
+		Logger::deferRequest($database, $request, $detolog);
84
+
85
+		$this->getNotificationHelper()->requestDeferred($request);
86
+		SessionAlert::success("Request {$request->getId()} deferred to {$deto}");
87
+
88
+		$this->redirect();
89
+	}
90 90
 }
Please login to merge, or discard this patch.