mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Merge remote-tracking branch 'github-nickvergessen/ticket/12371' into develop-ascraeus
* github-nickvergessen/ticket/12371: [ticket/12371] Fix language string [ticket/12371] Fix typos in comment [ticket/12371] Fix redirect link for approve_post and post_in_queue [ticket/12371] Delete the approve_post notification when editing a post [ticket/12371] Fix language in comment [ticket/12371] Reapprove the post and topic again in tests [ticket/12371] Correctly set is_starter when editing first post of the topic [ticket/12371] Add functional tests for reapproving [ticket/12371] Fix query in mcp_sorting() [ticket/12371] Rename disapprove and softdelete tests [ticket/12371] We do not group quote notifications anymore [ticket/12371] Fix SQL query [ticket/11772] Do not send out new topic/post notifications when reapproving [ticket/12052] Use different visibility when post was edited [ticket/12052] Add support for ITEM_UNAPPROVED to set_post_visibility method [ticket/12371] Do not add unlimited users as responders [ticket/12371] Do not update the notification entry unneccessarily [ticket/12371] Do not delete post related notifications when a post is deleted [ticket/12371] Allow notification types to redirect to a different url [ticket/12371] Do not group "quote" notifications
This commit is contained in:
@@ -215,23 +215,23 @@ class content_visibility
|
||||
/**
|
||||
* Change visibility status of one post or all posts of a topic
|
||||
*
|
||||
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED}
|
||||
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE}
|
||||
* @param $post_id mixed Post ID or array of post IDs to act on,
|
||||
* if it is empty, all posts of topic_id will be modified
|
||||
* @param $topic_id int Topic where $post_id is found
|
||||
* @param $forum_id int Forum where $topic_id is found
|
||||
* @param $user_id int User performing the action
|
||||
* @param $time int Timestamp when the action is performed
|
||||
* @param $reason string Reason why the visibilty was changed.
|
||||
* @param $reason string Reason why the visibility was changed.
|
||||
* @param $is_starter bool Is this the first post of the topic changed?
|
||||
* @param $is_latest bool Is this the last post of the topic changed?
|
||||
* @param $limit_visibility mixed Limit updating per topic_id to a certain visibility
|
||||
* @param $limit_delete_time mixed Limit updating per topic_id to a certain deletion time
|
||||
* @return array Changed post data, empty array if an error occured.
|
||||
* @return array Changed post data, empty array if an error occurred.
|
||||
*/
|
||||
public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest, $limit_visibility = false, $limit_delete_time = false)
|
||||
{
|
||||
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED)))
|
||||
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE)))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -326,7 +326,7 @@ class content_visibility
|
||||
// Update users postcounts
|
||||
foreach ($postcounts as $num_posts => $poster_ids)
|
||||
{
|
||||
if ($visibility == ITEM_DELETED)
|
||||
if (in_array($visibility, array(ITEM_REAPPROVE, ITEM_DELETED)))
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->users_table . '
|
||||
SET user_posts = 0
|
||||
@@ -387,54 +387,36 @@ class content_visibility
|
||||
// Update the topic's reply count and the forum's post count
|
||||
if ($update_topic_postcount)
|
||||
{
|
||||
$cur_posts = $cur_unapproved_posts = $cur_softdeleted_posts = 0;
|
||||
$field_alias = array(
|
||||
ITEM_APPROVED => 'posts_approved',
|
||||
ITEM_UNAPPROVED => 'posts_unapproved',
|
||||
ITEM_DELETED => 'posts_softdeleted',
|
||||
ITEM_REAPPROVE => 'posts_unapproved',
|
||||
);
|
||||
$cur_posts = array_fill_keys($field_alias, 0);
|
||||
|
||||
foreach ($postcount_visibility as $post_visibility => $visibility_posts)
|
||||
{
|
||||
// We need to substract the posts from the counters ...
|
||||
if ($post_visibility == ITEM_APPROVED)
|
||||
{
|
||||
$cur_posts += $visibility_posts;
|
||||
}
|
||||
else if ($post_visibility == ITEM_UNAPPROVED)
|
||||
{
|
||||
$cur_unapproved_posts += $visibility_posts;
|
||||
}
|
||||
else if ($post_visibility == ITEM_DELETED)
|
||||
{
|
||||
$cur_softdeleted_posts += $visibility_posts;
|
||||
}
|
||||
$cur_posts[$field_alias[(int) $post_visibility]] += $visibility_posts;
|
||||
}
|
||||
|
||||
$sql_ary = array();
|
||||
if ($visibility == ITEM_DELETED)
|
||||
$recipient_field = $field_alias[$visibility];
|
||||
|
||||
foreach ($cur_posts as $field => $count)
|
||||
{
|
||||
if ($cur_posts)
|
||||
// Decrease the count for the old statuses.
|
||||
if ($count && $field != $recipient_field)
|
||||
{
|
||||
$sql_ary['posts_approved'] = ' - ' . $cur_posts;
|
||||
}
|
||||
if ($cur_unapproved_posts)
|
||||
{
|
||||
$sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts;
|
||||
}
|
||||
if ($cur_posts + $cur_unapproved_posts)
|
||||
{
|
||||
$sql_ary['posts_softdeleted'] = ' + ' . ($cur_posts + $cur_unapproved_posts);
|
||||
$sql_ary[$field] = " - $count";
|
||||
}
|
||||
}
|
||||
else
|
||||
// Add up the count from all statuses excluding the recipient status.
|
||||
$count_increase = array_sum(array_diff($cur_posts, array($recipient_field)));
|
||||
|
||||
if ($count_increase)
|
||||
{
|
||||
if ($cur_unapproved_posts)
|
||||
{
|
||||
$sql_ary['posts_unapproved'] = ' - ' . $cur_unapproved_posts;
|
||||
}
|
||||
if ($cur_softdeleted_posts)
|
||||
{
|
||||
$sql_ary['posts_softdeleted'] = ' - ' . $cur_softdeleted_posts;
|
||||
}
|
||||
if ($cur_softdeleted_posts + $cur_unapproved_posts)
|
||||
{
|
||||
$sql_ary['posts_approved'] = ' + ' . ($cur_softdeleted_posts + $cur_unapproved_posts);
|
||||
}
|
||||
$sql_ary[$recipient_field] = " + $count_increase";
|
||||
}
|
||||
|
||||
if (sizeof($sql_ary))
|
||||
@@ -475,7 +457,7 @@ class content_visibility
|
||||
* as soft deleted.
|
||||
* If you want to update all posts, use the force option.
|
||||
*
|
||||
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED}
|
||||
* @param $visibility int Element of {ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE}
|
||||
* @param $topic_id mixed Topic ID to act on
|
||||
* @param $forum_id int Forum where $topic_id is found
|
||||
* @param $user_id int User performing the action
|
||||
@@ -486,7 +468,7 @@ class content_visibility
|
||||
*/
|
||||
public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason, $force_update_all = false)
|
||||
{
|
||||
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED)))
|
||||
if (!in_array($visibility, array(ITEM_APPROVED, ITEM_DELETED, ITEM_REAPPROVE)))
|
||||
{
|
||||
return array();
|
||||
}
|
||||
@@ -532,7 +514,7 @@ class content_visibility
|
||||
}
|
||||
else if (!$force_update_all && $original_topic_data['topic_visibility'] == ITEM_APPROVED && $visibility == ITEM_DELETED)
|
||||
{
|
||||
// If we're soft deleting a topic we only approved posts are soft deleted.
|
||||
// If we're soft deleting a topic we only mark approved posts as soft deleted.
|
||||
$this->set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true, $original_topic_data['topic_visibility']);
|
||||
}
|
||||
else
|
||||
|
@@ -138,4 +138,12 @@ class approve_post extends \phpbb\notification\type\post
|
||||
{
|
||||
return 'post_approved';
|
||||
}
|
||||
|
||||
/**
|
||||
* {inheritDoc}
|
||||
*/
|
||||
public function get_redirect_url()
|
||||
{
|
||||
return $this->get_url();
|
||||
}
|
||||
}
|
||||
|
@@ -275,6 +275,14 @@ abstract class base implements \phpbb\notification\type\type_interface
|
||||
return $this->mark(true, $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* {inheritDoc}
|
||||
*/
|
||||
public function get_redirect_url()
|
||||
{
|
||||
return $this->get_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare to output the notification to the template
|
||||
*
|
||||
|
@@ -110,10 +110,14 @@ class bookmark extends \phpbb\notification\type\post
|
||||
unset($notify_users[$row['user_id']]);
|
||||
|
||||
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
|
||||
$sql = 'UPDATE ' . $this->notifications_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
|
||||
WHERE notification_id = ' . $row['notification_id'];
|
||||
$this->db->sql_query($sql);
|
||||
$update_responders = $notification->add_responders($post);
|
||||
if (!empty($update_responders))
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->notifications_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $update_responders) . '
|
||||
WHERE notification_id = ' . $row['notification_id'];
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
|
@@ -152,10 +152,14 @@ class post extends \phpbb\notification\type\base
|
||||
unset($notify_users[$row['user_id']]);
|
||||
|
||||
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
|
||||
$sql = 'UPDATE ' . $this->notifications_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
|
||||
WHERE notification_id = ' . $row['notification_id'];
|
||||
$this->db->sql_query($sql);
|
||||
$update_responders = $notification->add_responders($post);
|
||||
if (!empty($update_responders))
|
||||
{
|
||||
$sql = 'UPDATE ' . $this->notifications_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $update_responders) . '
|
||||
WHERE notification_id = ' . $row['notification_id'];
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
@@ -206,7 +210,11 @@ class post extends \phpbb\notification\type\base
|
||||
}
|
||||
}
|
||||
|
||||
if ($trimmed_responders_cnt)
|
||||
if ($trimmed_responders_cnt > 20)
|
||||
{
|
||||
$usernames[] = $this->user->lang('NOTIFICATION_MANY_OTHERS');
|
||||
}
|
||||
else if ($trimmed_responders_cnt)
|
||||
{
|
||||
$usernames[] = $this->user->lang('NOTIFICATION_X_OTHERS', $trimmed_responders_cnt);
|
||||
}
|
||||
@@ -269,6 +277,14 @@ class post extends \phpbb\notification\type\base
|
||||
return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "p={$this->item_id}#p{$this->item_id}");
|
||||
}
|
||||
|
||||
/**
|
||||
* {inheritDoc}
|
||||
*/
|
||||
public function get_redirect_url()
|
||||
{
|
||||
return append_sid($this->phpbb_root_path . 'viewtopic.' . $this->php_ext, "t={$this->item_parent_id}&view=unread#unread");
|
||||
}
|
||||
|
||||
/**
|
||||
* Users needed to query before this notification can be displayed
|
||||
*
|
||||
@@ -384,19 +400,27 @@ class post extends \phpbb\notification\type\base
|
||||
// Do not add them as a responder if they were the original poster that created the notification
|
||||
if ($this->get_data('poster_id') == $post['poster_id'])
|
||||
{
|
||||
return array('notification_data' => serialize($this->get_data(false)));
|
||||
return array();
|
||||
}
|
||||
|
||||
$responders = $this->get_data('responders');
|
||||
|
||||
$responders = ($responders === null) ? array() : $responders;
|
||||
|
||||
// Do not add more than 25 responders,
|
||||
// we trim the username list to "a, b, c and x others" anyway
|
||||
// so there is no use to add all of them anyway.
|
||||
if (sizeof($responders) > 25)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($responders as $responder)
|
||||
{
|
||||
// Do not add them as a responder multiple times
|
||||
if ($responder['poster_id'] == $post['poster_id'])
|
||||
{
|
||||
return array('notification_data' => serialize($this->get_data(false)));
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,6 +431,15 @@ class post extends \phpbb\notification\type\base
|
||||
|
||||
$this->set_data('responders', $responders);
|
||||
|
||||
return array('notification_data' => serialize($this->get_data(false)));
|
||||
$serialized_data = serialize($this->get_data(false));
|
||||
|
||||
// If the data is longer then 4000 characters, it would cause a SQL error.
|
||||
// We don't add the username to the list if this is the case.
|
||||
if (utf8_strlen($serialized_data) >= 4000)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
return array('notification_data' => $serialized_data);
|
||||
}
|
||||
}
|
||||
|
@@ -118,6 +118,14 @@ class post_in_queue extends \phpbb\notification\type\post
|
||||
return append_sid($this->phpbb_root_path . 'mcp.' . $this->php_ext, "i=queue&mode=approve_details&f={$this->get_data('forum_id')}&p={$this->item_id}");
|
||||
}
|
||||
|
||||
/**
|
||||
* {inheritDoc}
|
||||
*/
|
||||
public function get_redirect_url()
|
||||
{
|
||||
return parent::get_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for preparing the data for insertion in an SQL query
|
||||
* (The service handles insertion)
|
||||
|
@@ -113,29 +113,6 @@ class quote extends \phpbb\notification\type\post
|
||||
|
||||
$notify_users = $this->check_user_notification_options($auth_read[$post['forum_id']]['f_read'], $options);
|
||||
|
||||
// Try to find the users who already have been notified about replies and have not read the topic since and just update their notifications
|
||||
$update_notifications = array();
|
||||
$sql = 'SELECT n.*
|
||||
FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
|
||||
WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
|
||||
AND n.item_parent_id = ' . (int) self::get_item_parent_id($post) . '
|
||||
AND n.notification_read = 0
|
||||
AND nt.notification_type_id = n.notification_type_id
|
||||
AND nt.notification_type_enabled = 1';
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
// Do not create a new notification
|
||||
unset($notify_users[$row['user_id']]);
|
||||
|
||||
$notification = $this->notification_manager->get_item_type_class($this->get_type(), $row);
|
||||
$sql = 'UPDATE ' . $this->notifications_table . '
|
||||
SET ' . $this->db->sql_build_array('UPDATE', $notification->add_responders($post)) . '
|
||||
WHERE notification_id = ' . $row['notification_id'];
|
||||
$this->db->sql_query($sql);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
return $notify_users;
|
||||
}
|
||||
|
||||
@@ -190,6 +167,14 @@ class quote extends \phpbb\notification\type\post
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {inheritDoc}
|
||||
*/
|
||||
public function get_redirect_url()
|
||||
{
|
||||
return $this->get_url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get email template
|
||||
*
|
||||
|
@@ -98,6 +98,13 @@ interface type_interface
|
||||
*/
|
||||
public function get_url();
|
||||
|
||||
/**
|
||||
* Get the url to redirect after the item has been marked as read
|
||||
*
|
||||
* @return string URL
|
||||
*/
|
||||
public function get_redirect_url();
|
||||
|
||||
/**
|
||||
* URL to unsubscribe to this notification
|
||||
*
|
||||
|
Reference in New Issue
Block a user