You are here

protected function ImportCommand::execute in Tome 8

3 methods override ImportCommand::execute()
DeleteContentCommand::execute in modules/tome_sync/src/Commands/DeleteContentCommand.php
ImportContentCommand::execute in modules/tome_sync/src/Commands/ImportContentCommand.php
ImportPartialCommand::execute in modules/tome_sync/src/Commands/ImportPartialCommand.php

File

modules/tome_sync/src/Commands/ImportCommand.php, line 89

Class

ImportCommand
Contains the tome:import command.

Namespace

Drupal\tome_sync\Commands

Code

protected function execute(InputInterface $input, OutputInterface $output) {
  $options = $input
    ->getOptions();
  if (!$options['yes'] && !$this
    ->io()
    ->confirm('Your local site\'s config, content, and files will be deleted and replaced.', FALSE)) {
    return 0;
  }
  if (!$this
    ->checkImportingState($options)) {
    return 0;
  }
  $this->state
    ->set(ImporterInterface::STATE_KEY_IMPORTING, TRUE);
  $delete_content = [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type) {
    if ($entity_type instanceof ContentEntityTypeInterface) {
      foreach ($this->entityTypeManager
        ->getStorage($entity_type
        ->id())
        ->getQuery()
        ->execute() as $id) {
        $delete_content[] = $entity_type
          ->id() . ':' . $id;
      }
    }
  }
  if (!$this
    ->deleteContent($delete_content, $options['entity-count'], $options['process-count'])) {
    return 1;
  }
  $this
    ->prepareConfigForImport();
  if (!$this
    ->runCommand($this->executable . " config:import -y", NULL, NULL)) {
    return 1;
  }
  $chunked_names = $this->importer
    ->getChunkedNames();
  if (!$this
    ->importChunks($chunked_names, $options['entity-count'], $options['process-count'])) {
    return 1;
  }
  $this->importer
    ->importFiles();
  if (!$this
    ->runCommand($this->executable . " cache:rebuild -y", NULL, NULL)) {
    return 1;
  }
  if (!$this
    ->runCommand($this->executable . " tome:import-complete")) {
    return 1;
  }
  $this->state
    ->set(ImporterInterface::STATE_KEY_IMPORTING, FALSE);
  $this
    ->io()
    ->success('Imported config, content, and files.');
}