class MetadataWriter in Backup and Migrate 5.0.x
Add metadata such as a description to the backup file.
@package Drupal\backup_migrate\Core\Filter
Hierarchy
- class \Drupal\backup_migrate\Core\Plugin\PluginBase implements ConfigurableInterface, PluginInterface uses ConfigurableTrait
- class \Drupal\backup_migrate\Core\Filter\MetadataWriter implements FileProcessorInterface, PluginCallerInterface uses FileProcessorTrait, PluginCallerTrait
Expanded class hierarchy of MetadataWriter
1 file declares its use of MetadataWriter
- backup_migrate.module in ./
backup_migrate.module - Primary hook implementations for Backup Migrate.
File
- src/
Core/ Filter/ MetadataWriter.php, line 18
Namespace
Drupal\backup_migrate\Core\FilterView source
class MetadataWriter extends PluginBase implements FileProcessorInterface, PluginCallerInterface {
use FileProcessorTrait;
use PluginCallerTrait;
/**
* {@inheritdoc}
*/
public function configSchema(array $params = []) {
$schema = [];
// Backup configuration.
if ($params['operation'] == 'backup') {
$schema['groups']['advanced'] = [
'title' => 'Advanced Settings',
];
$schema['fields']['description'] = [
'group' => 'advanced',
'type' => 'text',
'title' => 'Description',
'multiline' => TRUE,
];
}
return $schema;
}
/**
* Get the default values for the plugin.
*
* @return \Drupal\backup_migrate\Core\Config\Config
*/
public function configDefaults() {
return new Config([
'description' => '',
'generator' => 'Backup and Migrate',
'generatorversion' => defined('BACKUP_MIGRATE_CORE_VERSION') ? constant('BACKUP_MIGRATE_CORE_VERSION') : 'unknown',
'generatorurl' => 'https://github.com/backupmigrate',
'bam_sourceid' => '',
]);
}
/**
* Generate a list of metadata keys to be stored with the backup.
*
* @return array
*/
protected function getMetaKeys() {
return [
'description',
'generator',
'generatorversion',
'generatorurl',
'bam_sourceid',
'bam_scheduleid',
];
}
/**
* Run before the backup/restore begins.
*/
public function setUp($operand, $options) {
if ($options['operation'] == 'backup' && $options['source_id']) {
$this
->config()
->set('bam_sourceid', $options['source_id']);
if ($source = $this
->plugins()
->get($options['source_id'])) {
// @todo Query the source for it's type and name.
}
}
return $operand;
}
/**
* Run after a backup. Add metadata to the file.
*
* @param \Drupal\backup_migrate\Core\File\BackupFileWritableInterface $file
*
* @return \Drupal\backup_migrate\Core\File\BackupFileWritableInterface
*/
public function afterBackup(BackupFileWritableInterface $file) {
// Add the various metadata.
foreach ($this
->getMetaKeys() as $key) {
$value = $this
->confGet($key);
$file
->setMeta($key, $value);
}
return $file;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableTrait:: |
protected | property | The object's configuration object. | |
ConfigurableTrait:: |
protected | property | The initial configuration. | |
ConfigurableTrait:: |
public | function | Get a specific value from the configuration. | |
ConfigurableTrait:: |
public | function | Get the configuration object for this item. | |
ConfigurableTrait:: |
public | function | Get any validation errors in the config. | |
ConfigurableTrait:: |
public | function | Set the configuration for all plugins. | 1 |
ConfigurableTrait:: |
public | function | 2 | |
FileProcessorTrait:: |
protected | property | ||
FileProcessorTrait:: |
public | function | Provide the file mime for the given file extension if known. | |
FileProcessorTrait:: |
public | function | Get the temp file manager. | |
FileProcessorTrait:: |
public | function | Inject the temp file manager. | |
MetadataWriter:: |
public | function | Run after a backup. Add metadata to the file. | |
MetadataWriter:: |
public | function |
Get the default values for the plugin. Overrides ConfigurableTrait:: |
|
MetadataWriter:: |
public | function |
Get a default (blank) schema. Overrides ConfigurableTrait:: |
|
MetadataWriter:: |
protected | function | Generate a list of metadata keys to be stored with the backup. | |
MetadataWriter:: |
public | function | Run before the backup/restore begins. | |
PluginBase:: |
public | function |
What is the weight of the given operation for this plugin. Overrides PluginInterface:: |
|
PluginBase:: |
public | function |
Get a list of supported operations and their weight. Overrides PluginInterface:: |
8 |
PluginBase:: |
public | function |
Does this plugin implement the given operation. Overrides PluginInterface:: |
|
PluginCallerTrait:: |
protected | property | ||
PluginCallerTrait:: |
public | function | Get the plugin manager. | |
PluginCallerTrait:: |
public | function | Inject the plugin manager. | |
TranslatableTrait:: |
protected | property | ||
TranslatableTrait:: |
public | function | ||
TranslatableTrait:: |
public | function | Translate the given string if there is a translator service available. |