You are here

public function AcquiaContentHubCDFCommands::importCdf in Acquia Content Hub 8.2

Imports entities from a CDF Document.

@command acquia:contenthub-import-local-cdf @aliases ach-ilc

Parameters

string $location: The location of the cdf file.

Throws

\Exception

File

src/Commands/AcquiaContentHubCDFCommands.php, line 75

Class

AcquiaContentHubCDFCommands
Class AcquiaContentHubCommands.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function importCdf($location) : void {
  if (!file_exists($location)) {
    throw new \Exception("The cdf to import was not found in the specified location.");
  }
  $json = file_get_contents($location);
  $data = Json::decode($json);
  $document_parts = [];
  foreach ($data['entities'] as $entity) {
    $document_parts[] = CDFObject::fromArray($entity);
  }
  $cdf_document = new CDFDocument(...$document_parts);

  /** @var \Drupal\acquia_contenthub\ContentHubCommonActions $common */
  $common = \Drupal::service('acquia_contenthub_common_actions');
  $stack = $common
    ->importEntityCdfDocument($cdf_document);
  $this->output
    ->writeln(dt("Imported @items from @location.", [
    '@items' => count($stack
      ->getDependencies()),
    '@location' => $location,
  ]));
}