Failed Conditions
Push — newinternal ( 216d62...410e59 )
by Simon
05:28 queued 13s
created
includes/DataObjects/JobQueue.php 2 patches
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,8 @@
 block discarded – undo
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)',
Please login to merge, or discard this patch.
includes/DataObjects/CommunityUser.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -16,163 +16,163 @@
 block discarded – undo
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
-    #endregion
142
-
143
-    #region user access checks
144
-
145
-    public function isIdentified(IdentificationVerifier $iv)
146
-    {
147
-        return false;
148
-    }
149
-
150
-    public function isSuspended()
151
-    {
152
-        return false;
153
-    }
154
-
155
-    public function isNewUser()
156
-    {
157
-        return false;
158
-    }
159
-
160
-    public function isDeclined()
161
-    {
162
-        return false;
163
-    }
164
-
165
-    public function isCommunityUser()
166
-    {
167
-        return true;
168
-    }
169
-
170
-    #endregion
171
-
172
-    public function getApprovalDate()
173
-    {
174
-        $data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
175
-
176
-        return $data;
177
-    }
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
+	#endregion
142
+
143
+	#region user access checks
144
+
145
+	public function isIdentified(IdentificationVerifier $iv)
146
+	{
147
+		return false;
148
+	}
149
+
150
+	public function isSuspended()
151
+	{
152
+		return false;
153
+	}
154
+
155
+	public function isNewUser()
156
+	{
157
+		return false;
158
+	}
159
+
160
+	public function isDeclined()
161
+	{
162
+		return false;
163
+	}
164
+
165
+	public function isCommunityUser()
166
+	{
167
+		return true;
168
+	}
169
+
170
+	#endregion
171
+
172
+	public function getApprovalDate()
173
+	{
174
+		$data = DateTime::createFromFormat("Y-m-d H:i:s", "1970-01-01 00:00:00");
175
+
176
+		return $data;
177
+	}
178 178
 }
Please login to merge, or discard this patch.
includes/DataObjects/OAuthIdentity.php 1 patch
Indentation   +285 added lines, -285 removed lines patch added patch discarded remove patch
@@ -16,51 +16,51 @@  discard block
 block discarded – undo
16 16
 
17 17
 class OAuthIdentity extends DataObject
18 18
 {
19
-    #region Fields
20
-    /** @var int */
21
-    private $user;
22
-    /** @var string */
23
-    private $iss;
24
-    /** @var int */
25
-    private $sub;
26
-    /** @var string */
27
-    private $aud;
28
-    /** @var int */
29
-    private $exp;
30
-    /** @var int */
31
-    private $iat;
32
-    /** @var string */
33
-    private $username;
34
-    /** @var int */
35
-    private $editcount;
36
-    /** @var int */
37
-    private $confirmed_email;
38
-    /** @var int */
39
-    private $blocked;
40
-    /** @var string */
41
-    private $registered;
42
-    /** @var int */
43
-    private $checkuser;
44
-    /** @var int */
45
-    private $grantbasic;
46
-    /** @var int */
47
-    private $grantcreateaccount;
48
-    /** @var int */
49
-    private $granthighvolume;
50
-    /** @var int */
51
-    private $grantcreateeditmovepage;
52
-    #endregion
53
-
54
-    /**
55
-     * Saves a data object to the database, either updating or inserting a record.
56
-     * @return void
57
-     * @throws Exception
58
-     * @throws OptimisticLockFailedException
59
-     */
60
-    public function save()
61
-    {
62
-        if ($this->isNew()) {
63
-            $statement = $this->dbObject->prepare(<<<SQL
19
+	#region Fields
20
+	/** @var int */
21
+	private $user;
22
+	/** @var string */
23
+	private $iss;
24
+	/** @var int */
25
+	private $sub;
26
+	/** @var string */
27
+	private $aud;
28
+	/** @var int */
29
+	private $exp;
30
+	/** @var int */
31
+	private $iat;
32
+	/** @var string */
33
+	private $username;
34
+	/** @var int */
35
+	private $editcount;
36
+	/** @var int */
37
+	private $confirmed_email;
38
+	/** @var int */
39
+	private $blocked;
40
+	/** @var string */
41
+	private $registered;
42
+	/** @var int */
43
+	private $checkuser;
44
+	/** @var int */
45
+	private $grantbasic;
46
+	/** @var int */
47
+	private $grantcreateaccount;
48
+	/** @var int */
49
+	private $granthighvolume;
50
+	/** @var int */
51
+	private $grantcreateeditmovepage;
52
+	#endregion
53
+
54
+	/**
55
+	 * Saves a data object to the database, either updating or inserting a record.
56
+	 * @return void
57
+	 * @throws Exception
58
+	 * @throws OptimisticLockFailedException
59
+	 */
60
+	public function save()
61
+	{
62
+		if ($this->isNew()) {
63
+			$statement = $this->dbObject->prepare(<<<SQL
64 64
                 INSERT INTO oauthidentity (
65 65
                     user, iss, sub, aud, exp, iat, username, editcount, confirmed_email, blocked, registered, checkuser, 
66 66
                     grantbasic, grantcreateaccount, granthighvolume, grantcreateeditmovepage
@@ -69,34 +69,34 @@  discard block
 block discarded – undo
69 69
                     :checkuser, :grantbasic, :grantcreateaccount, :granthighvolume, :grantcreateeditmovepage
70 70
                 )
71 71
 SQL
72
-            );
73
-
74
-            $statement->bindValue(':user', $this->user);
75
-            $statement->bindValue(':iss', $this->iss);
76
-            $statement->bindValue(':sub', $this->sub);
77
-            $statement->bindValue(':aud', $this->aud);
78
-            $statement->bindValue(':exp', $this->exp);
79
-            $statement->bindValue(':iat', $this->iat);
80
-            $statement->bindValue(':username', $this->username);
81
-            $statement->bindValue(':editcount', $this->editcount);
82
-            $statement->bindValue(':confirmed_email', $this->confirmed_email);
83
-            $statement->bindValue(':blocked', $this->blocked);
84
-            $statement->bindValue(':registered', $this->registered);
85
-            $statement->bindValue(':checkuser', $this->checkuser);
86
-            $statement->bindValue(':grantbasic', $this->grantbasic);
87
-            $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
88
-            $statement->bindValue(':granthighvolume', $this->granthighvolume);
89
-            $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
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
-            $statement = $this->dbObject->prepare(<<<SQL
72
+			);
73
+
74
+			$statement->bindValue(':user', $this->user);
75
+			$statement->bindValue(':iss', $this->iss);
76
+			$statement->bindValue(':sub', $this->sub);
77
+			$statement->bindValue(':aud', $this->aud);
78
+			$statement->bindValue(':exp', $this->exp);
79
+			$statement->bindValue(':iat', $this->iat);
80
+			$statement->bindValue(':username', $this->username);
81
+			$statement->bindValue(':editcount', $this->editcount);
82
+			$statement->bindValue(':confirmed_email', $this->confirmed_email);
83
+			$statement->bindValue(':blocked', $this->blocked);
84
+			$statement->bindValue(':registered', $this->registered);
85
+			$statement->bindValue(':checkuser', $this->checkuser);
86
+			$statement->bindValue(':grantbasic', $this->grantbasic);
87
+			$statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
88
+			$statement->bindValue(':granthighvolume', $this->granthighvolume);
89
+			$statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
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
+			$statement = $this->dbObject->prepare(<<<SQL
100 100
                 UPDATE oauthidentity SET
101 101
                       iss                     = :iss
102 102
                     , sub                     = :sub
@@ -116,211 +116,211 @@  discard block
 block discarded – undo
116 116
                     , updateversion           = updateversion + 1
117 117
                 WHERE  id = :id AND updateversion = :updateversion
118 118
 SQL
119
-            );
120
-
121
-            $statement->bindValue(':iss', $this->iss);
122
-            $statement->bindValue(':sub', $this->sub);
123
-            $statement->bindValue(':aud', $this->aud);
124
-            $statement->bindValue(':exp', $this->exp);
125
-            $statement->bindValue(':iat', $this->iat);
126
-            $statement->bindValue(':username', $this->username);
127
-            $statement->bindValue(':editcount', $this->editcount);
128
-            $statement->bindValue(':confirmed_email', $this->confirmed_email);
129
-            $statement->bindValue(':blocked', $this->blocked);
130
-            $statement->bindValue(':registered', $this->registered);
131
-            $statement->bindValue(':checkuser', $this->checkuser);
132
-            $statement->bindValue(':grantbasic', $this->grantbasic);
133
-            $statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
134
-            $statement->bindValue(':granthighvolume', $this->granthighvolume);
135
-            $statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
136
-
137
-            $statement->bindValue(':id', $this->id);
138
-            $statement->bindValue(':updateversion', $this->updateversion);
139
-
140
-            if (!$statement->execute()) {
141
-                throw new Exception($statement->errorInfo());
142
-            }
143
-
144
-            if ($statement->rowCount() !== 1) {
145
-                throw new OptimisticLockFailedException();
146
-            }
147
-
148
-            $this->updateversion++;
149
-        }
150
-    }
151
-
152
-    #region Properties
153
-
154
-    /**
155
-     * @return int
156
-     */
157
-    public function getUserId()
158
-    {
159
-        return $this->user;
160
-    }
161
-
162
-    /**
163
-     * @param int $user
164
-     */
165
-    public function setUserId($user)
166
-    {
167
-        $this->user = $user;
168
-    }
169
-
170
-    /**
171
-     * @return string
172
-     */
173
-    public function getIssuer()
174
-    {
175
-        return $this->iss;
176
-    }
177
-
178
-    /**
179
-     * @return int
180
-     */
181
-    public function getSubject()
182
-    {
183
-        return $this->sub;
184
-    }
185
-
186
-    /**
187
-     * @return string
188
-     */
189
-    public function getAudience()
190
-    {
191
-        return $this->aud;
192
-    }
193
-
194
-    /**
195
-     * @return int
196
-     */
197
-    public function getExpirationTime()
198
-    {
199
-        return $this->exp;
200
-    }
201
-
202
-    /**
203
-     * @return int
204
-     */
205
-    public function getIssuedAtTime()
206
-    {
207
-        return $this->iat;
208
-    }
209
-
210
-    /**
211
-     * @return string
212
-     */
213
-    public function getUsername()
214
-    {
215
-        return $this->username;
216
-    }
217
-
218
-    /**
219
-     * @return int
220
-     */
221
-    public function getEditCount()
222
-    {
223
-        return $this->editcount;
224
-    }
225
-
226
-    /**
227
-     * @return bool
228
-     */
229
-    public function getConfirmedEmail()
230
-    {
231
-        return $this->confirmed_email == 1;
232
-    }
233
-
234
-    /**
235
-     * @return bool
236
-     */
237
-    public function getBlocked()
238
-    {
239
-        return $this->blocked == 1;
240
-    }
241
-
242
-    /**
243
-     * @return string
244
-     */
245
-    public function getRegistered()
246
-    {
247
-        return $this->registered;
248
-    }
249
-
250
-    public function getRegistrationDate()
251
-    {
252
-        return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r');
253
-    }
254
-
255
-    public function getAccountAge()
256
-    {
257
-        $regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered);
258
-        $interval = $regDate->diff(new DateTimeImmutable(), true);
259
-
260
-        return $interval->days;
261
-    }
262
-
263
-    /**
264
-     * @return bool
265
-     */
266
-    public function getCheckuser()
267
-    {
268
-        return $this->checkuser == 1;
269
-    }
270
-
271
-    /**
272
-     * @return bool
273
-     */
274
-    public function getGrantBasic()
275
-    {
276
-        return $this->grantbasic == 1;
277
-    }
278
-
279
-    /**
280
-     * @return bool
281
-     */
282
-    public function getGrantCreateAccount()
283
-    {
284
-        return $this->grantcreateaccount == 1;
285
-    }
286
-
287
-    /**
288
-     * @return bool
289
-     */
290
-    public function getGrantHighVolume()
291
-    {
292
-        return $this->granthighvolume == 1;
293
-    }
294
-
295
-    /**
296
-     * @return bool
297
-     */
298
-    public function getGrantCreateEditMovePage()
299
-    {
300
-        return $this->grantcreateeditmovepage == 1;
301
-    }
302
-
303
-    #endregion Properties
304
-
305
-    /**
306
-     * Populates the fields of this instance from a provided JSON Web Token
307
-     *
308
-     * @param stdClass $jwt
309
-     */
310
-    public function populate($jwt)
311
-    {
312
-        $this->iss = $jwt->iss;
313
-        $this->sub = $jwt->sub;
314
-        $this->aud = $jwt->aud;
315
-        $this->exp = $jwt->exp;
316
-        $this->iat = $jwt->iat;
317
-        $this->username = $jwt->username;
318
-        $this->editcount = $jwt->editcount;
319
-        $this->confirmed_email = $jwt->confirmed_email ? 1 : 0;
320
-        $this->blocked = $jwt->blocked ? 1 : 0;
321
-        $this->registered = $jwt->registered;
322
-
323
-        /*
119
+			);
120
+
121
+			$statement->bindValue(':iss', $this->iss);
122
+			$statement->bindValue(':sub', $this->sub);
123
+			$statement->bindValue(':aud', $this->aud);
124
+			$statement->bindValue(':exp', $this->exp);
125
+			$statement->bindValue(':iat', $this->iat);
126
+			$statement->bindValue(':username', $this->username);
127
+			$statement->bindValue(':editcount', $this->editcount);
128
+			$statement->bindValue(':confirmed_email', $this->confirmed_email);
129
+			$statement->bindValue(':blocked', $this->blocked);
130
+			$statement->bindValue(':registered', $this->registered);
131
+			$statement->bindValue(':checkuser', $this->checkuser);
132
+			$statement->bindValue(':grantbasic', $this->grantbasic);
133
+			$statement->bindValue(':grantcreateaccount', $this->grantcreateaccount);
134
+			$statement->bindValue(':granthighvolume', $this->granthighvolume);
135
+			$statement->bindValue(':grantcreateeditmovepage', $this->grantcreateeditmovepage);
136
+
137
+			$statement->bindValue(':id', $this->id);
138
+			$statement->bindValue(':updateversion', $this->updateversion);
139
+
140
+			if (!$statement->execute()) {
141
+				throw new Exception($statement->errorInfo());
142
+			}
143
+
144
+			if ($statement->rowCount() !== 1) {
145
+				throw new OptimisticLockFailedException();
146
+			}
147
+
148
+			$this->updateversion++;
149
+		}
150
+	}
151
+
152
+	#region Properties
153
+
154
+	/**
155
+	 * @return int
156
+	 */
157
+	public function getUserId()
158
+	{
159
+		return $this->user;
160
+	}
161
+
162
+	/**
163
+	 * @param int $user
164
+	 */
165
+	public function setUserId($user)
166
+	{
167
+		$this->user = $user;
168
+	}
169
+
170
+	/**
171
+	 * @return string
172
+	 */
173
+	public function getIssuer()
174
+	{
175
+		return $this->iss;
176
+	}
177
+
178
+	/**
179
+	 * @return int
180
+	 */
181
+	public function getSubject()
182
+	{
183
+		return $this->sub;
184
+	}
185
+
186
+	/**
187
+	 * @return string
188
+	 */
189
+	public function getAudience()
190
+	{
191
+		return $this->aud;
192
+	}
193
+
194
+	/**
195
+	 * @return int
196
+	 */
197
+	public function getExpirationTime()
198
+	{
199
+		return $this->exp;
200
+	}
201
+
202
+	/**
203
+	 * @return int
204
+	 */
205
+	public function getIssuedAtTime()
206
+	{
207
+		return $this->iat;
208
+	}
209
+
210
+	/**
211
+	 * @return string
212
+	 */
213
+	public function getUsername()
214
+	{
215
+		return $this->username;
216
+	}
217
+
218
+	/**
219
+	 * @return int
220
+	 */
221
+	public function getEditCount()
222
+	{
223
+		return $this->editcount;
224
+	}
225
+
226
+	/**
227
+	 * @return bool
228
+	 */
229
+	public function getConfirmedEmail()
230
+	{
231
+		return $this->confirmed_email == 1;
232
+	}
233
+
234
+	/**
235
+	 * @return bool
236
+	 */
237
+	public function getBlocked()
238
+	{
239
+		return $this->blocked == 1;
240
+	}
241
+
242
+	/**
243
+	 * @return string
244
+	 */
245
+	public function getRegistered()
246
+	{
247
+		return $this->registered;
248
+	}
249
+
250
+	public function getRegistrationDate()
251
+	{
252
+		return DateTimeImmutable::createFromFormat('YmdHis', $this->registered)->format('r');
253
+	}
254
+
255
+	public function getAccountAge()
256
+	{
257
+		$regDate = DateTimeImmutable::createFromFormat('YmdHis', $this->registered);
258
+		$interval = $regDate->diff(new DateTimeImmutable(), true);
259
+
260
+		return $interval->days;
261
+	}
262
+
263
+	/**
264
+	 * @return bool
265
+	 */
266
+	public function getCheckuser()
267
+	{
268
+		return $this->checkuser == 1;
269
+	}
270
+
271
+	/**
272
+	 * @return bool
273
+	 */
274
+	public function getGrantBasic()
275
+	{
276
+		return $this->grantbasic == 1;
277
+	}
278
+
279
+	/**
280
+	 * @return bool
281
+	 */
282
+	public function getGrantCreateAccount()
283
+	{
284
+		return $this->grantcreateaccount == 1;
285
+	}
286
+
287
+	/**
288
+	 * @return bool
289
+	 */
290
+	public function getGrantHighVolume()
291
+	{
292
+		return $this->granthighvolume == 1;
293
+	}
294
+
295
+	/**
296
+	 * @return bool
297
+	 */
298
+	public function getGrantCreateEditMovePage()
299
+	{
300
+		return $this->grantcreateeditmovepage == 1;
301
+	}
302
+
303
+	#endregion Properties
304
+
305
+	/**
306
+	 * Populates the fields of this instance from a provided JSON Web Token
307
+	 *
308
+	 * @param stdClass $jwt
309
+	 */
310
+	public function populate($jwt)
311
+	{
312
+		$this->iss = $jwt->iss;
313
+		$this->sub = $jwt->sub;
314
+		$this->aud = $jwt->aud;
315
+		$this->exp = $jwt->exp;
316
+		$this->iat = $jwt->iat;
317
+		$this->username = $jwt->username;
318
+		$this->editcount = $jwt->editcount;
319
+		$this->confirmed_email = $jwt->confirmed_email ? 1 : 0;
320
+		$this->blocked = $jwt->blocked ? 1 : 0;
321
+		$this->registered = $jwt->registered;
322
+
323
+		/*
324 324
          * Rights we need:
325 325
          *  Account creation
326 326
          *      createaccount      => createaccount
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
          * Any antispoof conflicts will still have to be resolved manually using the normal creation form.
343 343
          */
344 344
 
345
-        $this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0;
346
-        $this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0;
347
-        $this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0;
345
+		$this->grantbasic = in_array('basic', $jwt->grants) ? 1 : 0;
346
+		$this->grantcreateaccount = in_array('createaccount', $jwt->grants) ? 1 : 0;
347
+		$this->grantcreateeditmovepage = in_array('createeditmovepage', $jwt->grants) ? 1 : 0;
348 348
 
349
-        // we don't request these yet.
350
-        $this->granthighvolume = 0;
349
+		// we don't request these yet.
350
+		$this->granthighvolume = 0;
351 351
 
352
-        $this->checkuser = in_array('checkuser', $jwt->rights) ? 1 : 0;
353
-    }
352
+		$this->checkuser = in_array('checkuser', $jwt->rights) ? 1 : 0;
353
+	}
354 354
 }
355 355
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ApplicationBase.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -25,155 +25,155 @@
 block discarded – undo
25 25
 
26 26
 abstract class ApplicationBase
27 27
 {
28
-    private $configuration;
29
-
30
-    public function __construct(SiteConfiguration $configuration)
31
-    {
32
-        $this->configuration = $configuration;
33
-    }
34
-
35
-    /**
36
-     * Application entry point.
37
-     *
38
-     * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
-     */
40
-    public function run()
41
-    {
42
-        try {
43
-            if ($this->setupEnvironment()) {
44
-                $this->main();
45
-            }
46
-        }
47
-        catch (Exception $ex) {
48
-            print $ex->getMessage();
49
-        }
50
-        finally {
51
-            $this->cleanupEnvironment();
52
-        }
53
-    }
54
-
55
-    /**
56
-     * Environment setup
57
-     *
58
-     * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
-     * and shut down prematurely.
60
-     *
61
-     * @return bool
62
-     * @throws EnvironmentException
63
-     */
64
-    protected function setupEnvironment()
65
-    {
66
-        $this->setupDatabase();
67
-
68
-        return true;
69
-    }
70
-
71
-    /**
72
-     * @return PdoDatabase
73
-     * @throws EnvironmentException
74
-     * @throws Exception
75
-     */
76
-    protected function setupDatabase()
77
-    {
78
-        // check the schema version
79
-        $database = PdoDatabase::getDatabaseConnection('acc');
80
-
81
-        /** @var int $actualVersion */
82
-        $actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
-        if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
-            throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
-        }
86
-
87
-        return $database;
88
-    }
89
-
90
-    /**
91
-     * @return SiteConfiguration
92
-     */
93
-    public function getConfiguration()
94
-    {
95
-        return $this->configuration;
96
-    }
97
-
98
-    /**
99
-     * Main application logic
100
-     * @return void
101
-     */
102
-    abstract protected function main();
103
-
104
-    /**
105
-     * Any cleanup tasks should go here
106
-     *
107
-     * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
-     * This should *only* be for cleaning up, no logic should go here.
109
-     *
110
-     * @return void
111
-     */
112
-    abstract protected function cleanupEnvironment();
113
-
114
-    /**
115
-     * @param ITask             $page
116
-     * @param SiteConfiguration $siteConfiguration
117
-     * @param PdoDatabase       $database
118
-     * @param PdoDatabase       $notificationsDatabase
119
-     *
120
-     * @return void
121
-     */
122
-    protected function setupHelpers(
123
-        ITask $page,
124
-        SiteConfiguration $siteConfiguration,
125
-        PdoDatabase $database,
126
-        PdoDatabase $notificationsDatabase = null
127
-    ) {
128
-        $page->setSiteConfiguration($siteConfiguration);
129
-
130
-        // setup the global database object
131
-        $page->setDatabase($database);
132
-
133
-        // set up helpers and inject them into the page.
134
-        $httpHelper = new HttpHelper(
135
-            $siteConfiguration->getUserAgent(),
136
-            $siteConfiguration->getCurlDisableVerifyPeer()
137
-        );
138
-
139
-        $page->setEmailHelper(new EmailHelper());
140
-        $page->setHttpHelper($httpHelper);
141
-        $page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
-
143
-        if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
-            $page->setLocationProvider(new FakeLocationProvider());
145
-        }
146
-        else {
147
-            $page->setLocationProvider(
148
-                new IpLocationProvider(
149
-                    $database,
150
-                    $siteConfiguration->getLocationProviderApiKey(),
151
-                    $httpHelper
152
-                ));
153
-        }
154
-
155
-        $page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
-
157
-        $page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
-
159
-        $page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
-            $database,
161
-            $this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
-            $httpHelper));
163
-
164
-        $page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
-            $siteConfiguration->getOAuthBaseUrl(),
166
-            $siteConfiguration->getOAuthConsumerToken(),
167
-            $siteConfiguration->getOAuthConsumerSecret(),
168
-            $httpHelper,
169
-            $siteConfiguration->getMediawikiWebServiceEndpoint()
170
-        ));
171
-
172
-        $page->setNotificationHelper(new IrcNotificationHelper(
173
-            $siteConfiguration,
174
-            $database,
175
-            $notificationsDatabase));
176
-
177
-        $page->setTorExitProvider(new TorExitProvider($database));
178
-    }
28
+	private $configuration;
29
+
30
+	public function __construct(SiteConfiguration $configuration)
31
+	{
32
+		$this->configuration = $configuration;
33
+	}
34
+
35
+	/**
36
+	 * Application entry point.
37
+	 *
38
+	 * Sets up the environment and runs the application, performing any global cleanup operations when done.
39
+	 */
40
+	public function run()
41
+	{
42
+		try {
43
+			if ($this->setupEnvironment()) {
44
+				$this->main();
45
+			}
46
+		}
47
+		catch (Exception $ex) {
48
+			print $ex->getMessage();
49
+		}
50
+		finally {
51
+			$this->cleanupEnvironment();
52
+		}
53
+	}
54
+
55
+	/**
56
+	 * Environment setup
57
+	 *
58
+	 * This method initialises the tool environment. If the tool cannot be initialised correctly, it will return false
59
+	 * and shut down prematurely.
60
+	 *
61
+	 * @return bool
62
+	 * @throws EnvironmentException
63
+	 */
64
+	protected function setupEnvironment()
65
+	{
66
+		$this->setupDatabase();
67
+
68
+		return true;
69
+	}
70
+
71
+	/**
72
+	 * @return PdoDatabase
73
+	 * @throws EnvironmentException
74
+	 * @throws Exception
75
+	 */
76
+	protected function setupDatabase()
77
+	{
78
+		// check the schema version
79
+		$database = PdoDatabase::getDatabaseConnection('acc');
80
+
81
+		/** @var int $actualVersion */
82
+		$actualVersion = (int)$database->query('SELECT version FROM schemaversion')->fetchColumn();
83
+		if ($actualVersion !== $this->getConfiguration()->getSchemaVersion()) {
84
+			throw new EnvironmentException('Database schema is wrong version! Please either update configuration or database.');
85
+		}
86
+
87
+		return $database;
88
+	}
89
+
90
+	/**
91
+	 * @return SiteConfiguration
92
+	 */
93
+	public function getConfiguration()
94
+	{
95
+		return $this->configuration;
96
+	}
97
+
98
+	/**
99
+	 * Main application logic
100
+	 * @return void
101
+	 */
102
+	abstract protected function main();
103
+
104
+	/**
105
+	 * Any cleanup tasks should go here
106
+	 *
107
+	 * Note that we need to be very careful here, as exceptions may have been thrown and handled.
108
+	 * This should *only* be for cleaning up, no logic should go here.
109
+	 *
110
+	 * @return void
111
+	 */
112
+	abstract protected function cleanupEnvironment();
113
+
114
+	/**
115
+	 * @param ITask             $page
116
+	 * @param SiteConfiguration $siteConfiguration
117
+	 * @param PdoDatabase       $database
118
+	 * @param PdoDatabase       $notificationsDatabase
119
+	 *
120
+	 * @return void
121
+	 */
122
+	protected function setupHelpers(
123
+		ITask $page,
124
+		SiteConfiguration $siteConfiguration,
125
+		PdoDatabase $database,
126
+		PdoDatabase $notificationsDatabase = null
127
+	) {
128
+		$page->setSiteConfiguration($siteConfiguration);
129
+
130
+		// setup the global database object
131
+		$page->setDatabase($database);
132
+
133
+		// set up helpers and inject them into the page.
134
+		$httpHelper = new HttpHelper(
135
+			$siteConfiguration->getUserAgent(),
136
+			$siteConfiguration->getCurlDisableVerifyPeer()
137
+		);
138
+
139
+		$page->setEmailHelper(new EmailHelper());
140
+		$page->setHttpHelper($httpHelper);
141
+		$page->setWikiTextHelper(new WikiTextHelper($siteConfiguration, $page->getHttpHelper()));
142
+
143
+		if ($siteConfiguration->getLocationProviderApiKey() === null) {
144
+			$page->setLocationProvider(new FakeLocationProvider());
145
+		}
146
+		else {
147
+			$page->setLocationProvider(
148
+				new IpLocationProvider(
149
+					$database,
150
+					$siteConfiguration->getLocationProviderApiKey(),
151
+					$httpHelper
152
+				));
153
+		}
154
+
155
+		$page->setXffTrustProvider(new XffTrustProvider($siteConfiguration->getSquidList(), $database));
156
+
157
+		$page->setRdnsProvider(new CachedRDnsLookupProvider($database));
158
+
159
+		$page->setAntiSpoofProvider(new CachedApiAntispoofProvider(
160
+			$database,
161
+			$this->getConfiguration()->getMediawikiWebServiceEndpoint(),
162
+			$httpHelper));
163
+
164
+		$page->setOAuthProtocolHelper(new OAuthProtocolHelper(
165
+			$siteConfiguration->getOAuthBaseUrl(),
166
+			$siteConfiguration->getOAuthConsumerToken(),
167
+			$siteConfiguration->getOAuthConsumerSecret(),
168
+			$httpHelper,
169
+			$siteConfiguration->getMediawikiWebServiceEndpoint()
170
+		));
171
+
172
+		$page->setNotificationHelper(new IrcNotificationHelper(
173
+			$siteConfiguration,
174
+			$database,
175
+			$notificationsDatabase));
176
+
177
+		$page->setTorExitProvider(new TorExitProvider($database));
178
+	}
179 179
 }
180 180
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleStart.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -15,74 +15,74 @@
 block discarded – undo
15 15
 
16 16
 class ConsoleStart extends ApplicationBase
17 17
 {
18
-    /**
19
-     * @var ConsoleTaskBase
20
-     */
21
-    private $consoleTask;
18
+	/**
19
+	 * @var ConsoleTaskBase
20
+	 */
21
+	private $consoleTask;
22 22
 
23
-    /**
24
-     * ConsoleStart constructor.
25
-     *
26
-     * @param SiteConfiguration $configuration
27
-     * @param ConsoleTaskBase   $consoleTask
28
-     */
29
-    public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
-    {
31
-        parent::__construct($configuration);
32
-        $this->consoleTask = $consoleTask;
33
-    }
23
+	/**
24
+	 * ConsoleStart constructor.
25
+	 *
26
+	 * @param SiteConfiguration $configuration
27
+	 * @param ConsoleTaskBase   $consoleTask
28
+	 */
29
+	public function __construct(SiteConfiguration $configuration, ConsoleTaskBase $consoleTask)
30
+	{
31
+		parent::__construct($configuration);
32
+		$this->consoleTask = $consoleTask;
33
+	}
34 34
 
35
-    protected function setupEnvironment()
36
-    {
37
-        // initialise super-global providers
38
-        WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
35
+	protected function setupEnvironment()
36
+	{
37
+		// initialise super-global providers
38
+		WebRequest::setGlobalStateProvider(new FakeGlobalStateProvider());
39 39
 
40
-        if (WebRequest::method() !== null) {
41
-            throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
-        }
40
+		if (WebRequest::method() !== null) {
41
+			throw new EnvironmentException('This is a console task, which cannot be executed via the web.');
42
+		}
43 43
 
44
-        return parent::setupEnvironment();
45
-    }
44
+		return parent::setupEnvironment();
45
+	}
46 46
 
47
-    protected function cleanupEnvironment()
48
-    {
49
-    }
47
+	protected function cleanupEnvironment()
48
+	{
49
+	}
50 50
 
51
-    /**
52
-     * Main application logic
53
-     */
54
-    protected function main()
55
-    {
56
-        $database = PdoDatabase::getDatabaseConnection('acc');
51
+	/**
52
+	 * Main application logic
53
+	 */
54
+	protected function main()
55
+	{
56
+		$database = PdoDatabase::getDatabaseConnection('acc');
57 57
 
58
-        if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
-            $notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
-        }
61
-        else {
62
-            // pass through null
63
-            $notificationsDatabase = null;
64
-        }
58
+		if ($this->getConfiguration()->getIrcNotificationsEnabled()) {
59
+			$notificationsDatabase = PdoDatabase::getDatabaseConnection('notifications');
60
+		}
61
+		else {
62
+			// pass through null
63
+			$notificationsDatabase = null;
64
+		}
65 65
 
66
-        $this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
66
+		$this->setupHelpers($this->consoleTask, $this->getConfiguration(), $database, $notificationsDatabase);
67 67
 
68
-        // initialise a database transaction
69
-        if (!$database->beginTransaction()) {
70
-            throw new Exception('Failed to start transaction on primary database.');
71
-        }
68
+		// initialise a database transaction
69
+		if (!$database->beginTransaction()) {
70
+			throw new Exception('Failed to start transaction on primary database.');
71
+		}
72 72
 
73
-        try {
74
-            // run the task
75
-            $this->consoleTask->execute();
73
+		try {
74
+			// run the task
75
+			$this->consoleTask->execute();
76 76
 
77
-            if ($database->hasActiveTransaction()) {
78
-                $database->commit();
79
-            }
80
-        }
81
-        finally {
82
-            // Catch any hanging on transactions
83
-            if ($database->hasActiveTransaction()) {
84
-                $database->rollBack();
85
-            }
86
-        }
87
-    }
77
+			if ($database->hasActiveTransaction()) {
78
+				$database->commit();
79
+			}
80
+		}
81
+		finally {
82
+			// Catch any hanging on transactions
83
+			if ($database->hasActiveTransaction()) {
84
+				$database->rollBack();
85
+			}
86
+		}
87
+	}
88 88
 }
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/RefreshOAuthDataTask.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -17,35 +17,35 @@
 block discarded – undo
17 17
 
18 18
 class RefreshOAuthDataTask extends ConsoleTaskBase
19 19
 {
20
-    public function execute()
21
-    {
22
-        $database = $this->getDatabase();
23
-
24
-        $idList = $database
25
-            ->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL')
26
-            ->fetchAll(PDO::FETCH_COLUMN);
27
-
28
-        if (count($idList) > 0) {
29
-            /** @var User[] $users */
30
-            $users = UserSearchHelper::get($database)->inIds($idList)->fetch();
31
-
32
-            $expiredStatement = $database
33
-                ->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\'');
34
-
35
-            foreach ($users as $u) {
36
-                $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(),
37
-                    $this->getSiteConfiguration());
38
-
39
-                try {
40
-                    $oauth->refreshIdentity();
41
-                }
42
-                catch (OAuthException $ex) {
43
-                    $expiredStatement->execute(array(':u' => $u->getId()));
44
-                }
45
-            }
46
-        }
47
-
48
-        $this->getDatabase()
49
-            ->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\'');
50
-    }
20
+	public function execute()
21
+	{
22
+		$database = $this->getDatabase();
23
+
24
+		$idList = $database
25
+			->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL')
26
+			->fetchAll(PDO::FETCH_COLUMN);
27
+
28
+		if (count($idList) > 0) {
29
+			/** @var User[] $users */
30
+			$users = UserSearchHelper::get($database)->inIds($idList)->fetch();
31
+
32
+			$expiredStatement = $database
33
+				->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\'');
34
+
35
+			foreach ($users as $u) {
36
+				$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(),
37
+					$this->getSiteConfiguration());
38
+
39
+				try {
40
+					$oauth->refreshIdentity();
41
+				}
42
+				catch (OAuthException $ex) {
43
+					$expiredStatement->execute(array(':u' => $u->getId()));
44
+				}
45
+			}
46
+		}
47
+
48
+		$this->getDatabase()
49
+			->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\'');
50
+	}
51 51
 }
52 52
\ No newline at end of file
Please login to merge, or discard this patch.
includes/ConsoleTasks/ClearOAuthDataTask.php 3 patches
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 
15 15
 class ClearOAuthDataTask extends ConsoleTaskBase
16 16
 {
17
-    public function execute()
18
-    {
19
-        $database = $this->getDatabase();
17
+	public function execute()
18
+	{
19
+		$database = $this->getDatabase();
20 20
 
21
-        $users = UserSearchHelper::get($database)->inIds(
22
-            $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
21
+		$users = UserSearchHelper::get($database)->inIds(
22
+			$database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
25
-            $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26
-            $oauth->detach();
27
-        }
24
+		foreach ($users as $u){
25
+			$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26
+			$oauth->detach();
27
+		}
28 28
 
29
-        $database->exec('DELETE FROM oauthtoken');
30
-        $database->exec('DELETE FROM oauthidentity');
31
-    }
29
+		$database->exec('DELETE FROM oauthtoken');
30
+		$database->exec('DELETE FROM oauthidentity');
31
+	}
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $users = UserSearchHelper::get($database)->inIds(
22 22
             $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
24
+        foreach ($users as $u) {
25 25
             $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26 26
             $oauth->detach();
27 27
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
         $users = UserSearchHelper::get($database)->inIds(
22 22
             $database->query('SELECT user FROM oauthtoken WHERE type = \'access\'')->fetchColumn());
23 23
 
24
-        foreach ($users as $u){
24
+        foreach ($users as $u) {
25 25
             $oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
26 26
             $oauth->detach();
27 27
         }
Please login to merge, or discard this patch.
includes/ConsoleTasks/RunJobQueueTask.php 3 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -22,111 +22,111 @@
 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
-                $database->beginTransaction();
63
-
64
-                // re-lock the job
65
-                $job->setStatus(JobQueue::STATUS_RUNNING);
66
-                $job->save();
67
-
68
-                // validate we're allowed to run the requested task (whitelist)
69
-                if (!in_array($job->getTask(), $this->taskList)) {
70
-                    throw new ApplicationLogicException('Job task not registered');
71
-                }
72
-
73
-                // Create a task.
74
-                $taskName = $job->getTask();
75
-
76
-                if(!class_exists($taskName)) {
77
-                    throw new ApplicationLogicException('Job task does not exist');
78
-                }
79
-
80
-                /** @var BackgroundTaskBase $task */
81
-                $task = new $taskName;
82
-
83
-                $this->setupTask($task, $job);
84
-                $task->run();
85
-            }
86
-            catch (Exception $ex) {
87
-                $database->rollBack();
88
-                $database->beginTransaction();
89
-
90
-                /** @var JobQueue $job */
91
-                $job = JobQueue::getById($job->getId(), $database);
92
-                $job->setDatabase($database);
93
-                $job->setStatus(JobQueue::STATUS_FAILED);
94
-                $job->setError($ex->getMessage());
95
-                $job->setAcknowledged(0);
96
-                $job->save();
97
-
98
-                /** @var Request $request */
99
-                $request = Request::getById($job->getRequest(), $database);
100
-                if ($request === false) {
101
-                    $request = null;
102
-                }
103
-
104
-                Logger::backgroundJobIssue($this->getDatabase(), $job);
105
-
106
-                $database->commit();
107
-            }
108
-            finally {
109
-                $database->commit();
110
-            }
111
-        }
112
-    }
113
-
114
-    /**
115
-     * @param BackgroundTaskBase $task
116
-     * @param JobQueue           $job
117
-     */
118
-    private function setupTask(BackgroundTaskBase $task, JobQueue $job)
119
-    {
120
-        $task->setJob($job);
121
-        $task->setDatabase($this->getDatabase());
122
-        $task->setHttpHelper($this->getHttpHelper());
123
-        $task->setOauthProtocolHelper($this->getOAuthProtocolHelper());
124
-        $task->setEmailHelper($this->getEmailHelper());
125
-        $task->setSiteConfiguration($this->getSiteConfiguration());
126
-        $task->setNotificationHelper($this->getNotificationHelper());
127
-    }
128
-
129
-    public static function errorHandler($errno, $errstr, $errfile, $errline) {
130
-        throw new Exception($errfile . "@" . $errline . ": " . $errstr);
131
-    }
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
+				$database->beginTransaction();
63
+
64
+				// re-lock the job
65
+				$job->setStatus(JobQueue::STATUS_RUNNING);
66
+				$job->save();
67
+
68
+				// validate we're allowed to run the requested task (whitelist)
69
+				if (!in_array($job->getTask(), $this->taskList)) {
70
+					throw new ApplicationLogicException('Job task not registered');
71
+				}
72
+
73
+				// Create a task.
74
+				$taskName = $job->getTask();
75
+
76
+				if(!class_exists($taskName)) {
77
+					throw new ApplicationLogicException('Job task does not exist');
78
+				}
79
+
80
+				/** @var BackgroundTaskBase $task */
81
+				$task = new $taskName;
82
+
83
+				$this->setupTask($task, $job);
84
+				$task->run();
85
+			}
86
+			catch (Exception $ex) {
87
+				$database->rollBack();
88
+				$database->beginTransaction();
89
+
90
+				/** @var JobQueue $job */
91
+				$job = JobQueue::getById($job->getId(), $database);
92
+				$job->setDatabase($database);
93
+				$job->setStatus(JobQueue::STATUS_FAILED);
94
+				$job->setError($ex->getMessage());
95
+				$job->setAcknowledged(0);
96
+				$job->save();
97
+
98
+				/** @var Request $request */
99
+				$request = Request::getById($job->getRequest(), $database);
100
+				if ($request === false) {
101
+					$request = null;
102
+				}
103
+
104
+				Logger::backgroundJobIssue($this->getDatabase(), $job);
105
+
106
+				$database->commit();
107
+			}
108
+			finally {
109
+				$database->commit();
110
+			}
111
+		}
112
+	}
113
+
114
+	/**
115
+	 * @param BackgroundTaskBase $task
116
+	 * @param JobQueue           $job
117
+	 */
118
+	private function setupTask(BackgroundTaskBase $task, JobQueue $job)
119
+	{
120
+		$task->setJob($job);
121
+		$task->setDatabase($this->getDatabase());
122
+		$task->setHttpHelper($this->getHttpHelper());
123
+		$task->setOauthProtocolHelper($this->getOAuthProtocolHelper());
124
+		$task->setEmailHelper($this->getEmailHelper());
125
+		$task->setSiteConfiguration($this->getSiteConfiguration());
126
+		$task->setNotificationHelper($this->getNotificationHelper());
127
+	}
128
+
129
+	public static function errorHandler($errno, $errstr, $errfile, $errline) {
130
+		throw new Exception($errfile . "@" . $errline . ": " . $errstr);
131
+	}
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
                 // Create a task.
74 74
                 $taskName = $job->getTask();
75 75
 
76
-                if(!class_exists($taskName)) {
76
+                if (!class_exists($taskName)) {
77 77
                     throw new ApplicationLogicException('Job task does not exist');
78 78
                 }
79 79
 
@@ -127,6 +127,6 @@  discard block
 block discarded – undo
127 127
     }
128 128
 
129 129
     public static function errorHandler($errno, $errstr, $errfile, $errline) {
130
-        throw new Exception($errfile . "@" . $errline . ": " . $errstr);
130
+        throw new Exception($errfile."@".$errline.": ".$errstr);
131 131
     }
132 132
 }
133 133
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -126,7 +126,8 @@
 block discarded – undo
126 126
         $task->setNotificationHelper($this->getNotificationHelper());
127 127
     }
128 128
 
129
-    public static function errorHandler($errno, $errstr, $errfile, $errline) {
129
+    public static function errorHandler($errno, $errstr, $errfile, $errline)
130
+    {
130 131
         throw new Exception($errfile . "@" . $errline . ": " . $errstr);
131 132
     }
132 133
 }
133 134
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/PageJobQueue.php 2 patches
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -26,239 +26,239 @@
 block discarded – undo
26 26
 
27 27
 class PageJobQueue extends PagedInternalPageBase
28 28
 {
29
-    /**
30
-     * Main function for this page, when no specific actions are called.
31
-     * @return void
32
-     */
33
-    protected function main()
34
-    {
35
-        $this->setHtmlTitle('Job Queue Management');
29
+	/**
30
+	 * Main function for this page, when no specific actions are called.
31
+	 * @return void
32
+	 */
33
+	protected function main()
34
+	{
35
+		$this->setHtmlTitle('Job Queue Management');
36 36
 
37
-        $this->prepareMaps();
37
+		$this->prepareMaps();
38 38
 
39
-        $database = $this->getDatabase();
39
+		$database = $this->getDatabase();
40 40
 
41
-        /** @var JobQueue[] $jobList */
42
-        $jobList = JobQueueSearchHelper::get($database)
43
-            ->statusIn(array('ready', 'waiting', 'running', 'failed'))
44
-            ->notAcknowledged()
45
-            ->fetch();
41
+		/** @var JobQueue[] $jobList */
42
+		$jobList = JobQueueSearchHelper::get($database)
43
+			->statusIn(array('ready', 'waiting', 'running', 'failed'))
44
+			->notAcknowledged()
45
+			->fetch();
46 46
 
47
-        $userIds = array();
48
-        $requestIds = array();
47
+		$userIds = array();
48
+		$requestIds = array();
49 49
 
50
-        foreach ($jobList as $job) {
51
-            $userIds[] = $job->getTriggerUserId();
52
-            $requestIds[] = $job->getRequest();
50
+		foreach ($jobList as $job) {
51
+			$userIds[] = $job->getTriggerUserId();
52
+			$requestIds[] = $job->getRequest();
53 53
 
54
-            $job->setDatabase($database);
55
-        }
54
+			$job->setDatabase($database);
55
+		}
56 56
 
57
-        $this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
57
+		$this->assign('canSeeAll', $this->barrierTest('all', User::getCurrent($database)));
58 58
 
59
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
60
-        $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
59
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
60
+		$this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
61 61
 
62
-        $this->assign('joblist', $jobList);
63
-        $this->setTemplate('jobqueue/main.tpl');
64
-    }
62
+		$this->assign('joblist', $jobList);
63
+		$this->setTemplate('jobqueue/main.tpl');
64
+	}
65 65
 
66
-    protected function all()
67
-    {
68
-        $this->setHtmlTitle('All Jobs');
66
+	protected function all()
67
+	{
68
+		$this->setHtmlTitle('All Jobs');
69 69
 
70
-        $this->prepareMaps();
70
+		$this->prepareMaps();
71 71
 
72
-        $database = $this->getDatabase();
72
+		$database = $this->getDatabase();
73 73
 
74
-        $searchHelper = JobQueueSearchHelper::get($database);
75
-        $this->setSearchHelper($searchHelper);
76
-        $this->setupLimits();
74
+		$searchHelper = JobQueueSearchHelper::get($database);
75
+		$this->setSearchHelper($searchHelper);
76
+		$this->setupLimits();
77 77
 
78
-        $filterUser = WebRequest::getString('filterUser');
79
-        $filterTask = WebRequest::getString('filterTask');
80
-        $filterStatus = WebRequest::getString('filterStatus');
81
-        $filterRequest = WebRequest::getString('filterRequest');
78
+		$filterUser = WebRequest::getString('filterUser');
79
+		$filterTask = WebRequest::getString('filterTask');
80
+		$filterStatus = WebRequest::getString('filterStatus');
81
+		$filterRequest = WebRequest::getString('filterRequest');
82 82
 
83
-        if ($filterUser !== null) {
84
-            $searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
85
-        }
83
+		if ($filterUser !== null) {
84
+			$searchHelper->byUser(User::getByUsername($filterUser, $database)->getId());
85
+		}
86 86
 
87
-        if ($filterTask !== null) {
88
-            $searchHelper->byTask($filterTask);
89
-        }
87
+		if ($filterTask !== null) {
88
+			$searchHelper->byTask($filterTask);
89
+		}
90 90
 
91
-        if ($filterStatus !== null) {
92
-            $searchHelper->byStatus($filterStatus);
93
-        }
91
+		if ($filterStatus !== null) {
92
+			$searchHelper->byStatus($filterStatus);
93
+		}
94 94
 
95
-        if ($filterRequest !== null) {
96
-            $searchHelper->byRequest($filterRequest);
97
-        }
95
+		if ($filterRequest !== null) {
96
+			$searchHelper->byRequest($filterRequest);
97
+		}
98 98
 
99
-        /** @var JobQueue[] $jobList */
100
-        $jobList = $searchHelper->getRecordCount($count)->fetch();
99
+		/** @var JobQueue[] $jobList */
100
+		$jobList = $searchHelper->getRecordCount($count)->fetch();
101 101
 
102
-        $this->setupPageData($count, array(
103
-            'filterUser' => $filterUser,
104
-            'filterTask' => $filterTask,
105
-            'filterStatus' => $filterStatus,
106
-            'filterRequest' => $filterRequest,
107
-        ));
102
+		$this->setupPageData($count, array(
103
+			'filterUser' => $filterUser,
104
+			'filterTask' => $filterTask,
105
+			'filterStatus' => $filterStatus,
106
+			'filterRequest' => $filterRequest,
107
+		));
108 108
 
109
-        $userIds = array();
110
-        $requestIds = array();
109
+		$userIds = array();
110
+		$requestIds = array();
111 111
 
112
-        foreach ($jobList as $job) {
113
-            $userIds[] = $job->getTriggerUserId();
114
-            $requestIds[] = $job->getRequest();
112
+		foreach ($jobList as $job) {
113
+			$userIds[] = $job->getTriggerUserId();
114
+			$requestIds[] = $job->getRequest();
115 115
 
116
-            $job->setDatabase($database);
117
-        }
116
+			$job->setDatabase($database);
117
+		}
118 118
 
119
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
120
-            return UserSearchHelper::get($database)->fetchColumn('username');
121
-        });
119
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
120
+			return UserSearchHelper::get($database)->fetchColumn('username');
121
+		});
122 122
 
123
-        $this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
124
-        $this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
123
+		$this->assign('users', UserSearchHelper::get($database)->inIds($userIds)->fetchMap('username'));
124
+		$this->assign('requests', RequestSearchHelper::get($database)->inIds($requestIds)->fetchMap('name'));
125 125
 
126
-        $this->assign('joblist', $jobList);
126
+		$this->assign('joblist', $jobList);
127 127
 
128
-        $this->setTemplate('jobqueue/all.tpl');
129
-    }
128
+		$this->setTemplate('jobqueue/all.tpl');
129
+	}
130 130
 
131
-    protected function view()
132
-    {
133
-        $jobId = WebRequest::getInt('id');
134
-        $database = $this->getDatabase();
131
+	protected function view()
132
+	{
133
+		$jobId = WebRequest::getInt('id');
134
+		$database = $this->getDatabase();
135 135
 
136
-        if ($jobId === null) {
137
-            throw new ApplicationLogicException('No job specified');
138
-        }
136
+		if ($jobId === null) {
137
+			throw new ApplicationLogicException('No job specified');
138
+		}
139 139
 
140
-        /** @var JobQueue $job */
141
-        $job = JobQueue::getById($jobId, $database);
140
+		/** @var JobQueue $job */
141
+		$job = JobQueue::getById($jobId, $database);
142 142
 
143
-        if ($job === false) {
144
-            throw new ApplicationLogicException('Could not find requested job');
145
-        }
143
+		if ($job === false) {
144
+			throw new ApplicationLogicException('Could not find requested job');
145
+		}
146 146
 
147
-        $this->setHtmlTitle('Job #' . $job->getId());
147
+		$this->setHtmlTitle('Job #' . $job->getId());
148 148
 
149
-        $this->prepareMaps();
149
+		$this->prepareMaps();
150 150
 
151
-        $this->assign('user', User::getById($job->getTriggerUserId(), $database));
152
-        $this->assign('request', Request::getById($job->getRequest(), $database));
153
-        $this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
154
-        $this->assign('parent', JobQueue::getById($job->getParent(), $database));
151
+		$this->assign('user', User::getById($job->getTriggerUserId(), $database));
152
+		$this->assign('request', Request::getById($job->getRequest(), $database));
153
+		$this->assign('emailTemplate', EmailTemplate::getById($job->getEmailTemplate(), $database));
154
+		$this->assign('parent', JobQueue::getById($job->getParent(), $database));
155 155
 
156
-        /** @var Log[] $logs */
157
-        $logs = LogSearchHelper::get($database)->byObjectType('JobQueue')
158
-            ->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
159
-        if ($logCount === 0) {
160
-            $this->assign('log', array());
161
-        }
162
-        else {
163
-            list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
156
+		/** @var Log[] $logs */
157
+		$logs = LogSearchHelper::get($database)->byObjectType('JobQueue')
158
+			->byObjectId($job->getId())->getRecordCount($logCount)->fetch();
159
+		if ($logCount === 0) {
160
+			$this->assign('log', array());
161
+		}
162
+		else {
163
+			list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
164 164
 
165
-            $this->assign("log", $logData);
166
-            $this->assign("users", $users);
167
-        }
165
+			$this->assign("log", $logData);
166
+			$this->assign("users", $users);
167
+		}
168 168
 
169
-        $this->assignCSRFToken();
169
+		$this->assignCSRFToken();
170 170
 
171
-        $this->assign('job', $job);
171
+		$this->assign('job', $job);
172 172
 
173
-        $this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
174
-        $this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
175
-        $this->setTemplate('jobqueue/view.tpl');
176
-    }
173
+		$this->assign('canAcknowledge', $this->barrierTest('acknowledge', User::getCurrent($database)));
174
+		$this->assign('canRequeue', $this->barrierTest('requeue', User::getCurrent($database)));
175
+		$this->setTemplate('jobqueue/view.tpl');
176
+	}
177 177
 
178
-    protected function acknowledge()
179
-    {
180
-        if (!WebRequest::wasPosted()) {
181
-            throw new ApplicationLogicException('This page does not support GET methods.');
182
-        }
178
+	protected function acknowledge()
179
+	{
180
+		if (!WebRequest::wasPosted()) {
181
+			throw new ApplicationLogicException('This page does not support GET methods.');
182
+		}
183 183
 
184
-        $this->validateCSRFToken();
184
+		$this->validateCSRFToken();
185 185
 
186
-        $jobId = WebRequest::postInt('job');
187
-        $database = $this->getDatabase();
186
+		$jobId = WebRequest::postInt('job');
187
+		$database = $this->getDatabase();
188 188
 
189
-        if ($jobId === null) {
190
-            throw new ApplicationLogicException('No job specified');
191
-        }
189
+		if ($jobId === null) {
190
+			throw new ApplicationLogicException('No job specified');
191
+		}
192 192
 
193
-        /** @var JobQueue $job */
194
-        $job = JobQueue::getById($jobId, $database);
193
+		/** @var JobQueue $job */
194
+		$job = JobQueue::getById($jobId, $database);
195 195
 
196
-        if ($job === false) {
197
-            throw new ApplicationLogicException('Could not find requested job');
198
-        }
196
+		if ($job === false) {
197
+			throw new ApplicationLogicException('Could not find requested job');
198
+		}
199 199
 
200
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
201
-        $job->setAcknowledged(true);
202
-        $job->save();
200
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
201
+		$job->setAcknowledged(true);
202
+		$job->save();
203 203
 
204
-        Logger::backgroundJobAcknowledged($database, $job);
204
+		Logger::backgroundJobAcknowledged($database, $job);
205 205
 
206
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
207
-    }
206
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
207
+	}
208 208
 
209
-    protected function requeue()
210
-    {
211
-        if (!WebRequest::wasPosted()) {
212
-            throw new ApplicationLogicException('This page does not support GET methods.');
213
-        }
209
+	protected function requeue()
210
+	{
211
+		if (!WebRequest::wasPosted()) {
212
+			throw new ApplicationLogicException('This page does not support GET methods.');
213
+		}
214 214
 
215
-        $this->validateCSRFToken();
215
+		$this->validateCSRFToken();
216 216
 
217
-        $jobId = WebRequest::postInt('job');
218
-        $database = $this->getDatabase();
217
+		$jobId = WebRequest::postInt('job');
218
+		$database = $this->getDatabase();
219 219
 
220
-        if ($jobId === null) {
221
-            throw new ApplicationLogicException('No job specified');
222
-        }
220
+		if ($jobId === null) {
221
+			throw new ApplicationLogicException('No job specified');
222
+		}
223 223
 
224
-        /** @var JobQueue $job */
225
-        $job = JobQueue::getById($jobId, $database);
224
+		/** @var JobQueue $job */
225
+		$job = JobQueue::getById($jobId, $database);
226 226
 
227
-        if ($job === false) {
228
-            throw new ApplicationLogicException('Could not find requested job');
229
-        }
227
+		if ($job === false) {
228
+			throw new ApplicationLogicException('Could not find requested job');
229
+		}
230 230
 
231
-        $job->setStatus(JobQueue::STATUS_READY);
232
-        $job->setUpdateVersion(WebRequest::postInt('updateVersion'));
233
-        $job->setAcknowledged(null);
234
-        $job->setError(null);
235
-        $job->save();
236
-
237
-        /** @var Request $request */
238
-        $request = Request::getById($job->getRequest(), $database);
239
-        $request->setStatus(RequestStatus::JOBQUEUE);
240
-        $request->save();
231
+		$job->setStatus(JobQueue::STATUS_READY);
232
+		$job->setUpdateVersion(WebRequest::postInt('updateVersion'));
233
+		$job->setAcknowledged(null);
234
+		$job->setError(null);
235
+		$job->save();
236
+
237
+		/** @var Request $request */
238
+		$request = Request::getById($job->getRequest(), $database);
239
+		$request->setStatus(RequestStatus::JOBQUEUE);
240
+		$request->save();
241 241
 
242
-        Logger::enqueuedJobQueue($database, $request);
243
-        Logger::backgroundJobRequeued($database, $job);
244
-
245
-        $this->redirect('jobQueue', 'view', array('id' => $jobId));
246
-    }
247
-
248
-    protected function prepareMaps()
249
-    {
250
-        $taskNameMap = JobQueue::getTaskDescriptions();
251
-
252
-        $statusDecriptionMap = array(
253
-            JobQueue::STATUS_CANCELLED => 'The job was cancelled',
254
-            JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
255
-            JobQueue::STATUS_FAILED    => 'The job encountered an error',
256
-            JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
257
-            JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
258
-            JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
259
-            JobQueue::STATUS_HELD      => 'The job has manually held from processing',
260
-        );
261
-        $this->assign('taskNameMap', $taskNameMap);
262
-        $this->assign('statusDescriptionMap', $statusDecriptionMap);
263
-    }
242
+		Logger::enqueuedJobQueue($database, $request);
243
+		Logger::backgroundJobRequeued($database, $job);
244
+
245
+		$this->redirect('jobQueue', 'view', array('id' => $jobId));
246
+	}
247
+
248
+	protected function prepareMaps()
249
+	{
250
+		$taskNameMap = JobQueue::getTaskDescriptions();
251
+
252
+		$statusDecriptionMap = array(
253
+			JobQueue::STATUS_CANCELLED => 'The job was cancelled',
254
+			JobQueue::STATUS_COMPLETE  => 'The job completed successfully',
255
+			JobQueue::STATUS_FAILED    => 'The job encountered an error',
256
+			JobQueue::STATUS_READY     => 'The job is ready to be picked up by the next job runner execution',
257
+			JobQueue::STATUS_RUNNING   => 'The job is being run right now by the job runner',
258
+			JobQueue::STATUS_WAITING   => 'The job has been picked up by a job runner',
259
+			JobQueue::STATUS_HELD      => 'The job has manually held from processing',
260
+		);
261
+		$this->assign('taskNameMap', $taskNameMap);
262
+		$this->assign('statusDescriptionMap', $statusDecriptionMap);
263
+	}
264 264
 }
265 265
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@
 block discarded – undo
144 144
             throw new ApplicationLogicException('Could not find requested job');
145 145
         }
146 146
 
147
-        $this->setHtmlTitle('Job #' . $job->getId());
147
+        $this->setHtmlTitle('Job #'.$job->getId());
148 148
 
149 149
         $this->prepareMaps();
150 150
 
Please login to merge, or discard this patch.