Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (14 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/mcp/mcp_queue.php

    r400 r702  
    33*
    44* @package mcp
    5 * @version $Id: mcp_queue.php 9133 2008-11-30 12:03:43Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    106106                                        $template->assign_vars(array(
    107107                                                'S_TOPIC_REVIEW'        => true,
     108                                                'S_BBCODE_ALLOWED'      => $post_info['enable_bbcode'],
    108109                                                'TOPIC_TITLE'           => $post_info['topic_title'])
    109110                                        );
     
    492493
    493494                $total_topics = $total_posts = 0;
    494                 $forum_topics_posts = $topic_approve_sql = $topic_replies_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
    495                 $user_posts_sql = array();
    496 
    497                 $update_forum_information = false;
     495                $topic_approve_sql = $post_approve_sql = $topic_id_list = $forum_id_list = $approve_log = array();
     496                $user_posts_sql = $post_approved_list = array();
    498497
    499498                foreach ($post_info as $post_id => $post_data)
    500499                {
     500                        if ($post_data['post_approved'])
     501                        {
     502                                $post_approved_list[] = $post_id;
     503                                continue;
     504                        }
     505
    501506                        $topic_id_list[$post_data['topic_id']] = 1;
    502507
     
    518523                                if ($post_data['forum_id'])
    519524                                {
    520                                         if (!isset($forum_topics_posts[$post_data['forum_id']]))
    521                                         {
    522                                                 $forum_topics_posts[$post_data['forum_id']] = array(
    523                                                         'forum_posts'   => 0,
    524                                                         'forum_topics'  => 0
    525                                                 );
    526                                         }
    527 
    528525                                        $total_topics++;
    529                                         $forum_topics_posts[$post_data['forum_id']]['forum_topics']++;
    530526                                }
    531527                                $topic_approve_sql[] = $post_data['topic_id'];
     
    540536                        else
    541537                        {
    542                                 if (!isset($topic_replies_sql[$post_data['topic_id']]))
    543                                 {
    544                                         $topic_replies_sql[$post_data['topic_id']] = 0;
    545                                 }
    546                                 $topic_replies_sql[$post_data['topic_id']]++;
    547 
    548538                                $approve_log[] = array(
    549539                                        'type'                  => 'post',
     
    556546                        if ($post_data['forum_id'])
    557547                        {
    558                                 if (!isset($forum_topics_posts[$post_data['forum_id']]))
    559                                 {
    560                                         $forum_topics_posts[$post_data['forum_id']] = array(
    561                                                 'forum_posts'   => 0,
    562                                                 'forum_topics'  => 0
    563                                         );
    564                                 }
    565 
    566548                                $total_posts++;
    567                                 $forum_topics_posts[$post_data['forum_id']]['forum_posts']++;
    568549
    569550                                // Increment by topic_replies if we approve a topic...
     
    572553                                {
    573554                                        $total_posts += $post_data['topic_replies'];
    574                                         $forum_topics_posts[$post_data['forum_id']]['forum_posts'] += $post_data['topic_replies'];
    575555                                }
    576556                        }
    577557
    578558                        $post_approve_sql[] = $post_id;
    579 
    580                         // If the post is newer than the last post information stored we need to update the forum information
    581                         if ($post_data['post_time'] >= $post_data['forum_last_post_time'])
    582                         {
    583                                 $update_forum_information = true;
    584                         }
     559                }
     560
     561                $post_id_list = array_values(array_diff($post_id_list, $post_approved_list));
     562                for ($i = 0, $size = sizeof($post_approved_list); $i < $size; $i++)
     563                {
     564                        unset($post_info[$post_approved_list[$i]]);
    585565                }
    586566
     
    601581                }
    602582
     583                unset($topic_approve_sql, $post_approve_sql);
     584
    603585                foreach ($approve_log as $log_data)
    604586                {
    605587                        add_log('mod', $log_data['forum_id'], $log_data['topic_id'], ($log_data['type'] == 'topic') ? 'LOG_TOPIC_APPROVED' : 'LOG_POST_APPROVED', $log_data['post_subject']);
    606                 }
    607 
    608                 if (sizeof($topic_replies_sql))
    609                 {
    610                         foreach ($topic_replies_sql as $topic_id => $num_replies)
    611                         {
    612                                 $sql = 'UPDATE ' . TOPICS_TABLE . "
    613                                         SET topic_replies = topic_replies + $num_replies
    614                                         WHERE topic_id = $topic_id";
    615                                 $db->sql_query($sql);
    616                         }
    617                 }
    618 
    619                 if (sizeof($forum_topics_posts))
    620                 {
    621                         foreach ($forum_topics_posts as $forum_id => $row)
    622                         {
    623                                 $sql = 'UPDATE ' . FORUMS_TABLE . '
    624                                         SET ';
    625                                 $sql .= ($row['forum_topics']) ? "forum_topics = forum_topics + {$row['forum_topics']}" : '';
    626                                 $sql .= ($row['forum_topics'] && $row['forum_posts']) ? ', ' : '';
    627                                 $sql .= ($row['forum_posts']) ? "forum_posts = forum_posts + {$row['forum_posts']}" : '';
    628                                 $sql .= " WHERE forum_id = $forum_id";
    629 
    630                                 $db->sql_query($sql);
    631                         }
    632588                }
    633589
     
    653609                if ($total_topics)
    654610                {
    655                         set_config('num_topics', $config['num_topics'] + $total_topics, true);
     611                        set_config_count('num_topics', $total_topics, true);
    656612                }
    657613
    658614                if ($total_posts)
    659615                {
    660                         set_config('num_posts', $config['num_posts'] + $total_posts, true);
    661                 }
    662                 unset($topic_approve_sql, $topic_replies_sql, $post_approve_sql);
    663 
    664                 update_post_information('topic', array_keys($topic_id_list));
    665 
    666                 if ($update_forum_information)
    667                 {
    668                         update_post_information('forum', array_keys($forum_id_list));
    669                 }
     616                        set_config_count('num_posts', $total_posts, true);
     617                }
     618
     619                sync('topic', 'topic_id', array_keys($topic_id_list), true);
     620                sync('forum', 'forum_id', array_keys($forum_id_list), true, true);
    670621                unset($topic_id_list, $forum_id_list);
    671622
     
    734685                else
    735686                {
    736                         $success_msg = (sizeof($post_id_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
     687                        $success_msg = (sizeof($post_id_list) + sizeof($post_approved_list) == 1) ? 'POST_APPROVED_SUCCESS' : 'POSTS_APPROVED_SUCCESS';
    737688                }
    738689        }
     
    846797        if (confirm_box(true))
    847798        {
    848 
    849                 // If Topic -> forum_topics_real -= 1
    850                 // If Post -> topic_replies_real -= 1
    851 
    852                 $num_disapproved = 0;
    853                 $forum_topics_real = $topic_id_list = $forum_id_list = $topic_replies_real_sql = $post_disapprove_sql = $disapprove_log = array();
    854 
     799                $disapprove_log = $disapprove_log_topics = $disapprove_log_posts = array();
     800                $topic_replies_real = $post_disapprove_list = array();
     801
     802                // Build a list of posts to be unapproved and get the related topics real replies count
    855803                foreach ($post_info as $post_id => $post_data)
    856804                {
    857                         $topic_id_list[$post_data['topic_id']] = 1;
    858 
    859                         if ($post_data['forum_id'])
    860                         {
    861                                 $forum_id_list[$post_data['forum_id']] = 1;
    862                         }
    863 
    864                         // Topic or Post. ;)
    865                         /**
    866                         * @todo this probably is a different method than the one used by delete_posts, does this cause counter inconsistency?
    867                         */
    868                         if ($post_data['topic_first_post_id'] == $post_id && $post_data['topic_last_post_id'] == $post_id)
    869                         {
    870                                 if ($post_data['forum_id'])
    871                                 {
    872                                         if (!isset($forum_topics_real[$post_data['forum_id']]))
    873                                         {
    874                                                 $forum_topics_real[$post_data['forum_id']] = 0;
    875                                         }
    876                                         $forum_topics_real[$post_data['forum_id']]++;
    877                                         $num_disapproved++;
    878                                 }
    879 
    880                                 $disapprove_log[] = array(
    881                                         'type'                  => 'topic',
    882                                         'post_subject'  => $post_data['post_subject'],
    883                                         'forum_id'              => $post_data['forum_id'],
    884                                         'topic_id'              => 0, // useless to log a topic id, as it will be deleted
     805                        $post_disapprove_list[$post_id] = $post_data['topic_id'];
     806                        if (!isset($topic_replies_real[$post_data['topic_id']]))
     807                        {
     808                                $topic_replies_real[$post_data['topic_id']] = $post_data['topic_replies_real'];
     809                        }
     810                }
     811
     812                // Now we build the log array
     813                foreach ($post_disapprove_list as $post_id => $topic_id)
     814                {
     815                        // If the count of disapproved posts for the topic is greater
     816                        // than topic's real replies count, the whole topic is disapproved/deleted
     817                        if (sizeof(array_keys($post_disapprove_list, $topic_id)) > $topic_replies_real[$topic_id])
     818                        {
     819                                // Don't write the log more than once for every topic
     820                                if (!isset($disapprove_log_topics[$topic_id]))
     821                                {
     822                                        // Build disapproved topics log
     823                                        $disapprove_log_topics[$topic_id] = array(
     824                                                'type'                  => 'topic',
     825                                                'post_subject'  => $post_info[$post_id]['topic_title'],
     826                                                'forum_id'              => $post_info[$post_id]['forum_id'],
     827                                                'topic_id'              => 0, // useless to log a topic id, as it will be deleted
     828                                        );
     829                                }
     830                        }
     831                        else
     832                        {
     833                                // Build disapproved posts log
     834                                $disapprove_log_posts[] = array(
     835                                        'type'                  => 'post',
     836                                        'post_subject'  => $post_info[$post_id]['post_subject'],
     837                                        'forum_id'              => $post_info[$post_id]['forum_id'],
     838                                        'topic_id'              => $post_info[$post_id]['topic_id'],
    885839                                );
    886                         }
    887                         else
    888                         {
    889                                 if (!isset($topic_replies_real_sql[$post_data['topic_id']]))
    890                                 {
    891                                         $topic_replies_real_sql[$post_data['topic_id']] = 0;
    892                                 }
    893                                 $topic_replies_real_sql[$post_data['topic_id']]++;
    894 
    895                                 $disapprove_log[] = array(
    896                                         'type'                  => 'post',
    897                                         'post_subject'  => $post_data['post_subject'],
    898                                         'forum_id'              => $post_data['forum_id'],
    899                                         'topic_id'              => $post_data['topic_id'],
    900                                 );
    901                         }
    902 
    903                         $post_disapprove_sql[] = $post_id;
    904                 }
    905 
    906                 unset($post_data);
    907 
    908                 if (sizeof($forum_topics_real))
    909                 {
    910                         foreach ($forum_topics_real as $forum_id => $topics_real)
    911                         {
    912                                 $sql = 'UPDATE ' . FORUMS_TABLE . "
    913                                         SET forum_topics_real = forum_topics_real - $topics_real
    914                                         WHERE forum_id = $forum_id";
    915                                 $db->sql_query($sql);
    916                         }
    917                 }
    918 
    919                 if (sizeof($topic_replies_real_sql))
    920                 {
    921                         foreach ($topic_replies_real_sql as $topic_id => $num_replies)
    922                         {
    923                                 $sql = 'UPDATE ' . TOPICS_TABLE . "
    924                                         SET topic_replies_real = topic_replies_real - $num_replies
    925                                         WHERE topic_id = $topic_id";
    926                                 $db->sql_query($sql);
    927                         }
    928                 }
    929 
    930                 if (sizeof($post_disapprove_sql))
     840
     841                        }
     842                }
     843
     844                // Get disapproved posts/topics counts separately
     845                $num_disapproved_topics = sizeof($disapprove_log_topics);
     846                $num_disapproved_posts = sizeof($disapprove_log_posts);
     847
     848                // Build the whole log
     849                $disapprove_log = array_merge($disapprove_log_topics, $disapprove_log_posts);
     850
     851                // Unset unneeded arrays
     852                unset($post_data, $disapprove_log_topics, $disapprove_log_posts);
     853
     854                // Let's do the job - delete disapproved posts
     855                if (sizeof($post_disapprove_list))
    931856                {
    932857                        if (!function_exists('delete_posts'))
     
    936861
    937862                        // We do not check for permissions here, because the moderator allowed approval/disapproval should be allowed to delete the disapproved posts
    938                         delete_posts('post_id', $post_disapprove_sql);
     863                        // Note: function delete_posts triggers related forums/topics sync,
     864                        // so we don't need to call update_post_information later and to adjust real topic replies or forum topics count manually
     865                        delete_posts('post_id', array_keys($post_disapprove_list));
    939866
    940867                        foreach ($disapprove_log as $log_data)
     
    943870                        }
    944871                }
    945                 unset($post_disapprove_sql, $topic_replies_real_sql);
    946 
    947                 update_post_information('topic', array_keys($topic_id_list));
    948 
    949                 if (sizeof($forum_id_list))
    950                 {
    951                         update_post_information('forum', array_keys($forum_id_list));
    952                 }
    953                 unset($topic_id_list, $forum_id_list);
    954872
    955873                $messenger = new messenger();
     
    980898                                                        // Load up the language pack
    981899                                                        $lang = array();
    982                                                         @include($phpbb_root_path . '/language/' . $post_data['user_lang'] . '/mcp.' . $phpEx);
     900                                                        @include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
    983901
    984902                                                        // If we find the reason in this language pack use it
     
    1019937                $messenger->save_queue();
    1020938
    1021                 if (sizeof($forum_topics_real))
    1022                 {
    1023                         $success_msg = ($num_disapproved == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
     939                if ($num_disapproved_topics)
     940                {
     941                        $success_msg = ($num_disapproved_topics == 1) ? 'TOPIC_DISAPPROVED_SUCCESS' : 'TOPICS_DISAPPROVED_SUCCESS';
    1024942                }
    1025943                else
    1026944                {
    1027                         $success_msg = (sizeof($post_id_list) == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
     945                        $success_msg = ($num_disapproved_posts == 1) ? 'POST_DISAPPROVED_SUCCESS' : 'POSTS_DISAPPROVED_SUCCESS';
    1028946                }
    1029947        }
Note: See TracChangeset for help on using the changeset viewer.