You are here

public function ContentExportTrait::generateSiteUUIDFile in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Form/ContentExportTrait.php \Drupal\content_sync\Form\ContentExportTrait::generateSiteUUIDFile()

Generate UUID YAML file To use for site UUID validation.

Parameters

$data: The batch content to persist.

array $context: The batch context.

File

src/Form/ContentExportTrait.php, line 212

Class

ContentExportTrait
Defines the content export form.

Namespace

Drupal\content_sync\Form

Code

public function generateSiteUUIDFile($serializer_context, &$context) {

  //Include Site UUID to YML file
  $site_config = \Drupal::config('system.site');
  $site_uuid_source = $site_config
    ->get('uuid');
  $entity['site_uuid'] = $site_uuid_source;

  // Set the name
  $name = "site.uuid";
  if (isset($serializer_context['export_type'])) {
    if ($serializer_context['export_type'] == 'snapshot') {

      //Save to cs_db_snapshot table.
      $activeStorage = new ContentDatabaseStorage(\Drupal::database(), 'cs_db_snapshot');
      $activeStorage
        ->write($name, $entity);
    }
    elseif ($serializer_context['export_type'] == 'tar') {

      // Add YAML to the archiver
      $this
        ->getArchiver()
        ->addString("entities/{$name}.yml", Yaml::encode($entity));
    }
    elseif ($serializer_context['export_type'] == 'folder') {
      $path = $serializer_context['content_sync_directory_entities'];
      $destination = $path . "/{$name}.yml";
      \Drupal::service('file_system')
        ->prepareDirectory($path, FileSystemInterface::CREATE_DIRECTORY);
      $file = \Drupal::service('file_system')
        ->saveData(Yaml::encode($entity), $destination, FileSystemInterface::EXISTS_REPLACE);
    }
  }
  $context['message'] = $name;
  $context['results'][] = $name;
  $context['finished'] = 1;
}