42 lines
926 B
PHP
42 lines
926 B
PHP
<?php
|
|
/**
|
|
* @package AKSRT
|
|
*/
|
|
|
|
namespace AKSRT\Core;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class DBMigrator {
|
|
use DBMigratorPart2;
|
|
use DBMigratorPart3;
|
|
use DBMigratorIdentity;
|
|
use DBMigratorVip;
|
|
|
|
/** Current schema version; changing it re-runs dbDelta. */
|
|
const SCHEMA_VERSION = '2.0.0';
|
|
|
|
const OPT_KEY = 'aksrt_db_schema_version';
|
|
|
|
/**
|
|
* Register hooks.
|
|
*/
|
|
public static function init(): void {
|
|
add_action('after_switch_theme', [self::class, 'maybe_migrate']);
|
|
add_action('admin_init', [self::class, 'maybe_migrate']);
|
|
}
|
|
|
|
/**
|
|
* Run table schema upgrade when version mismatches.
|
|
*/
|
|
public static function maybe_migrate(): void {
|
|
$current = get_option(self::OPT_KEY, '');
|
|
if ($current === self::SCHEMA_VERSION) {
|
|
return;
|
|
}
|
|
|
|
self::run();
|
|
update_option(self::OPT_KEY, self::SCHEMA_VERSION);
|
|
}
|
|
}
|