protected function ExportDrupalCommand::execute in Search API Synonym 8
File
- src/Command/ExportDrupalCommand.php, line 77
Class
- ExportDrupalCommand
- Drupal Console Command for export synonyms.
Namespace
Drupal\search_api_synonym\Command
Code
protected function execute(InputInterface $input, OutputInterface $output) {
$pluginManager = \Drupal::service('plugin.manager.search_api_synonym.export');
$plugin = $input
->getOption('plugin');
$langcode = $input
->getOption('langcode');
$type = $input
->getOption('type');
$filter = $input
->getOption('filter');
$file = $input
->getOption('file');
$incremental = $input
->getOption('incremental');
$io = new DrupalStyle($input, $output);
if (!$pluginManager
->validatePlugin($plugin)) {
$error = TRUE;
$io
->info($this
->trans('commands.searchapi.synonym.export.messages.invalidplugin'));
}
if (empty($langcode)) {
$error = TRUE;
$io
->info($this
->trans('commands.searchapi.synonym.export.messages.invalidlangcode'));
}
if (!empty($type) && !$this
->validateOptionType($type)) {
$error = TRUE;
$io
->info($this
->trans('commands.searchapi.synonym.export.messages.invalidtype'));
}
if (!empty($filter) && !$this
->validateOptionFilter($filter)) {
$error = TRUE;
$io
->info($this
->trans('commands.searchapi.synonym.export.messages.invalidfilter'));
}
if (!isset($error)) {
$io
->info($this
->trans('commands.searchapi.synonym.export.messages.start'));
$options = [
'langcode' => $langcode,
'type' => $type,
'filter' => $filter,
'file' => $file,
'incremental' => (int) $incremental,
];
$pluginManager
->setPluginId($plugin);
$pluginManager
->setExportOptions($options);
if ($result = $pluginManager
->executeExport()) {
$io
->info($this
->trans('commands.searchapi.synonym.export.messages.success'));
$io
->info($result);
}
}
}