Skip to content
Snippets Groups Projects

Issue #3248928: Redirect or provide link to apply form for user who started update if accessing start form

Merged Issue #3248928: Redirect or provide link to apply form for user who started update if accessing start form
All threads resolved!
All threads resolved!
Files
3
+ 48
27
@@ -14,10 +14,12 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Url;
use Drupal\package_manager\Exception\StageException;
use Drupal\system\SystemManager;
use Drupal\update\UpdateManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
* Defines a form to update Drupal core.
@@ -57,6 +59,13 @@ class UpdaterForm extends FormBase {
*/
protected $eventDispatcher;
/**
* The current session.
*
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
*/
protected $session;
/**
* Constructs a new UpdaterForm object.
*
@@ -68,12 +77,15 @@ class UpdaterForm extends FormBase {
* The readiness validation manager service.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher service.
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* The current session.
*/
public function __construct(StateInterface $state, Updater $updater, ReadinessValidationManager $readiness_validation_manager, EventDispatcherInterface $event_dispatcher) {
public function __construct(StateInterface $state, Updater $updater, ReadinessValidationManager $readiness_validation_manager, EventDispatcherInterface $event_dispatcher, SessionInterface $session) {
$this->updater = $updater;
$this->state = $state;
$this->readinessValidationManager = $readiness_validation_manager;
$this->eventDispatcher = $event_dispatcher;
$this->session = $session;
}
/**
@@ -91,7 +103,8 @@ class UpdaterForm extends FormBase {
$container->get('state'),
$container->get('automatic_updates.updater'),
$container->get('automatic_updates.readiness_validation_manager'),
$container->get('event_dispatcher')
$container->get('event_dispatcher'),
$container->get('session')
);
}
@@ -101,6 +114,30 @@ class UpdaterForm extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$this->messenger()->addWarning($this->t('This is an experimental Automatic Updater using Composer. Use at your own risk.'));
if ($this->updater->isAvailable()) {
$stage_exists = FALSE;
}
else {
$stage_exists = TRUE;
// If there's a stage ID stored in the session, try to claim the stage
// with it. If we succeed, then an update is already in progress, and the
// current session started it, so redirect them to the confirmation form.
$stage_id = $this->session->get(BatchProcessor::STAGE_ID_SESSION_KEY);
if ($stage_id) {
try {
$this->updater->claim($stage_id);
return $this->redirect('automatic_updates.confirmation_page', [
'stage_id' => $stage_id,
]);
}
catch (StageException $e) {
// We already know a stage exists, even if it's not ours, so we don't
// have to do anything else here.
}
}
}
$form['last_check'] = [
'#theme' => 'update_last_check',
'#last' => $this->state->get('update.last_check', 0),
@@ -210,45 +247,29 @@ class UpdaterForm extends FormBase {
}
$this->displayResults($results, $this->messenger());
// If there were no errors, allow the user to proceed with the update.
if ($this->getOverallSeverity($results) !== SystemManager::REQUIREMENT_ERROR) {
$form['actions'] = $this->actions($form_state);
}
return $form;
}
/**
* Builds the form actions.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return mixed[][]
* The form's actions elements.
*/
protected function actions(FormStateInterface $form_state): array {
$actions = ['#type' => 'actions'];
if (!$this->updater->isAvailable()) {
// If the form has been submitted do not display this error message
if ($stage_exists) {
// If the form has been submitted, do not display this error message
// because ::deleteExistingUpdate() may run on submit. The message will
// still be displayed on form build if needed.
if (!$form_state->getUserInput()) {
$this->messenger()->addError($this->t('Cannot begin an update because another Composer operation is currently in progress.'));
}
$actions['delete'] = [
$form['actions']['delete'] = [
'#type' => 'submit',
'#value' => $this->t('Delete existing update'),
'#submit' => ['::deleteExistingUpdate'],
];
}
else {
$actions['submit'] = [
// If there were no errors, allow the user to proceed with the update.
elseif ($this->getOverallSeverity($results) !== SystemManager::REQUIREMENT_ERROR) {
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Update'),
];
}
return $actions;
$form['actions']['#type'] = 'actions';
return $form;
}
/**
Loading