You are here

class MetadataWriter in Backup and Migrate 8.4

Class MetadataWriter.

@package BackupMigrate\Core\Filter

Add metadata such as a description to the backup file.

Hierarchy

Expanded class hierarchy of MetadataWriter

File

lib/backup_migrate_core/src/Filter/MetadataWriter.php, line 20

Namespace

BackupMigrate\Core\Filter
View source
class MetadataWriter extends PluginBase implements FileProcessorInterface, PluginCallerInterface {
  use FileProcessorTrait;
  use PluginCallerTrait;

  /**
   * {@inheritdoc}
   */
  public function configSchema($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 \BackupMigrate\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 \BackupMigrate\Core\File\BackupFileWritableInterface $file
   *
   * @return \BackupMigrate\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

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
FileProcessorTrait::$tempfilemanager protected property
FileProcessorTrait::alterMime public function Provide the file mime for the given file extension if known.
FileProcessorTrait::getTempFileManager public function Get the temp file manager.
FileProcessorTrait::setTempFileManager public function Inject the temp file manager.
MetadataWriter::afterBackup public function Run after a backup. Add metadata to the file.
MetadataWriter::configDefaults public function Get the default values for the plugin. Overrides ConfigurableTrait::configDefaults
MetadataWriter::configSchema public function Get a default (blank) schema. Overrides ConfigurableTrait::configSchema
MetadataWriter::getMetaKeys protected function Generate a list of metadata keys to be stored with the backup.
MetadataWriter::setUp public function Run before the backup/restore begins.
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
PluginCallerTrait::$plugins protected property
PluginCallerTrait::plugins public function Get the plugin manager.
PluginCallerTrait::setPluginManager public function Inject the plugin manager.
TranslatableTrait::$translator protected property
TranslatableTrait::setTranslator public function
TranslatableTrait::t public function Translate the given string if there is a translator service available.