Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 58
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
add_webpush
0.00% covered (danger)
0.00%
0 / 58
0.00% covered (danger)
0.00%
0 / 6
42
0.00% covered (danger)
0.00%
0 / 1
 depends_on
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 effectively_installed
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 update_schema
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 1
2
 revert_schema
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 update_data
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
2
 revert_data
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 *
4 * This file is part of the phpBB Forum Software package.
5 *
6 * @copyright (c) phpBB Limited <https://www.phpbb.com>
7 * @license GNU General Public License, version 2 (GPL-2.0)
8 *
9 * For full copyright and license information, please see
10 * the docs/CREDITS.txt file.
11 *
12 */
13
14namespace phpbb\db\migration\data\v400;
15
16use phpbb\db\migration\migration;
17
18class add_webpush extends migration
19{
20    public static function depends_on(): array
21    {
22        return [
23            '\phpbb\db\migration\data\v400\dev',
24        ];
25    }
26
27    public function effectively_installed(): bool
28    {
29        return $this->db_tools->sql_table_exists($this->table_prefix . 'notification_push');
30    }
31
32    public function update_schema(): array
33    {
34        return [
35            'add_tables'    => [
36                $this->table_prefix . 'notification_push' => [
37                    'COLUMNS'    => [
38                        'notification_type_id'    => ['USINT', 0],
39                        'item_id'                => ['ULINT', 0],
40                        'item_parent_id'        => ['ULINT', 0],
41                        'user_id'                => ['ULINT', 0],
42                        'push_data'                => ['MTEXT', ''],
43                        'notification_time'        => ['TIMESTAMP', 0]
44                    ],
45                    'PRIMARY_KEY' => ['notification_type_id', 'item_id', 'item_parent_id', 'user_id'],
46                ],
47                $this->table_prefix . 'push_subscriptions' => [
48                    'COLUMNS'    => [
49                        'subscription_id'    => ['ULINT', null, 'auto_increment'],
50                        'user_id'            => ['ULINT', 0],
51                        'endpoint'            => ['TEXT', ''],
52                        'expiration_time'    => ['TIMESTAMP', 0],
53                        'p256dh'            => ['VCHAR', ''],
54                        'auth'                => ['VCHAR', ''],
55                    ],
56                    'PRIMARY_KEY' => ['subscription_id', 'user_id'],
57                ]
58            ],
59        ];
60    }
61
62    public function revert_schema(): array
63    {
64        return [
65            'drop_tables' => [
66                $this->table_prefix . 'notification_push',
67                $this->table_prefix . 'push_subscriptions',
68            ],
69        ];
70    }
71
72    public function update_data(): array
73    {
74        return [
75            ['config.add', ['webpush_enable', false]],
76            ['config.add', ['webpush_vapid_public', '']],
77            ['config.add', ['webpush_vapid_private', '']],
78            ['module.add', [
79                'acp',
80                'ACP_CLIENT_COMMUNICATION',
81                [
82                    'module_basename'    => 'acp_board',
83                    'module_langname'    => 'ACP_WEBPUSH_SETTINGS',
84                    'module_mode'        => 'webpush',
85                    'module_auth'        => 'acl_a_board',
86                    'after'                => ['settings', 'ACP_JABBER_SETTINGS'],
87                ],
88            ]],
89        ];
90    }
91
92    public function revert_data(): array
93    {
94        return [
95            ['config.remove', ['webpush_enable']],
96            ['config.remove', ['webpush_vapid_public']],
97            ['config.remove', ['webpush_vapid_private']],
98            ['module.remove', ['acp', 'ACP_CLIENT_COMMUNICATION', 'ACP_WEBPUSH_SETTINGS']]
99        ];
100    }
101}