mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
[ticket/17010] Add Webpush settings and language entries
PHPBB3-17010
This commit is contained in:
parent
d05e2dd043
commit
873a22176d
5 changed files with 35 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use Minishlink\WebPush\VAPID;
|
||||||
use phpbb\config\config;
|
use phpbb\config\config;
|
||||||
use phpbb\language\language;
|
use phpbb\language\language;
|
||||||
use phpbb\user;
|
use phpbb\user;
|
||||||
|
@ -490,6 +491,7 @@ class acp_board
|
||||||
'title' => 'ACP_WEBPUSH_SETTINGS',
|
'title' => 'ACP_WEBPUSH_SETTINGS',
|
||||||
'vars' => [
|
'vars' => [
|
||||||
'legend1' => 'GENERAL_SETTINGS',
|
'legend1' => 'GENERAL_SETTINGS',
|
||||||
|
'webpush_enable' => ['lang' => 'WEBPUSH_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true],
|
||||||
'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true],
|
'webpush_vapid_public' => ['lang' => 'WEBPUSH_VAPID_PUBLIC', 'validate' => 'string', 'type' => 'text:25:255', 'explain' => true],
|
||||||
'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true],
|
'webpush_vapid_private' => ['lang' => 'WEBPUSH_VAPID_PRIVATE', 'validate' => 'string', 'type' => 'password:25:255', 'explain' => true],
|
||||||
|
|
||||||
|
@ -537,6 +539,27 @@ class acp_board
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($mode == 'webpush')
|
||||||
|
{
|
||||||
|
// Create VAPID keys if keys are empty and web push is enabled
|
||||||
|
if ($submit && $cfg_array['webpush_enable'] && $cfg_array['webpush_enable'] != $config['webpush_enable']
|
||||||
|
&& empty($cfg_array['webpush_vapid_public']) && empty($cfg_array['webpush_vapid_private'])
|
||||||
|
&& empty($config['webpush_vapid_public']) && empty($config['webpush_vapid_private']))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$vapid_keys = VAPID::createVapidKeys();
|
||||||
|
$cfg_array['webpush_vapid_public'] = $vapid_keys['publicKey'];
|
||||||
|
$cfg_array['webpush_vapid_private'] = $vapid_keys['privateKey'];
|
||||||
|
}
|
||||||
|
catch (\ErrorException $exception)
|
||||||
|
{
|
||||||
|
// Nothing we can do about this, user will have to follow the
|
||||||
|
// documentation and manually create these.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// We validate the complete config if wished
|
// We validate the complete config if wished
|
||||||
validate_config_vars($display_vars['vars'], $cfg_array, $error);
|
validate_config_vars($display_vars['vars'], $cfg_array, $error);
|
||||||
|
|
||||||
|
|
|
@ -326,6 +326,9 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\pro
|
||||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\config\path', 'images/avatars/upload');
|
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\avatar\config\path', 'images/avatars/upload');
|
||||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\provider', 'phpbb\storage\provider\local');
|
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\provider', 'phpbb\storage\provider\local');
|
||||||
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\config\path', 'store');
|
INSERT INTO phpbb_config (config_name, config_value) VALUES ('storage\backup\config\path', 'store');
|
||||||
|
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_enable', '0');
|
||||||
|
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_public', '');
|
||||||
|
INSERT INTO phpbb_config (config_name, config_value) VALUES ('webpush_vapid_private', '');
|
||||||
|
|
||||||
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1);
|
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cache_last_gc', '0', 1);
|
||||||
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1);
|
INSERT INTO phpbb_config (config_name, config_value, is_dynamic) VALUES ('cron_lock', '0', 1);
|
||||||
|
|
|
@ -601,6 +601,8 @@ $lang = array_merge($lang, array(
|
||||||
|
|
||||||
$lang = array_merge($lang, [
|
$lang = array_merge($lang, [
|
||||||
'ACP_WEBPUSH_SETTINGS_EXPLAIN' => 'Here you can enable and control the use of Webpush for board notifications. Webpush is a simple protocol for the delivery of real-time events to user agents, more commonly known as push messages. It is supported by most modern browsers on desktop and mobile devices.',
|
'ACP_WEBPUSH_SETTINGS_EXPLAIN' => 'Here you can enable and control the use of Webpush for board notifications. Webpush is a simple protocol for the delivery of real-time events to user agents, more commonly known as push messages. It is supported by most modern browsers on desktop and mobile devices.',
|
||||||
|
'WEBPUSH_ENABLE' => 'Enable Webpush',
|
||||||
|
'WEBPUSH_ENABLE_EXPLAIN' => 'Allow receiving notifications via Webpush.<br><em><strong>Note:</strong></em> If VAPID keys have not been set, phpBB will try to automatically create them when enabling Webpush.',
|
||||||
'WEBPUSH_VAPID_PUBLIC' => 'VAPID public key',
|
'WEBPUSH_VAPID_PUBLIC' => 'VAPID public key',
|
||||||
'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The VAPID public key will be shared to authenticate push messages sent by your site.<br><em><strong>Warning:</strong> Changing the VAPID public key will automatically invalidate all webpush subscriptions.</em>',
|
'WEBPUSH_VAPID_PUBLIC_EXPLAIN' => 'The VAPID public key will be shared to authenticate push messages sent by your site.<br><em><strong>Warning:</strong> Changing the VAPID public key will automatically invalidate all webpush subscriptions.</em>',
|
||||||
'WEBPUSH_VAPID_PRIVATE' => 'VAPID private key',
|
'WEBPUSH_VAPID_PRIVATE' => 'VAPID private key',
|
||||||
|
|
|
@ -13,9 +13,10 @@
|
||||||
|
|
||||||
namespace phpbb\db\migration\data\v400;
|
namespace phpbb\db\migration\data\v400;
|
||||||
|
|
||||||
|
use Minishlink\WebPush\VAPID;
|
||||||
use phpbb\db\migration\migration;
|
use phpbb\db\migration\migration;
|
||||||
|
|
||||||
class add_notification_push_table extends migration
|
class add_webpush extends migration
|
||||||
{
|
{
|
||||||
public static function depends_on(): array
|
public static function depends_on(): array
|
||||||
{
|
{
|
||||||
|
@ -56,6 +57,7 @@ class add_notification_push_table extends migration
|
||||||
public function update_data(): array
|
public function update_data(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
['config.add', ['webpush_enable', false]],
|
||||||
['config.add', ['webpush_vapid_public', '']],
|
['config.add', ['webpush_vapid_public', '']],
|
||||||
['config.add', ['webpush_vapid_private', '']],
|
['config.add', ['webpush_vapid_private', '']],
|
||||||
['module.add', [
|
['module.add', [
|
||||||
|
@ -75,8 +77,10 @@ class add_notification_push_table extends migration
|
||||||
public function revert_data(): array
|
public function revert_data(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
['config.remove', ['webpush_enable']],
|
||||||
['config.remove', ['webpush_vapid_public']],
|
['config.remove', ['webpush_vapid_public']],
|
||||||
['config.remove', ['webpush_vapid_private']],
|
['config.remove', ['webpush_vapid_private']],
|
||||||
|
['module.remove', ['acp', 'ACP_BOARD_CONFIGURATION', 'ACP_WEBPUSH_SETTINGS']]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -142,7 +142,7 @@ class migrations_check_config_added_test extends phpbb_test_case
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill error entries for configuration options which were not added to shema_data.sql
|
// Fill error entries for configuration options which were not added to schema_data.sql
|
||||||
if (!isset($config_names[$config_name]))
|
if (!isset($config_names[$config_name]))
|
||||||
{
|
{
|
||||||
$config_names[$config_name] = [$config_name, $class];
|
$config_names[$config_name] = [$config_name, $class];
|
||||||
|
@ -160,7 +160,7 @@ class migrations_check_config_added_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_config_option_exists_in_schema_data($config_name, $class)
|
public function test_config_option_exists_in_schema_data($config_name, $class)
|
||||||
{
|
{
|
||||||
$message = 'Migration: %1$s, config_name: %2$s; not added to shema_data.sql';
|
$message = 'Migration: %1$s, config_name: %2$s; not added to schema_data.sql';
|
||||||
|
|
||||||
$this->assertNotFalse(strpos($this->schema_data, $config_name),
|
$this->assertNotFalse(strpos($this->schema_data, $config_name),
|
||||||
sprintf($message, $class, $config_name)
|
sprintf($message, $class, $config_name)
|
||||||
|
|
Loading…
Add table
Reference in a new issue