function deleteCategories($categories, $moveBoardsTo = null)
{
    global $sourcedir, $smcFunc, $cat_tree;
    require_once $sourcedir . '/Subs-Boards.php';
    getBoardTree();
    // With no category set to move the boards to, delete them all.
    if ($moveBoardsTo === null) {
        $request = $smcFunc['db_query']('', '
			SELECT id_board
			FROM {db_prefix}boards
			WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories));
        $boards_inside = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $boards_inside[] = $row['id_board'];
        }
        $smcFunc['db_free_result']($request);
        if (!empty($boards_inside)) {
            deleteBoards($boards_inside, null);
        }
    } elseif (in_array($moveBoardsTo, $categories)) {
        trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
    } else {
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}boards
			SET id_cat = {int:new_parent_cat}
			WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories, 'new_parent_cat' => $moveBoardsTo));
    }
    // Noone will ever be able to collapse these categories anymore.
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}collapsed_categories
		WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories));
    // Do the deletion of the category itself
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}categories
		WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories));
    // Log what we've done.
    foreach ($categories as $category) {
        logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
    }
    // Get all boards back into the right order.
    reorderBoards();
}
Exemplo n.º 2
0
function deleteBoards($boards_to_remove, $moveChildrenTo = null)
{
    global $sourcedir, $boards, $smcFunc;
    // No boards to delete? Return!
    if (empty($boards_to_remove)) {
        return;
    }
    getBoardTree();
    // If $moveChildrenTo is set to null, include the children in the removal.
    if ($moveChildrenTo === null) {
        // Get a list of the child boards that will also be removed.
        $child_boards_to_remove = array();
        foreach ($boards_to_remove as $board_to_remove) {
            recursiveBoards($child_boards_to_remove, $boards[$board_to_remove]['tree']);
        }
        // Merge the children with their parents.
        if (!empty($child_boards_to_remove)) {
            $boards_to_remove = array_unique(array_merge($boards_to_remove, $child_boards_to_remove));
        }
    } else {
        foreach ($boards_to_remove as $id_board) {
            // !!! Separate category?
            if ($moveChildrenTo === 0) {
                fixChildren($id_board, 0, 0);
            } else {
                fixChildren($id_board, $boards[$moveChildrenTo]['level'] + 1, $moveChildrenTo);
            }
        }
    }
    // Delete ALL topics in the selected boards (done first so topics can't be marooned.)
    $request = $smcFunc['db_query']('', '
		SELECT id_topic
		FROM {db_prefix}topics
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    $topics = array();
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $topics[] = $row['id_topic'];
    }
    $smcFunc['db_free_result']($request);
    require_once $sourcedir . '/RemoveTopic.php';
    removeTopics($topics, false);
    // Delete the board's logs.
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}log_mark_read
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}log_boards
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}log_notify
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    // Delete this board's moderators.
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}moderators
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    // Delete any extra events in the calendar.
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}calendar
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    // Delete any message icons that only appear on these boards.
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}message_icons
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    // Delete the boards.
    $smcFunc['db_query']('', '
		DELETE FROM {db_prefix}boards
		WHERE id_board IN ({array_int:boards_to_remove})', array('boards_to_remove' => $boards_to_remove));
    // Latest message/topic might not be there anymore.
    updateStats('message');
    updateStats('topic');
    updateSettings(array('calendar_updated' => time()));
    // Plus reset the cache to stop people getting odd results.
    updateSettings(array('settings_updated' => time()));
    // Clean the cache as well.
    clean_cache('data');
    // Let's do some serious logging.
    foreach ($boards_to_remove as $id_board) {
        logAction('delete_board', array('boardname' => $boards[$id_board]['name']), 'admin');
    }
    reorderBoards();
}
Exemplo n.º 3
0
function doStep2()
{
    global $convert_data, $from_prefix, $to_prefix, $modSettings, $command_line;
    global $smcFunc, $sourcedir, $current_step;
    $current_step = 2;
    $_GET['step'] = '2';
    $debug = false;
    if (isset($_REQUEST['debug'])) {
        $debug = true;
    }
    print_line(($command_line ? ' * ' : '') . 'Recalculating forum statistics... ', false);
    if ($_GET['substep'] <= 0) {
        if ($debug) {
            print_line('Get all members with wrong number of personal messages..');
        }
        // Get all members with wrong number of personal messages.
        $request = convert_query("\n\t\t\tSELECT mem.id_member, COUNT(pmr.id_pm) AS real_num, mem.instant_messages\n\t\t\tFROM {$to_prefix}members AS mem\n\t\t\t\tLEFT JOIN {$to_prefix}pm_recipients AS pmr ON (mem.id_member = pmr.id_member AND pmr.deleted = 0)\n\t\t\tGROUP BY mem.id_member\n\t\t\tHAVING real_num != instant_messages");
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}members\n\t\t\t\tSET instant_messages = {$row['real_num']}\n\t\t\t\tWHERE id_member = {$row['id_member']}\n\t\t\t\tLIMIT 1");
            pastTime(0);
        }
        $smcFunc['db_free_result']($request);
        if ($debug) {
            print_line('Correct all unread messages..');
        }
        $request = convert_query("\n\t\t\tSELECT mem.id_member, COUNT(pmr.id_pm) AS real_num, mem.unread_messages\n\t\t\tFROM {$to_prefix}members AS mem\n\t\t\t\tLEFT JOIN {$to_prefix}pm_recipients AS pmr ON (mem.id_member = pmr.id_member AND pmr.deleted = 0 AND pmr.is_read = 0)\n\t\t\tGROUP BY mem.id_member\n\t\t\tHAVING real_num != unread_messages");
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}members\n\t\t\t\tSET unread_messages = {$row['real_num']}\n\t\t\t\tWHERE id_member = {$row['id_member']}\n\t\t\t\tLIMIT 1");
            pastTime(0);
        }
        $smcFunc['db_free_result']($request);
        pastTime(1);
    }
    if ($_GET['substep'] <= 1) {
        if ($debug) {
            print_line('Correct boards with incorrect msg ids..');
        }
        $request = convert_query("\n\t\t\tSELECT id_board, MAX(id_msg) AS id_last_msg, MAX(modified_time) AS last_edited\n\t\t\tFROM {$to_prefix}messages\n\t\t\tGROUP BY id_board");
        $modifyData = array();
        $modifyMsg = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\tSET id_last_msg = {$row['id_last_msg']}, id_msg_updated = {$row['id_last_msg']}\n\t\t\t\tWHERE id_board = {$row['id_board']}\n\t\t\t\tLIMIT 1");
            $modifyData[$row['id_board']] = array('last_msg' => $row['id_last_msg'], 'last_edited' => $row['last_edited']);
            $modifyMsg[] = $row['id_last_msg'];
        }
        $smcFunc['db_free_result']($request);
        // Are there any boards where the updated message is not the last?
        if (!empty($modifyMsg)) {
            if ($debug) {
                print_line('Correct any boards that do not show the correct last message..');
            }
            $request = convert_query("\n\t\t\t\tSELECT id_board, id_msg, modified_time, poster_time\n\t\t\t\tFROM {$to_prefix}messages\n\t\t\t\tWHERE id_msg IN (" . implode(',', $modifyMsg) . ")");
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                // Have we got a message modified before this was posted?
                if (max($row['modified_time'], $row['poster_time']) < $modifyData[$row['id_board']]['last_edited']) {
                    // Work out the ID of the message (This seems long but it won't happen much.
                    $request2 = convert_query("\n\t\t\t\t\t\tSELECT id_msg\n\t\t\t\t\t\tFROM {$to_prefix}messages\n\t\t\t\t\t\tWHERE modified_time = " . $modifyData[$row['id_board']]['last_edited'] . "\n\t\t\t\t\t\tLIMIT 1");
                    if ($smcFunc['db_num_rows']($request2) != 0) {
                        list($id_msg) = $smcFunc['db_fetch_row']($request2);
                        convert_query("\n\t\t\t\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\t\t\t\tSET id_msg_updated = {$id_msg}\n\t\t\t\t\t\t\tWHERE id_board = {$row['id_board']}\n\t\t\t\t\t\t\tLIMIT 1");
                    }
                    $smcFunc['db_free_result']($request2);
                }
            }
            $smcFunc['db_free_result']($request);
        }
        pastTime(2);
    }
    if ($_GET['substep'] <= 2) {
        if ($debug) {
            print_line('Correct any incorrect groups..');
        }
        $request = convert_query("\n\t\t\tSELECT id_group\n\t\t\tFROM {$to_prefix}membergroups\n\t\t\tWHERE min_posts = -1");
        $all_groups = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $all_groups[] = $row['id_group'];
        }
        $smcFunc['db_free_result']($request);
        $request = convert_query("\n\t\t\tSELECT id_board, member_groups\n\t\t\tFROM {$to_prefix}boards\n\t\t\tWHERE FIND_IN_SET(0, member_groups)");
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\tSET member_groups = '" . implode(',', array_unique(array_merge($all_groups, explode(',', $row['member_groups'])))) . "'\n\t\t\t\tWHERE id_board = {$row['id_board']}\n\t\t\t\tLIMIT 1");
        }
        $smcFunc['db_free_result']($request);
        pastTime(3);
    }
    if ($_GET['substep'] <= 3) {
        if ($debug) {
            print_line('Update our statitics..');
        }
        // Get the number of messages...
        $result = convert_query("\n\t\t\tSELECT COUNT(*) AS total_messages, MAX(id_msg) AS max_msg_id\n\t\t\tFROM {$to_prefix}messages");
        $row = $smcFunc['db_fetch_assoc']($result);
        $smcFunc['db_free_result']($result);
        // Update the latest member.  (highest id_member)
        $result = convert_query("\n\t\t\tSELECT id_member AS latest_member, real_name AS latest_real_name\n\t\t\tFROM {$to_prefix}members\n\t\t\tORDER BY id_member DESC\n\t\t\tLIMIT 1");
        if ($smcFunc['db_num_rows']($result)) {
            $row += $smcFunc['db_fetch_assoc']($result);
        }
        $smcFunc['db_free_result']($result);
        // Update the member count.
        $result = convert_query("\n\t\t\tSELECT COUNT(*) AS total_members\n\t\t\tFROM {$to_prefix}members");
        $row += $smcFunc['db_fetch_assoc']($result);
        $smcFunc['db_free_result']($result);
        // Get the number of topics.
        $result = convert_query("\n\t\t\tSELECT COUNT(*) AS total_topics\n\t\t\tFROM {$to_prefix}topics");
        $row += $smcFunc['db_fetch_assoc']($result);
        $smcFunc['db_free_result']($result);
        $smcFunc['db_insert']('replace', '{db_prefix}settings', array('variable' => 'string', 'value' => 'string'), array(array('latest_member', $row['latest_member']), array('latest_real_name', $row['latest_real_name']), array('total_members', $row['total_members']), array('total_messages', $row['total_messages']), array('max_msg_id', $row['max_msg_id']), array('total_topics', $row['total_topics']), array('disable_hash_time', time() + 7776000)), array('name'));
        pastTime(4);
    }
    if ($_GET['substep'] <= 4) {
        if ($debug) {
            print_line('Correct any posts groups..');
        }
        $request = convert_query("\n\t\t\tSELECT id_group, min_posts\n\t\t\tFROM {$to_prefix}membergroups\n\t\t\tWHERE min_posts != -1\n\t\t\tORDER BY min_posts DESC");
        $post_groups = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $post_groups[$row['min_posts']] = $row['id_group'];
        }
        $smcFunc['db_free_result']($request);
        $request = convert_query("\n\t\t\tSELECT id_member, posts\n\t\t\tFROM {$to_prefix}members");
        $mg_updates = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $group = 4;
            foreach ($post_groups as $min_posts => $group_id) {
                if ($row['posts'] >= $min_posts) {
                    $group = $group_id;
                    break;
                }
            }
            $mg_updates[$group][] = $row['id_member'];
        }
        $smcFunc['db_free_result']($request);
        foreach ($mg_updates as $group_to => $update_members) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}members\n\t\t\t\tSET id_post_group = {$group_to}\n\t\t\t\tWHERE id_member IN (" . implode(', ', $update_members) . ")\n\t\t\t\tLIMIT " . count($update_members));
        }
        // This isn't completely related, but should be rather quick.
        convert_query("\n\t\t\tUPDATE {$to_prefix}members\n\t\t\tSET icq = ''\n\t\t\tWHERE icq = '0'");
        pastTime(5);
    }
    if ($_GET['substep'] <= 5) {
        if ($debug) {
            print_line('Correct all board topics/post counts..');
        }
        // Needs to be done separately for each board.
        $result_boards = convert_query("\n\t\t\tSELECT id_board\n\t\t\tFROM {$to_prefix}boards");
        $boards = array();
        while ($row_boards = $smcFunc['db_fetch_assoc']($result_boards)) {
            $boards[] = $row_boards['id_board'];
        }
        $smcFunc['db_free_result']($result_boards);
        foreach ($boards as $id_board) {
            // Get the number of topics, and iterate through them.
            $result_topics = convert_query("\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM {$to_prefix}topics\n\t\t\t\tWHERE id_board = {$id_board}");
            list($num_topics) = $smcFunc['db_fetch_row']($result_topics);
            $smcFunc['db_free_result']($result_topics);
            // Find how many messages are in the board.
            $result_posts = convert_query("\n\t\t\t\tSELECT COUNT(*)\n\t\t\t\tFROM {$to_prefix}messages\n\t\t\t\tWHERE id_board = {$id_board}");
            list($num_posts) = $smcFunc['db_fetch_row']($result_posts);
            $smcFunc['db_free_result']($result_posts);
            // Fix the board's totals.
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\tSET num_topics = {$num_topics}, num_posts = {$num_posts}\n\t\t\t\tWHERE id_board = {$id_board}\n\t\t\t\tLIMIT 1");
        }
        pastTime(6);
    }
    // Remove all topics that have zero messages in the messages table.
    if ($_GET['substep'] <= 6) {
        if ($debug) {
            print_line('Removing any topics that have zero messages..');
        }
        while (true) {
            $resultTopic = convert_query("\n\t\t\t\tSELECT t.id_topic, COUNT(m.id_msg) AS num_msg\n\t\t\t\tFROM {$to_prefix}topics AS t\n\t\t\t\t\tLEFT JOIN {$to_prefix}messages AS m ON (m.id_topic = t.id_topic)\n\t\t\t\tGROUP BY t.id_topic\n\t\t\t\tHAVING num_msg = 0\n\t\t\t\tLIMIT {$_REQUEST['start']}, " . (!empty($convert_data['step2_block_size']) ? $convert_data['step2_block_size'] : 200));
            $numRows = $smcFunc['db_num_rows']($resultTopic);
            if ($numRows > 0) {
                $stupidTopics = array();
                while ($topicArray = $smcFunc['db_fetch_assoc']($resultTopic)) {
                    $stupidTopics[] = $topicArray['id_topic'];
                }
                convert_query("\n\t\t\t\t\tDELETE FROM {$to_prefix}topics\n\t\t\t\t\tWHERE id_topic IN (" . implode(',', $stupidTopics) . ')
					LIMIT ' . count($stupidTopics));
                convert_query("\n\t\t\t\t\tDELETE FROM {$to_prefix}log_topics\n\t\t\t\t\tWHERE id_topic IN (" . implode(',', $stupidTopics) . ')');
            }
            $smcFunc['db_free_result']($resultTopic);
            if ($numRows < 200) {
                break;
            }
            $_REQUEST['start'] += 200;
            pastTime(6);
        }
        $_REQUEST['start'] = 0;
        pastTime(7);
    }
    // Get the correct number of replies.
    if ($_GET['substep'] <= 7) {
        if ($debug) {
            print_line('Correct the number of replies..');
        }
        // Make sure we have the function "getMsgMemberID"
        require_once $sourcedir . '/Subs-Boards.php';
        while (true) {
            $resultTopic = convert_query("\n\t\t\t\tSELECT\n\t\t\t\t\tt.id_topic, MIN(m.id_msg) AS myid_first_msg, t.id_first_msg,\n\t\t\t\t\tMAX(m.id_msg) AS myid_last_msg, t.id_last_msg, COUNT(m.id_msg) - 1 AS my_num_replies,\n\t\t\t\t\tt.num_replies\n\t\t\t\tFROM {$to_prefix}topics AS t\n\t\t\t\t\tLEFT JOIN {$to_prefix}messages AS m ON (m.id_topic = t.id_topic)\n\t\t\t\tGROUP BY t.id_topic\n\t\t\t\tHAVING id_first_msg != myid_first_msg OR id_last_msg != myid_last_msg OR num_replies != my_num_replies\n\t\t\t\tLIMIT {$_REQUEST['start']}, " . (!empty($convert_data['step2_block_size']) ? $convert_data['step2_block_size'] : 200));
            $numRows = $smcFunc['db_num_rows']($resultTopic);
            while ($topicArray = $smcFunc['db_fetch_assoc']($resultTopic)) {
                $memberStartedID = getMsgMemberID($topicArray['myid_first_msg']);
                $memberUpdatedID = getMsgMemberID($topicArray['myid_last_msg']);
                convert_query("\n\t\t\t\t\tUPDATE {$to_prefix}topics\n\t\t\t\t\tSET id_first_msg = '{$topicArray['myid_first_msg']}',\n\t\t\t\t\t\tid_member_started = '{$memberStartedID}', id_last_msg = '{$topicArray['myid_last_msg']}',\n\t\t\t\t\t\tid_member_updated = '{$memberUpdatedID}', num_replies = '{$topicArray['my_num_replies']}'\n\t\t\t\t\tWHERE id_topic = {$topicArray['id_topic']}\n\t\t\t\t\tLIMIT 1");
            }
            $smcFunc['db_free_result']($resultTopic);
            if ($numRows < 200) {
                break;
            }
            $_REQUEST['start'] += 100;
            pastTime(7);
        }
        $_REQUEST['start'] = 0;
        pastTime(8);
    }
    // Fix id_cat, id_parent, and child_level.
    if ($_GET['substep'] <= 8) {
        if ($debug) {
            print_line('Fix the Categories and board layout..');
        }
        // First, let's get an array of boards and parents.
        $request = convert_query("\n\t\t\tSELECT id_board, id_parent, id_cat\n\t\t\tFROM {$to_prefix}boards");
        $child_map = array();
        $cat_map = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $child_map[$row['id_parent']][] = $row['id_board'];
            $cat_map[$row['id_board']] = $row['id_cat'];
        }
        $smcFunc['db_free_result']($request);
        // Let's look for any boards with obviously invalid parents...
        foreach ($child_map as $parent => $dummy) {
            if ($parent != 0 && !isset($cat_map[$parent])) {
                // Perhaps it was supposed to be their id_cat?
                foreach ($dummy as $board) {
                    if (empty($cat_map[$board])) {
                        $cat_map[$board] = $parent;
                    }
                }
                $child_map[0] = array_merge(isset($child_map[0]) ? $child_map[0] : array(), $dummy);
                unset($child_map[$parent]);
            }
        }
        // The above id_parents and id_cats may all be wrong; we know id_parent = 0 is right.
        $solid_parents = array(array(0, 0));
        $fixed_boards = array();
        while (!empty($solid_parents)) {
            list($parent, $level) = array_pop($solid_parents);
            if (!isset($child_map[$parent])) {
                continue;
            }
            // Fix all of this board's children.
            foreach ($child_map[$parent] as $board) {
                if ($parent != 0) {
                    $cat_map[$board] = $cat_map[$parent];
                }
                $fixed_boards[$board] = array($parent, $cat_map[$board], $level);
                $solid_parents[] = array($board, $level + 1);
            }
        }
        foreach ($fixed_boards as $board => $fix) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\tSET id_parent = " . (int) $fix[0] . ", id_cat = " . (int) $fix[1] . ", child_level = " . (int) $fix[2] . "\n\t\t\t\tWHERE id_board = " . (int) $board . "\n\t\t\t\tLIMIT 1");
        }
        // Leftovers should be brought to the root.  They had weird parents we couldn't find.
        if (count($fixed_boards) < count($cat_map)) {
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\tSET child_level = 0, id_parent = 0" . (empty($fixed_boards) ? '' : "\n\t\t\t\tWHERE id_board NOT IN (" . implode(', ', array_keys($fixed_boards)) . ")"));
        }
        // Last check: any boards not in a good category?
        $request = convert_query("\n\t\t\tSELECT id_cat\n\t\t\tFROM {$to_prefix}categories");
        $real_cats = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $real_cats[] = $row['id_cat'];
        }
        $smcFunc['db_free_result']($request);
        $fix_cats = array();
        foreach ($cat_map as $board => $cat) {
            if (!in_array($cat, $real_cats)) {
                $fix_cats[] = $cat;
            }
        }
        if (!empty($fix_cats)) {
            $smcFunc['db_insert']('insert', '{db_prefix}categories', array('name' => 'string'), array('General Category'), array('name'));
            $catch_cat = $smcFunc['db_insert_id']('{db_prefix}categories');
            convert_query("\n\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\tSET id_cat = " . (int) $catch_cat . "\n\t\t\t\tWHERE id_cat IN (" . implode(', ', array_unique($fix_cats)) . ")");
        }
        pastTime(9);
    }
    if ($_GET['substep'] <= 9) {
        if ($debug) {
            print_line('Correct category orders..');
        }
        $request = convert_query("\n\t\t\tSELECT c.id_cat, c.cat_order, b.id_board, b.board_order\n\t\t\tFROM {$to_prefix}categories AS c\n\t\t\t\tLEFT JOIN {$to_prefix}boards AS b ON (b.id_cat = c.id_cat)\n\t\t\tORDER BY c.cat_order, b.child_level, b.board_order, b.id_board");
        $cat_order = -1;
        $board_order = -1;
        $curCat = -1;
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if ($curCat != $row['id_cat']) {
                $curCat = $row['id_cat'];
                if (++$cat_order != $row['cat_order']) {
                    convert_query("\n\t\t\t\t\t\tUPDATE {$to_prefix}categories\n\t\t\t\t\t\tSET cat_order = {$cat_order}\n\t\t\t\t\t\tWHERE id_cat = {$row['id_cat']}\n\t\t\t\t\t\tLIMIT 1");
                }
            }
            if (!empty($row['id_board']) && ++$board_order != $row['board_order']) {
                convert_query("\n\t\t\t\t\tUPDATE {$to_prefix}boards\n\t\t\t\t\tSET board_order = {$board_order}\n\t\t\t\t\tWHERE id_board = {$row['id_board']}\n\t\t\t\t\tLIMIT 1");
            }
        }
        $smcFunc['db_free_result']($request);
        pastTime(10);
    }
    if ($_GET['substep'] <= 10) {
        if ($debug) {
            print_line('Force the board order..');
        }
        // Update our BoardOrder
        require_once $sourcedir . '/Subs-Boards.php';
        reorderBoards();
        // Update our Smileys table.
        require_once $sourcedir . '/ManageSmileys.php';
        sortSmileyTable();
        pastTime(11);
    }
    if ($_GET['substep'] <= 11) {
        if ($debug) {
            print_line('Correct any incorrect attachments..');
        }
        $request = convert_query("\n\t\t\tSELECT COUNT(*)\n\t\t\tFROM {$to_prefix}attachments");
        list($attachments) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
        while ($_REQUEST['start'] < $attachments) {
            $request = convert_query("\n\t\t\t\tSELECT id_attach, filename, attachment_type\n\t\t\t\tFROM {$to_prefix}attachments\n\t\t\t\tWHERE id_thumb = 0\n\t\t\t\t\tAND (RIGHT(filename, 4) IN ('.gif', '.jpg', '.png', '.bmp') OR RIGHT(filename, 5) = '.jpeg')\n\t\t\t\t\tAND width = 0\n\t\t\t\t\tAND height = 0\n\t\t\t\tLIMIT {$_REQUEST['start']}, " . (!empty($convert_data['step2_block_size']) ? $convert_data['step2_block_size'] : 500));
            if ($smcFunc['db_num_rows']($request) == 0) {
                break;
            }
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                if ($row['attachment_type'] == 1) {
                    $request2 = convert_query("\n\t\t\t\t\t\tSELECT value\n\t\t\t\t\t\tFROM {$to_prefix}settings\n\t\t\t\t\t\tWHERE variable = 'custom_avatar_dir'\n\t\t\t\t\t\tLIMIT 1");
                    list($custom_avatar_dir) = $smcFunc['db_fetch_row']($request2);
                    $smcFunc['db_free_result']($request2);
                    $filename = $custom_avatar_dir . '/' . $row['filename'];
                } else {
                    $filename = getAttachmentFilename($row['filename'], $row['id_attach']);
                }
                // Probably not one of the converted ones, then?
                if (!file_exists($filename)) {
                    continue;
                }
                $size = @getimagesize($filename);
                $filesize = @filesize($filename);
                if (!empty($size) && !empty($size[0]) && !empty($size[1]) && !empty($filesize)) {
                    convert_query("\n\t\t\t\t\t\tUPDATE {$to_prefix}attachments\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\tsize = " . (int) $filesize . ",\n\t\t\t\t\t\t\twidth = " . (int) $size[0] . ",\n\t\t\t\t\t\t\theight = " . (int) $size[1] . "\n\t\t\t\t\t\tWHERE id_attach = {$row['id_attach']}\n\t\t\t\t\t\tLIMIT 1");
                }
            }
            $smcFunc['db_free_result']($request);
            // More?
            // We can't keep converting the same files over and over again!
            $_REQUEST['start'] += 500;
            pastTime(11);
        }
        $_REQUEST['start'] = 0;
        pastTime(12);
    }
    // Lets rebuild the indexes.
    if ($_GET['substep'] <= 12) {
        if ($debug) {
            print_line('rebuilding indexes for topics..');
        }
        db_extend('packages');
        $indexes = $smcFunc['db_list_indexes']($to_prefix . 'topics', true, array('no_prefix' => true));
        if (!isset($indexes['PRIMARY'])) {
            $smcFunc['db_add_index']($to_prefix . 'topics', array('type' => 'PRIMARY', 'columns' => array('id_topic')), array('no_prefix' => true));
        }
        if (!isset($indexes['last_message'])) {
            $smcFunc['db_add_index']($to_prefix . 'topics', array('type' => 'UNIQUE', 'name' => 'last_message', 'columns' => array('id_last_msg', 'id_board')), array('no_prefix' => true));
        }
        if (!isset($indexes['first_message'])) {
            $smcFunc['db_add_index']($to_prefix . 'topics', array('type' => 'UNIQUE', 'name' => 'first_message', 'columns' => array('id_first_msg', 'id_board')), array('no_prefix' => true));
        }
        if (!isset($indexes['poll'])) {
            $smcFunc['db_add_index']($to_prefix . 'topics', array('type' => 'UNIQUE', 'name' => 'poll', 'columns' => array('id_poll', 'id_topic')), array('no_prefix' => true));
        }
        if (!isset($indexes['is_sticky'])) {
            $smcFunc['db_add_index']($to_prefix . 'topics', array('type' => 'INDEX', 'name' => 'is_sticky', 'columns' => array('is_sticky')), array('no_prefix' => true));
        }
        if (!isset($indexes['id_board'])) {
            $smcFunc['db_add_index']($to_prefix . 'topics', array('type' => 'INDEX', 'name' => 'id_board', 'columns' => array('id_board')), array('no_prefix' => true));
        }
        $_REQUEST['start'] = 0;
        pastTime(13);
    }
    if ($_GET['substep'] <= 13) {
        if ($debug) {
            print_line('rebuilding indexes for messages..');
        }
        db_extend('packages');
        $indexes = $smcFunc['db_list_indexes']($to_prefix . 'messages', true, array('no_prefix' => true));
        if (!isset($indexes['PRIMARY'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'PRIMARY', 'columns' => array('id_msg')), array('no_prefix' => true));
        }
        if (!isset($indexes['topic'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'UNIQUE', 'name' => 'topic', 'columns' => array('id_topic', 'id_msg')), array('no_prefix' => true));
        }
        if (!isset($indexes['id_board'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'UNIQUE', 'name' => 'id_board', 'columns' => array('id_board', 'id_msg')), array('no_prefix' => true));
        }
        if (!isset($indexes['id_member'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'UNIQUE', 'name' => 'id_member', 'columns' => array('id_member', 'id_msg')), array('no_prefix' => true));
        }
        if (!isset($indexes['ip_index'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'INDEX', 'name' => 'ip_index', 'columns' => array('poster_ip(15)', 'id_topic')), array('no_prefix' => true));
        }
        if (!isset($indexes['participation'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'INDEX', 'name' => 'participation', 'columns' => array('id_member', 'id_topic')), array('no_prefix' => true));
        }
        if (!isset($indexes['showPosts'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'INDEX', 'name' => 'show_posts', 'columns' => array('id_member', 'id_member')), array('no_prefix' => true));
        }
        if (!isset($indexes['id_topic'])) {
            $smcFunc['db_add_index']($to_prefix . 'messages', array('type' => 'INDEX', 'name' => 'id_topic', 'columns' => array('id_topic')), array('no_prefix' => true));
        }
        $_REQUEST['start'] = 0;
        pastTime(14);
    }
    print_line(' Successful.');
    return doStep3();
}
Exemplo n.º 4
0
/**
 * Remove one or more categories.
 * general function to delete one or more categories.
 * allows to move all boards in the categories to a different category before deleting them.
 * if moveBoardsTo is set to null, all boards inside the given categories will be deleted.
 * deletes all information that's associated with the given categories.
 * updates the statistics to reflect the new situation.
 *
 * @param int[] $categories
 * @param integer|null $moveBoardsTo = null
 */
function deleteCategories($categories, $moveBoardsTo = null)
{
    global $cat_tree;
    $db = database();
    require_once SUBSDIR . '/Boards.subs.php';
    getBoardTree();
    call_integration_hook('integrate_delete_category', array($categories, &$moveBoardsTo));
    // With no category set to move the boards to, delete them all.
    if ($moveBoardsTo === null) {
        $boards_inside = array_keys(fetchBoardsInfo(array('categories' => $categories)));
        if (!empty($boards_inside)) {
            deleteBoards($boards_inside, null);
        }
    } elseif (in_array($moveBoardsTo, $categories)) {
        trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
    } else {
        $db->query('', '
			UPDATE {db_prefix}boards
			SET id_cat = {int:new_parent_cat}
			WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories, 'new_parent_cat' => $moveBoardsTo));
    }
    // No one will ever be able to collapse these categories anymore.
    $db->query('', '
		DELETE FROM {db_prefix}collapsed_categories
		WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories));
    // Do the deletion of the category itself
    $db->query('', '
		DELETE FROM {db_prefix}categories
		WHERE id_cat IN ({array_int:category_list})', array('category_list' => $categories));
    // Log what we've done.
    foreach ($categories as $category) {
        logAction('delete_cat', array('catname' => $cat_tree[$category]['node']['name']), 'admin');
    }
    // Get all boards back into the right order.
    reorderBoards();
}
Exemplo n.º 5
0
function deleteCategories($categories, $moveBoardsTo = null)
{
    global $db_prefix;
    // With no category set to move the boards to, delete them all.
    if ($moveBoardsTo === null) {
        $request = db_query("\n\t\t\tSELECT ID_BOARD\n\t\t\tFROM {$db_prefix}boards\n\t\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ')', __FILE__, __LINE__);
        $boards_inside = array();
        while ($row = mysql_fetch_assoc($request)) {
            $boards_inside[] = $row['ID_BOARD'];
        }
        mysql_free_result($request);
        if (!empty($boards_inside)) {
            deleteBoards($boards_inside, null);
        }
    } elseif (in_array($moveBoardsTo, $categories)) {
        trigger_error('deleteCategories(): You cannot move the boards to a category that\'s being deleted', E_USER_ERROR);
    } else {
        db_query("\n\t\t\tUPDATE {$db_prefix}boards\n\t\t\tSET ID_CAT = {$moveBoardsTo}\n\t\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ')', __FILE__, __LINE__);
    }
    // Noone will ever be able to collapse these categories anymore.
    db_query("\n\t\tDELETE FROM {$db_prefix}collapsed_categories\n\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ")", __FILE__, __LINE__);
    // Do the deletion of the category itself
    db_query("\n\t\tDELETE FROM {$db_prefix}categories\n\t\tWHERE ID_CAT IN (" . implode(', ', $categories) . ")\n\t\tLIMIT 1", __FILE__, __LINE__);
    // Get all boards back into the right order.
    reorderBoards();
}