Skip to content

Commit 36a6877

Browse files
Apply suggestions from code review
Co-authored-by: Joas Schilling <[email protected]> Signed-off-by: S1m <[email protected]>
1 parent 3c1e695 commit 36a6877

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

lib/Controller/WebPushController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function registerWP(string $endpoint, string $uaPublicKey, string $auth,
104104
if (
105105
!filter_var($endpoint, FILTER_VALIDATE_URL)
106106
|| \strlen($endpoint) > 765
107-
|| !preg_match('/^https\:\/\//', $endpoint)
107+
|| !str_starts_with($endpoint, 'https://')
108108
) {
109109
return new DataResponse(['message' => 'INVALID_ENDPOINT'], Http::STATUS_BAD_REQUEST);
110110
}
@@ -233,7 +233,7 @@ protected function saveSubscription(IUser $user, IToken $token, string $endpoint
233233
$result->closeCursor();
234234

235235
if (!$row) {
236-
// In case the user has already a subscription, but inactive or with a different enpoint, pubkey or auth secret
236+
// In case the user has already a subscription, but inactive or with a different endpoint, pubkey or auth secret
237237
$this->deleteSubscription($user, $token);
238238
$activationToken = Uuid::v4()->toRfc4122();
239239
if ($this->insertSubscription($user, $token, $endpoint, $uaPublicKey, $auth, $activationToken, $appTypes)) {

lib/Migration/Version6000Date20251112110000.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
use OCP\Migration\SimpleMigrationStep;
1818

1919
/**
20-
* Recreate notifications_pushtoken(s) with a primary key for cluster support
20+
* Create database table to webpush support
2121
*/
2222
class Version6000Date20251112110000 extends SimpleMigrationStep {
23-
public function __construct(
24-
protected IDBConnection $connection,
25-
) {
26-
}
2723

2824
/**
2925
* @param IOutput $output
@@ -38,7 +34,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
3834

3935
if (!$schema->hasTable('notifications_webpush')) {
4036
$table = $schema->createTable('notifications_webpush');
41-
$table->addColumn('id', Types::INTEGER, [
37+
$table->addColumn('id', Types::BIGINT, [
4238
'autoincrement' => true,
4339
'notnull' => true,
4440
'length' => 4,
@@ -48,9 +44,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
4844
'notnull' => true,
4945
'length' => 64,
5046
]);
51-
$table->addColumn('token', Types::INTEGER, [
52-
'notnull' => true,
53-
'length' => 4,
47+
$table->addColumn('token', Types::BIGINT, [
5448
'default' => 0,
5549
]);
5650
$table->addColumn('endpoint', Types::STRING, [
@@ -80,10 +74,11 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
8074

8175
$table->setPrimaryKey(['id']);
8276
// Allow a single push subscription per device
83-
$table->addUniqueIndex(['uid', 'token'], 'oc_npushwp_uid');
77+
$table->addUniqueIndex(['uid', 'token'], 'notifwebpush_uid_token');
8478
// If the push endpoint is removed, we will delete the row based on the endpoint
85-
$table->addIndex(['endpoint'], 'oc_npushwp_endpoint');
79+
$table->addIndex(['endpoint'], 'notifwebpush_endpoint');
80+
return $schema;
8681
}
87-
return $schema;
82+
return null;
8883
}
8984
}

0 commit comments

Comments
 (0)