@@ -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 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 |
@@ -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 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 | } |
@@ -15,95 +15,95 @@ |
||
15 | 15 | |
16 | 16 | class UserRole extends DataObject |
17 | 17 | { |
18 | - /** @var int */ |
|
19 | - private $user; |
|
20 | - /** @var string */ |
|
21 | - private $role; |
|
18 | + /** @var int */ |
|
19 | + private $user; |
|
20 | + /** @var string */ |
|
21 | + private $role; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param int $userId |
|
25 | - * @param PdoDatabase $database |
|
26 | - * |
|
27 | - * @return UserRole[] |
|
28 | - */ |
|
29 | - public static function getForUser($userId, PdoDatabase $database) |
|
30 | - { |
|
31 | - $sql = 'SELECT * FROM userrole WHERE user = :user'; |
|
32 | - $statement = $database->prepare($sql); |
|
33 | - $statement->bindValue(':user', $userId); |
|
23 | + /** |
|
24 | + * @param int $userId |
|
25 | + * @param PdoDatabase $database |
|
26 | + * |
|
27 | + * @return UserRole[] |
|
28 | + */ |
|
29 | + public static function getForUser($userId, PdoDatabase $database) |
|
30 | + { |
|
31 | + $sql = 'SELECT * FROM userrole WHERE user = :user'; |
|
32 | + $statement = $database->prepare($sql); |
|
33 | + $statement->bindValue(':user', $userId); |
|
34 | 34 | |
35 | - $statement->execute(); |
|
35 | + $statement->execute(); |
|
36 | 36 | |
37 | - $result = array(); |
|
37 | + $result = array(); |
|
38 | 38 | |
39 | - /** @var Ban $v */ |
|
40 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
41 | - $v->setDatabase($database); |
|
42 | - $result[] = $v; |
|
43 | - } |
|
39 | + /** @var Ban $v */ |
|
40 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, get_called_class()) as $v) { |
|
41 | + $v->setDatabase($database); |
|
42 | + $result[] = $v; |
|
43 | + } |
|
44 | 44 | |
45 | - return $result; |
|
46 | - } |
|
45 | + return $result; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Saves a data object to the database, either updating or inserting a record. |
|
50 | - * |
|
51 | - * @throws Exception |
|
52 | - */ |
|
53 | - public function save() |
|
54 | - { |
|
55 | - if ($this->isNew()) { |
|
56 | - // insert |
|
57 | - $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);' |
|
58 | - ); |
|
59 | - $statement->bindValue(":user", $this->user); |
|
60 | - $statement->bindValue(":role", $this->role); |
|
48 | + /** |
|
49 | + * Saves a data object to the database, either updating or inserting a record. |
|
50 | + * |
|
51 | + * @throws Exception |
|
52 | + */ |
|
53 | + public function save() |
|
54 | + { |
|
55 | + if ($this->isNew()) { |
|
56 | + // insert |
|
57 | + $statement = $this->dbObject->prepare('INSERT INTO `userrole` (user, role) VALUES (:user, :role);' |
|
58 | + ); |
|
59 | + $statement->bindValue(":user", $this->user); |
|
60 | + $statement->bindValue(":role", $this->role); |
|
61 | 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 | - throw new Exception('Updating roles is not available'); |
|
72 | - } |
|
73 | - } |
|
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 | + throw new Exception('Updating roles is not available'); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - #region Properties |
|
75 | + #region Properties |
|
76 | 76 | |
77 | - /** |
|
78 | - * @return int |
|
79 | - */ |
|
80 | - public function getUser() |
|
81 | - { |
|
82 | - return $this->user; |
|
83 | - } |
|
77 | + /** |
|
78 | + * @return int |
|
79 | + */ |
|
80 | + public function getUser() |
|
81 | + { |
|
82 | + return $this->user; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @param int $user |
|
87 | - */ |
|
88 | - public function setUser($user) |
|
89 | - { |
|
90 | - $this->user = $user; |
|
91 | - } |
|
85 | + /** |
|
86 | + * @param int $user |
|
87 | + */ |
|
88 | + public function setUser($user) |
|
89 | + { |
|
90 | + $this->user = $user; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function getRole() |
|
97 | - { |
|
98 | - return $this->role; |
|
99 | - } |
|
93 | + /** |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function getRole() |
|
97 | + { |
|
98 | + return $this->role; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * @param string $role |
|
103 | - */ |
|
104 | - public function setRole($role) |
|
105 | - { |
|
106 | - $this->role = $role; |
|
107 | - } |
|
108 | - #endregion |
|
101 | + /** |
|
102 | + * @param string $role |
|
103 | + */ |
|
104 | + public function setRole($role) |
|
105 | + { |
|
106 | + $this->role = $role; |
|
107 | + } |
|
108 | + #endregion |
|
109 | 109 | } |
@@ -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 | } |
@@ -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 | } |
@@ -22,73 +22,73 @@ |
||
22 | 22 | */ |
23 | 23 | class Notification extends DataObject |
24 | 24 | { |
25 | - private $date; |
|
26 | - private $type; |
|
27 | - private $text; |
|
25 | + private $date; |
|
26 | + private $type; |
|
27 | + private $text; |
|
28 | 28 | |
29 | - public function delete() |
|
30 | - { |
|
31 | - throw new Exception("You shouldn't be doing this..."); |
|
32 | - } |
|
29 | + public function delete() |
|
30 | + { |
|
31 | + throw new Exception("You shouldn't be doing this..."); |
|
32 | + } |
|
33 | 33 | |
34 | - public function save() |
|
35 | - { |
|
36 | - if ($this->isNew()) { |
|
37 | - // insert |
|
38 | - $statement = $this->dbObject->prepare("INSERT INTO notification ( type, text ) VALUES ( :type, :text );"); |
|
39 | - $statement->bindValue(":type", $this->type); |
|
40 | - $statement->bindValue(":text", $this->text); |
|
34 | + public function save() |
|
35 | + { |
|
36 | + if ($this->isNew()) { |
|
37 | + // insert |
|
38 | + $statement = $this->dbObject->prepare("INSERT INTO notification ( type, text ) VALUES ( :type, :text );"); |
|
39 | + $statement->bindValue(":type", $this->type); |
|
40 | + $statement->bindValue(":text", $this->text); |
|
41 | 41 | |
42 | - if ($statement->execute()) { |
|
43 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
44 | - } |
|
45 | - else { |
|
46 | - throw new Exception($statement->errorInfo()); |
|
47 | - } |
|
48 | - } |
|
49 | - else { |
|
50 | - throw new Exception("You shouldn't be doing this..."); |
|
51 | - } |
|
52 | - } |
|
42 | + if ($statement->execute()) { |
|
43 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
44 | + } |
|
45 | + else { |
|
46 | + throw new Exception($statement->errorInfo()); |
|
47 | + } |
|
48 | + } |
|
49 | + else { |
|
50 | + throw new Exception("You shouldn't be doing this..."); |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - public function getDate() |
|
55 | - { |
|
56 | - return new DateTimeImmutable($this->date); |
|
57 | - } |
|
54 | + public function getDate() |
|
55 | + { |
|
56 | + return new DateTimeImmutable($this->date); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return int |
|
61 | - */ |
|
62 | - public function getType() |
|
63 | - { |
|
64 | - return $this->type; |
|
65 | - } |
|
59 | + /** |
|
60 | + * @return int |
|
61 | + */ |
|
62 | + public function getType() |
|
63 | + { |
|
64 | + return $this->type; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @return string |
|
69 | - */ |
|
70 | - public function getText() |
|
71 | - { |
|
72 | - return $this->text; |
|
73 | - } |
|
67 | + /** |
|
68 | + * @return string |
|
69 | + */ |
|
70 | + public function getText() |
|
71 | + { |
|
72 | + return $this->text; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Summary of setType |
|
77 | - * |
|
78 | - * @param int $type |
|
79 | - */ |
|
80 | - public function setType($type) |
|
81 | - { |
|
82 | - $this->type = $type; |
|
83 | - } |
|
75 | + /** |
|
76 | + * Summary of setType |
|
77 | + * |
|
78 | + * @param int $type |
|
79 | + */ |
|
80 | + public function setType($type) |
|
81 | + { |
|
82 | + $this->type = $type; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Summary of setText |
|
87 | - * |
|
88 | - * @param string $text |
|
89 | - */ |
|
90 | - public function setText($text) |
|
91 | - { |
|
92 | - $this->text = $text; |
|
93 | - } |
|
85 | + /** |
|
86 | + * Summary of setText |
|
87 | + * |
|
88 | + * @param string $text |
|
89 | + */ |
|
90 | + public function setText($text) |
|
91 | + { |
|
92 | + $this->text = $text; |
|
93 | + } |
|
94 | 94 | } |
@@ -41,12 +41,10 @@ |
||
41 | 41 | |
42 | 42 | if ($statement->execute()) { |
43 | 43 | $this->id = (int)$this->dbObject->lastInsertId(); |
44 | - } |
|
45 | - else { |
|
44 | + } else { |
|
46 | 45 | throw new Exception($statement->errorInfo()); |
47 | 46 | } |
48 | - } |
|
49 | - else { |
|
47 | + } else { |
|
50 | 48 | throw new Exception("You shouldn't be doing this..."); |
51 | 49 | } |
52 | 50 | } |
@@ -408,7 +408,7 @@ |
||
408 | 408 | . '|' . $this->forwardedip // } private data not known to those without access |
409 | 409 | . '|' . $this->useragent // } |
410 | 410 | . '|' . $this->email // } |
411 | - . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
411 | + . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
412 | 412 | |
413 | 413 | return hash('sha256', $data); |
414 | 414 | } |
@@ -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 |
@@ -21,31 +21,31 @@ 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 $comment; |
|
29 | - private $status = "Open"; |
|
30 | - private $date; |
|
31 | - private $emailsent = 0; |
|
32 | - private $emailconfirm; |
|
33 | - /** @var int|null */ |
|
34 | - private $reserved = null; |
|
35 | - private $useragent; |
|
36 | - private $forwardedip; |
|
37 | - private $hasComments = false; |
|
38 | - private $hasCommentsResolved = false; |
|
39 | - |
|
40 | - /** |
|
41 | - * @throws Exception |
|
42 | - * @throws OptimisticLockFailedException |
|
43 | - */ |
|
44 | - public function save() |
|
45 | - { |
|
46 | - if ($this->isNew()) { |
|
47 | - // insert |
|
48 | - $statement = $this->dbObject->prepare(<<<SQL |
|
24 | + private $email; |
|
25 | + private $ip; |
|
26 | + private $name; |
|
27 | + /** @var string|null */ |
|
28 | + private $comment; |
|
29 | + private $status = "Open"; |
|
30 | + private $date; |
|
31 | + private $emailsent = 0; |
|
32 | + private $emailconfirm; |
|
33 | + /** @var int|null */ |
|
34 | + private $reserved = null; |
|
35 | + private $useragent; |
|
36 | + private $forwardedip; |
|
37 | + private $hasComments = false; |
|
38 | + private $hasCommentsResolved = false; |
|
39 | + |
|
40 | + /** |
|
41 | + * @throws Exception |
|
42 | + * @throws OptimisticLockFailedException |
|
43 | + */ |
|
44 | + public function save() |
|
45 | + { |
|
46 | + if ($this->isNew()) { |
|
47 | + // insert |
|
48 | + $statement = $this->dbObject->prepare(<<<SQL |
|
49 | 49 | INSERT INTO `request` ( |
50 | 50 | email, ip, name, comment, status, date, emailsent, |
51 | 51 | emailconfirm, reserved, useragent, forwardedip |
@@ -54,28 +54,28 @@ discard block |
||
54 | 54 | :emailconfirm, :reserved, :useragent, :forwardedip |
55 | 55 | ); |
56 | 56 | SQL |
57 | - ); |
|
58 | - $statement->bindValue(':email', $this->email); |
|
59 | - $statement->bindValue(':ip', $this->ip); |
|
60 | - $statement->bindValue(':name', $this->name); |
|
61 | - $statement->bindValue(':comment', $this->comment); |
|
62 | - $statement->bindValue(':status', $this->status); |
|
63 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
64 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
65 | - $statement->bindValue(':reserved', $this->reserved); |
|
66 | - $statement->bindValue(':useragent', $this->useragent); |
|
67 | - $statement->bindValue(':forwardedip', $this->forwardedip); |
|
68 | - |
|
69 | - if ($statement->execute()) { |
|
70 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
71 | - } |
|
72 | - else { |
|
73 | - throw new Exception($statement->errorInfo()); |
|
74 | - } |
|
75 | - } |
|
76 | - else { |
|
77 | - // update |
|
78 | - $statement = $this->dbObject->prepare(<<<SQL |
|
57 | + ); |
|
58 | + $statement->bindValue(':email', $this->email); |
|
59 | + $statement->bindValue(':ip', $this->ip); |
|
60 | + $statement->bindValue(':name', $this->name); |
|
61 | + $statement->bindValue(':comment', $this->comment); |
|
62 | + $statement->bindValue(':status', $this->status); |
|
63 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
64 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
65 | + $statement->bindValue(':reserved', $this->reserved); |
|
66 | + $statement->bindValue(':useragent', $this->useragent); |
|
67 | + $statement->bindValue(':forwardedip', $this->forwardedip); |
|
68 | + |
|
69 | + if ($statement->execute()) { |
|
70 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
71 | + } |
|
72 | + else { |
|
73 | + throw new Exception($statement->errorInfo()); |
|
74 | + } |
|
75 | + } |
|
76 | + else { |
|
77 | + // update |
|
78 | + $statement = $this->dbObject->prepare(<<<SQL |
|
79 | 79 | UPDATE `request` SET |
80 | 80 | status = :status, |
81 | 81 | emailsent = :emailsent, |
@@ -84,163 +84,163 @@ discard block |
||
84 | 84 | updateversion = updateversion + 1 |
85 | 85 | WHERE id = :id AND updateversion = :updateversion; |
86 | 86 | SQL |
87 | - ); |
|
88 | - |
|
89 | - $statement->bindValue(':id', $this->id); |
|
90 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
91 | - |
|
92 | - $statement->bindValue(':status', $this->status); |
|
93 | - $statement->bindValue(':emailsent', $this->emailsent); |
|
94 | - $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
95 | - $statement->bindValue(':reserved', $this->reserved); |
|
96 | - |
|
97 | - if (!$statement->execute()) { |
|
98 | - throw new Exception($statement->errorInfo()); |
|
99 | - } |
|
100 | - |
|
101 | - if ($statement->rowCount() !== 1) { |
|
102 | - throw new OptimisticLockFailedException(); |
|
103 | - } |
|
104 | - |
|
105 | - $this->updateversion++; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function getIp() |
|
113 | - { |
|
114 | - return $this->ip; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $ip |
|
119 | - */ |
|
120 | - public function setIp($ip) |
|
121 | - { |
|
122 | - $this->ip = $ip; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function getName() |
|
129 | - { |
|
130 | - return $this->name; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param string $name |
|
135 | - */ |
|
136 | - public function setName($name) |
|
137 | - { |
|
138 | - $this->name = $name; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return string|null |
|
143 | - */ |
|
144 | - public function getComment() |
|
145 | - { |
|
146 | - return $this->comment; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @param string $comment |
|
151 | - */ |
|
152 | - public function setComment($comment) |
|
153 | - { |
|
154 | - $this->comment = $comment; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function getStatus() |
|
161 | - { |
|
162 | - return $this->status; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @param string $status |
|
167 | - */ |
|
168 | - public function setStatus($status) |
|
169 | - { |
|
170 | - $this->status = $status; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Returns the time the request was first submitted |
|
175 | - * |
|
176 | - * @return DateTimeImmutable |
|
177 | - */ |
|
178 | - public function getDate() |
|
179 | - { |
|
180 | - return new DateTimeImmutable($this->date); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @return bool |
|
185 | - */ |
|
186 | - public function getEmailSent() |
|
187 | - { |
|
188 | - return $this->emailsent == "1"; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param bool $emailSent |
|
193 | - */ |
|
194 | - public function setEmailSent($emailSent) |
|
195 | - { |
|
196 | - $this->emailsent = $emailSent ? 1 : 0; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @return int|null |
|
201 | - */ |
|
202 | - public function getReserved() |
|
203 | - { |
|
204 | - return $this->reserved; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @param int|null $reserved |
|
209 | - */ |
|
210 | - public function setReserved($reserved) |
|
211 | - { |
|
212 | - $this->reserved = $reserved; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @return string |
|
217 | - */ |
|
218 | - public function getUserAgent() |
|
219 | - { |
|
220 | - return $this->useragent; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param string $useragent |
|
225 | - */ |
|
226 | - public function setUserAgent($useragent) |
|
227 | - { |
|
228 | - $this->useragent = $useragent; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * @return string|null |
|
233 | - */ |
|
234 | - public function getForwardedIp() |
|
235 | - { |
|
236 | - return $this->forwardedip; |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * @param string|null $forwardedip |
|
241 | - */ |
|
242 | - public function setForwardedIp($forwardedip) |
|
243 | - { |
|
87 | + ); |
|
88 | + |
|
89 | + $statement->bindValue(':id', $this->id); |
|
90 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
91 | + |
|
92 | + $statement->bindValue(':status', $this->status); |
|
93 | + $statement->bindValue(':emailsent', $this->emailsent); |
|
94 | + $statement->bindValue(':emailconfirm', $this->emailconfirm); |
|
95 | + $statement->bindValue(':reserved', $this->reserved); |
|
96 | + |
|
97 | + if (!$statement->execute()) { |
|
98 | + throw new Exception($statement->errorInfo()); |
|
99 | + } |
|
100 | + |
|
101 | + if ($statement->rowCount() !== 1) { |
|
102 | + throw new OptimisticLockFailedException(); |
|
103 | + } |
|
104 | + |
|
105 | + $this->updateversion++; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function getIp() |
|
113 | + { |
|
114 | + return $this->ip; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $ip |
|
119 | + */ |
|
120 | + public function setIp($ip) |
|
121 | + { |
|
122 | + $this->ip = $ip; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function getName() |
|
129 | + { |
|
130 | + return $this->name; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param string $name |
|
135 | + */ |
|
136 | + public function setName($name) |
|
137 | + { |
|
138 | + $this->name = $name; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return string|null |
|
143 | + */ |
|
144 | + public function getComment() |
|
145 | + { |
|
146 | + return $this->comment; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @param string $comment |
|
151 | + */ |
|
152 | + public function setComment($comment) |
|
153 | + { |
|
154 | + $this->comment = $comment; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function getStatus() |
|
161 | + { |
|
162 | + return $this->status; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @param string $status |
|
167 | + */ |
|
168 | + public function setStatus($status) |
|
169 | + { |
|
170 | + $this->status = $status; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Returns the time the request was first submitted |
|
175 | + * |
|
176 | + * @return DateTimeImmutable |
|
177 | + */ |
|
178 | + public function getDate() |
|
179 | + { |
|
180 | + return new DateTimeImmutable($this->date); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | + public function getEmailSent() |
|
187 | + { |
|
188 | + return $this->emailsent == "1"; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param bool $emailSent |
|
193 | + */ |
|
194 | + public function setEmailSent($emailSent) |
|
195 | + { |
|
196 | + $this->emailsent = $emailSent ? 1 : 0; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @return int|null |
|
201 | + */ |
|
202 | + public function getReserved() |
|
203 | + { |
|
204 | + return $this->reserved; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @param int|null $reserved |
|
209 | + */ |
|
210 | + public function setReserved($reserved) |
|
211 | + { |
|
212 | + $this->reserved = $reserved; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @return string |
|
217 | + */ |
|
218 | + public function getUserAgent() |
|
219 | + { |
|
220 | + return $this->useragent; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param string $useragent |
|
225 | + */ |
|
226 | + public function setUserAgent($useragent) |
|
227 | + { |
|
228 | + $this->useragent = $useragent; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * @return string|null |
|
233 | + */ |
|
234 | + public function getForwardedIp() |
|
235 | + { |
|
236 | + return $this->forwardedip; |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * @param string|null $forwardedip |
|
241 | + */ |
|
242 | + public function setForwardedIp($forwardedip) |
|
243 | + { |
|
244 | 244 | // Verify that the XFF chain only contains valid IP addresses, and silently discard anything that isn't. |
245 | 245 | |
246 | 246 | $xff = explode(',', $forwardedip); |
@@ -254,83 +254,83 @@ discard block |
||
254 | 254 | } |
255 | 255 | |
256 | 256 | $this->forwardedip = implode(", ", $valid); |
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @return bool |
|
261 | - */ |
|
262 | - public function hasComments() |
|
263 | - { |
|
264 | - if ($this->hasCommentsResolved) { |
|
265 | - return $this->hasComments; |
|
266 | - } |
|
267 | - |
|
268 | - if ($this->comment != "") { |
|
269 | - $this->hasComments = true; |
|
270 | - $this->hasCommentsResolved = true; |
|
271 | - |
|
272 | - return true; |
|
273 | - } |
|
274 | - |
|
275 | - $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
276 | - $commentsQuery->bindValue(":id", $this->id); |
|
277 | - |
|
278 | - $commentsQuery->execute(); |
|
279 | - |
|
280 | - $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
281 | - $this->hasCommentsResolved = true; |
|
282 | - |
|
283 | - return $this->hasComments; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @return string |
|
288 | - */ |
|
289 | - public function getEmailConfirm() |
|
290 | - { |
|
291 | - return $this->emailconfirm; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $emailconfirm |
|
296 | - */ |
|
297 | - public function setEmailConfirm($emailconfirm) |
|
298 | - { |
|
299 | - $this->emailconfirm = $emailconfirm; |
|
300 | - } |
|
301 | - |
|
302 | - public function generateEmailConfirmationHash() |
|
303 | - { |
|
304 | - $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * @return string|null |
|
309 | - */ |
|
310 | - public function getEmail() |
|
311 | - { |
|
312 | - return $this->email; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * @param string|null $email |
|
317 | - */ |
|
318 | - public function setEmail($email) |
|
319 | - { |
|
320 | - $this->email = $email; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @return string |
|
325 | - * @throws Exception |
|
326 | - */ |
|
327 | - public function getClosureReason() |
|
328 | - { |
|
329 | - if ($this->status != 'Closed') { |
|
330 | - throw new Exception("Can't get closure reason for open request."); |
|
331 | - } |
|
332 | - |
|
333 | - $statement = $this->dbObject->prepare(<<<SQL |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @return bool |
|
261 | + */ |
|
262 | + public function hasComments() |
|
263 | + { |
|
264 | + if ($this->hasCommentsResolved) { |
|
265 | + return $this->hasComments; |
|
266 | + } |
|
267 | + |
|
268 | + if ($this->comment != "") { |
|
269 | + $this->hasComments = true; |
|
270 | + $this->hasCommentsResolved = true; |
|
271 | + |
|
272 | + return true; |
|
273 | + } |
|
274 | + |
|
275 | + $commentsQuery = $this->dbObject->prepare("SELECT COUNT(*) AS num FROM comment WHERE request = :id;"); |
|
276 | + $commentsQuery->bindValue(":id", $this->id); |
|
277 | + |
|
278 | + $commentsQuery->execute(); |
|
279 | + |
|
280 | + $this->hasComments = ($commentsQuery->fetchColumn() != 0); |
|
281 | + $this->hasCommentsResolved = true; |
|
282 | + |
|
283 | + return $this->hasComments; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @return string |
|
288 | + */ |
|
289 | + public function getEmailConfirm() |
|
290 | + { |
|
291 | + return $this->emailconfirm; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $emailconfirm |
|
296 | + */ |
|
297 | + public function setEmailConfirm($emailconfirm) |
|
298 | + { |
|
299 | + $this->emailconfirm = $emailconfirm; |
|
300 | + } |
|
301 | + |
|
302 | + public function generateEmailConfirmationHash() |
|
303 | + { |
|
304 | + $this->emailconfirm = bin2hex(openssl_random_pseudo_bytes(16)); |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * @return string|null |
|
309 | + */ |
|
310 | + public function getEmail() |
|
311 | + { |
|
312 | + return $this->email; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * @param string|null $email |
|
317 | + */ |
|
318 | + public function setEmail($email) |
|
319 | + { |
|
320 | + $this->email = $email; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @return string |
|
325 | + * @throws Exception |
|
326 | + */ |
|
327 | + public function getClosureReason() |
|
328 | + { |
|
329 | + if ($this->status != 'Closed') { |
|
330 | + throw new Exception("Can't get closure reason for open request."); |
|
331 | + } |
|
332 | + |
|
333 | + $statement = $this->dbObject->prepare(<<<SQL |
|
334 | 334 | SELECT closes.mail_desc |
335 | 335 | FROM log |
336 | 336 | INNER JOIN closes ON log.action = closes.closes |
@@ -340,25 +340,25 @@ discard block |
||
340 | 340 | ORDER BY log.timestamp DESC |
341 | 341 | LIMIT 1; |
342 | 342 | SQL |
343 | - ); |
|
344 | - |
|
345 | - $statement->bindValue(":requestId", $this->id); |
|
346 | - $statement->execute(); |
|
347 | - $reason = $statement->fetchColumn(); |
|
348 | - |
|
349 | - return $reason; |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Gets a value indicating whether the request was closed as created or not. |
|
354 | - */ |
|
355 | - public function getWasCreated() |
|
356 | - { |
|
357 | - if ($this->status != 'Closed') { |
|
358 | - throw new Exception("Can't get closure reason for open request."); |
|
359 | - } |
|
343 | + ); |
|
344 | + |
|
345 | + $statement->bindValue(":requestId", $this->id); |
|
346 | + $statement->execute(); |
|
347 | + $reason = $statement->fetchColumn(); |
|
348 | + |
|
349 | + return $reason; |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Gets a value indicating whether the request was closed as created or not. |
|
354 | + */ |
|
355 | + public function getWasCreated() |
|
356 | + { |
|
357 | + if ($this->status != 'Closed') { |
|
358 | + throw new Exception("Can't get closure reason for open request."); |
|
359 | + } |
|
360 | 360 | |
361 | - $statement = $this->dbObject->prepare(<<<SQL |
|
361 | + $statement = $this->dbObject->prepare(<<<SQL |
|
362 | 362 | SELECT emailtemplate.oncreated, log.action |
363 | 363 | FROM log |
364 | 364 | LEFT JOIN emailtemplate ON CONCAT('Closed ', emailtemplate.id) = log.action |
@@ -368,60 +368,60 @@ discard block |
||
368 | 368 | ORDER BY log.timestamp DESC |
369 | 369 | LIMIT 1; |
370 | 370 | SQL |
371 | - ); |
|
372 | - |
|
373 | - $statement->bindValue(":requestId", $this->id); |
|
374 | - $statement->execute(); |
|
375 | - $onCreated = $statement->fetchColumn(0); |
|
376 | - $logAction = $statement->fetchColumn(1); |
|
377 | - $statement->closeCursor(); |
|
378 | - |
|
379 | - if ($onCreated === null) { |
|
380 | - return $logAction === "Closed custom-y"; |
|
381 | - } |
|
382 | - |
|
383 | - return (bool)$onCreated; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @return DateTime |
|
388 | - */ |
|
389 | - public function getClosureDate() |
|
390 | - { |
|
391 | - $logQuery = $this->dbObject->prepare(<<<SQL |
|
371 | + ); |
|
372 | + |
|
373 | + $statement->bindValue(":requestId", $this->id); |
|
374 | + $statement->execute(); |
|
375 | + $onCreated = $statement->fetchColumn(0); |
|
376 | + $logAction = $statement->fetchColumn(1); |
|
377 | + $statement->closeCursor(); |
|
378 | + |
|
379 | + if ($onCreated === null) { |
|
380 | + return $logAction === "Closed custom-y"; |
|
381 | + } |
|
382 | + |
|
383 | + return (bool)$onCreated; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @return DateTime |
|
388 | + */ |
|
389 | + public function getClosureDate() |
|
390 | + { |
|
391 | + $logQuery = $this->dbObject->prepare(<<<SQL |
|
392 | 392 | SELECT timestamp FROM log |
393 | 393 | WHERE objectid = :request AND objecttype = 'Request' AND action LIKE 'Closed%' |
394 | 394 | ORDER BY timestamp DESC LIMIT 1; |
395 | 395 | SQL |
396 | - ); |
|
397 | - $logQuery->bindValue(":request", $this->getId()); |
|
398 | - $logQuery->execute(); |
|
399 | - $logTime = $logQuery->fetchColumn(); |
|
400 | - $logQuery->closeCursor(); |
|
401 | - |
|
402 | - return new DateTime($logTime); |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
407 | - * data to unauthorised* users. |
|
408 | - * |
|
409 | - * *:Not tool admins, check users, or the reserving user. |
|
410 | - * |
|
411 | - * @return string |
|
412 | - * |
|
413 | - * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
414 | - * Maybe depend on the last logged action timestamp? |
|
415 | - */ |
|
416 | - public function getRevealHash() |
|
417 | - { |
|
418 | - $data = $this->id // unique per request |
|
419 | - . '|' . $this->ip // } |
|
420 | - . '|' . $this->forwardedip // } private data not known to those without access |
|
421 | - . '|' . $this->useragent // } |
|
422 | - . '|' . $this->email // } |
|
423 | - . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
424 | - |
|
425 | - return hash('sha256', $data); |
|
426 | - } |
|
396 | + ); |
|
397 | + $logQuery->bindValue(":request", $this->getId()); |
|
398 | + $logQuery->execute(); |
|
399 | + $logTime = $logQuery->fetchColumn(); |
|
400 | + $logQuery->closeCursor(); |
|
401 | + |
|
402 | + return new DateTime($logTime); |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * Returns a hash based on data within this request which can be generated easily from the data to be used to reveal |
|
407 | + * data to unauthorised* users. |
|
408 | + * |
|
409 | + * *:Not tool admins, check users, or the reserving user. |
|
410 | + * |
|
411 | + * @return string |
|
412 | + * |
|
413 | + * @todo future work to make invalidation better. Possibly move to the database and invalidate on relevant events? |
|
414 | + * Maybe depend on the last logged action timestamp? |
|
415 | + */ |
|
416 | + public function getRevealHash() |
|
417 | + { |
|
418 | + $data = $this->id // unique per request |
|
419 | + . '|' . $this->ip // } |
|
420 | + . '|' . $this->forwardedip // } private data not known to those without access |
|
421 | + . '|' . $this->useragent // } |
|
422 | + . '|' . $this->email // } |
|
423 | + . '|' . $this->status; // to rudimentarily invalidate the token on status change |
|
424 | + |
|
425 | + return hash('sha256', $data); |
|
426 | + } |
|
427 | 427 | } |
@@ -183,12 +183,10 @@ |
||
183 | 183 | |
184 | 184 | if ($statement->execute()) { |
185 | 185 | $this->id = (int)$this->dbObject->lastInsertId(); |
186 | - } |
|
187 | - else { |
|
186 | + } else { |
|
188 | 187 | throw new Exception($statement->errorInfo()); |
189 | 188 | } |
190 | - } |
|
191 | - else { |
|
189 | + } else { |
|
192 | 190 | // update |
193 | 191 | $statement = $this->dbObject->prepare(<<<SQL |
194 | 192 | UPDATE `emailtemplate` |
@@ -21,176 +21,176 @@ discard block |
||
21 | 21 | */ |
22 | 22 | class EmailTemplate extends DataObject |
23 | 23 | { |
24 | - /** Note, also used in template-table.tpl */ |
|
25 | - const CREATED = "created"; |
|
26 | - /** Note, also used in template-table.tpl */ |
|
27 | - const NOT_CREATED = "not created"; |
|
28 | - /** Note, also used in template-table.tpl */ |
|
29 | - const NONE = null; |
|
30 | - /** @var string the name of the template */ |
|
31 | - private $name; |
|
32 | - private $text; |
|
33 | - /** @var string|null */ |
|
34 | - private $jsquestion; |
|
35 | - private $active = 1; |
|
36 | - private $preloadonly = 0; |
|
37 | - private $defaultaction = self::NOT_CREATED; |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets active non-preload templates |
|
41 | - * |
|
42 | - * @param string $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED) |
|
43 | - * @param PdoDatabase $database |
|
44 | - * |
|
45 | - * @return array|false |
|
46 | - */ |
|
47 | - public static function getActiveTemplates($defaultAction, PdoDatabase $database) |
|
48 | - { |
|
49 | - global $createdid; |
|
50 | - |
|
51 | - $statement = $database->prepare(<<<SQL |
|
24 | + /** Note, also used in template-table.tpl */ |
|
25 | + const CREATED = "created"; |
|
26 | + /** Note, also used in template-table.tpl */ |
|
27 | + const NOT_CREATED = "not created"; |
|
28 | + /** Note, also used in template-table.tpl */ |
|
29 | + const NONE = null; |
|
30 | + /** @var string the name of the template */ |
|
31 | + private $name; |
|
32 | + private $text; |
|
33 | + /** @var string|null */ |
|
34 | + private $jsquestion; |
|
35 | + private $active = 1; |
|
36 | + private $preloadonly = 0; |
|
37 | + private $defaultaction = self::NOT_CREATED; |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets active non-preload templates |
|
41 | + * |
|
42 | + * @param string $defaultAction Default action to take (EmailTemplate::CREATED or EmailTemplate::NOT_CREATED) |
|
43 | + * @param PdoDatabase $database |
|
44 | + * |
|
45 | + * @return array|false |
|
46 | + */ |
|
47 | + public static function getActiveTemplates($defaultAction, PdoDatabase $database) |
|
48 | + { |
|
49 | + global $createdid; |
|
50 | + |
|
51 | + $statement = $database->prepare(<<<SQL |
|
52 | 52 | SELECT * FROM `emailtemplate` |
53 | 53 | WHERE defaultaction = :forcreated AND active = 1 AND preloadonly = 0 AND id != :createdid; |
54 | 54 | SQL |
55 | - ); |
|
56 | - $statement->bindValue(":createdid", $createdid); |
|
57 | - $statement->bindValue(":forcreated", $defaultAction); |
|
58 | - |
|
59 | - $statement->execute(); |
|
60 | - |
|
61 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
62 | - |
|
63 | - /** @var EmailTemplate $t */ |
|
64 | - foreach ($resultObject as $t) { |
|
65 | - $t->setDatabase($database); |
|
66 | - } |
|
67 | - |
|
68 | - return $resultObject; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Gets active non-preload and preload templates, optionally filtered by the default action. |
|
73 | - * |
|
74 | - * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED, |
|
75 | - * EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to |
|
76 | - * just get everything. |
|
77 | - * @param PdoDatabase $database |
|
78 | - * |
|
79 | - * @return array|false |
|
80 | - */ |
|
81 | - public static function getAllActiveTemplates($defaultAction, PdoDatabase $database) |
|
82 | - { |
|
83 | - $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;"); |
|
84 | - |
|
85 | - if ($defaultAction === false) { |
|
86 | - $statement = $database->prepare( |
|
87 | - "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;"); |
|
88 | - } |
|
89 | - |
|
90 | - if ($defaultAction === null) { |
|
91 | - $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 1;"); |
|
92 | - } |
|
93 | - |
|
94 | - $statement->bindValue(":forcreated", $defaultAction); |
|
95 | - |
|
96 | - $statement->execute(); |
|
97 | - |
|
98 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
99 | - |
|
100 | - /** @var EmailTemplate $t */ |
|
101 | - foreach ($resultObject as $t) { |
|
102 | - $t->setDatabase($database); |
|
103 | - } |
|
104 | - |
|
105 | - return $resultObject; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets all the unactive templates |
|
110 | - * |
|
111 | - * @param PdoDatabase $database |
|
112 | - * |
|
113 | - * @return array |
|
114 | - */ |
|
115 | - public static function getAllInactiveTemplates(PdoDatabase $database) |
|
116 | - { |
|
117 | - $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 0;"); |
|
118 | - $statement->execute(); |
|
119 | - |
|
120 | - $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
121 | - |
|
122 | - /** @var EmailTemplate $t */ |
|
123 | - foreach ($resultObject as $t) { |
|
124 | - $t->setDatabase($database); |
|
125 | - } |
|
126 | - |
|
127 | - return $resultObject; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $name |
|
132 | - * @param PdoDatabase $database |
|
133 | - * |
|
134 | - * @return EmailTemplate|false |
|
135 | - */ |
|
136 | - public static function getByName($name, PdoDatabase $database) |
|
137 | - { |
|
138 | - $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;"); |
|
139 | - $statement->bindValue(":name", $name); |
|
140 | - |
|
141 | - $statement->execute(); |
|
142 | - |
|
143 | - $resultObject = $statement->fetchObject(get_called_class()); |
|
144 | - |
|
145 | - if ($resultObject != false) { |
|
146 | - $resultObject->setDatabase($database); |
|
147 | - } |
|
148 | - |
|
149 | - return $resultObject; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @return EmailTemplate |
|
154 | - */ |
|
155 | - public static function getDroppedTemplate() |
|
156 | - { |
|
157 | - $t = new EmailTemplate(); |
|
158 | - $t->id = 0; |
|
159 | - $t->active = 1; |
|
160 | - $t->name = 'Dropped'; |
|
161 | - |
|
162 | - return $t; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * @throws Exception |
|
167 | - */ |
|
168 | - public function save() |
|
169 | - { |
|
170 | - if ($this->isNew()) { |
|
171 | - // insert |
|
172 | - $statement = $this->dbObject->prepare(<<<SQL |
|
55 | + ); |
|
56 | + $statement->bindValue(":createdid", $createdid); |
|
57 | + $statement->bindValue(":forcreated", $defaultAction); |
|
58 | + |
|
59 | + $statement->execute(); |
|
60 | + |
|
61 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
62 | + |
|
63 | + /** @var EmailTemplate $t */ |
|
64 | + foreach ($resultObject as $t) { |
|
65 | + $t->setDatabase($database); |
|
66 | + } |
|
67 | + |
|
68 | + return $resultObject; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Gets active non-preload and preload templates, optionally filtered by the default action. |
|
73 | + * |
|
74 | + * @param null|bool|string $defaultAction Default action to take (EmailTemplate::CREATED, |
|
75 | + * EmailTemplate::NOT_CREATED, or EmailTemplate::NONE), or optionally null to |
|
76 | + * just get everything. |
|
77 | + * @param PdoDatabase $database |
|
78 | + * |
|
79 | + * @return array|false |
|
80 | + */ |
|
81 | + public static function getAllActiveTemplates($defaultAction, PdoDatabase $database) |
|
82 | + { |
|
83 | + $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE defaultaction = :forcreated AND active = 1;"); |
|
84 | + |
|
85 | + if ($defaultAction === false) { |
|
86 | + $statement = $database->prepare( |
|
87 | + "SELECT * FROM `emailtemplate` WHERE defaultaction NOT IN ('created', 'not created') AND active = 1;"); |
|
88 | + } |
|
89 | + |
|
90 | + if ($defaultAction === null) { |
|
91 | + $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 1;"); |
|
92 | + } |
|
93 | + |
|
94 | + $statement->bindValue(":forcreated", $defaultAction); |
|
95 | + |
|
96 | + $statement->execute(); |
|
97 | + |
|
98 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
99 | + |
|
100 | + /** @var EmailTemplate $t */ |
|
101 | + foreach ($resultObject as $t) { |
|
102 | + $t->setDatabase($database); |
|
103 | + } |
|
104 | + |
|
105 | + return $resultObject; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets all the unactive templates |
|
110 | + * |
|
111 | + * @param PdoDatabase $database |
|
112 | + * |
|
113 | + * @return array |
|
114 | + */ |
|
115 | + public static function getAllInactiveTemplates(PdoDatabase $database) |
|
116 | + { |
|
117 | + $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE active = 0;"); |
|
118 | + $statement->execute(); |
|
119 | + |
|
120 | + $resultObject = $statement->fetchAll(PDO::FETCH_CLASS, get_called_class()); |
|
121 | + |
|
122 | + /** @var EmailTemplate $t */ |
|
123 | + foreach ($resultObject as $t) { |
|
124 | + $t->setDatabase($database); |
|
125 | + } |
|
126 | + |
|
127 | + return $resultObject; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $name |
|
132 | + * @param PdoDatabase $database |
|
133 | + * |
|
134 | + * @return EmailTemplate|false |
|
135 | + */ |
|
136 | + public static function getByName($name, PdoDatabase $database) |
|
137 | + { |
|
138 | + $statement = $database->prepare("SELECT * FROM `emailtemplate` WHERE name = :name LIMIT 1;"); |
|
139 | + $statement->bindValue(":name", $name); |
|
140 | + |
|
141 | + $statement->execute(); |
|
142 | + |
|
143 | + $resultObject = $statement->fetchObject(get_called_class()); |
|
144 | + |
|
145 | + if ($resultObject != false) { |
|
146 | + $resultObject->setDatabase($database); |
|
147 | + } |
|
148 | + |
|
149 | + return $resultObject; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @return EmailTemplate |
|
154 | + */ |
|
155 | + public static function getDroppedTemplate() |
|
156 | + { |
|
157 | + $t = new EmailTemplate(); |
|
158 | + $t->id = 0; |
|
159 | + $t->active = 1; |
|
160 | + $t->name = 'Dropped'; |
|
161 | + |
|
162 | + return $t; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * @throws Exception |
|
167 | + */ |
|
168 | + public function save() |
|
169 | + { |
|
170 | + if ($this->isNew()) { |
|
171 | + // insert |
|
172 | + $statement = $this->dbObject->prepare(<<<SQL |
|
173 | 173 | INSERT INTO `emailtemplate` (name, text, jsquestion, defaultaction, active, preloadonly) |
174 | 174 | VALUES (:name, :text, :jsquestion, :defaultaction, :active, :preloadonly); |
175 | 175 | SQL |
176 | - ); |
|
177 | - $statement->bindValue(":name", $this->name); |
|
178 | - $statement->bindValue(":text", $this->text); |
|
179 | - $statement->bindValue(":jsquestion", $this->jsquestion); |
|
180 | - $statement->bindValue(":defaultaction", $this->defaultaction); |
|
181 | - $statement->bindValue(":active", $this->active); |
|
182 | - $statement->bindValue(":preloadonly", $this->preloadonly); |
|
183 | - |
|
184 | - if ($statement->execute()) { |
|
185 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
186 | - } |
|
187 | - else { |
|
188 | - throw new Exception($statement->errorInfo()); |
|
189 | - } |
|
190 | - } |
|
191 | - else { |
|
192 | - // update |
|
193 | - $statement = $this->dbObject->prepare(<<<SQL |
|
176 | + ); |
|
177 | + $statement->bindValue(":name", $this->name); |
|
178 | + $statement->bindValue(":text", $this->text); |
|
179 | + $statement->bindValue(":jsquestion", $this->jsquestion); |
|
180 | + $statement->bindValue(":defaultaction", $this->defaultaction); |
|
181 | + $statement->bindValue(":active", $this->active); |
|
182 | + $statement->bindValue(":preloadonly", $this->preloadonly); |
|
183 | + |
|
184 | + if ($statement->execute()) { |
|
185 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
186 | + } |
|
187 | + else { |
|
188 | + throw new Exception($statement->errorInfo()); |
|
189 | + } |
|
190 | + } |
|
191 | + else { |
|
192 | + // update |
|
193 | + $statement = $this->dbObject->prepare(<<<SQL |
|
194 | 194 | UPDATE `emailtemplate` |
195 | 195 | SET name = :name, |
196 | 196 | text = :text, |
@@ -201,130 +201,130 @@ discard block |
||
201 | 201 | updateversion = updateversion + 1 |
202 | 202 | WHERE id = :id AND updateversion = :updateversion; |
203 | 203 | SQL |
204 | - ); |
|
205 | - $statement->bindValue(':id', $this->id); |
|
206 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
207 | - |
|
208 | - $statement->bindValue(':name', $this->name); |
|
209 | - $statement->bindValue(":text", $this->text); |
|
210 | - $statement->bindValue(":jsquestion", $this->jsquestion); |
|
211 | - $statement->bindValue(":defaultaction", $this->defaultaction); |
|
212 | - $statement->bindValue(":active", $this->active); |
|
213 | - $statement->bindValue(":preloadonly", $this->preloadonly); |
|
214 | - |
|
215 | - if (!$statement->execute()) { |
|
216 | - throw new Exception($statement->errorInfo()); |
|
217 | - } |
|
218 | - |
|
219 | - if ($statement->rowCount() !== 1) { |
|
220 | - throw new OptimisticLockFailedException(); |
|
221 | - } |
|
222 | - |
|
223 | - $this->updateversion++; |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Override delete() from DataObject |
|
229 | - */ |
|
230 | - public function delete() |
|
231 | - { |
|
232 | - throw new Exception("You shouldn't be doing that, you'll break logs."); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public function getName() |
|
239 | - { |
|
240 | - return $this->name; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $name |
|
245 | - */ |
|
246 | - public function setName($name) |
|
247 | - { |
|
248 | - $this->name = $name; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public function getText() |
|
255 | - { |
|
256 | - return $this->text; |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @param string $text |
|
261 | - */ |
|
262 | - public function setText($text) |
|
263 | - { |
|
264 | - $this->text = $text; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @return string|null |
|
269 | - */ |
|
270 | - public function getJsquestion() |
|
271 | - { |
|
272 | - return $this->jsquestion; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @param string $jsquestion |
|
277 | - */ |
|
278 | - public function setJsquestion($jsquestion) |
|
279 | - { |
|
280 | - $this->jsquestion = $jsquestion; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function getDefaultAction() |
|
287 | - { |
|
288 | - return $this->defaultaction; |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * @param string $defaultAction |
|
293 | - */ |
|
294 | - public function setDefaultAction($defaultAction) |
|
295 | - { |
|
296 | - $this->defaultaction = $defaultAction; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * @return bool |
|
301 | - */ |
|
302 | - public function getActive() |
|
303 | - { |
|
304 | - return $this->active == 1; |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * @param bool $active |
|
309 | - */ |
|
310 | - public function setActive($active) |
|
311 | - { |
|
312 | - $this->active = $active ? 1 : 0; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * @return bool |
|
317 | - */ |
|
318 | - public function getPreloadOnly() |
|
319 | - { |
|
320 | - return $this->preloadonly == 1; |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * @param bool $preloadonly |
|
325 | - */ |
|
326 | - public function setPreloadOnly($preloadonly) |
|
327 | - { |
|
328 | - $this->preloadonly = $preloadonly ? 1 : 0; |
|
329 | - } |
|
204 | + ); |
|
205 | + $statement->bindValue(':id', $this->id); |
|
206 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
207 | + |
|
208 | + $statement->bindValue(':name', $this->name); |
|
209 | + $statement->bindValue(":text", $this->text); |
|
210 | + $statement->bindValue(":jsquestion", $this->jsquestion); |
|
211 | + $statement->bindValue(":defaultaction", $this->defaultaction); |
|
212 | + $statement->bindValue(":active", $this->active); |
|
213 | + $statement->bindValue(":preloadonly", $this->preloadonly); |
|
214 | + |
|
215 | + if (!$statement->execute()) { |
|
216 | + throw new Exception($statement->errorInfo()); |
|
217 | + } |
|
218 | + |
|
219 | + if ($statement->rowCount() !== 1) { |
|
220 | + throw new OptimisticLockFailedException(); |
|
221 | + } |
|
222 | + |
|
223 | + $this->updateversion++; |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Override delete() from DataObject |
|
229 | + */ |
|
230 | + public function delete() |
|
231 | + { |
|
232 | + throw new Exception("You shouldn't be doing that, you'll break logs."); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public function getName() |
|
239 | + { |
|
240 | + return $this->name; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $name |
|
245 | + */ |
|
246 | + public function setName($name) |
|
247 | + { |
|
248 | + $this->name = $name; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public function getText() |
|
255 | + { |
|
256 | + return $this->text; |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @param string $text |
|
261 | + */ |
|
262 | + public function setText($text) |
|
263 | + { |
|
264 | + $this->text = $text; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @return string|null |
|
269 | + */ |
|
270 | + public function getJsquestion() |
|
271 | + { |
|
272 | + return $this->jsquestion; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @param string $jsquestion |
|
277 | + */ |
|
278 | + public function setJsquestion($jsquestion) |
|
279 | + { |
|
280 | + $this->jsquestion = $jsquestion; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function getDefaultAction() |
|
287 | + { |
|
288 | + return $this->defaultaction; |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * @param string $defaultAction |
|
293 | + */ |
|
294 | + public function setDefaultAction($defaultAction) |
|
295 | + { |
|
296 | + $this->defaultaction = $defaultAction; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * @return bool |
|
301 | + */ |
|
302 | + public function getActive() |
|
303 | + { |
|
304 | + return $this->active == 1; |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * @param bool $active |
|
309 | + */ |
|
310 | + public function setActive($active) |
|
311 | + { |
|
312 | + $this->active = $active ? 1 : 0; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * @return bool |
|
317 | + */ |
|
318 | + public function getPreloadOnly() |
|
319 | + { |
|
320 | + return $this->preloadonly == 1; |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * @param bool $preloadonly |
|
325 | + */ |
|
326 | + public function setPreloadOnly($preloadonly) |
|
327 | + { |
|
328 | + $this->preloadonly = $preloadonly ? 1 : 0; |
|
329 | + } |
|
330 | 330 | } |
@@ -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` |
@@ -19,166 +19,166 @@ |
||
19 | 19 | */ |
20 | 20 | class WelcomeTemplate extends DataObject |
21 | 21 | { |
22 | - /** @var string */ |
|
23 | - private $usercode; |
|
24 | - /** @var string */ |
|
25 | - private $botcode; |
|
26 | - private $usageCache; |
|
27 | - private $deleted = 0; |
|
28 | - |
|
29 | - /** |
|
30 | - * Summary of getAll |
|
31 | - * |
|
32 | - * @param PdoDatabase $database |
|
33 | - * |
|
34 | - * @return WelcomeTemplate[] |
|
35 | - */ |
|
36 | - public static function getAll(PdoDatabase $database) |
|
37 | - { |
|
38 | - $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;"); |
|
39 | - |
|
40 | - $statement->execute(); |
|
41 | - |
|
42 | - $result = array(); |
|
43 | - /** @var WelcomeTemplate $v */ |
|
44 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) { |
|
45 | - $v->setDatabase($database); |
|
46 | - $result[] = $v; |
|
47 | - } |
|
48 | - |
|
49 | - return $result; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @throws Exception |
|
54 | - */ |
|
55 | - public function save() |
|
56 | - { |
|
57 | - if ($this->isNew()) { |
|
58 | - // insert |
|
59 | - $statement = $this->dbObject->prepare(<<<SQL |
|
22 | + /** @var string */ |
|
23 | + private $usercode; |
|
24 | + /** @var string */ |
|
25 | + private $botcode; |
|
26 | + private $usageCache; |
|
27 | + private $deleted = 0; |
|
28 | + |
|
29 | + /** |
|
30 | + * Summary of getAll |
|
31 | + * |
|
32 | + * @param PdoDatabase $database |
|
33 | + * |
|
34 | + * @return WelcomeTemplate[] |
|
35 | + */ |
|
36 | + public static function getAll(PdoDatabase $database) |
|
37 | + { |
|
38 | + $statement = $database->prepare("SELECT * FROM welcometemplate WHERE deleted = 0;"); |
|
39 | + |
|
40 | + $statement->execute(); |
|
41 | + |
|
42 | + $result = array(); |
|
43 | + /** @var WelcomeTemplate $v */ |
|
44 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, self::class) as $v) { |
|
45 | + $v->setDatabase($database); |
|
46 | + $result[] = $v; |
|
47 | + } |
|
48 | + |
|
49 | + return $result; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @throws Exception |
|
54 | + */ |
|
55 | + public function save() |
|
56 | + { |
|
57 | + if ($this->isNew()) { |
|
58 | + // insert |
|
59 | + $statement = $this->dbObject->prepare(<<<SQL |
|
60 | 60 | INSERT INTO welcometemplate (usercode, botcode) VALUES (:usercode, :botcode); |
61 | 61 | SQL |
62 | - ); |
|
63 | - $statement->bindValue(":usercode", $this->usercode); |
|
64 | - $statement->bindValue(":botcode", $this->botcode); |
|
65 | - |
|
66 | - if ($statement->execute()) { |
|
67 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
68 | - } |
|
69 | - else { |
|
70 | - throw new Exception($statement->errorInfo()); |
|
71 | - } |
|
72 | - } |
|
73 | - else { |
|
74 | - // update |
|
75 | - $statement = $this->dbObject->prepare(<<<SQL |
|
62 | + ); |
|
63 | + $statement->bindValue(":usercode", $this->usercode); |
|
64 | + $statement->bindValue(":botcode", $this->botcode); |
|
65 | + |
|
66 | + if ($statement->execute()) { |
|
67 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
68 | + } |
|
69 | + else { |
|
70 | + throw new Exception($statement->errorInfo()); |
|
71 | + } |
|
72 | + } |
|
73 | + else { |
|
74 | + // update |
|
75 | + $statement = $this->dbObject->prepare(<<<SQL |
|
76 | 76 | UPDATE `welcometemplate` |
77 | 77 | SET usercode = :usercode, botcode = :botcode, updateversion = updateversion + 1 |
78 | 78 | WHERE id = :id AND updateversion = :updateversion; |
79 | 79 | SQL |
80 | - ); |
|
81 | - |
|
82 | - $statement->bindValue(':id', $this->id); |
|
83 | - $statement->bindValue(':updateversion', $this->updateversion); |
|
84 | - |
|
85 | - $statement->bindValue(':usercode', $this->usercode); |
|
86 | - $statement->bindValue(':botcode', $this->botcode); |
|
87 | - |
|
88 | - if (!$statement->execute()) { |
|
89 | - throw new Exception($statement->errorInfo()); |
|
90 | - } |
|
91 | - |
|
92 | - if ($statement->rowCount() !== 1) { |
|
93 | - throw new OptimisticLockFailedException(); |
|
94 | - } |
|
95 | - |
|
96 | - $this->updateversion++; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getUserCode() |
|
104 | - { |
|
105 | - return $this->usercode; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param string $usercode |
|
110 | - */ |
|
111 | - public function setUserCode($usercode) |
|
112 | - { |
|
113 | - $this->usercode = $usercode; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * @return string |
|
118 | - */ |
|
119 | - public function getBotCode() |
|
120 | - { |
|
121 | - return $this->botcode; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @param string $botcode |
|
126 | - */ |
|
127 | - public function setBotCode($botcode) |
|
128 | - { |
|
129 | - $this->botcode = $botcode; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @return User[] |
|
134 | - */ |
|
135 | - public function getUsersUsingTemplate() |
|
136 | - { |
|
137 | - if ($this->usageCache === null) { |
|
138 | - $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;"); |
|
139 | - |
|
140 | - $statement->execute(array(":id" => $this->id)); |
|
141 | - |
|
142 | - $result = array(); |
|
143 | - /** @var WelcomeTemplate $v */ |
|
144 | - foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) { |
|
145 | - $v->setDatabase($this->dbObject); |
|
146 | - $result[] = $v; |
|
147 | - } |
|
148 | - |
|
149 | - $this->usageCache = $result; |
|
150 | - } |
|
151 | - |
|
152 | - return $this->usageCache; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Deletes the object from the database |
|
157 | - */ |
|
158 | - public function delete() |
|
159 | - { |
|
160 | - if ($this->id === null) { |
|
161 | - // wtf? |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;"; |
|
166 | - $statement = $this->dbObject->prepare($deleteQuery); |
|
167 | - |
|
168 | - $statement->bindValue(":id", $this->id); |
|
169 | - $statement->bindValue(":updateversion", $this->updateversion); |
|
170 | - $statement->execute(); |
|
171 | - |
|
172 | - if ($statement->rowCount() !== 1) { |
|
173 | - throw new OptimisticLockFailedException(); |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * @return bool |
|
179 | - */ |
|
180 | - public function isDeleted() |
|
181 | - { |
|
182 | - return ((int)$this->deleted) === 1; |
|
183 | - } |
|
80 | + ); |
|
81 | + |
|
82 | + $statement->bindValue(':id', $this->id); |
|
83 | + $statement->bindValue(':updateversion', $this->updateversion); |
|
84 | + |
|
85 | + $statement->bindValue(':usercode', $this->usercode); |
|
86 | + $statement->bindValue(':botcode', $this->botcode); |
|
87 | + |
|
88 | + if (!$statement->execute()) { |
|
89 | + throw new Exception($statement->errorInfo()); |
|
90 | + } |
|
91 | + |
|
92 | + if ($statement->rowCount() !== 1) { |
|
93 | + throw new OptimisticLockFailedException(); |
|
94 | + } |
|
95 | + |
|
96 | + $this->updateversion++; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getUserCode() |
|
104 | + { |
|
105 | + return $this->usercode; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param string $usercode |
|
110 | + */ |
|
111 | + public function setUserCode($usercode) |
|
112 | + { |
|
113 | + $this->usercode = $usercode; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * @return string |
|
118 | + */ |
|
119 | + public function getBotCode() |
|
120 | + { |
|
121 | + return $this->botcode; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @param string $botcode |
|
126 | + */ |
|
127 | + public function setBotCode($botcode) |
|
128 | + { |
|
129 | + $this->botcode = $botcode; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @return User[] |
|
134 | + */ |
|
135 | + public function getUsersUsingTemplate() |
|
136 | + { |
|
137 | + if ($this->usageCache === null) { |
|
138 | + $statement = $this->dbObject->prepare("SELECT * FROM user WHERE welcome_template = :id;"); |
|
139 | + |
|
140 | + $statement->execute(array(":id" => $this->id)); |
|
141 | + |
|
142 | + $result = array(); |
|
143 | + /** @var WelcomeTemplate $v */ |
|
144 | + foreach ($statement->fetchAll(PDO::FETCH_CLASS, User::class) as $v) { |
|
145 | + $v->setDatabase($this->dbObject); |
|
146 | + $result[] = $v; |
|
147 | + } |
|
148 | + |
|
149 | + $this->usageCache = $result; |
|
150 | + } |
|
151 | + |
|
152 | + return $this->usageCache; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Deletes the object from the database |
|
157 | + */ |
|
158 | + public function delete() |
|
159 | + { |
|
160 | + if ($this->id === null) { |
|
161 | + // wtf? |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + $deleteQuery = "UPDATE welcometemplate SET deleted = 1 WHERE id = :id AND updateversion = :updateversion;"; |
|
166 | + $statement = $this->dbObject->prepare($deleteQuery); |
|
167 | + |
|
168 | + $statement->bindValue(":id", $this->id); |
|
169 | + $statement->bindValue(":updateversion", $this->updateversion); |
|
170 | + $statement->execute(); |
|
171 | + |
|
172 | + if ($statement->rowCount() !== 1) { |
|
173 | + throw new OptimisticLockFailedException(); |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * @return bool |
|
179 | + */ |
|
180 | + public function isDeleted() |
|
181 | + { |
|
182 | + return ((int)$this->deleted) === 1; |
|
183 | + } |
|
184 | 184 | } |
@@ -17,151 +17,151 @@ |
||
17 | 17 | */ |
18 | 18 | class Log extends DataObject |
19 | 19 | { |
20 | - /** @var int */ |
|
21 | - private $objectid; |
|
22 | - /** @var string */ |
|
23 | - private $objecttype; |
|
24 | - /** @var int */ |
|
25 | - private $user; |
|
26 | - /** @var string */ |
|
27 | - private $action; |
|
28 | - private $timestamp; |
|
29 | - /** @var string|null */ |
|
30 | - private $comment; |
|
31 | - |
|
32 | - /** |
|
33 | - * @throws Exception |
|
34 | - */ |
|
35 | - public function save() |
|
36 | - { |
|
37 | - if ($this->isNew()) { |
|
38 | - $statement = $this->dbObject->prepare(<<<SQL |
|
20 | + /** @var int */ |
|
21 | + private $objectid; |
|
22 | + /** @var string */ |
|
23 | + private $objecttype; |
|
24 | + /** @var int */ |
|
25 | + private $user; |
|
26 | + /** @var string */ |
|
27 | + private $action; |
|
28 | + private $timestamp; |
|
29 | + /** @var string|null */ |
|
30 | + private $comment; |
|
31 | + |
|
32 | + /** |
|
33 | + * @throws Exception |
|
34 | + */ |
|
35 | + public function save() |
|
36 | + { |
|
37 | + if ($this->isNew()) { |
|
38 | + $statement = $this->dbObject->prepare(<<<SQL |
|
39 | 39 | INSERT INTO log (objectid, objecttype, user, action, timestamp, comment) |
40 | 40 | VALUES (:id, :type, :user, :action, CURRENT_TIMESTAMP(), :comment); |
41 | 41 | SQL |
42 | - ); |
|
43 | - |
|
44 | - $statement->bindValue(":id", $this->objectid); |
|
45 | - $statement->bindValue(":type", $this->objecttype); |
|
46 | - $statement->bindValue(":user", $this->user); |
|
47 | - $statement->bindValue(":action", $this->action); |
|
48 | - $statement->bindValue(":comment", $this->comment); |
|
49 | - |
|
50 | - if ($statement->execute()) { |
|
51 | - $this->id = (int)$this->dbObject->lastInsertId(); |
|
52 | - } |
|
53 | - else { |
|
54 | - throw new Exception($statement->errorInfo()); |
|
55 | - } |
|
56 | - } |
|
57 | - else { |
|
58 | - throw new Exception("Updating logs is not available"); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * @throws Exception |
|
64 | - */ |
|
65 | - public function delete() |
|
66 | - { |
|
67 | - throw new Exception("Deleting logs is not available."); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @return int |
|
72 | - */ |
|
73 | - public function getObjectId() |
|
74 | - { |
|
75 | - return $this->objectid; |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * Summary of setObjectId |
|
80 | - * |
|
81 | - * @param int $objectId |
|
82 | - */ |
|
83 | - public function setObjectId($objectId) |
|
84 | - { |
|
85 | - $this->objectid = $objectId; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - public function getObjectType() |
|
92 | - { |
|
93 | - return $this->objecttype; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Summary of setObjectType |
|
98 | - * |
|
99 | - * @param string $objectType |
|
100 | - */ |
|
101 | - public function setObjectType($objectType) |
|
102 | - { |
|
103 | - $this->objecttype = $objectType; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @return int |
|
108 | - */ |
|
109 | - public function getUser() |
|
110 | - { |
|
111 | - return $this->user; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Summary of setUser |
|
116 | - * |
|
117 | - * @param User $user |
|
118 | - */ |
|
119 | - public function setUser(User $user) |
|
120 | - { |
|
121 | - $this->user = $user->getId(); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public function getAction() |
|
128 | - { |
|
129 | - return $this->action; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Summary of setAction |
|
134 | - * |
|
135 | - * @param string $action |
|
136 | - */ |
|
137 | - public function setAction($action) |
|
138 | - { |
|
139 | - $this->action = $action; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @return DateTimeImmutable |
|
144 | - */ |
|
145 | - public function getTimestamp() |
|
146 | - { |
|
147 | - return new DateTimeImmutable($this->timestamp); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @return string|null |
|
152 | - */ |
|
153 | - public function getComment() |
|
154 | - { |
|
155 | - return $this->comment; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Summary of setComment |
|
160 | - * |
|
161 | - * @param string $comment |
|
162 | - */ |
|
163 | - public function setComment($comment) |
|
164 | - { |
|
165 | - $this->comment = $comment; |
|
166 | - } |
|
42 | + ); |
|
43 | + |
|
44 | + $statement->bindValue(":id", $this->objectid); |
|
45 | + $statement->bindValue(":type", $this->objecttype); |
|
46 | + $statement->bindValue(":user", $this->user); |
|
47 | + $statement->bindValue(":action", $this->action); |
|
48 | + $statement->bindValue(":comment", $this->comment); |
|
49 | + |
|
50 | + if ($statement->execute()) { |
|
51 | + $this->id = (int)$this->dbObject->lastInsertId(); |
|
52 | + } |
|
53 | + else { |
|
54 | + throw new Exception($statement->errorInfo()); |
|
55 | + } |
|
56 | + } |
|
57 | + else { |
|
58 | + throw new Exception("Updating logs is not available"); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * @throws Exception |
|
64 | + */ |
|
65 | + public function delete() |
|
66 | + { |
|
67 | + throw new Exception("Deleting logs is not available."); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @return int |
|
72 | + */ |
|
73 | + public function getObjectId() |
|
74 | + { |
|
75 | + return $this->objectid; |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * Summary of setObjectId |
|
80 | + * |
|
81 | + * @param int $objectId |
|
82 | + */ |
|
83 | + public function setObjectId($objectId) |
|
84 | + { |
|
85 | + $this->objectid = $objectId; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + public function getObjectType() |
|
92 | + { |
|
93 | + return $this->objecttype; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Summary of setObjectType |
|
98 | + * |
|
99 | + * @param string $objectType |
|
100 | + */ |
|
101 | + public function setObjectType($objectType) |
|
102 | + { |
|
103 | + $this->objecttype = $objectType; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @return int |
|
108 | + */ |
|
109 | + public function getUser() |
|
110 | + { |
|
111 | + return $this->user; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Summary of setUser |
|
116 | + * |
|
117 | + * @param User $user |
|
118 | + */ |
|
119 | + public function setUser(User $user) |
|
120 | + { |
|
121 | + $this->user = $user->getId(); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public function getAction() |
|
128 | + { |
|
129 | + return $this->action; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Summary of setAction |
|
134 | + * |
|
135 | + * @param string $action |
|
136 | + */ |
|
137 | + public function setAction($action) |
|
138 | + { |
|
139 | + $this->action = $action; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @return DateTimeImmutable |
|
144 | + */ |
|
145 | + public function getTimestamp() |
|
146 | + { |
|
147 | + return new DateTimeImmutable($this->timestamp); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @return string|null |
|
152 | + */ |
|
153 | + public function getComment() |
|
154 | + { |
|
155 | + return $this->comment; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Summary of setComment |
|
160 | + * |
|
161 | + * @param string $comment |
|
162 | + */ |
|
163 | + public function setComment($comment) |
|
164 | + { |
|
165 | + $this->comment = $comment; |
|
166 | + } |
|
167 | 167 | } |
@@ -49,12 +49,10 @@ |
||
49 | 49 | |
50 | 50 | if ($statement->execute()) { |
51 | 51 | $this->id = (int)$this->dbObject->lastInsertId(); |
52 | - } |
|
53 | - else { |
|
52 | + } else { |
|
54 | 53 | throw new Exception($statement->errorInfo()); |
55 | 54 | } |
56 | - } |
|
57 | - else { |
|
55 | + } else { |
|
58 | 56 | throw new Exception("Updating logs is not available"); |
59 | 57 | } |
60 | 58 | } |