/** * @dataProvider fixture_data */ public function test_update($description, $from, $to, $expected_result_count, $expected_notify_status) { $db = $this->new_dbal(); phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $from, $to); $sql = 'SELECT COUNT(*) AS remaining_rows FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $to; $result = $db->sql_query($sql); $result_count = $db->sql_fetchfield('remaining_rows'); $db->sql_freeresult($result); $this->assertEquals($expected_result_count, $result_count); // user id of 1 is the user being updated $sql = 'SELECT notify_status FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $to . ' AND user_id = 1'; $result = $db->sql_query($sql); $notify_status = $db->sql_fetchfield('notify_status'); $db->sql_freeresult($result); $this->assertEquals($expected_notify_status, $notify_status); }
/** * Merge selected topics into selected topic */ function merge_topics($forum_id, $topic_ids, $to_topic_id) { global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request; if (!sizeof($topic_ids)) { $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']); return; } if (!$to_topic_id) { $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); return; } $sync_topics = array_merge($topic_ids, array($to_topic_id)); $topic_data = phpbb_get_topic_data($sync_topics, 'm_merge'); if (!sizeof($topic_data) || empty($topic_data[$to_topic_id])) { $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); return; } $sync_forums = array(); foreach ($topic_data as $data) { $sync_forums[$data['forum_id']] = $data['forum_id']; } $topic_data = $topic_data[$to_topic_id]; $post_id_list = $request->variable('post_id_list', array(0)); $start = $request->variable('start', 0); if (!sizeof($post_id_list) && sizeof($topic_ids)) { $sql = 'SELECT post_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $topic_ids); $result = $db->sql_query($sql); $post_id_list = array(); while ($row = $db->sql_fetchrow($result)) { $post_id_list[] = $row['post_id']; } $db->sql_freeresult($result); } if (!sizeof($post_id_list)) { $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); return; } if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge'))) { return; } $redirect = $request->variable('redirect', build_url(array('quickmod'))); $s_hidden_fields = build_hidden_fields(array('i' => 'main', 'f' => $forum_id, 'post_id_list' => $post_id_list, 'to_topic_id' => $to_topic_id, 'mode' => 'forum_view', 'action' => 'merge_topics', 'start' => $start, 'redirect' => $redirect, 'topic_id_list' => $topic_ids)); $return_link = ''; if (confirm_box(true)) { $to_forum_id = $topic_data['forum_id']; move_posts($post_id_list, $to_topic_id, false); $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array('forum_id' => $to_forum_id, 'topic_id' => $to_topic_id, $topic_data['topic_title'])); // Message and return links $success_msg = 'POSTS_MERGED_SUCCESS'; if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) { include $phpbb_root_path . 'includes/functions_database_helper.' . $phpEx; } // Update the topic watch table. phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id); // Update the bookmarks table. phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $topic_ids, $to_topic_id); // Re-sync the topics and forums because the auto-sync was deactivated in the call of move_posts() sync('topic_reported', 'topic_id', $sync_topics); sync('topic_attachment', 'topic_id', $sync_topics); sync('topic', 'topic_id', $sync_topics, true); sync('forum', 'forum_id', $sync_forums, true, true); // Link to the new topic $return_link .= ($return_link ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $to_forum_id . '&t=' . $to_topic_id) . '">', '</a>'); $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.{$phpEx}?f={$to_forum_id}&t={$to_topic_id}"); $redirect = reapply_sid($redirect); meta_refresh(3, $redirect); trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); } else { confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields); } }
/** * Merge selected posts into selected topic */ function merge_posts($topic_id, $to_topic_id) { global $db, $template, $user, $phpEx, $phpbb_root_path, $auth; if (!$to_topic_id) { $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); return; } $topic_data = get_topic_data(array($to_topic_id), 'm_merge'); if (!sizeof($topic_data)) { $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); return; } $topic_data = $topic_data[$to_topic_id]; $post_id_list = request_var('post_id_list', array(0)); $start = request_var('start', 0); if (!sizeof($post_id_list)) { $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']); return; } if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge'))) { return; } $redirect = request_var('redirect', build_url(array('quickmod'))); $s_hidden_fields = build_hidden_fields(array('i' => 'main', 'post_id_list' => $post_id_list, 'to_topic_id' => $to_topic_id, 'mode' => 'topic_view', 'action' => 'merge_posts', 'start' => $start, 'redirect' => $redirect, 't' => $topic_id)); $success_msg = $return_link = ''; if (confirm_box(true)) { $to_forum_id = $topic_data['forum_id']; move_posts($post_id_list, $to_topic_id); add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']); // Message and return links $success_msg = 'POSTS_MERGED_SUCCESS'; // Does the original topic still exist? If yes, link back to it $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . ' WHERE topic_id = ' . $topic_id; $result = $db->sql_query_limit($sql, 1); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if ($row) { $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&t=' . $topic_id) . '">', '</a>'); } else { if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) { include $phpbb_root_path . 'includes/functions_database_helper.' . $phpEx; } // If the topic no longer exist, we will update the topic watch table. phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', array($topic_id), $to_topic_id); // If the topic no longer exist, we will update the bookmarks table. phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', array($topic_id), $to_topic_id); } // Link to the new topic $return_link .= ($return_link ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $to_forum_id . '&t=' . $to_topic_id) . '">', '</a>'); } else { confirm_box(false, 'MERGE_POSTS', $s_hidden_fields); } $redirect = request_var('redirect', "index.{$phpEx}"); $redirect = reapply_sid($redirect); if (!$success_msg) { return; } else { meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$to_forum_id}&t={$to_topic_id}")); trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); } }