Skip to content
Snippets Groups Projects
Verified Commit c3fb21d0 authored by Bartek Jaskulski's avatar Bartek Jaskulski
Browse files

fix: respect migration status and break loop on error


Signed-off-by: default avatarBart Jaskulski <bjaskulski@protonmail.com>
parent faa9ebc0
No related branches found
No related tags found
No related merge requests found
......@@ -108,8 +108,21 @@ class WpdbMigrator implements Migrator {
}
$this->logger->info( 'DB update start' );
$current_version = $this->get_current_version();
try {
$this->do_migrate();
} 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( esc_html( $error_msg ), E_USER_WARNING ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
}
$this->logger->info( 'DB update finished' );
}
private function do_migrate(): void {
$current_version = $this->get_current_version();
foreach ( $this->migrations_repository->get_migrations() as $migration ) {
if (
$this->comparator->compare(
......@@ -117,21 +130,18 @@ class WpdbMigrator implements Migrator {
$this->get_current_version()
) > 0
) {
$this->logger->info( sprintf( 'DB update %s:%s', $current_version, $migration->get_version() ) );
try {
$migration->get_migration()->up();
$success = $migration->get_migration()->up();
if ( $success ) {
$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 ); // phpcs:ignore
} else {
throw new \RuntimeException();
}
}
}
$this->logger->info( 'DB update finished' );
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment