You are here

function processContentExportFiles in Content Synchronization 8

Processes the content archive export batch

Parameters

$files: The batch content to persist.

array $context: The batch context.

1 string reference to 'processContentExportFiles'
ContentExportForm::submitForm in src/Form/ContentExportForm.php
Form submission handler.

File

./content_sync.batch.inc, line 475

Code

function processContentExportFiles($files, &$context) {

  //Initialize ArchiverTar
  $archiver = new ArchiveTar(file_directory_temp() . '/content.tar.gz', 'gz');

  //Initialize Batch
  if (empty($context['sandbox'])) {
    $context['sandbox']['progress'] = 0;
    $context['sandbox']['current_number'] = 0;
    $context['sandbox']['max'] = count($files);
  }

  // Get submitted values
  $entity_type = $files[$context['sandbox']['progress']]['entity_type'];
  $entity_bundle = $files[$context['sandbox']['progress']]['entity_bundle'];
  $entity_id = $files[$context['sandbox']['progress']]['entity_id'];

  //Validate that it is a Content Entity
  $entityTypeManager = \Drupal::entityTypeManager();
  $instances = $entityTypeManager
    ->getDefinitions();
  if (!(isset($instances[$entity_type]) && $instances[$entity_type] instanceof ContentEntityType)) {
    $context['results']['errors'][] = t('Entity type does not exist or it is not a content instance.') . $entity_type;
  }
  else {

    // Generate the YAML file.
    $entity = _content_sync_db_to_entity($entity_type, $entity_bundle, $entity_id);

    // Create the name
    $name = $entity_type . "." . $entity_bundle . "." . $entity['values'][0]['uuid'][0]['value'];

    // Create the file.
    $archiver
      ->addString("{$name}.yml", Yaml::encode($entity));
    $context['message'] = $name;
    $context['results'][] = $name;
  }
  $context['sandbox']['progress']++;
  if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
    $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
  }
}