/** * @param InputInterface $input * @param OutputInterface $output * @return null|int */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->writeSection('Start Import'); // Check if there is a reader for the given file extension $format = $this->getFormat(); if (!array_key_exists($format, $this->readers)) { throw new \InvalidArgumentException('Format "' . $format . '" is currently not supported."'); } /** @var \Semaio\ConfigImportExport\Model\File\Reader\ReaderInterface $reader */ $reader = $this->getObjectManager()->create($this->readers[$format]); if (!$reader || !is_object($reader)) { throw new \InvalidArgumentException(ucfirst($format) . ' file reader could not be instantiated."'); } // Retrieve the arguments $folder = $input->getArgument('folder'); $baseFolder = $input->getOption('base'); $environment = $input->getArgument('environment'); // Configure the finder $finder = $this->finder; $finder->setFolder($folder); $finder->setBaseFolder($baseFolder); $finder->setEnvironment($environment); $finder->setFormat($format); // Process the import $this->importProcessor->setFormat($format); $this->importProcessor->setReader($reader); $this->importProcessor->setFinder($finder); $this->importProcessor->setOutput($output); $this->importProcessor->process(); // Clear the cache after import $this->getCacheManager()->clean(['config', 'full_page']); }
/** * @param InputInterface $input * @param OutputInterface $output * @return null|int */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $this->writeSection('Start Export'); $format = $this->getFormat(); if (!array_key_exists($format, $this->writers)) { throw new \InvalidArgumentException('Format "' . $format . '" is currently not supported."'); } /** @var \Semaio\ConfigImportExport\Model\File\Writer\WriterInterface $writer */ $writer = $this->getObjectManager()->create($this->writers[$format]); if (!$writer || !is_object($writer)) { throw new \InvalidArgumentException(ucfirst($format) . ' file writer could not be instantiated."'); } $filename = (string) $input->getOption('filename'); if ($filename != '') { $writer->setBaseFilename($filename); } $writer->setOutput($output); $writer->setIsHierarchical('y' === $input->getOption('hierarchical')); $writer->setIsFilePerNameSpace('y' === $input->getOption('filePerNameSpace')); $include = $input->getOption('include'); if (!empty($include) && is_string($include) === true) { $this->exportProcessor->setInclude($include); } $includeScope = $input->getOption('includeScope'); if (!empty($includeScope) && is_string($includeScope) === true) { $this->exportProcessor->setIncludeScope($includeScope); } $exclude = $input->getOption('exclude'); if (!empty($exclude) && is_string($exclude) === true) { $this->exportProcessor->setExclude($exclude); } $this->exportProcessor->setWriter($writer); $this->exportProcessor->setOutput($output); $this->exportProcessor->process(); }