class PendingUpdatesValidator

Same name and namespace in other branches
  1. 11.x core/modules/package_manager/src/Validator/PendingUpdatesValidator.php \Drupal\package_manager\Validator\PendingUpdatesValidator

Validates that there are no pending database updates.

@internal This is an internal part of Package Manager and may be changed or removed at any time without warning. External code should not interact with this class.

Hierarchy

  • class \Drupal\package_manager\Validator\PendingUpdatesValidator implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait

Expanded class hierarchy of PendingUpdatesValidator

1 file declares its use of PendingUpdatesValidator
PendingUpdatesValidatorTest.php in core/modules/package_manager/tests/src/Kernel/PendingUpdatesValidatorTest.php

File

core/modules/package_manager/src/Validator/PendingUpdatesValidator.php, line 24

Namespace

Drupal\package_manager\Validator
View source
final class PendingUpdatesValidator implements EventSubscriberInterface {
  use StringTranslationTrait;
  public function __construct(private readonly string $appRoot, private readonly UpdateRegistry $updateRegistry) {
  }
  
  /**
   * Validates that there are no pending database updates.
   */
  public function validate(SandboxValidationEvent $event) : void {
    if ($this->updatesExist()) {
      $message = $this->t('Some modules have database updates pending. You should run the <a href=":update">database update script</a> immediately.', [
        ':update' => Url::fromRoute('system.db_update')->toString(),
      ]);
      $event->addError([
        $message,
      ]);
    }
  }
  
  /**
   * Checks if there are any pending update or post-update hooks.
   *
   * @return bool
   *   TRUE if there are any pending update or post-update hooks, FALSE
   *   otherwise.
   */
  public function updatesExist() : bool {
    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();
    return $hook_updates || $post_updates;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() : array {
    return [
      PreCreateEvent::class => 'validate',
      StatusCheckEvent::class => 'validate',
      PreApplyEvent::class => 'validate',
    ];
  }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
PendingUpdatesValidator::getSubscribedEvents public static function
PendingUpdatesValidator::updatesExist public function Checks if there are any pending update or post-update hooks.
PendingUpdatesValidator::validate public function Validates that there are no pending database updates.
PendingUpdatesValidator::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
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. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.