diff --git a/automatic_updates_extensions/src/ExtensionUpdater.php b/automatic_updates_extensions/src/ExtensionUpdater.php index 5fc6e2057a356a509ed8b2985ca3653f3ca81742..8e1046bac81724c9c3a7ba6cb2d45934f43c92c8 100644 --- a/automatic_updates_extensions/src/ExtensionUpdater.php +++ b/automatic_updates_extensions/src/ExtensionUpdater.php @@ -3,6 +3,7 @@ namespace Drupal\automatic_updates_extensions; use Drupal\automatic_updates\Exception\UpdateException; +use Drupal\automatic_updates\LegacyVersionUtility; use Drupal\package_manager\Event\StageEvent; use Drupal\package_manager\Exception\StageValidationException; use Drupal\package_manager\Stage; diff --git a/automatic_updates_extensions/src/Validator/UpdateReleaseValidator.php b/automatic_updates_extensions/src/Validator/UpdateReleaseValidator.php index 15c581ee111fad6fa9ed531437b44455bcc17980..9870fbd8c5b61b0261486df3d66ef1636e3ed488 100644 --- a/automatic_updates_extensions/src/Validator/UpdateReleaseValidator.php +++ b/automatic_updates_extensions/src/Validator/UpdateReleaseValidator.php @@ -4,7 +4,7 @@ namespace Drupal\automatic_updates_extensions\Validator; use Drupal\automatic_updates\ProjectInfo; use Drupal\automatic_updates_extensions\ExtensionUpdater; -use Drupal\automatic_updates_extensions\LegacyVersionUtility; +use Drupal\automatic_updates\LegacyVersionUtility; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\Event\PreCreateEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php b/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php index de0f6e2eb04b941ceff79afba4e7496d9853c1b1..013cb6fa01597430df1f2c95f026c710182311a1 100644 --- a/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php +++ b/automatic_updates_extensions/tests/src/Kernel/Validator/UpdateReleaseValidatorTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\automatic_updates_extensions\Kernel\Valdiator; -use Drupal\automatic_updates_extensions\LegacyVersionUtility; +use Drupal\automatic_updates\LegacyVersionUtility; use Drupal\package_manager\Event\PreCreateEvent; use Drupal\package_manager\ValidationResult; use Drupal\Tests\automatic_updates_extensions\Kernel\AutomaticUpdatesExtensionsKernelTestBase; diff --git a/automatic_updates_extensions/src/LegacyVersionUtility.php b/src/LegacyVersionUtility.php similarity index 98% rename from automatic_updates_extensions/src/LegacyVersionUtility.php rename to src/LegacyVersionUtility.php index d2daffa4400bd8ade3974c5543bf92071730360b..f6b2a553449c031b79380d64cecd2013331407ff 100644 --- a/automatic_updates_extensions/src/LegacyVersionUtility.php +++ b/src/LegacyVersionUtility.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\automatic_updates_extensions; +namespace Drupal\automatic_updates; use Drupal\Core\Extension\ExtensionVersion; diff --git a/src/ProjectInfo.php b/src/ProjectInfo.php index 927a855737afe4cfdd24bb81dd8d3e902b19a69e..79391b05afee802851aab9857b4c870d3747d5da 100644 --- a/src/ProjectInfo.php +++ b/src/ProjectInfo.php @@ -2,6 +2,7 @@ namespace Drupal\automatic_updates; +use Composer\Semver\Comparator; use Drupal\automatic_updates_9_3_shim\ProjectRelease; use Drupal\Core\Extension\ExtensionVersion; use Drupal\update\UpdateManagerInterface; @@ -115,7 +116,9 @@ class ProjectInfo { foreach ($available_updates['releases'] as $release_info) { $release = ProjectRelease::createFromArray($release_info); $version = $release->getVersion(); - if ($version === $installed_version) { + $semantic_version = LegacyVersionUtility::convertToSemanticVersion($version); + $semantic_installed_version = LegacyVersionUtility::convertToSemanticVersion($installed_version); + if (Comparator::lessThanOrEqualTo($semantic_version, $semantic_installed_version)) { // Stop searching for releases as soon as we find the installed version. break; } diff --git a/tests/fixtures/release-history/aaa_automatic_updates_test.9.8.2.xml b/tests/fixtures/release-history/aaa_automatic_updates_test.9.8.2.xml index 0d0e8477cba1c8cbc6aa2818d95f1625261f0d1a..e3e53de5adf5c6a51eb4fa0b40e2894945018145 100644 --- a/tests/fixtures/release-history/aaa_automatic_updates_test.9.8.2.xml +++ b/tests/fixtures/release-history/aaa_automatic_updates_test.9.8.2.xml @@ -94,5 +94,29 @@ <term><name>Release type</name><value>Bug fixes</value></term> </terms> </release> + <release> + <name>AAA 7.0.0-dev</name> + <version>7.0.x-dev</version> + <status>published</status> + <release_link>http://example.com/aaa_automatic_updates_test-9-7-0-dev-release</release_link> + <download_link>http://example.com/aaa_automatic_updates_test-9-7-0-dev.tar.gz</download_link> + <date>1250424521</date> + <terms> + <term><name>Release type</name><value>New features</value></term> + <term><name>Release type</name><value>Bug fixes</value></term> + </terms> + </release> + <release> + <name>AAA 8.x-6.x-dev</name> + <version>8.x-6.x-dev</version> + <status>published</status> + <release_link>http://example.com/aaa_automatic_updates_test-9-8-0-dev-release</release_link> + <download_link>http://example.com/aaa_automatic_updates_test-9-8-0-dev.tar.gz</download_link> + <date>1250424521</date> + <terms> + <term><name>Release type</name><value>New features</value></term> + <term><name>Release type</name><value>Bug fixes</value></term> + </terms> + </release> </releases> </project> diff --git a/tests/src/Kernel/ProjectInfoTest.php b/tests/src/Kernel/ProjectInfoTest.php index e19e20b2d522bf971206b2305886415ce46dedf2..7b11e703b0e17b367520fce2dc71a48f66af12d4 100644 --- a/tests/src/Kernel/ProjectInfoTest.php +++ b/tests/src/Kernel/ProjectInfoTest.php @@ -104,6 +104,16 @@ class ProjectInfoTest extends AutomaticUpdatesKernelTestBase { '8.x-6.1', ['7.0.1', '7.0.0', '7.0.0-alpha1', '8.x-6.2'], ], + 'contrib, semver and legacy, on semantic dev' => [ + 'aaa_automatic_updates_test.9.8.2.xml', + '7.0.x-dev', + ['7.0.1', '7.0.0', '7.0.0-alpha1'], + ], + 'contrib, semver and legacy, on legacy dev' => [ + 'aaa_automatic_updates_test.9.8.2.xml', + '8.x-6.x-dev', + ['7.0.1', '7.0.0', '7.0.0-alpha1', '8.x-6.2', '8.x-6.1', '8.x-6.0', '8.x-6.0-alpha1'], + ], ]; } diff --git a/tests/src/Kernel/ReadinessValidation/InstalledVersionValidatorTest.php b/tests/src/Kernel/ReadinessValidation/InstalledVersionValidatorTest.php index 3fb138504ee28be0b12914e9d9f8fedcbfa66b8d..69ace78cff6f1d4a268a8278e2d13f6597fa51c0 100644 --- a/tests/src/Kernel/ReadinessValidation/InstalledVersionValidatorTest.php +++ b/tests/src/Kernel/ReadinessValidation/InstalledVersionValidatorTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\automatic_updates\Kernel\ReadinessValidation; +use Drupal\automatic_updates\CronUpdater; use Drupal\package_manager\ValidationResult; use Drupal\Tests\automatic_updates\Kernel\AutomaticUpdatesKernelTestBase; @@ -22,6 +23,11 @@ class InstalledVersionValidatorTest extends AutomaticUpdatesKernelTestBase { */ public function testInstalledVersionValidation(): void { $this->setCoreVersion('9.8.0-dev'); + // Disable cron to avoid messages from other validators. + // @see \Drupal\automatic_updates\Validator\CronUpdateVersionValidator + $this->config('automatic_updates.settings') + ->set('cron', CronUpdater::DISABLED) + ->save(); $result = ValidationResult::createError([ 'Drupal cannot be automatically updated from the installed version, 9.8.0-dev, because automatic updates from a dev version to any other version are not supported.', diff --git a/automatic_updates_extensions/tests/src/Unit/LegacyVersionUtilityTest.php b/tests/src/Unit/LegacyVersionUtilityTest.php similarity index 88% rename from automatic_updates_extensions/tests/src/Unit/LegacyVersionUtilityTest.php rename to tests/src/Unit/LegacyVersionUtilityTest.php index df52a4b2b5883c877446480208835903bd2956fe..1d3da036bbd3cf15a6ee0ef7f59f7bcc6973934c 100644 --- a/automatic_updates_extensions/tests/src/Unit/LegacyVersionUtilityTest.php +++ b/tests/src/Unit/LegacyVersionUtilityTest.php @@ -1,14 +1,14 @@ <?php -namespace Drupal\Tests\automatic_updates_extensions\Unit; +namespace Drupal\Tests\automatic_updates\Unit; -use Drupal\automatic_updates_extensions\LegacyVersionUtility; +use Drupal\automatic_updates\LegacyVersionUtility; use Drupal\Tests\UnitTestCase; /** - * @coversDefaultClass \Drupal\automatic_updates_extensions\LegacyVersionUtility + * @coversDefaultClass \Drupal\automatic_updates\LegacyVersionUtility * - * @group automatic_updates_extensions + * @group automatic_updates */ class LegacyVersionUtilityTest extends UnitTestCase {