settings = $settings; } /** * Run the pending migrations of the current site. * * @throws RuntimeException When a migration fails; the version stays at the last completed one. */ public function run(): void { $current = $this->settings->schema_version(); foreach ( self::migrations() as $version => $migration ) { if ( $version <= $current ) { continue; } $migration(); $this->settings->set_schema_version( $version ); } } /** * Request-time entry point: upgrade after a plugin update and never break the request when that fails. */ public function maybe_run(): void { if ( $this->settings->schema_version() >= Schema::VERSION ) { return; } try { $this->run(); } catch ( RuntimeException $e ) { wp_trigger_error( __METHOD__, $e->getMessage() ); } } /** * Migrations by the schema version they produce. * * @return array */ private static function migrations(): array { return array( 1 => array( Schema::class, 'install' ), ); } }