mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[feature/soft-delete] Allow setting the visibility change reason
PHPBB3-9657
This commit is contained in:
parent
dc2835af78
commit
e5377e98c7
2 changed files with 39 additions and 18 deletions
|
@ -185,21 +185,28 @@ class phpbb_content_visibility
|
|||
* @param $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED}
|
||||
* @param $topic_id - int - topic ID to act on
|
||||
* @param $forum_id - int - forum ID where $topic_id resides
|
||||
* @return bool true = success, false = fail
|
||||
* @return void
|
||||
*/
|
||||
static public function set_topic_visibility($visibility, $topic_id, $forum_id)
|
||||
static public function set_topic_visibility($visibility, $topic_id, $forum_id, $user_id, $time, $reason)
|
||||
{
|
||||
global $db;
|
||||
|
||||
$sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_visibility = ' . (int) $visibility . '
|
||||
$data = array(
|
||||
'topic_visibility' => (int) $visibility,
|
||||
'topic_delete_user' => (int) $user_id,
|
||||
'topic_delete_time' => ((int) $time) ?: time(),
|
||||
'topic_delete_reason' => truncate_string($reason, 255, 255, false),
|
||||
);
|
||||
|
||||
$sql = 'UPDATE ' . TOPICS_TABLE . '
|
||||
SET ' . $db->sql_build_array('UPDATE', $data) . '
|
||||
WHERE topic_id = ' . (int) $topic_id;
|
||||
$db->sql_query($sql);
|
||||
|
||||
// if we're approving, disapproving, or deleteing a topic, assume that
|
||||
// we are adjusting _all_ posts in that topic.
|
||||
$status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true);
|
||||
|
||||
return $status;
|
||||
// If we're approving, disapproving, or deleteing a topic
|
||||
// we also update all posts in that topic that need to be changed.
|
||||
// However, we do not set the same reason for every post.
|
||||
self::set_post_visibility($visibility, false, $topic_id, $forum_id, $user_id, $time, '', true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -209,8 +216,9 @@ class phpbb_content_visibility
|
|||
* @param $forum_id - int - forum ID where $topic_id resides
|
||||
* @param $is_starter - bool - is this the first post of the topic
|
||||
* @param $is_latest - bool - is this the last post of the topic
|
||||
* @return void
|
||||
*/
|
||||
static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $is_starter, $is_latest)
|
||||
static public function set_post_visibility($visibility, $post_id, $topic_id, $forum_id, $user_id, $time, $reason, $is_starter, $is_latest)
|
||||
{
|
||||
global $db;
|
||||
|
||||
|
@ -230,21 +238,34 @@ class phpbb_content_visibility
|
|||
}
|
||||
else
|
||||
{
|
||||
// throw new MissingArgumentsException(); <-- a nice idea
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'UPDATE ' . POSTS_TABLE . ' SET post_visibility = ' . (int) $visibility . '
|
||||
$data = array(
|
||||
'post_visibility' => (int) $visibility,
|
||||
'post_delete_user' => (int) $user_id,
|
||||
'post_delete_time' => ((int) $time) ?: time(),
|
||||
'post_delete_reason' => truncate_string($reason, 255, 255, false),
|
||||
);
|
||||
|
||||
$sql = 'UPDATE ' . POSTS_TABLE . '
|
||||
SET ' . $db->sql_build_array('UPDATE', $data) . '
|
||||
WHERE ' . $where_sql;
|
||||
$db->sql_query($sql);
|
||||
|
||||
// Sync the first/last topic information if needed
|
||||
if ($is_starter || $is_latest)
|
||||
{
|
||||
if ($topic_id)
|
||||
{
|
||||
update_post_information('topic', $topic_id, false);
|
||||
}
|
||||
if ($forum_id)
|
||||
{
|
||||
update_post_information('forum', $forum_id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the current logged-in user soft-delete posts?
|
||||
|
|
|
@ -1411,7 +1411,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id
|
|||
/**
|
||||
* Delete Post
|
||||
*/
|
||||
function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
|
||||
function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $softdelete_reason = '')
|
||||
{
|
||||
global $db, $user, $auth;
|
||||
global $config, $phpEx, $phpbb_root_path;
|
||||
|
@ -1466,7 +1466,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
|
|||
|
||||
if ($is_soft)
|
||||
{
|
||||
phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id));
|
||||
phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, ($data['topic_first_post_id'] == $post_id), ($data['topic_last_post_id'] == $post_id));
|
||||
phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data);
|
||||
}
|
||||
else
|
||||
|
@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
|
|||
if ($is_soft)
|
||||
{
|
||||
$topic_row = array();
|
||||
phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id);
|
||||
phpbb_content_visibility::set_topic_visibility(ITEM_DELETED, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason);
|
||||
phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data);
|
||||
}
|
||||
else
|
||||
|
@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
|
|||
case 'delete_last_post':
|
||||
if ($is_soft)
|
||||
{
|
||||
phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, $user->data['user_id'], time(), $softdelete_reason, false, true);
|
||||
phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data);
|
||||
phpbb_content_visibility::set_post_visibility(ITEM_DELETED, $post_id, $topic_id, $forum_id, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue