@@ -21,30 +21,30 @@ discard block |
||
| 21 | 21 | */ |
| 22 | 22 | class Request extends DataObject |
| 23 | 23 | { |
| 24 | - private $email; |
|
| 25 | - private $ip; |
|
| 26 | - private $name; |
|
| 27 | - /** @var string|null */ |
|
| 28 | - private $status = "Open"; |
|
| 29 | - private $date; |
|
| 30 | - private $emailsent = 0; |
|
| 31 | - private $emailconfirm; |
|
| 32 | - /** @var int|null */ |
|
| 33 | - private $reserved = null; |
|
| 34 | - private $useragent; |
|
| 35 | - private $forwardedip; |
|
| 36 | - private $hasComments = false; |
|
| 37 | - private $hasCommentsResolved = false; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @throws Exception |
|
| 41 | - * @throws OptimisticLockFailedException |
|
| 42 | - */ |
|
| 43 | - public function save() |
|
| 44 | - { |
|
| 45 | - if ($this->isNew()) { |
|
| 46 | - // insert |
|
| 47 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 24 | + private $email; |
|
| 25 | + private $ip; |
|
| 26 | + private $name; |
|
| 27 | + /** @var string|null */ |
|
| 28 | + private $status = "Open"; |
|
| 29 | + private $date; |
|
| 30 | + private $emailsent = 0; |
|
| 31 | + private $emailconfirm; |
|
| 32 | + /** @var int|null */ |
|
| 33 | + private $reserved = null; |
|
| 34 | + private $useragent; |
|
| 35 | + private $forwardedip; |
|
| 36 | + private $hasComments = false; |
|
| 37 | + private $hasCommentsResolved = false; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @throws Exception |
|
| 41 | + * @throws OptimisticLockFailedException |
|
| 42 | + */ |
|
| 43 | + public function save() |
|
| 44 | + { |
|
| 45 | + if ($this->isNew()) { |
|
| 46 | + // insert |
|
| 47 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 48 | 48 | INSERT INTO `request` ( |
| 49 | 49 | email, ip, name, status, date, emailsent, |
| 50 | 50 | emailconfirm, reserved, useragent, forwardedip |
@@ -53,27 +53,27 @@ discard block |
||
| 53 | 53 | :emailconfirm, :reserved, :useragent, :forwardedip |
| 54 | 54 | ); |
| 55 | 55 | SQL |
| 56 | - ); |
|
| 57 | - $statement->bindValue(':email', $this->email); |
|
| 58 | - $statement->bindValue(':ip', $this->ip); |
|
| 59 | - $statement->bindValue(':name', $this->name); |
|
| 60 | - $statement->bindValue(':status', $this->status); |
|
| 61 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
| 62 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 63 | - $statement->bindValue(':reserved', $this->reserved); |
|
| 64 | - $statement->bindValue(':useragent', $this->useragent); |
|
| 65 | - $statement->bindValue(':forwardedip', $this->forwardedip); |
|
| 66 | - |
|
| 67 | - if ($statement->execute()) { |
|
| 68 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 69 | - } |
|
| 70 | - else { |
|
| 71 | - throw new Exception($statement->errorInfo()); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - else { |
|
| 75 | - // update |
|
| 76 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 56 | + ); |
|
| 57 | + $statement->bindValue(':email', $this->email); |
|
| 58 | + $statement->bindValue(':ip', $this->ip); |
|
| 59 | + $statement->bindValue(':name', $this->name); |
|
| 60 | + $statement->bindValue(':status', $this->status); |
|
| 61 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
| 62 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 63 | + $statement->bindValue(':reserved', $this->reserved); |
|
| 64 | + $statement->bindValue(':useragent', $this->useragent); |
|
| 65 | + $statement->bindValue(':forwardedip', $this->forwardedip); |
|
| 66 | + |
|
| 67 | + if ($statement->execute()) { |
|
| 68 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 69 | + } |
|
| 70 | + else { |
|
| 71 | + throw new Exception($statement->errorInfo()); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + else { |
|
| 75 | + // update |
|
| 76 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 77 | 77 | UPDATE `request` SET |
| 78 | 78 | status = :status, |
| 79 | 79 | emailsent = :emailsent, |
@@ -82,147 +82,147 @@ discard block |
||
| 82 | 82 | updateversion = updateversion + 1 |
| 83 | 83 | WHERE id = :id AND updateversion = :updateversion; |
| 84 | 84 | SQL |
| 85 | - ); |
|
| 86 | - |
|
| 87 | - $statement->bindValue(':id', $this->id); |
|
| 88 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 89 | - |
|
| 90 | - $statement->bindValue(':status', $this->status); |
|
| 91 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
| 92 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 93 | - $statement->bindValue(':reserved', $this->reserved); |
|
| 94 | - |
|
| 95 | - if (!$statement->execute()) { |
|
| 96 | - throw new Exception($statement->errorInfo()); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ($statement->rowCount() !== 1) { |
|
| 100 | - throw new OptimisticLockFailedException(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $this->updateversion++; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - public function getIp() |
|
| 111 | - { |
|
| 112 | - return $this->ip; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param string $ip |
|
| 117 | - */ |
|
| 118 | - public function setIp($ip) |
|
| 119 | - { |
|
| 120 | - $this->ip = $ip; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - public function getName() |
|
| 127 | - { |
|
| 128 | - return $this->name; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @param string $name |
|
| 133 | - */ |
|
| 134 | - public function setName($name) |
|
| 135 | - { |
|
| 136 | - $this->name = $name; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function getStatus() |
|
| 143 | - { |
|
| 144 | - return $this->status; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @param string $status |
|
| 149 | - */ |
|
| 150 | - public function setStatus($status) |
|
| 151 | - { |
|
| 152 | - $this->status = $status; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Returns the time the request was first submitted |
|
| 157 | - * |
|
| 158 | - * @return DateTimeImmutable |
|
| 159 | - */ |
|
| 160 | - public function getDate() |
|
| 161 | - { |
|
| 162 | - return new DateTimeImmutable($this->date); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @return bool |
|
| 167 | - */ |
|
| 168 | - public function getEmailSent() |
|
| 169 | - { |
|
| 170 | - return $this->emailsent == "1"; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @param bool $emailSent |
|
| 175 | - */ |
|
| 176 | - public function setEmailSent($emailSent) |
|
| 177 | - { |
|
| 178 | - $this->emailsent = $emailSent ? 1 : 0; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @return int|null |
|
| 183 | - */ |
|
| 184 | - public function getReserved() |
|
| 185 | - { |
|
| 186 | - return $this->reserved; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @param int|null $reserved |
|
| 191 | - */ |
|
| 192 | - public function setReserved($reserved) |
|
| 193 | - { |
|
| 194 | - $this->reserved = $reserved; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @return string |
|
| 199 | - */ |
|
| 200 | - public function getUserAgent() |
|
| 201 | - { |
|
| 202 | - return $this->useragent; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param string $useragent |
|
| 207 | - */ |
|
| 208 | - public function setUserAgent($useragent) |
|
| 209 | - { |
|
| 210 | - $this->useragent = $useragent; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * @return string|null |
|
| 215 | - */ |
|
| 216 | - public function getForwardedIp() |
|
| 217 | - { |
|
| 218 | - return $this->forwardedip; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * @param string|null $forwardedip |
|
| 223 | - */ |
|
| 224 | - public function setForwardedIp($forwardedip) |
|
| 225 | - { |
|
| 85 | + ); |
|
| 86 | + |
|
| 87 | + $statement->bindValue(':id', $this->id); |
|
| 88 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 89 | + |
|
| 90 | + $statement->bindValue(':status', $this->status); |
|
| 91 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
| 92 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
| 93 | + $statement->bindValue(':reserved', $this->reserved); |
|
| 94 | + |
|
| 95 | + if (!$statement->execute()) { |
|
| 96 | + throw new Exception($statement->errorInfo()); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ($statement->rowCount() !== 1) { |
|
| 100 | + throw new OptimisticLockFailedException(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $this->updateversion++; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + public function getIp() |
|
| 111 | + { |
|
| 112 | + return $this->ip; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param string $ip |
|
| 117 | + */ |
|
| 118 | + public function setIp($ip) |
|
| 119 | + { |
|
| 120 | + $this->ip = $ip; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + public function getName() |
|
| 127 | + { |
|
| 128 | + return $this->name; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @param string $name |
|
| 133 | + */ |
|
| 134 | + public function setName($name) |
|
| 135 | + { |
|
| 136 | + $this->name = $name; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function getStatus() |
|
| 143 | + { |
|
| 144 | + return $this->status; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + /** |
|
| 148 | + * @param string $status |
|
| 149 | + */ |
|
| 150 | + public function setStatus($status) |
|
| 151 | + { |
|
| 152 | + $this->status = $status; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Returns the time the request was first submitted |
|
| 157 | + * |
|
| 158 | + * @return DateTimeImmutable |
|
| 159 | + */ |
|
| 160 | + public function getDate() |
|
| 161 | + { |
|
| 162 | + return new DateTimeImmutable($this->date); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @return bool |
|
| 167 | + */ |
|
| 168 | + public function getEmailSent() |
|
| 169 | + { |
|
| 170 | + return $this->emailsent == "1"; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * @param bool $emailSent |
|
| 175 | + */ |
|
| 176 | + public function setEmailSent($emailSent) |
|
| 177 | + { |
|
| 178 | + $this->emailsent = $emailSent ? 1 : 0; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @return int|null |
|
| 183 | + */ |
|
| 184 | + public function getReserved() |
|
| 185 | + { |
|
| 186 | + return $this->reserved; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @param int|null $reserved |
|
| 191 | + */ |
|
| 192 | + public function setReserved($reserved) |
|
| 193 | + { |
|
| 194 | + $this->reserved = $reserved; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @return string |
|
| 199 | + */ |
|
| 200 | + public function getUserAgent() |
|
| 201 | + { |
|
| 202 | + return $this->useragent; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param string $useragent |
|
| 207 | + */ |
|
| 208 | + public function setUserAgent($useragent) |
|
| 209 | + { |
|
| 210 | + $this->useragent = $useragent; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * @return string|null |
|
| 215 | + */ |
|
| 216 | + public function getForwardedIp() |
|
| 217 | + { |
|
| 218 | + return $this->forwardedip; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * @param string|null $forwardedip |
|
| 223 | + */ |
|
| 224 | + public function setForwardedIp($forwardedip) |
|
| 225 | + { |
|
| 226 | 226 | // Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't. |
| 227 | 227 | |
| 228 | 228 | $xff = explode(',', $forwardedip); |
@@ -236,76 +236,76 @@ discard block |
||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | $this->forwardedip = implode(", ", $valid); |
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @return bool |
|
| 243 | - */ |
|
| 244 | - public function hasComments() |
|
| 245 | - { |
|
| 246 | - if ($this->hasCommentsResolved) { |
|
| 247 | - return $this->hasComments; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
| 251 | - $commentsQuery->bindValue(":id", $this->id); |
|
| 252 | - |
|
| 253 | - $commentsQuery->execute(); |
|
| 254 | - |
|
| 255 | - $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
| 256 | - $this->hasCommentsResolved = true; |
|
| 257 | - |
|
| 258 | - return $this->hasComments; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @return string |
|
| 263 | - */ |
|
| 264 | - public function getEmailConfirm() |
|
| 265 | - { |
|
| 266 | - return $this->emailconfirm; |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @param string $emailconfirm |
|
| 271 | - */ |
|
| 272 | - public function setEmailConfirm($emailconfirm) |
|
| 273 | - { |
|
| 274 | - $this->emailconfirm = $emailconfirm; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - public function generateEmailConfirmationHash() |
|
| 278 | - { |
|
| 279 | - $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @return string|null |
|
| 284 | - */ |
|
| 285 | - public function getEmail() |
|
| 286 | - { |
|
| 287 | - return $this->email; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @param string|null $email |
|
| 292 | - */ |
|
| 293 | - public function setEmail($email) |
|
| 294 | - { |
|
| 295 | - $this->email = $email; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return string |
|
| 300 | - * @throws Exception |
|
| 301 | - */ |
|
| 302 | - public function getClosureReason() |
|
| 303 | - { |
|
| 304 | - if ($this->status != 'Closed') { |
|
| 305 | - throw new Exception("Can't get closure reason for open request."); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @return bool |
|
| 243 | + */ |
|
| 244 | + public function hasComments() |
|
| 245 | + { |
|
| 246 | + if ($this->hasCommentsResolved) { |
|
| 247 | + return $this->hasComments; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
| 251 | + $commentsQuery->bindValue(":id", $this->id); |
|
| 252 | + |
|
| 253 | + $commentsQuery->execute(); |
|
| 254 | + |
|
| 255 | + $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
| 256 | + $this->hasCommentsResolved = true; |
|
| 257 | + |
|
| 258 | + return $this->hasComments; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @return string |
|
| 263 | + */ |
|
| 264 | + public function getEmailConfirm() |
|
| 265 | + { |
|
| 266 | + return $this->emailconfirm; |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + /** |
|
| 270 | + * @param string $emailconfirm |
|
| 271 | + */ |
|
| 272 | + public function setEmailConfirm($emailconfirm) |
|
| 273 | + { |
|
| 274 | + $this->emailconfirm = $emailconfirm; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + public function generateEmailConfirmationHash() |
|
| 278 | + { |
|
| 279 | + $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * @return string|null |
|
| 284 | + */ |
|
| 285 | + public function getEmail() |
|
| 286 | + { |
|
| 287 | + return $this->email; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @param string|null $email |
|
| 292 | + */ |
|
| 293 | + public function setEmail($email) |
|
| 294 | + { |
|
| 295 | + $this->email = $email; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return string |
|
| 300 | + * @throws Exception |
|
| 301 | + */ |
|
| 302 | + public function getClosureReason() |
|
| 303 | + { |
|
| 304 | + if ($this->status != 'Closed') { |
|
| 305 | + throw new Exception("Can't get closure reason for open request."); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 309 | 309 | SELECT closes.mail_desc |
| 310 | 310 | FROM log |
| 311 | 311 | INNER JOIN closes ON log.action = closes.closes |
@@ -315,25 +315,25 @@ discard block |
||
| 315 | 315 | ORDER BY log.timestamp DESC |
| 316 | 316 | LIMIT 1; |
| 317 | 317 | SQL |
| 318 | - ); |
|
| 319 | - |
|
| 320 | - $statement->bindValue(":requestId", $this->id); |
|
| 321 | - $statement->execute(); |
|
| 322 | - $reason = $statement->fetchColumn(); |
|
| 323 | - |
|
| 324 | - return $reason; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * Gets a value indicating whether the request was closed as created or not. |
|
| 329 | - */ |
|
| 330 | - public function getWasCreated() |
|
| 331 | - { |
|
| 332 | - if ($this->status != 'Closed') { |
|
| 333 | - throw new Exception("Can't get closure reason for open request."); |
|
| 334 | - } |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + $statement->bindValue(":requestId", $this->id); |
|
| 321 | + $statement->execute(); |
|
| 322 | + $reason = $statement->fetchColumn(); |
|
| 323 | + |
|
| 324 | + return $reason; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * Gets a value indicating whether the request was closed as created or not. |
|
| 329 | + */ |
|
| 330 | + public function getWasCreated() |
|
| 331 | + { |
|
| 332 | + if ($this->status != 'Closed') { |
|
| 333 | + throw new Exception("Can't get closure reason for open request."); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 336 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 337 | 337 | SELECT emailtemplate.oncreated, log.action |
| 338 | 338 | FROM log |
| 339 | 339 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
@@ -343,60 +343,60 @@ discard block |
||
| 343 | 343 | ORDER BY log.timestamp DESC |
| 344 | 344 | LIMIT 1; |
| 345 | 345 | SQL |
| 346 | - ); |
|
| 347 | - |
|
| 348 | - $statement->bindValue(":requestId", $this->id); |
|
| 349 | - $statement->execute(); |
|
| 350 | - $onCreated = $statement->fetchColumn(0); |
|
| 351 | - $logAction = $statement->fetchColumn(1); |
|
| 352 | - $statement->closeCursor(); |
|
| 353 | - |
|
| 354 | - if ($onCreated === null) { |
|
| 355 | - return $logAction === "Closed custom-y"; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return (bool)$onCreated; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * @return DateTime |
|
| 363 | - */ |
|
| 364 | - public function getClosureDate() |
|
| 365 | - { |
|
| 366 | - $logQuery = $this->dbObject->prepare(<<<SQL |
|
| 346 | + ); |
|
| 347 | + |
|
| 348 | + $statement->bindValue(":requestId", $this->id); |
|
| 349 | + $statement->execute(); |
|
| 350 | + $onCreated = $statement->fetchColumn(0); |
|
| 351 | + $logAction = $statement->fetchColumn(1); |
|
| 352 | + $statement->closeCursor(); |
|
| 353 | + |
|
| 354 | + if ($onCreated === null) { |
|
| 355 | + return $logAction === "Closed custom-y"; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return (bool)$onCreated; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * @return DateTime |
|
| 363 | + */ |
|
| 364 | + public function getClosureDate() |
|
| 365 | + { |
|
| 366 | + $logQuery = $this->dbObject->prepare(<<<SQL |
|
| 367 | 367 | SELECT timestamp FROM log |
| 368 | 368 | WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%' |
| 369 | 369 | ORDER BY timestamp DESC LIMIT 1; |
| 370 | 370 | SQL |
| 371 | - ); |
|
| 372 | - $logQuery->bindValue(":request", $this->getId()); |
|
| 373 | - $logQuery->execute(); |
|
| 374 | - $logTime = $logQuery->fetchColumn(); |
|
| 375 | - $logQuery->closeCursor(); |
|
| 376 | - |
|
| 377 | - return new DateTime($logTime); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
| 382 | - * data to unauthorised* users. |
|
| 383 | - * |
|
| 384 | - * *:Not tool admins, check users, or the reserving user. |
|
| 385 | - * |
|
| 386 | - * @return string |
|
| 387 | - * |
|
| 388 | - * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
| 389 | - * Maybe depend on the last logged action timestamp? |
|
| 390 | - */ |
|
| 391 | - public function getRevealHash() |
|
| 392 | - { |
|
| 393 | - $data = $this->id // unique per request |
|
| 394 | - . '|' . $this->ip // } |
|
| 395 | - . '|' . $this->forwardedip // } private data not known to those without access |
|
| 396 | - . '|' . $this->useragent // } |
|
| 397 | - . '|' . $this->email // } |
|
| 398 | - . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
| 399 | - |
|
| 400 | - return hash('sha256', $data); |
|
| 401 | - } |
|
| 371 | + ); |
|
| 372 | + $logQuery->bindValue(":request", $this->getId()); |
|
| 373 | + $logQuery->execute(); |
|
| 374 | + $logTime = $logQuery->fetchColumn(); |
|
| 375 | + $logQuery->closeCursor(); |
|
| 376 | + |
|
| 377 | + return new DateTime($logTime); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
| 382 | + * data to unauthorised* users. |
|
| 383 | + * |
|
| 384 | + * *:Not tool admins, check users, or the reserving user. |
|
| 385 | + * |
|
| 386 | + * @return string |
|
| 387 | + * |
|
| 388 | + * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
| 389 | + * Maybe depend on the last logged action timestamp? |
|
| 390 | + */ |
|
| 391 | + public function getRevealHash() |
|
| 392 | + { |
|
| 393 | + $data = $this->id // unique per request |
|
| 394 | + . '|' . $this->ip // } |
|
| 395 | + . '|' . $this->forwardedip // } private data not known to those without access |
|
| 396 | + . '|' . $this->useragent // } |
|
| 397 | + . '|' . $this->email // } |
|
| 398 | + . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
| 399 | + |
|
| 400 | + return hash('sha256', $data); |
|
| 401 | + } |
|
| 402 | 402 | } |
@@ -20,171 +20,171 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class Comment extends DataObject |
| 22 | 22 | { |
| 23 | - private $time; |
|
| 24 | - private $user; |
|
| 25 | - private $comment; |
|
| 26 | - private $visibility = "user"; |
|
| 27 | - private $request; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Retrieves all comments for a request, optionally filtered |
|
| 31 | - * |
|
| 32 | - * @param integer $id Request ID to search by |
|
| 33 | - * @param PdoDatabase $database |
|
| 34 | - * @param bool $showAll True to show all comments, False to show only unprotected comments, and protected |
|
| 35 | - * comments visible to $userId |
|
| 36 | - * @param null|int $userId User to filter by |
|
| 37 | - * |
|
| 38 | - * @return Comment[] |
|
| 39 | - */ |
|
| 40 | - public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null) |
|
| 41 | - { |
|
| 42 | - if ($showAll) { |
|
| 43 | - $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;'); |
|
| 44 | - } |
|
| 45 | - else { |
|
| 46 | - $statement = $database->prepare(<<<SQL |
|
| 23 | + private $time; |
|
| 24 | + private $user; |
|
| 25 | + private $comment; |
|
| 26 | + private $visibility = "user"; |
|
| 27 | + private $request; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Retrieves all comments for a request, optionally filtered |
|
| 31 | + * |
|
| 32 | + * @param integer $id Request ID to search by |
|
| 33 | + * @param PdoDatabase $database |
|
| 34 | + * @param bool $showAll True to show all comments, False to show only unprotected comments, and protected |
|
| 35 | + * comments visible to $userId |
|
| 36 | + * @param null|int $userId User to filter by |
|
| 37 | + * |
|
| 38 | + * @return Comment[] |
|
| 39 | + */ |
|
| 40 | + public static function getForRequest($id, PdoDatabase $database, $showAll = false, $userId = null) |
|
| 41 | + { |
|
| 42 | + if ($showAll) { |
|
| 43 | + $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;'); |
|
| 44 | + } |
|
| 45 | + else { |
|
| 46 | + $statement = $database->prepare(<<<SQL |
|
| 47 | 47 | SELECT * FROM comment |
| 48 | 48 | WHERE request = :target AND (visibility = 'user' OR visibility = 'requester' OR user = :userid); |
| 49 | 49 | SQL |
| 50 | - ); |
|
| 51 | - $statement->bindValue(':userid', $userId); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $statement->bindValue(':target', $id); |
|
| 55 | - |
|
| 56 | - $statement->execute(); |
|
| 57 | - |
|
| 58 | - $result = array(); |
|
| 59 | - /** @var Comment $v */ |
|
| 60 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
| 61 | - $v->setDatabase($database); |
|
| 62 | - $result[] = $v; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - return $result; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @throws Exception |
|
| 70 | - */ |
|
| 71 | - public function save() |
|
| 72 | - { |
|
| 73 | - if ($this->isNew()) { |
|
| 74 | - // insert |
|
| 75 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 50 | + ); |
|
| 51 | + $statement->bindValue(':userid', $userId); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $statement->bindValue(':target', $id); |
|
| 55 | + |
|
| 56 | + $statement->execute(); |
|
| 57 | + |
|
| 58 | + $result = array(); |
|
| 59 | + /** @var Comment $v */ |
|
| 60 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
| 61 | + $v->setDatabase($database); |
|
| 62 | + $result[] = $v; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + return $result; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @throws Exception |
|
| 70 | + */ |
|
| 71 | + public function save() |
|
| 72 | + { |
|
| 73 | + if ($this->isNew()) { |
|
| 74 | + // insert |
|
| 75 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 76 | 76 | INSERT INTO comment ( time, user, comment, visibility, request ) |
| 77 | 77 | VALUES ( CURRENT_TIMESTAMP(), :user, :comment, :visibility, :request ); |
| 78 | 78 | SQL |
| 79 | - ); |
|
| 80 | - $statement->bindValue(":user", $this->user); |
|
| 81 | - $statement->bindValue(":comment", $this->comment); |
|
| 82 | - $statement->bindValue(":visibility", $this->visibility); |
|
| 83 | - $statement->bindValue(":request", $this->request); |
|
| 84 | - |
|
| 85 | - if ($statement->execute()) { |
|
| 86 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 87 | - } |
|
| 88 | - else { |
|
| 89 | - throw new Exception($statement->errorInfo()); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - else { |
|
| 93 | - // update |
|
| 94 | - $statement = $this->dbObject->prepare(<<<SQL |
|
| 79 | + ); |
|
| 80 | + $statement->bindValue(":user", $this->user); |
|
| 81 | + $statement->bindValue(":comment", $this->comment); |
|
| 82 | + $statement->bindValue(":visibility", $this->visibility); |
|
| 83 | + $statement->bindValue(":request", $this->request); |
|
| 84 | + |
|
| 85 | + if ($statement->execute()) { |
|
| 86 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
| 87 | + } |
|
| 88 | + else { |
|
| 89 | + throw new Exception($statement->errorInfo()); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + else { |
|
| 93 | + // update |
|
| 94 | + $statement = $this->dbObject->prepare(<<<SQL |
|
| 95 | 95 | UPDATE comment |
| 96 | 96 | SET comment = :comment, visibility = :visibility, updateversion = updateversion + 1 |
| 97 | 97 | WHERE id = :id AND updateversion = :updateversion; |
| 98 | 98 | SQL |
| 99 | - ); |
|
| 100 | - |
|
| 101 | - $statement->bindValue(':id', $this->id); |
|
| 102 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
| 103 | - |
|
| 104 | - $statement->bindValue(':comment', $this->comment); |
|
| 105 | - $statement->bindValue(':visibility', $this->visibility); |
|
| 106 | - |
|
| 107 | - if (!$statement->execute()) { |
|
| 108 | - throw new Exception($statement->errorInfo()); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if ($statement->rowCount() !== 1) { |
|
| 112 | - throw new OptimisticLockFailedException(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->updateversion++; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * @return DateTimeImmutable |
|
| 121 | - */ |
|
| 122 | - public function getTime() |
|
| 123 | - { |
|
| 124 | - return new DateTimeImmutable($this->time); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return int |
|
| 129 | - */ |
|
| 130 | - public function getUser() |
|
| 131 | - { |
|
| 132 | - return $this->user; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param int $user |
|
| 137 | - */ |
|
| 138 | - public function setUser($user) |
|
| 139 | - { |
|
| 140 | - $this->user = $user; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function getComment() |
|
| 147 | - { |
|
| 148 | - return $this->comment; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param string $comment |
|
| 153 | - */ |
|
| 154 | - public function setComment($comment) |
|
| 155 | - { |
|
| 156 | - $this->comment = $comment; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @return string |
|
| 161 | - */ |
|
| 162 | - public function getVisibility() |
|
| 163 | - { |
|
| 164 | - return $this->visibility; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @param string $visibility |
|
| 169 | - */ |
|
| 170 | - public function setVisibility($visibility) |
|
| 171 | - { |
|
| 172 | - $this->visibility = $visibility; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @return int |
|
| 177 | - */ |
|
| 178 | - public function getRequest() |
|
| 179 | - { |
|
| 180 | - return $this->request; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @param int $request |
|
| 185 | - */ |
|
| 186 | - public function setRequest($request) |
|
| 187 | - { |
|
| 188 | - $this->request = $request; |
|
| 189 | - } |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + $statement->bindValue(':id', $this->id); |
|
| 102 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
| 103 | + |
|
| 104 | + $statement->bindValue(':comment', $this->comment); |
|
| 105 | + $statement->bindValue(':visibility', $this->visibility); |
|
| 106 | + |
|
| 107 | + if (!$statement->execute()) { |
|
| 108 | + throw new Exception($statement->errorInfo()); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if ($statement->rowCount() !== 1) { |
|
| 112 | + throw new OptimisticLockFailedException(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->updateversion++; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * @return DateTimeImmutable |
|
| 121 | + */ |
|
| 122 | + public function getTime() |
|
| 123 | + { |
|
| 124 | + return new DateTimeImmutable($this->time); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return int |
|
| 129 | + */ |
|
| 130 | + public function getUser() |
|
| 131 | + { |
|
| 132 | + return $this->user; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param int $user |
|
| 137 | + */ |
|
| 138 | + public function setUser($user) |
|
| 139 | + { |
|
| 140 | + $this->user = $user; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function getComment() |
|
| 147 | + { |
|
| 148 | + return $this->comment; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param string $comment |
|
| 153 | + */ |
|
| 154 | + public function setComment($comment) |
|
| 155 | + { |
|
| 156 | + $this->comment = $comment; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @return string |
|
| 161 | + */ |
|
| 162 | + public function getVisibility() |
|
| 163 | + { |
|
| 164 | + return $this->visibility; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @param string $visibility |
|
| 169 | + */ |
|
| 170 | + public function setVisibility($visibility) |
|
| 171 | + { |
|
| 172 | + $this->visibility = $visibility; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @return int |
|
| 177 | + */ |
|
| 178 | + public function getRequest() |
|
| 179 | + { |
|
| 180 | + return $this->request; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @param int $request |
|
| 185 | + */ |
|
| 186 | + public function setRequest($request) |
|
| 187 | + { |
|
| 188 | + $this->request = $request; |
|
| 189 | + } |
|
| 190 | 190 | } |
@@ -41,8 +41,7 @@ discard block |
||
| 41 | 41 | { |
| 42 | 42 | if ($showAll) { |
| 43 | 43 | $statement = $database->prepare('SELECT * FROM comment WHERE request = :target;'); |
| 44 | - } |
|
| 45 | - else { |
|
| 44 | + } else { |
|
| 46 | 45 | $statement = $database->prepare(<<<SQL |
| 47 | 46 | SELECT * FROM comment |
| 48 | 47 | WHERE request = :target AND (visibility = 'user' OR visibility = 'requester' OR user = :userid); |
@@ -84,12 +83,10 @@ discard block |
||
| 84 | 83 | |
| 85 | 84 | if ($statement->execute()) { |
| 86 | 85 | $this->id = (int)$this->dbObject->lastInsertId(); |
| 87 | - } |
|
| 88 | - else { |
|
| 86 | + } else { |
|
| 89 | 87 | throw new Exception($statement->errorInfo()); |
| 90 | 88 | } |
| 91 | - } |
|
| 92 | - else { |
|
| 89 | + } else { |
|
| 93 | 90 | // update |
| 94 | 91 | $statement = $this->dbObject->prepare(<<<SQL |
| 95 | 92 | UPDATE comment |
@@ -21,72 +21,72 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageEditComment extends InternalPageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - * @throws ApplicationLogicException |
|
| 27 | - * @throws Exception |
|
| 28 | - */ |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $commentId = WebRequest::getInt('id'); |
|
| 32 | - if ($commentId === null) { |
|
| 33 | - throw new ApplicationLogicException('Comment ID not specified'); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $database = $this->getDatabase(); |
|
| 37 | - |
|
| 38 | - /** @var Comment $comment */ |
|
| 39 | - $comment = Comment::getById($commentId, $database); |
|
| 40 | - if ($comment === false) { |
|
| 41 | - throw new ApplicationLogicException('Comment not found'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $currentUser = User::getCurrent($database); |
|
| 45 | - if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
| 46 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** @var Request $request */ |
|
| 50 | - $request = Request::getById($comment->getRequest(), $database); |
|
| 51 | - |
|
| 52 | - if ($request === false) { |
|
| 53 | - throw new ApplicationLogicException('Request was not found.'); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - if (WebRequest::wasPosted()) { |
|
| 57 | - $this->validateCSRFToken(); |
|
| 58 | - $newComment = WebRequest::postString('newcomment'); |
|
| 59 | - |
|
| 60 | - if($comment ->getVisibility() !== 'requester') { |
|
| 61 | - $visibility = WebRequest::postString('visibility'); |
|
| 62 | - |
|
| 63 | - if ($visibility !== 'user' && $visibility !== 'admin') { |
|
| 64 | - throw new ApplicationLogicException('Comment visibility is not valid'); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - $comment->setVisibility($visibility); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // optimistically lock from the load of the edit comment form |
|
| 71 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 72 | - $comment->setUpdateVersion($updateVersion); |
|
| 73 | - |
|
| 74 | - $comment->setComment($newComment); |
|
| 75 | - |
|
| 76 | - $comment->save(); |
|
| 77 | - |
|
| 78 | - Logger::editComment($database, $comment, $request); |
|
| 79 | - $this->getNotificationHelper()->commentEdited($comment, $request); |
|
| 80 | - SessionAlert::success("Comment has been saved successfully"); |
|
| 81 | - |
|
| 82 | - $this->redirect('viewRequest', null, array('id' => $comment->getRequest())); |
|
| 83 | - } |
|
| 84 | - else { |
|
| 85 | - $this->assignCSRFToken(); |
|
| 86 | - $this->assign('comment', $comment); |
|
| 87 | - $this->assign('request', $request); |
|
| 88 | - $this->assign('user', User::getById($comment->getUser(), $database)); |
|
| 89 | - $this->setTemplate('edit-comment.tpl'); |
|
| 90 | - } |
|
| 91 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + * @throws ApplicationLogicException |
|
| 27 | + * @throws Exception |
|
| 28 | + */ |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $commentId = WebRequest::getInt('id'); |
|
| 32 | + if ($commentId === null) { |
|
| 33 | + throw new ApplicationLogicException('Comment ID not specified'); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $database = $this->getDatabase(); |
|
| 37 | + |
|
| 38 | + /** @var Comment $comment */ |
|
| 39 | + $comment = Comment::getById($commentId, $database); |
|
| 40 | + if ($comment === false) { |
|
| 41 | + throw new ApplicationLogicException('Comment not found'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $currentUser = User::getCurrent($database); |
|
| 45 | + if ($comment->getUser() !== $currentUser->getId() && !$this->barrierTest('editOthers', $currentUser)) { |
|
| 46 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** @var Request $request */ |
|
| 50 | + $request = Request::getById($comment->getRequest(), $database); |
|
| 51 | + |
|
| 52 | + if ($request === false) { |
|
| 53 | + throw new ApplicationLogicException('Request was not found.'); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + if (WebRequest::wasPosted()) { |
|
| 57 | + $this->validateCSRFToken(); |
|
| 58 | + $newComment = WebRequest::postString('newcomment'); |
|
| 59 | + |
|
| 60 | + if($comment ->getVisibility() !== 'requester') { |
|
| 61 | + $visibility = WebRequest::postString('visibility'); |
|
| 62 | + |
|
| 63 | + if ($visibility !== 'user' && $visibility !== 'admin') { |
|
| 64 | + throw new ApplicationLogicException('Comment visibility is not valid'); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + $comment->setVisibility($visibility); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // optimistically lock from the load of the edit comment form |
|
| 71 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 72 | + $comment->setUpdateVersion($updateVersion); |
|
| 73 | + |
|
| 74 | + $comment->setComment($newComment); |
|
| 75 | + |
|
| 76 | + $comment->save(); |
|
| 77 | + |
|
| 78 | + Logger::editComment($database, $comment, $request); |
|
| 79 | + $this->getNotificationHelper()->commentEdited($comment, $request); |
|
| 80 | + SessionAlert::success("Comment has been saved successfully"); |
|
| 81 | + |
|
| 82 | + $this->redirect('viewRequest', null, array('id' => $comment->getRequest())); |
|
| 83 | + } |
|
| 84 | + else { |
|
| 85 | + $this->assignCSRFToken(); |
|
| 86 | + $this->assign('comment', $comment); |
|
| 87 | + $this->assign('request', $request); |
|
| 88 | + $this->assign('user', User::getById($comment->getUser(), $database)); |
|
| 89 | + $this->setTemplate('edit-comment.tpl'); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | $this->validateCSRFToken(); |
| 58 | 58 | $newComment = WebRequest::postString('newcomment'); |
| 59 | 59 | |
| 60 | - if($comment ->getVisibility() !== 'requester') { |
|
| 60 | + if ($comment ->getVisibility() !== 'requester') { |
|
| 61 | 61 | $visibility = WebRequest::postString('visibility'); |
| 62 | 62 | |
| 63 | 63 | if ($visibility !== 'user' && $visibility !== 'admin') { |
@@ -25,274 +25,274 @@ |
||
| 25 | 25 | |
| 26 | 26 | class PageViewRequest extends InternalPageBase |
| 27 | 27 | { |
| 28 | - use RequestData; |
|
| 29 | - const STATUS_SYMBOL_OPEN = '☐'; |
|
| 30 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 31 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Main function for this page, when no specific actions are called. |
|
| 35 | - * @throws ApplicationLogicException |
|
| 36 | - */ |
|
| 37 | - protected function main() |
|
| 38 | - { |
|
| 39 | - // set up csrf protection |
|
| 40 | - $this->assignCSRFToken(); |
|
| 41 | - |
|
| 42 | - // get some useful objects |
|
| 43 | - $database = $this->getDatabase(); |
|
| 44 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 45 | - $config = $this->getSiteConfiguration(); |
|
| 46 | - $currentUser = User::getCurrent($database); |
|
| 47 | - |
|
| 48 | - // Test we should be able to look at this request |
|
| 49 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 50 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 51 | - // Not allowed to look at this yet. |
|
| 52 | - throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $this->setupBasicData($request, $config); |
|
| 57 | - |
|
| 58 | - $this->setupUsernameData($request); |
|
| 59 | - |
|
| 60 | - $this->setupTitle($request); |
|
| 61 | - |
|
| 62 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 63 | - $this->setupGeneralData($database); |
|
| 64 | - |
|
| 65 | - $this->assign('requestDataCleared', false); |
|
| 66 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 67 | - $this->assign('requestDataCleared', true); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 71 | - |
|
| 72 | - $this->setupCreationTypes($currentUser); |
|
| 73 | - |
|
| 74 | - $this->setupLogData($request, $database); |
|
| 75 | - |
|
| 76 | - $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 77 | - |
|
| 78 | - $this->assign('showRevealLink', false); |
|
| 79 | - if ($request->getReserved() === $currentUser->getId() || |
|
| 80 | - $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 81 | - ) { |
|
| 82 | - $this->assign('showRevealLink', true); |
|
| 83 | - $this->assign('revealHash', $request->getRevealHash()); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($allowedPrivateData) { |
|
| 87 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 88 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 89 | - |
|
| 90 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 91 | - $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 92 | - |
|
| 93 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 94 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 95 | - $this->setupCheckUserData($request); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - $this->setTemplate('view-request/main.tpl'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param Request $request |
|
| 105 | - */ |
|
| 106 | - protected function setupTitle(Request $request) |
|
| 107 | - { |
|
| 108 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 109 | - if ($request->getStatus() === 'Closed') { |
|
| 110 | - if ($request->getWasCreated()) { |
|
| 111 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 112 | - } |
|
| 113 | - else { |
|
| 114 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Sets up data unrelated to the request, such as the email template information |
|
| 123 | - * |
|
| 124 | - * @param PdoDatabase $database |
|
| 125 | - */ |
|
| 126 | - protected function setupGeneralData(PdoDatabase $database) |
|
| 127 | - { |
|
| 128 | - $config = $this->getSiteConfiguration(); |
|
| 129 | - |
|
| 130 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 131 | - |
|
| 132 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 133 | - |
|
| 134 | - $this->assign('requestStates', $config->getRequestStates()); |
|
| 135 | - |
|
| 136 | - /** @var EmailTemplate $createdTemplate */ |
|
| 137 | - $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 138 | - |
|
| 139 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 140 | - $this->assign('createdId', $createdTemplate->getId()); |
|
| 141 | - $this->assign('createdName', $createdTemplate->getName()); |
|
| 142 | - |
|
| 143 | - $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 144 | - $this->assign("createReasons", $createReasons); |
|
| 145 | - $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 146 | - $this->assign("declineReasons", $declineReasons); |
|
| 147 | - |
|
| 148 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 149 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
| 150 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 151 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 152 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 153 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - private function setupLogData(Request $request, PdoDatabase $database) |
|
| 157 | - { |
|
| 158 | - $currentUser = User::getCurrent($database); |
|
| 159 | - |
|
| 160 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 161 | - $requestLogs = array(); |
|
| 162 | - |
|
| 163 | - /** @var User[] $nameCache */ |
|
| 164 | - $nameCache = array(); |
|
| 165 | - |
|
| 166 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 167 | - |
|
| 168 | - /** @var Log|Comment $entry */ |
|
| 169 | - foreach ($logs as $entry) { |
|
| 170 | - // both log and comment have a 'user' field |
|
| 171 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 172 | - $entryUser = User::getById($entry->getUser(), $database); |
|
| 173 | - $nameCache[$entry->getUser()] = $entryUser; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if ($entry instanceof Comment) { |
|
| 177 | - $requestLogs[] = array( |
|
| 178 | - 'type' => 'comment', |
|
| 179 | - 'security' => $entry->getVisibility(), |
|
| 180 | - 'user' => $entry->getVisibility() == 'requester' ? $request->getName() :$nameCache[$entry->getUser()]->getUsername(), |
|
| 181 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 182 | - 'entry' => null, |
|
| 183 | - 'time' => $entry->getTime(), |
|
| 184 | - 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 185 | - 'id' => $entry->getId(), |
|
| 186 | - 'comment' => $entry->getComment(), |
|
| 187 | - ); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if ($entry instanceof Log) { |
|
| 191 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 192 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 193 | - |
|
| 194 | - $entryComment = $entry->getComment(); |
|
| 195 | - |
|
| 196 | - if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){ |
|
| 197 | - $data = unserialize($entry->getComment()); |
|
| 198 | - /** @var JobQueue $job */ |
|
| 199 | - $job = JobQueue::getById($data['job'], $database); |
|
| 200 | - $requestLogs[] = array( |
|
| 201 | - 'type' => 'joblog', |
|
| 202 | - 'security' => 'user', |
|
| 203 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 204 | - 'user' => $entryUser->getUsername(), |
|
| 205 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 206 | - 'time' => $entry->getTimestamp(), |
|
| 207 | - 'canedit' => false, |
|
| 208 | - 'id' => $entry->getId(), |
|
| 209 | - 'jobId' => $job->getId(), |
|
| 210 | - 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 211 | - ); |
|
| 212 | - } else { |
|
| 213 | - $requestLogs[] = array( |
|
| 214 | - 'type' => 'log', |
|
| 215 | - 'security' => 'user', |
|
| 216 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 217 | - 'user' => $entryUser->getUsername(), |
|
| 218 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 219 | - 'time' => $entry->getTimestamp(), |
|
| 220 | - 'canedit' => false, |
|
| 221 | - 'id' => $entry->getId(), |
|
| 222 | - 'comment' => $entryComment, |
|
| 223 | - ); |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 229 | - |
|
| 230 | - $this->assign("requestLogs", $requestLogs); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param Request $request |
|
| 235 | - */ |
|
| 236 | - protected function setupUsernameData(Request $request) |
|
| 237 | - { |
|
| 238 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 239 | - |
|
| 240 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 241 | - $this->assign('requestBlacklist', $blacklistData); |
|
| 242 | - |
|
| 243 | - try { |
|
| 244 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 245 | - } |
|
| 246 | - catch (Exception $ex) { |
|
| 247 | - $spoofs = $ex->getMessage(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $this->assign("spoofs", $spoofs); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - private function setupCreationTypes(User $user) |
|
| 254 | - { |
|
| 255 | - $this->assign('allowWelcomeSkip', false); |
|
| 256 | - $this->assign('forceWelcomeSkip', false); |
|
| 257 | - |
|
| 258 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 259 | - |
|
| 260 | - if ($user->getWelcomeTemplate() != 0) { |
|
| 261 | - $this->assign('allowWelcomeSkip', true); |
|
| 262 | - |
|
| 263 | - if (!$oauth->canWelcome()) { |
|
| 264 | - $this->assign('forceWelcomeSkip', true); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // test credentials |
|
| 269 | - $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 270 | - $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 271 | - $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
|
| 272 | - |
|
| 273 | - $this->assign('canManualCreate', $canManualCreate); |
|
| 274 | - $this->assign('canOauthCreate', $canOauthCreate); |
|
| 275 | - $this->assign('canBotCreate', $canBotCreate); |
|
| 276 | - |
|
| 277 | - // show/hide the type radio buttons |
|
| 278 | - $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 279 | - |
|
| 280 | - if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
|
| 281 | - // user is not allowed to use their default. Force a choice. |
|
| 282 | - $creationHasChoice = true; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $this->assign('creationHasChoice', $creationHasChoice); |
|
| 286 | - |
|
| 287 | - // determine problems in creation types |
|
| 288 | - $this->assign('botProblem', false); |
|
| 289 | - if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 290 | - $this->assign('botProblem', true); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $this->assign('oauthProblem', false); |
|
| 294 | - if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 295 | - $this->assign('oauthProblem', true); |
|
| 296 | - } |
|
| 297 | - } |
|
| 28 | + use RequestData; |
|
| 29 | + const STATUS_SYMBOL_OPEN = '☐'; |
|
| 30 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 31 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Main function for this page, when no specific actions are called. |
|
| 35 | + * @throws ApplicationLogicException |
|
| 36 | + */ |
|
| 37 | + protected function main() |
|
| 38 | + { |
|
| 39 | + // set up csrf protection |
|
| 40 | + $this->assignCSRFToken(); |
|
| 41 | + |
|
| 42 | + // get some useful objects |
|
| 43 | + $database = $this->getDatabase(); |
|
| 44 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 45 | + $config = $this->getSiteConfiguration(); |
|
| 46 | + $currentUser = User::getCurrent($database); |
|
| 47 | + |
|
| 48 | + // Test we should be able to look at this request |
|
| 49 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 50 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 51 | + // Not allowed to look at this yet. |
|
| 52 | + throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $this->setupBasicData($request, $config); |
|
| 57 | + |
|
| 58 | + $this->setupUsernameData($request); |
|
| 59 | + |
|
| 60 | + $this->setupTitle($request); |
|
| 61 | + |
|
| 62 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 63 | + $this->setupGeneralData($database); |
|
| 64 | + |
|
| 65 | + $this->assign('requestDataCleared', false); |
|
| 66 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 67 | + $this->assign('requestDataCleared', true); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 71 | + |
|
| 72 | + $this->setupCreationTypes($currentUser); |
|
| 73 | + |
|
| 74 | + $this->setupLogData($request, $database); |
|
| 75 | + |
|
| 76 | + $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 77 | + |
|
| 78 | + $this->assign('showRevealLink', false); |
|
| 79 | + if ($request->getReserved() === $currentUser->getId() || |
|
| 80 | + $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 81 | + ) { |
|
| 82 | + $this->assign('showRevealLink', true); |
|
| 83 | + $this->assign('revealHash', $request->getRevealHash()); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($allowedPrivateData) { |
|
| 87 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 88 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 89 | + |
|
| 90 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 91 | + $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 92 | + |
|
| 93 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 94 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 95 | + $this->setupCheckUserData($request); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + $this->setTemplate('view-request/main.tpl'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param Request $request |
|
| 105 | + */ |
|
| 106 | + protected function setupTitle(Request $request) |
|
| 107 | + { |
|
| 108 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 109 | + if ($request->getStatus() === 'Closed') { |
|
| 110 | + if ($request->getWasCreated()) { |
|
| 111 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 112 | + } |
|
| 113 | + else { |
|
| 114 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Sets up data unrelated to the request, such as the email template information |
|
| 123 | + * |
|
| 124 | + * @param PdoDatabase $database |
|
| 125 | + */ |
|
| 126 | + protected function setupGeneralData(PdoDatabase $database) |
|
| 127 | + { |
|
| 128 | + $config = $this->getSiteConfiguration(); |
|
| 129 | + |
|
| 130 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 131 | + |
|
| 132 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 133 | + |
|
| 134 | + $this->assign('requestStates', $config->getRequestStates()); |
|
| 135 | + |
|
| 136 | + /** @var EmailTemplate $createdTemplate */ |
|
| 137 | + $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 138 | + |
|
| 139 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 140 | + $this->assign('createdId', $createdTemplate->getId()); |
|
| 141 | + $this->assign('createdName', $createdTemplate->getName()); |
|
| 142 | + |
|
| 143 | + $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 144 | + $this->assign("createReasons", $createReasons); |
|
| 145 | + $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 146 | + $this->assign("declineReasons", $declineReasons); |
|
| 147 | + |
|
| 148 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 149 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
| 150 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 151 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 152 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 153 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + private function setupLogData(Request $request, PdoDatabase $database) |
|
| 157 | + { |
|
| 158 | + $currentUser = User::getCurrent($database); |
|
| 159 | + |
|
| 160 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 161 | + $requestLogs = array(); |
|
| 162 | + |
|
| 163 | + /** @var User[] $nameCache */ |
|
| 164 | + $nameCache = array(); |
|
| 165 | + |
|
| 166 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 167 | + |
|
| 168 | + /** @var Log|Comment $entry */ |
|
| 169 | + foreach ($logs as $entry) { |
|
| 170 | + // both log and comment have a 'user' field |
|
| 171 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 172 | + $entryUser = User::getById($entry->getUser(), $database); |
|
| 173 | + $nameCache[$entry->getUser()] = $entryUser; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if ($entry instanceof Comment) { |
|
| 177 | + $requestLogs[] = array( |
|
| 178 | + 'type' => 'comment', |
|
| 179 | + 'security' => $entry->getVisibility(), |
|
| 180 | + 'user' => $entry->getVisibility() == 'requester' ? $request->getName() :$nameCache[$entry->getUser()]->getUsername(), |
|
| 181 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 182 | + 'entry' => null, |
|
| 183 | + 'time' => $entry->getTime(), |
|
| 184 | + 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 185 | + 'id' => $entry->getId(), |
|
| 186 | + 'comment' => $entry->getComment(), |
|
| 187 | + ); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if ($entry instanceof Log) { |
|
| 191 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 192 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 193 | + |
|
| 194 | + $entryComment = $entry->getComment(); |
|
| 195 | + |
|
| 196 | + if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){ |
|
| 197 | + $data = unserialize($entry->getComment()); |
|
| 198 | + /** @var JobQueue $job */ |
|
| 199 | + $job = JobQueue::getById($data['job'], $database); |
|
| 200 | + $requestLogs[] = array( |
|
| 201 | + 'type' => 'joblog', |
|
| 202 | + 'security' => 'user', |
|
| 203 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 204 | + 'user' => $entryUser->getUsername(), |
|
| 205 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 206 | + 'time' => $entry->getTimestamp(), |
|
| 207 | + 'canedit' => false, |
|
| 208 | + 'id' => $entry->getId(), |
|
| 209 | + 'jobId' => $job->getId(), |
|
| 210 | + 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 211 | + ); |
|
| 212 | + } else { |
|
| 213 | + $requestLogs[] = array( |
|
| 214 | + 'type' => 'log', |
|
| 215 | + 'security' => 'user', |
|
| 216 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 217 | + 'user' => $entryUser->getUsername(), |
|
| 218 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 219 | + 'time' => $entry->getTimestamp(), |
|
| 220 | + 'canedit' => false, |
|
| 221 | + 'id' => $entry->getId(), |
|
| 222 | + 'comment' => $entryComment, |
|
| 223 | + ); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 229 | + |
|
| 230 | + $this->assign("requestLogs", $requestLogs); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param Request $request |
|
| 235 | + */ |
|
| 236 | + protected function setupUsernameData(Request $request) |
|
| 237 | + { |
|
| 238 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 239 | + |
|
| 240 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 241 | + $this->assign('requestBlacklist', $blacklistData); |
|
| 242 | + |
|
| 243 | + try { |
|
| 244 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 245 | + } |
|
| 246 | + catch (Exception $ex) { |
|
| 247 | + $spoofs = $ex->getMessage(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $this->assign("spoofs", $spoofs); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + private function setupCreationTypes(User $user) |
|
| 254 | + { |
|
| 255 | + $this->assign('allowWelcomeSkip', false); |
|
| 256 | + $this->assign('forceWelcomeSkip', false); |
|
| 257 | + |
|
| 258 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 259 | + |
|
| 260 | + if ($user->getWelcomeTemplate() != 0) { |
|
| 261 | + $this->assign('allowWelcomeSkip', true); |
|
| 262 | + |
|
| 263 | + if (!$oauth->canWelcome()) { |
|
| 264 | + $this->assign('forceWelcomeSkip', true); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // test credentials |
|
| 269 | + $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 270 | + $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 271 | + $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
|
| 272 | + |
|
| 273 | + $this->assign('canManualCreate', $canManualCreate); |
|
| 274 | + $this->assign('canOauthCreate', $canOauthCreate); |
|
| 275 | + $this->assign('canBotCreate', $canBotCreate); |
|
| 276 | + |
|
| 277 | + // show/hide the type radio buttons |
|
| 278 | + $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 279 | + |
|
| 280 | + if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
|
| 281 | + // user is not allowed to use their default. Force a choice. |
|
| 282 | + $creationHasChoice = true; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $this->assign('creationHasChoice', $creationHasChoice); |
|
| 286 | + |
|
| 287 | + // determine problems in creation types |
|
| 288 | + $this->assign('botProblem', false); |
|
| 289 | + if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 290 | + $this->assign('botProblem', true); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $this->assign('oauthProblem', false); |
|
| 294 | + if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 295 | + $this->assign('oauthProblem', true); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | 298 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | $requestLogs[] = array( |
| 178 | 178 | 'type' => 'comment', |
| 179 | 179 | 'security' => $entry->getVisibility(), |
| 180 | - 'user' => $entry->getVisibility() == 'requester' ? $request->getName() :$nameCache[$entry->getUser()]->getUsername(), |
|
| 180 | + 'user' => $entry->getVisibility() == 'requester' ? $request->getName() : $nameCache[$entry->getUser()]->getUsername(), |
|
| 181 | 181 | 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
| 182 | 182 | 'entry' => null, |
| 183 | 183 | 'time' => $entry->getTime(), |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | $entryComment = $entry->getComment(); |
| 195 | 195 | |
| 196 | - if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){ |
|
| 196 | + if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') { |
|
| 197 | 197 | $data = unserialize($entry->getComment()); |
| 198 | 198 | /** @var JobQueue $job */ |
| 199 | 199 | $job = JobQueue::getById($data['job'], $database); |
@@ -21,188 +21,188 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageRequestAccount extends PublicInterfacePageBase |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Main function for this page, when no specific actions are called. |
|
| 26 | - * @return void |
|
| 27 | - * @throws OptimisticLockFailedException |
|
| 28 | - * @throws Exception |
|
| 29 | - */ |
|
| 30 | - protected function main() |
|
| 31 | - { |
|
| 32 | - // dual mode page |
|
| 33 | - if (WebRequest::wasPosted()) { |
|
| 34 | - $request = $this->createNewRequest(); |
|
| 35 | - $comment = $this->createComment(); |
|
| 36 | - |
|
| 37 | - $validationErrors = $this->validateRequest($request); |
|
| 38 | - |
|
| 39 | - if (count($validationErrors) > 0) { |
|
| 40 | - foreach ($validationErrors as $validationError) { |
|
| 41 | - SessionAlert::error($validationError->getErrorMessage()); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - // Preserve the data after an error |
|
| 45 | - WebRequest::setSessionContext('accountReq', |
|
| 46 | - array( |
|
| 47 | - 'username' => WebRequest::postString('name'), |
|
| 48 | - 'email' => WebRequest::postEmail('email'), |
|
| 49 | - 'comments' => WebRequest::postString('comments'), |
|
| 50 | - ) |
|
| 51 | - ); |
|
| 52 | - |
|
| 53 | - // Validation error, bomb out early. |
|
| 54 | - $this->redirect(); |
|
| 55 | - |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // actually save the request to the database |
|
| 60 | - if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 61 | - $this->saveAsEmailConfirmation($request, $comment); |
|
| 62 | - } |
|
| 63 | - else { |
|
| 64 | - $this->saveWithoutEmailConfirmation($request, $comment); |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - // set the form values from the session context |
|
| 69 | - $context = WebRequest::getSessionContext('accountReq'); |
|
| 70 | - if ($context !== null && is_array($context)) { |
|
| 71 | - $this->assign('username', $context['username']); |
|
| 72 | - $this->assign('email', $context['email']); |
|
| 73 | - $this->assign('comments', $context['comments']); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Clear it for a refresh |
|
| 77 | - WebRequest::setSessionContext('accountReq', null); |
|
| 78 | - |
|
| 79 | - $this->setTemplate('request/request-form.tpl'); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return Request |
|
| 85 | - */ |
|
| 86 | - protected function createNewRequest() |
|
| 87 | - { |
|
| 88 | - $request = new Request(); |
|
| 89 | - $request->setDatabase($this->getDatabase()); |
|
| 90 | - |
|
| 91 | - $request->setName(WebRequest::postString('name')); |
|
| 92 | - $request->setEmail(WebRequest::postEmail('email')); |
|
| 93 | - |
|
| 94 | - $request->setIp(WebRequest::remoteAddress()); |
|
| 95 | - $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 96 | - |
|
| 97 | - $request->setUserAgent(WebRequest::userAgent()); |
|
| 98 | - |
|
| 99 | - return $request; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @return Comment|null |
|
| 104 | - */ |
|
| 105 | - private function createComment() |
|
| 106 | - { |
|
| 107 | - $commentText = WebRequest::postString('comments'); |
|
| 108 | - if ($commentText === null || trim($commentText) === '') { |
|
| 109 | - return null; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - $comment = new Comment(); |
|
| 113 | - $comment->setDatabase($this->getDatabase()); |
|
| 114 | - |
|
| 115 | - $comment->setVisibility('requester'); |
|
| 116 | - $comment->setUser(null); |
|
| 117 | - $comment->setComment($commentText); |
|
| 118 | - |
|
| 119 | - return $comment; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @param Request $request |
|
| 124 | - * |
|
| 125 | - * @return ValidationError[] |
|
| 126 | - */ |
|
| 127 | - protected function validateRequest($request) |
|
| 128 | - { |
|
| 129 | - $validationHelper = new RequestValidationHelper( |
|
| 130 | - new BanHelper($this->getDatabase()), |
|
| 131 | - $request, |
|
| 132 | - WebRequest::postEmail('emailconfirm'), |
|
| 133 | - $this->getDatabase(), |
|
| 134 | - $this->getAntiSpoofProvider(), |
|
| 135 | - $this->getXffTrustProvider(), |
|
| 136 | - $this->getHttpHelper(), |
|
| 137 | - $this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 138 | - $this->getSiteConfiguration()->getTitleBlacklistEnabled(), |
|
| 139 | - $this->getTorExitProvider()); |
|
| 140 | - |
|
| 141 | - // These are arrays of ValidationError. |
|
| 142 | - $nameValidation = $validationHelper->validateName(); |
|
| 143 | - $emailValidation = $validationHelper->validateEmail(); |
|
| 144 | - $otherValidation = $validationHelper->validateOther(); |
|
| 145 | - |
|
| 146 | - $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 147 | - |
|
| 148 | - return $validationErrors; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @param Request $request |
|
| 153 | - * |
|
| 154 | - * @param Comment|null $comment |
|
| 155 | - * |
|
| 156 | - * @throws OptimisticLockFailedException |
|
| 157 | - * @throws Exception |
|
| 158 | - */ |
|
| 159 | - protected function saveAsEmailConfirmation(Request $request, $comment) |
|
| 160 | - { |
|
| 161 | - $request->generateEmailConfirmationHash(); |
|
| 162 | - $request->save(); |
|
| 163 | - |
|
| 164 | - if ($comment !== null) { |
|
| 165 | - $comment->setRequest($request->getId()); |
|
| 166 | - $comment->save(); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 170 | - $request->getIp(), |
|
| 171 | - $request->getForwardedIp()); |
|
| 172 | - |
|
| 173 | - $this->assign("ip", $trustedIp); |
|
| 174 | - $this->assign("id", $request->getId()); |
|
| 175 | - $this->assign("hash", $request->getEmailConfirm()); |
|
| 176 | - |
|
| 177 | - // Sends the confirmation email to the user. |
|
| 178 | - $this->getEmailHelper()->sendMail( |
|
| 179 | - $request->getEmail(), |
|
| 180 | - "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 181 | - $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 182 | - |
|
| 183 | - $this->redirect('emailConfirmationRequired'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param Request $request |
|
| 188 | - * |
|
| 189 | - * @param Comment|null $comment |
|
| 190 | - * |
|
| 191 | - * @throws OptimisticLockFailedException |
|
| 192 | - * @throws Exception |
|
| 193 | - */ |
|
| 194 | - protected function saveWithoutEmailConfirmation(Request $request, $comment) |
|
| 195 | - { |
|
| 196 | - $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 197 | - $request->save(); |
|
| 198 | - |
|
| 199 | - if ($comment !== null) { |
|
| 200 | - $comment->setRequest($request->getId()); |
|
| 201 | - $comment->save(); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $this->getNotificationHelper()->requestReceived($request); |
|
| 205 | - |
|
| 206 | - $this->redirect('requestSubmitted'); |
|
| 207 | - } |
|
| 24 | + /** |
|
| 25 | + * Main function for this page, when no specific actions are called. |
|
| 26 | + * @return void |
|
| 27 | + * @throws OptimisticLockFailedException |
|
| 28 | + * @throws Exception |
|
| 29 | + */ |
|
| 30 | + protected function main() |
|
| 31 | + { |
|
| 32 | + // dual mode page |
|
| 33 | + if (WebRequest::wasPosted()) { |
|
| 34 | + $request = $this->createNewRequest(); |
|
| 35 | + $comment = $this->createComment(); |
|
| 36 | + |
|
| 37 | + $validationErrors = $this->validateRequest($request); |
|
| 38 | + |
|
| 39 | + if (count($validationErrors) > 0) { |
|
| 40 | + foreach ($validationErrors as $validationError) { |
|
| 41 | + SessionAlert::error($validationError->getErrorMessage()); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + // Preserve the data after an error |
|
| 45 | + WebRequest::setSessionContext('accountReq', |
|
| 46 | + array( |
|
| 47 | + 'username' => WebRequest::postString('name'), |
|
| 48 | + 'email' => WebRequest::postEmail('email'), |
|
| 49 | + 'comments' => WebRequest::postString('comments'), |
|
| 50 | + ) |
|
| 51 | + ); |
|
| 52 | + |
|
| 53 | + // Validation error, bomb out early. |
|
| 54 | + $this->redirect(); |
|
| 55 | + |
|
| 56 | + return; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // actually save the request to the database |
|
| 60 | + if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
|
| 61 | + $this->saveAsEmailConfirmation($request, $comment); |
|
| 62 | + } |
|
| 63 | + else { |
|
| 64 | + $this->saveWithoutEmailConfirmation($request, $comment); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + // set the form values from the session context |
|
| 69 | + $context = WebRequest::getSessionContext('accountReq'); |
|
| 70 | + if ($context !== null && is_array($context)) { |
|
| 71 | + $this->assign('username', $context['username']); |
|
| 72 | + $this->assign('email', $context['email']); |
|
| 73 | + $this->assign('comments', $context['comments']); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Clear it for a refresh |
|
| 77 | + WebRequest::setSessionContext('accountReq', null); |
|
| 78 | + |
|
| 79 | + $this->setTemplate('request/request-form.tpl'); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return Request |
|
| 85 | + */ |
|
| 86 | + protected function createNewRequest() |
|
| 87 | + { |
|
| 88 | + $request = new Request(); |
|
| 89 | + $request->setDatabase($this->getDatabase()); |
|
| 90 | + |
|
| 91 | + $request->setName(WebRequest::postString('name')); |
|
| 92 | + $request->setEmail(WebRequest::postEmail('email')); |
|
| 93 | + |
|
| 94 | + $request->setIp(WebRequest::remoteAddress()); |
|
| 95 | + $request->setForwardedIp(WebRequest::forwardedAddress()); |
|
| 96 | + |
|
| 97 | + $request->setUserAgent(WebRequest::userAgent()); |
|
| 98 | + |
|
| 99 | + return $request; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @return Comment|null |
|
| 104 | + */ |
|
| 105 | + private function createComment() |
|
| 106 | + { |
|
| 107 | + $commentText = WebRequest::postString('comments'); |
|
| 108 | + if ($commentText === null || trim($commentText) === '') { |
|
| 109 | + return null; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + $comment = new Comment(); |
|
| 113 | + $comment->setDatabase($this->getDatabase()); |
|
| 114 | + |
|
| 115 | + $comment->setVisibility('requester'); |
|
| 116 | + $comment->setUser(null); |
|
| 117 | + $comment->setComment($commentText); |
|
| 118 | + |
|
| 119 | + return $comment; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @param Request $request |
|
| 124 | + * |
|
| 125 | + * @return ValidationError[] |
|
| 126 | + */ |
|
| 127 | + protected function validateRequest($request) |
|
| 128 | + { |
|
| 129 | + $validationHelper = new RequestValidationHelper( |
|
| 130 | + new BanHelper($this->getDatabase()), |
|
| 131 | + $request, |
|
| 132 | + WebRequest::postEmail('emailconfirm'), |
|
| 133 | + $this->getDatabase(), |
|
| 134 | + $this->getAntiSpoofProvider(), |
|
| 135 | + $this->getXffTrustProvider(), |
|
| 136 | + $this->getHttpHelper(), |
|
| 137 | + $this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 138 | + $this->getSiteConfiguration()->getTitleBlacklistEnabled(), |
|
| 139 | + $this->getTorExitProvider()); |
|
| 140 | + |
|
| 141 | + // These are arrays of ValidationError. |
|
| 142 | + $nameValidation = $validationHelper->validateName(); |
|
| 143 | + $emailValidation = $validationHelper->validateEmail(); |
|
| 144 | + $otherValidation = $validationHelper->validateOther(); |
|
| 145 | + |
|
| 146 | + $validationErrors = array_merge($nameValidation, $emailValidation, $otherValidation); |
|
| 147 | + |
|
| 148 | + return $validationErrors; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @param Request $request |
|
| 153 | + * |
|
| 154 | + * @param Comment|null $comment |
|
| 155 | + * |
|
| 156 | + * @throws OptimisticLockFailedException |
|
| 157 | + * @throws Exception |
|
| 158 | + */ |
|
| 159 | + protected function saveAsEmailConfirmation(Request $request, $comment) |
|
| 160 | + { |
|
| 161 | + $request->generateEmailConfirmationHash(); |
|
| 162 | + $request->save(); |
|
| 163 | + |
|
| 164 | + if ($comment !== null) { |
|
| 165 | + $comment->setRequest($request->getId()); |
|
| 166 | + $comment->save(); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp( |
|
| 170 | + $request->getIp(), |
|
| 171 | + $request->getForwardedIp()); |
|
| 172 | + |
|
| 173 | + $this->assign("ip", $trustedIp); |
|
| 174 | + $this->assign("id", $request->getId()); |
|
| 175 | + $this->assign("hash", $request->getEmailConfirm()); |
|
| 176 | + |
|
| 177 | + // Sends the confirmation email to the user. |
|
| 178 | + $this->getEmailHelper()->sendMail( |
|
| 179 | + $request->getEmail(), |
|
| 180 | + "[ACC #{$request->getId()}] English Wikipedia Account Request", |
|
| 181 | + $this->fetchTemplate('request/confirmation-mail.tpl')); |
|
| 182 | + |
|
| 183 | + $this->redirect('emailConfirmationRequired'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param Request $request |
|
| 188 | + * |
|
| 189 | + * @param Comment|null $comment |
|
| 190 | + * |
|
| 191 | + * @throws OptimisticLockFailedException |
|
| 192 | + * @throws Exception |
|
| 193 | + */ |
|
| 194 | + protected function saveWithoutEmailConfirmation(Request $request, $comment) |
|
| 195 | + { |
|
| 196 | + $request->setEmailConfirm(0); // fixme Since it can't be null |
|
| 197 | + $request->save(); |
|
| 198 | + |
|
| 199 | + if ($comment !== null) { |
|
| 200 | + $comment->setRequest($request->getId()); |
|
| 201 | + $comment->save(); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $this->getNotificationHelper()->requestReceived($request); |
|
| 205 | + |
|
| 206 | + $this->redirect('requestSubmitted'); |
|
| 207 | + } |
|
| 208 | 208 | } |
| 209 | 209 | \ No newline at end of file |
@@ -59,12 +59,10 @@ |
||
| 59 | 59 | // actually save the request to the database |
| 60 | 60 | if ($this->getSiteConfiguration()->getEmailConfirmationEnabled()) { |
| 61 | 61 | $this->saveAsEmailConfirmation($request, $comment); |
| 62 | - } |
|
| 63 | - else { |
|
| 62 | + } else { |
|
| 64 | 63 | $this->saveWithoutEmailConfirmation($request, $comment); |
| 65 | 64 | } |
| 66 | - } |
|
| 67 | - else { |
|
| 65 | + } else { |
|
| 68 | 66 | // set the form values from the session context |
| 69 | 67 | $context = WebRequest::getSessionContext('accountReq'); |
| 70 | 68 | if ($context !== null && is_array($context)) { |