コード例 #1
0
ファイル: Form.php プロジェクト: Doability/magento2dev
 /**
  * List of files
  *
  * @return array
  */
 protected function getFiles()
 {
     $options = [];
     $path = $this->config->getStopwordDirectoryPath();
     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;
 }
コード例 #2
0
ファイル: Stopword.php プロジェクト: Doability/magento2dev
 /**
  * @return array
  */
 public function getAvailableFiles()
 {
     $files = [];
     $path = $this->config->getStopwordDirectoryPath();
     if (file_exists($path)) {
         $dh = opendir($path);
         while (false !== ($filename = readdir($dh))) {
             if (substr($filename, 0, 1) != '.') {
                 $files[] = $path . DIRECTORY_SEPARATOR . $filename;
             }
         }
     }
     return $files;
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($input->getOption('remove')) {
         $store = $input->getOption('store');
         $collection = $this->stopwordFactory->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} stopwords are removed...</info>");
             }
         }
         $output->writeln("<info>{$cnt} stopwords are removed.</info>");
         return;
     }
     if ($input->getOption('file') && $input->getOption('store')) {
         $file = $this->config->getStopwordDirectoryPath() . DIRECTORY_SEPARATOR . $input->getOption('file');
         $store = $input->getOption('store');
         $result = $this->stopwordFactory->create()->import($file, $store);
         $output->writeln("<info>Imported {$result['stopwords']} stopwords</info>");
     } else {
         $output->writeln('<info>Available files:</info>');
         foreach ($this->stopwordFactory->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()}]");
         }
     }
 }