From cb0dc2a9dfd6e3fabcfff76c9108c4f3933f3dbf Mon Sep 17 00:00:00 2001 From: Bart Jaskulski <bjaskulski@protonmail.com> Date: Tue, 14 Jun 2022 23:09:56 +0200 Subject: [PATCH] feat: dont try to upgrade database if there is no need to --- composer.lock | 36 ++++++++++++++++++------------------ src/WpdbMigrator.php | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/composer.lock b/composer.lock index 2be73c4..98aa1b6 100644 --- a/composer.lock +++ b/composer.lock @@ -107,16 +107,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.6.8", + "version": "1.7.14", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "d76498c5531232cb8386ceb6004f7e013138d3ba" + "reference": "e6f145f196a59c7ca91ea926c87ef3d936c4305f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d76498c5531232cb8386ceb6004f7e013138d3ba", - "reference": "d76498c5531232cb8386ceb6004f7e013138d3ba", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e6f145f196a59c7ca91ea926c87ef3d936c4305f", + "reference": "e6f145f196a59c7ca91ea926c87ef3d936c4305f", "shasum": "" }, "require": { @@ -142,7 +142,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.6.8" + "source": "https://github.com/phpstan/phpstan/tree/1.7.14" }, "funding": [ { @@ -162,20 +162,20 @@ "type": "tidelift" } ], - "time": "2022-05-10T06:54:21+00:00" + "time": "2022-06-14T13:09:35+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.6.2", + "version": "3.7.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" + "reference": "a2cd51b45bcaef9c1f2a4bda48f2dd2fa2b95563" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", - "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a2cd51b45bcaef9c1f2a4bda48f2dd2fa2b95563", + "reference": "a2cd51b45bcaef9c1f2a4bda48f2dd2fa2b95563", "shasum": "" }, "require": { @@ -218,20 +218,20 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2021-12-12T21:44:58+00:00" + "time": "2022-06-13T06:31:38+00:00" }, { "name": "symfony/polyfill-php73", - "version": "v1.25.0", + "version": "v1.26.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5" + "reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5", - "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/e440d35fa0286f77fb45b79a03fedbeda9307e85", + "reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85", "shasum": "" }, "require": { @@ -240,7 +240,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.23-dev" + "dev-main": "1.26-dev" }, "thanks": { "name": "symfony/polyfill", @@ -281,7 +281,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.25.0" + "source": "https://github.com/symfony/polyfill-php73/tree/v1.26.0" }, "funding": [ { @@ -297,7 +297,7 @@ "type": "tidelift" } ], - "time": "2021-06-05T21:20:04+00:00" + "time": "2022-05-24T11:49:31+00:00" }, { "name": "szepeviktor/phpstan-wordpress", diff --git a/src/WpdbMigrator.php b/src/WpdbMigrator.php index 90f0983..f32a02d 100644 --- a/src/WpdbMigrator.php +++ b/src/WpdbMigrator.php @@ -88,9 +88,25 @@ class WpdbMigrator implements Migrator { return new Version( get_option( $this->option_name, '' ) ); } + private function needs_migration(): bool { + $migrations = $this->migrations_repository->get_migrations(); + $last_migration = end( $migrations ); + if ( $last_migration === false ) { + return false; + } + if ( $this->comparator->compare( $last_migration->get_version(), $this->get_current_version() ) ) { + return true; + } + return false; + } + public function migrate(): void { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; + if ( ! $this->needs_migration() ) { + return; + } + $this->logger->info( 'DB update start' ); $current_version = $this->get_current_version(); -- GitLab