DrupalUtils.php in Backup and Migrate 8.4
File
src/Filter/DrupalUtils.php
View source
<?php
namespace BackupMigrate\Drupal\Filter;
use BackupMigrate\Core\Exception\BackupMigrateException;
use BackupMigrate\Core\File\BackupFileReadableInterface;
use BackupMigrate\Core\Plugin\PluginBase;
use BackupMigrate\Core\Config\Config;
use BackupMigrate\Core\Translation\TranslatableTrait;
use Drupal\Core\Database\Database;
class DrupalUtils extends PluginBase {
protected $maintenance_mode;
public function configSchema($params = []) {
$schema = [];
if ($params['operation'] == 'backup' || $params['operation'] == 'restore') {
$schema['groups']['advanced'] = [
'title' => 'Advanced Settings',
];
$schema['fields']['site_offline'] = [
'group' => 'advanced',
'type' => 'boolean',
'title' => $this
->t('Take site offline'),
'description' => $this
->t('Take the site offline during backup and show a maintenance message. Site will be taken back online once the backup is complete.'),
];
}
return $schema;
}
public function configDefaults() {
return new Config([
'disable_query_log' => TRUE,
'site_offline' => FALSE,
]);
}
public function setUp() {
$this
->takeSiteOffline();
}
public function tearDown() {
$this
->takeSiteOnline();
}
protected function takeSiteOffline() {
if ($this
->confGet('site_offline') && !\Drupal::state()
->get('system.maintenance_mode')) {
\Drupal::state()
->set('system.maintenance_mode', TRUE);
$this->maintenance_mode = TRUE;
}
}
protected function takeSiteOnline() {
if ($this->maintenance_mode) {
\Drupal::state()
->set('system.maintenance_mode', FALSE);
}
}
public function beforeRestore(BackupFileReadableInterface $file) {
return $file;
}
}