/** * Synonym files * * @return array */ protected function getFiles() { $options = []; $path = $this->config->getSynonymDirectoryPath(); if (file_exists($path)) { $dh = opendir($path); while (false !== ($filename = readdir($dh))) { if (substr($filename, 0, 1) != '.') { $info = pathinfo($filename); $options[$path . DIRECTORY_SEPARATOR . $filename] = $info['filename']; } } } return $options; }
/** * @return array */ public function getAvailableFiles() { $files = []; $path = $this->config->getSynonymDirectoryPath(); if (file_exists($path)) { $dh = opendir($path); while (false !== ($filename = readdir($dh))) { if (substr($filename, 0, 1) != '.') { $files[] = $path . DIRECTORY_SEPARATOR . $filename; } } } return $files; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { if ($input->getOption('remove')) { $store = $input->getOption('store'); $collection = $this->synonymFactory->create()->getCollection(); if ($store) { $collection->addFieldToFilter('store_id', $store); } $cnt = 0; foreach ($collection as $item) { $item->delete(); $cnt++; if ($cnt % 1000 == 0) { $output->writeln("<info>{$cnt} synonyms are removed...</info>"); } } $output->writeln("<info>{$cnt} synonyms are removed.</info>"); return; } if ($input->getOption('file') && $input->getOption('store')) { $file = $this->config->getSynonymDirectoryPath() . DIRECTORY_SEPARATOR . $input->getOption('file'); $store = $input->getOption('store'); $result = $this->synonymFactory->create()->import($file, $store); $output->writeln("<info>Imported {$result['synonyms']} synonyms</info>"); } else { $output->writeln('<info>Available files:</info>'); foreach ($this->synonymFactory->create()->getAvailableFiles() as $file) { $info = pathinfo($file); $output->writeln(" {$info['basename']}"); } $output->writeln('<info>Available stores:</info>'); foreach ($this->storeManager->getStores(true) as $store) { $output->writeln(" {$store->getId()} [{$store->getCode()}]"); } } }