BBP_Converter::process_callback()

Callback processor

Description

Source

File: bp-forums/admin/converter.php

	public function process_callback() {

		// Verify intent
		check_ajax_referer( 'bbp_converter_process' );

		// Bail if user cannot view import page
		if ( ! current_user_can( 'bbp_tools_import_page' ) ) {
			wp_die( '0' );
		}

		if ( ! ini_get( 'safe_mode' ) ) {
			set_time_limit( 0 );
			ini_set( 'memory_limit',   '256M' );
			ini_set( 'implicit_flush', '1'    );
			ignore_user_abort( true );
		}

		// Save step and count so that it can be restarted.
		if ( ! get_option( '_bbp_converter_step' ) || ( !empty( $_POST['_bbp_converter_restart'] ) ) ) {
			update_option( '_bbp_converter_step',  1 );
			update_option( '_bbp_converter_start', 0 );
		}

		$step  = (int) get_option( '_bbp_converter_step',  1 );
		$min   = (int) get_option( '_bbp_converter_start', 0 );
		$count = ! empty( $_POST['_bbp_converter_rows'] ) ? min( max( (int) $_POST['_bbp_converter_rows'], 1 ), 5000 ) : 100;
		$max   = ( $min + $count ) - 1;
		$start = $min;

		// Bail if platform did not get saved
		$platform = !empty( $_POST['_bbp_converter_platform' ] ) ? sanitize_text_field( $_POST['_bbp_converter_platform' ] ) : get_option( '_bbp_converter_platform' );
		if ( empty( $platform ) )
			return;

		// Include the appropriate converter.
		$converter = bbp_new_converter( $platform );

		switch ( $step ) {

			// STEP 1. Clean all tables.
			case 1 :
				if ( !empty( $_POST['_bbp_converter_clean'] ) ) {
					if ( $converter->clean( $start ) ) {
						update_option( '_bbp_converter_step',  $step + 1 );
						update_option( '_bbp_converter_start', 0         );
						$this->sync_table( true );
						if ( empty( $start ) ) {
							$this->converter_output( __( 'No data to clean', 'buddyboss' ) );
						}
					} else {
						update_option( '_bbp_converter_start', $max + 1 );
						$this->converter_output( sprintf( __( 'Deleting previously converted data (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
					}
				} else {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
				}

				break;

			// STEP 2. Convert users.
			case 2 :
				if ( !empty( $_POST['_bbp_converter_convert_users'] ) ) {
					if ( $converter->convert_users( $start ) ) {
						update_option( '_bbp_converter_step',  $step + 1 );
						update_option( '_bbp_converter_start', 0         );
						if ( empty( $start ) ) {
							$this->converter_output( __( 'No users to convert', 'buddyboss' ) );
						}
					} else {
						update_option( '_bbp_converter_start', $max + 1 );
						$this->converter_output( sprintf(  __( 'Converting users (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
					}
				} else {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
				}

				break;

			// STEP 3. Clean passwords.
			case 3 :
				if ( !empty( $_POST['_bbp_converter_convert_users'] ) ) {
					if ( $converter->clean_passwords( $start ) ) {
						update_option( '_bbp_converter_step',  $step + 1 );
						update_option( '_bbp_converter_start', 0         );
						if ( empty( $start ) ) {
							$this->converter_output( __( 'No passwords to clear', 'buddyboss' ) );
						}
					} else {
						update_option( '_bbp_converter_start', $max + 1 );
						$this->converter_output( sprintf( __( 'Delete users WordPress default passwords (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
					}
				} else {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
				}

				break;

			// STEP 4. Convert forums.
			case 4 :
				if ( $converter->convert_forums( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No forums to convert', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Converting forums (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 5. Convert forum parents.
			case 5 :
				if ( $converter->convert_forum_parents( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No forum parents to convert', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Calculating forum hierarchy (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 6. Convert discussions.
			case 6 :
				if ( $converter->convert_topics( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No discussions to convert', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Converting discussions (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 7. Stick discussions.
			case 7 :
				if ( $converter->convert_topic_stickies( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No stickies to stick', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Calculating discussion stickies (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 8. Stick to front discussion (Super Sicky).
			case 8 :
				if ( $converter->convert_topic_super_stickies( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No super stickies to stick', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Calculating discussion super stickies (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 9. Convert tags.
			case 9 :
				if ( $converter->convert_tags( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No tags to convert', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Converting discussion tags (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 10. Convert replies.
			case 10 :
				if ( $converter->convert_replies( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No replies to convert', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Converting replies (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			// STEP 11. Convert reply_to parents.
			case 11 :
				if ( $converter->convert_reply_to_parents( $start ) ) {
					update_option( '_bbp_converter_step',  $step + 1 );
					update_option( '_bbp_converter_start', 0         );
					if ( empty( $start ) ) {
						$this->converter_output( __( 'No reply_to parents to convert', 'buddyboss' ) );
					}
				} else {
					update_option( '_bbp_converter_start', $max + 1 );
					$this->converter_output( sprintf( __( 'Calculating reply_to parents (%1$s - %2$s)', 'buddyboss' ), $min, $max ) );
				}

				break;

			default :
				delete_option( '_bbp_converter_step'  );
				delete_option( '_bbp_converter_start' );
				delete_option( '_bbp_converter_query' );

				$this->converter_output( __( 'Conversion Complete', 'buddyboss' ) );

				break;
		}
	}

Changelog

Changelog
Version Description
bbPress (r3813) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.