|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * |
| 4 | + * phpBB Browser Push Notifications. An extension for the phpBB Forum Software package. |
| 5 | + * |
| 6 | + * @copyright (c) 2023, phpBB Limited <https://www.phpbb.com> |
| 7 | + * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +namespace phpbb\webpushnotifications\migrations; |
| 12 | + |
| 13 | +use phpbb\db\migration\container_aware_migration; |
| 14 | + |
| 15 | +class handle_subscriptions extends container_aware_migration |
| 16 | +{ |
| 17 | + public function revert_data(): array |
| 18 | + { |
| 19 | + return [ |
| 20 | + ['custom', [[$this, 'update_subscriptions']]], |
| 21 | + ]; |
| 22 | + } |
| 23 | + |
| 24 | + public function update_subscriptions() |
| 25 | + { |
| 26 | + $user_notifications_table = $this->table_prefix . 'user_notifications'; |
| 27 | + |
| 28 | + // Check if webpush notification method exists in phpBB core (as of phpBB 4.0) |
| 29 | + $core_webpush_exists = $this->container->has('notification.method.webpush'); |
| 30 | + |
| 31 | + /* |
| 32 | + * If webpush notification method exists in phpBB core, |
| 33 | + * keep all subscriptions by just renaming notification method. |
| 34 | + * Otherwise remove all subscriptions |
| 35 | + */ |
| 36 | + $sql = $core_webpush_exists ? |
| 37 | + 'UPDATE ' . $user_notifications_table . " |
| 38 | + SET method = '" . $this->db->sql_escape('notification.method.webpush') . "' |
| 39 | + WHERE method = '" . $this->db->sql_escape('phpbb.wpn.notification.method.webpush') . "'" : |
| 40 | + |
| 41 | + 'DELETE FROM ' . $user_notifications_table . " |
| 42 | + WHERE method = '" . $this->db->sql_escape('phpbb.wpn.notification.method.webpush') . "'"; |
| 43 | + |
| 44 | + $this->db->sql_query($sql); |
| 45 | + } |
| 46 | +} |
0 commit comments