aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2012-09-28 16:53:38 +0200
committerJoas Schilling <nickvergessen@gmx.de>2012-09-28 16:53:38 +0200
commite5377e98c7eca8754f423ef495e4b092590f4e03 (patch)
tree6dd5b768926a11ac3320ecc5d80117ff51c8b78b /phpBB/includes
parentdc2835af785c6bf0209d91791f27a931fb334a5b (diff)
downloadforums-e5377e98c7eca8754f423ef495e4b092590f4e03.tar
forums-e5377e98c7eca8754f423ef495e4b092590f4e03.tar.gz
forums-e5377e98c7eca8754f423ef495e4b092590f4e03.tar.bz2
forums-e5377e98c7eca8754f423ef495e4b092590f4e03.tar.xz
forums-e5377e98c7eca8754f423ef495e4b092590f4e03.zip
[feature/soft-delete] Allow setting the visibility change reason
PHPBB3-9657
Diffstat (limited to 'phpBB/includes')
-rw-r--r--phpBB/includes/content_visibility.php49
-rw-r--r--phpBB/includes/functions_posting.php8
2 files changed, 39 insertions, 18 deletions
diff --git a/phpBB/includes/content_visibility.php b/phpBB/includes/content_visibility.php
index 55adf00e8c..165c28f1af 100644
--- a/phpBB/includes/content_visibility.php
+++ b/phpBB/includes/content_visibility.php
@@ -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,19 +238,32 @@ 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)
{
- update_post_information('topic', $topic_id, false);
- update_post_information('forum', $forum_id, false);
+ if ($topic_id)
+ {
+ update_post_information('topic', $topic_id, false);
+ }
+ if ($forum_id)
+ {
+ update_post_information('forum', $forum_id, false);
+ }
}
}
diff --git a/phpBB/includes/functions_posting.php b/phpBB/includes/functions_posting.php
index b63a41df7d..38f173330a 100644
--- a/phpBB/includes/functions_posting.php
+++ b/phpBB/includes/functions_posting.php
@@ -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
{