You are here

class ExportContentCommand in Tome 8

Contains the tome:export-content command.

@internal

Hierarchy

Expanded class hierarchy of ExportContentCommand

1 string reference to 'ExportContentCommand'
tome_sync.services.yml in modules/tome_sync/tome_sync.services.yml
modules/tome_sync/tome_sync.services.yml
1 service uses ExportContentCommand
tome_sync.export_content_command in modules/tome_sync/tome_sync.services.yml
Drupal\tome_sync\Commands\ExportContentCommand

File

modules/tome_sync/src/Commands/ExportContentCommand.php, line 15

Namespace

Drupal\tome_sync\Commands
View source
class ExportContentCommand extends ExportCommand {

  /**
   * {@inheritdoc}
   */
  protected function configure() {
    $this
      ->setName('tome:export-content')
      ->setDescription('Exports given content.')
      ->addArgument('chunk', InputArgument::REQUIRED, 'A comma separated list of ID pairs in the format entity_type_id:id.');
  }

  /**
   * {@inheritdoc}
   */
  public function execute(InputInterface $input, OutputInterface $output) {
    $chunk = $input
      ->getArgument('chunk');
    $id_pairs = explode(',', $chunk);
    $storages = [];
    foreach ($id_pairs as $id_pair) {
      list($entity_type_id, $id) = explode(':', $id_pair);
      $entity_type = $this->entityTypeManager
        ->getDefinition($entity_type_id);
      if (!$entity_type) {
        $this
          ->io()
          ->error("The entity type {$entity_type_id} does not exist.");
        return 1;
      }
      if (!isset($storages[$entity_type_id])) {
        $storages[$entity_type_id] = $this->entityTypeManager
          ->getStorage($entity_type_id);
      }
      $entity = $storages[$entity_type_id]
        ->load($id);
      if (!$entity) {
        $this
          ->io()
          ->error("No entity found for {$id_pair}.");
        return 1;
      }
      if (!$entity instanceof ContentEntityInterface) {
        $this
          ->io()
          ->error("{$id_pair} is not a content entity.");
        return 1;
      }
      foreach ($entity
        ->getTranslationLanguages() as $language) {
        $this->exporter
          ->exportContent($entity
          ->getTranslation($language
          ->getId()));
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandBase::$executable protected property The current executable path.
CommandBase::$io protected property The IO decorator.
CommandBase::initialize protected function
CommandBase::io protected function Returns the IO decorator, for reporting errors. Overrides ProcessTrait::io
ExecutableFinderTrait::findExecutable protected function Finds an executable string for the current process.
ExportCommand::$entityTypeManager protected property The entity type manager.
ExportCommand::$eventDispatcher protected property The event dispatcher.
ExportCommand::$exporter protected property The exporter.
ExportCommand::ENTITY_COUNT constant The default number of entities to import in each process.
ExportCommand::PROCESS_COUNT constant The default number of processes to invoke.
ExportCommand::__construct public function Constructs an ExportCommand instance.
ExportContentCommand::configure protected function Overrides ExportCommand::configure
ExportContentCommand::execute public function Overrides ExportCommand::execute
ProcessTrait::displayErrors protected function Displays errors using the IO component.
ProcessTrait::runCommand protected function Runs a single command and outputs errors if encountered.
ProcessTrait::runCommands protected function Runs commands with concurrency.