1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-07 16:15:22 +02:00

[feature/soft-delete] Fix restoring a post via editing

PHPBB3-9567
This commit is contained in:
Joas Schilling 2012-10-08 23:09:12 +02:00
parent 53e01bba19
commit e447a0fa07
3 changed files with 18 additions and 50 deletions

View File

@ -311,6 +311,12 @@ class phpbb_content_visibility
} }
else if ($is_starter && $topic_id) else if ($is_starter && $topic_id)
{ {
if (!function_exists('sync'))
{
global $phpEx, $phpbb_root_path;
include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
}
// ... so we need to use sync, if the first post is changed. // ... so we need to use sync, if the first post is changed.
// The forum is resynced recursive by sync() itself. // The forum is resynced recursive by sync() itself.
sync('topic', 'topic_id', $topic_id, true); sync('topic', 'topic_id', $topic_id, true);

View File

@ -1481,7 +1481,7 @@ function delete_post($forum_id, $topic_id, $post_id, &$data, $is_soft = false, $
$db->sql_transaction('commit'); $db->sql_transaction('commit');
// Collect the necessary information for updating the tables // Collect the necessary information for updating the tables
$sql_data[FORUMS_TABLE] = ''; $sql_data[FORUMS_TABLE] = $sql_data[TOPICS_TABLE] = '';
switch ($post_mode) switch ($post_mode)
{ {
case 'delete_topic': case 'delete_topic':

View File

@ -274,7 +274,7 @@ switch ($mode)
break; break;
case 'soft_delete': case 'soft_delete':
if ($user->data['is_registered'] && $auth->acl_gets('f_softdelete', 'm_softdelete', $forum_id)) if ($user->data['is_registered'] && phpbb_content_visibility::can_soft_delete($forum_id, $post_data['poster_id'], $post_data['post_edit_locked']))
{ {
$is_authed = true; $is_authed = true;
} }
@ -886,53 +886,15 @@ if ($submit || $preview || $refresh)
if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id)) if ($submit && $mode == 'edit' && $post_data['post_visibility'] == ITEM_DELETED && !isset($_POST['soft_delete']) && $auth->acl_get('m_approve', $forum_id))
{ {
//@todo: REMOVE the magic! $is_first_post = ($post_id == $post_data['topic_first_post_id'] || !$post_data['topic_replies']);
// if this is the first post of the topic, restore the whole topic $is_last_post = ($post_id == $post_data['topic_last_post_id'] || !$post_data['topic_replies']);
if ($post_id == $post_data['topic_first_post_id']) $updated_post_data = phpbb_content_visibility::set_post_visibility(ITEM_APPROVED, $post_id, $post_data['topic_id'], $post_data['forum_id'], $user->data['user_id'], time(), '', $is_first_post, $is_last_post);
if (!empty($updated_post_data))
{ {
// that means we need to gather data for all posts in the topic, not // Update the post_data, so we don't need to refetch it.
// just the one being edited $post_data = array_merge($post_data, $updated_post_data);
$sql = 'SELECT post_id, poster_id, post_subject, post_postcount
FROM ' . POSTS_TABLE . '
WHERE topic_id = ' . $post_data['topic_id'] . '
AND post_visibility = ' . ITEM_DELETED;
$result = $db->sql_query($sql);
$post_ids = array();
while ($row = $db->sql_fetchrow($result))
{
$post_ids[] = $row['post_id'];
$posts_data[$row['post_id']] = array(
// all posts are from the same topic and forum
// and are deleted because of the constraints to the query above
'topic_id' => $post_data['topic_id'],
'forum_id' => $post_data['forum_id'],
'topic_replies' => $post_data['topic_replies'],
'topic_first_post_id' => $post_data['topic_first_post_id'],
'post_visibility' => ITEM_DELETED,
'poster_id' => $row['poster_id'],
'post_subject' => $row['post_subject'],
'post_postcount'=> $row['post_postcount'],
);
} }
// No direct query is needed, just update the array
$post_data['post_visibility'] = $post_data['topic_visibility'] = ITEM_APPROVED;
}
else
{
$post_ids = array($post_id);
$posts_data = array($post_id => $post_data);
$post_data['post_visibility'] = ITEM_APPROVED;
}
// don't feel that a confirm_box is needed for this
// do not return / trigger_error after this because the post content can also be changed
phpbb_content_visibility::unhide_posts_topics('restore', $posts_data, $post_ids);
} }
// Parse subject // Parse subject
@ -1598,10 +1560,10 @@ function handle_post_delete($forum_id, $topic_id, $post_id, &$post_data, $is_sof
'post_reported' => $post_data['post_reported'], 'post_reported' => $post_data['post_reported'],
'post_time' => $post_data['post_time'], 'post_time' => $post_data['post_time'],
'poster_id' => $post_data['poster_id'], 'poster_id' => $post_data['poster_id'],
'post_postcount' => $post_data['post_postcount'] 'post_postcount' => $post_data['post_postcount'],
); );
$next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft); $next_post_id = delete_post($forum_id, $topic_id, $post_id, $data, $is_soft);//@todo: $reason);
$post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username']; $post_username = ($post_data['poster_id'] == ANONYMOUS && !empty($post_data['post_username'])) ? $post_data['post_username'] : $post_data['username'];
if ($next_post_id === false) if ($next_post_id === false)