Example #1
0
function prune($forum_id, $prune_date, $prune_all = false)
{
    global $db, $lang;
    $prune_all = $prune_all ? '' : 'AND t.topic_vote = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
    //
    // Those without polls and announcements ... unless told otherwise!
    //
    $sql = "SELECT t.topic_id \n\t\tFROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t\n\t\tWHERE t.forum_id = {$forum_id}\n\t\t\t{$prune_all} \n\t\t\tAND ( p.post_id = t.topic_last_post_id \n\t\t\t\tOR t.topic_last_post_id = 0 )";
    if ($prune_date != '') {
        $sql .= " AND p.post_time < {$prune_date}";
    }
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Could not obtain lists of topics to prune', '', __LINE__, __FILE__, $sql);
    }
    $sql_topics = '';
    while ($row = $db->sql_fetchrow($result)) {
        $sql_topics .= ($sql_topics != '' ? ', ' : '') . $row['topic_id'];
    }
    $db->sql_freeresult($result);
    if ($sql_topics != '') {
        $sql = "SELECT post_id\n\t\t\tFROM " . POSTS_TABLE . " \n\t\t\tWHERE forum_id = {$forum_id} \n\t\t\t\tAND topic_id IN ({$sql_topics})";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not obtain list of posts to prune', '', __LINE__, __FILE__, $sql);
        }
        $sql_post = '';
        while ($row = $db->sql_fetchrow($result)) {
            $sql_post .= ($sql_post != '' ? ', ' : '') . $row['post_id'];
        }
        $db->sql_freeresult($result);
        if ($sql_post != '') {
            $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " \n\t\t\t\tWHERE topic_id IN ({$sql_topics})";
            if (!$db->sql_query($sql, BEGIN_TRANSACTION)) {
                message_die(GENERAL_ERROR, 'Could not delete watched topics during prune', '', __LINE__, __FILE__, $sql);
            }
            $sql = "DELETE FROM " . TOPICS_TABLE . " \n\t\t\t\tWHERE topic_id IN ({$sql_topics})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not delete topics during prune', '', __LINE__, __FILE__, $sql);
            }
            $pruned_topics = $db->sql_affectedrows();
            $sql = "DELETE FROM " . POSTS_TABLE . " \n\t\t\t\tWHERE post_id IN ({$sql_post})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not delete post_text during prune', '', __LINE__, __FILE__, $sql);
            }
            $pruned_posts = $db->sql_affectedrows();
            $sql = "DELETE FROM " . POSTS_TEXT_TABLE . " \n\t\t\t\tWHERE post_id IN ({$sql_post})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not delete post during prune', '', __LINE__, __FILE__, $sql);
            }
            remove_search_post($sql_post);
            prune_attachments($sql_post);
            return array('topics' => $pruned_topics, 'posts' => $pruned_posts);
        }
    }
    return array('topics' => 0, 'posts' => 0);
}
Example #2
0
function prune($forum_id, $prune_date, $prune_all = false)
{
    global $db, $lang, $class_mcp;
    if (!class_exists('class_mcp')) {
        include IP_ROOT_PATH . 'includes/class_mcp.' . PHP_EXT;
    }
    if (empty($class_mcp)) {
        $class_mcp = new class_mcp();
    }
    // Before pruning, lets try to clean up the invalid topic entries
    $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
		WHERE topic_last_post_id = 0';
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $class_mcp->sync('topic', $row['topic_id']);
    }
    $db->sql_freeresult($result);
    $prune_all = $prune_all ? '' : 'AND t.poll_start = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
    // Those without polls and announcements... unless told otherwise!
    $sql = "SELECT t.topic_id\n\t\tFROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t\n\t\tWHERE t.forum_id = {$forum_id}\n\t\t\t{$prune_all}\n\t\t\tAND p.post_id = t.topic_last_post_id";
    if ($prune_date != '') {
        $sql .= " AND p.post_time < {$prune_date}";
    }
    $result = $db->sql_query($sql);
    $sql_topics = '';
    while ($row = $db->sql_fetchrow($result)) {
        $sql_topics .= ($sql_topics != '' ? ', ' : '') . $row['topic_id'];
    }
    $db->sql_freeresult($result);
    if ($sql_topics != '') {
        $sql = "SELECT post_id\n\t\t\tFROM " . POSTS_TABLE . "\n\t\t\tWHERE forum_id = {$forum_id}\n\t\t\t\tAND topic_id IN ({$sql_topics})";
        $result = $db->sql_query($sql);
        $sql_post = '';
        while ($row = $db->sql_fetchrow($result)) {
            $sql_post .= ($sql_post != '' ? ', ' : '') . $row['post_id'];
        }
        $db->sql_freeresult($result);
        if ($sql_post != '') {
            $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " WHERE topic_id IN ({$sql_topics})";
            $db->sql_transaction('begin');
            $db->sql_query($sql);
            $sql = "DELETE FROM " . TOPICS_TABLE . " WHERE topic_id IN ({$sql_topics})";
            $db->sql_query($sql);
            $pruned_topics = $db->sql_affectedrows();
            // Event Registration - BEGIN
            $sql = "DELETE FROM " . REGISTRATION_TABLE . " WHERE topic_id IN ({$sql_topics})";
            $db->sql_query($sql);
            // Event Registration - END
            $sql = "DELETE FROM " . BOOKMARK_TABLE . " WHERE topic_id IN ({$sql_topics})";
            $db->sql_query($sql);
            $sql = "DELETE FROM " . POSTS_TABLE . " WHERE post_id IN ({$sql_post})";
            $db->sql_query($sql);
            $pruned_posts = $db->sql_affectedrows();
            $db->sql_transaction('commit');
            remove_search_post($sql_post);
            // UPI2DB - BEGIN
            prune_upi2db($sql_post);
            // UPI2DB - END
            prune_attachments($sql_post);
            return array('topics' => $pruned_topics, 'posts' => $pruned_posts);
        }
    }
    return array('topics' => 0, 'posts' => 0);
}
Example #3
0
function prune($forum_id, $prune_date, $prune_all = false)
{
    global $db, $lang;
    // Before pruning, lets try to clean up the invalid topic entries
    $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
		WHERE topic_last_post_id = 0';
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Could not obtain lists of topics to sync', '', __LINE__, __FILE__, $sql);
    }
    while ($row = $db->sql_fetchrow($result)) {
        sync('topic', $row['topic_id']);
    }
    $db->sql_freeresult($result);
    $prune_all = $prune_all ? '' : 'AND t.topic_vote = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
    //
    // Those without polls and announcements ... unless told otherwise!
    //
    $sql = "SELECT t.topic_id \n\t\tFROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t\n\t\tWHERE t.forum_id = {$forum_id}\n\t\t\t{$prune_all} \n\t\t\tAND p.post_id = t.topic_last_post_id";
    if ($prune_date != '') {
        $sql .= " AND p.post_time < {$prune_date}";
    }
    if (!($result = $db->sql_query($sql))) {
        message_die(GENERAL_ERROR, 'Could not obtain lists of topics to prune', '', __LINE__, __FILE__, $sql);
    }
    $sql_topics = '';
    while ($row = $db->sql_fetchrow($result)) {
        $sql_topics .= ($sql_topics != '' ? ', ' : '') . $row['topic_id'];
    }
    $db->sql_freeresult($result);
    if ($sql_topics != '') {
        $sql = "SELECT post_id\n\t\t\tFROM " . POSTS_TABLE . " \n\t\t\tWHERE forum_id = {$forum_id} \n\t\t\t\tAND topic_id IN ({$sql_topics})";
        if (!($result = $db->sql_query($sql))) {
            message_die(GENERAL_ERROR, 'Could not obtain list of posts to prune', '', __LINE__, __FILE__, $sql);
        }
        $sql_post = '';
        while ($row = $db->sql_fetchrow($result)) {
            $sql_post .= ($sql_post != '' ? ', ' : '') . $row['post_id'];
        }
        $db->sql_freeresult($result);
        if ($sql_post != '') {
            $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " \n\t\t\t\tWHERE topic_id IN ({$sql_topics})";
            if (!$db->sql_query($sql, BEGIN_TRANSACTION)) {
                message_die(GENERAL_ERROR, 'Could not delete watched topics during prune', '', __LINE__, __FILE__, $sql);
            }
            $sql = "DELETE FROM " . TOPICS_TABLE . " \n\t\t\t\tWHERE topic_id IN ({$sql_topics})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not delete topics during prune', '', __LINE__, __FILE__, $sql);
            }
            $pruned_topics = $db->sql_affectedrows();
            $sql = "DELETE FROM " . POSTS_TABLE . " \n\t\t\t\tWHERE post_id IN ({$sql_post})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not delete post_text during prune', '', __LINE__, __FILE__, $sql);
            }
            $pruned_posts = $db->sql_affectedrows();
            $sql = "DELETE FROM " . POSTS_TEXT_TABLE . " \n\t\t\t\tWHERE post_id IN ({$sql_post})";
            if (!$db->sql_query($sql)) {
                message_die(GENERAL_ERROR, 'Could not delete post during prune', '', __LINE__, __FILE__, $sql);
            }
            remove_search_post($sql_post);
            /* -- mod : File Attachment Mod v2 Version 2.4.3 ---------------------------------------------------- */
            if (!intval($attach_config['disable_mod'])) {
                prune_attachments($sql_post);
            }
            /* -- fin : File Attachment Mod v2 Version 2.4.3 ---------------------------------------------------- */
            return array('topics' => $pruned_topics, 'posts' => $pruned_posts);
        }
    }
    return array('topics' => 0, 'posts' => 0);
}