Skip to content
Snippets Groups Projects

Issue #3254755: Add method to UpdateRecommender to recommend release during cron.

Open Issue #3254755: Add method to UpdateRecommender to recommend release during cron.
1 unresolved thread
1 unresolved thread
1 file
+ 44
0
Compare changes
  • Side-by-side
  • Inline
+ 44
0
@@ -3,6 +3,7 @@
namespace Drupal\automatic_updates;
use Drupal\automatic_updates_9_3_shim\ProjectRelease;
use Drupal\Core\Extension\ExtensionVersion;
use Drupal\update\UpdateManagerInterface;
/**
@@ -66,4 +67,47 @@ class UpdateRecommender {
return ProjectRelease::createFromArray($project['releases'][$recommended_version]);
}
/**
* Returns the recommended release of Drupal core for updates during cron.
*
* @param bool $refresh
* (optional) Whether to fetch the latest information about available
* updates from drupal.org. This can be an expensive operation, so defaults
* to FALSE.
*
* @return \Drupal\automatic_updates_9_3_shim\ProjectRelease|null
* A value object with information about the recommended release, or NULL
* if Drupal core is already up-to-date.
*
* @throws \LogicException
* If Drupal core is out of date and the recommended version of cannot be
* determined.
*/
public function getRecommendedReleaseDuringCron(bool $refresh = FALSE): ?ProjectRelease {
    • I chatted with @kunal.sachdev and he had the idea to just put the logic in the existing getRecommendedRelease(). We could add a constructor to this class to pass an optional parameter for $stage. If it is a CronUpdater would have slightly different logic.

      We would have to check if $project['recommended'] was the next patch release. Then we would loop through $project['security updates'] and check if any of those were the next patch release.

      Actually this logic may be useful for the form case to. We could evaluate $project['recommended'] and all $project['security updates'] version. If we had private function UpdateVersionValidator::isUpdateVersionSupported() then that function could check if cron updater was being used. Then our logic in getRecommendedRelease() would not have to consider cron.

      That would probably mean that UpdateVersionValidator::isUpdateVersionSupported() would duplicate a lot of logic in \Drupal\automatic_updates\Validator\UpdateVersionValidator::checkUpdateVersion because that method also has to determine if a version is supported for an update depending on whether you are using the cronupdater or not.

      To avoid this we could add public static function validateUpdateVersion(string $from_version_string, string $to_version_string, Updater $updater): ?ValidationResult Then in we won't need UpdateVersionValidator::isUpdateVersionSupported() because in getRecommendedRelease() we could

      if (!UpdateVersionValidator::validateUpdateVersion($project_data['drupal']['existing version'], $project_data['drupal']['recommended'], $this->updater)) {
            // can use release
      }

      and then the same for all the security releases

Please register or sign in to reply
$project = $this->getProjectInfo($refresh);
$from_version_string = $project['drupal']['existing_version'];
$from_version = ExtensionVersion::createFromVersionString($from_version_string);
// If we're already up-to-date, there's nothing else we need to do.
if ($project['status'] === UpdateManagerInterface::CURRENT) {
return NULL;
}
// If we don't know what to recommend they update to, time to freak out.
elseif (empty($project['security updates'])) {
throw new \LogicException('Drupal core is out of date, but the recommended version could not be determined.');
}
$recommended_release = [];
foreach ($project['security updates'] as $security_update) {
$to_version_string = $security_update['version'];
$to_version = ExtensionVersion::createFromVersionString($to_version_string);
if($from_version->getMajorVersion() === $to_version->getMajorVersion() && $from_version->getMajorVersion() === $to_version->getMinorVersion()){
$recommended_release = $security_update;
break;
}
}
if (empty($recommended_release)) {
throw new \LogicException('Drupal core is out of date, but the recommended version could not be determined.');
}
return ProjectRelease::createFromArray($recommended_release);
}
}
Loading