class ExportContentCommand in Tome 8
Contains the tome:export-content command.
@internal
Hierarchy
- class \Drupal\tome_base\CommandBase extends \Symfony\Component\Console\Command\Command uses ExecutableFinderTrait, ProcessTrait
- class \Drupal\tome_sync\Commands\ExportCommand
- class \Drupal\tome_sync\Commands\ExportContentCommand
- class \Drupal\tome_sync\Commands\ExportCommand
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
File
- modules/
tome_sync/ src/ Commands/ ExportContentCommand.php, line 15
Namespace
Drupal\tome_sync\CommandsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CommandBase:: |
protected | property | The current executable path. | |
CommandBase:: |
protected | property | The IO decorator. | |
CommandBase:: |
protected | function | ||
CommandBase:: |
protected | function |
Returns the IO decorator, for reporting errors. Overrides ProcessTrait:: |
|
ExecutableFinderTrait:: |
protected | function | Finds an executable string for the current process. | |
ExportCommand:: |
protected | property | The entity type manager. | |
ExportCommand:: |
protected | property | The event dispatcher. | |
ExportCommand:: |
protected | property | The exporter. | |
ExportCommand:: |
constant | The default number of entities to import in each process. | ||
ExportCommand:: |
constant | The default number of processes to invoke. | ||
ExportCommand:: |
public | function | Constructs an ExportCommand instance. | |
ExportContentCommand:: |
protected | function |
Overrides ExportCommand:: |
|
ExportContentCommand:: |
public | function |
Overrides ExportCommand:: |
|
ProcessTrait:: |
protected | function | Displays errors using the IO component. | |
ProcessTrait:: |
protected | function | Runs a single command and outputs errors if encountered. | |
ProcessTrait:: |
protected | function | Runs commands with concurrency. |