PUM_Admin_Upgrade_Routine

Class PUM_Admin_Upgrade_Routine


Description Description


Source Source

File: includes/admin/upgrades/class-pum-admin-upgrade-routine.php

class PUM_Admin_Upgrade_Routine {

	/**
	 * Describe the upgrade routine.
	 *
	 * @return string
	 */
	public static function description() {
		return '';
	}

	/**
	 * Run the upgrade routine.
	 *
	 * @return void
	 */
	public static function run() {
	}

	/**
	 * Properly redirects or returns redirect url if DOING_AJAX.
	 *
	 * @param string $redirect
	 */
	public static function redirect( $redirect = '' ) {
		wp_redirect( $redirect );
		exit;
	}

	/**
	 * Generate the next step ajax response or redirect.
	 */
	public static function next_step() {

		$upgrades = PUM_Admin_Upgrades::instance();

		$upgrades->step_up();

		if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
			echo wp_json_encode( array(
				'status' => sprintf( __( 'Step %d of approximately %d running', 'popup-maker' ), $upgrades->get_arg( 'step' ), $upgrades->get_arg( 'steps' ) ),
				'next'   => $upgrades->get_args(),
			) );
			exit;
		} else {
			$redirect = add_query_arg( $upgrades->get_args(), admin_url() );
			PUM_Admin_Upgrade_Routine::redirect( $redirect );
		}

	}

	public static function done() {

		$upgrades = PUM_Admin_Upgrades::instance();

		delete_option( 'pum_doing_upgrade' );

		$upgrades->set_upgrade_complete( $upgrades->current_routine() );

		$upgrades->set_pum_db_ver( $upgrades->get_arg( 'pum-upgrade' ) );

		$next_routine = $upgrades->next_routine();

		if ( $upgrades->has_upgrades() && $next_routine && $upgrades->get_upgrade( $next_routine ) ) {
			if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {

				$upgrades->set_arg( 'step', 1 );
				$upgrades->set_arg( 'completed', 0 );
				$upgrades->set_arg( 'pum-upgrade', $next_routine );

				echo wp_json_encode( array(
					'status' => sprintf( '<strong>%s</strong>', $upgrades->get_upgrade( $next_routine ) ),
					'next'   => $upgrades->get_args(),
				) );
				exit;
			}
		}

	}
}


Top ↑

Methods Methods

  • description — Describe the upgrade routine.
  • done
  • next_step — Generate the next step ajax response or redirect.
  • redirect — Properly redirects or returns redirect url if DOING_AJAX.
  • run — Run the upgrade routine.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.