You are here

function backup_migrate_backup_migrate_service_object_alter in Backup and Migrate 5.0.x

Same name and namespace in other branches
  1. 8.4 backup_migrate.module \backup_migrate_backup_migrate_service_object_alter()

Implements hook_backup_migrate_service_object_alter().

File

./backup_migrate.module, line 110
Primary hook implementations for Backup Migrate.

Code

function backup_migrate_backup_migrate_service_object_alter(BackupMigrateInterface &$bam, $options = []) {

  // Add the core Backup and Migrate plugins to the service object.
  $sources = $bam
    ->sources();
  $destinations = $bam
    ->destinations();
  $plugins = $bam
    ->plugins();
  $services = $bam
    ->services();

  // Add a temp file manager which can access the drupal temp directory.
  $services
    ->add('TempFileAdapter', new DrupalTempFileAdapter(\Drupal::service('file_system'), 'temporary://', 'bam'));
  $services
    ->add('TempFileManager', new TempFileManager($services
    ->get('TempFileAdapter')));

  // Add a logger which prints everything to the browser.
  $services
    ->add('Logger', new DrupalSetMessageLogger());
  $services
    ->add('ArchiveReader', new TarArchiveReader());
  $services
    ->add('ArchiveWriter', new TarArchiveWriter());

  // If this is a nobrowser op (cron) then do not add the browser plugins.
  // @todo Make this better.
  if (empty($options['nobrowser'])) {

    // Add a download destination.
    $user = \Drupal::currentUser();
    if ($user
      ->hasPermission('access backup files')) {
      $destinations
        ->add('download', new DrupalBrowserDownloadDestination(new Config([
        'name' => t('Download'),
      ])));
    }

    // Add an upload destination.
    $destinations
      ->add('upload', new DrupalBrowserUploadDestination(new Config([
      'name' => t('Upload'),
    ])));
  }

  // Add a file naming filter.
  $plugins
    ->add('namer', new FileNamer());

  // Add a compression filter.
  $plugins
    ->add('compressor', new CompressionFilter());

  // Add the Encrypt utilities filter.
  $plugins
    ->add('encrypt', new DrupalEncrypt());

  // Add the Drupal utilities filter.
  $plugins
    ->add('utils', new DrupalUtils());

  // Add a file metadata filter.
  $plugins
    ->add('metadata', new MetadataWriter(new Config([
    'generator' => 'Backup and Migrate for Drupal (https://www.drupal.org/project/backup_migrate)',
    'generatorurl' => 'https://www.drupal.org/project/backup_migrate',
    'generatorversion' => backup_migrate_module_version(),
  ])));

  // Add the custom configured sources.
  foreach (Source::loadMultiple() as $source) {
    $source
      ->getPlugin()
      ->alterBackupMigrate($bam, $source
      ->get('id'), $options);
  }

  // Add the custom configured destination.
  foreach (Destination::loadMultiple() as $destination) {
    $destination
      ->getPlugin()
      ->alterBackupMigrate($bam, $destination
      ->get('id'), $options);
  }
}