Skip to content
Snippets Groups Projects
Commit 0f8beaf4 authored by Joshua Sedler's avatar Joshua Sedler :cartwheel_tone2: Committed by Damien McKenna
Browse files

Issue #3228379 by grevil, jillh68, solideogloria, slejnej, anybody,...

Issue #3228379 by grevil, jillh68, solideogloria, slejnej, anybody, damienmckenna, chris dart, jcnventura, jamesgrobertson, koffer, cristiroma, mrdrewkeller: Download errors, backup files contain trailing HTML, corrupts archive backups.
parent 9cd24ab0
No related branches found
No related tags found
1 merge request!29Issue #3228379: Failed network - error
Pipeline #304092 passed with warnings
......@@ -33,6 +33,9 @@ By DamienMcKenna: Updated CHANGELOG.txt for recent 5.0.x changes already present
#3438158 by Project Update Bot, grevil, vladimiraus, ankitv18, damienmckenna,
markie, solideogloria, benstallings: Automated Drupal 11 compatibility fixes.
#3472560 by ankitv18, damienmckenna, solideogloria: Fix cspell pipeline.
#3228379 by grevil, jillh68, solideogloria, slejnej, anybody, damienmckenna,
chris dart, jcnventura, jamesgrobertson, koffer, cristiroma, mrdrewkeller:
Download errors, backup files contain trailing HTML, corrupts archive backups.
Backup and Migrate 5.0.x-dev, 2023-xx-xx
......
......@@ -22,6 +22,13 @@ class DrupalBrowserDownloadDestination extends BrowserDownloadDestination {
// $headers); all the way out to the output of the caller.
// Probably need to provide the response as a service in the environment.
parent::saveFile($file);
// Exit here to prevent any further output and the module from breaking.
// @see https://www.drupal.org/project/backup_migrate/issues/3228379
// @todo Firing "exit()" here, will prevent the site coming out of
// maintenance mode. As a current workaround we are simply not allowing
// the "download" destination in combination with "Take site offline".
// @see https://www.drupal.org/project/backup_migrate/issues/3475192
exit();
}
}
......@@ -89,6 +89,16 @@ class BackupMigrateAdvancedBackupForm extends FormBase {
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// @todo Currently there is a problem, where the download destination does not
// support taking the site offline.
// @see https://www.drupal.org/project/backup_migrate/issues/3475192
$destinationId = $form_state->getValue('destination_id');
$siteOffline = !empty($form_state->getValue('utils')['site_offline']) ? $form_state->getValue('utils')['site_offline'] : FALSE;
if ($destinationId === 'download' && $siteOffline) {
$form_state->setErrorByName('destination_id', $this->t('The Backup Destination "Download" does not support taking the site offline during backup.'));
$form_state->setErrorByName('utils][site_offline');
}
$bam = backup_migrate_get_service_object($form_state->getValues());
// Let the plugins validate their own config data.
......
......@@ -15,7 +15,7 @@ class AdminFunctionalityTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['backup_migrate'];
protected static $modules = ['backup_migrate', 'test_page_test'];
/**
* {@inheritdoc}
......@@ -34,6 +34,9 @@ class AdminFunctionalityTest extends BrowserTestBase {
parent::setUp();
$this->container->get('router.builder')->rebuild();
// Set test-page as front page:
$this->config('system.site')->set('page.front', '/test-page')->save();
// Ensure backup_migrate folder exists, the
// `admin/config/development/backup_migrate/backups` path will fail without
// this.
......@@ -482,4 +485,64 @@ class AdminFunctionalityTest extends BrowserTestBase {
$session->pageTextNotContains('There are no backups in this destination.');
}
/**
* Tests the advanced backup.
*
* Tests the advanced backup using the "Take site offline" setting and
* setting the Backup Destination to "Download".
*/
public function testAdvancedBackupWithMaintenanceModeEnabledDestinationDownload() {
$session = $this->assertSession();
$page = $this->getSession()->getPage();
// Got to the advance backup site and create a backup with taking the site
// offline:
$this->drupalGet('/admin/config/development/backup_migrate/advanced');
$session->statusCodeEquals(200);
$page->checkField('edit-utils-site-offline');
$page->selectFieldOption('edit-destination-id', 'download');
$page->pressButton('edit-submit');
// Setting both the site offline and the destination to download should
// not be allowed:
$session->statusCodeEquals(200);
$session->pageTextContains('The Backup Destination "Download" does not support taking the site offline during backup.');
// Uncheck taking the site offline:
$page->uncheckField('edit-utils-site-offline');
$page->pressButton('edit-submit');
// Check if the backup is downloaded now:
$session->statusCodeEquals(200);
$session->responseHeaderContains('Content-Disposition', 'attachment');
// Check if the front page is still reachable after the backup:
$this->drupalGet('<front>');
$session->statusCodeEquals(200);
}
/**
* Tests the advanced backup.
*
* Tests the advanced backup using the "Take site offline" setting and
* setting the Backup Destination to "Private Files Directory".
*/
public function testAdvancedBackupWithMaintenanceModeEnabledDestinationPrivate() {
$session = $this->assertSession();
$page = $this->getSession()->getPage();
// Check if maintenance mode is currently disabled, note that as we have not
// changed it yet, it will be NULL as it is uninitialized:
$this->assertEmpty(\Drupal::state()->get('system.maintenance_mode'));
// Got to the advance backup site and create a backup with taking the site
// offline:
$this->drupalGet('/admin/config/development/backup_migrate/advanced');
$session->statusCodeEquals(200);
$page->checkField('edit-utils-site-offline');
$page->selectFieldOption('edit-destination-id', 'private_files');
$page->pressButton('edit-submit');
// Check if the backup was completed:
$session->statusCodeEquals(200);
$session->pageTextContains('Backup Complete.');
// Maintenance mode should be disabled now, check the front page:
$this->drupalGet('<front>');
$session->statusCodeEquals(200);
// It should be FALSE now, as it was enabled and then disabled:
$this->assertFalse(\Drupal::state()->get('system.maintenance_mode'));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment