public function UpdateVersionValidator::checkUpdateVersion in Automatic Updates 8.2
Validates that core is not being updated to another minor or major version.
Parameters
\Drupal\automatic_updates\Event\PreStartEvent|\Drupal\automatic_updates\Event\ReadinessCheckEvent $event: The event object.
1 call to UpdateVersionValidator::checkUpdateVersion()
- UpdateVersionValidator::checkReadinessUpdateVersion in src/
Validator/ UpdateVersionValidator.php - Validates readiness check event.
File
- src/
Validator/ UpdateVersionValidator.php, line 52
Class
- UpdateVersionValidator
- Validates that core updates are within a supported version range.
Namespace
Drupal\automatic_updates\ValidatorCode
public function checkUpdateVersion(UpdateEvent $event) : void {
$from_version = ExtensionVersion::createFromVersionString($this
->getCoreVersion());
$core_package_names = $event
->getActiveComposer()
->getCorePackageNames();
// All the core packages will be updated to the same version, so it doesn't
// matter which specific package we're looking at.
$core_package_name = reset($core_package_names);
$to_version = ExtensionVersion::createFromVersionString($event
->getPackageVersions()[$core_package_name]);
if ($from_version
->getMajorVersion() !== $to_version
->getMajorVersion()) {
$error = ValidationResult::createError([
$this
->t('Updating from one major version to another is not supported.'),
]);
$event
->addValidationResult($error);
}
elseif ($from_version
->getMinorVersion() !== $to_version
->getMinorVersion()) {
$error = ValidationResult::createError([
$this
->t('Updating from one minor version to another is not supported.'),
]);
$event
->addValidationResult($error);
}
}