You are here

class UpdateRecommender in Automatic Updates 8.2

Determines the recommended release of Drupal core to update to.

Hierarchy

Expanded class hierarchy of UpdateRecommender

5 files declare their use of UpdateRecommender
automatic_updates.module in ./automatic_updates.module
Contains hook implementations for Automatic Updates.
ReadinessValidationManager.php in src/Validation/ReadinessValidationManager.php
TestController.php in tests/modules/automatic_updates_test/src/TestController.php
UpdateRecommenderTest.php in tests/src/Kernel/UpdateRecommenderTest.php
UpdaterForm.php in src/Form/UpdaterForm.php

File

src/UpdateRecommender.php, line 11

Namespace

Drupal\automatic_updates
View source
class UpdateRecommender {

  /**
   * Returns up-to-date project information for Drupal core.
   *
   * @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 array
   *   The retrieved project information for Drupal core.
   *
   * @throws \RuntimeException
   *   If data about available updates cannot be retrieved.
   */
  public function getProjectInfo(bool $refresh = FALSE) : array {
    $available_updates = update_get_available($refresh);
    if (empty($available_updates)) {
      throw new \RuntimeException('There was a problem getting update information. Try again later.');
    }
    $project_data = update_calculate_project_data($available_updates);
    return $project_data['drupal'];
  }

  /**
   * Returns the recommended release of Drupal core.
   *
   * @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 getRecommendedRelease(bool $refresh = FALSE) : ?ProjectRelease {
    $project = $this
      ->getProjectInfo($refresh);

    // If we're already up-to-date, there's nothing else we need to do.
    if ($project['status'] === UpdateManagerInterface::CURRENT) {
      return NULL;
    }
    elseif (empty($project['recommended'])) {
      throw new \LogicException('Drupal core is out of date, but the recommended version could not be determined.');
    }
    $recommended_version = $project['recommended'];
    return ProjectRelease::createFromArray($project['releases'][$recommended_version]);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UpdateRecommender::getProjectInfo public function Returns up-to-date project information for Drupal core.
UpdateRecommender::getRecommendedRelease public function Returns the recommended release of Drupal core.