DBExcludeFilter.php in Backup and Migrate 8.4
File
lib/backup_migrate_core/src/Filter/DBExcludeFilter.php
View source
<?php
namespace BackupMigrate\Core\Filter;
use BackupMigrate\Core\Config\Config;
use BackupMigrate\Core\Plugin\PluginBase;
use BackupMigrate\Core\Plugin\PluginManager;
use BackupMigrate\Core\Source\DatabaseSourceInterface;
class DBExcludeFilter extends PluginBase {
protected $source_manager;
public function beforeDBTableBackup($table, $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;
}
public function configDefaults() {
return new Config([
'source' => '',
'exclude_tables' => [],
'nodata_tables' => [],
]);
}
public function configSchema($params = []) {
$schema = [];
if ($params['operation'] == 'backup') {
$tables = [];
foreach ($this
->sources()
->getAll() as $source_key => $source) {
if ($source instanceof DatabaseSourceInterface) {
$tables += $source
->getTableNames();
}
if ($tables) {
$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;
}
public function sources() {
return $this->source_manager ? $this->source_manager : new PluginManager();
}
public function setSourceManager($source_manager) {
$this->source_manager = $source_manager;
}
}