function move_forum_content($from_id, $to_id, $sync = true)
{
global $db, $phpbb_dispatcher;
$errors = array();
/**
* Event when we move content from one forum to another
*
* @event core.acp_manage_forums_move_content
* @var int from_id If of the current parent forum
* @var int to_id If of the new parent forum
* @var bool sync Shall we sync the "to"-forum's data
* @var array errors Array of errors, should be strings and not
* language key. If this array is not empty,
* The content will not be moved.
* @since 3.1.0-a1
*/
$vars = array('from_id', 'to_id', 'sync', 'errors');
extract($phpbb_dispatcher->trigger_event('core.acp_manage_forums_move_content', compact($vars)));
// Return if there were errors
if (!empty($errors)) {
return $errors;
}
$table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
foreach ($table_ary as $table) {
$sql = "UPDATE {$table}\n\t\t\t\tSET forum_id = {$to_id}\n\t\t\t\tWHERE forum_id = {$from_id}";
$db->sql_query($sql);
}
unset($table_ary);
$table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
foreach ($table_ary as $table) {
$sql = "DELETE FROM {$table}\n\t\t\t\tWHERE forum_id = {$from_id}";
$db->sql_query($sql);
}
if ($sync) {
// Delete ghost topics that link back to the same forum then resync counters
sync('topic_moved');
sync('forum', 'forum_id', $to_id, false, true);
}
return array();
}