Esempio n. 1
0
 public function substep102()
 {
     $to_prefix = $this->config->to_prefix;
     $request = $this->db->query("\n\t\t\tSELECT COUNT(*) AS count, id_member\n\t\t\tFROM {$to_prefix}message_likes\n\t\t\tGROUP BY id_member");
     while ($row = $this->db->fetch_assoc($request)) {
         $this->db->query("\n\t\t\t\tUPDATE {$to_prefix}members\n\t\t\t\tSET likes_given = {$row['count']}\n\t\t\t\tWHERE id_member = {$row['id_member']}\n\t\t\t\tLIMIT 1");
         pastTime(0);
     }
     $this->db->free_result($request);
 }
Esempio n. 2
0
 protected function updateStatus(&$substep, &$do_steps)
 {
     $table_test = true;
     // Increase the substep slightly...
     pastTime(++$substep);
     $_SESSION['import_steps'][$substep]['title'] = (string) $this->current_step->title;
     if (!isset($_SESSION['import_steps'][$substep]['status'])) {
         $_SESSION['import_steps'][$substep]['status'] = 0;
     }
     if (!in_array($substep, $do_steps)) {
         $_SESSION['import_steps'][$substep]['status'] = 2;
         $_SESSION['import_steps'][$substep]['presql'] = true;
     } elseif ($this->current_step->detect) {
         $table_test = $this->detect((string) $this->current_step->detect);
         if ($table_test === false) {
             $_SESSION['import_steps'][$substep]['status'] = 3;
             $_SESSION['import_steps'][$substep]['presql'] = true;
         }
     }
     $this->template->status($substep, $_SESSION['import_steps'][$substep]['status'], $_SESSION['import_steps'][$substep]['title']);
     return $table_test;
 }
Esempio n. 3
0
 public function substep13()
 {
     $indexes = array('id_msg' => array('name' => 'id_msg', 'columns' => array('id_msg'), 'type' => 'primary'), 'id_topic' => array('name' => 'id_topic', 'columns' => array('id_topic', 'id_msg'), 'type' => 'unique'), 'id_board' => array('name' => 'id_board', 'columns' => array('id_board', 'id_msg'), 'type' => 'unique'), 'id_member' => array('name' => 'id_member', 'columns' => array('id_member', 'id_msg'), 'type' => 'unique'), 'ip_index' => array('name' => 'ip_index', 'columns' => array('poster_ip(15)', 'id_topic'), 'type' => 'key'), 'participation' => array('name' => 'participation', 'columns' => array('id_member', 'id_topic'), 'type' => 'key'), 'show_posts' => array('name' => 'show_posts', 'columns' => array('id_member', 'id_board'), 'type' => 'key'), 'id_topic' => array('name' => 'id_topic', 'columns' => array('id_topic'), 'type' => 'key'), 'id_member_msg' => array('name' => 'id_member_msg', 'columns' => array('id_member', 'approved', 'id_msg'), 'type' => 'key'), 'current_topic' => array('name' => 'current_topic', 'columns' => array('id_topic', 'id_msg', 'id_member', 'approved'), 'type' => 'key'));
     foreach ($indexes as $index_info) {
         $this->db->alter_table("{$to_prefix}messages", $index_info);
     }
     $_REQUEST['start'] = 0;
     pastTime(14);
 }
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();
}
Esempio n. 5
0
<?php

function pastTime($since)
{
    // Getting difference from start to end
    $diff = strtotime('now') - $since;
    if ($diff >= 1) {
        $time = [12 * 30 * 24 * 60 * 60 => 'y', 30 * 24 * 60 * 60 => 'm', 24 * 60 * 60 => 'd', 60 * 60 => 'h', 60 => 'min', 1 => 'sec'];
        // Looping through the array in order to find the right time difference
        foreach ($time as $secs => $str) {
            $div = $diff / $secs;
            if ($div >= 1) {
                return round($div) . $str . ' ago';
            }
        }
    } else {
        return 'now';
    }
}
echo pastTime(strtotime('2015/12/01'));
Esempio n. 6
0
 /**
  * we have imported the old database, let's recalculate the forum statistics.
  *
  * @global Database $db
  * @global type $to_prefix
  * @return boolean
  */
 public function doStep2()
 {
     $step2_importer_class = $this->_importer_base_class_name . '_step2';
     $instance = new $step2_importer_class($this->db, $this->config);
     $methods = get_class_methods($instance);
     $substeps = array();
     $substep = 0;
     foreach ($methods as $method) {
         if (substr($method, 0, 7) !== 'substep') {
             continue;
         }
         $substeps[substr($method, 7)] = $method;
     }
     ksort($substeps);
     foreach ($substeps as $key => $method) {
         if ($substep <= $key) {
             call_user_func(array($instance, $method));
         }
         $substep++;
         pastTime($substep);
     }
     return $key;
 }