You are here

public function SubscriberAudit::generateManifest in Acquia Content Hub 8

Generate Manifest file.

Parameters

string $file_path: The path to Manifest file.

array $entity_type_ids: An array of entity type ids we want to search and delete.

File

acquia_contenthub_audit/src/SubscriberAudit.php, line 210

Class

SubscriberAudit
Audits Subscribers.

Namespace

Drupal\acquia_contenthub_audit

Code

public function generateManifest(string $file_path, array $entity_type_ids = []) {
  $entities = $this
    ->findEntitiesToImport();
  $origin = $this->configFactory
    ->get('acquia_contenthub.admin_settings')
    ->get('origin');
  if (file_exists($file_path)) {
    $manifest = (include $file_path);
  }
  else {
    $manifest = [];
  }
  if ($entities) {
    foreach ($entities as $uuid => $entity) {
      if ($origin != $entity['entity']
        ->getOrigin()) {
        $manifest[$origin]['import'][$entity['entity']
          ->getOrigin()][$uuid] = [
          'type' => $entity['entity']
            ->getType(),
          'filter' => $entity['filter'],
        ];
      }
    }
  }
  $entities = $this
    ->findEntitiesToDelete($entity_type_ids);
  foreach ($entities['delete'] as $uuid => $entity) {
    $local_entity = $this->entityRepository
      ->loadEntityByUuid($entity->entity_type, $uuid);
    if ($local_entity) {
      $manifest[$origin]['delete'][$entity->entity_type][$uuid] = [
        'id' => $local_entity
          ->id(),
        'label' => $local_entity
          ->label(),
        'url' => $local_entity
          ->toUrl('canonical', [
          'absolute' => TRUE,
        ]),
      ];
    }
    else {
      $manifest[$origin]['delete_tracking'][$entity->entity_type][$uuid] = [
        'type' => $entity->entity_type,
        'id' => $entity->entity_id,
      ];
    }
  }
  foreach ($entities['missing'] as $uuid => $item) {
    $manifest[$origin]['missing'][$item->origin][$item->entity_type][$item->entity_uuid] = [
      'type' => $item->entity_type,
      'id' => $item->entity_id,
    ];
  }
  if (file_put_contents($file_path, "<?php\n\nreturn " . var_export($manifest, TRUE) . ";")) {
    print sprintf("The manifest file was successfully written to %s.\n", $file_path);
  }
}