You are here

function processContentSyncSnapshot in Content Synchronization 8

Processes the content snapshot batch - when the module is installed

Parameters

$files: The batch content to persist.

array $context: The batch context.

1 string reference to 'processContentSyncSnapshot'
content_sync_install in ./content_sync.install
Implements hook_install().

File

./content_sync.batch.inc, line 520

Code

function processContentSyncSnapshot($files, &$context) {

  //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 {

    // Store the data for diff
    $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'];

    // Insert Data
    $activeStorage = new Drupal\Core\Config\DatabaseStorage(\Drupal::database(), 'cs_db_snapshot');
    $activeStorage
      ->write($name, $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'];
  }
}