diff --git a/src/Form/UpdateReady.php b/src/Form/UpdateReady.php index 48954ad4e8f35c2c89df4484acfe37ae19cab79d..6f81bac387c51e8edbf92732982407111f13ddee 100644 --- a/src/Form/UpdateReady.php +++ b/src/Form/UpdateReady.php @@ -139,6 +139,11 @@ class UpdateReady extends FormBase { ]; $form['actions'] = ['#type' => 'actions']; + $form['actions']['cancel'] = [ + '#type' => 'submit', + '#value' => $this->t('Cancel update'), + '#submit' => ['::cancel'], + ]; $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Continue'), @@ -184,4 +189,13 @@ class UpdateReady extends FormBase { batch_set($batch); } + /** + * Cancels the in-progress update. + */ + public function cancel(array &$form, FormStateInterface $form_state): void { + $this->updater->destroy(); + $this->messenger()->addStatus($this->t('The update was successfully cancelled.')); + $form_state->setRedirect('automatic_updates.report_update'); + } + } diff --git a/tests/src/Functional/UpdaterFormTest.php b/tests/src/Functional/UpdaterFormTest.php index 71140ad70313dfdf8592da201e92d9d015002c00..3705748c178dbd3dd02863e38af8096b99a712a1 100644 --- a/tests/src/Functional/UpdaterFormTest.php +++ b/tests/src/Functional/UpdaterFormTest.php @@ -263,6 +263,7 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { // Delete the existing update. $page->pressButton('Delete existing update'); + $assert_session->pageTextContains('Staged update deleted'); $assert_session->pageTextNotContains('Cannot begin an update because another Composer operation is currently in progress.'); // Ensure we can start another update after deleting the existing one. @@ -273,6 +274,12 @@ class UpdaterFormTest extends AutomaticUpdatesFunctionalTestBase { $this->assertUpdateReady(); $this->assertUpdateStagedTimes(2); $assert_session->buttonExists('Continue'); + // Cancel the update, then ensure that we are bounced back to the start + // page, and that it will allow us to begin the update anew. + $page->pressButton('Cancel update'); + $assert_session->addressEquals('/admin/reports/updates/automatic-update'); + $assert_session->pageTextContains('The update was successfully cancelled.'); + $assert_session->buttonExists('Update'); } /**