@@ -30,13 +30,11 @@ |
||
30 | 30 | notificationtype varchar(10), |
31 | 31 | notificationaddress varchar(64) |
32 | 32 | ); |
33 | - |
|
34 | 33 | * |
35 | 34 | * In version 3.0 the format of the tmpblocktimestamp was changed from a datetime format to an integer. |
36 | 35 | * Because it holds a unix timestamp a 64-bit (8-byte) integer. To upgrade the user table to the new format use: |
37 | 36 | |
38 | 37 | ALTER TABLE user MODIFY tmpblocktimestamp BIGINT; |
39 | - |
|
40 | 38 | */ |
41 | 39 | |
42 | 40 | use Psr\Log\LoggerInterface; |
@@ -89,21 +89,21 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function _getStringValue(string $columnName, string $userId): string |
91 | 91 | { |
92 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
92 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
93 | 93 | throw new InvalidArgumentException('Unsupported column name'); |
94 | 94 | } |
95 | 95 | |
96 | 96 | try { |
97 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
97 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
98 | 98 | $sth->execute(array($userId)); |
99 | - $res=$sth->fetchColumn(); |
|
99 | + $res = $sth->fetchColumn(); |
|
100 | 100 | if ($res === false) { |
101 | 101 | // No result |
102 | 102 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
103 | 103 | throw new RuntimeException('User not found'); |
104 | 104 | } |
105 | 105 | if ($res === NULL) { |
106 | - return ''; // Value unset |
|
106 | + return ''; // Value unset |
|
107 | 107 | } |
108 | 108 | if (!is_string($res)) { |
109 | 109 | $this->logger->error(sprintf('Expected string type while getting "%s" for user "%s"', $columnName, $userId)); |
@@ -127,28 +127,28 @@ discard block |
||
127 | 127 | */ |
128 | 128 | private function _getIntValue(string $columnName, string $userId): int |
129 | 129 | { |
130 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
130 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
131 | 131 | throw new InvalidArgumentException('Unsupported column name'); |
132 | 132 | } |
133 | 133 | |
134 | 134 | try { |
135 | - $sth = $this->handle->prepare('SELECT ' . $columnName . ' FROM ' . $this->tablename . ' WHERE userid = ?'); |
|
135 | + $sth = $this->handle->prepare('SELECT '.$columnName.' FROM '.$this->tablename.' WHERE userid = ?'); |
|
136 | 136 | $sth->execute(array($userId)); |
137 | - $res=$sth->fetchColumn(); |
|
137 | + $res = $sth->fetchColumn(); |
|
138 | 138 | if ($res === false) { |
139 | 139 | // No result |
140 | 140 | $this->logger->error(sprintf('No result getting "%s" for user "%s"', $columnName, $userId)); |
141 | 141 | throw new RuntimeException('User not found'); |
142 | 142 | } |
143 | 143 | if ($res === NULL) { |
144 | - return 0; // Value unset |
|
144 | + return 0; // Value unset |
|
145 | 145 | } |
146 | 146 | // Return type for integers depends on the PDO driver, can be string |
147 | 147 | if (!is_numeric($res)) { |
148 | 148 | $this->logger->error(sprintf('Expected int type while getting "%s" for user "%s"', $columnName, $userId)); |
149 | 149 | throw new RuntimeException('Unexpected return type'); |
150 | 150 | } |
151 | - return (int)$res; |
|
151 | + return (int) $res; |
|
152 | 152 | } |
153 | 153 | catch (Exception $e) { |
154 | 154 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
@@ -165,11 +165,11 @@ discard block |
||
165 | 165 | */ |
166 | 166 | private function _setStringValue(string $columnName, string $userId, string $value): void |
167 | 167 | { |
168 | - if ( !in_array($columnName, $this->_allowedStringColumns) ) { |
|
168 | + if (!in_array($columnName, $this->_allowedStringColumns)) { |
|
169 | 169 | throw new InvalidArgumentException('Unsupported column name'); |
170 | 170 | } |
171 | 171 | try { |
172 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
172 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
173 | 173 | $sth->execute(array($value, $userId)); |
174 | 174 | if ($sth->rowCount() == 0) { |
175 | 175 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -193,11 +193,11 @@ discard block |
||
193 | 193 | */ |
194 | 194 | private function _setIntValue(string $columnName, string $userId, int $value): void |
195 | 195 | { |
196 | - if ( !in_array($columnName, $this->_allowedIntColumns) ) { |
|
196 | + if (!in_array($columnName, $this->_allowedIntColumns)) { |
|
197 | 197 | throw new InvalidArgumentException('Unsupported column name'); |
198 | 198 | } |
199 | 199 | try { |
200 | - $sth = $this->handle->prepare('UPDATE ' . $this->tablename . ' SET ' . $columnName . ' = ? WHERE userid = ?'); |
|
200 | + $sth = $this->handle->prepare('UPDATE '.$this->tablename.' SET '.$columnName.' = ? WHERE userid = ?'); |
|
201 | 201 | $sth->execute(array($value, $userId)); |
202 | 202 | if ($sth->rowCount() == 0) { |
203 | 203 | // Required for mysql which only returns the number of rows that were actually updated |
@@ -309,17 +309,17 @@ discard block |
||
309 | 309 | { |
310 | 310 | // Check for blocked |
311 | 311 | if ($this->_getIntValue('blocked', $userId) != 0) { |
312 | - return true; // Blocked |
|
312 | + return true; // Blocked |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | if (0 == $tempBlockDuration) { |
316 | - return false; // No check for temporary block |
|
316 | + return false; // No check for temporary block |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | // Check for temporary block |
320 | 320 | $timestamp = $this->getTemporaryBlockTimestamp($userId); |
321 | 321 | // if no temporary block timestamp is set or if the temporary block is expired, return false |
322 | - if ( 0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
322 | + if (0 == $timestamp || ($timestamp + $tempBlockDuration * 60) < time()) { |
|
323 | 323 | return false; |
324 | 324 | } |
325 | 325 | return true; |
@@ -110,8 +110,7 @@ discard block |
||
110 | 110 | throw new RuntimeException('Unexpected return type'); |
111 | 111 | } |
112 | 112 | return $res; |
113 | - } |
|
114 | - catch (Exception $e) { |
|
113 | + } catch (Exception $e) { |
|
115 | 114 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
116 | 115 | throw ReadWriteException::fromOriginalException($e); |
117 | 116 | } |
@@ -149,8 +148,7 @@ discard block |
||
149 | 148 | throw new RuntimeException('Unexpected return type'); |
150 | 149 | } |
151 | 150 | return (int)$res; |
152 | - } |
|
153 | - catch (Exception $e) { |
|
151 | + } catch (Exception $e) { |
|
154 | 152 | $this->logger->error('PDO error getting user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
155 | 153 | throw ReadWriteException::fromOriginalException($e); |
156 | 154 | } |
@@ -177,8 +175,7 @@ discard block |
||
177 | 175 | throw new RuntimeException('User not found'); |
178 | 176 | } |
179 | 177 | } |
180 | - } |
|
181 | - catch (Exception $e) { |
|
178 | + } catch (Exception $e) { |
|
182 | 179 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
183 | 180 | throw ReadWriteException::fromOriginalException($e); |
184 | 181 | } |
@@ -205,8 +202,7 @@ discard block |
||
205 | 202 | throw new RuntimeException('User not found'); |
206 | 203 | } |
207 | 204 | } |
208 | - } |
|
209 | - catch (Exception $e) { |
|
205 | + } catch (Exception $e) { |
|
210 | 206 | $this->logger->error('PDO error updating user', array('exception' => $e, 'userId' => $userId, 'columnName'=>$columnName)); |
211 | 207 | throw ReadWriteException::fromOriginalException($e); |
212 | 208 | } |
@@ -223,8 +219,7 @@ discard block |
||
223 | 219 | try { |
224 | 220 | $sth = $this->handle->prepare("INSERT INTO ".$this->tablename." (displayname,userid) VALUES (?,?)"); |
225 | 221 | $sth->execute(array($displayName, $userId)); |
226 | - } |
|
227 | - catch (Exception $e) { |
|
222 | + } catch (Exception $e) { |
|
228 | 223 | $this->logger->error(sprintf('Error creating user "%s"', $userId), array('exception'=>$e)); |
229 | 224 | throw new ReadWriteException('The user could not be saved in the user storage (PDO)'); |
230 | 225 | } |
@@ -239,8 +234,7 @@ discard block |
||
239 | 234 | $sth = $this->handle->prepare("SELECT userid FROM ".$this->tablename." WHERE userid = ?"); |
240 | 235 | $sth->execute(array($userId)); |
241 | 236 | return (false !== $sth->fetchColumn()); |
242 | - } |
|
243 | - catch (Exception $e) { |
|
237 | + } catch (Exception $e) { |
|
244 | 238 | $this->logger->error('PDO error checking user exists', array('exception'=>$e, 'userId'=>$userId)); |
245 | 239 | throw ReadWriteException::fromOriginalException($e); |
246 | 240 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | $options = $this->getOptions(); |
24 | 24 | if (isset($options['apns.proxy_host_url'])) { |
25 | 25 | // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy |
26 | - $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress(); |
|
26 | + $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress(); |
|
27 | 27 | $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443; |
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | - $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
30 | + $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
31 | 31 | } |
32 | 32 | else { |
33 | 33 | $version_info = curl_version(); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | // Get the UID from the client certificate we use for authentication, this |
40 | 40 | // is set to the bundle ID. |
41 | - $options=$this->getOptions(); |
|
41 | + $options = $this->getOptions(); |
|
42 | 42 | $cert_filename = $options['apns.certificate']; |
43 | 43 | $cert_file_contents = file_get_contents($cert_filename); |
44 | 44 | if (false === $cert_file_contents) { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - $cert=openssl_x509_parse( $cert_file_contents ); |
|
50 | + $cert = openssl_x509_parse($cert_file_contents); |
|
51 | 51 | if (false === $cert) { |
52 | 52 | throw new RuntimeException('Error parsing APNS client certificate'); |
53 | 53 | } |
@@ -72,42 +72,42 @@ discard block |
||
72 | 72 | $authProvider = AuthProvider\Certificate::create($authProviderOptions); |
73 | 73 | |
74 | 74 | // Create the push message |
75 | - $alert=Alert::create(); |
|
75 | + $alert = Alert::create(); |
|
76 | 76 | $alert->setBody($this->getText()); |
77 | 77 | // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle() |
78 | 78 | // The tiqr service currently does not implement this. |
79 | - $payload=Payload::create()->setAlert($alert); |
|
79 | + $payload = Payload::create()->setAlert($alert); |
|
80 | 80 | $payload->setSound('default'); |
81 | 81 | foreach ($this->getCustomProperties() as $name => $value) { |
82 | 82 | $payload->setCustomValue($name, $value); |
83 | 83 | } |
84 | 84 | $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
85 | - $notification=new Notification($payload, $this->getAddress()); |
|
85 | + $notification = new Notification($payload, $this->getAddress()); |
|
86 | 86 | // Set expiration to 30 seconds from now, same as Message_APNS |
87 | 87 | $now = new DateTime(); |
88 | - $expirationInstant=$now->add(new DateInterval('PT30S')); |
|
88 | + $expirationInstant = $now->add(new DateInterval('PT30S')); |
|
89 | 89 | $notification->setExpirationAt($expirationInstant); |
90 | 90 | |
91 | 91 | // Send the push message |
92 | 92 | $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options); |
93 | 93 | $client->addNotification($notification); |
94 | - $responses=$client->push(); |
|
95 | - if ( sizeof($responses) != 1) { |
|
96 | - $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) ); |
|
94 | + $responses = $client->push(); |
|
95 | + if (sizeof($responses) != 1) { |
|
96 | + $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses))); |
|
97 | 97 | if (sizeof($responses) == 0) { |
98 | 98 | $this->logger->warning('Could not determine whether the notification was sent'); |
99 | 99 | return; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | /** @var \Pushok\Response $response */ |
103 | - $response = reset($responses); // Get first response from the array |
|
104 | - $deviceToken=$response->getDeviceToken() ?? ''; |
|
103 | + $response = reset($responses); // Get first response from the array |
|
104 | + $deviceToken = $response->getDeviceToken() ?? ''; |
|
105 | 105 | // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
106 | - $apnsId=$response->getApnsId() ?? ''; |
|
106 | + $apnsId = $response->getApnsId() ?? ''; |
|
107 | 107 | // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
108 | - $statusCode=$response->getStatusCode(); |
|
108 | + $statusCode = $response->getStatusCode(); |
|
109 | 109 | $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
110 | - if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
110 | + if (strcasecmp($deviceToken, $this->getAddress())) { |
|
111 | 111 | $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
112 | 112 | } |
113 | 113 | if ($statusCode == 200) { |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | - $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
120 | - $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
118 | + $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | + $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
120 | + $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
121 | 121 | |
122 | 122 | $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
123 | 123 | throw new RuntimeException( |
@@ -28,8 +28,7 @@ |
||
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | 30 | $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
31 | - } |
|
32 | - else { |
|
31 | + } else { |
|
33 | 32 | $version_info = curl_version(); |
34 | 33 | if ($version_info['features'] & CURL_VERSION_HTTP2 == 0) { |
35 | 34 | throw new RuntimeException('APNS2 requires HTTP/2 support in curl'); |