You are here

class PendingUpdatesValidator in Automatic Updates 8.2

Validates that there are no pending database updates.

Hierarchy

Expanded class hierarchy of PendingUpdatesValidator

1 string reference to 'PendingUpdatesValidator'
automatic_updates.services.yml in ./automatic_updates.services.yml
automatic_updates.services.yml
1 service uses PendingUpdatesValidator
automatic_updates.pending_updates_validator in ./automatic_updates.services.yml
Drupal\automatic_updates\Validator\PendingUpdatesValidator

File

src/Validator/PendingUpdatesValidator.php, line 17

Namespace

Drupal\automatic_updates\Validator
View source
class PendingUpdatesValidator implements EventSubscriberInterface {
  use StringTranslationTrait;

  /**
   * The Drupal root.
   *
   * @var string
   */
  protected $appRoot;

  /**
   * The update registry service.
   *
   * @var \Drupal\Core\Update\UpdateRegistry
   */
  protected $updateRegistry;

  /**
   * Constructs an PendingUpdatesValidator object.
   *
   * @param string $app_root
   *   The Drupal root.
   * @param \Drupal\Core\Update\UpdateRegistry $update_registry
   *   The update registry service.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation
   *   The translation service.
   */
  public function __construct(string $app_root, UpdateRegistry $update_registry, TranslationInterface $translation) {
    $this->appRoot = $app_root;
    $this->updateRegistry = $update_registry;
    $this
      ->setStringTranslation($translation);
  }

  /**
   * Validates that there are no pending database updates.
   *
   * @param \Drupal\automatic_updates\Event\UpdateEvent $event
   *   The update event.
   */
  public function checkPendingUpdates(UpdateEvent $event) {
    require_once $this->appRoot . '/core/includes/install.inc';
    require_once $this->appRoot . '/core/includes/update.inc';
    drupal_load_updates();
    $hook_updates = update_get_update_list();
    $post_updates = $this->updateRegistry
      ->getPendingUpdateFunctions();
    if ($hook_updates || $post_updates) {
      $message = $this
        ->t('Some modules have database schema updates to install. You should run the <a href=":update">database update script</a> immediately.', [
        ':update' => Url::fromRoute('system.db_update')
          ->toString(),
      ]);
      $error = ValidationResult::createError([
        $message,
      ]);
      $event
        ->addValidationResult($error);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      AutomaticUpdatesEvents::PRE_START => 'checkPendingUpdates',
      AutomaticUpdatesEvents::READINESS_CHECK => 'checkPendingUpdates',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PendingUpdatesValidator::$appRoot protected property The Drupal root.
PendingUpdatesValidator::$updateRegistry protected property The update registry service.
PendingUpdatesValidator::checkPendingUpdates public function Validates that there are no pending database updates.
PendingUpdatesValidator::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
PendingUpdatesValidator::__construct public function Constructs an PendingUpdatesValidator object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.