1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 22:10:45 +02:00

[ticket/17010] Handle already existing subscriptions

PHPBB3-17010
This commit is contained in:
Marc Alexander
2023-07-03 14:38:01 +02:00
parent 5098f315fd
commit 6b00e9fe09
3 changed files with 63 additions and 9 deletions

View File

@@ -48,7 +48,6 @@ class add_webpush extends migration
'COLUMNS' => [
'subscription_id' => ['ULINT', null, 'auto_increment'],
'user_id' => ['ULINT', 0],
// 'device_name' => ['VCHAR:64', ''],
'endpoint' => ['TEXT', ''],
'expiration_time' => ['TIMESTAMP', 0],
'p256dh' => ['VCHAR', ''],

View File

@@ -35,9 +35,6 @@ class webpush
/** @var string UCP form token name */
private const FORM_TOKEN_UCP = 'ucp_webpush';
/** @var string Push worker form token name */
private const FORM_TOKEN_WORKER = 'webpush_worker';
/** @var config */
protected $config;
@@ -206,6 +203,7 @@ class webpush
$template_data += [
'VAPID_PUBLIC_KEY' => $this->config['webpush_vapid_public'],
'U_WEBPUSH_WORKER_URL' => $this->controller_helper->route('phpbb_ucp_push_worker_controller'),
'SUBSCRIPTIONS' => $this->get_subscriptions(),
];
$content = $this->template->render('webpush.js.twig', $template_data);
@@ -273,4 +271,26 @@ class webpush
'form_tokens' => $this->form_helper->get_form_tokens(self::FORM_TOKEN_UCP),
]);
}
/**
* Get subscriptions for current user
*
* @return array Subscriptions for user
*/
protected function get_subscriptions(): array
{
$subscriptions = [];
$sql = 'SELECT endpoint, expiration_time
FROM ' . $this->push_subscriptions_table . '
WHERE user_id = ' . $this->user->id();
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
$subscriptions[] = $row;
}
$this->db->sql_freeresult($result);
return $subscriptions;
}
}