Passed
Push — master ( 3e5dae...8d4e4c )
by Simon
12:37
created
includes/DataObjects/Comment.php 1 patch
Indentation   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -20,228 +20,228 @@
 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
-    private $flagged = 0;
29
-    private $edited;
30
-
31
-    /**
32
-     * Retrieves all comments for a request, optionally filtered
33
-     *
34
-     * @param integer     $id             Request ID to search by
35
-     * @param PdoDatabase $database
36
-     * @param bool        $showRestricted True to show all comments, False to show only unprotected comments, and protected
37
-     *                                    comments visible to $userId
38
-     * @param bool        $showCheckuser
39
-     * @param null|int    $userId         User to filter by
40
-     *
41
-     * @return Comment[]
42
-     */
43
-    public static function getForRequest($id, PdoDatabase $database, $showRestricted = false, $showCheckuser = false, $userId = null)
44
-    {
45
-        $parameters = ['requester', 'user'];
46
-        if ($showCheckuser) {
47
-            $parameters[] = 'checkuser';
48
-        }
49
-        if ($showRestricted) {
50
-            $parameters[] = 'admin';
51
-        }
52
-
53
-        $visibilityPlaceholders = str_repeat('?,', count($parameters) - 1) . '?';
54
-
55
-        $statement = $database->prepare(<<<SQL
23
+	private $time;
24
+	private $user;
25
+	private $comment;
26
+	private $visibility = "user";
27
+	private $request;
28
+	private $flagged = 0;
29
+	private $edited;
30
+
31
+	/**
32
+	 * Retrieves all comments for a request, optionally filtered
33
+	 *
34
+	 * @param integer     $id             Request ID to search by
35
+	 * @param PdoDatabase $database
36
+	 * @param bool        $showRestricted True to show all comments, False to show only unprotected comments, and protected
37
+	 *                                    comments visible to $userId
38
+	 * @param bool        $showCheckuser
39
+	 * @param null|int    $userId         User to filter by
40
+	 *
41
+	 * @return Comment[]
42
+	 */
43
+	public static function getForRequest($id, PdoDatabase $database, $showRestricted = false, $showCheckuser = false, $userId = null)
44
+	{
45
+		$parameters = ['requester', 'user'];
46
+		if ($showCheckuser) {
47
+			$parameters[] = 'checkuser';
48
+		}
49
+		if ($showRestricted) {
50
+			$parameters[] = 'admin';
51
+		}
52
+
53
+		$visibilityPlaceholders = str_repeat('?,', count($parameters) - 1) . '?';
54
+
55
+		$statement = $database->prepare(<<<SQL
56 56
 SELECT * FROM comment
57 57
 WHERE (visibility in (${visibilityPlaceholders}) OR user = ?) AND request = ?;
58 58
 SQL
59
-        );
60
-
61
-        $parameters[] = $userId;
62
-        $parameters[] = $id;
63
-
64
-        $statement->execute($parameters);
65
-
66
-        $result = array();
67
-        /** @var Comment $v */
68
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
69
-            $v->setDatabase($database);
70
-            $result[] = $v;
71
-        }
72
-
73
-        return $result;
74
-    }
75
-
76
-    public static function getFlaggedComments(PdoDatabase $database)
77
-    {
78
-        $statement = $database->prepare('SELECT * FROM comment WHERE flagged = 1;');
79
-        $statement->execute();
80
-
81
-        $result = array();
82
-        /** @var Comment $v */
83
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
84
-            $v->setDatabase($database);
85
-            $result[] = $v;
86
-        }
87
-
88
-        return $result;
89
-    }
90
-
91
-    /**
92
-     * @throws Exception
93
-     */
94
-    public function save()
95
-    {
96
-        if ($this->isNew()) {
97
-            // insert
98
-            $statement = $this->dbObject->prepare(<<<SQL
59
+		);
60
+
61
+		$parameters[] = $userId;
62
+		$parameters[] = $id;
63
+
64
+		$statement->execute($parameters);
65
+
66
+		$result = array();
67
+		/** @var Comment $v */
68
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
69
+			$v->setDatabase($database);
70
+			$result[] = $v;
71
+		}
72
+
73
+		return $result;
74
+	}
75
+
76
+	public static function getFlaggedComments(PdoDatabase $database)
77
+	{
78
+		$statement = $database->prepare('SELECT * FROM comment WHERE flagged = 1;');
79
+		$statement->execute();
80
+
81
+		$result = array();
82
+		/** @var Comment $v */
83
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
84
+			$v->setDatabase($database);
85
+			$result[] = $v;
86
+		}
87
+
88
+		return $result;
89
+	}
90
+
91
+	/**
92
+	 * @throws Exception
93
+	 */
94
+	public function save()
95
+	{
96
+		if ($this->isNew()) {
97
+			// insert
98
+			$statement = $this->dbObject->prepare(<<<SQL
99 99
 INSERT INTO comment ( time, user, comment, visibility, request, flagged )
100 100
 VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request, :flagged );
101 101
 SQL
102
-            );
103
-            $statement->bindValue(":user", $this->user);
104
-            $statement->bindValue(":comment", $this->comment);
105
-            $statement->bindValue(":visibility", $this->visibility);
106
-            $statement->bindValue(":request", $this->request);
107
-            $statement->bindValue(":flagged", $this->flagged);
108
-
109
-            if ($statement->execute()) {
110
-                $this->id = (int)$this->dbObject->lastInsertId();
111
-            }
112
-            else {
113
-                throw new Exception($statement->errorInfo());
114
-            }
115
-        }
116
-        else {
117
-            // update
118
-            $statement = $this->dbObject->prepare(<<<SQL
102
+			);
103
+			$statement->bindValue(":user", $this->user);
104
+			$statement->bindValue(":comment", $this->comment);
105
+			$statement->bindValue(":visibility", $this->visibility);
106
+			$statement->bindValue(":request", $this->request);
107
+			$statement->bindValue(":flagged", $this->flagged);
108
+
109
+			if ($statement->execute()) {
110
+				$this->id = (int)$this->dbObject->lastInsertId();
111
+			}
112
+			else {
113
+				throw new Exception($statement->errorInfo());
114
+			}
115
+		}
116
+		else {
117
+			// update
118
+			$statement = $this->dbObject->prepare(<<<SQL
119 119
 UPDATE comment
120 120
 SET comment = :comment, visibility = :visibility, flagged = :flagged, edited = :edited, updateversion = updateversion + 1
121 121
 WHERE id = :id AND updateversion = :updateversion;
122 122
 SQL
123
-            );
124
-
125
-            $statement->bindValue(':id', $this->id);
126
-            $statement->bindValue(':updateversion', $this->updateversion);
127
-
128
-            $statement->bindValue(':comment', $this->comment);
129
-            $statement->bindValue(':visibility', $this->visibility);
130
-            $statement->bindValue(":flagged", $this->flagged);
131
-            $statement->bindValue(":edited", $this->edited);
132
-
133
-            if (!$statement->execute()) {
134
-                throw new Exception($statement->errorInfo());
135
-            }
136
-
137
-            if ($statement->rowCount() !== 1) {
138
-                throw new OptimisticLockFailedException();
139
-            }
140
-
141
-            $this->updateversion++;
142
-        }
143
-    }
144
-
145
-    /**
146
-     * @return DateTimeImmutable
147
-     */
148
-    public function getTime()
149
-    {
150
-        return new DateTimeImmutable($this->time);
151
-    }
152
-
153
-    /**
154
-     * @return int
155
-     */
156
-    public function getUser()
157
-    {
158
-        return $this->user;
159
-    }
160
-
161
-    /**
162
-     * @param int $user
163
-     */
164
-    public function setUser($user)
165
-    {
166
-        $this->user = $user;
167
-    }
168
-
169
-    /**
170
-     * @return string
171
-     */
172
-    public function getComment()
173
-    {
174
-        return $this->comment;
175
-    }
176
-
177
-    /**
178
-     * @param string $comment
179
-     */
180
-    public function setComment($comment)
181
-    {
182
-        $this->comment = $comment;
183
-    }
184
-
185
-    /**
186
-     * @return string
187
-     */
188
-    public function getVisibility()
189
-    {
190
-        return $this->visibility;
191
-    }
192
-
193
-    /**
194
-     * @param string $visibility
195
-     */
196
-    public function setVisibility($visibility)
197
-    {
198
-        $this->visibility = $visibility;
199
-    }
200
-
201
-    /**
202
-     * @return int
203
-     */
204
-    public function getRequest()
205
-    {
206
-        return $this->request;
207
-    }
208
-
209
-    /**
210
-     * @param int $request
211
-     */
212
-    public function setRequest($request)
213
-    {
214
-        $this->request = $request;
215
-    }
216
-
217
-    /**
218
-     * @return bool
219
-     */
220
-    public function getFlagged() : bool
221
-    {
222
-        return $this->flagged == 1;
223
-    }
224
-
225
-    /**
226
-     * @param bool $flagged
227
-     */
228
-    public function setFlagged(bool $flagged): void
229
-    {
230
-        $this->flagged = $flagged ? 1 : 0;
231
-    }
232
-
233
-    public function touchEdited() : void
234
-    {
235
-        $dateTimeImmutable = new DateTimeImmutable("now");
236
-        $this->edited = $dateTimeImmutable->format('Y-m-d H:i:s');
237
-    }
238
-
239
-    public function getEdited() : ?DateTimeImmutable
240
-    {
241
-        if ($this->edited === null) {
242
-            return null;
243
-        }
244
-
245
-        return new DateTimeImmutable($this->edited);
246
-    }
123
+			);
124
+
125
+			$statement->bindValue(':id', $this->id);
126
+			$statement->bindValue(':updateversion', $this->updateversion);
127
+
128
+			$statement->bindValue(':comment', $this->comment);
129
+			$statement->bindValue(':visibility', $this->visibility);
130
+			$statement->bindValue(":flagged", $this->flagged);
131
+			$statement->bindValue(":edited", $this->edited);
132
+
133
+			if (!$statement->execute()) {
134
+				throw new Exception($statement->errorInfo());
135
+			}
136
+
137
+			if ($statement->rowCount() !== 1) {
138
+				throw new OptimisticLockFailedException();
139
+			}
140
+
141
+			$this->updateversion++;
142
+		}
143
+	}
144
+
145
+	/**
146
+	 * @return DateTimeImmutable
147
+	 */
148
+	public function getTime()
149
+	{
150
+		return new DateTimeImmutable($this->time);
151
+	}
152
+
153
+	/**
154
+	 * @return int
155
+	 */
156
+	public function getUser()
157
+	{
158
+		return $this->user;
159
+	}
160
+
161
+	/**
162
+	 * @param int $user
163
+	 */
164
+	public function setUser($user)
165
+	{
166
+		$this->user = $user;
167
+	}
168
+
169
+	/**
170
+	 * @return string
171
+	 */
172
+	public function getComment()
173
+	{
174
+		return $this->comment;
175
+	}
176
+
177
+	/**
178
+	 * @param string $comment
179
+	 */
180
+	public function setComment($comment)
181
+	{
182
+		$this->comment = $comment;
183
+	}
184
+
185
+	/**
186
+	 * @return string
187
+	 */
188
+	public function getVisibility()
189
+	{
190
+		return $this->visibility;
191
+	}
192
+
193
+	/**
194
+	 * @param string $visibility
195
+	 */
196
+	public function setVisibility($visibility)
197
+	{
198
+		$this->visibility = $visibility;
199
+	}
200
+
201
+	/**
202
+	 * @return int
203
+	 */
204
+	public function getRequest()
205
+	{
206
+		return $this->request;
207
+	}
208
+
209
+	/**
210
+	 * @param int $request
211
+	 */
212
+	public function setRequest($request)
213
+	{
214
+		$this->request = $request;
215
+	}
216
+
217
+	/**
218
+	 * @return bool
219
+	 */
220
+	public function getFlagged() : bool
221
+	{
222
+		return $this->flagged == 1;
223
+	}
224
+
225
+	/**
226
+	 * @param bool $flagged
227
+	 */
228
+	public function setFlagged(bool $flagged): void
229
+	{
230
+		$this->flagged = $flagged ? 1 : 0;
231
+	}
232
+
233
+	public function touchEdited() : void
234
+	{
235
+		$dateTimeImmutable = new DateTimeImmutable("now");
236
+		$this->edited = $dateTimeImmutable->format('Y-m-d H:i:s');
237
+	}
238
+
239
+	public function getEdited() : ?DateTimeImmutable
240
+	{
241
+		if ($this->edited === null) {
242
+			return null;
243
+		}
244
+
245
+		return new DateTimeImmutable($this->edited);
246
+	}
247 247
 }
Please login to merge, or discard this patch.
includes/DataObjects/EmailTemplate.php 1 patch
Indentation   +328 added lines, -328 removed lines patch added patch discarded remove patch
@@ -21,178 +21,178 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class EmailTemplate extends DataObject
23 23
 {
24
-    const ACTION_CREATED = 'created';
25
-    const ACTION_NOT_CREATED = 'not created';
26
-    const ACTION_NONE = 'none';
27
-    const ACTION_DEFER = 'defer';
28
-
29
-    /** @var string the name of the template */
30
-    private $name;
31
-    private $text;
32
-    /** @var string|null */
33
-    private $jsquestion;
34
-    private $active = 1;
35
-    private $preloadonly = 0;
36
-    private $defaultaction = self::ACTION_NOT_CREATED;
37
-    private $queue;
38
-
39
-    /**
40
-     * Gets active non-preload templates
41
-     *
42
-     * @param string      $defaultAction Default action to take (EmailTemplate::ACTION_CREATED or EmailTemplate::ACTION_NOT_CREATED)
43
-     * @param PdoDatabase $database
44
-     * @param int|null    $filter Template IDs to filter out
45
-     *
46
-     * @return array|false
47
-     */
48
-    public static function getActiveNonpreloadTemplates($defaultAction, PdoDatabase $database, ?int $filter = null)
49
-    {
50
-        $statement = $database->prepare(<<<SQL
24
+	const ACTION_CREATED = 'created';
25
+	const ACTION_NOT_CREATED = 'not created';
26
+	const ACTION_NONE = 'none';
27
+	const ACTION_DEFER = 'defer';
28
+
29
+	/** @var string the name of the template */
30
+	private $name;
31
+	private $text;
32
+	/** @var string|null */
33
+	private $jsquestion;
34
+	private $active = 1;
35
+	private $preloadonly = 0;
36
+	private $defaultaction = self::ACTION_NOT_CREATED;
37
+	private $queue;
38
+
39
+	/**
40
+	 * Gets active non-preload templates
41
+	 *
42
+	 * @param string      $defaultAction Default action to take (EmailTemplate::ACTION_CREATED or EmailTemplate::ACTION_NOT_CREATED)
43
+	 * @param PdoDatabase $database
44
+	 * @param int|null    $filter Template IDs to filter out
45
+	 *
46
+	 * @return array|false
47
+	 */
48
+	public static function getActiveNonpreloadTemplates($defaultAction, PdoDatabase $database, ?int $filter = null)
49
+	{
50
+		$statement = $database->prepare(<<<SQL
51 51
 SELECT * FROM `emailtemplate`
52 52
 WHERE defaultaction = :forcreated AND active = 1 AND preloadonly = 0 AND (:skipFilter = 1 OR id <> :filter);
53 53
 SQL
54
-        );
55
-        $statement->bindValue(":forcreated", $defaultAction);
56
-        $statement->bindValue(":filter", $filter);
57
-        $statement->bindValue(":skipFilter", $filter === null ? 1 : 0);
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::ACTION_CREATED,
75
-     *                                        EmailTemplate::ACTION_NOT_CREATED, or EmailTemplate::ACTION_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 inactive 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->defaultaction = self::ACTION_NONE;
161
-        $t->name = 'Dropped';
162
-
163
-        return $t;
164
-    }
165
-
166
-    /**
167
-     * @throws Exception
168
-     */
169
-    public function save()
170
-    {
171
-        if ($this->isNew()) {
172
-            // insert
173
-            $statement = $this->dbObject->prepare(<<<SQL
54
+		);
55
+		$statement->bindValue(":forcreated", $defaultAction);
56
+		$statement->bindValue(":filter", $filter);
57
+		$statement->bindValue(":skipFilter", $filter === null ? 1 : 0);
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::ACTION_CREATED,
75
+	 *                                        EmailTemplate::ACTION_NOT_CREATED, or EmailTemplate::ACTION_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 inactive 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->defaultaction = self::ACTION_NONE;
161
+		$t->name = 'Dropped';
162
+
163
+		return $t;
164
+	}
165
+
166
+	/**
167
+	 * @throws Exception
168
+	 */
169
+	public function save()
170
+	{
171
+		if ($this->isNew()) {
172
+			// insert
173
+			$statement = $this->dbObject->prepare(<<<SQL
174 174
 INSERT INTO `emailtemplate` (name, text, jsquestion, defaultaction, active, preloadonly, queue)
175 175
 VALUES (:name, :text, :jsquestion, :defaultaction, :active, :preloadonly, :queue);
176 176
 SQL
177
-            );
178
-            $statement->bindValue(":name", $this->name);
179
-            $statement->bindValue(":text", $this->text);
180
-            $statement->bindValue(":jsquestion", $this->jsquestion);
181
-            $statement->bindValue(":defaultaction", $this->defaultaction);
182
-            $statement->bindValue(":active", $this->active);
183
-            $statement->bindValue(":preloadonly", $this->preloadonly);
184
-            $statement->bindValue(":queue", $this->queue);
185
-
186
-            if ($statement->execute()) {
187
-                $this->id = (int)$this->dbObject->lastInsertId();
188
-            }
189
-            else {
190
-                throw new Exception($statement->errorInfo());
191
-            }
192
-        }
193
-        else {
194
-            // update
195
-            $statement = $this->dbObject->prepare(<<<SQL
177
+			);
178
+			$statement->bindValue(":name", $this->name);
179
+			$statement->bindValue(":text", $this->text);
180
+			$statement->bindValue(":jsquestion", $this->jsquestion);
181
+			$statement->bindValue(":defaultaction", $this->defaultaction);
182
+			$statement->bindValue(":active", $this->active);
183
+			$statement->bindValue(":preloadonly", $this->preloadonly);
184
+			$statement->bindValue(":queue", $this->queue);
185
+
186
+			if ($statement->execute()) {
187
+				$this->id = (int)$this->dbObject->lastInsertId();
188
+			}
189
+			else {
190
+				throw new Exception($statement->errorInfo());
191
+			}
192
+		}
193
+		else {
194
+			// update
195
+			$statement = $this->dbObject->prepare(<<<SQL
196 196
 UPDATE `emailtemplate`
197 197
 SET name = :name,
198 198
 	text = :text,
@@ -204,166 +204,166 @@  discard block
 block discarded – undo
204 204
 	updateversion = updateversion + 1
205 205
 WHERE id = :id AND updateversion = :updateversion;
206 206
 SQL
207
-            );
208
-            $statement->bindValue(':id', $this->id);
209
-            $statement->bindValue(':updateversion', $this->updateversion);
210
-
211
-            $statement->bindValue(':name', $this->name);
212
-            $statement->bindValue(":text", $this->text);
213
-            $statement->bindValue(":jsquestion", $this->jsquestion);
214
-            $statement->bindValue(":defaultaction", $this->defaultaction);
215
-            $statement->bindValue(":active", $this->active);
216
-            $statement->bindValue(":preloadonly", $this->preloadonly);
217
-            $statement->bindValue(":queue", $this->queue);
218
-
219
-            if (!$statement->execute()) {
220
-                throw new Exception($statement->errorInfo());
221
-            }
222
-
223
-            if ($statement->rowCount() !== 1) {
224
-                throw new OptimisticLockFailedException();
225
-            }
226
-
227
-            $this->updateversion++;
228
-        }
229
-    }
230
-
231
-    /**
232
-     * Override delete() from DataObject
233
-     */
234
-    public function delete()
235
-    {
236
-        throw new Exception("You shouldn't be doing that, you'll break logs.");
237
-    }
238
-
239
-    /**
240
-     * @return string
241
-     */
242
-    public function getName()
243
-    {
244
-        return $this->name;
245
-    }
246
-
247
-    /**
248
-     * @param string $name
249
-     */
250
-    public function setName($name)
251
-    {
252
-        $this->name = $name;
253
-    }
254
-
255
-    /**
256
-     * @return string
257
-     */
258
-    public function getText()
259
-    {
260
-        return $this->text;
261
-    }
262
-
263
-    /**
264
-     * @param string $text
265
-     */
266
-    public function setText($text)
267
-    {
268
-        $this->text = $text;
269
-    }
270
-
271
-    /**
272
-     * @return string|null
273
-     */
274
-    public function getJsquestion()
275
-    {
276
-        return $this->jsquestion;
277
-    }
278
-
279
-    /**
280
-     * @param string $jsquestion
281
-     */
282
-    public function setJsquestion($jsquestion)
283
-    {
284
-        $this->jsquestion = $jsquestion;
285
-    }
286
-
287
-    /**
288
-     * @return string
289
-     */
290
-    public function getDefaultAction()
291
-    {
292
-        return $this->defaultaction;
293
-    }
294
-
295
-    /**
296
-     * @param string $defaultAction
297
-     */
298
-    public function setDefaultAction($defaultAction)
299
-    {
300
-        $this->defaultaction = $defaultAction;
301
-    }
302
-
303
-    /**
304
-     * @return bool
305
-     */
306
-    public function getActive()
307
-    {
308
-        return $this->active == 1;
309
-    }
310
-
311
-    /**
312
-     * @param bool $active
313
-     */
314
-    public function setActive($active)
315
-    {
316
-        $this->active = $active ? 1 : 0;
317
-    }
318
-
319
-    /**
320
-     * @return bool
321
-     */
322
-    public function getPreloadOnly()
323
-    {
324
-        return $this->preloadonly == 1;
325
-    }
326
-
327
-    /**
328
-     * @param bool $preloadonly
329
-     */
330
-    public function setPreloadOnly($preloadonly)
331
-    {
332
-        $this->preloadonly = $preloadonly ? 1 : 0;
333
-    }
334
-
335
-    /**
336
-     * @return int|null
337
-     */
338
-    public function getQueue(): ?int
339
-    {
340
-        return $this->queue;
341
-    }
342
-
343
-    /**
344
-     * @return RequestQueue|null
345
-     */
346
-    public function getQueueObject(): ?RequestQueue
347
-    {
348
-        if ($this->queue === null) {
349
-            return null;
350
-        }
351
-
352
-        /** @var $dataObject RequestQueue|false */
353
-        $dataObject = RequestQueue::getById($this->queue, $this->getDatabase());
354
-
355
-        if ($dataObject === false) {
356
-            return null;
357
-        }
358
-
359
-        return $dataObject;
360
-    }
361
-
362
-    /**
363
-     * @param int|null $queue
364
-     */
365
-    public function setQueue(?int $queue): void
366
-    {
367
-        $this->queue = $queue;
368
-    }
207
+			);
208
+			$statement->bindValue(':id', $this->id);
209
+			$statement->bindValue(':updateversion', $this->updateversion);
210
+
211
+			$statement->bindValue(':name', $this->name);
212
+			$statement->bindValue(":text", $this->text);
213
+			$statement->bindValue(":jsquestion", $this->jsquestion);
214
+			$statement->bindValue(":defaultaction", $this->defaultaction);
215
+			$statement->bindValue(":active", $this->active);
216
+			$statement->bindValue(":preloadonly", $this->preloadonly);
217
+			$statement->bindValue(":queue", $this->queue);
218
+
219
+			if (!$statement->execute()) {
220
+				throw new Exception($statement->errorInfo());
221
+			}
222
+
223
+			if ($statement->rowCount() !== 1) {
224
+				throw new OptimisticLockFailedException();
225
+			}
226
+
227
+			$this->updateversion++;
228
+		}
229
+	}
230
+
231
+	/**
232
+	 * Override delete() from DataObject
233
+	 */
234
+	public function delete()
235
+	{
236
+		throw new Exception("You shouldn't be doing that, you'll break logs.");
237
+	}
238
+
239
+	/**
240
+	 * @return string
241
+	 */
242
+	public function getName()
243
+	{
244
+		return $this->name;
245
+	}
246
+
247
+	/**
248
+	 * @param string $name
249
+	 */
250
+	public function setName($name)
251
+	{
252
+		$this->name = $name;
253
+	}
254
+
255
+	/**
256
+	 * @return string
257
+	 */
258
+	public function getText()
259
+	{
260
+		return $this->text;
261
+	}
262
+
263
+	/**
264
+	 * @param string $text
265
+	 */
266
+	public function setText($text)
267
+	{
268
+		$this->text = $text;
269
+	}
270
+
271
+	/**
272
+	 * @return string|null
273
+	 */
274
+	public function getJsquestion()
275
+	{
276
+		return $this->jsquestion;
277
+	}
278
+
279
+	/**
280
+	 * @param string $jsquestion
281
+	 */
282
+	public function setJsquestion($jsquestion)
283
+	{
284
+		$this->jsquestion = $jsquestion;
285
+	}
286
+
287
+	/**
288
+	 * @return string
289
+	 */
290
+	public function getDefaultAction()
291
+	{
292
+		return $this->defaultaction;
293
+	}
294
+
295
+	/**
296
+	 * @param string $defaultAction
297
+	 */
298
+	public function setDefaultAction($defaultAction)
299
+	{
300
+		$this->defaultaction = $defaultAction;
301
+	}
302
+
303
+	/**
304
+	 * @return bool
305
+	 */
306
+	public function getActive()
307
+	{
308
+		return $this->active == 1;
309
+	}
310
+
311
+	/**
312
+	 * @param bool $active
313
+	 */
314
+	public function setActive($active)
315
+	{
316
+		$this->active = $active ? 1 : 0;
317
+	}
318
+
319
+	/**
320
+	 * @return bool
321
+	 */
322
+	public function getPreloadOnly()
323
+	{
324
+		return $this->preloadonly == 1;
325
+	}
326
+
327
+	/**
328
+	 * @param bool $preloadonly
329
+	 */
330
+	public function setPreloadOnly($preloadonly)
331
+	{
332
+		$this->preloadonly = $preloadonly ? 1 : 0;
333
+	}
334
+
335
+	/**
336
+	 * @return int|null
337
+	 */
338
+	public function getQueue(): ?int
339
+	{
340
+		return $this->queue;
341
+	}
342
+
343
+	/**
344
+	 * @return RequestQueue|null
345
+	 */
346
+	public function getQueueObject(): ?RequestQueue
347
+	{
348
+		if ($this->queue === null) {
349
+			return null;
350
+		}
351
+
352
+		/** @var $dataObject RequestQueue|false */
353
+		$dataObject = RequestQueue::getById($this->queue, $this->getDatabase());
354
+
355
+		if ($dataObject === false) {
356
+			return null;
357
+		}
358
+
359
+		return $dataObject;
360
+	}
361
+
362
+	/**
363
+	 * @param int|null $queue
364
+	 */
365
+	public function setQueue(?int $queue): void
366
+	{
367
+		$this->queue = $queue;
368
+	}
369 369
 }
Please login to merge, or discard this patch.
includes/DataObjects/Domain.php 2 patches
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -17,92 +17,92 @@  discard block
 block discarded – undo
17 17
 
18 18
 class Domain extends DataObject
19 19
 {
20
-    /** @var string */
21
-    private $shortname;
22
-    /** @var string */
23
-    private $longname;
24
-    /** @var string */
25
-    private $wikiarticlepath;
26
-    /** @var string */
27
-    private $wikiapipath;
28
-    /** @var int */
29
-    private $enabled = 0;
30
-    /** @var int|null */
31
-    private $defaultclose;
32
-    /** @var string */
33
-    private $defaultlanguage = 'en';
34
-    /** @var string */
35
-    private $emailreplyaddress;
36
-    /** @var string|null */
37
-    private $notificationtarget;
38
-    /** @var string */
39
-    private $localdocumentation;
40
-
41
-    /** @var Domain Cache variable of the current domain */
42
-    private static $currentDomain;
43
-
44
-    public static function getCurrent(PdoDatabase $database)
45
-    {
46
-        if (self::$currentDomain === null) {
47
-            $sessionDomain = WebRequest::getSessionDomain();
48
-
49
-            if ($sessionDomain !== null) {
50
-                /** @var Domain $domain */
51
-                $domain = self::getById($sessionDomain, $database);
52
-
53
-                if ($domain === false) {
54
-                    self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
55
-                }
56
-                else {
57
-                    self::$currentDomain = $domain;
58
-                }
59
-            }
60
-            else {
61
-                self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
62
-            }
63
-        }
64
-
65
-        return self::$currentDomain;
66
-    }
67
-
68
-    public static function getByShortName(string $shortName, PdoDatabase $database)
69
-    {
70
-        $statement = $database->prepare(<<<SQL
20
+	/** @var string */
21
+	private $shortname;
22
+	/** @var string */
23
+	private $longname;
24
+	/** @var string */
25
+	private $wikiarticlepath;
26
+	/** @var string */
27
+	private $wikiapipath;
28
+	/** @var int */
29
+	private $enabled = 0;
30
+	/** @var int|null */
31
+	private $defaultclose;
32
+	/** @var string */
33
+	private $defaultlanguage = 'en';
34
+	/** @var string */
35
+	private $emailreplyaddress;
36
+	/** @var string|null */
37
+	private $notificationtarget;
38
+	/** @var string */
39
+	private $localdocumentation;
40
+
41
+	/** @var Domain Cache variable of the current domain */
42
+	private static $currentDomain;
43
+
44
+	public static function getCurrent(PdoDatabase $database)
45
+	{
46
+		if (self::$currentDomain === null) {
47
+			$sessionDomain = WebRequest::getSessionDomain();
48
+
49
+			if ($sessionDomain !== null) {
50
+				/** @var Domain $domain */
51
+				$domain = self::getById($sessionDomain, $database);
52
+
53
+				if ($domain === false) {
54
+					self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
55
+				}
56
+				else {
57
+					self::$currentDomain = $domain;
58
+				}
59
+			}
60
+			else {
61
+				self::$currentDomain = self::getById(1, $database); // FIXME: #594 User::getCurrent($database)->getDefaultDomain();
62
+			}
63
+		}
64
+
65
+		return self::$currentDomain;
66
+	}
67
+
68
+	public static function getByShortName(string $shortName, PdoDatabase $database)
69
+	{
70
+		$statement = $database->prepare(<<<SQL
71 71
             SELECT * FROM domain WHERE shortname = :name;
72 72
 SQL
73
-        );
73
+		);
74 74
 
75
-        $statement->execute([
76
-            ':name' => $shortName,
77
-        ]);
75
+		$statement->execute([
76
+			':name' => $shortName,
77
+		]);
78 78
 
79
-        /** @var RequestForm|false $result */
80
-        $result = $statement->fetchObject(get_called_class());
79
+		/** @var RequestForm|false $result */
80
+		$result = $statement->fetchObject(get_called_class());
81 81
 
82
-        if ($result !== false) {
83
-            $result->setDatabase($database);
84
-        }
82
+		if ($result !== false) {
83
+			$result->setDatabase($database);
84
+		}
85 85
 
86
-        return $result;
87
-    }
86
+		return $result;
87
+	}
88 88
 
89
-    public static function getAll(PdoDatabase $database) {
90
-        $statement = $database->prepare("SELECT * FROM domain;");
91
-        $statement->execute();
89
+	public static function getAll(PdoDatabase $database) {
90
+		$statement = $database->prepare("SELECT * FROM domain;");
91
+		$statement->execute();
92 92
 
93
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
93
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
94 94
 
95
-        /** @var Domain $t */
96
-        foreach ($resultObject as $t) {
97
-            $t->setDatabase($database);
98
-        }
95
+		/** @var Domain $t */
96
+		foreach ($resultObject as $t) {
97
+			$t->setDatabase($database);
98
+		}
99 99
 
100
-        return $resultObject;
101
-    }
100
+		return $resultObject;
101
+	}
102 102
 
103
-    public static function getDomainByUser(PdoDatabase $database, User $user, ?bool $enabled = null)
104
-    {
105
-        $statement = $database->prepare(<<<'SQL'
103
+	public static function getDomainByUser(PdoDatabase $database, User $user, ?bool $enabled = null)
104
+	{
105
+		$statement = $database->prepare(<<<'SQL'
106 106
             SELECT d.* 
107 107
             FROM domain d
108 108
             INNER JOIN userdomain ud on d.id = ud.domain
@@ -110,27 +110,27 @@  discard block
 block discarded – undo
110 110
             AND (:filterEnabled = 0 OR d.enabled = :enabled)
111 111
 SQL
112 112
 );
113
-        $statement->execute([
114
-            ':user' => $user->getId(),
115
-            ':filterEnabled' => ($enabled === null) ? 0 : 1,
116
-            ':enabled' => ($enabled) ? 1 : 0
117
-        ]);
118
-
119
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
120
-
121
-        /** @var Domain $t */
122
-        foreach ($resultObject as $t) {
123
-            $t->setDatabase($database);
124
-        }
125
-
126
-        return $resultObject;
127
-    }
128
-
129
-    public function save()
130
-    {
131
-        if ($this->isNew()) {
132
-            // insert
133
-            $statement = $this->dbObject->prepare(<<<SQL
113
+		$statement->execute([
114
+			':user' => $user->getId(),
115
+			':filterEnabled' => ($enabled === null) ? 0 : 1,
116
+			':enabled' => ($enabled) ? 1 : 0
117
+		]);
118
+
119
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
120
+
121
+		/** @var Domain $t */
122
+		foreach ($resultObject as $t) {
123
+			$t->setDatabase($database);
124
+		}
125
+
126
+		return $resultObject;
127
+	}
128
+
129
+	public function save()
130
+	{
131
+		if ($this->isNew()) {
132
+			// insert
133
+			$statement = $this->dbObject->prepare(<<<SQL
134 134
                 INSERT INTO domain (
135 135
                     shortname, longname, wikiarticlepath, wikiapipath, enabled, defaultclose, defaultlanguage, 
136 136
                     emailreplyaddress, notificationtarget, localdocumentation
@@ -139,29 +139,29 @@  discard block
 block discarded – undo
139 139
                     :emailreplyaddress, :notificationtarget, :localdocumentation
140 140
                 );
141 141
 SQL
142
-            );
143
-
144
-            $statement->bindValue(":shortname", $this->shortname);
145
-            $statement->bindValue(":longname", $this->longname);
146
-            $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
147
-            $statement->bindValue(":wikiapipath", $this->wikiapipath);
148
-            $statement->bindValue(":enabled", $this->enabled);
149
-            $statement->bindValue(":defaultclose", $this->defaultclose);
150
-            $statement->bindValue(":defaultlanguage", $this->defaultlanguage);
151
-            $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
152
-            $statement->bindValue(":notificationtarget", $this->notificationtarget);
153
-            $statement->bindValue(":localdocumentation", $this->localdocumentation);
154
-
155
-
156
-            if ($statement->execute()) {
157
-                $this->id = (int)$this->dbObject->lastInsertId();
158
-            }
159
-            else {
160
-                throw new Exception($statement->errorInfo());
161
-            }
162
-        }
163
-        else {
164
-            $statement = $this->dbObject->prepare(<<<SQL
142
+			);
143
+
144
+			$statement->bindValue(":shortname", $this->shortname);
145
+			$statement->bindValue(":longname", $this->longname);
146
+			$statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
147
+			$statement->bindValue(":wikiapipath", $this->wikiapipath);
148
+			$statement->bindValue(":enabled", $this->enabled);
149
+			$statement->bindValue(":defaultclose", $this->defaultclose);
150
+			$statement->bindValue(":defaultlanguage", $this->defaultlanguage);
151
+			$statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
152
+			$statement->bindValue(":notificationtarget", $this->notificationtarget);
153
+			$statement->bindValue(":localdocumentation", $this->localdocumentation);
154
+
155
+
156
+			if ($statement->execute()) {
157
+				$this->id = (int)$this->dbObject->lastInsertId();
158
+			}
159
+			else {
160
+				throw new Exception($statement->errorInfo());
161
+			}
162
+		}
163
+		else {
164
+			$statement = $this->dbObject->prepare(<<<SQL
165 165
                 UPDATE domain SET
166 166
                     longname = :longname,
167 167
                     wikiarticlepath = :wikiarticlepath,
@@ -176,190 +176,190 @@  discard block
 block discarded – undo
176 176
                     updateversion = updateversion + 1
177 177
 				WHERE id = :id AND updateversion = :updateversion;
178 178
 SQL
179
-            );
180
-
181
-            $statement->bindValue(":longname", $this->longname);
182
-            $statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
183
-            $statement->bindValue(":wikiapipath", $this->wikiapipath);
184
-            $statement->bindValue(":enabled", $this->enabled);
185
-            $statement->bindValue(":defaultclose", $this->defaultclose);
186
-            $statement->bindValue(":defaultlanguage", $this->defaultlanguage);
187
-            $statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
188
-            $statement->bindValue(":notificationtarget", $this->notificationtarget);
189
-            $statement->bindValue(":localdocumentation", $this->localdocumentation);
190
-
191
-            $statement->bindValue(':id', $this->id);
192
-            $statement->bindValue(':updateversion', $this->updateversion);
193
-
194
-            if (!$statement->execute()) {
195
-                throw new Exception($statement->errorInfo());
196
-            }
197
-
198
-            if ($statement->rowCount() !== 1) {
199
-                throw new OptimisticLockFailedException();
200
-            }
201
-
202
-            $this->updateversion++;
203
-        }
204
-    }
205
-
206
-    /**
207
-     * @return string
208
-     */
209
-    public function getShortName(): string
210
-    {
211
-        return $this->shortname;
212
-    }
213
-
214
-    /**
215
-     * @param string $shortName
216
-     */
217
-    public function setShortName(string $shortName): void
218
-    {
219
-        $this->shortname = $shortName;
220
-    }
221
-
222
-    /**
223
-     * @return string
224
-     */
225
-    public function getLongName(): string
226
-    {
227
-        return $this->longname;
228
-    }
229
-
230
-    /**
231
-     * @param string $longName
232
-     */
233
-    public function setLongName(string $longName): void
234
-    {
235
-        $this->longname = $longName;
236
-    }
237
-
238
-    /**
239
-     * @return string
240
-     */
241
-    public function getWikiArticlePath(): string
242
-    {
243
-        return $this->wikiarticlepath;
244
-    }
245
-
246
-    /**
247
-     * @param string $wikiArticlePath
248
-     */
249
-    public function setWikiArticlePath(string $wikiArticlePath): void
250
-    {
251
-        $this->wikiarticlepath = $wikiArticlePath;
252
-    }
253
-
254
-    /**
255
-     * @return string
256
-     */
257
-    public function getWikiApiPath(): string
258
-    {
259
-        return $this->wikiapipath;
260
-    }
261
-
262
-    /**
263
-     * @param string $wikiApiPath
264
-     */
265
-    public function setWikiApiPath(string $wikiApiPath): void
266
-    {
267
-        $this->wikiapipath = $wikiApiPath;
268
-    }
269
-
270
-    /**
271
-     * @return bool
272
-     */
273
-    public function isEnabled(): bool
274
-    {
275
-        return $this->enabled == 1;
276
-    }
277
-
278
-    /**
279
-     * @param bool $enabled
280
-     */
281
-    public function setEnabled(bool $enabled): void
282
-    {
283
-        $this->enabled = $enabled ? 1 : 0;
284
-    }
285
-
286
-    /**
287
-     * @return int
288
-     */
289
-    public function getDefaultClose(): ?int
290
-    {
291
-        return $this->defaultclose;
292
-    }
293
-
294
-    /**
295
-     * @param int $defaultClose
296
-     */
297
-    public function setDefaultClose(?int $defaultClose): void
298
-    {
299
-        $this->defaultclose = $defaultClose;
300
-    }
301
-
302
-    /**
303
-     * @return string
304
-     */
305
-    public function getDefaultLanguage(): string
306
-    {
307
-        return $this->defaultlanguage;
308
-    }
309
-
310
-    /**
311
-     * @param string $defaultLanguage
312
-     */
313
-    public function setDefaultLanguage(string $defaultLanguage): void
314
-    {
315
-        $this->defaultlanguage = $defaultLanguage;
316
-    }
317
-
318
-    /**
319
-     * @return string
320
-     */
321
-    public function getEmailReplyAddress(): string
322
-    {
323
-        return $this->emailreplyaddress;
324
-    }
325
-
326
-    /**
327
-     * @param string $emailReplyAddress
328
-     */
329
-    public function setEmailReplyAddress(string $emailReplyAddress): void
330
-    {
331
-        $this->emailreplyaddress = $emailReplyAddress;
332
-    }
333
-
334
-    /**
335
-     * @return string|null
336
-     */
337
-    public function getNotificationTarget(): ?string
338
-    {
339
-        return $this->notificationtarget;
340
-    }
341
-
342
-    /**
343
-     * @param string|null $notificationTarget
344
-     */
345
-    public function setNotificationTarget(?string $notificationTarget): void
346
-    {
347
-        $this->notificationtarget = $notificationTarget;
348
-    }
349
-
350
-    /**
351
-     * @return string
352
-     */
353
-    public function getLocalDocumentation(): string
354
-    {
355
-        return $this->localdocumentation;
356
-    }
357
-
358
-    /**
359
-     * @param string $localDocumentation
360
-     */
361
-    public function setLocalDocumentation(string $localDocumentation): void
362
-    {
363
-        $this->localdocumentation = $localDocumentation;
364
-    }
179
+			);
180
+
181
+			$statement->bindValue(":longname", $this->longname);
182
+			$statement->bindValue(":wikiarticlepath", $this->wikiarticlepath);
183
+			$statement->bindValue(":wikiapipath", $this->wikiapipath);
184
+			$statement->bindValue(":enabled", $this->enabled);
185
+			$statement->bindValue(":defaultclose", $this->defaultclose);
186
+			$statement->bindValue(":defaultlanguage", $this->defaultlanguage);
187
+			$statement->bindValue(":emailreplyaddress", $this->emailreplyaddress);
188
+			$statement->bindValue(":notificationtarget", $this->notificationtarget);
189
+			$statement->bindValue(":localdocumentation", $this->localdocumentation);
190
+
191
+			$statement->bindValue(':id', $this->id);
192
+			$statement->bindValue(':updateversion', $this->updateversion);
193
+
194
+			if (!$statement->execute()) {
195
+				throw new Exception($statement->errorInfo());
196
+			}
197
+
198
+			if ($statement->rowCount() !== 1) {
199
+				throw new OptimisticLockFailedException();
200
+			}
201
+
202
+			$this->updateversion++;
203
+		}
204
+	}
205
+
206
+	/**
207
+	 * @return string
208
+	 */
209
+	public function getShortName(): string
210
+	{
211
+		return $this->shortname;
212
+	}
213
+
214
+	/**
215
+	 * @param string $shortName
216
+	 */
217
+	public function setShortName(string $shortName): void
218
+	{
219
+		$this->shortname = $shortName;
220
+	}
221
+
222
+	/**
223
+	 * @return string
224
+	 */
225
+	public function getLongName(): string
226
+	{
227
+		return $this->longname;
228
+	}
229
+
230
+	/**
231
+	 * @param string $longName
232
+	 */
233
+	public function setLongName(string $longName): void
234
+	{
235
+		$this->longname = $longName;
236
+	}
237
+
238
+	/**
239
+	 * @return string
240
+	 */
241
+	public function getWikiArticlePath(): string
242
+	{
243
+		return $this->wikiarticlepath;
244
+	}
245
+
246
+	/**
247
+	 * @param string $wikiArticlePath
248
+	 */
249
+	public function setWikiArticlePath(string $wikiArticlePath): void
250
+	{
251
+		$this->wikiarticlepath = $wikiArticlePath;
252
+	}
253
+
254
+	/**
255
+	 * @return string
256
+	 */
257
+	public function getWikiApiPath(): string
258
+	{
259
+		return $this->wikiapipath;
260
+	}
261
+
262
+	/**
263
+	 * @param string $wikiApiPath
264
+	 */
265
+	public function setWikiApiPath(string $wikiApiPath): void
266
+	{
267
+		$this->wikiapipath = $wikiApiPath;
268
+	}
269
+
270
+	/**
271
+	 * @return bool
272
+	 */
273
+	public function isEnabled(): bool
274
+	{
275
+		return $this->enabled == 1;
276
+	}
277
+
278
+	/**
279
+	 * @param bool $enabled
280
+	 */
281
+	public function setEnabled(bool $enabled): void
282
+	{
283
+		$this->enabled = $enabled ? 1 : 0;
284
+	}
285
+
286
+	/**
287
+	 * @return int
288
+	 */
289
+	public function getDefaultClose(): ?int
290
+	{
291
+		return $this->defaultclose;
292
+	}
293
+
294
+	/**
295
+	 * @param int $defaultClose
296
+	 */
297
+	public function setDefaultClose(?int $defaultClose): void
298
+	{
299
+		$this->defaultclose = $defaultClose;
300
+	}
301
+
302
+	/**
303
+	 * @return string
304
+	 */
305
+	public function getDefaultLanguage(): string
306
+	{
307
+		return $this->defaultlanguage;
308
+	}
309
+
310
+	/**
311
+	 * @param string $defaultLanguage
312
+	 */
313
+	public function setDefaultLanguage(string $defaultLanguage): void
314
+	{
315
+		$this->defaultlanguage = $defaultLanguage;
316
+	}
317
+
318
+	/**
319
+	 * @return string
320
+	 */
321
+	public function getEmailReplyAddress(): string
322
+	{
323
+		return $this->emailreplyaddress;
324
+	}
325
+
326
+	/**
327
+	 * @param string $emailReplyAddress
328
+	 */
329
+	public function setEmailReplyAddress(string $emailReplyAddress): void
330
+	{
331
+		$this->emailreplyaddress = $emailReplyAddress;
332
+	}
333
+
334
+	/**
335
+	 * @return string|null
336
+	 */
337
+	public function getNotificationTarget(): ?string
338
+	{
339
+		return $this->notificationtarget;
340
+	}
341
+
342
+	/**
343
+	 * @param string|null $notificationTarget
344
+	 */
345
+	public function setNotificationTarget(?string $notificationTarget): void
346
+	{
347
+		$this->notificationtarget = $notificationTarget;
348
+	}
349
+
350
+	/**
351
+	 * @return string
352
+	 */
353
+	public function getLocalDocumentation(): string
354
+	{
355
+		return $this->localdocumentation;
356
+	}
357
+
358
+	/**
359
+	 * @param string $localDocumentation
360
+	 */
361
+	public function setLocalDocumentation(string $localDocumentation): void
362
+	{
363
+		$this->localdocumentation = $localDocumentation;
364
+	}
365 365
 }
366 366
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -86,7 +86,8 @@
 block discarded – undo
86 86
         return $result;
87 87
     }
88 88
 
89
-    public static function getAll(PdoDatabase $database) {
89
+    public static function getAll(PdoDatabase $database)
90
+    {
90 91
         $statement = $database->prepare("SELECT * FROM domain;");
91 92
         $statement->execute();
92 93
 
Please login to merge, or discard this patch.
includes/DataObjects/Ban.php 1 patch
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -19,389 +19,389 @@
 block discarded – undo
19 19
  */
20 20
 class Ban extends DataObject
21 21
 {
22
-    const ACTION_BLOCK = 'block';
23
-    const ACTION_DROP = 'drop';
24
-    const ACTION_DEFER = 'defer';
25
-    const ACTION_NONE = 'none';
26
-
27
-    /** @var string|null */
28
-    private $name;
29
-    /** @var string|null */
30
-    private $ip;
31
-    /** @var int|null */
32
-    private $ipmask;
33
-    /** @var string|null */
34
-    private $email;
35
-    /** @var string|null */
36
-    private $useragent;
37
-
38
-    private $user;
39
-    private $reason;
40
-    private $date;
41
-    private $duration;
42
-    private $active;
43
-    private $action = self::ACTION_BLOCK;
44
-    private $targetqueue;
45
-    private $visibility = 'user';
46
-
47
-    /**
48
-     * Gets all active bans, filtered by the optional target.
49
-     *
50
-     * @param PdoDatabase $database
51
-     *
52
-     * @return Ban[]
53
-     */
54
-    public static function getActiveBans(PdoDatabase $database)
55
-    {
56
-        $query = <<<SQL
22
+	const ACTION_BLOCK = 'block';
23
+	const ACTION_DROP = 'drop';
24
+	const ACTION_DEFER = 'defer';
25
+	const ACTION_NONE = 'none';
26
+
27
+	/** @var string|null */
28
+	private $name;
29
+	/** @var string|null */
30
+	private $ip;
31
+	/** @var int|null */
32
+	private $ipmask;
33
+	/** @var string|null */
34
+	private $email;
35
+	/** @var string|null */
36
+	private $useragent;
37
+
38
+	private $user;
39
+	private $reason;
40
+	private $date;
41
+	private $duration;
42
+	private $active;
43
+	private $action = self::ACTION_BLOCK;
44
+	private $targetqueue;
45
+	private $visibility = 'user';
46
+
47
+	/**
48
+	 * Gets all active bans, filtered by the optional target.
49
+	 *
50
+	 * @param PdoDatabase $database
51
+	 *
52
+	 * @return Ban[]
53
+	 */
54
+	public static function getActiveBans(PdoDatabase $database)
55
+	{
56
+		$query = <<<SQL
57 57
 SELECT * FROM ban 
58 58
 WHERE (duration > UNIX_TIMESTAMP() OR duration is null) 
59 59
   AND active = 1;
60 60
 SQL;
61
-        $statement = $database->prepare($query);
62
-        $statement->execute();
63
-        $result = array();
64
-
65
-        /** @var Ban $v */
66
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
67
-            $v->setDatabase($database);
68
-            $result[] = $v;
69
-        }
70
-
71
-        return $result;
72
-    }
73
-
74
-    /**
75
-     * Gets a ban by it's ID if it's currently active.
76
-     *
77
-     * @param     integer $id
78
-     * @param PdoDatabase $database
79
-     *
80
-     * @return Ban|false
81
-     */
82
-    public static function getActiveId($id, PdoDatabase $database)
83
-    {
84
-        $statement = $database->prepare(<<<SQL
61
+		$statement = $database->prepare($query);
62
+		$statement->execute();
63
+		$result = array();
64
+
65
+		/** @var Ban $v */
66
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
67
+			$v->setDatabase($database);
68
+			$result[] = $v;
69
+		}
70
+
71
+		return $result;
72
+	}
73
+
74
+	/**
75
+	 * Gets a ban by it's ID if it's currently active.
76
+	 *
77
+	 * @param     integer $id
78
+	 * @param PdoDatabase $database
79
+	 *
80
+	 * @return Ban|false
81
+	 */
82
+	public static function getActiveId($id, PdoDatabase $database)
83
+	{
84
+		$statement = $database->prepare(<<<SQL
85 85
 SELECT *
86 86
 FROM ban
87 87
 WHERE id = :id  AND (duration > UNIX_TIMESTAMP() OR duration is null) AND active = 1;
88 88
 SQL
89
-        );
90
-        $statement->bindValue(":id", $id);
91
-
92
-        $statement->execute();
93
-
94
-        $resultObject = $statement->fetchObject(get_called_class());
95
-
96
-        if ($resultObject !== false) {
97
-            $resultObject->setDatabase($database);
98
-        }
99
-
100
-        return $resultObject;
101
-    }
102
-
103
-    public static function getByIdList($values, PdoDatabase $database)
104
-    {
105
-        if (count($values) === 0) {
106
-            return [];
107
-        }
108
-
109
-        // use the provided array to produce a list of question marks of the same length as the array.
110
-        $valueCount = count($values);
111
-        $inSection = str_repeat('?,', $valueCount - 1) . '?';
112
-
113
-        // this is still parameterised! It's using positional parameters instead of named ones.
114
-        $query = 'SELECT * FROM ban WHERE id IN (' . $inSection . ')';
115
-        $statement = $database->prepare($query);
116
-
117
-        // execute the statement with the provided parameter list.
118
-        $statement->execute($values);
119
-
120
-        $result = [];
121
-        foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
122
-            $v->setDatabase($database);
123
-            $result[] = $v;
124
-        }
125
-
126
-        return $result;
127
-    }
128
-
129
-    /**
130
-     * @throws Exception
131
-     */
132
-    public function save()
133
-    {
134
-        if ($this->isNew()) {
135
-            // insert
136
-            $statement = $this->dbObject->prepare(<<<SQL
89
+		);
90
+		$statement->bindValue(":id", $id);
91
+
92
+		$statement->execute();
93
+
94
+		$resultObject = $statement->fetchObject(get_called_class());
95
+
96
+		if ($resultObject !== false) {
97
+			$resultObject->setDatabase($database);
98
+		}
99
+
100
+		return $resultObject;
101
+	}
102
+
103
+	public static function getByIdList($values, PdoDatabase $database)
104
+	{
105
+		if (count($values) === 0) {
106
+			return [];
107
+		}
108
+
109
+		// use the provided array to produce a list of question marks of the same length as the array.
110
+		$valueCount = count($values);
111
+		$inSection = str_repeat('?,', $valueCount - 1) . '?';
112
+
113
+		// this is still parameterised! It's using positional parameters instead of named ones.
114
+		$query = 'SELECT * FROM ban WHERE id IN (' . $inSection . ')';
115
+		$statement = $database->prepare($query);
116
+
117
+		// execute the statement with the provided parameter list.
118
+		$statement->execute($values);
119
+
120
+		$result = [];
121
+		foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) {
122
+			$v->setDatabase($database);
123
+			$result[] = $v;
124
+		}
125
+
126
+		return $result;
127
+	}
128
+
129
+	/**
130
+	 * @throws Exception
131
+	 */
132
+	public function save()
133
+	{
134
+		if ($this->isNew()) {
135
+			// insert
136
+			$statement = $this->dbObject->prepare(<<<SQL
137 137
 INSERT INTO `ban` (name, email, ip, ipmask, useragent, user, reason, date, duration, active, action, targetqueue, visibility)
138 138
 VALUES (:name, :email, :ip, :ipmask, :useragent, :user, :reason, CURRENT_TIMESTAMP(), :duration, :active, :action, :targetqueue, :visibility);
139 139
 SQL
140
-            );
141
-
142
-            $statement->bindValue(":name", $this->name);
143
-            $statement->bindValue(":email", $this->email);
144
-            $statement->bindValue(":ip", $this->ip);
145
-            $statement->bindValue(":ipmask", $this->ipmask);
146
-            $statement->bindValue(":useragent", $this->useragent);
147
-
148
-            $statement->bindValue(":user", $this->user);
149
-            $statement->bindValue(":reason", $this->reason);
150
-            $statement->bindValue(":duration", $this->duration);
151
-            $statement->bindValue(":active", $this->active);
152
-            $statement->bindValue(":action", $this->action);
153
-            $statement->bindValue(":targetqueue", $this->targetqueue);
154
-            $statement->bindValue(":visibility", $this->visibility);
155
-
156
-            if ($statement->execute()) {
157
-                $this->id = (int)$this->dbObject->lastInsertId();
158
-            }
159
-            else {
160
-                throw new Exception($statement->errorInfo());
161
-            }
162
-        }
163
-        else {
164
-            // update
165
-            $statement = $this->dbObject->prepare(<<<SQL
140
+			);
141
+
142
+			$statement->bindValue(":name", $this->name);
143
+			$statement->bindValue(":email", $this->email);
144
+			$statement->bindValue(":ip", $this->ip);
145
+			$statement->bindValue(":ipmask", $this->ipmask);
146
+			$statement->bindValue(":useragent", $this->useragent);
147
+
148
+			$statement->bindValue(":user", $this->user);
149
+			$statement->bindValue(":reason", $this->reason);
150
+			$statement->bindValue(":duration", $this->duration);
151
+			$statement->bindValue(":active", $this->active);
152
+			$statement->bindValue(":action", $this->action);
153
+			$statement->bindValue(":targetqueue", $this->targetqueue);
154
+			$statement->bindValue(":visibility", $this->visibility);
155
+
156
+			if ($statement->execute()) {
157
+				$this->id = (int)$this->dbObject->lastInsertId();
158
+			}
159
+			else {
160
+				throw new Exception($statement->errorInfo());
161
+			}
162
+		}
163
+		else {
164
+			// update
165
+			$statement = $this->dbObject->prepare(<<<SQL
166 166
 UPDATE `ban`
167 167
 SET duration = :duration, active = :active, user = :user, action = :action, visibility = :visibility, 
168 168
     targetqueue = :targetqueue, updateversion = updateversion + 1
169 169
 WHERE id = :id AND updateversion = :updateversion;
170 170
 SQL
171
-            );
172
-            $statement->bindValue(':id', $this->id);
173
-            $statement->bindValue(':updateversion', $this->updateversion);
174
-
175
-            $statement->bindValue(':duration', $this->duration);
176
-            $statement->bindValue(':active', $this->active);
177
-            $statement->bindValue(':user', $this->user);
178
-            $statement->bindValue(":action", $this->action);
179
-            $statement->bindValue(":targetqueue", $this->targetqueue);
180
-            $statement->bindValue(":visibility", $this->visibility);
181
-
182
-            if (!$statement->execute()) {
183
-                throw new Exception($statement->errorInfo());
184
-            }
185
-
186
-            if ($statement->rowCount() !== 1) {
187
-                throw new OptimisticLockFailedException();
188
-            }
189
-
190
-            $this->updateversion++;
191
-        }
192
-    }
193
-
194
-    /**
195
-     * @return string
196
-     */
197
-    public function getReason()
198
-    {
199
-        return $this->reason;
200
-    }
201
-
202
-    /**
203
-     * @param string $reason
204
-     */
205
-    public function setReason($reason)
206
-    {
207
-        $this->reason = $reason;
208
-    }
209
-
210
-    /**
211
-     * @return mixed
212
-     */
213
-    public function getDate()
214
-    {
215
-        return $this->date;
216
-    }
217
-
218
-    /**
219
-     * @return mixed
220
-     */
221
-    public function getDuration()
222
-    {
223
-        return $this->duration;
224
-    }
225
-
226
-    /**
227
-     * @param mixed $duration
228
-     */
229
-    public function setDuration($duration)
230
-    {
231
-        $this->duration = $duration;
232
-    }
233
-
234
-    /**
235
-     * @return bool
236
-     */
237
-    public function isActive()
238
-    {
239
-        return $this->active == 1;
240
-    }
241
-
242
-    /**
243
-     * @param bool $active
244
-     */
245
-    public function setActive($active)
246
-    {
247
-        $this->active = $active ? 1 : 0;
248
-    }
249
-
250
-    /**
251
-     * @return int
252
-     */
253
-    public function getUser()
254
-    {
255
-        return $this->user;
256
-    }
257
-
258
-    /**
259
-     * @param int $user UserID of user who is setting the ban
260
-     */
261
-    public function setUser($user)
262
-    {
263
-        $this->user = $user;
264
-    }
265
-
266
-    /**
267
-     * @return string
268
-     */
269
-    public function getAction(): string
270
-    {
271
-        return $this->action;
272
-    }
273
-
274
-    /**
275
-     * @param string $action
276
-     */
277
-    public function setAction(string $action): void
278
-    {
279
-        $this->action = $action;
280
-    }
281
-
282
-    /**
283
-     * @return string
284
-     */
285
-    public function getVisibility() : string
286
-    {
287
-        return $this->visibility;
288
-    }
289
-
290
-    /**
291
-     * @param string $visibility
292
-     */
293
-    public function setVisibility(string $visibility): void
294
-    {
295
-        $this->visibility = $visibility;
296
-    }
297
-
298
-    /**
299
-     * @return string|null
300
-     */
301
-    public function getName(): ?string
302
-    {
303
-        return $this->name;
304
-    }
305
-
306
-    /**
307
-     * @param string|null $name
308
-     */
309
-    public function setName(?string $name): void
310
-    {
311
-        $this->name = $name;
312
-    }
313
-
314
-    /**
315
-     * @return string|null
316
-     */
317
-    public function getIp(): ?string
318
-    {
319
-        if ($this->ip === null) {
320
-            return null;
321
-        }
322
-
323
-        return inet_ntop($this->ip);
324
-    }
325
-
326
-    /**
327
-     * @return int|null
328
-     */
329
-    public function getIpMask(): ?int
330
-    {
331
-        return $this->ipmask;
332
-    }
333
-
334
-    /**
335
-     * @param string|null $ip
336
-     * @param int|null    $mask
337
-     */
338
-    public function setIp(?string $ip, ?int $mask): void
339
-    {
340
-        if ($ip === null) {
341
-            $this->ip = null;
342
-        }
343
-        else {
344
-            $this->ip = inet_pton($ip);
345
-        }
346
-
347
-        $this->ipmask = $mask;
348
-    }
349
-
350
-    /**
351
-     * @return string|null
352
-     */
353
-    public function getEmail(): ?string
354
-    {
355
-        return $this->email;
356
-    }
357
-
358
-    /**
359
-     * @param string|null $email
360
-     */
361
-    public function setEmail(?string $email): void
362
-    {
363
-        $this->email = $email;
364
-    }
365
-
366
-    /**
367
-     * @return string|null
368
-     */
369
-    public function getUseragent(): ?string
370
-    {
371
-        return $this->useragent;
372
-    }
373
-
374
-    /**
375
-     * @param string|null $useragent
376
-     */
377
-    public function setUseragent(?string $useragent): void
378
-    {
379
-        $this->useragent = $useragent;
380
-    }
381
-
382
-    /**
383
-     * @return int|null
384
-     */
385
-    public function getTargetQueue(): ?int
386
-    {
387
-        return $this->targetqueue;
388
-    }
389
-
390
-    /**
391
-     * @return RequestQueue|null
392
-     */
393
-    public function getTargetQueueObject(): ?RequestQueue
394
-    {
395
-        /** @var RequestQueue $queue */
396
-        $queue = RequestQueue::getById($this->targetqueue, $this->getDatabase());
397
-        return $queue === false ? null : $queue;
398
-    }
399
-
400
-    /**
401
-     * @param int|null $targetQueue
402
-     */
403
-    public function setTargetQueue(?int $targetQueue): void
404
-    {
405
-        $this->targetqueue = $targetQueue;
406
-    }
171
+			);
172
+			$statement->bindValue(':id', $this->id);
173
+			$statement->bindValue(':updateversion', $this->updateversion);
174
+
175
+			$statement->bindValue(':duration', $this->duration);
176
+			$statement->bindValue(':active', $this->active);
177
+			$statement->bindValue(':user', $this->user);
178
+			$statement->bindValue(":action", $this->action);
179
+			$statement->bindValue(":targetqueue", $this->targetqueue);
180
+			$statement->bindValue(":visibility", $this->visibility);
181
+
182
+			if (!$statement->execute()) {
183
+				throw new Exception($statement->errorInfo());
184
+			}
185
+
186
+			if ($statement->rowCount() !== 1) {
187
+				throw new OptimisticLockFailedException();
188
+			}
189
+
190
+			$this->updateversion++;
191
+		}
192
+	}
193
+
194
+	/**
195
+	 * @return string
196
+	 */
197
+	public function getReason()
198
+	{
199
+		return $this->reason;
200
+	}
201
+
202
+	/**
203
+	 * @param string $reason
204
+	 */
205
+	public function setReason($reason)
206
+	{
207
+		$this->reason = $reason;
208
+	}
209
+
210
+	/**
211
+	 * @return mixed
212
+	 */
213
+	public function getDate()
214
+	{
215
+		return $this->date;
216
+	}
217
+
218
+	/**
219
+	 * @return mixed
220
+	 */
221
+	public function getDuration()
222
+	{
223
+		return $this->duration;
224
+	}
225
+
226
+	/**
227
+	 * @param mixed $duration
228
+	 */
229
+	public function setDuration($duration)
230
+	{
231
+		$this->duration = $duration;
232
+	}
233
+
234
+	/**
235
+	 * @return bool
236
+	 */
237
+	public function isActive()
238
+	{
239
+		return $this->active == 1;
240
+	}
241
+
242
+	/**
243
+	 * @param bool $active
244
+	 */
245
+	public function setActive($active)
246
+	{
247
+		$this->active = $active ? 1 : 0;
248
+	}
249
+
250
+	/**
251
+	 * @return int
252
+	 */
253
+	public function getUser()
254
+	{
255
+		return $this->user;
256
+	}
257
+
258
+	/**
259
+	 * @param int $user UserID of user who is setting the ban
260
+	 */
261
+	public function setUser($user)
262
+	{
263
+		$this->user = $user;
264
+	}
265
+
266
+	/**
267
+	 * @return string
268
+	 */
269
+	public function getAction(): string
270
+	{
271
+		return $this->action;
272
+	}
273
+
274
+	/**
275
+	 * @param string $action
276
+	 */
277
+	public function setAction(string $action): void
278
+	{
279
+		$this->action = $action;
280
+	}
281
+
282
+	/**
283
+	 * @return string
284
+	 */
285
+	public function getVisibility() : string
286
+	{
287
+		return $this->visibility;
288
+	}
289
+
290
+	/**
291
+	 * @param string $visibility
292
+	 */
293
+	public function setVisibility(string $visibility): void
294
+	{
295
+		$this->visibility = $visibility;
296
+	}
297
+
298
+	/**
299
+	 * @return string|null
300
+	 */
301
+	public function getName(): ?string
302
+	{
303
+		return $this->name;
304
+	}
305
+
306
+	/**
307
+	 * @param string|null $name
308
+	 */
309
+	public function setName(?string $name): void
310
+	{
311
+		$this->name = $name;
312
+	}
313
+
314
+	/**
315
+	 * @return string|null
316
+	 */
317
+	public function getIp(): ?string
318
+	{
319
+		if ($this->ip === null) {
320
+			return null;
321
+		}
322
+
323
+		return inet_ntop($this->ip);
324
+	}
325
+
326
+	/**
327
+	 * @return int|null
328
+	 */
329
+	public function getIpMask(): ?int
330
+	{
331
+		return $this->ipmask;
332
+	}
333
+
334
+	/**
335
+	 * @param string|null $ip
336
+	 * @param int|null    $mask
337
+	 */
338
+	public function setIp(?string $ip, ?int $mask): void
339
+	{
340
+		if ($ip === null) {
341
+			$this->ip = null;
342
+		}
343
+		else {
344
+			$this->ip = inet_pton($ip);
345
+		}
346
+
347
+		$this->ipmask = $mask;
348
+	}
349
+
350
+	/**
351
+	 * @return string|null
352
+	 */
353
+	public function getEmail(): ?string
354
+	{
355
+		return $this->email;
356
+	}
357
+
358
+	/**
359
+	 * @param string|null $email
360
+	 */
361
+	public function setEmail(?string $email): void
362
+	{
363
+		$this->email = $email;
364
+	}
365
+
366
+	/**
367
+	 * @return string|null
368
+	 */
369
+	public function getUseragent(): ?string
370
+	{
371
+		return $this->useragent;
372
+	}
373
+
374
+	/**
375
+	 * @param string|null $useragent
376
+	 */
377
+	public function setUseragent(?string $useragent): void
378
+	{
379
+		$this->useragent = $useragent;
380
+	}
381
+
382
+	/**
383
+	 * @return int|null
384
+	 */
385
+	public function getTargetQueue(): ?int
386
+	{
387
+		return $this->targetqueue;
388
+	}
389
+
390
+	/**
391
+	 * @return RequestQueue|null
392
+	 */
393
+	public function getTargetQueueObject(): ?RequestQueue
394
+	{
395
+		/** @var RequestQueue $queue */
396
+		$queue = RequestQueue::getById($this->targetqueue, $this->getDatabase());
397
+		return $queue === false ? null : $queue;
398
+	}
399
+
400
+	/**
401
+	 * @param int|null $targetQueue
402
+	 */
403
+	public function setTargetQueue(?int $targetQueue): void
404
+	{
405
+		$this->targetqueue = $targetQueue;
406
+	}
407 407
 }
Please login to merge, or discard this patch.
includes/DataObjects/Request.php 1 patch
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -22,32 +22,32 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class Request extends DataObject
24 24
 {
25
-    private $email;
26
-    private $ip;
27
-    private $name;
28
-    /** @var string|null */
29
-    private $status = RequestStatus::OPEN;
30
-    private $queue;
31
-    private $date;
32
-    private $emailsent = 0;
33
-    private $emailconfirm;
34
-    /** @var int|null */
35
-    private $reserved = null;
36
-    private $useragent;
37
-    private $forwardedip;
38
-    private $hasComments = false;
39
-    private $hasCommentsResolved = false;
40
-    private $originform;
41
-
42
-    /**
43
-     * @throws Exception
44
-     * @throws OptimisticLockFailedException
45
-     */
46
-    public function save()
47
-    {
48
-        if ($this->isNew()) {
49
-            // insert
50
-            $statement = $this->dbObject->prepare(<<<SQL
25
+	private $email;
26
+	private $ip;
27
+	private $name;
28
+	/** @var string|null */
29
+	private $status = RequestStatus::OPEN;
30
+	private $queue;
31
+	private $date;
32
+	private $emailsent = 0;
33
+	private $emailconfirm;
34
+	/** @var int|null */
35
+	private $reserved = null;
36
+	private $useragent;
37
+	private $forwardedip;
38
+	private $hasComments = false;
39
+	private $hasCommentsResolved = false;
40
+	private $originform;
41
+
42
+	/**
43
+	 * @throws Exception
44
+	 * @throws OptimisticLockFailedException
45
+	 */
46
+	public function save()
47
+	{
48
+		if ($this->isNew()) {
49
+			// insert
50
+			$statement = $this->dbObject->prepare(<<<SQL
51 51
 INSERT INTO `request` (
52 52
 	email, ip, name, status, date, emailsent,
53 53
 	emailconfirm, reserved, useragent, forwardedip,
@@ -58,29 +58,29 @@  discard block
 block discarded – undo
58 58
     :queue, :originform
59 59
 );
60 60
 SQL
61
-            );
62
-            $statement->bindValue(':email', $this->email);
63
-            $statement->bindValue(':ip', $this->ip);
64
-            $statement->bindValue(':name', $this->name);
65
-            $statement->bindValue(':status', $this->status);
66
-            $statement->bindValue(':emailsent', $this->emailsent);
67
-            $statement->bindValue(':emailconfirm', $this->emailconfirm);
68
-            $statement->bindValue(':reserved', $this->reserved);
69
-            $statement->bindValue(':useragent', $this->useragent);
70
-            $statement->bindValue(':forwardedip', $this->forwardedip);
71
-            $statement->bindValue(':queue', $this->queue);
72
-            $statement->bindValue(':originform', $this->originform);
73
-
74
-            if ($statement->execute()) {
75
-                $this->id = (int)$this->dbObject->lastInsertId();
76
-            }
77
-            else {
78
-                throw new Exception($statement->errorInfo());
79
-            }
80
-        }
81
-        else {
82
-            // update
83
-            $statement = $this->dbObject->prepare(<<<SQL
61
+			);
62
+			$statement->bindValue(':email', $this->email);
63
+			$statement->bindValue(':ip', $this->ip);
64
+			$statement->bindValue(':name', $this->name);
65
+			$statement->bindValue(':status', $this->status);
66
+			$statement->bindValue(':emailsent', $this->emailsent);
67
+			$statement->bindValue(':emailconfirm', $this->emailconfirm);
68
+			$statement->bindValue(':reserved', $this->reserved);
69
+			$statement->bindValue(':useragent', $this->useragent);
70
+			$statement->bindValue(':forwardedip', $this->forwardedip);
71
+			$statement->bindValue(':queue', $this->queue);
72
+			$statement->bindValue(':originform', $this->originform);
73
+
74
+			if ($statement->execute()) {
75
+				$this->id = (int)$this->dbObject->lastInsertId();
76
+			}
77
+			else {
78
+				throw new Exception($statement->errorInfo());
79
+			}
80
+		}
81
+		else {
82
+			// update
83
+			$statement = $this->dbObject->prepare(<<<SQL
84 84
 UPDATE `request` SET
85 85
 	status = :status,
86 86
 	emailsent = :emailsent,
@@ -90,230 +90,230 @@  discard block
 block discarded – undo
90 90
 	updateversion = updateversion + 1
91 91
 WHERE id = :id AND updateversion = :updateversion;
92 92
 SQL
93
-            );
94
-
95
-            $statement->bindValue(':id', $this->id);
96
-            $statement->bindValue(':updateversion', $this->updateversion);
97
-
98
-            $statement->bindValue(':status', $this->status);
99
-            $statement->bindValue(':emailsent', $this->emailsent);
100
-            $statement->bindValue(':emailconfirm', $this->emailconfirm);
101
-            $statement->bindValue(':reserved', $this->reserved);
102
-            $statement->bindValue(':queue', $this->queue);
103
-
104
-            if (!$statement->execute()) {
105
-                throw new Exception($statement->errorInfo());
106
-            }
107
-
108
-            if ($statement->rowCount() !== 1) {
109
-                throw new OptimisticLockFailedException();
110
-            }
111
-
112
-            $this->updateversion++;
113
-        }
114
-    }
115
-
116
-    /**
117
-     * @return string
118
-     */
119
-    public function getIp()
120
-    {
121
-        return $this->ip;
122
-    }
123
-
124
-    /**
125
-     * @param string $ip
126
-     */
127
-    public function setIp($ip)
128
-    {
129
-        $this->ip = $ip;
130
-    }
131
-
132
-    /**
133
-     * @return string
134
-     */
135
-    public function getName()
136
-    {
137
-        return $this->name;
138
-    }
139
-
140
-    /**
141
-     * @param string $name
142
-     */
143
-    public function setName($name)
144
-    {
145
-        $this->name = $name;
146
-    }
147
-
148
-    /**
149
-     * @return string
150
-     */
151
-    public function getStatus()
152
-    {
153
-        return $this->status;
154
-    }
155
-
156
-    /**
157
-     * @param string $status
158
-     */
159
-    public function setStatus($status)
160
-    {
161
-        $this->status = $status;
162
-    }
163
-
164
-    /**
165
-     * Returns the time the request was first submitted
166
-     *
167
-     * @return DateTimeImmutable
168
-     */
169
-    public function getDate()
170
-    {
171
-        return new DateTimeImmutable($this->date);
172
-    }
173
-
174
-    /**
175
-     * @return bool
176
-     */
177
-    public function getEmailSent()
178
-    {
179
-        return $this->emailsent == "1";
180
-    }
181
-
182
-    /**
183
-     * @param bool $emailSent
184
-     */
185
-    public function setEmailSent($emailSent)
186
-    {
187
-        $this->emailsent = $emailSent ? 1 : 0;
188
-    }
189
-
190
-    /**
191
-     * @return int|null
192
-     */
193
-    public function getReserved()
194
-    {
195
-        return $this->reserved;
196
-    }
197
-
198
-    /**
199
-     * @param int|null $reserved
200
-     */
201
-    public function setReserved($reserved)
202
-    {
203
-        $this->reserved = $reserved;
204
-    }
205
-
206
-    /**
207
-     * @return string
208
-     */
209
-    public function getUserAgent()
210
-    {
211
-        return $this->useragent;
212
-    }
213
-
214
-    /**
215
-     * @param string $useragent
216
-     */
217
-    public function setUserAgent($useragent)
218
-    {
219
-        $this->useragent = $useragent;
220
-    }
221
-
222
-    /**
223
-     * @return string|null
224
-     */
225
-    public function getForwardedIp()
226
-    {
227
-        return $this->forwardedip;
228
-    }
229
-
230
-    /**
231
-     * @param string|null $forwardedip
232
-     */
233
-    public function setForwardedIp($forwardedip)
234
-    {
235
-        // Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't.
93
+			);
94
+
95
+			$statement->bindValue(':id', $this->id);
96
+			$statement->bindValue(':updateversion', $this->updateversion);
97
+
98
+			$statement->bindValue(':status', $this->status);
99
+			$statement->bindValue(':emailsent', $this->emailsent);
100
+			$statement->bindValue(':emailconfirm', $this->emailconfirm);
101
+			$statement->bindValue(':reserved', $this->reserved);
102
+			$statement->bindValue(':queue', $this->queue);
103
+
104
+			if (!$statement->execute()) {
105
+				throw new Exception($statement->errorInfo());
106
+			}
107
+
108
+			if ($statement->rowCount() !== 1) {
109
+				throw new OptimisticLockFailedException();
110
+			}
111
+
112
+			$this->updateversion++;
113
+		}
114
+	}
115
+
116
+	/**
117
+	 * @return string
118
+	 */
119
+	public function getIp()
120
+	{
121
+		return $this->ip;
122
+	}
123
+
124
+	/**
125
+	 * @param string $ip
126
+	 */
127
+	public function setIp($ip)
128
+	{
129
+		$this->ip = $ip;
130
+	}
131
+
132
+	/**
133
+	 * @return string
134
+	 */
135
+	public function getName()
136
+	{
137
+		return $this->name;
138
+	}
139
+
140
+	/**
141
+	 * @param string $name
142
+	 */
143
+	public function setName($name)
144
+	{
145
+		$this->name = $name;
146
+	}
147
+
148
+	/**
149
+	 * @return string
150
+	 */
151
+	public function getStatus()
152
+	{
153
+		return $this->status;
154
+	}
155
+
156
+	/**
157
+	 * @param string $status
158
+	 */
159
+	public function setStatus($status)
160
+	{
161
+		$this->status = $status;
162
+	}
163
+
164
+	/**
165
+	 * Returns the time the request was first submitted
166
+	 *
167
+	 * @return DateTimeImmutable
168
+	 */
169
+	public function getDate()
170
+	{
171
+		return new DateTimeImmutable($this->date);
172
+	}
173
+
174
+	/**
175
+	 * @return bool
176
+	 */
177
+	public function getEmailSent()
178
+	{
179
+		return $this->emailsent == "1";
180
+	}
181
+
182
+	/**
183
+	 * @param bool $emailSent
184
+	 */
185
+	public function setEmailSent($emailSent)
186
+	{
187
+		$this->emailsent = $emailSent ? 1 : 0;
188
+	}
189
+
190
+	/**
191
+	 * @return int|null
192
+	 */
193
+	public function getReserved()
194
+	{
195
+		return $this->reserved;
196
+	}
197
+
198
+	/**
199
+	 * @param int|null $reserved
200
+	 */
201
+	public function setReserved($reserved)
202
+	{
203
+		$this->reserved = $reserved;
204
+	}
205
+
206
+	/**
207
+	 * @return string
208
+	 */
209
+	public function getUserAgent()
210
+	{
211
+		return $this->useragent;
212
+	}
213
+
214
+	/**
215
+	 * @param string $useragent
216
+	 */
217
+	public function setUserAgent($useragent)
218
+	{
219
+		$this->useragent = $useragent;
220
+	}
221
+
222
+	/**
223
+	 * @return string|null
224
+	 */
225
+	public function getForwardedIp()
226
+	{
227
+		return $this->forwardedip;
228
+	}
229
+
230
+	/**
231
+	 * @param string|null $forwardedip
232
+	 */
233
+	public function setForwardedIp($forwardedip)
234
+	{
235
+		// Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't.
236 236
         
237
-        $xff = explode(',', $forwardedip);
238
-        $valid = array();
237
+		$xff = explode(',', $forwardedip);
238
+		$valid = array();
239 239
         
240
-        foreach ($xff as $ip) {
241
-            $ip = trim($ip);
242
-            if (filter_var($ip, FILTER_VALIDATE_IP)) {
243
-                $valid[] = $ip;
244
-            }
245
-        }
246
-        $this->forwardedip = implode(", ", $valid);
247
-    }
248
-
249
-    /**
250
-     * @return bool
251
-     */
252
-    public function hasComments()
253
-    {
254
-        if ($this->hasCommentsResolved) {
255
-            return $this->hasComments;
256
-        }
257
-
258
-        $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;");
259
-        $commentsQuery->bindValue(":id", $this->id);
260
-
261
-        $commentsQuery->execute();
262
-
263
-        $this->hasComments = ($commentsQuery->fetchColumn() != 0);
264
-        $this->hasCommentsResolved = true;
265
-
266
-        return $this->hasComments;
267
-    }
268
-
269
-    /**
270
-     * @return string
271
-     */
272
-    public function getEmailConfirm()
273
-    {
274
-        return $this->emailconfirm;
275
-    }
276
-
277
-    /**
278
-     * @param string $emailconfirm
279
-     */
280
-    public function setEmailConfirm($emailconfirm)
281
-    {
282
-        $this->emailconfirm = $emailconfirm;
283
-    }
284
-
285
-    public function generateEmailConfirmationHash()
286
-    {
287
-        $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16));
288
-    }
289
-
290
-    /**
291
-     * @return string|null
292
-     */
293
-    public function getEmail()
294
-    {
295
-        return $this->email;
296
-    }
297
-
298
-    /**
299
-     * @param string|null $email
300
-     */
301
-    public function setEmail($email)
302
-    {
303
-        $this->email = $email;
304
-    }
305
-
306
-    /**
307
-     * @return string
308
-     * @throws Exception
309
-     */
310
-    public function getClosureReason()
311
-    {
312
-        if ($this->status != 'Closed') {
313
-            throw new Exception("Can't get closure reason for open request.");
314
-        }
315
-
316
-        $statement = $this->dbObject->prepare(<<<SQL
240
+		foreach ($xff as $ip) {
241
+			$ip = trim($ip);
242
+			if (filter_var($ip, FILTER_VALIDATE_IP)) {
243
+				$valid[] = $ip;
244
+			}
245
+		}
246
+		$this->forwardedip = implode(", ", $valid);
247
+	}
248
+
249
+	/**
250
+	 * @return bool
251
+	 */
252
+	public function hasComments()
253
+	{
254
+		if ($this->hasCommentsResolved) {
255
+			return $this->hasComments;
256
+		}
257
+
258
+		$commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;");
259
+		$commentsQuery->bindValue(":id", $this->id);
260
+
261
+		$commentsQuery->execute();
262
+
263
+		$this->hasComments = ($commentsQuery->fetchColumn() != 0);
264
+		$this->hasCommentsResolved = true;
265
+
266
+		return $this->hasComments;
267
+	}
268
+
269
+	/**
270
+	 * @return string
271
+	 */
272
+	public function getEmailConfirm()
273
+	{
274
+		return $this->emailconfirm;
275
+	}
276
+
277
+	/**
278
+	 * @param string $emailconfirm
279
+	 */
280
+	public function setEmailConfirm($emailconfirm)
281
+	{
282
+		$this->emailconfirm = $emailconfirm;
283
+	}
284
+
285
+	public function generateEmailConfirmationHash()
286
+	{
287
+		$this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16));
288
+	}
289
+
290
+	/**
291
+	 * @return string|null
292
+	 */
293
+	public function getEmail()
294
+	{
295
+		return $this->email;
296
+	}
297
+
298
+	/**
299
+	 * @param string|null $email
300
+	 */
301
+	public function setEmail($email)
302
+	{
303
+		$this->email = $email;
304
+	}
305
+
306
+	/**
307
+	 * @return string
308
+	 * @throws Exception
309
+	 */
310
+	public function getClosureReason()
311
+	{
312
+		if ($this->status != 'Closed') {
313
+			throw new Exception("Can't get closure reason for open request.");
314
+		}
315
+
316
+		$statement = $this->dbObject->prepare(<<<SQL
317 317
 SELECT closes.mail_desc
318 318
 FROM log
319 319
 INNER JOIN closes ON log.action = closes.closes
@@ -323,25 +323,25 @@  discard block
 block discarded – undo
323 323
 ORDER BY log.timestamp DESC
324 324
 LIMIT 1;
325 325
 SQL
326
-        );
326
+		);
327 327
 
328
-        $statement->bindValue(":requestId", $this->id);
329
-        $statement->execute();
330
-        $reason = $statement->fetchColumn();
328
+		$statement->bindValue(":requestId", $this->id);
329
+		$statement->execute();
330
+		$reason = $statement->fetchColumn();
331 331
 
332
-        return $reason;
333
-    }
332
+		return $reason;
333
+	}
334 334
 
335
-    /**
336
-     * Gets a value indicating whether the request was closed as created or not.
337
-     */
338
-    public function getWasCreated()
339
-    {
340
-        if ($this->status != 'Closed') {
341
-            throw new Exception("Can't get closure reason for open request.");
342
-        }
335
+	/**
336
+	 * Gets a value indicating whether the request was closed as created or not.
337
+	 */
338
+	public function getWasCreated()
339
+	{
340
+		if ($this->status != 'Closed') {
341
+			throw new Exception("Can't get closure reason for open request.");
342
+		}
343 343
 
344
-        $statement = $this->dbObject->prepare(<<<SQL
344
+		$statement = $this->dbObject->prepare(<<<SQL
345 345
 SELECT emailtemplate.defaultaction, log.action
346 346
 FROM log
347 347
 LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action
@@ -351,43 +351,43 @@  discard block
 block discarded – undo
351 351
 ORDER BY log.timestamp DESC
352 352
 LIMIT 1;
353 353
 SQL
354
-        );
355
-
356
-        $statement->bindValue(":requestId", $this->id);
357
-        $statement->execute();
358
-        $defaultAction = $statement->fetchColumn(0);
359
-        $logAction = $statement->fetchColumn(1);
360
-        $statement->closeCursor();
361
-
362
-        if ($defaultAction === null) {
363
-            return $logAction === "Closed custom-y";
364
-        }
365
-
366
-        return $defaultAction === EmailTemplate::ACTION_CREATED;
367
-    }
368
-
369
-    /**
370
-     * @return DateTime
371
-     */
372
-    public function getClosureDate()
373
-    {
374
-        $logQuery = $this->dbObject->prepare(<<<SQL
354
+		);
355
+
356
+		$statement->bindValue(":requestId", $this->id);
357
+		$statement->execute();
358
+		$defaultAction = $statement->fetchColumn(0);
359
+		$logAction = $statement->fetchColumn(1);
360
+		$statement->closeCursor();
361
+
362
+		if ($defaultAction === null) {
363
+			return $logAction === "Closed custom-y";
364
+		}
365
+
366
+		return $defaultAction === EmailTemplate::ACTION_CREATED;
367
+	}
368
+
369
+	/**
370
+	 * @return DateTime
371
+	 */
372
+	public function getClosureDate()
373
+	{
374
+		$logQuery = $this->dbObject->prepare(<<<SQL
375 375
 SELECT timestamp FROM log
376 376
 WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%'
377 377
 ORDER BY timestamp DESC LIMIT 1;
378 378
 SQL
379
-        );
380
-        $logQuery->bindValue(":request", $this->getId());
381
-        $logQuery->execute();
382
-        $logTime = $logQuery->fetchColumn();
383
-        $logQuery->closeCursor();
384
-
385
-        return new DateTime($logTime);
386
-    }
387
-
388
-    public function getLastUpdated()
389
-    {
390
-        $logQuery = $this->dbObject->prepare(<<<SQL
379
+		);
380
+		$logQuery->bindValue(":request", $this->getId());
381
+		$logQuery->execute();
382
+		$logTime = $logQuery->fetchColumn();
383
+		$logQuery->closeCursor();
384
+
385
+		return new DateTime($logTime);
386
+	}
387
+
388
+	public function getLastUpdated()
389
+	{
390
+		$logQuery = $this->dbObject->prepare(<<<SQL
391 391
 SELECT max(d.ts) FROM (
392 392
     SELECT r.date AS ts FROM request r WHERE r.id = :requestr
393 393
     UNION ALL
@@ -396,93 +396,93 @@  discard block
 block discarded – undo
396 396
     SELECT c.time AS ts FROM comment c WHERE c.request = :requestc
397 397
 ) d
398 398
 SQL
399
-        );
400
-
401
-        $logQuery->bindValue(":requestr", $this->getId());
402
-        $logQuery->bindValue(":requestl", $this->getId());
403
-        $logQuery->bindValue(":requestc", $this->getId());
404
-        $logQuery->execute();
405
-        $logTime = $logQuery->fetchColumn();
406
-        $logQuery->closeCursor();
407
-
408
-        return new DateTime($logTime);
409
-    }
410
-
411
-    /**
412
-     * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal
413
-     * data to unauthorised* users.
414
-     *
415
-     * *:Not tool admins, check users, or the reserving user.
416
-     *
417
-     * @return string
418
-     *
419
-     * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events?
420
-     *       Maybe depend on the last logged action timestamp?
421
-     */
422
-    public function getRevealHash()
423
-    {
424
-        $data = $this->id         // unique per request
425
-            . '|' . $this->ip           // }
426
-            . '|' . $this->forwardedip  // } private data not known to those without access
427
-            . '|' . $this->useragent    // }
428
-            . '|' . $this->email        // }
429
-            . '|' . $this->status; // to rudimentarily invalidate the token on status change
430
-
431
-        return hash('sha256', $data);
432
-    }
433
-
434
-    /**
435
-     * @return int|null
436
-     */
437
-    public function getQueue() : ?int
438
-    {
439
-        return $this->queue;
440
-    }
441
-
442
-    /**
443
-     * @return RequestQueue|null
444
-     */
445
-    public function getQueueObject(): ?RequestQueue
446
-    {
447
-        /** @var RequestQueue $queue */
448
-        $queue = RequestQueue::getById($this->queue, $this->getDatabase());
449
-
450
-        return $queue === false ? null : $queue;
451
-    }
452
-
453
-    /**
454
-     * @param int|null $queue
455
-     */
456
-    public function setQueue(?int $queue): void
457
-    {
458
-        $this->queue = $queue;
459
-    }
460
-
461
-    /**
462
-     * @return int|null
463
-     */
464
-    public function getOriginForm(): ?int
465
-    {
466
-        return $this->originform;
467
-    }
468
-
469
-    public function getOriginFormObject(): ?RequestForm
470
-    {
471
-        if ($this->originform === null) {
472
-            return null;
473
-        }
474
-
475
-        /** @var RequestForm|bool $form */
476
-        $form = RequestForm::getById($this->originform, $this->getDatabase());
477
-
478
-        return $form === false ? null : $form;
479
-    }
480
-
481
-    /**
482
-     * @param int|null $originForm
483
-     */
484
-    public function setOriginForm(?int $originForm): void
485
-    {
486
-        $this->originform = $originForm;
487
-    }
399
+		);
400
+
401
+		$logQuery->bindValue(":requestr", $this->getId());
402
+		$logQuery->bindValue(":requestl", $this->getId());
403
+		$logQuery->bindValue(":requestc", $this->getId());
404
+		$logQuery->execute();
405
+		$logTime = $logQuery->fetchColumn();
406
+		$logQuery->closeCursor();
407
+
408
+		return new DateTime($logTime);
409
+	}
410
+
411
+	/**
412
+	 * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal
413
+	 * data to unauthorised* users.
414
+	 *
415
+	 * *:Not tool admins, check users, or the reserving user.
416
+	 *
417
+	 * @return string
418
+	 *
419
+	 * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events?
420
+	 *       Maybe depend on the last logged action timestamp?
421
+	 */
422
+	public function getRevealHash()
423
+	{
424
+		$data = $this->id         // unique per request
425
+			. '|' . $this->ip           // }
426
+			. '|' . $this->forwardedip  // } private data not known to those without access
427
+			. '|' . $this->useragent    // }
428
+			. '|' . $this->email        // }
429
+			. '|' . $this->status; // to rudimentarily invalidate the token on status change
430
+
431
+		return hash('sha256', $data);
432
+	}
433
+
434
+	/**
435
+	 * @return int|null
436
+	 */
437
+	public function getQueue() : ?int
438
+	{
439
+		return $this->queue;
440
+	}
441
+
442
+	/**
443
+	 * @return RequestQueue|null
444
+	 */
445
+	public function getQueueObject(): ?RequestQueue
446
+	{
447
+		/** @var RequestQueue $queue */
448
+		$queue = RequestQueue::getById($this->queue, $this->getDatabase());
449
+
450
+		return $queue === false ? null : $queue;
451
+	}
452
+
453
+	/**
454
+	 * @param int|null $queue
455
+	 */
456
+	public function setQueue(?int $queue): void
457
+	{
458
+		$this->queue = $queue;
459
+	}
460
+
461
+	/**
462
+	 * @return int|null
463
+	 */
464
+	public function getOriginForm(): ?int
465
+	{
466
+		return $this->originform;
467
+	}
468
+
469
+	public function getOriginFormObject(): ?RequestForm
470
+	{
471
+		if ($this->originform === null) {
472
+			return null;
473
+		}
474
+
475
+		/** @var RequestForm|bool $form */
476
+		$form = RequestForm::getById($this->originform, $this->getDatabase());
477
+
478
+		return $form === false ? null : $form;
479
+	}
480
+
481
+	/**
482
+	 * @param int|null $originForm
483
+	 */
484
+	public function setOriginForm(?int $originForm): void
485
+	{
486
+		$this->originform = $originForm;
487
+	}
488 488
 }
Please login to merge, or discard this patch.
includes/DataObjects/RequestQueue.php 1 patch
Indentation   +422 added lines, -422 removed lines patch added patch discarded remove patch
@@ -17,254 +17,254 @@  discard block
 block discarded – undo
17 17
 
18 18
 class RequestQueue extends DataObject
19 19
 {
20
-    const DEFAULT_DEFAULT = 'default';
21
-    const DEFAULT_ANTISPOOF = 'antispoof';
22
-    const DEFAULT_TITLEBLACKLIST = 'titleblacklist';
23
-
24
-    /** @var int */
25
-    private $enabled = 0;
26
-    /** @var int */
27
-    private $isdefault = 0;
28
-    /** @var int */
29
-    private $defaultantispoof = 0;
30
-    /** @var int */
31
-    private $defaulttitleblacklist = 0;
32
-    /** @var int */
33
-    private $domain;
34
-    /** @var string */
35
-    private $apiname;
36
-    /** @var string */
37
-    private $displayname;
38
-    /** @var string */
39
-    private $header;
40
-    /** @var string|null */
41
-    private $help;
42
-    /**
43
-     * @var string
44
-     * @deprecated Removal due as part of #607
45
-     */
46
-    private $logname;
47
-    /**
48
-     * @param PdoDatabase $database
49
-     *
50
-     * @return RequestQueue[]
51
-     */
52
-    public static function getAllQueues(PdoDatabase $database)
53
-    {
54
-        $statement = $database->prepare(<<<SQL
20
+	const DEFAULT_DEFAULT = 'default';
21
+	const DEFAULT_ANTISPOOF = 'antispoof';
22
+	const DEFAULT_TITLEBLACKLIST = 'titleblacklist';
23
+
24
+	/** @var int */
25
+	private $enabled = 0;
26
+	/** @var int */
27
+	private $isdefault = 0;
28
+	/** @var int */
29
+	private $defaultantispoof = 0;
30
+	/** @var int */
31
+	private $defaulttitleblacklist = 0;
32
+	/** @var int */
33
+	private $domain;
34
+	/** @var string */
35
+	private $apiname;
36
+	/** @var string */
37
+	private $displayname;
38
+	/** @var string */
39
+	private $header;
40
+	/** @var string|null */
41
+	private $help;
42
+	/**
43
+	 * @var string
44
+	 * @deprecated Removal due as part of #607
45
+	 */
46
+	private $logname;
47
+	/**
48
+	 * @param PdoDatabase $database
49
+	 *
50
+	 * @return RequestQueue[]
51
+	 */
52
+	public static function getAllQueues(PdoDatabase $database)
53
+	{
54
+		$statement = $database->prepare(<<<SQL
55 55
             SELECT * FROM requestqueue;
56 56
 SQL
57
-        );
58
-        $statement->execute();
59
-
60
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
61
-
62
-        /** @var RequestQueue $t */
63
-        foreach ($resultObject as $t) {
64
-            $t->setDatabase($database);
65
-        }
66
-
67
-        return $resultObject;
68
-    }
69
-
70
-    /**
71
-     * @param PdoDatabase $database
72
-     *
73
-     * @return RequestQueue[]
74
-     */
75
-    public static function getEnabledQueues(PdoDatabase $database)
76
-    {
77
-        $statement = $database->prepare(<<<SQL
57
+		);
58
+		$statement->execute();
59
+
60
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
61
+
62
+		/** @var RequestQueue $t */
63
+		foreach ($resultObject as $t) {
64
+			$t->setDatabase($database);
65
+		}
66
+
67
+		return $resultObject;
68
+	}
69
+
70
+	/**
71
+	 * @param PdoDatabase $database
72
+	 *
73
+	 * @return RequestQueue[]
74
+	 */
75
+	public static function getEnabledQueues(PdoDatabase $database)
76
+	{
77
+		$statement = $database->prepare(<<<SQL
78 78
             SELECT * FROM requestqueue WHERE enabled = 1;
79 79
 SQL
80
-        );
81
-        $statement->execute();
82
-
83
-        $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
84
-
85
-        /** @var RequestQueue $t */
86
-        foreach ($resultObject as $t) {
87
-            $t->setDatabase($database);
88
-        }
89
-
90
-        return $resultObject;
91
-    }
92
-
93
-    /**
94
-     * @param PdoDatabase $database
95
-     * @param string      $apiName
96
-     * @param int         $domain
97
-     *
98
-     * @return false|RequestQueue
99
-     */
100
-    public static function getByApiName(PdoDatabase $database, string $apiName, int $domain)
101
-    {
102
-        $statement = $database->prepare(<<<SQL
80
+		);
81
+		$statement->execute();
82
+
83
+		$resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class());
84
+
85
+		/** @var RequestQueue $t */
86
+		foreach ($resultObject as $t) {
87
+			$t->setDatabase($database);
88
+		}
89
+
90
+		return $resultObject;
91
+	}
92
+
93
+	/**
94
+	 * @param PdoDatabase $database
95
+	 * @param string      $apiName
96
+	 * @param int         $domain
97
+	 *
98
+	 * @return false|RequestQueue
99
+	 */
100
+	public static function getByApiName(PdoDatabase $database, string $apiName, int $domain)
101
+	{
102
+		$statement = $database->prepare(<<<SQL
103 103
             SELECT * FROM requestqueue WHERE apiname = :apiName AND domain = :domain;
104 104
 SQL
105
-        );
106
-
107
-        $statement->execute([
108
-            ':apiName' => $apiName,
109
-            ':domain'  => $domain,
110
-        ]);
111
-
112
-        /** @var RequestQueue|false $result */
113
-        $result = $statement->fetchObject(get_called_class());
114
-
115
-        if ($result !== false) {
116
-            $result->setDatabase($database);
117
-        }
118
-
119
-        return $result;
120
-    }
121
-
122
-    /**
123
-     * @param PdoDatabase $database
124
-     * @param string      $displayName
125
-     * @param int         $domain
126
-     *
127
-     * @return false|RequestQueue
128
-     */
129
-    public static function getByDisplayName(PdoDatabase $database, string $displayName, int $domain)
130
-    {
131
-        $statement = $database->prepare(<<<SQL
105
+		);
106
+
107
+		$statement->execute([
108
+			':apiName' => $apiName,
109
+			':domain'  => $domain,
110
+		]);
111
+
112
+		/** @var RequestQueue|false $result */
113
+		$result = $statement->fetchObject(get_called_class());
114
+
115
+		if ($result !== false) {
116
+			$result->setDatabase($database);
117
+		}
118
+
119
+		return $result;
120
+	}
121
+
122
+	/**
123
+	 * @param PdoDatabase $database
124
+	 * @param string      $displayName
125
+	 * @param int         $domain
126
+	 *
127
+	 * @return false|RequestQueue
128
+	 */
129
+	public static function getByDisplayName(PdoDatabase $database, string $displayName, int $domain)
130
+	{
131
+		$statement = $database->prepare(<<<SQL
132 132
             SELECT * FROM requestqueue WHERE displayname = :displayName AND domain = :domain;
133 133
 SQL
134
-        );
135
-
136
-        $statement->execute([
137
-            ':displayName' => $displayName,
138
-            ':domain'      => $domain,
139
-        ]);
140
-
141
-        /** @var RequestQueue|false $result */
142
-        $result = $statement->fetchObject(get_called_class());
143
-
144
-        if ($result !== false) {
145
-            $result->setDatabase($database);
146
-        }
147
-
148
-        return $result;
149
-    }
150
-
151
-    /**
152
-     * @param PdoDatabase $database
153
-     * @param string      $header
154
-     * @param int         $domain
155
-     *
156
-     * @return false|RequestQueue
157
-     */
158
-    public static function getByHeader(PdoDatabase $database, string $header, int $domain)
159
-    {
160
-        $statement = $database->prepare(<<<SQL
134
+		);
135
+
136
+		$statement->execute([
137
+			':displayName' => $displayName,
138
+			':domain'      => $domain,
139
+		]);
140
+
141
+		/** @var RequestQueue|false $result */
142
+		$result = $statement->fetchObject(get_called_class());
143
+
144
+		if ($result !== false) {
145
+			$result->setDatabase($database);
146
+		}
147
+
148
+		return $result;
149
+	}
150
+
151
+	/**
152
+	 * @param PdoDatabase $database
153
+	 * @param string      $header
154
+	 * @param int         $domain
155
+	 *
156
+	 * @return false|RequestQueue
157
+	 */
158
+	public static function getByHeader(PdoDatabase $database, string $header, int $domain)
159
+	{
160
+		$statement = $database->prepare(<<<SQL
161 161
             SELECT * FROM requestqueue WHERE header = :header AND domain = :domain;
162 162
 SQL
163
-        );
164
-
165
-        $statement->execute([
166
-            ':header' => $header,
167
-            ':domain' => $domain,
168
-        ]);
169
-
170
-        /** @var RequestQueue|false $result */
171
-        $result = $statement->fetchObject(get_called_class());
172
-
173
-        if ($result !== false) {
174
-            $result->setDatabase($database);
175
-        }
176
-
177
-        return $result;
178
-    }
179
-
180
-    /**
181
-     * @param PdoDatabase $database
182
-     * @param int         $domain
183
-     *
184
-     * @param string      $defaultType The type of default queue to get.
185
-     *
186
-     * @return false|RequestQueue
187
-     * @throws ApplicationLogicException
188
-     */
189
-    public static function getDefaultQueue(PdoDatabase $database, int $domain, string $defaultType = 'default')
190
-    {
191
-        switch ($defaultType) {
192
-            case self::DEFAULT_DEFAULT:
193
-                $sql = 'SELECT * FROM requestqueue WHERE isdefault = 1 AND domain = :domain;';
194
-                break;
195
-            case self::DEFAULT_ANTISPOOF:
196
-                $sql = 'SELECT * FROM requestqueue WHERE defaultantispoof = 1 AND domain = :domain;';
197
-                break;
198
-            case self::DEFAULT_TITLEBLACKLIST:
199
-                $sql = 'SELECT * FROM requestqueue WHERE defaulttitleblacklist = 1 AND domain = :domain;';
200
-                break;
201
-            default:
202
-                throw new ApplicationLogicException('Unknown request for default queue');
203
-        }
204
-
205
-        $statement = $database->prepare($sql);
206
-
207
-        $statement->execute([':domain' => $domain]);
208
-
209
-        /** @var RequestQueue|false $result */
210
-        $result = $statement->fetchObject(get_called_class());
211
-
212
-        if ($result !== false) {
213
-            $result->setDatabase($database);
214
-        }
215
-
216
-        return $result;
217
-    }
218
-
219
-    public function save()
220
-    {
221
-        // find and squish existing defaults
222
-        if ($this->isDefault()) {
223
-            $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET isdefault = 0 WHERE isdefault = 1 AND domain = :domain;');
224
-            $squishStatement->execute([':domain' => $this->domain]);
225
-        }
226
-
227
-        if ($this->isDefaultAntispoof()) {
228
-            $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaultantispoof = 0 WHERE defaultantispoof = 1 AND domain = :domain;');
229
-            $squishStatement->execute([':domain' => $this->domain]);
230
-        }
231
-
232
-        if ($this->isDefaultTitleBlacklist()) {
233
-            $squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaulttitleblacklist = 0 WHERE defaulttitleblacklist = 1 AND domain = :domain;');
234
-            $squishStatement->execute([':domain' => $this->domain]);
235
-        }
236
-
237
-        if ($this->isNew()) {
238
-            // insert
239
-            $statement = $this->dbObject->prepare(<<<SQL
163
+		);
164
+
165
+		$statement->execute([
166
+			':header' => $header,
167
+			':domain' => $domain,
168
+		]);
169
+
170
+		/** @var RequestQueue|false $result */
171
+		$result = $statement->fetchObject(get_called_class());
172
+
173
+		if ($result !== false) {
174
+			$result->setDatabase($database);
175
+		}
176
+
177
+		return $result;
178
+	}
179
+
180
+	/**
181
+	 * @param PdoDatabase $database
182
+	 * @param int         $domain
183
+	 *
184
+	 * @param string      $defaultType The type of default queue to get.
185
+	 *
186
+	 * @return false|RequestQueue
187
+	 * @throws ApplicationLogicException
188
+	 */
189
+	public static function getDefaultQueue(PdoDatabase $database, int $domain, string $defaultType = 'default')
190
+	{
191
+		switch ($defaultType) {
192
+			case self::DEFAULT_DEFAULT:
193
+				$sql = 'SELECT * FROM requestqueue WHERE isdefault = 1 AND domain = :domain;';
194
+				break;
195
+			case self::DEFAULT_ANTISPOOF:
196
+				$sql = 'SELECT * FROM requestqueue WHERE defaultantispoof = 1 AND domain = :domain;';
197
+				break;
198
+			case self::DEFAULT_TITLEBLACKLIST:
199
+				$sql = 'SELECT * FROM requestqueue WHERE defaulttitleblacklist = 1 AND domain = :domain;';
200
+				break;
201
+			default:
202
+				throw new ApplicationLogicException('Unknown request for default queue');
203
+		}
204
+
205
+		$statement = $database->prepare($sql);
206
+
207
+		$statement->execute([':domain' => $domain]);
208
+
209
+		/** @var RequestQueue|false $result */
210
+		$result = $statement->fetchObject(get_called_class());
211
+
212
+		if ($result !== false) {
213
+			$result->setDatabase($database);
214
+		}
215
+
216
+		return $result;
217
+	}
218
+
219
+	public function save()
220
+	{
221
+		// find and squish existing defaults
222
+		if ($this->isDefault()) {
223
+			$squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET isdefault = 0 WHERE isdefault = 1 AND domain = :domain;');
224
+			$squishStatement->execute([':domain' => $this->domain]);
225
+		}
226
+
227
+		if ($this->isDefaultAntispoof()) {
228
+			$squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaultantispoof = 0 WHERE defaultantispoof = 1 AND domain = :domain;');
229
+			$squishStatement->execute([':domain' => $this->domain]);
230
+		}
231
+
232
+		if ($this->isDefaultTitleBlacklist()) {
233
+			$squishStatement = $this->dbObject->prepare('UPDATE requestqueue SET defaulttitleblacklist = 0 WHERE defaulttitleblacklist = 1 AND domain = :domain;');
234
+			$squishStatement->execute([':domain' => $this->domain]);
235
+		}
236
+
237
+		if ($this->isNew()) {
238
+			// insert
239
+			$statement = $this->dbObject->prepare(<<<SQL
240 240
                 INSERT INTO requestqueue (
241 241
                     enabled, isdefault, defaultantispoof, defaulttitleblacklist, domain, apiname, displayname, header, help, logname
242 242
                 ) VALUES (
243 243
                     :enabled, :isdefault, :defaultantispoof, :defaulttitleblacklist, :domain, :apiname, :displayname, :header, :help, :logname
244 244
                 );
245 245
 SQL
246
-            );
247
-
248
-            $statement->bindValue(":enabled", $this->enabled);
249
-            $statement->bindValue(":isdefault", $this->isdefault);
250
-            $statement->bindValue(":defaultantispoof", $this->defaultantispoof);
251
-            $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist);
252
-            $statement->bindValue(":domain", $this->domain);
253
-            $statement->bindValue(":apiname", $this->apiname);
254
-            $statement->bindValue(":displayname", $this->displayname);
255
-            $statement->bindValue(":header", $this->header);
256
-            $statement->bindValue(":help", $this->help);
257
-            $statement->bindValue(":logname", $this->logname);
258
-
259
-            if ($statement->execute()) {
260
-                $this->id = (int)$this->dbObject->lastInsertId();
261
-            }
262
-            else {
263
-                throw new Exception($statement->errorInfo());
264
-            }
265
-        }
266
-        else {
267
-            $statement = $this->dbObject->prepare(<<<SQL
246
+			);
247
+
248
+			$statement->bindValue(":enabled", $this->enabled);
249
+			$statement->bindValue(":isdefault", $this->isdefault);
250
+			$statement->bindValue(":defaultantispoof", $this->defaultantispoof);
251
+			$statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist);
252
+			$statement->bindValue(":domain", $this->domain);
253
+			$statement->bindValue(":apiname", $this->apiname);
254
+			$statement->bindValue(":displayname", $this->displayname);
255
+			$statement->bindValue(":header", $this->header);
256
+			$statement->bindValue(":help", $this->help);
257
+			$statement->bindValue(":logname", $this->logname);
258
+
259
+			if ($statement->execute()) {
260
+				$this->id = (int)$this->dbObject->lastInsertId();
261
+			}
262
+			else {
263
+				throw new Exception($statement->errorInfo());
264
+			}
265
+		}
266
+		else {
267
+			$statement = $this->dbObject->prepare(<<<SQL
268 268
                 UPDATE requestqueue SET
269 269
                     enabled = :enabled,
270 270
                     isdefault = :isdefault,
@@ -280,194 +280,194 @@  discard block
 block discarded – undo
280 280
                     updateversion = updateversion + 1
281 281
 				WHERE id = :id AND updateversion = :updateversion;
282 282
 SQL
283
-            );
284
-
285
-            $statement->bindValue(":enabled", $this->enabled);
286
-            $statement->bindValue(":isdefault", $this->isdefault);
287
-            $statement->bindValue(":defaultantispoof", $this->defaultantispoof);
288
-            $statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist);
289
-            $statement->bindValue(":domain", $this->domain);
290
-            $statement->bindValue(":apiname", $this->apiname);
291
-            $statement->bindValue(":displayname", $this->displayname);
292
-            $statement->bindValue(":header", $this->header);
293
-            $statement->bindValue(":help", $this->help);
294
-            $statement->bindValue(":logname", $this->logname);
295
-
296
-            $statement->bindValue(':id', $this->id);
297
-            $statement->bindValue(':updateversion', $this->updateversion);
298
-
299
-            if (!$statement->execute()) {
300
-                throw new Exception($statement->errorInfo());
301
-            }
302
-
303
-            if ($statement->rowCount() !== 1) {
304
-                throw new OptimisticLockFailedException();
305
-            }
306
-
307
-            $this->updateversion++;
308
-        }
309
-    }
310
-
311
-    /**
312
-     * @return bool
313
-     */
314
-    public function isEnabled(): bool
315
-    {
316
-        return $this->enabled == 1;
317
-    }
318
-
319
-    /**
320
-     * @param bool $enabled
321
-     */
322
-    public function setEnabled(bool $enabled): void
323
-    {
324
-        $this->enabled = $enabled ? 1 : 0;
325
-    }
326
-
327
-    /**
328
-     * @return bool
329
-     */
330
-    public function isDefault(): bool
331
-    {
332
-        return $this->isdefault == 1;
333
-    }
334
-
335
-    /**
336
-     * @param bool $isDefault
337
-     */
338
-    public function setDefault(bool $isDefault): void
339
-    {
340
-        $this->isdefault = $isDefault ? 1 : 0;
341
-    }
342
-
343
-    /**
344
-     * @return bool
345
-     */
346
-    public function isDefaultAntispoof(): bool
347
-    {
348
-        return $this->defaultantispoof == 1;
349
-    }
350
-
351
-    /**
352
-     * @param bool $isDefault
353
-     */
354
-    public function setDefaultAntispoof(bool $isDefault): void
355
-    {
356
-        $this->defaultantispoof = $isDefault ? 1 : 0;
357
-    }
358
-
359
-    /**
360
-     * @return bool
361
-     */
362
-    public function isDefaultTitleBlacklist(): bool
363
-    {
364
-        return $this->defaulttitleblacklist == 1;
365
-    }
366
-
367
-    /**
368
-     * @param bool $isDefault
369
-     */
370
-    public function setDefaultTitleBlacklist(bool $isDefault): void
371
-    {
372
-        $this->defaulttitleblacklist = $isDefault ? 1 : 0;
373
-    }
374
-
375
-    /**
376
-     * @return int
377
-     */
378
-    public function getDomain(): int
379
-    {
380
-        return $this->domain;
381
-    }
382
-
383
-    /**
384
-     * @param int $domain
385
-     */
386
-    public function setDomain(int $domain): void
387
-    {
388
-        $this->domain = $domain;
389
-    }
390
-
391
-    /**
392
-     * @return string
393
-     */
394
-    public function getApiName(): string
395
-    {
396
-        return $this->apiname;
397
-    }
398
-
399
-    /**
400
-     * @param string $apiName
401
-     */
402
-    public function setApiName(string $apiName): void
403
-    {
404
-        $this->apiname = $apiName;
405
-    }
406
-
407
-    /**
408
-     * @return string
409
-     */
410
-    public function getDisplayName(): string
411
-    {
412
-        return $this->displayname;
413
-    }
414
-
415
-    /**
416
-     * @param string $displayName
417
-     */
418
-    public function setDisplayName(string $displayName): void
419
-    {
420
-        $this->displayname = $displayName;
421
-    }
422
-
423
-    /**
424
-     * @return string
425
-     */
426
-    public function getHeader(): string
427
-    {
428
-        return $this->header;
429
-    }
430
-
431
-    /**
432
-     * @param string $header
433
-     */
434
-    public function setHeader(string $header): void
435
-    {
436
-        $this->header = $header;
437
-    }
438
-
439
-    /**
440
-     * @return string|null
441
-     */
442
-    public function getHelp(): ?string
443
-    {
444
-        return $this->help;
445
-    }
446
-
447
-    /**
448
-     * @param string|null $help
449
-     */
450
-    public function setHelp(?string $help): void
451
-    {
452
-        $this->help = $help;
453
-    }
454
-
455
-    /**
456
-     * @return string
457
-     * @deprecated
458
-     */
459
-    public function getLogName(): string
460
-    {
461
-        return $this->logname;
462
-    }
463
-
464
-    /**
465
-     * @param string $logName
466
-     *
467
-     * @deprecated
468
-     */
469
-    public function setLogName(string $logName): void
470
-    {
471
-        $this->logname = $logName;
472
-    }
283
+			);
284
+
285
+			$statement->bindValue(":enabled", $this->enabled);
286
+			$statement->bindValue(":isdefault", $this->isdefault);
287
+			$statement->bindValue(":defaultantispoof", $this->defaultantispoof);
288
+			$statement->bindValue(":defaulttitleblacklist", $this->defaulttitleblacklist);
289
+			$statement->bindValue(":domain", $this->domain);
290
+			$statement->bindValue(":apiname", $this->apiname);
291
+			$statement->bindValue(":displayname", $this->displayname);
292
+			$statement->bindValue(":header", $this->header);
293
+			$statement->bindValue(":help", $this->help);
294
+			$statement->bindValue(":logname", $this->logname);
295
+
296
+			$statement->bindValue(':id', $this->id);
297
+			$statement->bindValue(':updateversion', $this->updateversion);
298
+
299
+			if (!$statement->execute()) {
300
+				throw new Exception($statement->errorInfo());
301
+			}
302
+
303
+			if ($statement->rowCount() !== 1) {
304
+				throw new OptimisticLockFailedException();
305
+			}
306
+
307
+			$this->updateversion++;
308
+		}
309
+	}
310
+
311
+	/**
312
+	 * @return bool
313
+	 */
314
+	public function isEnabled(): bool
315
+	{
316
+		return $this->enabled == 1;
317
+	}
318
+
319
+	/**
320
+	 * @param bool $enabled
321
+	 */
322
+	public function setEnabled(bool $enabled): void
323
+	{
324
+		$this->enabled = $enabled ? 1 : 0;
325
+	}
326
+
327
+	/**
328
+	 * @return bool
329
+	 */
330
+	public function isDefault(): bool
331
+	{
332
+		return $this->isdefault == 1;
333
+	}
334
+
335
+	/**
336
+	 * @param bool $isDefault
337
+	 */
338
+	public function setDefault(bool $isDefault): void
339
+	{
340
+		$this->isdefault = $isDefault ? 1 : 0;
341
+	}
342
+
343
+	/**
344
+	 * @return bool
345
+	 */
346
+	public function isDefaultAntispoof(): bool
347
+	{
348
+		return $this->defaultantispoof == 1;
349
+	}
350
+
351
+	/**
352
+	 * @param bool $isDefault
353
+	 */
354
+	public function setDefaultAntispoof(bool $isDefault): void
355
+	{
356
+		$this->defaultantispoof = $isDefault ? 1 : 0;
357
+	}
358
+
359
+	/**
360
+	 * @return bool
361
+	 */
362
+	public function isDefaultTitleBlacklist(): bool
363
+	{
364
+		return $this->defaulttitleblacklist == 1;
365
+	}
366
+
367
+	/**
368
+	 * @param bool $isDefault
369
+	 */
370
+	public function setDefaultTitleBlacklist(bool $isDefault): void
371
+	{
372
+		$this->defaulttitleblacklist = $isDefault ? 1 : 0;
373
+	}
374
+
375
+	/**
376
+	 * @return int
377
+	 */
378
+	public function getDomain(): int
379
+	{
380
+		return $this->domain;
381
+	}
382
+
383
+	/**
384
+	 * @param int $domain
385
+	 */
386
+	public function setDomain(int $domain): void
387
+	{
388
+		$this->domain = $domain;
389
+	}
390
+
391
+	/**
392
+	 * @return string
393
+	 */
394
+	public function getApiName(): string
395
+	{
396
+		return $this->apiname;
397
+	}
398
+
399
+	/**
400
+	 * @param string $apiName
401
+	 */
402
+	public function setApiName(string $apiName): void
403
+	{
404
+		$this->apiname = $apiName;
405
+	}
406
+
407
+	/**
408
+	 * @return string
409
+	 */
410
+	public function getDisplayName(): string
411
+	{
412
+		return $this->displayname;
413
+	}
414
+
415
+	/**
416
+	 * @param string $displayName
417
+	 */
418
+	public function setDisplayName(string $displayName): void
419
+	{
420
+		$this->displayname = $displayName;
421
+	}
422
+
423
+	/**
424
+	 * @return string
425
+	 */
426
+	public function getHeader(): string
427
+	{
428
+		return $this->header;
429
+	}
430
+
431
+	/**
432
+	 * @param string $header
433
+	 */
434
+	public function setHeader(string $header): void
435
+	{
436
+		$this->header = $header;
437
+	}
438
+
439
+	/**
440
+	 * @return string|null
441
+	 */
442
+	public function getHelp(): ?string
443
+	{
444
+		return $this->help;
445
+	}
446
+
447
+	/**
448
+	 * @param string|null $help
449
+	 */
450
+	public function setHelp(?string $help): void
451
+	{
452
+		$this->help = $help;
453
+	}
454
+
455
+	/**
456
+	 * @return string
457
+	 * @deprecated
458
+	 */
459
+	public function getLogName(): string
460
+	{
461
+		return $this->logname;
462
+	}
463
+
464
+	/**
465
+	 * @param string $logName
466
+	 *
467
+	 * @deprecated
468
+	 */
469
+	public function setLogName(string $logName): void
470
+	{
471
+		$this->logname = $logName;
472
+	}
473 473
 }
474 474
\ No newline at end of file
Please login to merge, or discard this patch.
includes/API/Actions/CountAction.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -21,47 +21,47 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class CountAction extends XmlApiPageBase implements IXmlApiAction
23 23
 {
24
-    /**
25
-     * The target user
26
-     * @var User $user
27
-     */
28
-    private $user;
24
+	/**
25
+	 * The target user
26
+	 * @var User $user
27
+	 */
28
+	private $user;
29 29
 
30
-    public function executeApiAction(DOMElement $apiDocument)
31
-    {
32
-        $username = WebRequest::getString('user');
33
-        if ($username === null) {
34
-            throw new ApiException("Please specify a username");
35
-        }
30
+	public function executeApiAction(DOMElement $apiDocument)
31
+	{
32
+		$username = WebRequest::getString('user');
33
+		if ($username === null) {
34
+			throw new ApiException("Please specify a username");
35
+		}
36 36
 
37
-        $userElement = $this->document->createElement("user");
38
-        $userElement->setAttribute("name", $username);
39
-        $apiDocument->appendChild($userElement);
37
+		$userElement = $this->document->createElement("user");
38
+		$userElement->setAttribute("name", $username);
39
+		$apiDocument->appendChild($userElement);
40 40
 
41
-        $user = User::getByUsername($username, $this->getDatabase());
41
+		$user = User::getByUsername($username, $this->getDatabase());
42 42
 
43
-        if ($user === false) {
44
-            $userElement->setAttribute("missing", "true");
43
+		if ($user === false) {
44
+			$userElement->setAttribute("missing", "true");
45 45
 
46
-            return $apiDocument;
47
-        }
46
+			return $apiDocument;
47
+		}
48 48
 
49
-        $this->user = $user;
49
+		$this->user = $user;
50 50
 
51
-        $userElement->setAttribute("level", $this->user->getStatus());
52
-        $userElement->setAttribute("created", $this->getAccountsCreated());
51
+		$userElement->setAttribute("level", $this->user->getStatus());
52
+		$userElement->setAttribute("created", $this->getAccountsCreated());
53 53
 
54
-        $userElement->setAttribute("today", $this->getToday());
54
+		$userElement->setAttribute("today", $this->getToday());
55 55
 
56
-        // Let the IRC bot handle the result of this.
57
-        $this->fetchAdminData($userElement);
56
+		// Let the IRC bot handle the result of this.
57
+		$this->fetchAdminData($userElement);
58 58
 
59
-        return $apiDocument;
60
-    }
59
+		return $apiDocument;
60
+	}
61 61
 
62
-    private function getAccountsCreated()
63
-    {
64
-        $query = <<<QUERY
62
+	private function getAccountsCreated()
63
+	{
64
+		$query = <<<QUERY
65 65
         SELECT COUNT(*) AS count
66 66
         FROM log
67 67
             LEFT JOIN emailtemplate ON concat('Closed ', emailtemplate.id) = log.action
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
             AND user.username = :username;
73 73
 QUERY;
74 74
 
75
-        $statement = $this->getDatabase()->prepare($query);
76
-        $statement->execute(array(":username" => $this->user->getUsername(), ":created" => EmailTemplate::ACTION_CREATED));
77
-        $result = $statement->fetchColumn();
78
-        $statement->closeCursor();
75
+		$statement = $this->getDatabase()->prepare($query);
76
+		$statement->execute(array(":username" => $this->user->getUsername(), ":created" => EmailTemplate::ACTION_CREATED));
77
+		$result = $statement->fetchColumn();
78
+		$statement->closeCursor();
79 79
 
80
-        return $result;
81
-    }
80
+		return $result;
81
+	}
82 82
 
83
-    private function getToday()
84
-    {
85
-        $query = <<<QUERY
83
+	private function getToday()
84
+	{
85
+		$query = <<<QUERY
86 86
         SELECT
87 87
             COUNT(*) AS count
88 88
         FROM log
@@ -94,76 +94,76 @@  discard block
 block discarded – undo
94 94
             AND user.username = :username;
95 95
 QUERY;
96 96
 
97
-        $statement = $this->getDatabase()->prepare($query);
98
-        $statement->bindValue(":username", $this->user->getUsername());
99
-        $statement->bindValue(":date", date('Y-m-d') . "%");
100
-        $statement->bindValue(":created", EmailTemplate::ACTION_CREATED);
101
-        $statement->execute();
102
-        $today = $statement->fetchColumn();
103
-        $statement->closeCursor();
97
+		$statement = $this->getDatabase()->prepare($query);
98
+		$statement->bindValue(":username", $this->user->getUsername());
99
+		$statement->bindValue(":date", date('Y-m-d') . "%");
100
+		$statement->bindValue(":created", EmailTemplate::ACTION_CREATED);
101
+		$statement->execute();
102
+		$today = $statement->fetchColumn();
103
+		$statement->closeCursor();
104 104
 
105
-        return $today;
106
-    }
105
+		return $today;
106
+	}
107 107
 
108
-    private function fetchAdminData(DOMElement $userElement)
109
-    {
110
-        $query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;";
108
+	private function fetchAdminData(DOMElement $userElement)
109
+	{
110
+		$query = "SELECT COUNT(*) AS count FROM log WHERE log.user = :userid AND log.action = :action;";
111 111
 
112
-        $statement = $this->getDatabase()->prepare($query);
113
-        $statement->bindValue(":userid", $this->user->getId());
112
+		$statement = $this->getDatabase()->prepare($query);
113
+		$statement->bindValue(":userid", $this->user->getId());
114 114
         
115
-        // Each entry is in the form [ database string, attribute name ]
116
-        // and it happens to be that the attribute is just the lower case form of the database value
117
-        $actions = [
118
-            ['Suspended', 'suspended'],
119
-            ['Promoted', 'promoted'],
120
-            ['Approved', 'approved'],
121
-            ['Demoted', 'demoted'],
122
-            ['Declined', 'declined'],
123
-            ['Renamed', 'renamed'],
124
-            ['Edited', 'edited'],
125
-            ['Prefchange', 'prefchange'],
126
-        ];
127
-        foreach ($actions as $action) {
128
-            $dbValue = $action[0];
129
-            $attributeName = $action[1];
115
+		// Each entry is in the form [ database string, attribute name ]
116
+		// and it happens to be that the attribute is just the lower case form of the database value
117
+		$actions = [
118
+			['Suspended', 'suspended'],
119
+			['Promoted', 'promoted'],
120
+			['Approved', 'approved'],
121
+			['Demoted', 'demoted'],
122
+			['Declined', 'declined'],
123
+			['Renamed', 'renamed'],
124
+			['Edited', 'edited'],
125
+			['Prefchange', 'prefchange'],
126
+		];
127
+		foreach ($actions as $action) {
128
+			$dbValue = $action[0];
129
+			$attributeName = $action[1];
130 130
             
131
-            $statement->bindValue(":action", $dbValue);
132
-            $statement->execute();
133
-            $attributeValue = $statement->fetchColumn();
134
-            $userElement->setAttribute($attributeName, $attributeValue);
135
-            $statement->closeCursor();
136
-        }
137
-
138
-        // Combine all three actions affecting Welcome templates into one count.
139
-        $combinedquery = $this->getDatabase()->prepare(<<<SQL
131
+			$statement->bindValue(":action", $dbValue);
132
+			$statement->execute();
133
+			$attributeValue = $statement->fetchColumn();
134
+			$userElement->setAttribute($attributeName, $attributeValue);
135
+			$statement->closeCursor();
136
+		}
137
+
138
+		// Combine all three actions affecting Welcome templates into one count.
139
+		$combinedquery = $this->getDatabase()->prepare(<<<SQL
140 140
             SELECT
141 141
                 COUNT(*) AS count
142 142
             FROM log
143 143
             WHERE log.user = :userid
144 144
                 AND log.action IN ('CreatedTemplate', 'EditedTemplate', 'DeletedTemplate');
145 145
 SQL
146
-        );
146
+		);
147 147
 
148
-        $combinedquery->bindValue(":userid", $this->user->getId());
149
-        $combinedquery->execute();
150
-        $dtc = $combinedquery->fetchColumn();
151
-        $userElement->setAttribute("welctempchange", $dtc);
152
-        $combinedquery->closeCursor();
148
+		$combinedquery->bindValue(":userid", $this->user->getId());
149
+		$combinedquery->execute();
150
+		$dtc = $combinedquery->fetchColumn();
151
+		$userElement->setAttribute("welctempchange", $dtc);
152
+		$combinedquery->closeCursor();
153 153
 
154
-        // Combine both actions affecting Email templates into one count.
155
-        $combinedquery = $this->getDatabase()->prepare(<<<SQL
154
+		// Combine both actions affecting Email templates into one count.
155
+		$combinedquery = $this->getDatabase()->prepare(<<<SQL
156 156
             SELECT COUNT(*) AS count
157 157
             FROM log
158 158
             WHERE log.user = :userid
159 159
                 AND log.action IN ('CreatedEmail', 'EditedEmail');
160 160
 SQL
161
-        );
162
-
163
-        $combinedquery->bindValue(":userid", $this->user->getId());
164
-        $combinedquery->execute();
165
-        $cec = $combinedquery->fetchColumn();
166
-        $userElement->setAttribute("emailtempchange", $cec);
167
-        $combinedquery->closeCursor();
168
-    }
161
+		);
162
+
163
+		$combinedquery->bindValue(":userid", $this->user->getId());
164
+		$combinedquery->execute();
165
+		$cec = $combinedquery->fetchColumn();
166
+		$userElement->setAttribute("emailtempchange", $cec);
167
+		$combinedquery->closeCursor();
168
+	}
169 169
 }
Please login to merge, or discard this patch.
includes/API/Actions/JsTemplateConfirmsAction.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,18 +14,18 @@
 block discarded – undo
14 14
 
15 15
 class JsTemplateConfirmsAction extends JsonApiPageBase implements IJsonApiAction
16 16
 {
17
-    public function executeApiAction()
18
-    {
19
-        /** @var EmailTemplate[] $templates */
20
-        $templates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
17
+	public function executeApiAction()
18
+	{
19
+		/** @var EmailTemplate[] $templates */
20
+		$templates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase());
21 21
 
22
-        $dataset = [];
23
-        foreach ($templates as $tpl) {
24
-            if ($tpl->getJsquestion() != "") {
25
-                $dataset[$tpl->getId()] = $tpl->getJsquestion();
26
-            }
27
-        }
22
+		$dataset = [];
23
+		foreach ($templates as $tpl) {
24
+			if ($tpl->getJsquestion() != "") {
25
+				$dataset[$tpl->getId()] = $tpl->getJsquestion();
26
+			}
27
+		}
28 28
 
29
-        return $dataset;
30
-    }
29
+		return $dataset;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
includes/API/Actions/JsUsersAction.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@
 block discarded – undo
16 16
 
17 17
 class JsUsersAction extends JsonApiPageBase implements IJsonApiAction
18 18
 {
19
-    public function executeApiAction()
20
-    {
21
-        $userSearchHelper = UserSearchHelper::get($this->getDatabase());
19
+	public function executeApiAction()
20
+	{
21
+		$userSearchHelper = UserSearchHelper::get($this->getDatabase());
22 22
 
23
-        if (WebRequest::getString('all') === null) {
24
-            $userSearchHelper->byStatus(User::STATUS_ACTIVE);
23
+		if (WebRequest::getString('all') === null) {
24
+			$userSearchHelper->byStatus(User::STATUS_ACTIVE);
25 25
 
26
-        }
26
+		}
27 27
 
28
-        $dataset = $userSearchHelper->fetchColumn('username');
29
-        return $dataset;
30
-    }
28
+		$dataset = $userSearchHelper->fetchColumn('username');
29
+		return $dataset;
30
+	}
31 31
 }
Please login to merge, or discard this patch.