-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscribe Toggle in Notification Dropdown #41
Changes from 1 commit
7c3fc16
5abdb49
47fc002
6610224
c4b60d1
389d4ef
c8a5a26
093b1b1
711d709
3fa5703
70d611f
9e27f11
0ef563d
772d46c
bbdbd22
e38239f
2d00c6d
9546447
a7907ae
d642b73
bb36bfd
7fcf10d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
/** | ||
* | ||
* phpBB Browser Push Notifications. An extension for the phpBB Forum Software package. | ||
* | ||
* @copyright (c) 2024, phpBB Limited <https://www.phpbb.com> | ||
* @license GNU General Public License, version 2 (GPL-2.0) | ||
* | ||
*/ | ||
|
||
namespace phpbb\webpushnotifications\migrations; | ||
|
||
use phpbb\db\migration\migration; | ||
|
||
class update_user_notifications extends migration | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public static function depends_on() | ||
{ | ||
return ['\phpbb\webpushnotifications\migrations\add_webpush']; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function effectively_installed() | ||
{ | ||
$sql = 'SELECT method | ||
FROM ' . $this->table_prefix . "user_notifications | ||
WHERE method = '" . $this->db->sql_escape('notification.method.phpbb.wpn.webpush') . "'"; | ||
$result = $this->db->sql_query($sql); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we need at least 1 positive result so probably |
||
$row = $this->db->sql_fetchrow($result); | ||
$this->db->sql_freeresult($result); | ||
|
||
return $row !== false; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function update_data() | ||
{ | ||
return [ | ||
['custom', [[$this, 'update_notifications']]], | ||
]; | ||
} | ||
|
||
/** | ||
* Add default push notifications for users in chunks | ||
* | ||
* @param $start int Start value for the update | ||
* @return int|true Next start value or true if complete | ||
*/ | ||
public function update_notifications($start) | ||
{ | ||
$start = (int) $start; | ||
$limit = 500; | ||
$updated = 0; | ||
|
||
$sql_ary = []; | ||
|
||
$sql = 'SELECT user_id | ||
FROM ' . $this->table_prefix . 'users | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably limit user types to |
||
ORDER BY user_id ASC'; | ||
$result = $this->db->sql_query_limit($sql, $limit, $start); | ||
|
||
while ($row = $this->db->sql_fetchrow($result)) | ||
{ | ||
$sql_ary[] = [ | ||
'item_type' => 'notification.type.pm', | ||
'item_id' => 0, | ||
'user_id' => (int) $row['user_id'], | ||
'notify' => 1, | ||
'method' => 'notification.method.phpbb.wpn.webpush', | ||
]; | ||
$sql_ary[] = [ | ||
'item_type' => 'notification.type.quote', | ||
'item_id' => 0, | ||
'user_id' => (int) $row['user_id'], | ||
'notify' => 1, | ||
'method' => 'notification.method.phpbb.wpn.webpush', | ||
]; | ||
$updated++; | ||
} | ||
$this->db->sql_freeresult($result); | ||
|
||
$this->db->sql_multi_insert($this->table_prefix . 'user_notifications', $sql_ary); | ||
|
||
return ($updated === $limit) ? $start + $limit : true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add
AND notify = 1
as far as we're looking for enabled notification types.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this I'm just looking to see if it exists yet, because if it does it means it's already been installed and people have started making settings already.