HEX
Server: Apache
System: Linux sxb1plmcpnl510113.prod.sxb1.secureserver.net 4.18.0-553.58.1.lve.el8.x86_64 #1 SMP Fri Jul 4 12:07:06 UTC 2025 x86_64
User: acnbijigo78q (10488831)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/acnbijigo78q/public_html/wp-content/plugins/acfml/classes/Upgrade/Upgrade.php
<?php

namespace ACFML\Upgrade;

use ACFML\Options;
use WPML\Utilities\Lock;

/**
 * Commands will run in admin only,
 * and below a lock to prevent concurrent upgrades.
 *
 * Changing the class name for a command or
 * adding a new command will re-trigger the whole
 * upgrade process.
 *
 * Each upgrade command is responsible for holding
 * its own status. If a command should not be re-triggered,
 * it should be defined inside the command class.
 */
class Upgrade {

	const LOCK_NAME = 'acfml-upgrade';

	const KEY_LAST_MIGRATION_HASH = 'last-migration-hash';

	/**
	 * @return void
	 */
	public static function init() {
		if ( self::canUpgrade() && self::needsUpgrade() ) {
			Lock::whileLocked( self::LOCK_NAME, 2 * MINUTE_IN_SECONDS, [ __CLASS__, 'run' ] );
		}
	}

	/**
	 * @return bool
	 */
	private static function canUpgrade() {
		if ( wp_doing_ajax() ) {
			return false;
		}

		if ( wp_doing_cron() ) {
			return false;
		}

		if ( defined( 'WP_CLI' ) && WP_CLI ) {
			return false;
		}

		return is_admin();
	}

	/**
	 * @return bool
	 */
	private static function needsUpgrade() {
		return Options::get( self::KEY_LAST_MIGRATION_HASH ) !== CommandsProvider::getHash();
	}

	/**
	 * @return void
	 */
	public static function run() {
		CommandsProvider::get()
			->each( function( $commandClass ) {
				call_user_func( [ $commandClass, 'run' ] );
			} );

		Options::set( self::KEY_LAST_MIGRATION_HASH, CommandsProvider::getHash() );
	}
}