@@ -21,22 +21,22 @@ |
||
21 | 21 | */ |
22 | 22 | abstract class ReadableException extends Exception |
23 | 23 | { |
24 | - use TemplateOutput; |
|
24 | + use TemplateOutput; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns a readable HTML error message that's displayable to the user using templates. |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - abstract public function getReadableError(); |
|
26 | + /** |
|
27 | + * Returns a readable HTML error message that's displayable to the user using templates. |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + abstract public function getReadableError(); |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return SiteConfiguration |
|
34 | - */ |
|
35 | - protected function getSiteConfiguration() |
|
36 | - { |
|
37 | - // Uck. However, we have encountered an exception. |
|
38 | - global $siteConfiguration; |
|
32 | + /** |
|
33 | + * @return SiteConfiguration |
|
34 | + */ |
|
35 | + protected function getSiteConfiguration() |
|
36 | + { |
|
37 | + // Uck. However, we have encountered an exception. |
|
38 | + global $siteConfiguration; |
|
39 | 39 | |
40 | - return $siteConfiguration; |
|
41 | - } |
|
40 | + return $siteConfiguration; |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | \ No newline at end of file |
@@ -21,13 +21,13 @@ |
||
21 | 21 | */ |
22 | 22 | class EnvironmentException extends Exception |
23 | 23 | { |
24 | - /** |
|
25 | - * EnvironmentException constructor. |
|
26 | - * |
|
27 | - * @param string $friendlyMessage |
|
28 | - */ |
|
29 | - public function __construct($friendlyMessage) |
|
30 | - { |
|
31 | - parent::__construct($friendlyMessage); |
|
32 | - } |
|
24 | + /** |
|
25 | + * EnvironmentException constructor. |
|
26 | + * |
|
27 | + * @param string $friendlyMessage |
|
28 | + */ |
|
29 | + public function __construct($friendlyMessage) |
|
30 | + { |
|
31 | + parent::__construct($friendlyMessage); |
|
32 | + } |
|
33 | 33 | } |
34 | 34 | \ No newline at end of file |
@@ -60,12 +60,10 @@ |
||
60 | 60 | |
61 | 61 | if ($statement->execute()) { |
62 | 62 | $this->id = (int)$this->dbObject->lastInsertId(); |
63 | - } |
|
64 | - else { |
|
63 | + } else { |
|
65 | 64 | throw new Exception($statement->errorInfo()); |
66 | 65 | } |
67 | - } |
|
68 | - else { |
|
66 | + } else { |
|
69 | 67 | // update |
70 | 68 | $statement = $this->dbObject->prepare(<<<SQL |
71 | 69 | UPDATE `geolocation` |
@@ -21,110 +21,110 @@ |
||
21 | 21 | */ |
22 | 22 | class GeoLocation extends DataObject |
23 | 23 | { |
24 | - private $address; |
|
25 | - private $data; |
|
26 | - private $creation; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $address |
|
30 | - * @param PdoDatabase $database |
|
31 | - * @param bool $forUpdate |
|
32 | - * @return GeoLocation |
|
33 | - */ |
|
34 | - public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
|
35 | - { |
|
36 | - $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
|
37 | - $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
38 | - |
|
39 | - $statement = $database->prepare($sql); |
|
40 | - $statement->bindValue(":id", $address); |
|
41 | - |
|
42 | - $statement->execute(); |
|
43 | - |
|
44 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
45 | - |
|
46 | - if ($resultObject != false) { |
|
47 | - $resultObject->setDatabase($database); |
|
48 | - } |
|
49 | - |
|
50 | - return $resultObject; |
|
51 | - } |
|
52 | - |
|
53 | - public function save() |
|
54 | - { |
|
55 | - if ($this->isNew()) { |
|
56 | - // insert |
|
57 | - $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;"); |
|
58 | - |
|
59 | - $statement->bindValue(":address", $this->address); |
|
60 | - $statement->bindValue(":data", $this->data); |
|
61 | - |
|
62 | - if ($statement->execute()) { |
|
63 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
64 | - } |
|
65 | - else { |
|
66 | - throw new Exception($statement->errorInfo()); |
|
67 | - } |
|
68 | - } |
|
69 | - else { |
|
70 | - // update |
|
71 | - $statement = $this->dbObject->prepare(<<<SQL |
|
24 | + private $address; |
|
25 | + private $data; |
|
26 | + private $creation; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $address |
|
30 | + * @param PdoDatabase $database |
|
31 | + * @param bool $forUpdate |
|
32 | + * @return GeoLocation |
|
33 | + */ |
|
34 | + public static function getByAddress($address, PdoDatabase $database, $forUpdate = false) |
|
35 | + { |
|
36 | + $lockMode = $forUpdate ? ' FOR UPDATE' : ''; |
|
37 | + $sql = "SELECT * FROM geolocation WHERE address = :id LIMIT 1" . $lockMode; |
|
38 | + |
|
39 | + $statement = $database->prepare($sql); |
|
40 | + $statement->bindValue(":id", $address); |
|
41 | + |
|
42 | + $statement->execute(); |
|
43 | + |
|
44 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
45 | + |
|
46 | + if ($resultObject != false) { |
|
47 | + $resultObject->setDatabase($database); |
|
48 | + } |
|
49 | + |
|
50 | + return $resultObject; |
|
51 | + } |
|
52 | + |
|
53 | + public function save() |
|
54 | + { |
|
55 | + if ($this->isNew()) { |
|
56 | + // insert |
|
57 | + $statement = $this->dbObject->prepare("INSERT INTO `geolocation` (address, data) VALUES (:address, :data) ON DUPLICATE KEY UPDATE address = address;"); |
|
58 | + |
|
59 | + $statement->bindValue(":address", $this->address); |
|
60 | + $statement->bindValue(":data", $this->data); |
|
61 | + |
|
62 | + if ($statement->execute()) { |
|
63 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
64 | + } |
|
65 | + else { |
|
66 | + throw new Exception($statement->errorInfo()); |
|
67 | + } |
|
68 | + } |
|
69 | + else { |
|
70 | + // update |
|
71 | + $statement = $this->dbObject->prepare(<<<SQL |
|
72 | 72 | UPDATE `geolocation` |
73 | 73 | SET address = :address, data = :data, updateversion = updateversion + 1 |
74 | 74 | WHERE id = :id AND updateversion = :updateversion; |
75 | 75 | SQL |
76 | - ); |
|
77 | - |
|
78 | - $statement->bindValue(":id", $this->id); |
|
79 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
80 | - |
|
81 | - $statement->bindValue(":address", $this->address); |
|
82 | - $statement->bindValue(":data", $this->data); |
|
83 | - |
|
84 | - if (!$statement->execute()) { |
|
85 | - throw new Exception($statement->errorInfo()); |
|
86 | - } |
|
87 | - |
|
88 | - if ($statement->rowCount() !== 1) { |
|
89 | - throw new OptimisticLockFailedException(); |
|
90 | - } |
|
91 | - |
|
92 | - $this->updateversion++; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - public function getAddress() |
|
97 | - { |
|
98 | - return $this->address; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $address |
|
103 | - */ |
|
104 | - public function setAddress($address) |
|
105 | - { |
|
106 | - $this->address = $address; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return array |
|
111 | - */ |
|
112 | - public function getData() |
|
113 | - { |
|
114 | - return unserialize($this->data); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param array $data |
|
119 | - */ |
|
120 | - public function setData($data) |
|
121 | - { |
|
122 | - $this->data = serialize($data); |
|
123 | - } |
|
124 | - |
|
125 | - /** @return DateTimeImmutable */ |
|
126 | - public function getCreation() |
|
127 | - { |
|
128 | - return new DateTimeImmutable($this->creation); |
|
129 | - } |
|
76 | + ); |
|
77 | + |
|
78 | + $statement->bindValue(":id", $this->id); |
|
79 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
80 | + |
|
81 | + $statement->bindValue(":address", $this->address); |
|
82 | + $statement->bindValue(":data", $this->data); |
|
83 | + |
|
84 | + if (!$statement->execute()) { |
|
85 | + throw new Exception($statement->errorInfo()); |
|
86 | + } |
|
87 | + |
|
88 | + if ($statement->rowCount() !== 1) { |
|
89 | + throw new OptimisticLockFailedException(); |
|
90 | + } |
|
91 | + |
|
92 | + $this->updateversion++; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + public function getAddress() |
|
97 | + { |
|
98 | + return $this->address; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $address |
|
103 | + */ |
|
104 | + public function setAddress($address) |
|
105 | + { |
|
106 | + $this->address = $address; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return array |
|
111 | + */ |
|
112 | + public function getData() |
|
113 | + { |
|
114 | + return unserialize($this->data); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param array $data |
|
119 | + */ |
|
120 | + public function setData($data) |
|
121 | + { |
|
122 | + $this->data = serialize($data); |
|
123 | + } |
|
124 | + |
|
125 | + /** @return DateTimeImmutable */ |
|
126 | + public function getCreation() |
|
127 | + { |
|
128 | + return new DateTimeImmutable($this->creation); |
|
129 | + } |
|
130 | 130 | } |
@@ -59,12 +59,10 @@ |
||
59 | 59 | |
60 | 60 | if ($statement->execute()) { |
61 | 61 | $this->id = (int)$this->dbObject->lastInsertId(); |
62 | - } |
|
63 | - else { |
|
62 | + } else { |
|
64 | 63 | throw new Exception($statement->errorInfo()); |
65 | 64 | } |
66 | - } |
|
67 | - else { |
|
65 | + } else { |
|
68 | 66 | // update |
69 | 67 | $statement = $this->dbObject->prepare(<<<SQL |
70 | 68 | UPDATE `rdnscache` |
@@ -19,109 +19,109 @@ |
||
19 | 19 | */ |
20 | 20 | class RDnsCache extends DataObject |
21 | 21 | { |
22 | - private $address; |
|
23 | - private $data; |
|
24 | - private $creation; |
|
25 | - |
|
26 | - /** |
|
27 | - * @param string $address |
|
28 | - * @param PdoDatabase $database |
|
29 | - * |
|
30 | - * @return RDnsCache|false |
|
31 | - */ |
|
32 | - public static function getByAddress($address, PdoDatabase $database) |
|
33 | - { |
|
34 | - // @todo add cache invalidation (timestamp?) |
|
35 | - $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;"); |
|
36 | - $statement->bindValue(":id", $address); |
|
37 | - |
|
38 | - $statement->execute(); |
|
39 | - |
|
40 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
41 | - |
|
42 | - if ($resultObject != false) { |
|
43 | - $resultObject->setDatabase($database); |
|
44 | - } |
|
45 | - |
|
46 | - return $resultObject; |
|
47 | - } |
|
48 | - |
|
49 | - public function save() |
|
50 | - { |
|
51 | - if ($this->isNew()) { |
|
52 | - // insert |
|
53 | - $statement = $this->dbObject->prepare(<<<SQL |
|
22 | + private $address; |
|
23 | + private $data; |
|
24 | + private $creation; |
|
25 | + |
|
26 | + /** |
|
27 | + * @param string $address |
|
28 | + * @param PdoDatabase $database |
|
29 | + * |
|
30 | + * @return RDnsCache|false |
|
31 | + */ |
|
32 | + public static function getByAddress($address, PdoDatabase $database) |
|
33 | + { |
|
34 | + // @todo add cache invalidation (timestamp?) |
|
35 | + $statement = $database->prepare("SELECT * FROM rdnscache WHERE address = :id LIMIT 1;"); |
|
36 | + $statement->bindValue(":id", $address); |
|
37 | + |
|
38 | + $statement->execute(); |
|
39 | + |
|
40 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
41 | + |
|
42 | + if ($resultObject != false) { |
|
43 | + $resultObject->setDatabase($database); |
|
44 | + } |
|
45 | + |
|
46 | + return $resultObject; |
|
47 | + } |
|
48 | + |
|
49 | + public function save() |
|
50 | + { |
|
51 | + if ($this->isNew()) { |
|
52 | + // insert |
|
53 | + $statement = $this->dbObject->prepare(<<<SQL |
|
54 | 54 | INSERT INTO `rdnscache` (address, data) VALUES (:address, :data); |
55 | 55 | SQL |
56 | - ); |
|
57 | - $statement->bindValue(":address", $this->address); |
|
58 | - $statement->bindValue(":data", $this->data); |
|
59 | - |
|
60 | - if ($statement->execute()) { |
|
61 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
62 | - } |
|
63 | - else { |
|
64 | - throw new Exception($statement->errorInfo()); |
|
65 | - } |
|
66 | - } |
|
67 | - else { |
|
68 | - // update |
|
69 | - $statement = $this->dbObject->prepare(<<<SQL |
|
56 | + ); |
|
57 | + $statement->bindValue(":address", $this->address); |
|
58 | + $statement->bindValue(":data", $this->data); |
|
59 | + |
|
60 | + if ($statement->execute()) { |
|
61 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
62 | + } |
|
63 | + else { |
|
64 | + throw new Exception($statement->errorInfo()); |
|
65 | + } |
|
66 | + } |
|
67 | + else { |
|
68 | + // update |
|
69 | + $statement = $this->dbObject->prepare(<<<SQL |
|
70 | 70 | UPDATE `rdnscache` |
71 | 71 | SET address = :address, data = :data, updateversion = updateversion + 1 |
72 | 72 | WHERE id = :id AND updateversion = :updateversion; |
73 | 73 | SQL |
74 | - ); |
|
75 | - |
|
76 | - $statement->bindValue(':id', $this->id); |
|
77 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
78 | - |
|
79 | - $statement->bindValue(':address', $this->address); |
|
80 | - $statement->bindValue(':data', $this->data); |
|
81 | - |
|
82 | - if (!$statement->execute()) { |
|
83 | - throw new Exception($statement->errorInfo()); |
|
84 | - } |
|
85 | - |
|
86 | - if ($statement->rowCount() !== 1) { |
|
87 | - throw new OptimisticLockFailedException(); |
|
88 | - } |
|
89 | - |
|
90 | - $this->updateversion++; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - public function getAddress() |
|
95 | - { |
|
96 | - return $this->address; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $address |
|
101 | - */ |
|
102 | - public function setAddress($address) |
|
103 | - { |
|
104 | - $this->address = $address; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function getData() |
|
111 | - { |
|
112 | - return unserialize($this->data); |
|
113 | - } |
|
114 | - |
|
115 | - public function setData($data) |
|
116 | - { |
|
117 | - $this->data = serialize($data); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return DateTimeImmutable |
|
122 | - */ |
|
123 | - public function getCreation() |
|
124 | - { |
|
125 | - return new DateTimeImmutable($this->creation); |
|
126 | - } |
|
74 | + ); |
|
75 | + |
|
76 | + $statement->bindValue(':id', $this->id); |
|
77 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
78 | + |
|
79 | + $statement->bindValue(':address', $this->address); |
|
80 | + $statement->bindValue(':data', $this->data); |
|
81 | + |
|
82 | + if (!$statement->execute()) { |
|
83 | + throw new Exception($statement->errorInfo()); |
|
84 | + } |
|
85 | + |
|
86 | + if ($statement->rowCount() !== 1) { |
|
87 | + throw new OptimisticLockFailedException(); |
|
88 | + } |
|
89 | + |
|
90 | + $this->updateversion++; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + public function getAddress() |
|
95 | + { |
|
96 | + return $this->address; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $address |
|
101 | + */ |
|
102 | + public function setAddress($address) |
|
103 | + { |
|
104 | + $this->address = $address; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function getData() |
|
111 | + { |
|
112 | + return unserialize($this->data); |
|
113 | + } |
|
114 | + |
|
115 | + public function setData($data) |
|
116 | + { |
|
117 | + $this->data = serialize($data); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return DateTimeImmutable |
|
122 | + */ |
|
123 | + public function getCreation() |
|
124 | + { |
|
125 | + return new DateTimeImmutable($this->creation); |
|
126 | + } |
|
127 | 127 | } |
@@ -61,12 +61,10 @@ |
||
61 | 61 | |
62 | 62 | if ($statement->execute()) { |
63 | 63 | $this->id = (int)$this->dbObject->lastInsertId(); |
64 | - } |
|
65 | - else { |
|
64 | + } else { |
|
66 | 65 | throw new Exception($statement->errorInfo()); |
67 | 66 | } |
68 | - } |
|
69 | - else { |
|
67 | + } else { |
|
70 | 68 | // update |
71 | 69 | throw new Exception('Updating roles is not available'); |
72 | 70 | } |
@@ -15,106 +15,106 @@ |
||
15 | 15 | |
16 | 16 | class UserRole extends DataObject |
17 | 17 | { |
18 | - /** @var int */ |
|
19 | - private $user; |
|
20 | - /** @var string */ |
|
21 | - private $role; |
|
22 | - private ?int $domain; |
|
23 | - |
|
24 | - /** |
|
25 | - * @param int $user |
|
26 | - * @param PdoDatabase $database |
|
27 | - * @param int $domain |
|
28 | - * |
|
29 | - * @return UserRole[] |
|
30 | - */ |
|
31 | - public static function getForUser(int $user, PdoDatabase $database, int $domain) |
|
32 | - { |
|
33 | - $sql = 'SELECT * FROM userrole WHERE user = :user AND (domain IS NULL OR domain = :domain)'; |
|
34 | - $statement = $database->prepare($sql); |
|
35 | - $statement->bindValue(':user', $user); |
|
36 | - $statement->bindValue(':domain', $domain); |
|
37 | - |
|
38 | - $statement->execute(); |
|
39 | - |
|
40 | - $result = array(); |
|
41 | - |
|
42 | - /** @var Ban $v */ |
|
43 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
44 | - $v->setDatabase($database); |
|
45 | - $result[] = $v; |
|
46 | - } |
|
47 | - |
|
48 | - return $result; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Saves a data object to the database, either updating or inserting a record. |
|
53 | - * |
|
54 | - * @throws Exception |
|
55 | - */ |
|
56 | - public function save() |
|
57 | - { |
|
58 | - if ($this->isNew()) { |
|
59 | - // insert |
|
60 | - $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role, domain) VALUES (:user, :role, :domain);' |
|
61 | - ); |
|
62 | - $statement->bindValue(":user", $this->user); |
|
63 | - $statement->bindValue(":role", $this->role); |
|
64 | - $statement->bindValue(":domain", $this->domain); |
|
65 | - |
|
66 | - if ($statement->execute()) { |
|
67 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
68 | - } |
|
69 | - else { |
|
70 | - throw new Exception($statement->errorInfo()); |
|
71 | - } |
|
72 | - } |
|
73 | - else { |
|
74 | - // update |
|
75 | - throw new Exception('Updating roles is not available'); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return int |
|
81 | - */ |
|
82 | - public function getUser() |
|
83 | - { |
|
84 | - return $this->user; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param int $user |
|
89 | - */ |
|
90 | - public function setUser($user) |
|
91 | - { |
|
92 | - $this->user = $user; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function getRole() |
|
99 | - { |
|
100 | - return $this->role; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $role |
|
105 | - */ |
|
106 | - public function setRole($role) |
|
107 | - { |
|
108 | - $this->role = $role; |
|
109 | - } |
|
110 | - |
|
111 | - public function getDomain(): ?int |
|
112 | - { |
|
113 | - return $this->domain; |
|
114 | - } |
|
115 | - |
|
116 | - public function setDomain(?int $domain): void |
|
117 | - { |
|
118 | - $this->domain = $domain; |
|
119 | - } |
|
18 | + /** @var int */ |
|
19 | + private $user; |
|
20 | + /** @var string */ |
|
21 | + private $role; |
|
22 | + private ?int $domain; |
|
23 | + |
|
24 | + /** |
|
25 | + * @param int $user |
|
26 | + * @param PdoDatabase $database |
|
27 | + * @param int $domain |
|
28 | + * |
|
29 | + * @return UserRole[] |
|
30 | + */ |
|
31 | + public static function getForUser(int $user, PdoDatabase $database, int $domain) |
|
32 | + { |
|
33 | + $sql = 'SELECT * FROM userrole WHERE user = :user AND (domain IS NULL OR domain = :domain)'; |
|
34 | + $statement = $database->prepare($sql); |
|
35 | + $statement->bindValue(':user', $user); |
|
36 | + $statement->bindValue(':domain', $domain); |
|
37 | + |
|
38 | + $statement->execute(); |
|
39 | + |
|
40 | + $result = array(); |
|
41 | + |
|
42 | + /** @var Ban $v */ |
|
43 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
44 | + $v->setDatabase($database); |
|
45 | + $result[] = $v; |
|
46 | + } |
|
47 | + |
|
48 | + return $result; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Saves a data object to the database, either updating or inserting a record. |
|
53 | + * |
|
54 | + * @throws Exception |
|
55 | + */ |
|
56 | + public function save() |
|
57 | + { |
|
58 | + if ($this->isNew()) { |
|
59 | + // insert |
|
60 | + $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role, domain) VALUES (:user, :role, :domain);' |
|
61 | + ); |
|
62 | + $statement->bindValue(":user", $this->user); |
|
63 | + $statement->bindValue(":role", $this->role); |
|
64 | + $statement->bindValue(":domain", $this->domain); |
|
65 | + |
|
66 | + if ($statement->execute()) { |
|
67 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
68 | + } |
|
69 | + else { |
|
70 | + throw new Exception($statement->errorInfo()); |
|
71 | + } |
|
72 | + } |
|
73 | + else { |
|
74 | + // update |
|
75 | + throw new Exception('Updating roles is not available'); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return int |
|
81 | + */ |
|
82 | + public function getUser() |
|
83 | + { |
|
84 | + return $this->user; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param int $user |
|
89 | + */ |
|
90 | + public function setUser($user) |
|
91 | + { |
|
92 | + $this->user = $user; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function getRole() |
|
99 | + { |
|
100 | + return $this->role; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $role |
|
105 | + */ |
|
106 | + public function setRole($role) |
|
107 | + { |
|
108 | + $this->role = $role; |
|
109 | + } |
|
110 | + |
|
111 | + public function getDomain(): ?int |
|
112 | + { |
|
113 | + return $this->domain; |
|
114 | + } |
|
115 | + |
|
116 | + public function setDomain(?int $domain): void |
|
117 | + { |
|
118 | + $this->domain = $domain; |
|
119 | + } |
|
120 | 120 | } |
@@ -47,8 +47,7 @@ |
||
47 | 47 | if ($this->isNew()) { |
48 | 48 | // insert |
49 | 49 | throw new Exception('Not allowed to create new site notice object'); |
50 | - } |
|
51 | - else { |
|
50 | + } else { |
|
52 | 51 | // update |
53 | 52 | $statement = $this->dbObject->prepare(<<<SQL |
54 | 53 | UPDATE sitenotice |
@@ -20,74 +20,74 @@ |
||
20 | 20 | */ |
21 | 21 | class SiteNotice extends DataObject |
22 | 22 | { |
23 | - /** @var string */ |
|
24 | - private $content; |
|
23 | + /** @var string */ |
|
24 | + private $content; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Get a message. |
|
28 | - * |
|
29 | - * @param PdoDatabase $database |
|
30 | - * |
|
31 | - * @return string The content for display |
|
32 | - */ |
|
33 | - public static function get(PdoDatabase $database) |
|
34 | - { |
|
35 | - /** @var SiteNotice $message */ |
|
36 | - $message = self::getById(1, $database); |
|
26 | + /** |
|
27 | + * Get a message. |
|
28 | + * |
|
29 | + * @param PdoDatabase $database |
|
30 | + * |
|
31 | + * @return string The content for display |
|
32 | + */ |
|
33 | + public static function get(PdoDatabase $database) |
|
34 | + { |
|
35 | + /** @var SiteNotice $message */ |
|
36 | + $message = self::getById(1, $database); |
|
37 | 37 | |
38 | - return $message->getContent(); |
|
39 | - } |
|
38 | + return $message->getContent(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Saves the object |
|
43 | - * @throws Exception |
|
44 | - */ |
|
45 | - public function save() |
|
46 | - { |
|
47 | - if ($this->isNew()) { |
|
48 | - // insert |
|
49 | - throw new Exception('Not allowed to create new site notice object'); |
|
50 | - } |
|
51 | - else { |
|
52 | - // update |
|
53 | - $statement = $this->dbObject->prepare(<<<SQL |
|
41 | + /** |
|
42 | + * Saves the object |
|
43 | + * @throws Exception |
|
44 | + */ |
|
45 | + public function save() |
|
46 | + { |
|
47 | + if ($this->isNew()) { |
|
48 | + // insert |
|
49 | + throw new Exception('Not allowed to create new site notice object'); |
|
50 | + } |
|
51 | + else { |
|
52 | + // update |
|
53 | + $statement = $this->dbObject->prepare(<<<SQL |
|
54 | 54 | UPDATE sitenotice |
55 | 55 | SET content = :content, updateversion = updateversion + 1 |
56 | 56 | WHERE updateversion = :updateversion; |
57 | 57 | SQL |
58 | - ); |
|
59 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
58 | + ); |
|
59 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
60 | 60 | |
61 | - $statement->bindValue(':content', $this->content); |
|
61 | + $statement->bindValue(':content', $this->content); |
|
62 | 62 | |
63 | - if (!$statement->execute()) { |
|
64 | - throw new Exception($statement->errorInfo()); |
|
65 | - } |
|
63 | + if (!$statement->execute()) { |
|
64 | + throw new Exception($statement->errorInfo()); |
|
65 | + } |
|
66 | 66 | |
67 | - if ($statement->rowCount() !== 1) { |
|
68 | - throw new OptimisticLockFailedException(); |
|
69 | - } |
|
67 | + if ($statement->rowCount() !== 1) { |
|
68 | + throw new OptimisticLockFailedException(); |
|
69 | + } |
|
70 | 70 | |
71 | - $this->updateversion++; |
|
72 | - } |
|
73 | - } |
|
71 | + $this->updateversion++; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Gets the content of the message |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function getContent() |
|
80 | - { |
|
81 | - return $this->content; |
|
82 | - } |
|
75 | + /** |
|
76 | + * Gets the content of the message |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function getContent() |
|
80 | + { |
|
81 | + return $this->content; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Sets the content of the message |
|
86 | - * |
|
87 | - * @param string $content |
|
88 | - */ |
|
89 | - public function setContent($content) |
|
90 | - { |
|
91 | - $this->content = $content; |
|
92 | - } |
|
84 | + /** |
|
85 | + * Sets the content of the message |
|
86 | + * |
|
87 | + * @param string $content |
|
88 | + */ |
|
89 | + public function setContent($content) |
|
90 | + { |
|
91 | + $this->content = $content; |
|
92 | + } |
|
93 | 93 | } |
@@ -67,12 +67,10 @@ |
||
67 | 67 | |
68 | 68 | if ($statement->execute()) { |
69 | 69 | $this->id = (int)$this->dbObject->lastInsertId(); |
70 | - } |
|
71 | - else { |
|
70 | + } else { |
|
72 | 71 | throw new Exception($statement->errorInfo()); |
73 | 72 | } |
74 | - } |
|
75 | - else { |
|
73 | + } else { |
|
76 | 74 | // update |
77 | 75 | $statement = $this->dbObject->prepare(<<<SQL |
78 | 76 | UPDATE `request` SET |
@@ -22,34 +22,34 @@ discard block |
||
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 | - /** @var int */ |
|
42 | - private $domain; |
|
43 | - |
|
44 | - /** |
|
45 | - * @throws Exception |
|
46 | - * @throws OptimisticLockFailedException |
|
47 | - */ |
|
48 | - public function save() |
|
49 | - { |
|
50 | - if ($this->isNew()) { |
|
51 | - // insert |
|
52 | - $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 | + /** @var int */ |
|
42 | + private $domain; |
|
43 | + |
|
44 | + /** |
|
45 | + * @throws Exception |
|
46 | + * @throws OptimisticLockFailedException |
|
47 | + */ |
|
48 | + public function save() |
|
49 | + { |
|
50 | + if ($this->isNew()) { |
|
51 | + // insert |
|
52 | + $statement = $this->dbObject->prepare(<<<SQL |
|
53 | 53 | INSERT INTO `request` ( |
54 | 54 | email, ip, name, status, date, emailsent, |
55 | 55 | emailconfirm, reserved, useragent, forwardedip, |
@@ -60,30 +60,30 @@ discard block |
||
60 | 60 | :queue, :originform, :domain |
61 | 61 | ); |
62 | 62 | SQL |
63 | - ); |
|
64 | - $statement->bindValue(':email', $this->email); |
|
65 | - $statement->bindValue(':ip', $this->ip); |
|
66 | - $statement->bindValue(':name', $this->name); |
|
67 | - $statement->bindValue(':status', $this->status); |
|
68 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
69 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
70 | - $statement->bindValue(':reserved', $this->reserved); |
|
71 | - $statement->bindValue(':useragent', $this->useragent); |
|
72 | - $statement->bindValue(':forwardedip', $this->forwardedip); |
|
73 | - $statement->bindValue(':queue', $this->queue); |
|
74 | - $statement->bindValue(':originform', $this->originform); |
|
75 | - $statement->bindValue(':domain', $this->domain); |
|
76 | - |
|
77 | - if ($statement->execute()) { |
|
78 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
79 | - } |
|
80 | - else { |
|
81 | - throw new Exception($statement->errorInfo()); |
|
82 | - } |
|
83 | - } |
|
84 | - else { |
|
85 | - // update |
|
86 | - $statement = $this->dbObject->prepare(<<<SQL |
|
63 | + ); |
|
64 | + $statement->bindValue(':email', $this->email); |
|
65 | + $statement->bindValue(':ip', $this->ip); |
|
66 | + $statement->bindValue(':name', $this->name); |
|
67 | + $statement->bindValue(':status', $this->status); |
|
68 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
69 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
70 | + $statement->bindValue(':reserved', $this->reserved); |
|
71 | + $statement->bindValue(':useragent', $this->useragent); |
|
72 | + $statement->bindValue(':forwardedip', $this->forwardedip); |
|
73 | + $statement->bindValue(':queue', $this->queue); |
|
74 | + $statement->bindValue(':originform', $this->originform); |
|
75 | + $statement->bindValue(':domain', $this->domain); |
|
76 | + |
|
77 | + if ($statement->execute()) { |
|
78 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
79 | + } |
|
80 | + else { |
|
81 | + throw new Exception($statement->errorInfo()); |
|
82 | + } |
|
83 | + } |
|
84 | + else { |
|
85 | + // update |
|
86 | + $statement = $this->dbObject->prepare(<<<SQL |
|
87 | 87 | UPDATE `request` SET |
88 | 88 | status = :status, |
89 | 89 | emailsent = :emailsent, |
@@ -93,230 +93,230 @@ discard block |
||
93 | 93 | updateversion = updateversion + 1 |
94 | 94 | WHERE id = :id AND updateversion = :updateversion; |
95 | 95 | SQL |
96 | - ); |
|
97 | - |
|
98 | - $statement->bindValue(':id', $this->id); |
|
99 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
100 | - |
|
101 | - $statement->bindValue(':status', $this->status); |
|
102 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
103 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
104 | - $statement->bindValue(':reserved', $this->reserved); |
|
105 | - $statement->bindValue(':queue', $this->queue); |
|
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 string |
|
121 | - */ |
|
122 | - public function getIp() |
|
123 | - { |
|
124 | - return $this->ip; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $ip |
|
129 | - */ |
|
130 | - public function setIp($ip) |
|
131 | - { |
|
132 | - $this->ip = $ip; |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * @return string |
|
137 | - */ |
|
138 | - public function getName() |
|
139 | - { |
|
140 | - return $this->name; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param string $name |
|
145 | - */ |
|
146 | - public function setName($name) |
|
147 | - { |
|
148 | - $this->name = $name; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function getStatus() |
|
155 | - { |
|
156 | - return $this->status; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @param string $status |
|
161 | - */ |
|
162 | - public function setStatus($status) |
|
163 | - { |
|
164 | - $this->status = $status; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Returns the time the request was first submitted |
|
169 | - * |
|
170 | - * @return DateTimeImmutable |
|
171 | - */ |
|
172 | - public function getDate() |
|
173 | - { |
|
174 | - return new DateTimeImmutable($this->date); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function getEmailSent() |
|
181 | - { |
|
182 | - return $this->emailsent == "1"; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * @param bool $emailSent |
|
187 | - */ |
|
188 | - public function setEmailSent($emailSent) |
|
189 | - { |
|
190 | - $this->emailsent = $emailSent ? 1 : 0; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * @return int|null |
|
195 | - */ |
|
196 | - public function getReserved() |
|
197 | - { |
|
198 | - return $this->reserved; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param int|null $reserved |
|
203 | - */ |
|
204 | - public function setReserved($reserved) |
|
205 | - { |
|
206 | - $this->reserved = $reserved; |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function getUserAgent() |
|
213 | - { |
|
214 | - return $this->useragent; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * @param string $useragent |
|
219 | - */ |
|
220 | - public function setUserAgent($useragent) |
|
221 | - { |
|
222 | - $this->useragent = $useragent; |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * @return string|null |
|
227 | - */ |
|
228 | - public function getForwardedIp() |
|
229 | - { |
|
230 | - return $this->forwardedip; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string|null $forwardedip |
|
235 | - */ |
|
236 | - public function setForwardedIp($forwardedip) |
|
237 | - { |
|
238 | - // Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't. |
|
96 | + ); |
|
97 | + |
|
98 | + $statement->bindValue(':id', $this->id); |
|
99 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
100 | + |
|
101 | + $statement->bindValue(':status', $this->status); |
|
102 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
103 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
104 | + $statement->bindValue(':reserved', $this->reserved); |
|
105 | + $statement->bindValue(':queue', $this->queue); |
|
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 string |
|
121 | + */ |
|
122 | + public function getIp() |
|
123 | + { |
|
124 | + return $this->ip; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $ip |
|
129 | + */ |
|
130 | + public function setIp($ip) |
|
131 | + { |
|
132 | + $this->ip = $ip; |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * @return string |
|
137 | + */ |
|
138 | + public function getName() |
|
139 | + { |
|
140 | + return $this->name; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param string $name |
|
145 | + */ |
|
146 | + public function setName($name) |
|
147 | + { |
|
148 | + $this->name = $name; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function getStatus() |
|
155 | + { |
|
156 | + return $this->status; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @param string $status |
|
161 | + */ |
|
162 | + public function setStatus($status) |
|
163 | + { |
|
164 | + $this->status = $status; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Returns the time the request was first submitted |
|
169 | + * |
|
170 | + * @return DateTimeImmutable |
|
171 | + */ |
|
172 | + public function getDate() |
|
173 | + { |
|
174 | + return new DateTimeImmutable($this->date); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function getEmailSent() |
|
181 | + { |
|
182 | + return $this->emailsent == "1"; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * @param bool $emailSent |
|
187 | + */ |
|
188 | + public function setEmailSent($emailSent) |
|
189 | + { |
|
190 | + $this->emailsent = $emailSent ? 1 : 0; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * @return int|null |
|
195 | + */ |
|
196 | + public function getReserved() |
|
197 | + { |
|
198 | + return $this->reserved; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param int|null $reserved |
|
203 | + */ |
|
204 | + public function setReserved($reserved) |
|
205 | + { |
|
206 | + $this->reserved = $reserved; |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function getUserAgent() |
|
213 | + { |
|
214 | + return $this->useragent; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * @param string $useragent |
|
219 | + */ |
|
220 | + public function setUserAgent($useragent) |
|
221 | + { |
|
222 | + $this->useragent = $useragent; |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * @return string|null |
|
227 | + */ |
|
228 | + public function getForwardedIp() |
|
229 | + { |
|
230 | + return $this->forwardedip; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string|null $forwardedip |
|
235 | + */ |
|
236 | + public function setForwardedIp($forwardedip) |
|
237 | + { |
|
238 | + // Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't. |
|
239 | 239 | |
240 | - $xff = explode(',', $forwardedip); |
|
241 | - $valid = array(); |
|
240 | + $xff = explode(',', $forwardedip); |
|
241 | + $valid = array(); |
|
242 | 242 | |
243 | - foreach ($xff as $ip) { |
|
244 | - $ip = trim($ip); |
|
245 | - if (filter_var($ip, FILTER_VALIDATE_IP)) { |
|
246 | - $valid[] = $ip; |
|
247 | - } |
|
248 | - } |
|
249 | - $this->forwardedip = implode(", ", $valid); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * @return bool |
|
254 | - */ |
|
255 | - public function hasComments() |
|
256 | - { |
|
257 | - if ($this->hasCommentsResolved) { |
|
258 | - return $this->hasComments; |
|
259 | - } |
|
260 | - |
|
261 | - $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
262 | - $commentsQuery->bindValue(":id", $this->id); |
|
263 | - |
|
264 | - $commentsQuery->execute(); |
|
265 | - |
|
266 | - $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
267 | - $this->hasCommentsResolved = true; |
|
268 | - |
|
269 | - return $this->hasComments; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - public function getEmailConfirm() |
|
276 | - { |
|
277 | - return $this->emailconfirm; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @param string $emailconfirm |
|
282 | - */ |
|
283 | - public function setEmailConfirm($emailconfirm) |
|
284 | - { |
|
285 | - $this->emailconfirm = $emailconfirm; |
|
286 | - } |
|
287 | - |
|
288 | - public function generateEmailConfirmationHash() |
|
289 | - { |
|
290 | - $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @return string|null |
|
295 | - */ |
|
296 | - public function getEmail() |
|
297 | - { |
|
298 | - return $this->email; |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @param string|null $email |
|
303 | - */ |
|
304 | - public function setEmail($email) |
|
305 | - { |
|
306 | - $this->email = $email; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * @return string |
|
311 | - * @throws Exception |
|
312 | - */ |
|
313 | - public function getClosureReason() |
|
314 | - { |
|
315 | - if ($this->status != 'Closed') { |
|
316 | - throw new Exception("Can't get closure reason for open request."); |
|
317 | - } |
|
318 | - |
|
319 | - $statement = $this->dbObject->prepare(<<<SQL |
|
243 | + foreach ($xff as $ip) { |
|
244 | + $ip = trim($ip); |
|
245 | + if (filter_var($ip, FILTER_VALIDATE_IP)) { |
|
246 | + $valid[] = $ip; |
|
247 | + } |
|
248 | + } |
|
249 | + $this->forwardedip = implode(", ", $valid); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * @return bool |
|
254 | + */ |
|
255 | + public function hasComments() |
|
256 | + { |
|
257 | + if ($this->hasCommentsResolved) { |
|
258 | + return $this->hasComments; |
|
259 | + } |
|
260 | + |
|
261 | + $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
262 | + $commentsQuery->bindValue(":id", $this->id); |
|
263 | + |
|
264 | + $commentsQuery->execute(); |
|
265 | + |
|
266 | + $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
267 | + $this->hasCommentsResolved = true; |
|
268 | + |
|
269 | + return $this->hasComments; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + public function getEmailConfirm() |
|
276 | + { |
|
277 | + return $this->emailconfirm; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @param string $emailconfirm |
|
282 | + */ |
|
283 | + public function setEmailConfirm($emailconfirm) |
|
284 | + { |
|
285 | + $this->emailconfirm = $emailconfirm; |
|
286 | + } |
|
287 | + |
|
288 | + public function generateEmailConfirmationHash() |
|
289 | + { |
|
290 | + $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @return string|null |
|
295 | + */ |
|
296 | + public function getEmail() |
|
297 | + { |
|
298 | + return $this->email; |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @param string|null $email |
|
303 | + */ |
|
304 | + public function setEmail($email) |
|
305 | + { |
|
306 | + $this->email = $email; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * @return string |
|
311 | + * @throws Exception |
|
312 | + */ |
|
313 | + public function getClosureReason() |
|
314 | + { |
|
315 | + if ($this->status != 'Closed') { |
|
316 | + throw new Exception("Can't get closure reason for open request."); |
|
317 | + } |
|
318 | + |
|
319 | + $statement = $this->dbObject->prepare(<<<SQL |
|
320 | 320 | SELECT closes.mail_desc |
321 | 321 | FROM log |
322 | 322 | INNER JOIN closes ON log.action = closes.closes |
@@ -326,25 +326,25 @@ discard block |
||
326 | 326 | ORDER BY log.timestamp DESC |
327 | 327 | LIMIT 1; |
328 | 328 | SQL |
329 | - ); |
|
329 | + ); |
|
330 | 330 | |
331 | - $statement->bindValue(":requestId", $this->id); |
|
332 | - $statement->execute(); |
|
333 | - $reason = $statement->fetchColumn(); |
|
331 | + $statement->bindValue(":requestId", $this->id); |
|
332 | + $statement->execute(); |
|
333 | + $reason = $statement->fetchColumn(); |
|
334 | 334 | |
335 | - return $reason; |
|
336 | - } |
|
335 | + return $reason; |
|
336 | + } |
|
337 | 337 | |
338 | - /** |
|
339 | - * Gets a value indicating whether the request was closed as created or not. |
|
340 | - */ |
|
341 | - public function getWasCreated() |
|
342 | - { |
|
343 | - if ($this->status != 'Closed') { |
|
344 | - throw new Exception("Can't get closure reason for open request."); |
|
345 | - } |
|
338 | + /** |
|
339 | + * Gets a value indicating whether the request was closed as created or not. |
|
340 | + */ |
|
341 | + public function getWasCreated() |
|
342 | + { |
|
343 | + if ($this->status != 'Closed') { |
|
344 | + throw new Exception("Can't get closure reason for open request."); |
|
345 | + } |
|
346 | 346 | |
347 | - $statement = $this->dbObject->prepare(<<<SQL |
|
347 | + $statement = $this->dbObject->prepare(<<<SQL |
|
348 | 348 | SELECT emailtemplate.defaultaction, log.action |
349 | 349 | FROM log |
350 | 350 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
@@ -354,43 +354,43 @@ discard block |
||
354 | 354 | ORDER BY log.timestamp DESC |
355 | 355 | LIMIT 1; |
356 | 356 | SQL |
357 | - ); |
|
358 | - |
|
359 | - $statement->bindValue(":requestId", $this->id); |
|
360 | - $statement->execute(); |
|
361 | - $defaultAction = $statement->fetchColumn(0); |
|
362 | - $logAction = $statement->fetchColumn(1); |
|
363 | - $statement->closeCursor(); |
|
364 | - |
|
365 | - if ($defaultAction === null) { |
|
366 | - return $logAction === "Closed custom-y"; |
|
367 | - } |
|
368 | - |
|
369 | - return $defaultAction === EmailTemplate::ACTION_CREATED; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * @return DateTime |
|
374 | - */ |
|
375 | - public function getClosureDate() |
|
376 | - { |
|
377 | - $logQuery = $this->dbObject->prepare(<<<SQL |
|
357 | + ); |
|
358 | + |
|
359 | + $statement->bindValue(":requestId", $this->id); |
|
360 | + $statement->execute(); |
|
361 | + $defaultAction = $statement->fetchColumn(0); |
|
362 | + $logAction = $statement->fetchColumn(1); |
|
363 | + $statement->closeCursor(); |
|
364 | + |
|
365 | + if ($defaultAction === null) { |
|
366 | + return $logAction === "Closed custom-y"; |
|
367 | + } |
|
368 | + |
|
369 | + return $defaultAction === EmailTemplate::ACTION_CREATED; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * @return DateTime |
|
374 | + */ |
|
375 | + public function getClosureDate() |
|
376 | + { |
|
377 | + $logQuery = $this->dbObject->prepare(<<<SQL |
|
378 | 378 | SELECT timestamp FROM log |
379 | 379 | WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%' |
380 | 380 | ORDER BY timestamp DESC LIMIT 1; |
381 | 381 | SQL |
382 | - ); |
|
383 | - $logQuery->bindValue(":request", $this->getId()); |
|
384 | - $logQuery->execute(); |
|
385 | - $logTime = $logQuery->fetchColumn(); |
|
386 | - $logQuery->closeCursor(); |
|
387 | - |
|
388 | - return new DateTime($logTime); |
|
389 | - } |
|
390 | - |
|
391 | - public function getLastUpdated() |
|
392 | - { |
|
393 | - $logQuery = $this->dbObject->prepare(<<<SQL |
|
382 | + ); |
|
383 | + $logQuery->bindValue(":request", $this->getId()); |
|
384 | + $logQuery->execute(); |
|
385 | + $logTime = $logQuery->fetchColumn(); |
|
386 | + $logQuery->closeCursor(); |
|
387 | + |
|
388 | + return new DateTime($logTime); |
|
389 | + } |
|
390 | + |
|
391 | + public function getLastUpdated() |
|
392 | + { |
|
393 | + $logQuery = $this->dbObject->prepare(<<<SQL |
|
394 | 394 | SELECT max(d.ts) FROM ( |
395 | 395 | SELECT r.date AS ts FROM request r WHERE r.id = :requestr |
396 | 396 | UNION ALL |
@@ -399,103 +399,103 @@ discard block |
||
399 | 399 | SELECT c.time AS ts FROM comment c WHERE c.request = :requestc |
400 | 400 | ) d |
401 | 401 | SQL |
402 | - ); |
|
403 | - |
|
404 | - $logQuery->bindValue(":requestr", $this->getId()); |
|
405 | - $logQuery->bindValue(":requestl", $this->getId()); |
|
406 | - $logQuery->bindValue(":requestc", $this->getId()); |
|
407 | - $logQuery->execute(); |
|
408 | - $logTime = $logQuery->fetchColumn(); |
|
409 | - $logQuery->closeCursor(); |
|
410 | - |
|
411 | - return new DateTime($logTime); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
416 | - * data to unauthorised* users. |
|
417 | - * |
|
418 | - * *:Not tool admins, check users, or the reserving user. |
|
419 | - * |
|
420 | - * @return string |
|
421 | - * |
|
422 | - * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
423 | - * Maybe depend on the last logged action timestamp? |
|
424 | - */ |
|
425 | - public function getRevealHash() |
|
426 | - { |
|
427 | - $data = $this->id // unique per request |
|
428 | - . '|' . $this->ip // } |
|
429 | - . '|' . $this->forwardedip // } private data not known to those without access |
|
430 | - . '|' . $this->useragent // } |
|
431 | - . '|' . $this->email // } |
|
432 | - . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
433 | - |
|
434 | - return hash('sha256', $data); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * @return int|null |
|
439 | - */ |
|
440 | - public function getQueue() : ?int |
|
441 | - { |
|
442 | - return $this->queue; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * @return RequestQueue|null |
|
447 | - */ |
|
448 | - public function getQueueObject(): ?RequestQueue |
|
449 | - { |
|
450 | - /** @var RequestQueue $queue */ |
|
451 | - $queue = RequestQueue::getById($this->queue, $this->getDatabase()); |
|
452 | - |
|
453 | - return $queue === false ? null : $queue; |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * @param int|null $queue |
|
458 | - */ |
|
459 | - public function setQueue(?int $queue): void |
|
460 | - { |
|
461 | - $this->queue = $queue; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * @return int|null |
|
466 | - */ |
|
467 | - public function getOriginForm(): ?int |
|
468 | - { |
|
469 | - return $this->originform; |
|
470 | - } |
|
471 | - |
|
472 | - public function getOriginFormObject(): ?RequestForm |
|
473 | - { |
|
474 | - if ($this->originform === null) { |
|
475 | - return null; |
|
476 | - } |
|
477 | - |
|
478 | - /** @var RequestForm|bool $form */ |
|
479 | - $form = RequestForm::getById($this->originform, $this->getDatabase()); |
|
480 | - |
|
481 | - return $form === false ? null : $form; |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * @param int|null $originForm |
|
486 | - */ |
|
487 | - public function setOriginForm(?int $originForm): void |
|
488 | - { |
|
489 | - $this->originform = $originForm; |
|
490 | - } |
|
491 | - |
|
492 | - public function getDomain(): int |
|
493 | - { |
|
494 | - return $this->domain; |
|
495 | - } |
|
496 | - |
|
497 | - public function setDomain(int $domain): void |
|
498 | - { |
|
499 | - $this->domain = $domain; |
|
500 | - } |
|
402 | + ); |
|
403 | + |
|
404 | + $logQuery->bindValue(":requestr", $this->getId()); |
|
405 | + $logQuery->bindValue(":requestl", $this->getId()); |
|
406 | + $logQuery->bindValue(":requestc", $this->getId()); |
|
407 | + $logQuery->execute(); |
|
408 | + $logTime = $logQuery->fetchColumn(); |
|
409 | + $logQuery->closeCursor(); |
|
410 | + |
|
411 | + return new DateTime($logTime); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
416 | + * data to unauthorised* users. |
|
417 | + * |
|
418 | + * *:Not tool admins, check users, or the reserving user. |
|
419 | + * |
|
420 | + * @return string |
|
421 | + * |
|
422 | + * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
423 | + * Maybe depend on the last logged action timestamp? |
|
424 | + */ |
|
425 | + public function getRevealHash() |
|
426 | + { |
|
427 | + $data = $this->id // unique per request |
|
428 | + . '|' . $this->ip // } |
|
429 | + . '|' . $this->forwardedip // } private data not known to those without access |
|
430 | + . '|' . $this->useragent // } |
|
431 | + . '|' . $this->email // } |
|
432 | + . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
433 | + |
|
434 | + return hash('sha256', $data); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * @return int|null |
|
439 | + */ |
|
440 | + public function getQueue() : ?int |
|
441 | + { |
|
442 | + return $this->queue; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * @return RequestQueue|null |
|
447 | + */ |
|
448 | + public function getQueueObject(): ?RequestQueue |
|
449 | + { |
|
450 | + /** @var RequestQueue $queue */ |
|
451 | + $queue = RequestQueue::getById($this->queue, $this->getDatabase()); |
|
452 | + |
|
453 | + return $queue === false ? null : $queue; |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * @param int|null $queue |
|
458 | + */ |
|
459 | + public function setQueue(?int $queue): void |
|
460 | + { |
|
461 | + $this->queue = $queue; |
|
462 | + } |
|
463 | + |
|
464 | + /** |
|
465 | + * @return int|null |
|
466 | + */ |
|
467 | + public function getOriginForm(): ?int |
|
468 | + { |
|
469 | + return $this->originform; |
|
470 | + } |
|
471 | + |
|
472 | + public function getOriginFormObject(): ?RequestForm |
|
473 | + { |
|
474 | + if ($this->originform === null) { |
|
475 | + return null; |
|
476 | + } |
|
477 | + |
|
478 | + /** @var RequestForm|bool $form */ |
|
479 | + $form = RequestForm::getById($this->originform, $this->getDatabase()); |
|
480 | + |
|
481 | + return $form === false ? null : $form; |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * @param int|null $originForm |
|
486 | + */ |
|
487 | + public function setOriginForm(?int $originForm): void |
|
488 | + { |
|
489 | + $this->originform = $originForm; |
|
490 | + } |
|
491 | + |
|
492 | + public function getDomain(): int |
|
493 | + { |
|
494 | + return $this->domain; |
|
495 | + } |
|
496 | + |
|
497 | + public function setDomain(int $domain): void |
|
498 | + { |
|
499 | + $this->domain = $domain; |
|
500 | + } |
|
501 | 501 | } |
@@ -18,101 +18,101 @@ |
||
18 | 18 | */ |
19 | 19 | class AntiSpoofCache extends DataObject |
20 | 20 | { |
21 | - /** @var string */ |
|
22 | - protected $username; |
|
23 | - /** @var string */ |
|
24 | - protected $data; |
|
25 | - /** @var string */ |
|
26 | - protected $timestamp; |
|
27 | - |
|
28 | - /** |
|
29 | - * @param string $username |
|
30 | - * @param PdoDatabase $database |
|
31 | - * |
|
32 | - * @return AntiSpoofCache|false |
|
33 | - */ |
|
34 | - public static function getByUsername($username, PdoDatabase $database) |
|
35 | - { |
|
36 | - $statement = $database->prepare(<<<SQL |
|
21 | + /** @var string */ |
|
22 | + protected $username; |
|
23 | + /** @var string */ |
|
24 | + protected $data; |
|
25 | + /** @var string */ |
|
26 | + protected $timestamp; |
|
27 | + |
|
28 | + /** |
|
29 | + * @param string $username |
|
30 | + * @param PdoDatabase $database |
|
31 | + * |
|
32 | + * @return AntiSpoofCache|false |
|
33 | + */ |
|
34 | + public static function getByUsername($username, PdoDatabase $database) |
|
35 | + { |
|
36 | + $statement = $database->prepare(<<<SQL |
|
37 | 37 | SELECT * |
38 | 38 | FROM antispoofcache |
39 | 39 | WHERE username = :id AND timestamp > date_sub(now(), INTERVAL 3 HOUR) |
40 | 40 | LIMIT 1 |
41 | 41 | SQL |
42 | - ); |
|
43 | - $statement->bindValue(":id", $username); |
|
44 | - |
|
45 | - $statement->execute(); |
|
46 | - |
|
47 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
48 | - |
|
49 | - if ($resultObject != false) { |
|
50 | - $resultObject->setDatabase($database); |
|
51 | - } |
|
52 | - |
|
53 | - return $resultObject; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function getUsername() |
|
60 | - { |
|
61 | - return $this->username; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param string $username |
|
66 | - */ |
|
67 | - public function setUsername($username) |
|
68 | - { |
|
69 | - $this->username = $username; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @return string |
|
74 | - */ |
|
75 | - public function getData() |
|
76 | - { |
|
77 | - return $this->data; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @param string $data |
|
82 | - */ |
|
83 | - public function setData($data) |
|
84 | - { |
|
85 | - $this->data = $data; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return DateTimeImmutable |
|
90 | - */ |
|
91 | - public function getTimestamp() |
|
92 | - { |
|
93 | - return new DateTimeImmutable($this->timestamp); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @throws Exception |
|
98 | - */ |
|
99 | - public function save() |
|
100 | - { |
|
101 | - if ($this->isNew()) { |
|
102 | - // insert |
|
103 | - // clear old data first |
|
104 | - $this->dbObject->exec("DELETE FROM antispoofcache WHERE timestamp < date_sub(now(), INTERVAL 3 HOUR);"); |
|
105 | - |
|
106 | - $statement = $this->dbObject->prepare("INSERT INTO antispoofcache (username, data) VALUES (:username, :data);"); |
|
107 | - $statement->bindValue(":username", $this->username); |
|
108 | - $statement->bindValue(":data", $this->data); |
|
109 | - |
|
110 | - if ($statement->execute()) { |
|
111 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
112 | - } |
|
113 | - else { |
|
114 | - throw new Exception($statement->errorInfo()); |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
42 | + ); |
|
43 | + $statement->bindValue(":id", $username); |
|
44 | + |
|
45 | + $statement->execute(); |
|
46 | + |
|
47 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
48 | + |
|
49 | + if ($resultObject != false) { |
|
50 | + $resultObject->setDatabase($database); |
|
51 | + } |
|
52 | + |
|
53 | + return $resultObject; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function getUsername() |
|
60 | + { |
|
61 | + return $this->username; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param string $username |
|
66 | + */ |
|
67 | + public function setUsername($username) |
|
68 | + { |
|
69 | + $this->username = $username; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @return string |
|
74 | + */ |
|
75 | + public function getData() |
|
76 | + { |
|
77 | + return $this->data; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @param string $data |
|
82 | + */ |
|
83 | + public function setData($data) |
|
84 | + { |
|
85 | + $this->data = $data; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return DateTimeImmutable |
|
90 | + */ |
|
91 | + public function getTimestamp() |
|
92 | + { |
|
93 | + return new DateTimeImmutable($this->timestamp); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @throws Exception |
|
98 | + */ |
|
99 | + public function save() |
|
100 | + { |
|
101 | + if ($this->isNew()) { |
|
102 | + // insert |
|
103 | + // clear old data first |
|
104 | + $this->dbObject->exec("DELETE FROM antispoofcache WHERE timestamp < date_sub(now(), INTERVAL 3 HOUR);"); |
|
105 | + |
|
106 | + $statement = $this->dbObject->prepare("INSERT INTO antispoofcache (username, data) VALUES (:username, :data);"); |
|
107 | + $statement->bindValue(":username", $this->username); |
|
108 | + $statement->bindValue(":data", $this->data); |
|
109 | + |
|
110 | + if ($statement->execute()) { |
|
111 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
112 | + } |
|
113 | + else { |
|
114 | + throw new Exception($statement->errorInfo()); |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | 118 | } |
@@ -109,8 +109,7 @@ |
||
109 | 109 | |
110 | 110 | if ($statement->execute()) { |
111 | 111 | $this->id = (int)$this->dbObject->lastInsertId(); |
112 | - } |
|
113 | - else { |
|
112 | + } else { |
|
114 | 113 | throw new Exception($statement->errorInfo()); |
115 | 114 | } |
116 | 115 | } |
@@ -65,12 +65,10 @@ |
||
65 | 65 | |
66 | 66 | if ($statement->execute()) { |
67 | 67 | $this->id = (int)$this->dbObject->lastInsertId(); |
68 | - } |
|
69 | - else { |
|
68 | + } else { |
|
70 | 69 | throw new Exception($statement->errorInfo()); |
71 | 70 | } |
72 | - } |
|
73 | - else { |
|
71 | + } else { |
|
74 | 72 | // update |
75 | 73 | $statement = $this->dbObject->prepare(<<<SQL |
76 | 74 | UPDATE `welcometemplate` |
@@ -20,204 +20,204 @@ |
||
20 | 20 | */ |
21 | 21 | class WelcomeTemplate extends DataObject |
22 | 22 | { |
23 | - /** @var string */ |
|
24 | - private $usercode; |
|
25 | - /** @var string */ |
|
26 | - private $botcode; |
|
27 | - private $usageCache; |
|
28 | - private $deleted = 0; |
|
29 | - /** @var int */ |
|
30 | - private $domain; |
|
31 | - |
|
32 | - /** |
|
33 | - * Summary of getAll |
|
34 | - * |
|
35 | - * @param PdoDatabase $database |
|
36 | - * |
|
37 | - * @return WelcomeTemplate[] |
|
38 | - */ |
|
39 | - public static function getAll(PdoDatabase $database, int $domain) |
|
40 | - { |
|
41 | - $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0 AND domain = :domain;"); |
|
42 | - |
|
43 | - $statement->execute([':domain' => $domain]); |
|
44 | - |
|
45 | - $result = array(); |
|
46 | - /** @var WelcomeTemplate $v */ |
|
47 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) { |
|
48 | - $v->setDatabase($database); |
|
49 | - $result[] = $v; |
|
50 | - } |
|
51 | - |
|
52 | - return $result; |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @throws Exception |
|
57 | - */ |
|
58 | - public function save() |
|
59 | - { |
|
60 | - if ($this->isNew()) { |
|
61 | - // insert |
|
62 | - $statement = $this->dbObject->prepare(<<<SQL |
|
23 | + /** @var string */ |
|
24 | + private $usercode; |
|
25 | + /** @var string */ |
|
26 | + private $botcode; |
|
27 | + private $usageCache; |
|
28 | + private $deleted = 0; |
|
29 | + /** @var int */ |
|
30 | + private $domain; |
|
31 | + |
|
32 | + /** |
|
33 | + * Summary of getAll |
|
34 | + * |
|
35 | + * @param PdoDatabase $database |
|
36 | + * |
|
37 | + * @return WelcomeTemplate[] |
|
38 | + */ |
|
39 | + public static function getAll(PdoDatabase $database, int $domain) |
|
40 | + { |
|
41 | + $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0 AND domain = :domain;"); |
|
42 | + |
|
43 | + $statement->execute([':domain' => $domain]); |
|
44 | + |
|
45 | + $result = array(); |
|
46 | + /** @var WelcomeTemplate $v */ |
|
47 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) { |
|
48 | + $v->setDatabase($database); |
|
49 | + $result[] = $v; |
|
50 | + } |
|
51 | + |
|
52 | + return $result; |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @throws Exception |
|
57 | + */ |
|
58 | + public function save() |
|
59 | + { |
|
60 | + if ($this->isNew()) { |
|
61 | + // insert |
|
62 | + $statement = $this->dbObject->prepare(<<<SQL |
|
63 | 63 | INSERT INTO welcometemplate (usercode, botcode, domain) VALUES (:usercode, :botcode, :domain); |
64 | 64 | SQL |
65 | - ); |
|
66 | - $statement->bindValue(":usercode", $this->usercode); |
|
67 | - $statement->bindValue(":botcode", $this->botcode); |
|
68 | - $statement->bindValue(":domain", $this->domain); |
|
69 | - |
|
70 | - if ($statement->execute()) { |
|
71 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
72 | - } |
|
73 | - else { |
|
74 | - throw new Exception($statement->errorInfo()); |
|
75 | - } |
|
76 | - } |
|
77 | - else { |
|
78 | - // update |
|
79 | - $statement = $this->dbObject->prepare(<<<SQL |
|
65 | + ); |
|
66 | + $statement->bindValue(":usercode", $this->usercode); |
|
67 | + $statement->bindValue(":botcode", $this->botcode); |
|
68 | + $statement->bindValue(":domain", $this->domain); |
|
69 | + |
|
70 | + if ($statement->execute()) { |
|
71 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
72 | + } |
|
73 | + else { |
|
74 | + throw new Exception($statement->errorInfo()); |
|
75 | + } |
|
76 | + } |
|
77 | + else { |
|
78 | + // update |
|
79 | + $statement = $this->dbObject->prepare(<<<SQL |
|
80 | 80 | UPDATE `welcometemplate` |
81 | 81 | SET usercode = :usercode, botcode = :botcode, updateversion = updateversion + 1 |
82 | 82 | WHERE id = :id AND updateversion = :updateversion; |
83 | 83 | SQL |
84 | - ); |
|
85 | - |
|
86 | - $statement->bindValue(':id', $this->id); |
|
87 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
88 | - |
|
89 | - $statement->bindValue(':usercode', $this->usercode); |
|
90 | - $statement->bindValue(':botcode', $this->botcode); |
|
91 | - |
|
92 | - if (!$statement->execute()) { |
|
93 | - throw new Exception($statement->errorInfo()); |
|
94 | - } |
|
95 | - |
|
96 | - if ($statement->rowCount() !== 1) { |
|
97 | - throw new OptimisticLockFailedException(); |
|
98 | - } |
|
99 | - |
|
100 | - $this->updateversion++; |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function getUserCode() |
|
108 | - { |
|
109 | - return $this->usercode; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @param string $usercode |
|
114 | - */ |
|
115 | - public function setUserCode($usercode) |
|
116 | - { |
|
117 | - $this->usercode = $usercode; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function getBotCode() |
|
124 | - { |
|
125 | - return $this->botcode; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $botcode |
|
130 | - */ |
|
131 | - public function setBotCode($botcode) |
|
132 | - { |
|
133 | - $this->botcode = $botcode; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @return User[] |
|
138 | - */ |
|
139 | - public function getUsersUsingTemplate() |
|
140 | - { |
|
141 | - if ($this->usageCache === null) { |
|
142 | - $statement = $this->dbObject->prepare("SELECT * FROM user WHERE id IN (SELECT DISTINCT user FROM userpreference WHERE preference = :pref AND value = :id);"); |
|
143 | - |
|
144 | - $statement->execute([ |
|
145 | - ':id' => $this->id, |
|
146 | - ':pref' => PreferenceManager::PREF_WELCOMETEMPLATE |
|
147 | - ]); |
|
148 | - |
|
149 | - $result = array(); |
|
150 | - /** @var WelcomeTemplate $v */ |
|
151 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) { |
|
152 | - $v->setDatabase($this->dbObject); |
|
153 | - $result[] = $v; |
|
154 | - } |
|
155 | - |
|
156 | - $this->usageCache = $result; |
|
157 | - } |
|
158 | - |
|
159 | - return $this->usageCache; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Deletes the object from the database |
|
164 | - */ |
|
165 | - public function delete() |
|
166 | - { |
|
167 | - if ($this->id === null) { |
|
168 | - // wtf? |
|
169 | - return; |
|
170 | - } |
|
171 | - |
|
172 | - $deleteQuery = "UPDATE welcometemplate SET deleted = 1, updateversion = updateversion + 1 WHERE id = :id AND updateversion = :updateversion;"; |
|
173 | - $statement = $this->dbObject->prepare($deleteQuery); |
|
174 | - |
|
175 | - $statement->bindValue(":id", $this->id); |
|
176 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
177 | - $statement->execute(); |
|
178 | - |
|
179 | - if ($statement->rowCount() !== 1) { |
|
180 | - throw new OptimisticLockFailedException(); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * @return bool |
|
186 | - */ |
|
187 | - public function isDeleted() |
|
188 | - { |
|
189 | - return ((int)$this->deleted) === 1; |
|
190 | - } |
|
191 | - |
|
192 | - public function getSectionHeader() |
|
193 | - { |
|
194 | - // Hard-coded for future update ability to change this per-template. This has beem moved from being hard-coded |
|
195 | - // directly in the welcome task, and safely permits us to show the header in the welcome template preview |
|
196 | - return "Welcome!"; |
|
197 | - } |
|
198 | - |
|
199 | - public function getBotCodeForWikiSave(string $request, $creator) |
|
200 | - { |
|
201 | - $templateText = $this->getBotCode(); |
|
202 | - |
|
203 | - $templateText = str_replace('$request', $request, $templateText); |
|
204 | - $templateText = str_replace('$creator', $creator, $templateText); |
|
205 | - |
|
206 | - // legacy; these have been removed in Prod for now, but I'm keeping them in case someone follows the |
|
207 | - // instructions in prod prior to deployment. |
|
208 | - $templateText = str_replace('$signature', '~~~~', $templateText); |
|
209 | - $templateText = str_replace('$username', $creator, $templateText); |
|
210 | - |
|
211 | - return $templateText; |
|
212 | - } |
|
213 | - |
|
214 | - public function getDomain(): int |
|
215 | - { |
|
216 | - return $this->domain; |
|
217 | - } |
|
218 | - |
|
219 | - public function setDomain(int $domain): void |
|
220 | - { |
|
221 | - $this->domain = $domain; |
|
222 | - } |
|
84 | + ); |
|
85 | + |
|
86 | + $statement->bindValue(':id', $this->id); |
|
87 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
88 | + |
|
89 | + $statement->bindValue(':usercode', $this->usercode); |
|
90 | + $statement->bindValue(':botcode', $this->botcode); |
|
91 | + |
|
92 | + if (!$statement->execute()) { |
|
93 | + throw new Exception($statement->errorInfo()); |
|
94 | + } |
|
95 | + |
|
96 | + if ($statement->rowCount() !== 1) { |
|
97 | + throw new OptimisticLockFailedException(); |
|
98 | + } |
|
99 | + |
|
100 | + $this->updateversion++; |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function getUserCode() |
|
108 | + { |
|
109 | + return $this->usercode; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @param string $usercode |
|
114 | + */ |
|
115 | + public function setUserCode($usercode) |
|
116 | + { |
|
117 | + $this->usercode = $usercode; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function getBotCode() |
|
124 | + { |
|
125 | + return $this->botcode; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $botcode |
|
130 | + */ |
|
131 | + public function setBotCode($botcode) |
|
132 | + { |
|
133 | + $this->botcode = $botcode; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @return User[] |
|
138 | + */ |
|
139 | + public function getUsersUsingTemplate() |
|
140 | + { |
|
141 | + if ($this->usageCache === null) { |
|
142 | + $statement = $this->dbObject->prepare("SELECT * FROM user WHERE id IN (SELECT DISTINCT user FROM userpreference WHERE preference = :pref AND value = :id);"); |
|
143 | + |
|
144 | + $statement->execute([ |
|
145 | + ':id' => $this->id, |
|
146 | + ':pref' => PreferenceManager::PREF_WELCOMETEMPLATE |
|
147 | + ]); |
|
148 | + |
|
149 | + $result = array(); |
|
150 | + /** @var WelcomeTemplate $v */ |
|
151 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) { |
|
152 | + $v->setDatabase($this->dbObject); |
|
153 | + $result[] = $v; |
|
154 | + } |
|
155 | + |
|
156 | + $this->usageCache = $result; |
|
157 | + } |
|
158 | + |
|
159 | + return $this->usageCache; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Deletes the object from the database |
|
164 | + */ |
|
165 | + public function delete() |
|
166 | + { |
|
167 | + if ($this->id === null) { |
|
168 | + // wtf? |
|
169 | + return; |
|
170 | + } |
|
171 | + |
|
172 | + $deleteQuery = "UPDATE welcometemplate SET deleted = 1, updateversion = updateversion + 1 WHERE id = :id AND updateversion = :updateversion;"; |
|
173 | + $statement = $this->dbObject->prepare($deleteQuery); |
|
174 | + |
|
175 | + $statement->bindValue(":id", $this->id); |
|
176 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
177 | + $statement->execute(); |
|
178 | + |
|
179 | + if ($statement->rowCount() !== 1) { |
|
180 | + throw new OptimisticLockFailedException(); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * @return bool |
|
186 | + */ |
|
187 | + public function isDeleted() |
|
188 | + { |
|
189 | + return ((int)$this->deleted) === 1; |
|
190 | + } |
|
191 | + |
|
192 | + public function getSectionHeader() |
|
193 | + { |
|
194 | + // Hard-coded for future update ability to change this per-template. This has beem moved from being hard-coded |
|
195 | + // directly in the welcome task, and safely permits us to show the header in the welcome template preview |
|
196 | + return "Welcome!"; |
|
197 | + } |
|
198 | + |
|
199 | + public function getBotCodeForWikiSave(string $request, $creator) |
|
200 | + { |
|
201 | + $templateText = $this->getBotCode(); |
|
202 | + |
|
203 | + $templateText = str_replace('$request', $request, $templateText); |
|
204 | + $templateText = str_replace('$creator', $creator, $templateText); |
|
205 | + |
|
206 | + // legacy; these have been removed in Prod for now, but I'm keeping them in case someone follows the |
|
207 | + // instructions in prod prior to deployment. |
|
208 | + $templateText = str_replace('$signature', '~~~~', $templateText); |
|
209 | + $templateText = str_replace('$username', $creator, $templateText); |
|
210 | + |
|
211 | + return $templateText; |
|
212 | + } |
|
213 | + |
|
214 | + public function getDomain(): int |
|
215 | + { |
|
216 | + return $this->domain; |
|
217 | + } |
|
218 | + |
|
219 | + public function setDomain(int $domain): void |
|
220 | + { |
|
221 | + $this->domain = $domain; |
|
222 | + } |
|
223 | 223 | } |