You are here

class DBExcludeFilter in Backup and Migrate 5.0.x

Allows the exclusion of certain data from a database.

@package Drupal\backup_migrate\Core\Filter

Hierarchy

Expanded class hierarchy of DBExcludeFilter

1 file declares its use of DBExcludeFilter
DefaultDBSourcePlugin.php in src/Plugin/BackupMigrateSource/DefaultDBSourcePlugin.php

File

src/Core/Filter/DBExcludeFilter.php, line 15

Namespace

Drupal\backup_migrate\Core\Filter
View source
class DBExcludeFilter extends PluginBase {

  /**
   * @var \Drupal\backup_migrate\Core\Plugin\PluginManager
   */
  protected $sourceManager;

  /**
   * The 'beforeDbTableBackup' plugin op.
   *
   * @param array $table
   * @param array $params
   *
   * @return array $table
   */
  public function beforeDbTableBackup(array $table, array $params = []) {
    $exclude = $this
      ->confGet('exclude_tables');
    $nodata = $this
      ->confGet('nodata_tables');
    if (in_array($table['name'], $exclude)) {
      $table['exclude'] = TRUE;
    }
    if (in_array($table['name'], $nodata)) {
      $table['nodata'] = TRUE;
    }
    return $table;
  }

  /**
   * Get the default values for the plugin.
   *
   * @return \Drupal\backup_migrate\Core\Config\Config
   */
  public function configDefaults() {
    return new Config([
      'source' => '',
      'exclude_tables' => [],
      'nodata_tables' => [],
    ]);
  }

  /**
   * Get a definition for user-configurable settings.
   *
   * @param array $params
   *
   * @return array
   */
  public function configSchema(array $params = []) {
    $schema = [];
    if ($params['operation'] == 'backup') {
      $tables = [];
      foreach ($this
        ->sources()
        ->getAll() as $source_key => $source) {
        if ($source instanceof DatabaseSourceInterface) {
          $tables += $source
            ->getTableNames();
        }
        if ($tables) {

          // Backup settings.
          $schema['groups']['default'] = [
            'title' => $this
              ->t('Exclude database tables'),
          ];
          $table_select = [
            'type' => 'enum',
            'multiple' => TRUE,
            'options' => $tables,
            'actions' => [
              'backup',
            ],
            'group' => 'default',
          ];
          $schema['fields']['exclude_tables'] = $table_select + [
            'title' => $this
              ->t('Exclude these tables entirely'),
          ];
          $schema['fields']['nodata_tables'] = $table_select + [
            'title' => $this
              ->t('Exclude data from these tables'),
          ];
        }
      }
    }
    return $schema;
  }

  /**
   * @return \Drupal\backup_migrate\Core\Plugin\PluginManager
   */
  public function sources() {
    return $this->sourceManager ? $this->sourceManager : new PluginManager();
  }

  /**
   * @param \Drupal\backup_migrate\Core\Plugin\PluginManager $sourceManager
   */
  public function setSourceManager(PluginManager $sourceManager) {
    $this->sourceManager = $sourceManager;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigurableTrait::$config protected property The object's configuration object.
ConfigurableTrait::$init protected property The initial configuration.
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
DBExcludeFilter::$sourceManager protected property
DBExcludeFilter::beforeDbTableBackup public function The 'beforeDbTableBackup' plugin op.
DBExcludeFilter::configDefaults public function Get the default values for the plugin. Overrides ConfigurableTrait::configDefaults
DBExcludeFilter::configSchema public function Get a definition for user-configurable settings. Overrides ConfigurableTrait::configSchema
DBExcludeFilter::setSourceManager public function
DBExcludeFilter::sources public function
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.