- Timestamp:
- 06/23/2017 04:21:58 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/classes/class-bbp-converter-base.php
r6573 r6601 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 if ( ! class_exists( 'BBP_Converter_Base' ) ) : 15 16 /** 16 17 * Base class to be extended by specific individual importers … … 85 86 public $convert_users = false; 86 87 88 /** 89 * @var bool Whether to clean up any old converter data. Default false. 90 */ 91 public $clean = false; 92 87 93 /** Methods ***************************************************************/ 88 94 … … 103 109 /** Sanitize Options **************************************************/ 104 110 111 $this->clean = ! empty( $_POST['_bbp_converter_clean'] ); 105 112 $this->convert_users = (bool) get_option( '_bbp_converter_convert_users', false ); 113 $this->halt = (bool) get_option( '_bbp_converter_halt', 0 ); 106 114 $this->max_rows = (int) get_option( '_bbp_converter_rows', 100 ); 107 115 … … 133 141 // Connection failed 134 142 if ( ! $this->opdb->db_connect( false ) ) { 135 wp_die( 'bbp_converter_db_connection_failed', esc_html__( 'Database connection failed.', 'bbpress' ) ); 143 $error = new WP_Error( 'bbp_converter_db_connection_failed', esc_html__( 'Database connection failed.', 'bbpress' ) ); 144 wp_send_json_error( $error ); 136 145 } 137 146 … … 140 149 141 150 /** 142 * Error Reporting151 * Don't wp_die() uncontrollably 143 152 */ 144 $this->wpdb->show_errors( );145 $this->opdb->show_errors( );153 $this->wpdb->show_errors( false ); 154 $this->opdb->show_errors( false ); 146 155 147 156 /** … … 624 633 */ 625 634 public function convert_forum_parents( $start = 1 ) { 626 627 635 $has_update = false; 628 629 if ( ! empty( $this->sync_table ) ) { 630 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ); 631 } else { 632 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ); 633 } 634 635 update_option( '_bbp_converter_query', $query ); 636 637 $forum_array = $this->wpdb->get_results( $query ); 638 639 foreach ( (array) $forum_array as $row ) { 636 $query = ! empty( $this->sync_table ) 637 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ) 638 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' ); 639 640 foreach ( $this->get_results( $query ) as $row ) { 640 641 $parent_id = $this->callback_forumid( $row->meta_value ); 641 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_parent = %d WHERE ID = %d LIMIT 1", $parent_id, $row->value_id ) );642 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_parent = %d WHERE ID = %d LIMIT 1", $parent_id, $row->value_id ) ); 642 643 $has_update = true; 643 644 } … … 652 653 */ 653 654 public function convert_topic_stickies( $start = 1 ) { 654 655 655 $has_update = false; 656 657 if ( ! empty( $this->sync_table ) ) { 658 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ); 659 } else { 660 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ); 661 } 662 663 update_option( '_bbp_converter_query', $query ); 664 665 $sticky_array = $this->wpdb->get_results( $query ); 666 667 foreach ( (array) $sticky_array as $row ) { 656 $query = ! empty( $this->sync_table ) 657 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ) 658 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' ); 659 660 foreach ( $this->get_results( $query ) as $row ) { 668 661 bbp_stick_topic( $row->value_id ); 669 662 $has_update = true; … … 679 672 */ 680 673 public function convert_topic_super_stickies( $start = 1 ) { 681 682 674 $has_update = false; 683 684 if ( ! empty( $this->sync_table ) ) { 685 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ); 686 } else { 687 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ); 688 } 689 690 update_option( '_bbp_converter_query', $query ); 691 692 $sticky_array = $this->wpdb->get_results( $query ); 693 694 foreach ( (array) $sticky_array as $row ) { 675 $query = ! empty( $this->sync_table ) 676 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ) 677 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' ); 678 679 foreach ( $this->get_results( $query ) as $row ) { 695 680 $super = true; 696 681 bbp_stick_topic( $row->value_id, $super ); … … 707 692 */ 708 693 public function convert_topic_closed_topics( $start = 1 ) { 709 710 694 $has_update = false; 711 712 if ( ! empty( $this->sync_table ) ) { 713 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ); 714 } else { 715 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ); 716 } 717 718 update_option( '_bbp_converter_query', $query ); 719 720 $closed_topic = $this->wpdb->get_results( $query ); 721 722 foreach ( (array) $closed_topic as $row ) { 695 $query = ! empty( $this->sync_table ) 696 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ) 697 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' ); 698 699 foreach ( $this->get_results( $query ) as $row ) { 723 700 bbp_close_topic( $row->value_id ); 724 701 $has_update = true; … … 734 711 */ 735 712 public function convert_reply_to_parents( $start = 1 ) { 736 737 713 $has_update = false; 738 739 if ( ! empty( $this->sync_table ) ) { 740 $query = $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ); 741 } else { 742 $query = $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ); 743 } 744 745 update_option( '_bbp_converter_query', $query ); 746 747 $reply_to_array = $this->wpdb->get_results( $query ); 748 749 foreach ( (array) $reply_to_array as $row ) { 714 $query = ! empty( $this->sync_table ) 715 ? $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ) 716 : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' ); 717 718 foreach ( $this->get_results( $query ) as $row ) { 750 719 $reply_to = $this->callback_reply_to( $row->meta_value ); 751 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %d LIMIT 1", $reply_to, '_bbp_reply_to', $row->value_id ) );720 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %d LIMIT 1", $reply_to, '_bbp_reply_to', $row->value_id ) ); 752 721 $has_update = true; 753 722 } … … 781 750 AND wp_postmeta2.meta_key = %s 782 751 LIMIT {$start}, {$this->max_rows}", 'true', '_bbp_old_topic_author_name_id' ); 783 784 } 785 786 update_option( '_bbp_converter_query', $query ); 787 788 $anonymous_topics = $this->wpdb->get_results( $query ); 789 790 foreach ( (array) $anonymous_topics as $row ) { 752 } 753 754 foreach ( $this->get_results( $query ) as $row ) { 791 755 $anonymous_topic_author_id = 0; 792 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_topic_author_id, $row->topic_id ) );756 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_topic_author_id, $row->topic_id ) ); 793 757 794 758 add_post_meta( $row->topic_id, '_bbp_anonymous_name', $row->topic_author ); … … 827 791 } 828 792 829 update_option( '_bbp_converter_query', $query ); 830 831 $anonymous_replies = $this->wpdb->get_results( $query ); 832 833 foreach ( (array) $anonymous_replies as $row ) { 793 foreach ( $this->get_results( $query ) as $row ) { 834 794 $anonymous_reply_author_id = 0; 835 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_reply_author_id, $row->reply_id ) );795 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_reply_author_id, $row->reply_id ) ); 836 796 837 797 add_post_meta( $row->reply_id, '_bbp_anonymous_name', $row->reply_author ); … … 853 813 /** Delete topics/forums/posts ****************************************/ 854 814 855 if ( true === $this->sync_table ) { 856 $query = $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->posts} ON(value_id = ID) WHERE meta_key LIKE '_bbp_%' AND value_type = %s GROUP BY value_id ORDER BY value_id DESC LIMIT {$this->max_rows}", 'post' ); 857 } else { 858 $query = $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key LIKE '_bbp_%' GROUP BY post_id ORDER BY post_id DESC LIMIT {$this->max_rows}" ); 859 } 860 861 update_option( '_bbp_converter_query', $query ); 862 863 $posts = $this->wpdb->get_results( $query, ARRAY_A ); 815 $query = ! empty( $this->sync_table ) 816 ? $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->posts} ON(value_id = ID) WHERE meta_key LIKE '_bbp_%' AND value_type = %s GROUP BY value_id ORDER BY value_id DESC LIMIT {$this->max_rows}", 'post' ) 817 : $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key LIKE '_bbp_%' GROUP BY post_id ORDER BY post_id DESC LIMIT {$this->max_rows}" ); 818 819 $posts = $this->get_results( $query, ARRAY_A ); 864 820 865 821 if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) { … … 872 828 /** Delete users ******************************************************/ 873 829 874 if ( true === $this->sync_table ) { 875 $query = $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->users} ON(value_id = ID) WHERE meta_key = %s AND value_type = %s LIMIT {$this->max_rows}", '_bbp_old_user_id', 'user' ); 876 } else { 877 $query = $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$this->max_rows}", '_bbp_old_user_id' ); 878 } 879 880 update_option( '_bbp_converter_query', $query ); 881 882 $users = $this->wpdb->get_results( $query, ARRAY_A ); 830 $query = ! empty( $this->sync_table ) 831 ? $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->users} ON(value_id = ID) WHERE meta_key = %s AND value_type = %s LIMIT {$this->max_rows}", '_bbp_old_user_id', 'user' ) 832 : $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$this->max_rows}", '_bbp_old_user_id' ); 833 834 $users = $this->get_results( $query, ARRAY_A ); 883 835 884 836 if ( ! empty( $users ) ) { … … 901 853 */ 902 854 public function clean_passwords( $start = 1 ) { 903 904 855 $has_delete = false; 905 856 $query = $this->wpdb->prepare( "SELECT user_id, meta_value FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$start}, {$this->max_rows}", '_bbp_password' ); 906 907 update_option( '_bbp_converter_query', $query ); 908 909 $converted = $this->wpdb->get_results( $query, ARRAY_A ); 857 $converted = $this->get_results( $query, ARRAY_A ); 910 858 911 859 if ( ! empty( $converted ) ) { … … 913 861 foreach ( $converted as $value ) { 914 862 if ( is_serialized( $value['meta_value'] ) ) { 915 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = '' WHERE ID = %d", $value['user_id'] ) );863 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = '' WHERE ID = %d", $value['user_id'] ) ); 916 864 } else { 917 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $value['meta_value'], $value['user_id'] ) );918 $this-> wpdb->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $value['user_id'] ) );865 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $value['meta_value'], $value['user_id'] ) ); 866 $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $value['user_id'] ) ); 919 867 } 920 868 } … … 944 892 private function get_fields( $tablename ) { 945 893 $rval = array(); 946 $field_array = $this-> wpdb->get_results( 'DESCRIBE ' . $tablename, ARRAY_A );894 $field_array = $this->get_results( 'DESCRIBE ' . $tablename, ARRAY_A ); 947 895 948 896 foreach ( $field_array as $field ) { … … 960 908 } 961 909 910 /** Database Wrappers *****************************************************/ 911 912 /** 913 * Update the last query option and return results 914 * 915 * @param string $query 916 * @param string $output 917 */ 918 private function get_row( $query = '' ) { 919 update_option( '_bbp_converter_query', $query ); 920 921 return $this->wpdb->get_row( $query ); 922 } 923 924 /** 925 * Update the last query option and return results 926 * 927 * @param string $query 928 * @param string $output 929 */ 930 private function get_results( $query = '', $output = OBJECT ) { 931 update_option( '_bbp_converter_query', $query ); 932 933 return (array) $this->wpdb->get_results( $query, $output ); 934 } 935 936 /** 937 * Update the last query option and do a general query 938 * 939 * @param string $query 940 */ 941 private function query( $query = '' ) { 942 update_option( '_bbp_converter_query', $query ); 943 944 return $this->wpdb->query( $query ); 945 } 946 962 947 /** Callbacks *************************************************************/ 963 948 … … 969 954 */ 970 955 public function callback_pass( $username, $password ) { 971 $user = $this-> wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) );956 $user = $this->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) ); 972 957 if ( ! empty( $user ) ) { 973 $usermeta = $this-> wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d LIMIT 1", '_bbp_password', $user->ID ) );958 $usermeta = $this->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d LIMIT 1", '_bbp_password', $user->ID ) ); 974 959 975 960 if ( ! empty( $usermeta ) ) { 976 961 if ( $this->authenticate_pass( $password, $usermeta->meta_value ) ) { 977 $this-> wpdb->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", wp_hash_password( $password ), $user->ID ) );978 $this-> wpdb->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $user->ID ) );962 $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", wp_hash_password( $password ), $user->ID ) ); 963 $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $user->ID ) ); 979 964 } 980 965 } … … 990 975 private function callback_forumid( $field ) { 991 976 if ( ! isset( $this->map_forumid[ $field ] ) ) { 992 if ( ! empty( $this->sync_table ) ) { 993 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 994 } else { 995 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 996 } 997 998 if ( ! is_null( $row ) ) { 999 $this->map_forumid[ $field ] = $row->value_id; 1000 } else { 1001 $this->map_forumid[ $field ] = 0; 1002 } 1003 } 977 $row = ! empty( $this->sync_table ) 978 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ) 979 : $this->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_forum_id', $field ) ); 980 981 $this->map_forumid[ $field ] = ! is_null( $row ) 982 ? $row->value_id 983 : 0; 984 } 985 1004 986 return $this->map_forumid[ $field ]; 1005 987 } … … 1013 995 private function callback_topicid( $field ) { 1014 996 if ( ! isset( $this->map_topicid[ $field ] ) ) { 1015 if ( ! empty( $this->sync_table ) ) { 1016 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1017 } else { 1018 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1019 } 1020 1021 if ( ! is_null( $row ) ) { 1022 $this->map_topicid[ $field ] = $row->value_id; 1023 } else { 1024 $this->map_topicid[ $field ] = 0; 1025 } 1026 } 997 $row = ! empty( $this->sync_table ) 998 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ) 999 : $this->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_topic_id', $field ) ); 1000 1001 $this->map_topicid[ $field ] = ! is_null( $row ) 1002 ? $row->value_id 1003 : 0; 1004 } 1005 1027 1006 return $this->map_topicid[ $field ]; 1028 1007 } … … 1038 1017 private function callback_reply_to( $field ) { 1039 1018 if ( ! isset( $this->map_reply_to[ $field ] ) ) { 1040 if ( ! empty( $this->sync_table ) ) { 1041 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1042 } else { 1043 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1044 } 1045 1046 if ( ! is_null( $row ) ) { 1047 $this->map_reply_to[ $field ] = $row->value_id; 1048 } else { 1049 $this->map_reply_to[ $field ] = 0; 1050 } 1051 } 1019 $row = ! empty( $this->sync_table ) 1020 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ) 1021 : $this->get_row( $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_reply_id', $field ) ); 1022 1023 $this->map_reply_to[ $field ] = ! is_null( $row ) 1024 ? $row->value_id 1025 : 0; 1026 } 1027 1052 1028 return $this->map_reply_to[ $field ]; 1053 1029 } … … 1061 1037 private function callback_userid( $field ) { 1062 1038 if ( ! isset( $this->map_userid[ $field ] ) ) { 1063 if ( ! empty( $this->sync_table ) ) { 1064 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1065 } else { 1066 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1067 } 1039 $row = ! empty( $this->sync_table ) 1040 ? $this->get_row( $this->wpdb->prepare( "SELECT value_id, meta_value FROM {$this->sync_table_name} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ) 1041 : $this->get_row( $this->wpdb->prepare( "SELECT user_id AS value_id FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND meta_value = %s LIMIT 1", '_bbp_old_user_id', $field ) ); 1068 1042 1069 1043 if ( ! is_null( $row ) ) { 1070 1044 $this->map_userid[ $field ] = $row->value_id; 1071 1045 } else { 1072 if ( true === $this->convert_users ) { 1073 $this->map_userid[ $field ] = 0; 1074 } else { 1075 $this->map_userid[ $field ] = $field; 1076 } 1046 $this->map_userid[ $field ] = ( true === $this->convert_users ) 1047 ? 0 1048 : $field; 1077 1049 } 1078 1050 } 1051 1079 1052 return $this->map_userid[ $field ]; 1080 1053 } … … 1089 1062 */ 1090 1063 private function callback_check_anonymous( $field ) { 1091 1092 if ( $this->callback_userid( $field ) == 0 ) { 1093 $field = 'true'; 1094 } else { 1095 $field = 'false'; 1096 } 1064 $field = ( $this->callback_userid( $field ) == 0 ) 1065 ? 'true' 1066 : 'false'; 1097 1067 1098 1068 return $field; … … 1110 1080 $this->map_topicid_to_forumid[ $topicid ] = 0; 1111 1081 } elseif ( ! isset( $this->map_topicid_to_forumid[ $topicid ] ) ) { 1112 $row = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT post_parent FROM {$this->wpdb->posts} WHERE ID = %d LIMIT 1", $topicid ) ); 1113 1114 if ( ! is_null( $row ) ) { 1115 $this->map_topicid_to_forumid[ $topicid ] = $row->post_parent; 1116 } else { 1117 $this->map_topicid_to_forumid[ $topicid ] = 0; 1118 } 1082 $row = $this->get_row( $this->wpdb->prepare( "SELECT post_parent FROM {$this->wpdb->posts} WHERE ID = %d LIMIT 1", $topicid ) ); 1083 1084 $this->map_topicid_to_forumid[ $topicid ] = ! is_null( $row ) 1085 ? $row->post_parent 1086 : 0; 1119 1087 } 1120 1088 … … 1150 1118 } 1151 1119 } 1120 endif;
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)