Completed
Push — newinternal-releasecandidate ( 410e59...fe35c3 )
by Simon
17s queued 14s
created
includes/DataObjects/WelcomeTemplate.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -19,166 +19,166 @@
 block discarded – undo
19 19
  */
20 20
 class WelcomeTemplate extends DataObject
21 21
 {
22
-    /** @var string */
23
-    private $usercode;
24
-    /** @var string */
25
-    private $botcode;
26
-    private $usageCache;
27
-    private $deleted = 0;
28
-
29
-    /**
30
-     * Summary of getAll
31
-     *
32
-     * @param PdoDatabase $database
33
-     *
34
-     * @return WelcomeTemplate[]
35
-     */
36
-    public static function getAll(PdoDatabase $database)
37
-    {
38
-        $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;");
39
-
40
-        $statement->execute();
41
-
42
-        $result = array();
43
-        /** @var WelcomeTemplate $v */
44
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) {
45
-            $v->setDatabase($database);
46
-            $result[] = $v;
47
-        }
48
-
49
-        return $result;
50
-    }
51
-
52
-    /**
53
-     * @throws Exception
54
-     */
55
-    public function save()
56
-    {
57
-        if ($this->isNew()) {
58
-            // insert
59
-            $statement = $this->dbObject->prepare(<<<SQL
22
+	/** @var string */
23
+	private $usercode;
24
+	/** @var string */
25
+	private $botcode;
26
+	private $usageCache;
27
+	private $deleted = 0;
28
+
29
+	/**
30
+	 * Summary of getAll
31
+	 *
32
+	 * @param PdoDatabase $database
33
+	 *
34
+	 * @return WelcomeTemplate[]
35
+	 */
36
+	public static function getAll(PdoDatabase $database)
37
+	{
38
+		$statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;");
39
+
40
+		$statement->execute();
41
+
42
+		$result = array();
43
+		/** @var WelcomeTemplate $v */
44
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) {
45
+			$v->setDatabase($database);
46
+			$result[] = $v;
47
+		}
48
+
49
+		return $result;
50
+	}
51
+
52
+	/**
53
+	 * @throws Exception
54
+	 */
55
+	public function save()
56
+	{
57
+		if ($this->isNew()) {
58
+			// insert
59
+			$statement = $this->dbObject->prepare(<<<SQL
60 60
 INSERT INTO welcometemplate (usercode, botcode) VALUES (:usercode, :botcode);
61 61
 SQL
62
-            );
63
-            $statement->bindValue(":usercode", $this->usercode);
64
-            $statement->bindValue(":botcode", $this->botcode);
65
-
66
-            if ($statement->execute()) {
67
-                $this->id = (int)$this->dbObject->lastInsertId();
68
-            }
69
-            else {
70
-                throw new Exception($statement->errorInfo());
71
-            }
72
-        }
73
-        else {
74
-            // update
75
-            $statement = $this->dbObject->prepare(<<<SQL
62
+			);
63
+			$statement->bindValue(":usercode", $this->usercode);
64
+			$statement->bindValue(":botcode", $this->botcode);
65
+
66
+			if ($statement->execute()) {
67
+				$this->id = (int)$this->dbObject->lastInsertId();
68
+			}
69
+			else {
70
+				throw new Exception($statement->errorInfo());
71
+			}
72
+		}
73
+		else {
74
+			// update
75
+			$statement = $this->dbObject->prepare(<<<SQL
76 76
 UPDATE `welcometemplate`
77 77
 SET usercode = :usercode, botcode = :botcode, updateversion = updateversion + 1
78 78
 WHERE id = :id AND updateversion = :updateversion;
79 79
 SQL
80
-            );
81
-
82
-            $statement->bindValue(':id', $this->id);
83
-            $statement->bindValue(':updateversion', $this->updateversion);
84
-
85
-            $statement->bindValue(':usercode', $this->usercode);
86
-            $statement->bindValue(':botcode', $this->botcode);
87
-
88
-            if (!$statement->execute()) {
89
-                throw new Exception($statement->errorInfo());
90
-            }
91
-
92
-            if ($statement->rowCount() !== 1) {
93
-                throw new OptimisticLockFailedException();
94
-            }
95
-
96
-            $this->updateversion++;
97
-        }
98
-    }
99
-
100
-    /**
101
-     * @return string
102
-     */
103
-    public function getUserCode()
104
-    {
105
-        return $this->usercode;
106
-    }
107
-
108
-    /**
109
-     * @param string $usercode
110
-     */
111
-    public function setUserCode($usercode)
112
-    {
113
-        $this->usercode = $usercode;
114
-    }
115
-
116
-    /**
117
-     * @return string
118
-     */
119
-    public function getBotCode()
120
-    {
121
-        return $this->botcode;
122
-    }
123
-
124
-    /**
125
-     * @param string $botcode
126
-     */
127
-    public function setBotCode($botcode)
128
-    {
129
-        $this->botcode = $botcode;
130
-    }
131
-
132
-    /**
133
-     * @return User[]
134
-     */
135
-    public function getUsersUsingTemplate()
136
-    {
137
-        if ($this->usageCache === null) {
138
-            $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;");
139
-
140
-            $statement->execute(array(":id" => $this->id));
141
-
142
-            $result = array();
143
-            /** @var WelcomeTemplate $v */
144
-            foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) {
145
-                $v->setDatabase($this->dbObject);
146
-                $result[] = $v;
147
-            }
148
-
149
-            $this->usageCache = $result;
150
-        }
151
-
152
-        return $this->usageCache;
153
-    }
154
-
155
-    /**
156
-     * Deletes the object from the database
157
-     */
158
-    public function delete()
159
-    {
160
-        if ($this->id === null) {
161
-            // wtf?
162
-            return;
163
-        }
164
-
165
-        $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;";
166
-        $statement = $this->dbObject->prepare($deleteQuery);
167
-
168
-        $statement->bindValue(":id", $this->id);
169
-        $statement->bindValue(":updateversion", $this->updateversion);
170
-        $statement->execute();
171
-
172
-        if ($statement->rowCount() !== 1) {
173
-            throw new OptimisticLockFailedException();
174
-        }
175
-    }
176
-
177
-    /**
178
-     * @return bool
179
-     */
180
-    public function isDeleted()
181
-    {
182
-        return ((int)$this->deleted) === 1;
183
-    }
80
+			);
81
+
82
+			$statement->bindValue(':id', $this->id);
83
+			$statement->bindValue(':updateversion', $this->updateversion);
84
+
85
+			$statement->bindValue(':usercode', $this->usercode);
86
+			$statement->bindValue(':botcode', $this->botcode);
87
+
88
+			if (!$statement->execute()) {
89
+				throw new Exception($statement->errorInfo());
90
+			}
91
+
92
+			if ($statement->rowCount() !== 1) {
93
+				throw new OptimisticLockFailedException();
94
+			}
95
+
96
+			$this->updateversion++;
97
+		}
98
+	}
99
+
100
+	/**
101
+	 * @return string
102
+	 */
103
+	public function getUserCode()
104
+	{
105
+		return $this->usercode;
106
+	}
107
+
108
+	/**
109
+	 * @param string $usercode
110
+	 */
111
+	public function setUserCode($usercode)
112
+	{
113
+		$this->usercode = $usercode;
114
+	}
115
+
116
+	/**
117
+	 * @return string
118
+	 */
119
+	public function getBotCode()
120
+	{
121
+		return $this->botcode;
122
+	}
123
+
124
+	/**
125
+	 * @param string $botcode
126
+	 */
127
+	public function setBotCode($botcode)
128
+	{
129
+		$this->botcode = $botcode;
130
+	}
131
+
132
+	/**
133
+	 * @return User[]
134
+	 */
135
+	public function getUsersUsingTemplate()
136
+	{
137
+		if ($this->usageCache === null) {
138
+			$statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;");
139
+
140
+			$statement->execute(array(":id" => $this->id));
141
+
142
+			$result = array();
143
+			/** @var WelcomeTemplate $v */
144
+			foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) {
145
+				$v->setDatabase($this->dbObject);
146
+				$result[] = $v;
147
+			}
148
+
149
+			$this->usageCache = $result;
150
+		}
151
+
152
+		return $this->usageCache;
153
+	}
154
+
155
+	/**
156
+	 * Deletes the object from the database
157
+	 */
158
+	public function delete()
159
+	{
160
+		if ($this->id === null) {
161
+			// wtf?
162
+			return;
163
+		}
164
+
165
+		$deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;";
166
+		$statement = $this->dbObject->prepare($deleteQuery);
167
+
168
+		$statement->bindValue(":id", $this->id);
169
+		$statement->bindValue(":updateversion", $this->updateversion);
170
+		$statement->execute();
171
+
172
+		if ($statement->rowCount() !== 1) {
173
+			throw new OptimisticLockFailedException();
174
+		}
175
+	}
176
+
177
+	/**
178
+	 * @return bool
179
+	 */
180
+	public function isDeleted()
181
+	{
182
+		return ((int)$this->deleted) === 1;
183
+	}
184 184
 }
Please login to merge, or discard this patch.
includes/DataObjects/EmailTemplate.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -21,176 +21,176 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class EmailTemplate extends DataObject
23 23
 {
24
-    /** Note, also used in template-table.tpl */
25
-    const CREATED = "created";
26
-    /** Note, also used in template-table.tpl */
27
-    const NOT_CREATED = "not created";
28
-    /** Note, also used in template-table.tpl */
29
-    const NONE = null;
30
-    /** @var string the name of the template */
31
-    private $name;
32
-    private $text;
33
-    /** @var string|null */
34
-    private $jsquestion;
35
-    private $active = 1;
36
-    private $preloadonly = 0;
37
-    private $defaultaction = self::NOT_CREATED;
38
-
39
-    /**
40
-     * Gets active non-preload templates
41
-     *
42
-     * @param string      $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
43
-     * @param PdoDatabase $database
44
-     *
45
-     * @return array|false
46
-     */
47
-    public static function getActiveTemplates($defaultAction, PdoDatabase $database)
48
-    {
49
-        global $createdid;
50
-
51
-        $statement = $database->prepare(<<<SQL
24
+	/** Note, also used in template-table.tpl */
25
+	const CREATED = "created";
26
+	/** Note, also used in template-table.tpl */
27
+	const NOT_CREATED = "not created";
28
+	/** Note, also used in template-table.tpl */
29
+	const NONE = null;
30
+	/** @var string the name of the template */
31
+	private $name;
32
+	private $text;
33
+	/** @var string|null */
34
+	private $jsquestion;
35
+	private $active = 1;
36
+	private $preloadonly = 0;
37
+	private $defaultaction = self::NOT_CREATED;
38
+
39
+	/**
40
+	 * Gets active non-preload templates
41
+	 *
42
+	 * @param string      $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED)
43
+	 * @param PdoDatabase $database
44
+	 *
45
+	 * @return array|false
46
+	 */
47
+	public static function getActiveTemplates($defaultAction, PdoDatabase $database)
48
+	{
49
+		global $createdid;
50
+
51
+		$statement = $database->prepare(<<<SQL
52 52
 SELECT * FROM `emailtemplate`
53 53
 WHERE defaultaction = :forcreated AND active = 1 AND preloadonly = 0 AND id != :createdid;
54 54
 SQL
55
-        );
56
-        $statement->bindValue(":createdid", $createdid);
57
-        $statement->bindValue(":forcreated", $defaultAction);
58
-
59
-        $statement->execute();
60
-
61
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
62
-
63
-        /** @var EmailTemplate $t */
64
-        foreach ($resultObject as $t) {
65
-            $t->setDatabase($database);
66
-        }
67
-
68
-        return $resultObject;
69
-    }
70
-
71
-    /**
72
-     * Gets active non-preload and preload templates, optionally filtered by the default action.
73
-     *
74
-     * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED,
75
-     *                                        EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to
76
-     *                                        just get everything.
77
-     * @param PdoDatabase      $database
78
-     *
79
-     * @return array|false
80
-     */
81
-    public static function getAllActiveTemplates($defaultAction, PdoDatabase $database)
82
-    {
83
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
84
-
85
-        if ($defaultAction === false) {
86
-            $statement = $database->prepare(
87
-                "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;");
88
-        }
89
-
90
-        if ($defaultAction === null) {
91
-            $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 1;");
92
-        }
93
-
94
-        $statement->bindValue(":forcreated", $defaultAction);
95
-
96
-        $statement->execute();
97
-
98
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
99
-
100
-        /** @var EmailTemplate $t */
101
-        foreach ($resultObject as $t) {
102
-            $t->setDatabase($database);
103
-        }
104
-
105
-        return $resultObject;
106
-    }
107
-
108
-    /**
109
-     * Gets all the unactive templates
110
-     *
111
-     * @param PdoDatabase $database
112
-     *
113
-     * @return array
114
-     */
115
-    public static function getAllInactiveTemplates(PdoDatabase $database)
116
-    {
117
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 0;");
118
-        $statement->execute();
119
-
120
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
121
-
122
-        /** @var EmailTemplate $t */
123
-        foreach ($resultObject as $t) {
124
-            $t->setDatabase($database);
125
-        }
126
-
127
-        return $resultObject;
128
-    }
129
-
130
-    /**
131
-     * @param string      $name
132
-     * @param PdoDatabase $database
133
-     *
134
-     * @return EmailTemplate|false
135
-     */
136
-    public static function getByName($name, PdoDatabase $database)
137
-    {
138
-        $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;");
139
-        $statement->bindValue(":name", $name);
140
-
141
-        $statement->execute();
142
-
143
-        $resultObject = $statement->fetchObject(get_called_class());
144
-
145
-        if ($resultObject != false) {
146
-            $resultObject->setDatabase($database);
147
-        }
148
-
149
-        return $resultObject;
150
-    }
151
-
152
-    /**
153
-     * @return EmailTemplate
154
-     */
155
-    public static function getDroppedTemplate()
156
-    {
157
-        $t = new EmailTemplate();
158
-        $t->id = 0;
159
-        $t->active = 1;
160
-        $t->name = 'Dropped';
161
-
162
-        return $t;
163
-    }
164
-
165
-    /**
166
-     * @throws Exception
167
-     */
168
-    public function save()
169
-    {
170
-        if ($this->isNew()) {
171
-            // insert
172
-            $statement = $this->dbObject->prepare(<<<SQL
55
+		);
56
+		$statement->bindValue(":createdid", $createdid);
57
+		$statement->bindValue(":forcreated", $defaultAction);
58
+
59
+		$statement->execute();
60
+
61
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
62
+
63
+		/** @var EmailTemplate $t */
64
+		foreach ($resultObject as $t) {
65
+			$t->setDatabase($database);
66
+		}
67
+
68
+		return $resultObject;
69
+	}
70
+
71
+	/**
72
+	 * Gets active non-preload and preload templates, optionally filtered by the default action.
73
+	 *
74
+	 * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED,
75
+	 *                                        EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to
76
+	 *                                        just get everything.
77
+	 * @param PdoDatabase      $database
78
+	 *
79
+	 * @return array|false
80
+	 */
81
+	public static function getAllActiveTemplates($defaultAction, PdoDatabase $database)
82
+	{
83
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;");
84
+
85
+		if ($defaultAction === false) {
86
+			$statement = $database->prepare(
87
+				"SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;");
88
+		}
89
+
90
+		if ($defaultAction === null) {
91
+			$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 1;");
92
+		}
93
+
94
+		$statement->bindValue(":forcreated", $defaultAction);
95
+
96
+		$statement->execute();
97
+
98
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
99
+
100
+		/** @var EmailTemplate $t */
101
+		foreach ($resultObject as $t) {
102
+			$t->setDatabase($database);
103
+		}
104
+
105
+		return $resultObject;
106
+	}
107
+
108
+	/**
109
+	 * Gets all the unactive templates
110
+	 *
111
+	 * @param PdoDatabase $database
112
+	 *
113
+	 * @return array
114
+	 */
115
+	public static function getAllInactiveTemplates(PdoDatabase $database)
116
+	{
117
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE  active = 0;");
118
+		$statement->execute();
119
+
120
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
121
+
122
+		/** @var EmailTemplate $t */
123
+		foreach ($resultObject as $t) {
124
+			$t->setDatabase($database);
125
+		}
126
+
127
+		return $resultObject;
128
+	}
129
+
130
+	/**
131
+	 * @param string      $name
132
+	 * @param PdoDatabase $database
133
+	 *
134
+	 * @return EmailTemplate|false
135
+	 */
136
+	public static function getByName($name, PdoDatabase $database)
137
+	{
138
+		$statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;");
139
+		$statement->bindValue(":name", $name);
140
+
141
+		$statement->execute();
142
+
143
+		$resultObject = $statement->fetchObject(get_called_class());
144
+
145
+		if ($resultObject != false) {
146
+			$resultObject->setDatabase($database);
147
+		}
148
+
149
+		return $resultObject;
150
+	}
151
+
152
+	/**
153
+	 * @return EmailTemplate
154
+	 */
155
+	public static function getDroppedTemplate()
156
+	{
157
+		$t = new EmailTemplate();
158
+		$t->id = 0;
159
+		$t->active = 1;
160
+		$t->name = 'Dropped';
161
+
162
+		return $t;
163
+	}
164
+
165
+	/**
166
+	 * @throws Exception
167
+	 */
168
+	public function save()
169
+	{
170
+		if ($this->isNew()) {
171
+			// insert
172
+			$statement = $this->dbObject->prepare(<<<SQL
173 173
 INSERT INTO `emailtemplate` (name, text, jsquestion, defaultaction, active, preloadonly)
174 174
 VALUES (:name, :text, :jsquestion, :defaultaction, :active, :preloadonly);
175 175
 SQL
176
-            );
177
-            $statement->bindValue(":name", $this->name);
178
-            $statement->bindValue(":text", $this->text);
179
-            $statement->bindValue(":jsquestion", $this->jsquestion);
180
-            $statement->bindValue(":defaultaction", $this->defaultaction);
181
-            $statement->bindValue(":active", $this->active);
182
-            $statement->bindValue(":preloadonly", $this->preloadonly);
183
-
184
-            if ($statement->execute()) {
185
-                $this->id = (int)$this->dbObject->lastInsertId();
186
-            }
187
-            else {
188
-                throw new Exception($statement->errorInfo());
189
-            }
190
-        }
191
-        else {
192
-            // update
193
-            $statement = $this->dbObject->prepare(<<<SQL
176
+			);
177
+			$statement->bindValue(":name", $this->name);
178
+			$statement->bindValue(":text", $this->text);
179
+			$statement->bindValue(":jsquestion", $this->jsquestion);
180
+			$statement->bindValue(":defaultaction", $this->defaultaction);
181
+			$statement->bindValue(":active", $this->active);
182
+			$statement->bindValue(":preloadonly", $this->preloadonly);
183
+
184
+			if ($statement->execute()) {
185
+				$this->id = (int)$this->dbObject->lastInsertId();
186
+			}
187
+			else {
188
+				throw new Exception($statement->errorInfo());
189
+			}
190
+		}
191
+		else {
192
+			// update
193
+			$statement = $this->dbObject->prepare(<<<SQL
194 194
 UPDATE `emailtemplate`
195 195
 SET name = :name,
196 196
 	text = :text,
@@ -201,130 +201,130 @@  discard block
 block discarded – undo
201 201
 	updateversion = updateversion + 1
202 202
 WHERE id = :id AND updateversion = :updateversion;
203 203
 SQL
204
-            );
205
-            $statement->bindValue(':id', $this->id);
206
-            $statement->bindValue(':updateversion', $this->updateversion);
207
-
208
-            $statement->bindValue(':name', $this->name);
209
-            $statement->bindValue(":text", $this->text);
210
-            $statement->bindValue(":jsquestion", $this->jsquestion);
211
-            $statement->bindValue(":defaultaction", $this->defaultaction);
212
-            $statement->bindValue(":active", $this->active);
213
-            $statement->bindValue(":preloadonly", $this->preloadonly);
214
-
215
-            if (!$statement->execute()) {
216
-                throw new Exception($statement->errorInfo());
217
-            }
218
-
219
-            if ($statement->rowCount() !== 1) {
220
-                throw new OptimisticLockFailedException();
221
-            }
222
-
223
-            $this->updateversion++;
224
-        }
225
-    }
226
-
227
-    /**
228
-     * Override delete() from DataObject
229
-     */
230
-    public function delete()
231
-    {
232
-        throw new Exception("You shouldn't be doing that, you'll break logs.");
233
-    }
234
-
235
-    /**
236
-     * @return string
237
-     */
238
-    public function getName()
239
-    {
240
-        return $this->name;
241
-    }
242
-
243
-    /**
244
-     * @param string $name
245
-     */
246
-    public function setName($name)
247
-    {
248
-        $this->name = $name;
249
-    }
250
-
251
-    /**
252
-     * @return string
253
-     */
254
-    public function getText()
255
-    {
256
-        return $this->text;
257
-    }
258
-
259
-    /**
260
-     * @param string $text
261
-     */
262
-    public function setText($text)
263
-    {
264
-        $this->text = $text;
265
-    }
266
-
267
-    /**
268
-     * @return string|null
269
-     */
270
-    public function getJsquestion()
271
-    {
272
-        return $this->jsquestion;
273
-    }
274
-
275
-    /**
276
-     * @param string $jsquestion
277
-     */
278
-    public function setJsquestion($jsquestion)
279
-    {
280
-        $this->jsquestion = $jsquestion;
281
-    }
282
-
283
-    /**
284
-     * @return string
285
-     */
286
-    public function getDefaultAction()
287
-    {
288
-        return $this->defaultaction;
289
-    }
290
-
291
-    /**
292
-     * @param string $defaultAction
293
-     */
294
-    public function setDefaultAction($defaultAction)
295
-    {
296
-        $this->defaultaction = $defaultAction;
297
-    }
298
-
299
-    /**
300
-     * @return bool
301
-     */
302
-    public function getActive()
303
-    {
304
-        return $this->active == 1;
305
-    }
306
-
307
-    /**
308
-     * @param bool $active
309
-     */
310
-    public function setActive($active)
311
-    {
312
-        $this->active = $active ? 1 : 0;
313
-    }
314
-
315
-    /**
316
-     * @return bool
317
-     */
318
-    public function getPreloadOnly()
319
-    {
320
-        return $this->preloadonly == 1;
321
-    }
322
-
323
-    /**
324
-     * @param bool $preloadonly
325
-     */
326
-    public function setPreloadOnly($preloadonly)
327
-    {
328
-        $this->preloadonly = $preloadonly ? 1 : 0;
329
-    }
204
+			);
205
+			$statement->bindValue(':id', $this->id);
206
+			$statement->bindValue(':updateversion', $this->updateversion);
207
+
208
+			$statement->bindValue(':name', $this->name);
209
+			$statement->bindValue(":text", $this->text);
210
+			$statement->bindValue(":jsquestion", $this->jsquestion);
211
+			$statement->bindValue(":defaultaction", $this->defaultaction);
212
+			$statement->bindValue(":active", $this->active);
213
+			$statement->bindValue(":preloadonly", $this->preloadonly);
214
+
215
+			if (!$statement->execute()) {
216
+				throw new Exception($statement->errorInfo());
217
+			}
218
+
219
+			if ($statement->rowCount() !== 1) {
220
+				throw new OptimisticLockFailedException();
221
+			}
222
+
223
+			$this->updateversion++;
224
+		}
225
+	}
226
+
227
+	/**
228
+	 * Override delete() from DataObject
229
+	 */
230
+	public function delete()
231
+	{
232
+		throw new Exception("You shouldn't be doing that, you'll break logs.");
233
+	}
234
+
235
+	/**
236
+	 * @return string
237
+	 */
238
+	public function getName()
239
+	{
240
+		return $this->name;
241
+	}
242
+
243
+	/**
244
+	 * @param string $name
245
+	 */
246
+	public function setName($name)
247
+	{
248
+		$this->name = $name;
249
+	}
250
+
251
+	/**
252
+	 * @return string
253
+	 */
254
+	public function getText()
255
+	{
256
+		return $this->text;
257
+	}
258
+
259
+	/**
260
+	 * @param string $text
261
+	 */
262
+	public function setText($text)
263
+	{
264
+		$this->text = $text;
265
+	}
266
+
267
+	/**
268
+	 * @return string|null
269
+	 */
270
+	public function getJsquestion()
271
+	{
272
+		return $this->jsquestion;
273
+	}
274
+
275
+	/**
276
+	 * @param string $jsquestion
277
+	 */
278
+	public function setJsquestion($jsquestion)
279
+	{
280
+		$this->jsquestion = $jsquestion;
281
+	}
282
+
283
+	/**
284
+	 * @return string
285
+	 */
286
+	public function getDefaultAction()
287
+	{
288
+		return $this->defaultaction;
289
+	}
290
+
291
+	/**
292
+	 * @param string $defaultAction
293
+	 */
294
+	public function setDefaultAction($defaultAction)
295
+	{
296
+		$this->defaultaction = $defaultAction;
297
+	}
298
+
299
+	/**
300
+	 * @return bool
301
+	 */
302
+	public function getActive()
303
+	{
304
+		return $this->active == 1;
305
+	}
306
+
307
+	/**
308
+	 * @param bool $active
309
+	 */
310
+	public function setActive($active)
311
+	{
312
+		$this->active = $active ? 1 : 0;
313
+	}
314
+
315
+	/**
316
+	 * @return bool
317
+	 */
318
+	public function getPreloadOnly()
319
+	{
320
+		return $this->preloadonly == 1;
321
+	}
322
+
323
+	/**
324
+	 * @param bool $preloadonly
325
+	 */
326
+	public function setPreloadOnly($preloadonly)
327
+	{
328
+		$this->preloadonly = $preloadonly ? 1 : 0;
329
+	}
330 330
 }
Please login to merge, or discard this patch.
includes/DataObjects/Comment.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -20,171 +20,171 @@
 block discarded – undo
20 20
  */
21 21
 class Comment extends DataObject
22 22
 {
23
-    private $time;
24
-    private $user;
25
-    private $comment;
26
-    private $visibility = "user";
27
-    private $request;
28
-
29
-    /**
30
-     * Retrieves all comments for a request, optionally filtered
31
-     *
32
-     * @param integer     $id      Request ID to search by
33
-     * @param PdoDatabase $database
34
-     * @param bool        $showAll True to show all comments, False to show only unprotected comments, and protected
35
-     *                             comments visible to $userId
36
-     * @param null|int    $userId  User to filter by
37
-     *
38
-     * @return Comment[]
39
-     */
40
-    public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null)
41
-    {
42
-        if ($showAll) {
43
-            $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
-        }
45
-        else {
46
-            $statement = $database->prepare(<<<SQL
23
+	private $time;
24
+	private $user;
25
+	private $comment;
26
+	private $visibility = "user";
27
+	private $request;
28
+
29
+	/**
30
+	 * Retrieves all comments for a request, optionally filtered
31
+	 *
32
+	 * @param integer     $id      Request ID to search by
33
+	 * @param PdoDatabase $database
34
+	 * @param bool        $showAll True to show all comments, False to show only unprotected comments, and protected
35
+	 *                             comments visible to $userId
36
+	 * @param null|int    $userId  User to filter by
37
+	 *
38
+	 * @return Comment[]
39
+	 */
40
+	public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null)
41
+	{
42
+		if ($showAll) {
43
+			$statement = $database->prepare('SELECT * FROM comment WHERE request = :target;');
44
+		}
45
+		else {
46
+			$statement = $database->prepare(<<<SQL
47 47
 SELECT * FROM comment
48 48
 WHERE request = :target AND (visibility = 'user' OR user = :userid);
49 49
 SQL
50
-            );
51
-            $statement->bindValue(':userid', $userId);
52
-        }
53
-
54
-        $statement->bindValue(':target', $id);
55
-
56
-        $statement->execute();
57
-
58
-        $result = array();
59
-        /** @var Comment $v */
60
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
61
-            $v->setDatabase($database);
62
-            $result[] = $v;
63
-        }
64
-
65
-        return $result;
66
-    }
67
-
68
-    /**
69
-     * @throws Exception
70
-     */
71
-    public function save()
72
-    {
73
-        if ($this->isNew()) {
74
-            // insert
75
-            $statement = $this->dbObject->prepare(<<<SQL
50
+			);
51
+			$statement->bindValue(':userid', $userId);
52
+		}
53
+
54
+		$statement->bindValue(':target', $id);
55
+
56
+		$statement->execute();
57
+
58
+		$result = array();
59
+		/** @var Comment $v */
60
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
61
+			$v->setDatabase($database);
62
+			$result[] = $v;
63
+		}
64
+
65
+		return $result;
66
+	}
67
+
68
+	/**
69
+	 * @throws Exception
70
+	 */
71
+	public function save()
72
+	{
73
+		if ($this->isNew()) {
74
+			// insert
75
+			$statement = $this->dbObject->prepare(<<<SQL
76 76
 INSERT INTO comment ( time, user, comment, visibility, request )
77 77
 VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request );
78 78
 SQL
79
-            );
80
-            $statement->bindValue(":user", $this->user);
81
-            $statement->bindValue(":comment", $this->comment);
82
-            $statement->bindValue(":visibility", $this->visibility);
83
-            $statement->bindValue(":request", $this->request);
84
-
85
-            if ($statement->execute()) {
86
-                $this->id = (int)$this->dbObject->lastInsertId();
87
-            }
88
-            else {
89
-                throw new Exception($statement->errorInfo());
90
-            }
91
-        }
92
-        else {
93
-            // update
94
-            $statement = $this->dbObject->prepare(<<<SQL
79
+			);
80
+			$statement->bindValue(":user", $this->user);
81
+			$statement->bindValue(":comment", $this->comment);
82
+			$statement->bindValue(":visibility", $this->visibility);
83
+			$statement->bindValue(":request", $this->request);
84
+
85
+			if ($statement->execute()) {
86
+				$this->id = (int)$this->dbObject->lastInsertId();
87
+			}
88
+			else {
89
+				throw new Exception($statement->errorInfo());
90
+			}
91
+		}
92
+		else {
93
+			// update
94
+			$statement = $this->dbObject->prepare(<<<SQL
95 95
 UPDATE comment
96 96
 SET comment = :comment, visibility = :visibility, updateversion = updateversion + 1
97 97
 WHERE id = :id AND updateversion = :updateversion;
98 98
 SQL
99
-            );
100
-
101
-            $statement->bindValue(':id', $this->id);
102
-            $statement->bindValue(':updateversion', $this->updateversion);
103
-
104
-            $statement->bindValue(':comment', $this->comment);
105
-            $statement->bindValue(':visibility', $this->visibility);
106
-
107
-            if (!$statement->execute()) {
108
-                throw new Exception($statement->errorInfo());
109
-            }
110
-
111
-            if ($statement->rowCount() !== 1) {
112
-                throw new OptimisticLockFailedException();
113
-            }
114
-
115
-            $this->updateversion++;
116
-        }
117
-    }
118
-
119
-    /**
120
-     * @return DateTimeImmutable
121
-     */
122
-    public function getTime()
123
-    {
124
-        return new DateTimeImmutable($this->time);
125
-    }
126
-
127
-    /**
128
-     * @return int
129
-     */
130
-    public function getUser()
131
-    {
132
-        return $this->user;
133
-    }
134
-
135
-    /**
136
-     * @param int $user
137
-     */
138
-    public function setUser($user)
139
-    {
140
-        $this->user = $user;
141
-    }
142
-
143
-    /**
144
-     * @return string
145
-     */
146
-    public function getComment()
147
-    {
148
-        return $this->comment;
149
-    }
150
-
151
-    /**
152
-     * @param string $comment
153
-     */
154
-    public function setComment($comment)
155
-    {
156
-        $this->comment = $comment;
157
-    }
158
-
159
-    /**
160
-     * @return string
161
-     */
162
-    public function getVisibility()
163
-    {
164
-        return $this->visibility;
165
-    }
166
-
167
-    /**
168
-     * @param string $visibility
169
-     */
170
-    public function setVisibility($visibility)
171
-    {
172
-        $this->visibility = $visibility;
173
-    }
174
-
175
-    /**
176
-     * @return int
177
-     */
178
-    public function getRequest()
179
-    {
180
-        return $this->request;
181
-    }
182
-
183
-    /**
184
-     * @param int $request
185
-     */
186
-    public function setRequest($request)
187
-    {
188
-        $this->request = $request;
189
-    }
99
+			);
100
+
101
+			$statement->bindValue(':id', $this->id);
102
+			$statement->bindValue(':updateversion', $this->updateversion);
103
+
104
+			$statement->bindValue(':comment', $this->comment);
105
+			$statement->bindValue(':visibility', $this->visibility);
106
+
107
+			if (!$statement->execute()) {
108
+				throw new Exception($statement->errorInfo());
109
+			}
110
+
111
+			if ($statement->rowCount() !== 1) {
112
+				throw new OptimisticLockFailedException();
113
+			}
114
+
115
+			$this->updateversion++;
116
+		}
117
+	}
118
+
119
+	/**
120
+	 * @return DateTimeImmutable
121
+	 */
122
+	public function getTime()
123
+	{
124
+		return new DateTimeImmutable($this->time);
125
+	}
126
+
127
+	/**
128
+	 * @return int
129
+	 */
130
+	public function getUser()
131
+	{
132
+		return $this->user;
133
+	}
134
+
135
+	/**
136
+	 * @param int $user
137
+	 */
138
+	public function setUser($user)
139
+	{
140
+		$this->user = $user;
141
+	}
142
+
143
+	/**
144
+	 * @return string
145
+	 */
146
+	public function getComment()
147
+	{
148
+		return $this->comment;
149
+	}
150
+
151
+	/**
152
+	 * @param string $comment
153
+	 */
154
+	public function setComment($comment)
155
+	{
156
+		$this->comment = $comment;
157
+	}
158
+
159
+	/**
160
+	 * @return string
161
+	 */
162
+	public function getVisibility()
163
+	{
164
+		return $this->visibility;
165
+	}
166
+
167
+	/**
168
+	 * @param string $visibility
169
+	 */
170
+	public function setVisibility($visibility)
171
+	{
172
+		$this->visibility = $visibility;
173
+	}
174
+
175
+	/**
176
+	 * @return int
177
+	 */
178
+	public function getRequest()
179
+	{
180
+		return $this->request;
181
+	}
182
+
183
+	/**
184
+	 * @param int $request
185
+	 */
186
+	public function setRequest($request)
187
+	{
188
+		$this->request = $request;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
includes/DataObjects/Ban.php 1 patch
Indentation   +239 added lines, -239 removed lines patch added patch discarded remove patch
@@ -19,267 +19,267 @@
 block discarded – undo
19 19
  */
20 20
 class Ban extends DataObject
21 21
 {
22
-    private $type;
23
-    private $target;
24
-    private $user;
25
-    private $reason;
26
-    private $date;
27
-    private $duration;
28
-    private $active;
29
-
30
-    /**
31
-     * Gets all active bans, filtered by the optional target.
32
-     *
33
-     * @param string|null $target
34
-     * @param PdoDatabase $database
35
-     *
36
-     * @return Ban[]
37
-     */
38
-    public static function getActiveBans($target, PdoDatabase $database)
39
-    {
40
-        if ($target !== null) {
41
-            $query = <<<SQL
22
+	private $type;
23
+	private $target;
24
+	private $user;
25
+	private $reason;
26
+	private $date;
27
+	private $duration;
28
+	private $active;
29
+
30
+	/**
31
+	 * Gets all active bans, filtered by the optional target.
32
+	 *
33
+	 * @param string|null $target
34
+	 * @param PdoDatabase $database
35
+	 *
36
+	 * @return Ban[]
37
+	 */
38
+	public static function getActiveBans($target, PdoDatabase $database)
39
+	{
40
+		if ($target !== null) {
41
+			$query = <<<SQL
42 42
 SELECT * FROM ban WHERE target = :target AND (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;
43 43
 SQL;
44
-            $statement = $database->prepare($query);
45
-            $statement->bindValue(":target", $target);
46
-        }
47
-        else {
48
-            $query = "SELECT * FROM ban WHERE (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;";
49
-            $statement = $database->prepare($query);
50
-        }
51
-
52
-        $statement->execute();
53
-
54
-        $result = array();
55
-
56
-        /** @var Ban $v */
57
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
58
-            $v->setDatabase($database);
59
-            $result[] = $v;
60
-        }
61
-
62
-        return $result;
63
-    }
64
-
65
-    /**
66
-     * Gets a ban by it's ID if it's currently active.
67
-     *
68
-     * @param     integer $id
69
-     * @param PdoDatabase $database
70
-     *
71
-     * @return Ban
72
-     */
73
-    public static function getActiveId($id, PdoDatabase $database)
74
-    {
75
-        $statement = $database->prepare(<<<SQL
44
+			$statement = $database->prepare($query);
45
+			$statement->bindValue(":target", $target);
46
+		}
47
+		else {
48
+			$query = "SELECT * FROM ban WHERE (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;";
49
+			$statement = $database->prepare($query);
50
+		}
51
+
52
+		$statement->execute();
53
+
54
+		$result = array();
55
+
56
+		/** @var Ban $v */
57
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
58
+			$v->setDatabase($database);
59
+			$result[] = $v;
60
+		}
61
+
62
+		return $result;
63
+	}
64
+
65
+	/**
66
+	 * Gets a ban by it's ID if it's currently active.
67
+	 *
68
+	 * @param     integer $id
69
+	 * @param PdoDatabase $database
70
+	 *
71
+	 * @return Ban
72
+	 */
73
+	public static function getActiveId($id, PdoDatabase $database)
74
+	{
75
+		$statement = $database->prepare(<<<SQL
76 76
 SELECT *
77 77
 FROM ban
78 78
 WHERE id = :id  AND (duration > UNIX_TIMESTAMP() OR duration = -1) AND active = 1;
79 79
 SQL
80
-        );
81
-        $statement->bindValue(":id", $id);
82
-
83
-        $statement->execute();
84
-
85
-        $resultObject = $statement->fetchObject(get_called_class());
86
-
87
-        if ($resultObject != false) {
88
-            $resultObject->setDatabase($database);
89
-        }
90
-
91
-        return $resultObject;
92
-    }
93
-
94
-    /**
95
-     * Get all active bans for a target and type.
96
-     *
97
-     * @param string      $target
98
-     * @param string      $type
99
-     * @param PdoDatabase $database
100
-     *
101
-     * @return Ban
102
-     */
103
-    public static function getBanByTarget($target, $type, PdoDatabase $database)
104
-    {
105
-        $query = <<<SQL
80
+		);
81
+		$statement->bindValue(":id", $id);
82
+
83
+		$statement->execute();
84
+
85
+		$resultObject = $statement->fetchObject(get_called_class());
86
+
87
+		if ($resultObject != false) {
88
+			$resultObject->setDatabase($database);
89
+		}
90
+
91
+		return $resultObject;
92
+	}
93
+
94
+	/**
95
+	 * Get all active bans for a target and type.
96
+	 *
97
+	 * @param string      $target
98
+	 * @param string      $type
99
+	 * @param PdoDatabase $database
100
+	 *
101
+	 * @return Ban
102
+	 */
103
+	public static function getBanByTarget($target, $type, PdoDatabase $database)
104
+	{
105
+		$query = <<<SQL
106 106
 SELECT * FROM ban
107 107
 WHERE type = :type
108 108
 	AND target = :target
109 109
 	AND (duration > UNIX_TIMESTAMP() OR duration = -1)
110 110
 	AND active = 1;
111 111
 SQL;
112
-        $statement = $database->prepare($query);
113
-        $statement->bindValue(":target", $target);
114
-        $statement->bindValue(":type", $type);
112
+		$statement = $database->prepare($query);
113
+		$statement->bindValue(":target", $target);
114
+		$statement->bindValue(":type", $type);
115 115
 
116
-        $statement->execute();
116
+		$statement->execute();
117 117
 
118
-        $resultObject = $statement->fetchObject(get_called_class());
118
+		$resultObject = $statement->fetchObject(get_called_class());
119 119
 
120
-        if ($resultObject != false) {
121
-            $resultObject->setDatabase($database);
122
-        }
120
+		if ($resultObject != false) {
121
+			$resultObject->setDatabase($database);
122
+		}
123 123
 
124
-        return $resultObject;
125
-    }
124
+		return $resultObject;
125
+	}
126 126
 
127
-    /**
128
-     * @throws Exception
129
-     */
130
-    public function save()
131
-    {
132
-        if ($this->isNew()) {
133
-            // insert
134
-            $statement = $this->dbObject->prepare(<<<SQL
127
+	/**
128
+	 * @throws Exception
129
+	 */
130
+	public function save()
131
+	{
132
+		if ($this->isNew()) {
133
+			// insert
134
+			$statement = $this->dbObject->prepare(<<<SQL
135 135
 INSERT INTO `ban` (type, target, user, reason, date, duration, active)
136 136
 VALUES (:type, :target, :user, :reason, CURRENT_TIMESTAMP(), :duration, :active);
137 137
 SQL
138
-            );
139
-            $statement->bindValue(":type", $this->type);
140
-            $statement->bindValue(":target", $this->target);
141
-            $statement->bindValue(":user", $this->user);
142
-            $statement->bindValue(":reason", $this->reason);
143
-            $statement->bindValue(":duration", $this->duration);
144
-            $statement->bindValue(":active", $this->active);
145
-
146
-            if ($statement->execute()) {
147
-                $this->id = (int)$this->dbObject->lastInsertId();
148
-            }
149
-            else {
150
-                throw new Exception($statement->errorInfo());
151
-            }
152
-        }
153
-        else {
154
-            // update
155
-            $statement = $this->dbObject->prepare(<<<SQL
138
+			);
139
+			$statement->bindValue(":type", $this->type);
140
+			$statement->bindValue(":target", $this->target);
141
+			$statement->bindValue(":user", $this->user);
142
+			$statement->bindValue(":reason", $this->reason);
143
+			$statement->bindValue(":duration", $this->duration);
144
+			$statement->bindValue(":active", $this->active);
145
+
146
+			if ($statement->execute()) {
147
+				$this->id = (int)$this->dbObject->lastInsertId();
148
+			}
149
+			else {
150
+				throw new Exception($statement->errorInfo());
151
+			}
152
+		}
153
+		else {
154
+			// update
155
+			$statement = $this->dbObject->prepare(<<<SQL
156 156
 UPDATE `ban`
157 157
 SET duration = :duration, active = :active, user = :user, updateversion = updateversion + 1
158 158
 WHERE id = :id AND updateversion = :updateversion;
159 159
 SQL
160
-            );
161
-            $statement->bindValue(':id', $this->id);
162
-            $statement->bindValue(':updateversion', $this->updateversion);
163
-
164
-            $statement->bindValue(':duration', $this->duration);
165
-            $statement->bindValue(':active', $this->active);
166
-            $statement->bindValue(':user', $this->user);
167
-
168
-            if (!$statement->execute()) {
169
-                throw new Exception($statement->errorInfo());
170
-            }
171
-
172
-            if ($statement->rowCount() !== 1) {
173
-                throw new OptimisticLockFailedException();
174
-            }
175
-
176
-            $this->updateversion++;
177
-        }
178
-    }
179
-
180
-    /**
181
-     * @return string
182
-     */
183
-    public function getType()
184
-    {
185
-        return $this->type;
186
-    }
187
-
188
-    /**
189
-     * @param string $type
190
-     */
191
-    public function setType($type)
192
-    {
193
-        $this->type = $type;
194
-    }
195
-
196
-    /**
197
-     * @return string
198
-     */
199
-    public function getTarget()
200
-    {
201
-        return $this->target;
202
-    }
203
-
204
-    /**
205
-     * @param string $target
206
-     */
207
-    public function setTarget($target)
208
-    {
209
-        $this->target = $target;
210
-    }
211
-
212
-    /**
213
-     * @return string
214
-     */
215
-    public function getReason()
216
-    {
217
-        return $this->reason;
218
-    }
219
-
220
-    /**
221
-     * @param string $reason
222
-     */
223
-    public function setReason($reason)
224
-    {
225
-        $this->reason = $reason;
226
-    }
227
-
228
-    /**
229
-     * @return mixed
230
-     */
231
-    public function getDate()
232
-    {
233
-        return $this->date;
234
-    }
235
-
236
-    /**
237
-     * @return mixed
238
-     */
239
-    public function getDuration()
240
-    {
241
-        return $this->duration;
242
-    }
243
-
244
-    /**
245
-     * @param mixed $duration
246
-     */
247
-    public function setDuration($duration)
248
-    {
249
-        $this->duration = $duration;
250
-    }
251
-
252
-    /**
253
-     * @return bool
254
-     */
255
-    public function isActive()
256
-    {
257
-        return $this->active == 1;
258
-    }
259
-
260
-    /**
261
-     * @param bool $active
262
-     */
263
-    public function setActive($active)
264
-    {
265
-        $this->active = $active ? 1 : 0;
266
-    }
267
-
268
-    /**
269
-     * @return int
270
-     */
271
-    public function getUser()
272
-    {
273
-        return $this->user;
274
-    }
275
-
276
-    /**
277
-     * @param int $user UserID of user who is setting the ban
278
-     *
279
-     * @throws Exception
280
-     */
281
-    public function setUser($user)
282
-    {
283
-        $this->user = $user;
284
-    }
160
+			);
161
+			$statement->bindValue(':id', $this->id);
162
+			$statement->bindValue(':updateversion', $this->updateversion);
163
+
164
+			$statement->bindValue(':duration', $this->duration);
165
+			$statement->bindValue(':active', $this->active);
166
+			$statement->bindValue(':user', $this->user);
167
+
168
+			if (!$statement->execute()) {
169
+				throw new Exception($statement->errorInfo());
170
+			}
171
+
172
+			if ($statement->rowCount() !== 1) {
173
+				throw new OptimisticLockFailedException();
174
+			}
175
+
176
+			$this->updateversion++;
177
+		}
178
+	}
179
+
180
+	/**
181
+	 * @return string
182
+	 */
183
+	public function getType()
184
+	{
185
+		return $this->type;
186
+	}
187
+
188
+	/**
189
+	 * @param string $type
190
+	 */
191
+	public function setType($type)
192
+	{
193
+		$this->type = $type;
194
+	}
195
+
196
+	/**
197
+	 * @return string
198
+	 */
199
+	public function getTarget()
200
+	{
201
+		return $this->target;
202
+	}
203
+
204
+	/**
205
+	 * @param string $target
206
+	 */
207
+	public function setTarget($target)
208
+	{
209
+		$this->target = $target;
210
+	}
211
+
212
+	/**
213
+	 * @return string
214
+	 */
215
+	public function getReason()
216
+	{
217
+		return $this->reason;
218
+	}
219
+
220
+	/**
221
+	 * @param string $reason
222
+	 */
223
+	public function setReason($reason)
224
+	{
225
+		$this->reason = $reason;
226
+	}
227
+
228
+	/**
229
+	 * @return mixed
230
+	 */
231
+	public function getDate()
232
+	{
233
+		return $this->date;
234
+	}
235
+
236
+	/**
237
+	 * @return mixed
238
+	 */
239
+	public function getDuration()
240
+	{
241
+		return $this->duration;
242
+	}
243
+
244
+	/**
245
+	 * @param mixed $duration
246
+	 */
247
+	public function setDuration($duration)
248
+	{
249
+		$this->duration = $duration;
250
+	}
251
+
252
+	/**
253
+	 * @return bool
254
+	 */
255
+	public function isActive()
256
+	{
257
+		return $this->active == 1;
258
+	}
259
+
260
+	/**
261
+	 * @param bool $active
262
+	 */
263
+	public function setActive($active)
264
+	{
265
+		$this->active = $active ? 1 : 0;
266
+	}
267
+
268
+	/**
269
+	 * @return int
270
+	 */
271
+	public function getUser()
272
+	{
273
+		return $this->user;
274
+	}
275
+
276
+	/**
277
+	 * @param int $user UserID of user who is setting the ban
278
+	 *
279
+	 * @throws Exception
280
+	 */
281
+	public function setUser($user)
282
+	{
283
+		$this->user = $user;
284
+	}
285 285
 }
Please login to merge, or discard this patch.
includes/DataObject.php 1 patch
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -23,124 +23,124 @@
 block discarded – undo
23 23
  */
24 24
 abstract class DataObject
25 25
 {
26
-    /** @var int ID of the object */
27
-    protected $id = null;
28
-    /** @var int update version for optimistic locking */
29
-    protected $updateversion = 0;
30
-    /**
31
-     * @var PdoDatabase
32
-     */
33
-    protected $dbObject;
34
-
35
-    /**
36
-     * Retrieves a data object by it's row ID.
37
-     *
38
-     * @param int         $id
39
-     * @param PdoDatabase $database
40
-     *
41
-     * @return DataObject|false
42
-     */
43
-    public static function getById($id, PdoDatabase $database)
44
-    {
45
-        $array = explode('\\', get_called_class());
46
-        $realClassName = strtolower(end($array));
47
-
48
-        $statement = $database->prepare("SELECT * FROM {$realClassName} WHERE id = :id LIMIT 1;");
49
-        $statement->bindValue(":id", $id);
50
-
51
-        $statement->execute();
52
-
53
-        $resultObject = $statement->fetchObject(get_called_class());
54
-
55
-        if ($resultObject != false) {
56
-            $resultObject->setDatabase($database);
57
-        }
58
-
59
-        return $resultObject;
60
-    }
61
-
62
-    public function setDatabase(PdoDatabase $db)
63
-    {
64
-        $this->dbObject = $db;
65
-    }
66
-
67
-    /**
68
-     * Gets the database associated with this data object.
69
-     * @return PdoDatabase
70
-     */
71
-    public function getDatabase()
72
-    {
73
-        return $this->dbObject;
74
-    }
75
-
76
-    /**
77
-     * Saves a data object to the database, either updating or inserting a record.
78
-     *
79
-     * @return void
80
-     */
81
-    abstract public function save();
82
-
83
-    /**
84
-     * Retrieves the ID attribute
85
-     */
86
-    public function getId()
87
-    {
88
-        return (int)$this->id;
89
-    }
90
-
91
-    /**
92
-     * Deletes the object from the database
93
-     */
94
-    public function delete()
95
-    {
96
-        if ($this->id === null) {
97
-            // wtf?
98
-            return;
99
-        }
100
-
101
-        $array = explode('\\', get_called_class());
102
-        $realClassName = strtolower(end($array));
103
-
104
-        $deleteQuery = "DELETE FROM {$realClassName} WHERE id = :id AND updateversion = :updateversion;";
105
-        $statement = $this->dbObject->prepare($deleteQuery);
106
-
107
-        $statement->bindValue(":id", $this->id);
108
-        $statement->bindValue(":updateversion", $this->updateversion);
109
-        $statement->execute();
110
-
111
-        if ($statement->rowCount() !== 1) {
112
-            throw new OptimisticLockFailedException();
113
-        }
114
-
115
-        $this->id = null;
116
-    }
117
-
118
-    /**
119
-     * @return int
120
-     */
121
-    public function getUpdateVersion()
122
-    {
123
-        return $this->updateversion;
124
-    }
125
-
126
-    /**
127
-     * Sets the update version.
128
-     *
129
-     * You should never call this to change the value of the update version. You should only call it when passing user
130
-     * input through.
131
-     *
132
-     * @param int $updateVersion
133
-     */
134
-    public function setUpdateVersion($updateVersion)
135
-    {
136
-        $this->updateversion = $updateVersion;
137
-    }
138
-
139
-    /**
140
-     * @return bool
141
-     */
142
-    public function isNew()
143
-    {
144
-        return $this->id === null;
145
-    }
26
+	/** @var int ID of the object */
27
+	protected $id = null;
28
+	/** @var int update version for optimistic locking */
29
+	protected $updateversion = 0;
30
+	/**
31
+	 * @var PdoDatabase
32
+	 */
33
+	protected $dbObject;
34
+
35
+	/**
36
+	 * Retrieves a data object by it's row ID.
37
+	 *
38
+	 * @param int         $id
39
+	 * @param PdoDatabase $database
40
+	 *
41
+	 * @return DataObject|false
42
+	 */
43
+	public static function getById($id, PdoDatabase $database)
44
+	{
45
+		$array = explode('\\', get_called_class());
46
+		$realClassName = strtolower(end($array));
47
+
48
+		$statement = $database->prepare("SELECT * FROM {$realClassName} WHERE id = :id LIMIT 1;");
49
+		$statement->bindValue(":id", $id);
50
+
51
+		$statement->execute();
52
+
53
+		$resultObject = $statement->fetchObject(get_called_class());
54
+
55
+		if ($resultObject != false) {
56
+			$resultObject->setDatabase($database);
57
+		}
58
+
59
+		return $resultObject;
60
+	}
61
+
62
+	public function setDatabase(PdoDatabase $db)
63
+	{
64
+		$this->dbObject = $db;
65
+	}
66
+
67
+	/**
68
+	 * Gets the database associated with this data object.
69
+	 * @return PdoDatabase
70
+	 */
71
+	public function getDatabase()
72
+	{
73
+		return $this->dbObject;
74
+	}
75
+
76
+	/**
77
+	 * Saves a data object to the database, either updating or inserting a record.
78
+	 *
79
+	 * @return void
80
+	 */
81
+	abstract public function save();
82
+
83
+	/**
84
+	 * Retrieves the ID attribute
85
+	 */
86
+	public function getId()
87
+	{
88
+		return (int)$this->id;
89
+	}
90
+
91
+	/**
92
+	 * Deletes the object from the database
93
+	 */
94
+	public function delete()
95
+	{
96
+		if ($this->id === null) {
97
+			// wtf?
98
+			return;
99
+		}
100
+
101
+		$array = explode('\\', get_called_class());
102
+		$realClassName = strtolower(end($array));
103
+
104
+		$deleteQuery = "DELETE FROM {$realClassName} WHERE id = :id AND updateversion = :updateversion;";
105
+		$statement = $this->dbObject->prepare($deleteQuery);
106
+
107
+		$statement->bindValue(":id", $this->id);
108
+		$statement->bindValue(":updateversion", $this->updateversion);
109
+		$statement->execute();
110
+
111
+		if ($statement->rowCount() !== 1) {
112
+			throw new OptimisticLockFailedException();
113
+		}
114
+
115
+		$this->id = null;
116
+	}
117
+
118
+	/**
119
+	 * @return int
120
+	 */
121
+	public function getUpdateVersion()
122
+	{
123
+		return $this->updateversion;
124
+	}
125
+
126
+	/**
127
+	 * Sets the update version.
128
+	 *
129
+	 * You should never call this to change the value of the update version. You should only call it when passing user
130
+	 * input through.
131
+	 *
132
+	 * @param int $updateVersion
133
+	 */
134
+	public function setUpdateVersion($updateVersion)
135
+	{
136
+		$this->updateversion = $updateVersion;
137
+	}
138
+
139
+	/**
140
+	 * @return bool
141
+	 */
142
+	public function isNew()
143
+	{
144
+		return $this->id === null;
145
+	}
146 146
 }
Please login to merge, or discard this patch.
includes/Pages/Statistics/StatsInactiveUsers.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -17,31 +17,31 @@
 block discarded – undo
17 17
 
18 18
 class StatsInactiveUsers extends InternalPageBase
19 19
 {
20
-    public function main()
21
-    {
22
-        $this->setHtmlTitle('Inactive Users :: Statistics');
23
-
24
-        $date = new DateTime();
25
-        $date->modify("-90 days");
26
-
27
-        $inactiveUsers = UserSearchHelper::get($this->getDatabase())
28
-            ->byStatus('Active')
29
-            ->lastActiveBefore($date)
30
-            ->getRoleMap($roleMap)
31
-            ->fetch();
32
-
33
-        $this->assign('inactiveUsers', $inactiveUsers);
34
-        $this->assign('roles', $roleMap);
35
-        $this->assign('canSuspend',
36
-            $this->barrierTest('suspend', User::getCurrent($this->getDatabase()), PageUserManagement::class));
37
-
38
-        $immuneUsers = $this->getDatabase()
39
-            ->query("SELECT user FROM userrole WHERE role IN ('toolRoot', 'checkuser') GROUP BY user;")
40
-            ->fetchAll(PDO::FETCH_COLUMN);
20
+	public function main()
21
+	{
22
+		$this->setHtmlTitle('Inactive Users :: Statistics');
23
+
24
+		$date = new DateTime();
25
+		$date->modify("-90 days");
26
+
27
+		$inactiveUsers = UserSearchHelper::get($this->getDatabase())
28
+			->byStatus('Active')
29
+			->lastActiveBefore($date)
30
+			->getRoleMap($roleMap)
31
+			->fetch();
32
+
33
+		$this->assign('inactiveUsers', $inactiveUsers);
34
+		$this->assign('roles', $roleMap);
35
+		$this->assign('canSuspend',
36
+			$this->barrierTest('suspend', User::getCurrent($this->getDatabase()), PageUserManagement::class));
37
+
38
+		$immuneUsers = $this->getDatabase()
39
+			->query("SELECT user FROM userrole WHERE role IN ('toolRoot', 'checkuser') GROUP BY user;")
40
+			->fetchAll(PDO::FETCH_COLUMN);
41 41
         
42
-        $this->assign('immune', array_fill_keys($immuneUsers, true));
42
+		$this->assign('immune', array_fill_keys($immuneUsers, true));
43 43
 
44
-        $this->setTemplate('statistics/inactive-users.tpl');
45
-        $this->assign('statsPageTitle', 'Inactive tool users');
46
-    }
44
+		$this->setTemplate('statistics/inactive-users.tpl');
45
+		$this->assign('statsPageTitle', 'Inactive tool users');
46
+	}
47 47
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageCloseRequest.php 1 patch
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -21,227 +21,227 @@
 block discarded – undo
21 21
 
22 22
 class PageCloseRequest extends RequestActionBase
23 23
 {
24
-    protected function main()
25
-    {
26
-        $this->processClose();
27
-    }
28
-
29
-    /**
30
-     * Main function for this page, when no specific actions are called.
31
-     * @throws ApplicationLogicException
32
-     */
33
-    final protected function processClose()
34
-    {
35
-        $this->checkPosted();
36
-        $database = $this->getDatabase();
37
-
38
-        $currentUser = User::getCurrent($database);
39
-        $template = $this->getTemplate($database);
40
-        $request = $this->getRequest($database);
41
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
42
-
43
-        if ($request->getStatus() === 'Closed') {
44
-            throw new ApplicationLogicException('Request is already closed');
45
-        }
46
-
47
-        if ($this->confirmEmailAlreadySent($request, $template)) {
48
-            return;
49
-        }
50
-
51
-        if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) {
52
-            return;
53
-        }
54
-
55
-        if ($this->confirmAccountCreated($request, $template)) {
56
-            return;
57
-        }
58
-
59
-        // I think we're good here...
60
-        $request->setStatus('Closed');
61
-        $request->setReserved(null);
62
-
63
-        Logger::closeRequest($database, $request, $template->getId(), null);
64
-
65
-        $request->save();
66
-
67
-        if ($currentUser->getWelcomeTemplate() !== null) {
68
-            $this->enqueueWelcomeTask($request, null, $currentUser, $database);
69
-        }
70
-
71
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
72
-        // be rolled back.
73
-
74
-        $this->getNotificationHelper()->requestClosed($request, $template->getName());
75
-        $sanitisedTemplateName = htmlentities($template->getName(), ENT_COMPAT, 'UTF-8');
76
-        SessionAlert::success("Request {$request->getId()} has been closed as {$sanitisedTemplateName}");
77
-
78
-        $this->sendMail($request, $template->getText(), $currentUser, false);
79
-
80
-        $this->redirect();
81
-    }
82
-
83
-    /**
84
-     * @param PdoDatabase $database
85
-     *
86
-     * @return EmailTemplate
87
-     * @throws ApplicationLogicException
88
-     */
89
-    protected function getTemplate(PdoDatabase $database)
90
-    {
91
-        $templateId = WebRequest::postInt('template');
92
-        if ($templateId === null) {
93
-            throw new ApplicationLogicException('No template specified');
94
-        }
95
-
96
-        /** @var EmailTemplate $template */
97
-        $template = EmailTemplate::getById($templateId, $database);
98
-        if ($template === false || !$template->getActive()) {
99
-            throw new ApplicationLogicException('Invalid or inactive template specified');
100
-        }
101
-
102
-        return $template;
103
-    }
104
-
105
-    /**
106
-     * @param Request       $request
107
-     * @param EmailTemplate $template
108
-     *
109
-     * @return bool
110
-     */
111
-    protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
112
-    {
113
-        if ($this->checkEmailAlreadySent($request)) {
114
-            $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl');
115
-
116
-            return true;
117
-        }
118
-
119
-        return false;
120
-    }
121
-
122
-    protected function checkEmailAlreadySent(Request $request)
123
-    {
124
-        if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) {
125
-            return true;
126
-        }
127
-
128
-        return false;
129
-    }
130
-
131
-    protected function checkReserveOverride(Request $request, User $currentUser)
132
-    {
133
-        $reservationId = $request->getReserved();
134
-
135
-        if ($reservationId !== 0 && $reservationId !== null) {
136
-            if (!WebRequest::postBoolean('reserveOverride')) {
137
-                if ($currentUser->getId() !== $reservationId) {
138
-                    return true;
139
-                }
140
-            }
141
-        }
142
-
143
-        return false;
144
-    }
145
-
146
-    /**
147
-     * @param Request       $request
148
-     * @param EmailTemplate $template
149
-     * @param User          $currentUser
150
-     * @param PdoDatabase   $database
151
-     *
152
-     * @return bool
153
-     */
154
-    protected function confirmReserveOverride(
155
-        Request $request,
156
-        EmailTemplate $template,
157
-        User $currentUser,
158
-        PdoDatabase $database
159
-    ) {
160
-        if ($this->checkReserveOverride($request, $currentUser)) {
161
-            $this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername());
162
-            $this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl');
163
-
164
-            return true;
165
-        }
166
-
167
-        return false;
168
-    }
169
-
170
-    /**
171
-     * @param Request       $request
172
-     * @param EmailTemplate $template
173
-     *
174
-     * @return bool
175
-     * @throws \Waca\Exceptions\CurlException
176
-     */
177
-    protected function confirmAccountCreated(Request $request, EmailTemplate $template)
178
-    {
179
-        if ($this->checkAccountCreated($request, $template)) {
180
-            $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl');
181
-
182
-            return true;
183
-        }
184
-
185
-        return false;
186
-    }
187
-
188
-    protected function checkAccountCreated(Request $request, EmailTemplate $template)
189
-    {
190
-        if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) {
191
-            $parameters = array(
192
-                'action'  => 'query',
193
-                'list'    => 'users',
194
-                'format'  => 'php',
195
-                'ususers' => $request->getName(),
196
-            );
197
-
198
-            $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(),
199
-                $parameters);
200
-
201
-            $apiResult = unserialize($content);
202
-            $exists = !isset($apiResult['query']['users']['0']['missing']);
203
-
204
-            if (!$exists) {
205
-                return true;
206
-            }
207
-        }
208
-
209
-        return false;
210
-    }
211
-
212
-    /**
213
-     * @param Request $request
214
-     * @param string  $mailText
215
-     * @param User    $currentUser
216
-     * @param boolean $ccMailingList
217
-     */
218
-    protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList)
219
-    {
220
-        $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper());
221
-        $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList);
222
-    }
223
-
224
-    /**
225
-     * @param Request       $request
226
-     * @param EmailTemplate $template
227
-     * @param string        $templateName
228
-     *
229
-     * @throws Exception
230
-     * @return void
231
-     */
232
-    protected function showConfirmation(Request $request, EmailTemplate $template, $templateName)
233
-    {
234
-        $this->assignCSRFToken();
235
-
236
-        $this->assign('request', $request->getId());
237
-        $this->assign('template', $template->getId());
238
-
239
-        $this->assign('updateversion', $request->getUpdateVersion());
240
-
241
-        $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false');
242
-        $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false');
243
-        $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false');
244
-
245
-        $this->setTemplate($templateName);
246
-    }
24
+	protected function main()
25
+	{
26
+		$this->processClose();
27
+	}
28
+
29
+	/**
30
+	 * Main function for this page, when no specific actions are called.
31
+	 * @throws ApplicationLogicException
32
+	 */
33
+	final protected function processClose()
34
+	{
35
+		$this->checkPosted();
36
+		$database = $this->getDatabase();
37
+
38
+		$currentUser = User::getCurrent($database);
39
+		$template = $this->getTemplate($database);
40
+		$request = $this->getRequest($database);
41
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
42
+
43
+		if ($request->getStatus() === 'Closed') {
44
+			throw new ApplicationLogicException('Request is already closed');
45
+		}
46
+
47
+		if ($this->confirmEmailAlreadySent($request, $template)) {
48
+			return;
49
+		}
50
+
51
+		if ($this->confirmReserveOverride($request, $template, $currentUser, $database)) {
52
+			return;
53
+		}
54
+
55
+		if ($this->confirmAccountCreated($request, $template)) {
56
+			return;
57
+		}
58
+
59
+		// I think we're good here...
60
+		$request->setStatus('Closed');
61
+		$request->setReserved(null);
62
+
63
+		Logger::closeRequest($database, $request, $template->getId(), null);
64
+
65
+		$request->save();
66
+
67
+		if ($currentUser->getWelcomeTemplate() !== null) {
68
+			$this->enqueueWelcomeTask($request, null, $currentUser, $database);
69
+		}
70
+
71
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
72
+		// be rolled back.
73
+
74
+		$this->getNotificationHelper()->requestClosed($request, $template->getName());
75
+		$sanitisedTemplateName = htmlentities($template->getName(), ENT_COMPAT, 'UTF-8');
76
+		SessionAlert::success("Request {$request->getId()} has been closed as {$sanitisedTemplateName}");
77
+
78
+		$this->sendMail($request, $template->getText(), $currentUser, false);
79
+
80
+		$this->redirect();
81
+	}
82
+
83
+	/**
84
+	 * @param PdoDatabase $database
85
+	 *
86
+	 * @return EmailTemplate
87
+	 * @throws ApplicationLogicException
88
+	 */
89
+	protected function getTemplate(PdoDatabase $database)
90
+	{
91
+		$templateId = WebRequest::postInt('template');
92
+		if ($templateId === null) {
93
+			throw new ApplicationLogicException('No template specified');
94
+		}
95
+
96
+		/** @var EmailTemplate $template */
97
+		$template = EmailTemplate::getById($templateId, $database);
98
+		if ($template === false || !$template->getActive()) {
99
+			throw new ApplicationLogicException('Invalid or inactive template specified');
100
+		}
101
+
102
+		return $template;
103
+	}
104
+
105
+	/**
106
+	 * @param Request       $request
107
+	 * @param EmailTemplate $template
108
+	 *
109
+	 * @return bool
110
+	 */
111
+	protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template)
112
+	{
113
+		if ($this->checkEmailAlreadySent($request)) {
114
+			$this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl');
115
+
116
+			return true;
117
+		}
118
+
119
+		return false;
120
+	}
121
+
122
+	protected function checkEmailAlreadySent(Request $request)
123
+	{
124
+		if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) {
125
+			return true;
126
+		}
127
+
128
+		return false;
129
+	}
130
+
131
+	protected function checkReserveOverride(Request $request, User $currentUser)
132
+	{
133
+		$reservationId = $request->getReserved();
134
+
135
+		if ($reservationId !== 0 && $reservationId !== null) {
136
+			if (!WebRequest::postBoolean('reserveOverride')) {
137
+				if ($currentUser->getId() !== $reservationId) {
138
+					return true;
139
+				}
140
+			}
141
+		}
142
+
143
+		return false;
144
+	}
145
+
146
+	/**
147
+	 * @param Request       $request
148
+	 * @param EmailTemplate $template
149
+	 * @param User          $currentUser
150
+	 * @param PdoDatabase   $database
151
+	 *
152
+	 * @return bool
153
+	 */
154
+	protected function confirmReserveOverride(
155
+		Request $request,
156
+		EmailTemplate $template,
157
+		User $currentUser,
158
+		PdoDatabase $database
159
+	) {
160
+		if ($this->checkReserveOverride($request, $currentUser)) {
161
+			$this->assign('reserveUser', User::getById($request->getReserved(), $database)->getUsername());
162
+			$this->showConfirmation($request, $template, 'close-confirmations/reserve-override.tpl');
163
+
164
+			return true;
165
+		}
166
+
167
+		return false;
168
+	}
169
+
170
+	/**
171
+	 * @param Request       $request
172
+	 * @param EmailTemplate $template
173
+	 *
174
+	 * @return bool
175
+	 * @throws \Waca\Exceptions\CurlException
176
+	 */
177
+	protected function confirmAccountCreated(Request $request, EmailTemplate $template)
178
+	{
179
+		if ($this->checkAccountCreated($request, $template)) {
180
+			$this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl');
181
+
182
+			return true;
183
+		}
184
+
185
+		return false;
186
+	}
187
+
188
+	protected function checkAccountCreated(Request $request, EmailTemplate $template)
189
+	{
190
+		if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) {
191
+			$parameters = array(
192
+				'action'  => 'query',
193
+				'list'    => 'users',
194
+				'format'  => 'php',
195
+				'ususers' => $request->getName(),
196
+			);
197
+
198
+			$content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(),
199
+				$parameters);
200
+
201
+			$apiResult = unserialize($content);
202
+			$exists = !isset($apiResult['query']['users']['0']['missing']);
203
+
204
+			if (!$exists) {
205
+				return true;
206
+			}
207
+		}
208
+
209
+		return false;
210
+	}
211
+
212
+	/**
213
+	 * @param Request $request
214
+	 * @param string  $mailText
215
+	 * @param User    $currentUser
216
+	 * @param boolean $ccMailingList
217
+	 */
218
+	protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList)
219
+	{
220
+		$requestEmailHelper = new RequestEmailHelper($this->getEmailHelper());
221
+		$requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList);
222
+	}
223
+
224
+	/**
225
+	 * @param Request       $request
226
+	 * @param EmailTemplate $template
227
+	 * @param string        $templateName
228
+	 *
229
+	 * @throws Exception
230
+	 * @return void
231
+	 */
232
+	protected function showConfirmation(Request $request, EmailTemplate $template, $templateName)
233
+	{
234
+		$this->assignCSRFToken();
235
+
236
+		$this->assign('request', $request->getId());
237
+		$this->assign('template', $template->getId());
238
+
239
+		$this->assign('updateversion', $request->getUpdateVersion());
240
+
241
+		$this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false');
242
+		$this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false');
243
+		$this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false');
244
+
245
+		$this->setTemplate($templateName);
246
+	}
247 247
 }
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageCustomClose.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -23,264 +23,264 @@
 block discarded – undo
23 23
 
24 24
 class PageCustomClose extends PageCloseRequest
25 25
 {
26
-    use RequestData;
27
-
28
-    protected function main()
29
-    {
30
-        $database = $this->getDatabase();
31
-
32
-        $request = $this->getRequest($database);
33
-        $currentUser = User::getCurrent($this->getDatabase());
34
-
35
-        if ($request->getStatus() === 'Closed') {
36
-            throw new ApplicationLogicException('Request is already closed');
37
-        }
38
-
39
-        // Dual-mode page
40
-        if (WebRequest::wasPosted()) {
41
-            $this->validateCSRFToken();
42
-            $this->doCustomClose($currentUser, $request, $database);
43
-
44
-            $this->redirect();
45
-        }
46
-        else {
47
-            $this->assignCSRFToken();
48
-            $this->showCustomCloseForm($database, $request);
49
-        }
50
-    }
51
-
52
-    /**
53
-     * @param $database
54
-     *
55
-     * @return Request
56
-     * @throws ApplicationLogicException
57
-     */
58
-    protected function getRequest(PdoDatabase $database)
59
-    {
60
-        $requestId = WebRequest::getInt('request');
61
-        if ($requestId === null) {
62
-            throw new ApplicationLogicException('Request ID not found');
63
-        }
64
-
65
-        /** @var Request $request */
66
-        $request = Request::getById($requestId, $database);
67
-
68
-        if ($request === false) {
69
-            throw new ApplicationLogicException('Request not found');
70
-        }
71
-
72
-        return $request;
73
-    }
74
-
75
-    /**
76
-     * @param PdoDatabase $database
77
-     *
78
-     * @return EmailTemplate|null
79
-     */
80
-    protected function getTemplate(PdoDatabase $database)
81
-    {
82
-        $templateId = WebRequest::getInt('template');
83
-        if ($templateId === null) {
84
-            return null;
85
-        }
86
-
87
-        /** @var EmailTemplate $template */
88
-        $template = EmailTemplate::getById($templateId, $database);
89
-        if ($template === false || !$template->getActive()) {
90
-            return null;
91
-        }
92
-
93
-        return $template;
94
-    }
95
-
96
-    /**
97
-     * @param $database
98
-     * @param $request
99
-     *
100
-     * @throws Exception
101
-     */
102
-    protected function showCustomCloseForm(PdoDatabase $database, Request $request)
103
-    {
104
-        $currentUser = User::getCurrent($database);
105
-        $config = $this->getSiteConfiguration();
106
-
107
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
108
-        if (!$allowedPrivateData) {
109
-            // we probably shouldn't be showing the user this form if they're not allowed to access private data...
110
-            throw new AccessDeniedException($this->getSecurityManager());
111
-        }
112
-
113
-        $template = $this->getTemplate($database);
114
-
115
-        // Preload data
116
-        $this->assign('defaultAction', '');
117
-        $this->assign('preloadText', '');
118
-        $this->assign('preloadTitle', '');
119
-
120
-        if ($template !== null) {
121
-            $this->assign('defaultAction', $template->getDefaultAction());
122
-            $this->assign('preloadText', $template->getText());
123
-            $this->assign('preloadTitle', $template->getName());
124
-        }
125
-
126
-        // Static data
127
-        $this->assign('requeststates', $config->getRequestStates());
128
-
129
-        // request data
130
-        $this->assign('requestId', $request->getIp());
131
-        $this->assign('updateVersion', $request->getUpdateVersion());
132
-        $this->setupBasicData($request, $config);
133
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
134
-        $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
135
-
136
-        // IP location
137
-        $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
138
-        $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp));
139
-
140
-        // Confirmations
141
-        $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request));
142
-        $this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser));
143
-
144
-        $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser));
145
-
146
-        // template
147
-        $this->setTemplate('custom-close.tpl');
148
-    }
149
-
150
-    /**
151
-     * @param User        $currentUser
152
-     * @param Request     $request
153
-     * @param PdoDatabase $database
154
-     *
155
-     * @throws ApplicationLogicException
156
-     */
157
-    protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database)
158
-    {
159
-        $messageBody = WebRequest::postString('msgbody');
160
-        if ($messageBody === null || trim($messageBody) === '') {
161
-            throw new ApplicationLogicException('Message body cannot be blank');
162
-        }
163
-
164
-        $ccMailingList = true;
165
-        if ($this->barrierTest('skipCcMailingList', $currentUser)) {
166
-            $ccMailingList = WebRequest::postBoolean('ccMailingList');
167
-        }
168
-
169
-        if ($request->getStatus() === 'Closed') {
170
-            throw new ApplicationLogicException('Request is already closed');
171
-        }
172
-
173
-        if (!(WebRequest::postBoolean('confirmEmailAlreadySent')
174
-            && WebRequest::postBoolean('confirmReserveOverride'))
175
-        ) {
176
-            throw new ApplicationLogicException('Not all confirmations checked');
177
-        }
178
-
179
-        $action = WebRequest::postString('action');
180
-        $availableRequestStates = $this->getSiteConfiguration()->getRequestStates();
181
-
182
-        if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) {
183
-            // Close request
184
-            $this->closeRequest($request, $database, $action, $messageBody);
185
-
186
-            // Send the mail after the save, since save can be rolled back
187
-            $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
-        }
189
-        else {
190
-            if (array_key_exists($action, $availableRequestStates)) {
191
-                // Defer to other state
192
-                $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193
-
194
-                // Send the mail after the save, since save can be rolled back
195
-                $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
-            }
197
-            else {
198
-                $request->setReserved(null);
199
-                $request->setUpdateVersion(WebRequest::postInt('updateversion'));
200
-                $request->save();
201
-
202
-                // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
203
-                // and be rolled back.
204
-
205
-                // Send mail
206
-                $this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
207
-
208
-                Logger::sentMail($database, $request, $messageBody);
209
-                Logger::unreserve($database, $request);
210
-
211
-                $this->getNotificationHelper()->sentMail($request);
212
-                SessionAlert::success("Sent mail to Request {$request->getId()}");
213
-            }
214
-        }
215
-    }
216
-
217
-    /**
218
-     * @param Request     $request
219
-     * @param PdoDatabase $database
220
-     * @param string      $action
221
-     * @param string      $messageBody
222
-     *
223
-     * @throws Exception
224
-     * @throws OptimisticLockFailedException
225
-     */
226
-    protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody)
227
-    {
228
-        $request->setStatus('Closed');
229
-        $request->setReserved(null);
230
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
231
-        $request->save();
232
-
233
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
234
-        // be rolled back.
235
-
236
-        if ($action == EmailTemplate::CREATED) {
237
-            $logCloseType = 'custom-y';
238
-            $notificationCloseType = "Custom, Created";
239
-        }
240
-        else {
241
-            $logCloseType = 'custom-n';
242
-            $notificationCloseType = "Custom, Not Created";
243
-        }
244
-
245
-        Logger::closeRequest($database, $request, $logCloseType, $messageBody);
246
-        $this->getNotificationHelper()->requestClosed($request, $notificationCloseType);
247
-
248
-        $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
249
-        SessionAlert::success("Request {$request->getId()} ({$requestName}) closed as {$notificationCloseType}.");
250
-    }
251
-
252
-    /**
253
-     * @param Request     $request
254
-     * @param PdoDatabase $database
255
-     * @param string      $action
256
-     * @param             $availableRequestStates
257
-     * @param string      $messageBody
258
-     *
259
-     * @throws Exception
260
-     * @throws OptimisticLockFailedException
261
-     */
262
-    protected function deferRequest(
263
-        Request $request,
264
-        PdoDatabase $database,
265
-        $action,
266
-        $availableRequestStates,
267
-        $messageBody
268
-    ) {
269
-        $request->setStatus($action);
270
-        $request->setReserved(null);
271
-        $request->setUpdateVersion(WebRequest::postInt('updateversion'));
272
-        $request->save();
273
-
274
-        // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
275
-        // and be rolled back.
276
-
277
-        $deferToLog = $availableRequestStates[$action]['defertolog'];
278
-        Logger::sentMail($database, $request, $messageBody);
279
-        Logger::deferRequest($database, $request, $deferToLog);
280
-
281
-        $this->getNotificationHelper()->requestDeferredWithMail($request);
282
-
283
-        $deferTo = $availableRequestStates[$action]['deferto'];
284
-        SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email.");
285
-    }
26
+	use RequestData;
27
+
28
+	protected function main()
29
+	{
30
+		$database = $this->getDatabase();
31
+
32
+		$request = $this->getRequest($database);
33
+		$currentUser = User::getCurrent($this->getDatabase());
34
+
35
+		if ($request->getStatus() === 'Closed') {
36
+			throw new ApplicationLogicException('Request is already closed');
37
+		}
38
+
39
+		// Dual-mode page
40
+		if (WebRequest::wasPosted()) {
41
+			$this->validateCSRFToken();
42
+			$this->doCustomClose($currentUser, $request, $database);
43
+
44
+			$this->redirect();
45
+		}
46
+		else {
47
+			$this->assignCSRFToken();
48
+			$this->showCustomCloseForm($database, $request);
49
+		}
50
+	}
51
+
52
+	/**
53
+	 * @param $database
54
+	 *
55
+	 * @return Request
56
+	 * @throws ApplicationLogicException
57
+	 */
58
+	protected function getRequest(PdoDatabase $database)
59
+	{
60
+		$requestId = WebRequest::getInt('request');
61
+		if ($requestId === null) {
62
+			throw new ApplicationLogicException('Request ID not found');
63
+		}
64
+
65
+		/** @var Request $request */
66
+		$request = Request::getById($requestId, $database);
67
+
68
+		if ($request === false) {
69
+			throw new ApplicationLogicException('Request not found');
70
+		}
71
+
72
+		return $request;
73
+	}
74
+
75
+	/**
76
+	 * @param PdoDatabase $database
77
+	 *
78
+	 * @return EmailTemplate|null
79
+	 */
80
+	protected function getTemplate(PdoDatabase $database)
81
+	{
82
+		$templateId = WebRequest::getInt('template');
83
+		if ($templateId === null) {
84
+			return null;
85
+		}
86
+
87
+		/** @var EmailTemplate $template */
88
+		$template = EmailTemplate::getById($templateId, $database);
89
+		if ($template === false || !$template->getActive()) {
90
+			return null;
91
+		}
92
+
93
+		return $template;
94
+	}
95
+
96
+	/**
97
+	 * @param $database
98
+	 * @param $request
99
+	 *
100
+	 * @throws Exception
101
+	 */
102
+	protected function showCustomCloseForm(PdoDatabase $database, Request $request)
103
+	{
104
+		$currentUser = User::getCurrent($database);
105
+		$config = $this->getSiteConfiguration();
106
+
107
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
108
+		if (!$allowedPrivateData) {
109
+			// we probably shouldn't be showing the user this form if they're not allowed to access private data...
110
+			throw new AccessDeniedException($this->getSecurityManager());
111
+		}
112
+
113
+		$template = $this->getTemplate($database);
114
+
115
+		// Preload data
116
+		$this->assign('defaultAction', '');
117
+		$this->assign('preloadText', '');
118
+		$this->assign('preloadTitle', '');
119
+
120
+		if ($template !== null) {
121
+			$this->assign('defaultAction', $template->getDefaultAction());
122
+			$this->assign('preloadText', $template->getText());
123
+			$this->assign('preloadTitle', $template->getName());
124
+		}
125
+
126
+		// Static data
127
+		$this->assign('requeststates', $config->getRequestStates());
128
+
129
+		// request data
130
+		$this->assign('requestId', $request->getIp());
131
+		$this->assign('updateVersion', $request->getUpdateVersion());
132
+		$this->setupBasicData($request, $config);
133
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
134
+		$this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
135
+
136
+		// IP location
137
+		$trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp());
138
+		$this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp));
139
+
140
+		// Confirmations
141
+		$this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request));
142
+		$this->assign('confirmReserveOverride', $this->checkReserveOverride($request, $currentUser));
143
+
144
+		$this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser));
145
+
146
+		// template
147
+		$this->setTemplate('custom-close.tpl');
148
+	}
149
+
150
+	/**
151
+	 * @param User        $currentUser
152
+	 * @param Request     $request
153
+	 * @param PdoDatabase $database
154
+	 *
155
+	 * @throws ApplicationLogicException
156
+	 */
157
+	protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database)
158
+	{
159
+		$messageBody = WebRequest::postString('msgbody');
160
+		if ($messageBody === null || trim($messageBody) === '') {
161
+			throw new ApplicationLogicException('Message body cannot be blank');
162
+		}
163
+
164
+		$ccMailingList = true;
165
+		if ($this->barrierTest('skipCcMailingList', $currentUser)) {
166
+			$ccMailingList = WebRequest::postBoolean('ccMailingList');
167
+		}
168
+
169
+		if ($request->getStatus() === 'Closed') {
170
+			throw new ApplicationLogicException('Request is already closed');
171
+		}
172
+
173
+		if (!(WebRequest::postBoolean('confirmEmailAlreadySent')
174
+			&& WebRequest::postBoolean('confirmReserveOverride'))
175
+		) {
176
+			throw new ApplicationLogicException('Not all confirmations checked');
177
+		}
178
+
179
+		$action = WebRequest::postString('action');
180
+		$availableRequestStates = $this->getSiteConfiguration()->getRequestStates();
181
+
182
+		if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) {
183
+			// Close request
184
+			$this->closeRequest($request, $database, $action, $messageBody);
185
+
186
+			// Send the mail after the save, since save can be rolled back
187
+			$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
188
+		}
189
+		else {
190
+			if (array_key_exists($action, $availableRequestStates)) {
191
+				// Defer to other state
192
+				$this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody);
193
+
194
+				// Send the mail after the save, since save can be rolled back
195
+				$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
196
+			}
197
+			else {
198
+				$request->setReserved(null);
199
+				$request->setUpdateVersion(WebRequest::postInt('updateversion'));
200
+				$request->save();
201
+
202
+				// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
203
+				// and be rolled back.
204
+
205
+				// Send mail
206
+				$this->sendMail($request, $messageBody, $currentUser, $ccMailingList);
207
+
208
+				Logger::sentMail($database, $request, $messageBody);
209
+				Logger::unreserve($database, $request);
210
+
211
+				$this->getNotificationHelper()->sentMail($request);
212
+				SessionAlert::success("Sent mail to Request {$request->getId()}");
213
+			}
214
+		}
215
+	}
216
+
217
+	/**
218
+	 * @param Request     $request
219
+	 * @param PdoDatabase $database
220
+	 * @param string      $action
221
+	 * @param string      $messageBody
222
+	 *
223
+	 * @throws Exception
224
+	 * @throws OptimisticLockFailedException
225
+	 */
226
+	protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody)
227
+	{
228
+		$request->setStatus('Closed');
229
+		$request->setReserved(null);
230
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
231
+		$request->save();
232
+
233
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and
234
+		// be rolled back.
235
+
236
+		if ($action == EmailTemplate::CREATED) {
237
+			$logCloseType = 'custom-y';
238
+			$notificationCloseType = "Custom, Created";
239
+		}
240
+		else {
241
+			$logCloseType = 'custom-n';
242
+			$notificationCloseType = "Custom, Not Created";
243
+		}
244
+
245
+		Logger::closeRequest($database, $request, $logCloseType, $messageBody);
246
+		$this->getNotificationHelper()->requestClosed($request, $notificationCloseType);
247
+
248
+		$requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8');
249
+		SessionAlert::success("Request {$request->getId()} ({$requestName}) closed as {$notificationCloseType}.");
250
+	}
251
+
252
+	/**
253
+	 * @param Request     $request
254
+	 * @param PdoDatabase $database
255
+	 * @param string      $action
256
+	 * @param             $availableRequestStates
257
+	 * @param string      $messageBody
258
+	 *
259
+	 * @throws Exception
260
+	 * @throws OptimisticLockFailedException
261
+	 */
262
+	protected function deferRequest(
263
+		Request $request,
264
+		PdoDatabase $database,
265
+		$action,
266
+		$availableRequestStates,
267
+		$messageBody
268
+	) {
269
+		$request->setStatus($action);
270
+		$request->setReserved(null);
271
+		$request->setUpdateVersion(WebRequest::postInt('updateversion'));
272
+		$request->save();
273
+
274
+		// Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE
275
+		// and be rolled back.
276
+
277
+		$deferToLog = $availableRequestStates[$action]['defertolog'];
278
+		Logger::sentMail($database, $request, $messageBody);
279
+		Logger::deferRequest($database, $request, $deferToLog);
280
+
281
+		$this->getNotificationHelper()->requestDeferredWithMail($request);
282
+
283
+		$deferTo = $availableRequestStates[$action]['deferto'];
284
+		SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email.");
285
+	}
286 286
 }
Please login to merge, or discard this patch.
includes/Pages/Registration/PageRegisterOption.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -12,18 +12,18 @@
 block discarded – undo
12 12
 
13 13
 class PageRegisterOption extends InternalPageBase
14 14
 {
15
-    /**
16
-     * Main function for this page, when no specific actions are called.
17
-     * @return void
18
-     */
19
-    protected function main()
20
-    {
21
-        $this->assign('allowRegistration', $this->getSiteConfiguration()->isRegistrationAllowed());
22
-        $this->setTemplate('registration/option.tpl');
23
-    }
15
+	/**
16
+	 * Main function for this page, when no specific actions are called.
17
+	 * @return void
18
+	 */
19
+	protected function main()
20
+	{
21
+		$this->assign('allowRegistration', $this->getSiteConfiguration()->isRegistrationAllowed());
22
+		$this->setTemplate('registration/option.tpl');
23
+	}
24 24
 
25
-    protected function isProtectedPage()
26
-    {
27
-        return false;
28
-    }
25
+	protected function isProtectedPage()
26
+	{
27
+		return false;
28
+	}
29 29
 }
Please login to merge, or discard this patch.