PluginProbe
bbPress / 2.6.17
bbPress v2.6.17
2.6.19 2.6.18 2.6.17 trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 All 74 releases
← All changes | includes/admin/classes/class-bbp-converter-base.php +88 -278 trunk → 2.6.17 View file →
@@ -1,10 +1,10 @@
1 1 <?php
2 2
3 3 /**
4 - * bbPress Converter Base Class.
4 + * bbPress Converter Base Class
5 5 *
6 - * Based on the hard work of Adam Ellis.
6 + * Based on the hard work of Adam Ellis
7 7 *
8 8 * @package bbPress
9 9 * @subpackage Administration
10 10 */
@@ -13,13 +13,13 @@
13 13 defined( 'ABSPATH' ) || exit;
14 14
15 15 if ( ! class_exists( 'BBP_Converter_Base' ) ) :
16 16 /**
17 - * Base class to be extended by specific individual importers.
17 + * Base class to be extended by specific individual importers
18 18 *
19 19 * phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
20 20 *
21 - * @since 2.1.0 bbPress (r3816)
21 + * @since 2.1.0 bbPress (r3813)
22 22 */
23 23 abstract class BBP_Converter_Base {
24 24
25 25 /**
@@ -114,9 +114,9 @@
114 114
115 115 /**
116 116 * Initialize the converter
117 117 *
118 - * @since 2.6.0 bbPress (r6456)
118 + * @since 2.1.0
119 119 */
120 120 private function init() {
121 121
122 122 /** BBCode Parse Properties *******************************************/
@@ -129,9 +129,9 @@
129 129
130 130 /** Sanitize Options **************************************************/
131 131
132 132 $this->clean = ! empty( $_POST['_bbp_converter_clean'] );
133 - $this->convert_users = current_user_can( 'bbp_tools_import_users' ) && (bool) get_option( '_bbp_converter_convert_users', false );
133 + $this->convert_users = (bool) get_option( '_bbp_converter_convert_users', false );
134 134 $this->halt = (bool) get_option( '_bbp_converter_halt', 0 );
135 135 $this->max_rows = (int) get_option( '_bbp_converter_rows', 100 );
136 136
137 137 /** Sanitize Connection ***********************************************/
@@ -155,8 +155,14 @@
155 155
156 156 // Setup old forum Database
157 157 $this->opdb = new BBP_Converter_DB( $db_user, $db_pass, $db_name, $db_host );
158 158
159 + // Connection failed
160 + if ( ! $this->opdb->db_connect( false ) ) {
161 + $error = new WP_Error( 'bbp_converter_db_connection_failed', esc_html__( 'Database connection failed.', 'bbpress' ) );
162 + wp_send_json_error( $error );
163 + }
164 +
159 165 // Maybe setup the database prefix
160 166 $this->opdb->prefix = $db_prefix;
161 167
162 168 /**
@@ -262,28 +268,21 @@
262 268 );
263 269 }
264 270
265 271 /**
266 - * Setup global values.
272 + * Setup global values
267 273 */
268 274 public function setup_globals() {}
269 275
270 276 /**
271 - * Setup fields that require an active source database connection.
272 - *
273 - * @since 2.6.18 bbPress (r7589)
277 + * Convert Forums
274 278 */
275 - protected function setup_source_fields() {}
276 -
277 - /**
278 - * Convert Forums.
279 - */
280 279 public function convert_forums( $start = 1 ) {
281 280 return $this->convert_table( 'forum', $start );
282 281 }
283 282
284 283 /**
285 - * Convert Topics / Threads.
284 + * Convert Topics / Threads
286 285 */
287 286 public function convert_topics( $start = 1 ) {
288 287 return $this->convert_table( 'topic', $start );
289 288 }
@@ -288,9 +287,9 @@
288 287 return $this->convert_table( 'topic', $start );
289 288 }
290 289
291 290 /**
292 - * Convert Posts.
291 + * Convert Posts
293 292 */
294 293 public function convert_replies( $start = 1 ) {
295 294 return $this->convert_table( 'reply', $start );
296 295 }
@@ -295,9 +294,9 @@
295 294 return $this->convert_table( 'reply', $start );
296 295 }
297 296
298 297 /**
299 - * Convert Users.
298 + * Convert Users
300 299 */
301 300 public function convert_users( $start = 1 ) {
302 301 return $this->convert_table( 'user', $start );
303 302 }
@@ -302,9 +301,9 @@
302 301 return $this->convert_table( 'user', $start );
303 302 }
304 303
305 304 /**
306 - * Convert Topic Tags.
305 + * Convert Topic Tags
307 306 */
308 307 public function convert_tags( $start = 1 ) {
309 308 return $this->convert_table( 'tags', $start );
310 309 }
@@ -309,9 +308,9 @@
309 308 return $this->convert_table( 'tags', $start );
310 309 }
311 310
312 311 /**
313 - * Convert Forum Subscriptions.
312 + * Convert Forum Subscriptions
314 313 */
315 314 public function convert_forum_subscriptions( $start = 1 ) {
316 315 return $this->convert_table( 'forum_subscriptions', $start );
317 316 }
@@ -316,9 +315,9 @@
316 315 return $this->convert_table( 'forum_subscriptions', $start );
317 316 }
318 317
319 318 /**
320 - * Convert Topic Subscriptions.
319 + * Convert Topic Subscriptions
321 320 */
322 321 public function convert_topic_subscriptions( $start = 1 ) {
323 322 return $this->convert_table( 'topic_subscriptions', $start );
324 323 }
@@ -323,9 +322,9 @@
323 322 return $this->convert_table( 'topic_subscriptions', $start );
324 323 }
325 324
326 325 /**
327 - * Convert Favorites.
326 + * Convert Favorites
328 327 */
329 328 public function convert_favorites( $start = 1 ) {
330 329 return $this->convert_table( 'favorites', $start );
331 330 }
@@ -330,31 +329,15 @@
330 329 return $this->convert_table( 'favorites', $start );
331 330 }
332 331
333 332 /**
334 - * Convert Table.
333 + * Convert Table
335 334 *
336 - * @since 2.1.0 bbPress (r3816) Connects to the source database when conversion begins.
337 - *
338 335 * @param string $to_type The destination type
339 336 * @param int $start Start row
340 337 */
341 338 public function convert_table( $to_type, $start ) {
342 - // Without account import, do not create users or user engagements.
343 - if ( ! $this->convert_users && in_array( $to_type, array( 'user', 'forum_subscriptions', 'topic_subscriptions', 'favorites' ), true ) ) {
344 - return true;
345 - }
346 339
347 - // Connect to the source database only when conversion begins. This keeps
348 - // first-login password upgrades independent of the source database.
349 - if ( ! $this->opdb->db_connect( false ) ) {
350 - $error = new WP_Error( 'bbp_converter_db_connection_failed', esc_html__( 'Database connection failed.', 'bbpress' ) );
351 - wp_send_json_error( $error );
352 - }
353 -
354 - // Setup fields that depend on the connected source schema.
355 - $this->setup_source_fields();
356 -
357 340 // Set some defaults
358 341 $has_insert = false;
359 342 $from_tablename = '';
360 343 $field_list = $from_tables = $tablefield_array = array();
@@ -467,20 +450,17 @@
467 450
468 451 // This row has a destination that matches one of the
469 452 // columns in this table.
470 453 if ( in_array( $row['to_fieldname'], $tablefield_array, true ) ) {
471 - // Source user IDs must not claim existing WordPress accounts.
472 - if ( ( 'post_author' === $row['to_fieldname'] ) && ! $this->convert_users ) {
473 - $insert_post['post_author'] = 0;
474 454
475 455 // Allows us to set default fields.
476 - } elseif ( isset( $row['default'] ) ) {
456 + if ( isset( $row['default'] ) ) {
477 457 $insert_post[ $row['to_fieldname'] ] = $row['default'];
478 458
479 459 // Translates a field from the old forum.
480 460 } elseif ( isset( $row['callback_method'] ) ) {
481 461 if ( ( 'callback_userid' === $row['callback_method'] ) && ( false === $this->convert_users ) ) {
482 - $insert_post[ $row['to_fieldname'] ] = 0;
462 + $insert_post[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ];
483 463 } else {
484 464 $insert_post[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) );
485 465 }
486 466
@@ -499,9 +479,9 @@
499 479
500 480 // Translates a field from the old forum.
501 481 } elseif ( isset( $row['callback_method'] ) ) {
502 482 if ( ( 'callback_userid' === $row['callback_method'] ) && ( false === $this->convert_users ) ) {
503 - $insert_postmeta[ $row['to_fieldname'] ] = 0;
483 + $insert_postmeta[ $row['to_fieldname'] ] = $forum[ $row['from_fieldname'] ];
504 484 } else {
505 485 $insert_postmeta[ $row['to_fieldname'] ] = call_user_func_array( array( $this, $row['callback_method'] ), array( $forum[ $row['from_fieldname'] ], $forum ) );
506 486 }
507 487
@@ -640,9 +620,9 @@
640 620
641 621 /** Forum, Topic, Reply ***************************/
642 622
643 623 default :
644 - $post_id = $this->insert_post( $insert_post );
624 + $post_id = wp_insert_post( $insert_post, true );
645 625
646 626 if ( is_numeric( $post_id ) ) {
647 627 foreach ( $insert_postmeta as $key => $value ) {
648 628 add_post_meta( $post_id, $key, $value, true );
@@ -698,46 +678,8 @@
698 678 return ! $has_insert;
699 679 }
700 680
701 681 /**
702 - * Insert a converted post without changing imported counts.
703 - *
704 - * Converter field maps include the source forum and topic counts. Prevent
705 - * post-status transition callbacks from incrementing those counts again as
706 - * each converted topic and reply is inserted.
707 - *
708 - * @since 2.6.18 bbPress (r7601)
709 - *
710 - * @param array $post_data Converted post data.
711 - * @return int|WP_Error Post ID on success, WP_Error on failure.
712 - */
713 - protected function insert_post( $post_data = array() ) {
714 - // Keep safe source formatting without trusting imported HTML.
715 - foreach ( array( 'post_content', 'post_excerpt' ) as $field ) {
716 - if ( isset( $post_data[ $field ] ) ) {
717 - $post_data[ $field ] = wp_kses_post( $post_data[ $field ] );
718 - }
719 - }
720 - if ( isset( $post_data['post_title'] ) ) {
721 - $post_data['post_title'] = wp_strip_all_tags( $post_data['post_title'] );
722 - }
723 -
724 - $suppress_count_updates = function () {
725 - return false;
726 - };
727 -
728 - add_filter( 'bbp_pre_update_counts_on_transition_post_status', $suppress_count_updates );
729 -
730 - try {
731 - $post_id = wp_insert_post( $post_data, true );
732 - } finally {
733 - remove_filter( 'bbp_pre_update_counts_on_transition_post_status', $suppress_count_updates );
734 - }
735 -
736 - return $post_id;
737 - }
738 -
739 - /**
740 682 * This method converts old forum hierarchy to new bbPress hierarchy.
741 683 */
742 684 public function convert_forum_parents( $start = 1 ) {
743 685 $has_update = false;
@@ -842,25 +784,25 @@
842 784 $has_update = false;
843 785
844 786 if ( ! empty( $this->sync_table ) ) {
845 787 $query = $this->wpdb->prepare( "SELECT sync_table1.value_id AS topic_id, sync_table1.meta_value AS topic_is_anonymous, sync_table2.meta_value AS topic_author
846 - FROM {$this->sync_table_name} AS sync_table1
847 - INNER JOIN {$this->sync_table_name} AS sync_table2
848 - ON ( sync_table1.value_id = sync_table2.value_id )
849 - WHERE sync_table1.meta_value = %s
850 - AND sync_table2.meta_key = %s
851 - LIMIT {$start}, {$this->max_rows}",
788 + FROM {$this->sync_table_name} AS sync_table1
789 + INNER JOIN {$this->sync_table_name} AS sync_table2
790 + ON ( sync_table1.value_id = sync_table2.value_id )
791 + WHERE sync_table1.meta_value = %s
792 + AND sync_table2.meta_key = %s
793 + LIMIT {$start}, {$this->max_rows}",
852 794 'true',
853 795 '_bbp_old_topic_author_name_id'
854 796 );
855 797 } else {
856 798 $query = $this->wpdb->prepare( "SELECT wp_postmeta1.post_id AS topic_id, wp_postmeta1.meta_value AS topic_is_anonymous, wp_postmeta2.meta_value AS topic_author
857 - FROM {$this->wpdb->postmeta} AS wp_postmeta1
858 - INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2
859 - ON ( wp_postmeta1.post_id = wp_postmeta2.post_id )
860 - WHERE wp_postmeta1.meta_value = %s
861 - AND wp_postmeta2.meta_key = %s
862 - LIMIT {$start}, {$this->max_rows}",
799 + FROM {$this->wpdb->postmeta} AS wp_postmeta1
800 + INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2
801 + ON ( wp_postmeta1.post_id = wp_postmeta2.post_id )
802 + WHERE wp_postmeta1.meta_value = %s
803 + AND wp_postmeta2.meta_key = %s
804 + LIMIT {$start}, {$this->max_rows}",
863 805 'true',
864 806 '_bbp_old_topic_author_name_id'
865 807 );
866 808 }
@@ -887,25 +829,25 @@
887 829 $has_update = false;
888 830
889 831 if ( ! empty( $this->sync_table ) ) {
890 832 $query = $this->wpdb->prepare( "SELECT sync_table1.value_id AS reply_id, sync_table1.meta_value AS reply_is_anonymous, sync_table2.meta_value AS reply_author
891 - FROM {$this->sync_table_name} AS sync_table1
892 - INNER JOIN {$this->sync_table_name} AS sync_table2
893 - ON ( sync_table1.value_id = sync_table2.value_id )
894 - WHERE sync_table1.meta_value = %s
895 - AND sync_table2.meta_key = %s
896 - LIMIT {$start}, {$this->max_rows}",
833 + FROM {$this->sync_table_name} AS sync_table1
834 + INNER JOIN {$this->sync_table_name} AS sync_table2
835 + ON ( sync_table1.value_id = sync_table2.value_id )
836 + WHERE sync_table1.meta_value = %s
837 + AND sync_table2.meta_key = %s
838 + LIMIT {$start}, {$this->max_rows}",
897 839 'true',
898 840 '_bbp_old_reply_author_name_id'
899 841 );
900 842 } else {
901 843 $query = $this->wpdb->prepare( "SELECT wp_postmeta1.post_id AS reply_id, wp_postmeta1.meta_value AS reply_is_anonymous, wp_postmeta2.meta_value AS reply_author
902 - FROM {$this->wpdb->postmeta} AS wp_postmeta1
903 - INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2
904 - ON ( wp_postmeta1.post_id = wp_postmeta2.post_id )
905 - WHERE wp_postmeta1.meta_value = %s
906 - AND wp_postmeta2.meta_key = %s
907 - LIMIT {$start}, {$this->max_rows}",
844 + FROM {$this->wpdb->postmeta} AS wp_postmeta1
845 + INNER JOIN {$this->wpdb->postmeta} AS wp_postmeta2
846 + ON ( wp_postmeta1.post_id = wp_postmeta2.post_id )
847 + WHERE wp_postmeta1.meta_value = %s
848 + AND wp_postmeta2.meta_key = %s
849 + LIMIT {$start}, {$this->max_rows}",
908 850 'true',
909 851 '_bbp_old_reply_author_name_id'
910 852 );
911 853 }
@@ -924,9 +866,9 @@
924 866
925 867 /**
926 868 * This method deletes data from the wp database.
927 869 *
928 - * @since 2.1.0 bbPress (r3816)
870 + * @since 2.6.0 bbPress (r6456)
929 871 */
930 872 public function clean() {
931 873
932 874 // Defaults
@@ -936,22 +878,9 @@
936 878
937 879 $esc_like = $this->wpdb->esc_like( '_bbp_' ) . '%';
938 880 $query = ! empty( $this->sync_table )
939 881 ? $this->wpdb->prepare( "SELECT value_id FROM {$this->sync_table_name} INNER JOIN {$this->wpdb->posts} ON(value_id = ID) WHERE meta_key LIKE %s AND value_type = %s GROUP BY value_id ORDER BY value_id DESC LIMIT {$this->max_rows}", $esc_like, 'post' )
940 - : $this->wpdb->prepare( "SELECT postmeta.post_id AS value_id
941 - FROM {$this->wpdb->postmeta} AS postmeta
942 - INNER JOIN {$this->wpdb->posts} AS posts ON ( postmeta.post_id = posts.ID )
943 - WHERE ( posts.post_type = %s AND postmeta.meta_key = %s )
944 - OR ( posts.post_type = %s AND postmeta.meta_key = %s )
945 - OR ( posts.post_type = %s AND postmeta.meta_key = %s )
946 - GROUP BY postmeta.post_id ORDER BY postmeta.post_id DESC LIMIT {$this->max_rows}",
947 - bbp_get_forum_post_type(),
948 - '_bbp_old_forum_id',
949 - bbp_get_topic_post_type(),
950 - '_bbp_old_topic_id',
951 - bbp_get_reply_post_type(),
952 - '_bbp_old_reply_id'
953 - );
882 + : $this->wpdb->prepare( "SELECT post_id AS value_id FROM {$this->wpdb->postmeta} WHERE meta_key LIKE %s GROUP BY post_id ORDER BY post_id DESC LIMIT {$this->max_rows}", $esc_like );
954 883
955 884 $posts = $this->get_results( $query, ARRAY_A );
956 885
957 886 if ( isset( $posts[0] ) && ! empty( $posts[0]['value_id'] ) ) {
@@ -964,13 +893,8 @@
964 893 }
965 894 }
966 895 }
967 896
968 - // Imported accounts are network-wide and cannot be owned by one site.
969 - if ( is_multisite() ) {
970 - return ! $has_delete;
971 - }
972 -
973 897 /** Delete users ******************************************************/
974 898
975 899 $query = ! empty( $this->sync_table )
976 900 ? $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' )
@@ -997,39 +921,25 @@
997 921
998 922 /**
999 923 * This method deletes passwords from the wp database.
1000 924 *
1001 - * @param int $start Current cleanup offset. Zero starts a new pass.
925 + * @param int $start Start row
1002 926 */
1003 - public function clean_passwords( $start = 0 ) {
927 + public function clean_passwords( $start = 1 ) {
1004 928 $has_delete = false;
1005 - $max_rows = (int) $this->max_rows;
1006 -
1007 - // Use an immutable cursor because native hashes are moved to user_pass and
1008 - // deleted from usermeta. An offset would skip rows as the result set shrinks.
1009 - $cursor = empty( $start )
1010 - ? 0
1011 - : (int) get_option( '_bbp_converter_passwords_cursor', 0 );
1012 -
1013 - $query = $this->wpdb->prepare( "SELECT umeta_id, user_id, meta_value FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND umeta_id > %d ORDER BY umeta_id ASC LIMIT {$max_rows}", '_bbp_password', $cursor );
929 + $query = $this->wpdb->prepare( "SELECT user_id, meta_value FROM {$this->wpdb->usermeta} WHERE meta_key = %s LIMIT {$start}, {$this->max_rows}", '_bbp_password' );
1014 930 $converted = $this->get_results( $query, ARRAY_A );
1015 931
1016 932 if ( ! empty( $converted ) ) {
1017 933 foreach ( $converted as $value ) {
1018 934 if ( is_serialized( $value['meta_value'] ) ) {
1019 - $this->update_password( $value['user_id'], '' );
935 + $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = '' WHERE ID = %d", $value['user_id'] ) );
1020 936 } else {
1021 - $this->update_password( $value['user_id'], $value['meta_value'] );
1022 - delete_user_meta( $value['user_id'], '_bbp_password' );
937 + $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $value['meta_value'], $value['user_id'] ) );
938 + $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $value['user_id'] ) );
1023 939 }
1024 -
1025 - clean_user_cache( $value['user_id'] );
1026 - $cursor = (int) $value['umeta_id'];
1027 940 }
1028 - update_option( '_bbp_converter_passwords_cursor', $cursor, false );
1029 941 $has_delete = true;
1030 - } else {
1031 - delete_option( '_bbp_converter_passwords_cursor' );
1032 942 }
1033 943
1034 944 return ! $has_delete;
1035 945 }
@@ -1047,11 +957,11 @@
1047 957 */
1048 958 abstract protected function info();
1049 959
1050 960 /**
1051 - * This method grabs appropriate fields from the table specified.
961 + * This method grabs appropriate fields from the table specified
1052 962 *
1053 - * @param string $tablename The table name to grab fields from.
963 + * @param string $tablename The table name to grab fields from
1054 964 */
1055 965 private function get_fields( $tablename = '' ) {
1056 966 $retval = array();
1057 967 $field_array = $this->get_results( "DESCRIBE {$tablename}", ARRAY_A );
@@ -1081,9 +991,9 @@
1081 991
1082 992 /** Database Wrappers *****************************************************/
1083 993
1084 994 /**
1085 - * Update the last query option and return results.
995 + * Update the last query option and return results
1086 996 *
1087 997 * @param string $query
1088 998 */
1089 999 private function get_row( $query = '' ) {
@@ -1092,9 +1002,9 @@
1092 1002 return $this->wpdb->get_row( $query ); // phpcs:ignore
1093 1003 }
1094 1004
1095 1005 /**
1096 - * Update the last query option and return results.
1006 + * Update the last query option and return results
1097 1007 *
1098 1008 * @param string $query
1099 1009 * @param string $output
1100 1010 */
@@ -1104,9 +1014,9 @@
1104 1014 return (array) $this->wpdb->get_results( $query, $output ); // phpcs:ignore
1105 1015 }
1106 1016
1107 1017 /**
1108 - * Update the last query option and do a general query.
1018 + * Update the last query option and do a general query
1109 1019 *
1110 1020 * @param string $query
1111 1021 */
1112 1022 private function query( $query = '' ) {
@@ -1115,27 +1025,13 @@
1115 1025 return $this->wpdb->query( $query ); // phpcs:ignore
1116 1026 }
1117 1027
1118 1028 /**
1119 - * Update a converted password without saving its hash in the last query option.
1029 + * Update the last query ran
1120 1030 *
1121 - * @since 2.6.19 bbPress (r7640)
1031 + * @since 2.6.0 bbPress (r6637)
1122 1032 *
1123 - * @param int $user_id User ID.
1124 - * @param string $password Password hash or an empty string.
1125 - */
1126 - private function update_password( $user_id, $password ) {
1127 - $query = $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $password, $user_id );
1128 -
1129 - return $this->wpdb->query( $query ); // phpcs:ignore
1130 - }
1131 -
1132 - /**
1133 - * Update the last query ran.
1134 - *
1135 - * @since 2.6.0 bbPress (r6638)
1136 - *
1137 - * @param string $query The literal MySQL query.
1033 + * @param string $query The literal MySQL query
1138 1034 * @return bool
1139 1035 */
1140 1036 private function update_query( $query = '' ) {
1141 1037 return update_option( '_bbp_converter_query', $query );
@@ -1141,13 +1037,13 @@
1141 1037 return update_option( '_bbp_converter_query', $query );
1142 1038 }
1143 1039
1144 1040 /**
1145 - * Update the number of rows in the current step.
1041 + * Update the number of rows in the current step
1146 1042 *
1147 - * @since 2.6.0 bbPress (r6681)
1043 + * @since 2.6.0 bbPress (r6637)
1148 1044 *
1149 - * @param string $query The literal MySQL query.
1045 + * @param string $query The literal MySQL query
1150 1046 * @return array
1151 1047 */
1152 1048 private function count_rows_by_results( $query = '' ) {
1153 1049 $results = $this->get_results( $query );
@@ -1157,13 +1053,13 @@
1157 1053 return $results;
1158 1054 }
1159 1055
1160 1056 /**
1161 - * Update the number of rows in the current step.
1057 + * Update the number of rows in the current step
1162 1058 *
1163 - * @since 2.6.0 bbPress (r6681)
1059 + * @since 2.6.0 bbPress (r6637)
1164 1060 *
1165 - * @param string $table_name The literal MySQL query.
1061 + * @param string $table_name The literal MySQL query
1166 1062 * @return bool
1167 1063 */
1168 1064 private function count_rows_by_table( $table_name = '' ) {
1169 1065 $count = (int) $this->opdb->get_var( "SELECT COUNT(*) FROM {$table_name}" );
@@ -1173,104 +1069,23 @@
1173 1069
1174 1070 /** Callbacks *************************************************************/
1175 1071
1176 1072 /**
1177 - * Unserialize imported password metadata as an array.
1073 + * Run password through wp_hash_password()
1178 1074 *
1179 - * @since 2.6.18 bbPress (r7589)
1180 - *
1181 - * @param string $serialized_pass Serialized password metadata.
1182 - * @return array|false Password metadata, or false when invalid.
1183 - */
1184 - protected function unserialize_pass( $serialized_pass = '' ) {
1185 - if ( ! is_string( $serialized_pass ) || ! is_serialized( $serialized_pass ) || $this->serialized_pass_has_object( $serialized_pass ) ) {
1186 - return false;
1187 - }
1188 -
1189 - // Malformed source metadata may still warn after is_serialized().
1190 - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
1191 - $pass_array = @unserialize(
1192 - $serialized_pass,
1193 - array(
1194 - 'allowed_classes' => false,
1195 - 'max_depth' => 1,
1196 - )
1197 - );
1198 -
1199 - return is_array( $pass_array )
1200 - ? $pass_array
1201 - : false;
1202 - }
1203 -
1204 - /**
1205 - * Check serialized password metadata for object tokens without instantiating it.
1206 - *
1207 - * Serialized strings are skipped by their declared byte length so object-like
1208 - * text inside a hash or salt does not cause a false positive.
1209 - *
1210 - * @since 2.6.18 bbPress (r7589)
1211 - *
1212 - * @param string $serialized_pass Serialized password metadata.
1213 - * @return bool True when the value contains an object or is unsafe to parse.
1214 - */
1215 - private function serialized_pass_has_object( $serialized_pass = '' ) {
1216 - $length = strlen( $serialized_pass );
1217 -
1218 - for ( $offset = 0; $offset < $length; ++$offset ) {
1219 - $token = $serialized_pass[ $offset ];
1220 -
1221 - if ( in_array( $token, array( 'O', 'C', 'E' ), true ) && isset( $serialized_pass[ $offset + 1 ] ) && ':' === $serialized_pass[ $offset + 1 ] ) {
1222 - return true;
1223 - }
1224 -
1225 - if ( 's' !== $token || ! isset( $serialized_pass[ $offset + 1 ] ) || ':' !== $serialized_pass[ $offset + 1 ] ) {
1226 - continue;
1227 - }
1228 -
1229 - $length_end = strpos( $serialized_pass, ':"', $offset + 2 );
1230 - if ( false === $length_end ) {
1231 - return true;
1232 - }
1233 -
1234 - $string_length = substr( $serialized_pass, $offset + 2, $length_end - $offset - 2 );
1235 - $string_start = $length_end + 2;
1236 - if ( '' === $string_length || ! ctype_digit( $string_length ) || (int) $string_length > $length - $string_start ) {
1237 - return true;
1238 - }
1239 -
1240 - $string_end = $string_start + (int) $string_length;
1241 - if ( ! isset( $serialized_pass[ $string_end ] ) || '"' !== $serialized_pass[ $string_end ] ) {
1242 - return true;
1243 - }
1244 -
1245 - $offset = $string_end;
1246 - }
1247 -
1248 - return false;
1249 - }
1250 -
1251 - /**
1252 - * Run password through wp_hash_password().
1253 - *
1254 - * @since 2.1.0 bbPress (r3866) Added the `$wp_password` parameter.
1255 - *
1256 1075 * @param string $username
1257 - * @param string $password
1258 - * @param string|null $wp_password Optional slashed password for WordPress.
1076 + * @param string $password
1259 1077 */
1260 - public function callback_pass( $username = '', $password = '', $wp_password = null ) {
1078 + public function callback_pass( $username = '', $password = '' ) {
1261 1079
1262 - // Password upgrades run during login, outside of converter progress.
1263 - // Avoid writing these lookups to the last query option on every attempt.
1264 -
1265 1080 // Get user – Bail if not found
1266 - $user = $this->wpdb->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) ); // phpcs:ignore
1081 + $user = $this->get_row( $this->wpdb->prepare( "SELECT * FROM {$this->wpdb->users} WHERE user_login = %s AND user_pass = '' LIMIT 1", $username ) );
1267 1082 if ( empty( $user ) ) {
1268 1083 return;
1269 1084 }
1270 1085
1271 1086 // Get usermeta – Bail if not found
1272 - $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 ) ); // phpcs:ignore
1087 + $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 ) );
1273 1088 if ( empty( $usermeta ) ) {
1274 1089 return;
1275 1090 }
1276 1091
@@ -1289,17 +1104,17 @@
1289 1104 return;
1290 1105 }
1291 1106
1292 1107 // Hash the password
1293 - $new_pass = wp_hash_password( is_null( $wp_password ) ? $password : $wp_password );
1108 + $new_pass = wp_hash_password( $password );
1294 1109
1295 1110 // Update
1296 - $this->update_password( $user->ID, $new_pass );
1111 + $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->users} SET user_pass = %s WHERE ID = %d", $new_pass, $user->ID ) );
1297 1112
1298 1113 // Clean up
1299 1114 unset( $new_pass );
1300 - delete_user_meta( $user->ID, '_bbp_password' );
1301 - delete_user_meta( $user->ID, '_bbp_class' );
1115 + $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_password', $user->ID ) );
1116 + $this->query( $this->wpdb->prepare( "DELETE FROM {$this->wpdb->usermeta} WHERE meta_key = %s AND user_id = %d", '_bbp_class', $user->ID ) );
1302 1117
1303 1118 // Clean the cache for this user since their password was
1304 1119 // upgraded from the old platform to the new.
1305 1120 clean_user_cache( $user->ID );
@@ -1305,9 +1120,9 @@
1305 1120 clean_user_cache( $user->ID );
1306 1121 }
1307 1122
1308 1123 /**
1309 - * A mini cache system to reduce database calls to forum ID's.
1124 + * A mini cache system to reduce database calls to forum ID's
1310 1125 *
1311 1126 * @param string $field
1312 1127 * @return string
1313 1128 */
@@ -1325,9 +1140,9 @@
1325 1140 return $this->map_forumid[ $field ];
1326 1141 }
1327 1142
1328 1143 /**
1329 - * A mini cache system to reduce database calls to topic ID's.
1144 + * A mini cache system to reduce database calls to topic ID's
1330 1145 *
1331 1146 * @param string $field
1332 1147 * @return string
1333 1148 */
@@ -1367,19 +1182,14 @@
1367 1182 return $this->map_reply_to[ $field ];
1368 1183 }
1369 1184
1370 1185 /**
1371 - * A mini cache system to reduce database calls to user ID's.
1186 + * A mini cache system to reduce database calls to user ID's
1372 1187 *
1373 1188 * @param string $field
1374 1189 * @return string
1375 1190 */
1376 1191 private function callback_userid( $field ) {
1377 - // Source IDs must never resolve to unrelated network users.
1378 - if ( ! $this->convert_users ) {
1379 - return 0;
1380 - }
1381 -
1382 1192 if ( ! isset( $this->map_userid[ $field ] ) ) {
1383 1193 $row = ! empty( $this->sync_table )
1384 1194 ? $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 ) )
1385 1195 : $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 ) );
@@ -1396,9 +1206,9 @@
1396 1206 return $this->map_userid[ $field ];
1397 1207 }
1398 1208
1399 1209 /**
1400 - * Check if the topic or reply author is anonymous.
1210 + * Check if the topic or reply author is anonymous
1401 1211 *
1402 1212 * @since 2.6.0 bbPress (r5544)
1403 1213 *
1404 1214 * @param string $field
@@ -1404,9 +1214,9 @@
1404 1214 * @param string $field
1405 1215 * @return string
1406 1216 */
1407 1217 private function callback_check_anonymous( $field ) {
1408 - $field = ! $this->callback_userid( $field )
1218 + $field = ( $this->callback_userid( $field ) == 0 )
1409 1219 ? 'true'
1410 1220 : 'false';
1411 1221
1412 1222 return $field;
@@ -1412,9 +1222,9 @@
1412 1222 return $field;
1413 1223 }
1414 1224
1415 1225 /**
1416 - * A mini cache system to reduce database calls map topics ID's to forum ID's.
1226 + * A mini cache system to reduce database calls map topics ID's to forum ID's
1417 1227 *
1418 1228 * @param string $field
1419 1229 * @return string
1420 1230 */
@@ -1453,9 +1263,9 @@
1453 1263 foreach ( $this->bbcode_parser_properties as $prop => $value ) {
1454 1264 $bbcode->{$prop} = $value;
1455 1265 }
1456 1266
1457 - return $bbcode->Parse( $field );
1267 + return html_entity_decode( $bbcode->Parse( $field ) );
1458 1268 }
1459 1269
1460 1270 protected function callback_null( $field ) {
1461 1271 return is_null( $field )