Merge pull request #6506 from marc1706/ticket/11449

[ticket/11449] Add separate method for deleting notifications by multiple types
This commit is contained in:
Marc Alexander 2023-08-03 19:45:33 +02:00 committed by GitHub
commit b447e4468a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 20 deletions

View file

@ -894,11 +894,11 @@ function delete_topics($where_type, $where_ids, $auto_sync = true, $post_count_s
/* @var $phpbb_notifications \phpbb\notification\manager */
$phpbb_notifications = $phpbb_container->get('notification_manager');
$phpbb_notifications->delete_notifications(array(
$phpbb_notifications->delete_notifications_by_types([
'notification.type.topic',
'notification.type.approve_topic',
'notification.type.topic_in_queue',
), $topic_ids);
], $topic_ids);
return $return;
}
@ -1185,7 +1185,7 @@ function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync =
/* @var $phpbb_notifications \phpbb\notification\manager */
$phpbb_notifications = $phpbb_container->get('notification_manager');
$phpbb_notifications->delete_notifications($delete_notifications_types, $post_ids);
$phpbb_notifications->delete_notifications_by_types($delete_notifications_types, $post_ids);
return count($post_ids);
}

View file

@ -474,25 +474,17 @@ class manager
}
/**
* Delete a notification
*
* @param string|array $notification_type_name Type identifier or array of item types (only acceptable if the $item_id is identical for the specified types)
* @param int|array $item_id Identifier within the type (or array of ids)
* @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
* @param mixed $user_id User id (Default: false; not checked)
* Delete notifications of specified type
*
* @param string $notification_type_name Type identifier
* @param int|array $item_id Identifier within the type (or array of ids)
* @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
* @param mixed $user_id User id (Default: false; not checked)
*
* @return void
*/
public function delete_notifications($notification_type_name, $item_id, $parent_id = false, $user_id = false)
public function delete_notifications(string $notification_type_name, $item_id, $parent_id = false, $user_id = false): void
{
if (is_array($notification_type_name))
{
foreach ($notification_type_name as $type)
{
$this->delete_notifications($type, $item_id, $parent_id, $user_id);
}
return;
}
$notification_type_id = $this->get_notification_type_id($notification_type_name);
/** @var method\method_interface $method */
@ -502,6 +494,24 @@ class manager
}
}
/**
* Delete notifications specified by multiple types
*
* @param array $notification_type_names Array of item types (only acceptable if the $item_id is identical for the specified types)
* @param int|array $item_id Identifier within the type (or array of ids)
* @param mixed $parent_id Parent identifier within the type (or array of ids), used in combination with item_id if specified (Default: false; not checked)
* @param mixed $user_id User id (Default: false; not checked)
*
* @return void
*/
public function delete_notifications_by_types(array $notification_type_names, $item_id, $parent_id = false, $user_id = false): void
{
foreach ($notification_type_names as $type)
{
$this->delete_notifications($type, $item_id, $parent_id, $user_id);
}
}
/**
* Get all of the subscription types
*

View file

@ -61,6 +61,10 @@ class phpbb_mock_notification_manager
{
}
public function delete_notifications_by_types()
{
}
public function get_subscription_types()
{
return array();