function acp_rebuild_thread_counters()
{
    global $db, $mybb, $lang;
    $query = $db->simple_select("threads", "COUNT(*) as num_threads");
    $num_threads = $db->fetch_field($query, 'num_threads');
    $page = intval($mybb->input['page']);
    $per_page = intval($mybb->input['threadcounters']);
    $start = ($page - 1) * $per_page;
    $end = $start + $per_page;
    $query = $db->simple_select("threads", "tid", '', array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
    while ($thread = $db->fetch_array($query)) {
        rebuild_thread_counters($thread['tid']);
    }
    check_proceed($num_threads, $end, ++$page, $per_page, "threadcounters", "do_rebuildthreadcounters", $lang->success_rebuilt_thread_counters);
}
Example #2
0
 if (is_array($prune_array['to_delete']) && count($prune_array['to_delete']) > 0) {
     foreach ($prune_array['to_delete'] as $tid) {
         $db->delete_query("threads", "tid='{$tid}'");
         $db->delete_query("threads", "closed='moved|{$tid}'");
         $db->delete_query("threadsubscriptions", "tid='{$tid}'");
         $db->delete_query("polls", "tid='{$tid}'");
         $db->delete_query("threadsread", "tid='{$tid}'");
         $db->delete_query("threadratings", "tid='{$tid}'");
     }
 }
 // After deleting threads, rebuild the thread counters for the affected threads
 if (is_array($prune_array['thread_update']) && count($prune_array['thread_update']) > 0) {
     $sql_array = implode(",", $prune_array['thread_update']);
     $query = $db->simple_select("threads", "tid", "tid IN (" . $sql_array . ")", array('order_by' => 'tid', 'order_dir' => 'asc'));
     while ($thread = $db->fetch_array($query)) {
         rebuild_thread_counters($thread['tid']);
     }
 }
 // After updating thread counters, update the affected forum counters
 if (is_array($prune_array['forum_update']) && count($prune_array['forum_update']) > 0) {
     $sql_array = implode(",", $prune_array['forum_update']);
     $query = $db->simple_select("forums", "fid", "fid IN (" . $sql_array . ")", array('order_by' => 'fid', 'order_dir' => 'asc'));
     while ($forum = $db->fetch_array($query)) {
         // Because we have a recursive array merge, check to see if there isn't a duplicated forum to update
         if ($looped_forum == $forum['fid']) {
             continue;
         }
         $looped_forum = $forum['fid'];
         rebuild_forum_counters($forum['fid']);
     }
 }
Example #3
0
function upgrade5_lastposts()
{
    global $db, $output;
    $output->print_header("Przebudowywanie informacji o ostatnich postach");
    if (!$_POST['tpp']) {
        echo "<p>Nastęnym krokiem w aktualizacji jest przebudowanie informacji o ostatnim poście w każdym wątku na Twoim forum. Wpisz w poniższe pole ilość wpisów, które mają zostać przetworzone na stronę.</p>";
        echo "<p><strong>Wpisów na stronę:</strong> <input type=\"text\" size=\"3\" value=\"200\" name=\"tpp\" /></p>";
        echo "<p>Jeżeli wszystko gotowe, naciśnij przycisk Dalej, aby rozpocząć proces przebudowy.</p>";
        $output->print_footer("5_lastposts");
    } else {
        require_once MYBB_ROOT . "inc/functions_rebuild.php";
        $query = $db->simple_select("threads", "COUNT(*) as num_threads", "closed NOT LIKE 'moved|%'");
        $num_threads = $db->fetch_field($query, 'num_threads');
        $tpp = intval($_POST['tpp']);
        $start = intval($_POST['start']);
        $end = $start + $tpp;
        if ($end > $num_threads) {
            $end = $num_threads;
        }
        echo "<p>Aktualizacja {$start} do {$end} z {$num_threads}...</p>";
        $query = $db->simple_select("threads", "tid, firstpost", "closed NOT LIKE 'moved|%'", array("order_by" => "tid", "order_dir" => "asc", "limit" => $tpp, "limit_start" => $start));
        while ($thread = $db->fetch_array($query)) {
            rebuild_thread_counters($thread['tid']);
            if ($thread['firstpost'] == 0) {
                update_first_post($thread['tid']);
            }
        }
        echo "<p>Zakończono</p>";
        if ($end >= $num_threads) {
            echo "<p>Proces przebudowy został pomyślnie zakończony. Naciśnij przycisk Dalej, aby kontynuować proces aktualizacji.";
            $output->print_footer("5_forumlastposts");
        } else {
            echo "<p>Naciśnij przycisk Dalej, aby kontynuować proces przebudowy.</p>";
            echo "<input type=\"hidden\" name=\"tpp\" value=\"{$tpp}\" />";
            echo "<input type=\"hidden\" name=\"start\" value=\"{$end}\" />";
            $output->print_footer("5_lastposts");
        }
    }
}
Example #4
0
function upgrade5_lastposts()
{
    global $db, $output;
    $output->print_header("Rebuilding Last Post Columns");
    if (!$_POST['tpp']) {
        echo "<p>The next step in the upgrade process involves rebuilding the last post information for every thread in your forum. Below, please enter the number of threads to process per page.</p>";
        echo "<p><strong>Threads Per Page:</strong> <input type=\"text\" size=\"3\" value=\"200\" name=\"tpp\" /></p>";
        echo "<p>Once you're ready, press next to begin the rebuild process.</p>";
        $output->print_footer("5_lastposts");
    } else {
        require_once MYBB_ROOT . "inc/functions_rebuild.php";
        $query = $db->simple_select("threads", "COUNT(*) as num_threads", "closed NOT LIKE 'moved|%'");
        $num_threads = $db->fetch_field($query, 'num_threads');
        $tpp = intval($_POST['tpp']);
        $start = intval($_POST['start']);
        $end = $start + $tpp;
        if ($end > $num_threads) {
            $end = $num_threads;
        }
        echo "<p>Updating {$start} to {$end} of {$num_threads}...</p>";
        $query = $db->simple_select("threads", "tid, firstpost", "closed NOT LIKE 'moved|%'", array("order_by" => "tid", "order_dir" => "asc", "limit" => $tpp, "limit_start" => $start));
        while ($thread = $db->fetch_array($query)) {
            rebuild_thread_counters($thread['tid']);
            if ($thread['firstpost'] == 0) {
                update_first_post($thread['tid']);
            }
        }
        echo "<p>Done</p>";
        if ($end >= $num_threads) {
            echo "<p>The rebuild process has completed successfully. Click next to continue with the upgrade.";
            $output->print_footer("5_forumlastposts");
        } else {
            echo "<p>Click Next to continue with the build process.</p>";
            echo "<input type=\"hidden\" name=\"tpp\" value=\"{$tpp}\" />";
            echo "<input type=\"hidden\" name=\"start\" value=\"{$end}\" />";
            $output->print_footer("5_lastposts");
        }
    }
}
 /**
  * Execute Normal and Inline Thread Moderation
  *
  * @param array $thread_options Moderation information
  * @param array Thread IDs. Only the first one will be used, but it needs to be an array
  * @return boolean true
  */
 function execute_thread_moderation($thread_options, $tids)
 {
     global $db, $mybb;
     $tid = (int) $tids[0];
     // Take the first thread to get thread data from
     $query = $db->simple_select("threads", 'fid', "tid='{$tid}'");
     $thread = $db->fetch_array($query);
     // If deleting threads, only do that
     if ($thread_options['deletethread'] == 1) {
         foreach ($tids as $tid) {
             $this->delete_thread($tid);
         }
     } else {
         if ($thread_options['mergethreads'] == 1 && count($tids) > 1) {
             $tid_list = implode(',', $tids);
             $options = array('order_by' => 'dateline', 'order_dir' => 'DESC');
             $query = $db->simple_select("threads", 'tid, subject', "tid IN ({$tid_list})", $options);
             // Select threads from newest to oldest
             $last_tid = 0;
             while ($tid = $db->fetch_array($query)) {
                 if ($last_tid != 0) {
                     $this->merge_threads($last_tid, $tid['tid'], $tid['subject']);
                     // And keep merging them until we get down to one thread.
                 }
                 $last_tid = $tid['tid'];
             }
         }
         if ($thread_options['deletepoll'] == 1) {
             foreach ($tids as $tid) {
                 $this->delete_poll($tid);
             }
         }
         if ($thread_options['removeredirects'] == 1) {
             foreach ($tids as $tid) {
                 $this->remove_redirects($tid);
             }
         }
         if ($thread_options['removesubscriptions'] == 1) {
             $this->remove_thread_subscriptions($tids, true);
         }
         if ($thread_options['approvethread'] == 'approve') {
             $this->approve_threads($tids, $thread['fid']);
         } elseif ($thread_options['approvethread'] == 'unapprove') {
             $this->unapprove_threads($tids, $thread['fid']);
         } elseif ($thread_options['approvethread'] == 'toggle') {
             $this->toggle_thread_visibility($tids, $thread['fid']);
         }
         if ($thread_options['softdeletethread'] == 'softdelete') {
             $this->soft_delete_threads($tids);
         } elseif ($thread_options['softdeletethread'] == 'restore') {
             $this->restore_threads($tids);
         } elseif ($thread_options['softdeletethread'] == 'toggle') {
             $this->toggle_thread_softdelete($tids);
         }
         if ($thread_options['openthread'] == 'open') {
             $this->open_threads($tids);
         } elseif ($thread_options['openthread'] == 'close') {
             $this->close_threads($tids);
         } elseif ($thread_options['openthread'] == 'toggle') {
             $this->toggle_thread_status($tids);
         }
         if ($thread_options['stickthread'] == 'stick') {
             $this->stick_threads($tids);
         } elseif ($thread_options['stickthread'] == 'unstick') {
             $this->unstick_threads($tids);
         } elseif ($thread_options['stickthread'] == 'toggle') {
             $this->toggle_thread_importance($tids);
         }
         if ($thread_options['threadprefix'] != '-1') {
             $this->apply_thread_prefix($tids, $thread_options['threadprefix']);
             // Update thread prefix
         }
         if (my_strtolower(trim($thread_options['newsubject'])) != '{subject}') {
             $this->change_thread_subject($tids, $thread_options['newsubject']);
         }
         if (!empty($thread_options['addreply'])) {
             $tid_list = implode(',', $tids);
             $query = $db->simple_select("threads", 'uid, fid, subject, tid, firstpost, closed', "tid IN ({$tid_list}) AND closed NOT LIKE 'moved|%'");
             require_once MYBB_ROOT . "inc/datahandlers/post.php";
             // Loop threads adding a reply to each one
             while ($thread = $db->fetch_array($query)) {
                 $posthandler = new PostDataHandler("insert");
                 if (empty($thread_options['replysubject'])) {
                     $new_subject = 'RE: ' . $thread['subject'];
                 } else {
                     $new_subject = str_ireplace('{username}', $mybb->user['username'], $thread_options['replysubject']);
                     $new_subject = str_ireplace('{subject}', $thread['subject'], $new_subject);
                 }
                 // Set the post data that came from the input to the $post array.
                 $post = array("tid" => $thread['tid'], "replyto" => $thread['firstpost'], "fid" => $thread['fid'], "subject" => $new_subject, "uid" => $mybb->user['uid'], "username" => $mybb->user['username'], "message" => $thread_options['addreply'], "ipaddress" => $db->escape_binary(my_inet_pton(get_ip())));
                 // Set up the post options from the input.
                 $post['options'] = array("signature" => 1, "emailnotify" => 0, "disablesmilies" => 0);
                 if ($thread['closed'] == 1) {
                     // Keep this thread closed
                     $post['modoptions']['closethread'] = 1;
                 }
                 $posthandler->set_data($post);
                 if ($posthandler->validate_post($post)) {
                     $posthandler->insert_post($post);
                 }
             }
         }
         if ($thread_options['movethread'] > 0 && $thread_options['movethread'] != $thread['fid']) {
             if ($thread_options['movethreadredirect'] == 1) {
                 $time = TIME_NOW + $thread_options['movethreadredirectexpire'] * 86400;
                 foreach ($tids as $tid) {
                     $this->move_thread($tid, $thread_options['movethread'], 'redirect', $time);
                 }
             } else {
                 $this->move_threads($tids, $thread_options['movethread']);
             }
         }
         if ($thread_options['copythread'] > 0 || $thread_options['copythread'] == -2) {
             if ($thread_options['copythread'] == -2) {
                 $thread_options['copythread'] = $thread['fid'];
             }
             foreach ($tids as $tid) {
                 $new_tid = $this->move_thread($tid, $thread_options['copythread'], 'copy');
             }
         }
         if (!empty($thread_options['recountrebuild'])) {
             require_once MYBB_ROOT . '/inc/functions_rebuild.php';
             foreach ($tids as $tid) {
                 rebuild_thread_counters($tid);
             }
         }
     }
     // Do we have a PM subject and PM message?
     if (isset($thread_options['pm_subject']) && $thread_options['pm_subject'] != '' && isset($thread_options['pm_message']) && $thread_options['pm_message'] != '') {
         $tid_list = implode(',', $tids);
         // For each thread, we send a PM to the author
         $query = $db->simple_select("threads", 'uid', "tid IN ({$tid_list})");
         while ($uid = $db->fetch_field($query, 'uid')) {
             // Let's send our PM
             $pm = array('subject' => $thread_options['pm_subject'], 'message' => $thread_options['pm_message'], 'touid' => $uid);
             send_pm($pm, $mybb->user['uid'], 1);
         }
     }
     return true;
 }
Example #6
0
 /**
  * Rebuild counters, and lastpost information right after importing posts
  *
  */
 public function counters_cleanup()
 {
     global $db, $output, $import_session;
     $output->print_header("Rebuilding Counters");
     $this->debug->log->trace0("Rebuilding thread, forum, and statistic counters");
     $output->construct_progress_bar();
     echo "<br />\nRebuilding thread, forum, and statistic counters...(This may take a while)<br /><br />\n";
     echo "<br />\nRebuilding thread counters... ";
     flush();
     // Rebuild thread counters, forum counters, user post counters, last post* and thread username
     $query = $db->simple_select("threads", "COUNT(*) as count", "import_tid != 0");
     $num_imported_threads = $db->fetch_field($query, "count");
     $progress = $last_percent = 0;
     if ($import_session['counters_cleanup_start'] < $num_imported_threads) {
         $this->debug->log->trace1("Rebuilding thread counters");
         $progress = $import_session['counters_cleanup_start'];
         $query = $db->simple_select("threads", "tid", "import_tid != 0", array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => intval($import_session['counters_cleanup_start']), 'limit' => 1000));
         while ($thread = $db->fetch_array($query)) {
             rebuild_thread_counters($thread['tid']);
             ++$progress;
             if ($progress % 5 == 0) {
                 if ($progress % 100 == 0) {
                     check_memory();
                 }
                 $percent = round($progress / $num_imported_threads * 100, 1);
                 if ($percent != $last_percent) {
                     $output->update_progress_bar($percent, "Rebuilding counters for thread #{$thread['tid']}");
                 }
                 $last_percent = $percent;
             }
         }
         $import_session['counters_cleanup_start'] += $progress;
         if ($import_session['counters_cleanup_start'] >= $num_imported_threads) {
             $this->debug->log->trace1("Finished rebuilding thread counters");
             $import_session['counters_cleanup'] = 0;
             echo "done.";
             flush();
             return;
         }
         $import_session['counters_cleanup'] = 1;
         return;
     }
     if ($import_session['counters_cleanup_start'] >= $num_imported_threads) {
         $this->debug->log->trace1("Rebuilding forum counters");
         echo "done. <br />Rebuilding forum counters... ";
         flush();
         $query = $db->simple_select("forums", "COUNT(*) as count", "import_fid != 0");
         $num_imported_forums = $db->fetch_field($query, "count");
         $progress = 0;
         $query = $db->simple_select("forums", "fid", "import_fid != 0", array('order_by' => 'fid', 'order_dir' => 'asc'));
         while ($forum = $db->fetch_array($query)) {
             rebuild_forum_counters($forum['fid']);
             ++$progress;
             $output->update_progress_bar(round($progress / $num_imported_forums * 50, 1) + 100, "Rebuilding counters for forum #{$forum['fid']}");
         }
         $output->update_progress_bar(150);
         $query = $db->simple_select("forums", "fid", "usepostcounts = 0");
         while ($forum = $db->fetch_array($query)) {
             $fids[] = $forum['fid'];
         }
         if (is_array($fids)) {
             $fids = implode(',', $fids);
         }
         if ($fids) {
             $fids = " AND fid NOT IN({$fids})";
         } else {
             $fids = "";
         }
         $this->debug->log->trace1("Rebuilding user counters");
         echo "done. <br />Rebuilding user counters... ";
         flush();
         $query = $db->simple_select("users", "COUNT(*) as count", "import_uid != 0");
         $num_imported_users = $db->fetch_field($query, "count");
         $progress = $last_percent = 0;
         $query = $db->simple_select("users", "uid", "import_uid != 0");
         while ($user = $db->fetch_array($query)) {
             $query2 = $db->simple_select("posts", "COUNT(*) AS post_count", "uid='{$user['uid']}' AND visible > 0{$fids}");
             $num_posts = $db->fetch_field($query2, "post_count");
             $db->free_result($query2);
             $db->update_query("users", array("postnum" => intval($num_posts)), "uid='{$user['uid']}'");
             ++$progress;
             $percent = round($progress / $num_imported_users * 50 + 150, 1);
             if ($percent != $last_percent) {
                 $output->update_progress_bar($percent, "Rebuilding counters for user #{$user['uid']}");
             }
             $last_percent = $percent;
         }
         // TODO: recount user posts doesn't seem to work
         $output->update_progress_bar(200, "Please wait...");
         echo "done.<br />";
         flush();
         sleep(3);
     }
 }