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!
1 file
+ 39
35
Compare changes
  • Side-by-side
  • Inline
+ 39
35
@@ -14,6 +14,7 @@ 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;
@@ -113,6 +114,31 @@ 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.'));
$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('_automatic_updates_stage_id');
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'] = [
'#theme' => 'update_last_check',
'#last' => $this->state->get('update.last_check', 0),
@@ -224,43 +250,21 @@ class UpdaterForm extends FormBase {
// 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
// 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'),
$form['actions'] = [
'submit' => [
'#type' => 'submit',
'#value' => $this->t('Update'),
],
'delete' => [
'#type' => 'submit',
'#value' => $this->t('Delete existing update'),
'#submit' => ['::deleteExistingUpdate'],
'#access' => $stage_exists,
],
'#type' => 'actions',
];
}
return $actions;
return $form;
}
/**
Loading