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!
+ 53
37
@@ -14,10 +14,12 @@ use Drupal\Core\Form\FormStateInterface;
@@ -14,10 +14,12 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
use Drupal\Core\Link;
use Drupal\Core\State\StateInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Url;
use Drupal\Core\Url;
 
use Drupal\package_manager\Exception\StageException;
use Drupal\system\SystemManager;
use Drupal\system\SystemManager;
use Drupal\update\UpdateManagerInterface;
use Drupal\update\UpdateManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
/**
* Defines a form to update Drupal core.
* Defines a form to update Drupal core.
@@ -57,6 +59,13 @@ class UpdaterForm extends FormBase {
@@ -57,6 +59,13 @@ class UpdaterForm extends FormBase {
*/
*/
protected $eventDispatcher;
protected $eventDispatcher;
 
/**
 
* The current session.
 
*
 
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
 
*/
 
protected $session;
 
/**
/**
* Constructs a new UpdaterForm object.
* Constructs a new UpdaterForm object.
*
*
@@ -68,12 +77,15 @@ class UpdaterForm extends FormBase {
@@ -68,12 +77,15 @@ class UpdaterForm extends FormBase {
* The readiness validation manager service.
* The readiness validation manager service.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher service.
* 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->updater = $updater;
$this->state = $state;
$this->state = $state;
$this->readinessValidationManager = $readiness_validation_manager;
$this->readinessValidationManager = $readiness_validation_manager;
$this->eventDispatcher = $event_dispatcher;
$this->eventDispatcher = $event_dispatcher;
 
$this->session = $session;
}
}
/**
/**
@@ -91,7 +103,8 @@ class UpdaterForm extends FormBase {
@@ -91,7 +103,8 @@ class UpdaterForm extends FormBase {
$container->get('state'),
$container->get('state'),
$container->get('automatic_updates.updater'),
$container->get('automatic_updates.updater'),
$container->get('automatic_updates.readiness_validation_manager'),
$container->get('automatic_updates.readiness_validation_manager'),
$container->get('event_dispatcher')
$container->get('event_dispatcher'),
 
$container->get('session')
);
);
}
}
@@ -101,6 +114,31 @@ class UpdaterForm extends FormBase {
@@ -101,6 +114,31 @@ class UpdaterForm extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
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.'));
$this->messenger()->addWarning($this->t('This is an experimental Automatic Updater using Composer. Use at your own risk.'));
 
$stage_exists = FALSE;
 
if (!$this->updater->isAvailable()) {
 
// 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) {
 
// 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.'));
 
}
 
$stage_exists = TRUE;
 
}
 
}
 
}
 
$form['last_check'] = [
$form['last_check'] = [
'#theme' => 'update_last_check',
'#theme' => 'update_last_check',
'#last' => $this->state->get('update.last_check', 0),
'#last' => $this->state->get('update.last_check', 0),
@@ -212,43 +250,21 @@ class UpdaterForm extends FormBase {
@@ -212,43 +250,21 @@ class UpdaterForm extends FormBase {
// If there were no errors, allow the user to proceed with the update.
// If there were no errors, allow the user to proceed with the update.
if ($this->getOverallSeverity($results) !== SystemManager::REQUIREMENT_ERROR) {
if ($this->getOverallSeverity($results) !== SystemManager::REQUIREMENT_ERROR) {
$form['actions'] = $this->actions($form_state);
$form['actions'] = [
}
'submit' => [
return $form;
'#type' => 'submit',
}
'#value' => $this->t('Update'),
],
/**
'delete' => [
* Builds the form actions.
'#type' => 'submit',
*
'#value' => $this->t('Delete existing update'),
* @param \Drupal\Core\Form\FormStateInterface $form_state
'#submit' => ['::deleteExistingUpdate'],
* The form state.
'#access' => $stage_exists,
*
],
* @return mixed[][]
'#type' => 'actions',
* 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
// 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'] = [
'#type' => 'submit',
'#value' => $this->t('Delete existing update'),
'#submit' => ['::deleteExistingUpdate'],
];
}
else {
$actions['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Update'),
];
];
}
}
return $actions;
return $form;
}
}
/**
/**
Loading