Changeset 702 for trunk/forum/includes/mcp/mcp_queue.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/mcp/mcp_queue.php
r400 r702 3 3 * 4 4 * @package mcp 5 * @version $Id : mcp_queue.php 9133 2008-11-30 12:03:43Z acydburn$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 106 106 $template->assign_vars(array( 107 107 'S_TOPIC_REVIEW' => true, 108 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'], 108 109 'TOPIC_TITLE' => $post_info['topic_title']) 109 110 ); … … 492 493 493 494 $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(); 498 497 499 498 foreach ($post_info as $post_id => $post_data) 500 499 { 500 if ($post_data['post_approved']) 501 { 502 $post_approved_list[] = $post_id; 503 continue; 504 } 505 501 506 $topic_id_list[$post_data['topic_id']] = 1; 502 507 … … 518 523 if ($post_data['forum_id']) 519 524 { 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' => 0525 );526 }527 528 525 $total_topics++; 529 $forum_topics_posts[$post_data['forum_id']]['forum_topics']++;530 526 } 531 527 $topic_approve_sql[] = $post_data['topic_id']; … … 540 536 else 541 537 { 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 548 538 $approve_log[] = array( 549 539 'type' => 'post', … … 556 546 if ($post_data['forum_id']) 557 547 { 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' => 0563 );564 }565 566 548 $total_posts++; 567 $forum_topics_posts[$post_data['forum_id']]['forum_posts']++;568 549 569 550 // Increment by topic_replies if we approve a topic... … … 572 553 { 573 554 $total_posts += $post_data['topic_replies']; 574 $forum_topics_posts[$post_data['forum_id']]['forum_posts'] += $post_data['topic_replies'];575 555 } 576 556 } 577 557 578 558 $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]]); 585 565 } 586 566 … … 601 581 } 602 582 583 unset($topic_approve_sql, $post_approve_sql); 584 603 585 foreach ($approve_log as $log_data) 604 586 { 605 587 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_replies614 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 }632 588 } 633 589 … … 653 609 if ($total_topics) 654 610 { 655 set_config ('num_topics', $config['num_topics'] +$total_topics, true);611 set_config_count('num_topics', $total_topics, true); 656 612 } 657 613 658 614 if ($total_posts) 659 615 { 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); 670 621 unset($topic_id_list, $forum_id_list); 671 622 … … 734 685 else 735 686 { 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'; 737 688 } 738 689 } … … 846 797 if (confirm_box(true)) 847 798 { 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 855 803 foreach ($post_info as $post_id => $post_data) 856 804 { 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'], 885 839 ); 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)) 931 856 { 932 857 if (!function_exists('delete_posts')) … … 936 861 937 862 // 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)); 939 866 940 867 foreach ($disapprove_log as $log_data) … … 943 870 } 944 871 } 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);954 872 955 873 $messenger = new messenger(); … … 980 898 // Load up the language pack 981 899 $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); 983 901 984 902 // If we find the reason in this language pack use it … … 1019 937 $messenger->save_queue(); 1020 938 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'; 1024 942 } 1025 943 else 1026 944 { 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'; 1028 946 } 1029 947 }
Note:
See TracChangeset
for help on using the changeset viewer.