/** * Executes the current command. * * @param \Yosymfony\Spress\Core\IO\IOInterface $io Input/output interface. * @param array $arguments Arguments passed to the command. * @param array $options Options passed to the command. * * @return null|int null or 0 if everything went fine, or an error code. */ public function executeCommand(IOInterface $io, array $arguments, array $options) { $style = new SpressImportConsoleStyle($io); $file = $arguments['file']; $srcPath = __DIR__ . '/../../../../'; $style->title('Importing from a Wordpress WXR file'); $providerCollection = new ProviderCollection(['wxr' => new WxrProvider()]); $assetsDir = $options['assets-dir']; $providerManager = new ProviderManager($providerCollection, $srcPath, $assetsDir); if ($options['dry-run'] == true) { $providerManager->enableDryRun(); $io->write('<info>Dry-run enabled</info>'); } if ($options['fetch-images'] == true) { $providerManager->enableFetchResources(); } if ($options['not-replace-urls'] == true) { $providerManager->doNotReplaceUrls(); } if (is_null($options['post-layout']) == false) { $providerManager->setPostLayout($options['post-layout']); } $io->write('<info>Starting...</info>'); try { $itemResults = $providerManager->import('wxr', ['file' => $file]); $style->ResultItems($itemResults); } catch (Exception $e) { $style->error($e->getMessage()); } }
/** * Executes the current command. * * @param \Yosymfony\Spress\Core\IO\IOInterface $io Input/output interface. * @param array $arguments Arguments passed to the command. * @param array $options Options passed to the command. * * @return null|int null or 0 if everything went fine, or an error code. */ public function executeCommand(IOInterface $io, array $arguments, array $options) { $header = false; $style = new SpressImportConsoleStyle($io); $file = $arguments['file']; $srcPath = __DIR__ . '/../../../../'; $style->title('Importing from a CSV file'); $providerCollection = new ProviderCollection(['csv' => new CsvProvider()]); $providerManager = new ProviderManager($providerCollection, $srcPath); if ($options['dry-run'] == true) { $providerManager->enableDryRun(); $io->write('<info>Dry-run enabled</info>'); } if ($options['not-header'] == true) { $header = true; $io->write('<info>CSV file without header</info>'); } if ($options['not-replace-urls'] == true) { $providerManager->doNotReplaceUrls(); } if (is_null($options['post-layout']) == false) { $providerManager->setPostLayout($options['post-layout']); } $io->write('<info>Starting...</info>'); try { $itemResults = $providerManager->import('csv', ['file' => $file, 'not_header' => $header, 'delimiter_character' => $options['delimiter-character'], 'enclosure_character' => $options['enclosure-character'], 'terms_delimiter_character' => $options['terms-delimiter-character']]); $style->ResultItems($itemResults); } catch (Exception $e) { $style->error($e->getMessage()); } }
/** * Reparse a site. * * @param \Yosymfony\Spress\Core\IO\IOInterface $io * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Yosymfony\ResourceWatcher\ResourceWatcher $rw */ protected function reParse(IOInterface $io, InputInterface $input, ResourceWatcher $rw) { $rw->findChanges(); if ($rw->hasChanges() === false) { return; } $io->write(sprintf('<comment>Rebuilding site... (%s new, %s updated and %s deleted resources)</comment>', count($rw->getNewResources()), count($rw->getUpdatedResources()), count($rw->getDeletedResources()))); $spress = $this->buildSpress($io, $input); $spress->parse(); $io->write('<success>Site ready.</success>'); }
/** * Buils a Spress instance. * * @param \Yosymfony\Spress\Core\IO\IOInterface $io * @param \Symfony\Component\Console\Input\InputInterface $input * * @return \Yosymfony\Spress\Core\Spress */ protected function buildSpress(IOInterface $io, InputInterface $input) { $timezone = $input->getOption('timezone'); $drafts = $input->getOption('drafts'); $safe = $input->getOption('safe'); $env = $input->getOption('env'); $sourceDir = $input->getOption('source'); $spress = $this->getApplication()->getSpress(); if (is_null($sourceDir) === false) { if (($realDir = realpath($sourceDir)) === false) { throw new \RuntimeException(sprintf('Invalid source path: "%s".', $sourceDir)); } $spress['spress.config.site_dir'] = $realDir; } $spress['spress.config.env'] = $env; $spress['spress.config.safe'] = $safe; $spress['spress.config.drafts'] = $drafts; $spress['spress.config.timezone'] = $timezone; $resolver = $this->getConfigResolver(); $resolver->resolve($spress['spress.config.values']); if ($spress['spress.config.values']['parsedown_activated'] === true) { $this->enableParsedown($spress); $io->labelValue('Parsedown converter', 'enabled'); } $spress['spress.io'] = $io; return $spress; }