Skip to content

Commit

Permalink
Merge pull request #16 from tajveez-73/patch-1
Browse files Browse the repository at this point in the history
Cron fails if directory doesn't Exists
  • Loading branch information
Tjitse-E authored Jun 9, 2021
2 parents c332cae + d11c5cd commit d743894
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Cron/GenerateSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Vendic\VueStorefrontSitemap\Model\Configuration;
use Vendic\VueStorefrontSitemap\Model\ProductCollection;
use Vendic\VueStorefrontSitemap\Model\SitemapFactory;
use Magento\Framework\Filesystem\Driver\File;

class GenerateSitemap
{
Expand Down Expand Up @@ -45,19 +46,25 @@ class GenerateSitemap
* @var CategoryCollection
*/
protected $categoryCollection;
/**
* @var File
*/
protected $fileDriver;

public function __construct(
CategoryCollection $categoryCollection,
Configuration $configuration,
ProductCollection $productCollection,
DirectoryList $directoryList,
SitemapFactory $sitemapFactory
SitemapFactory $sitemapFactory,
File $fileDriver
) {
$this->directoryList = $directoryList;
$this->sitemapFactory = $sitemapFactory;
$this->productCollection = $productCollection;
$this->configuration = $configuration;
$this->categoryCollection = $categoryCollection;
$this->fileDriver = $fileDriver;
}

public function execute() : void
Expand All @@ -66,6 +73,9 @@ public function execute() : void
$domain = $this->configuration->getVueStorefrontUrl();
$path = $this->getPubPath();

// Create directory at Path if doesn't exists
if (!$this->fileDriver->isDirectory($path)) $this->fileDriver->createDirectory($path, 0775);

// Sitemap configuration
$this->sitemap = $this->sitemapFactory->create($domain);
$this->sitemap->setPath($path);
Expand Down

0 comments on commit d743894

Please sign in to comment.