diff --git a/src/AbstractMigrationsRepository.php b/src/AbstractMigrationsRepository.php index 674d896d77da1e75ea1acfad727116e8c22f1256..5f1c81b6ba3ce38b2db9ec8c2cda849f79ae0e3f 100644 --- a/src/AbstractMigrationsRepository.php +++ b/src/AbstractMigrationsRepository.php @@ -41,6 +41,7 @@ abstract class AbstractMigrationsRepository implements MigrationsRepository { $this->migrations[ (string) $version ] = new AvailableMigration( $version, $migration ); } + /** @return iterable<AvailableMigration> */ public function get_migrations(): iterable { $this->load_migrations(); diff --git a/src/Version/WpdbMigrationFactory.php b/src/Version/WpdbMigrationFactory.php index 8594e3a6bd3f37dd58a2918a5fd2dd95977b4be2..91b63aa7a05fc84da5087da8dbc6166fe3d5af67 100644 --- a/src/Version/WpdbMigrationFactory.php +++ b/src/Version/WpdbMigrationFactory.php @@ -19,6 +19,11 @@ class WpdbMigrationFactory implements MigrationFactory { $this->logger = $logger; } + /** + * @param class-string<AbstractMigration> $migration_class + * + * @return AbstractMigration + */ public function create_version( string $migration_class ): AbstractMigration { return new $migration_class( $this->wpdb, diff --git a/src/WpdbMigrator.php b/src/WpdbMigrator.php index f32a02d0e0a33b831680212d8059c0cdf0b1fde2..c3166e287f23522df3a830235e0ebe1e0ed39755 100644 --- a/src/WpdbMigrator.php +++ b/src/WpdbMigrator.php @@ -111,16 +111,22 @@ class WpdbMigrator implements Migrator { $current_version = $this->get_current_version(); foreach ( $this->migrations_repository->get_migrations() as $migration ) { - if ( $this->comparator->compare( $migration->get_version(), $this->get_current_version() ) ) { + if ( + $this->comparator->compare( + $migration->get_version(), + $this->get_current_version() + ) === 1 + ) { $this->logger->info( sprintf( 'DB update %s:%s', $current_version, $migration->get_version() ) ); try { $migration->get_migration()->up(); $this->logger->info( sprintf( 'DB update %s:%s -> ', $current_version, $migration->get_version() ) . 'OK' ); update_option( $this->option_name, (string) $migration->get_version(), true ); } catch ( \Throwable $e ) { + // @phpstan-ignore-next-line $error_msg = sprintf( 'Error while upgrading a database: %s', $this->wpdb->last_error ); $this->logger->error( $error_msg ); - trigger_error( $error_msg, E_USER_WARNING ); + trigger_error( $error_msg, E_USER_WARNING ); // phpcs:ignore } } }