You are here

class DrupalUtils in Backup and Migrate 8.4

Class DrupalUtils.

@package BackupMigrate\Drupal\Filter

Hierarchy

Expanded class hierarchy of DrupalUtils

File

src/Filter/DrupalUtils.php, line 17

Namespace

BackupMigrate\Drupal\Filter
View source
class DrupalUtils extends PluginBase {

  /**
   * @var boolean Whether the site was put in maintenance mode before the operation.
   */
  protected $maintenance_mode;

  /**
   * {@inheritdoc}
   */
  public function configSchema($params = []) {
    $schema = [];

    // Backup configuration.
    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;
  }

  /**
   * Get the default values for the plugin.
   *
   * @return \BackupMigrate\Core\Config\Config
   */
  public function configDefaults() {
    return new Config([
      'disable_query_log' => TRUE,
      'site_offline' => FALSE,
    ]);
  }

  /**
   * Run before the backup/restore begins.
   */
  public function setUp() {
    $this
      ->takeSiteOffline();
  }

  /**
   * Run after the operation is complete.
   */
  public function tearDown() {
    $this
      ->takeSiteOnline();
  }

  /**
   * Take the site offline if we need to.
   */
  protected function takeSiteOffline() {

    // Take the site offline.
    if ($this
      ->confGet('site_offline') && !\Drupal::state()
      ->get('system.maintenance_mode')) {
      \Drupal::state()
        ->set('system.maintenance_mode', TRUE);
      $this->maintenance_mode = TRUE;
    }
  }

  /**
   * Take the site online if it was taken offline for this operation.
   */
  protected function takeSiteOnline() {

    // Take the site online again.
    if ($this->maintenance_mode) {
      \Drupal::state()
        ->set('system.maintenance_mode', FALSE);
    }
  }

  /**
   * Perform actions before restoring the backup.
   *
   * This used to perform a file size check but it occurred *after* the file
   * was uploaded and uncompressed, which was a complete waste of time.
   *
   * @todo Remove this.
   *
   * @param BackupFileReadableInterface $file
   *
   * @return BackupFileReadableInterface
   */
  public function beforeRestore(BackupFileReadableInterface $file) {
    return $file;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableTrait::$config protected property The object's configuration object.
ConfigurableTrait::$init protected property The initial configuration. These configuration options can be overriden by the config options but will not be overwritten. If the object is re-configured after construction any missing configuration options will revert to these values.
ConfigurableTrait::confGet public function Get a specific value from the configuration.
ConfigurableTrait::config public function Get the configuration object for this item.
ConfigurableTrait::configErrors public function Get any validation errors in the config.
ConfigurableTrait::setConfig public function Set the configuration for all plugins. 1
ConfigurableTrait::__construct public function 2
DrupalUtils::$maintenance_mode protected property
DrupalUtils::beforeRestore public function Perform actions before restoring the backup.
DrupalUtils::configDefaults public function Get the default values for the plugin. Overrides ConfigurableTrait::configDefaults
DrupalUtils::configSchema public function Get a default (blank) schema. Overrides ConfigurableTrait::configSchema
DrupalUtils::setUp public function Run before the backup/restore begins.
DrupalUtils::takeSiteOffline protected function Take the site offline if we need to.
DrupalUtils::takeSiteOnline protected function Take the site online if it was taken offline for this operation.
DrupalUtils::tearDown public function Run after the operation is complete.
PluginBase::opWeight public function What is the weight of the given operation for this plugin. Overrides PluginInterface::opWeight
PluginBase::supportedOps public function Get a list of supported operations and their weight. Overrides PluginInterface::supportedOps 8
PluginBase::supportsOp public function Does this plugin implement the given operation. Overrides PluginInterface::supportsOp
TranslatableTrait::$translator protected property
TranslatableTrait::setTranslator public function
TranslatableTrait::t public function Translate the given string if there is a translator service available.