class PendingUpdatesValidator in Automatic Updates 8.2
Validates that there are no pending database updates.
Hierarchy
- class \Drupal\automatic_updates\Validator\PendingUpdatesValidator implements \Symfony\Component\EventDispatcher\EventSubscriberInterface uses StringTranslationTrait
Expanded class hierarchy of PendingUpdatesValidator
1 string reference to 'PendingUpdatesValidator'
1 service uses PendingUpdatesValidator
File
- src/
Validator/ PendingUpdatesValidator.php, line 17
Namespace
Drupal\automatic_updates\ValidatorView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PendingUpdatesValidator:: |
protected | property | The Drupal root. | |
PendingUpdatesValidator:: |
protected | property | The update registry service. | |
PendingUpdatesValidator:: |
public | function | Validates that there are no pending database updates. | |
PendingUpdatesValidator:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
PendingUpdatesValidator:: |
public | function | Constructs an PendingUpdatesValidator object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |