/**
  * 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());
     }
 }
예제 #2
0
    public function testReplaceResourceUrl()
    {
        $providerCollection = new ProviderCollection(['array' => new ArrayProvider([['type' => 'resource', 'permalink' => 'https://spressimport.files.wordpress.com/2016/06/14004361452_b952deddeb_o.jpg'], ['type' => 'page', 'permalink' => 'http://mysite.com/about', 'content' => '<img src="https://spressimport.files.wordpress.com/2016/06/14004361452_b952deddeb_o.jpg" />']])]);
        $assetsPath = '/img';
        $providerManager = new ProviderManager($providerCollection, $this->srcPath, $assetsPath);
        $providerManager->enableFetchResources();
        $itemResults = $providerManager->import('array', []);
        $this->assertCount(2, $itemResults);
        $content = <<<EOC
---
permalink: /about
no_html_extension: true

---
<img src="/img/2016/06/14004361452_b952deddeb_o.jpg" />
EOC;
        $this->assertEquals($content, $itemResults[1]->getContent());
    }