class 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
File
-
core/
modules/ package_manager/ src/ Validator/ PendingUpdatesValidator.php, line 24
Namespace
Drupal\package_manager\ValidatorView source
final class PendingUpdatesValidator implements EventSubscriberInterface {
use StringTranslationTrait;
public function __construct(string $appRoot, UpdateRegistry $updateRegistry) {
}
/**
* Validates that there are no pending database updates.
*/
public function validate(PreOperationStageEvent $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. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.