HEX
Server: Apache
System: Linux ecngx285.inmotionhosting.com 4.18.0-553.79.1.lve.el8.x86_64 #1 SMP Wed Oct 15 17:59:35 UTC 2025 x86_64
User: zeusxp5 (3862)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/zeusxp5/tour.kamille.us/wp-content/plugins/surecart/app/src/Database/GeneralMigration.php
<?php

namespace SureCart\Database;

abstract class GeneralMigration {
	/**
	 * The version number when we will run the migration.
	 *
	 * @var string
	 */
	protected $version = '0.0.0';

	/**
	 * The key for the migration.
	 *
	 * @var string
	 */
	protected $migration_key = 'surecart_migration_version';

	/**
	 * Run on init.
	 *
	 * @return void
	 */
	public function bootstrap() {
		add_action( 'admin_init', [ $this, 'maybeRun' ] );
	}

	/**
	 * Maybe let's run the migration.
	 *
	 * @return void
	 */
	public function maybeRun() {
		if ( ! $this->shouldMigrate() ) {
			return;
		}

		// run the migration.
		$this->run();

		// update the migration complete on admin_init complete, after all migrations have run.
		add_action( 'admin_init', [ $this, 'complete' ], 999999 );
	}

	/**
	 * Should we run this migration?
	 *
	 * @return boolean
	 */
	public function shouldMigrate(): bool {
		// check if we already have done this migration.
		return version_compare( $this->version, $this->getLastMigrationVersion(), '>=' );
	}

	/**
	 * Run the migration
	 *
	 * @return void
	 */
	protected function run() {
	}

	/**
	 * Store the current plugin version when complete.
	 *
	 * @return void
	 */
	public function complete() {
		update_option( $this->migration_key, \SureCart::plugin()->version() );
	}

	/**
	 * Get the last version there was a migration.
	 *
	 * @return string
	 */
	public function getLastMigrationVersion() {
		return get_option( $this->migration_key, '0.0.0' );
	}
}