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 $visibility - int - element of {ITEM_UNAPPROVED, ITEM_APPROVED, ITEM_DELETED}
|
||||||
* @param $topic_id - int - topic ID to act on
|
* @param $topic_id - int - topic ID to act on
|
||||||
* @param $forum_id - int - forum ID where $topic_id resides
|
* @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;
|
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;
|
WHERE topic_id = ' . (int) $topic_id;
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
// if we're approving, disapproving, or deleteing a topic, assume that
|
// If we're approving, disapproving, or deleteing a topic
|
||||||
// we are adjusting _all_ posts in that topic.
|
// we also update all posts in that topic that need to be changed.
|
||||||
$status = self::set_post_visibility($visibility, false, $topic_id, $forum_id, true, true);
|
// 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);
|
||||||
return $status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,8 +216,9 @@ class phpbb_content_visibility
|
||||||
* @param $forum_id - int - forum ID where $topic_id resides
|
* @param $forum_id - int - forum ID where $topic_id resides
|
||||||
* @param $is_starter - bool - is this the first post of the topic
|
* @param $is_starter - bool - is this the first post of the topic
|
||||||
* @param $is_latest - bool - is this the last 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;
|
global $db;
|
||||||
|
|
||||||
|
@ -230,19 +238,32 @@ class phpbb_content_visibility
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// throw new MissingArgumentsException(); <-- a nice idea
|
return;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$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;
|
WHERE ' . $where_sql;
|
||||||
$db->sql_query($sql);
|
$db->sql_query($sql);
|
||||||
|
|
||||||
// Sync the first/last topic information if needed
|
// Sync the first/last topic information if needed
|
||||||
if ($is_starter || $is_latest)
|
if ($is_starter || $is_latest)
|
||||||
{
|
{
|
||||||
update_post_information('topic', $topic_id, false);
|
if ($topic_id)
|
||||||
update_post_information('forum', $forum_id, false);
|
{
|
||||||
|
update_post_information('topic', $topic_id, false);
|
||||||
|
}
|
||||||
|
if ($forum_id)
|
||||||
|
{
|
||||||
|
update_post_information('forum', $forum_id, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1411,7 +1411,7 @@ function user_notification($mode, $subject, $topic_title, $forum_name, $forum_id
|
||||||
/**
|
/**
|
||||||
* Delete Post
|
* 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 $db, $user, $auth;
|
||||||
global $config, $phpEx, $phpbb_root_path;
|
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)
|
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);
|
phpbb_content_visibility::hide_post($forum_id, time(), $data, $sql_data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1501,7 +1501,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
|
||||||
if ($is_soft)
|
if ($is_soft)
|
||||||
{
|
{
|
||||||
$topic_row = array();
|
$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);
|
phpbb_content_visibility::hide_topic($topic_id, $forum_id, $topic_row, $sql_data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1548,8 +1548,8 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false)
|
||||||
case 'delete_last_post':
|
case 'delete_last_post':
|
||||||
if ($is_soft)
|
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::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
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue