SitemapCommandController.php 1.08 KB
Newer Older
Dominique Feyer's avatar
Dominique Feyer committed
1 2 3
<?php
namespace Ttree\Neos\Sitemap\Command;

4
use Ttree\Neos\Sitemap\Domain\Model\SitemapDefinition;
5
use Ttree\Neos\Sitemap\Service\SitemapBuilderInterface;
Dominique Feyer's avatar
Dominique Feyer committed
6 7 8 9 10 11 12 13
use TYPO3\Flow\Annotations as Flow;
use TYPO3\Flow\Cli\CommandController;
use TYPO3\Flow\Utility\Files;

class SitemapCommandController extends CommandController {

    /**
     * @Flow\Inject
14
     * @var SitemapBuilderInterface
Dominique Feyer's avatar
Dominique Feyer committed
15
     */
16
    protected $sitemapBuilder;
Dominique Feyer's avatar
Dominique Feyer committed
17 18 19 20 21

    /**
     * @param string $siteNodeName
     * @param string $baseUrl
     * @param string $preset
22
     * @param boolean $async
Dominique Feyer's avatar
Dominique Feyer committed
23
     */
24
    public function generateCommand($siteNodeName, $baseUrl, $preset = 'default', $async = FALSE) {
25
        $definition = new SitemapDefinition($siteNodeName, $baseUrl, $preset);
26 27 28 29
        if ($async === TRUE) {
            $definition->queue();
        } else {
            $sitemap = $this->sitemapBuilder->build($definition);
Dominique Feyer's avatar
Dominique Feyer committed
30

31 32 33 34
            $pathAndFilename = $definition->getPath();
            Files::createDirectoryRecursively(dirname($pathAndFilename));
            file_put_contents($pathAndFilename, (string)$sitemap);
        }
Dominique Feyer's avatar
Dominique Feyer committed
35 36 37
    }

}