Skip to content

Commit

Permalink
Update GenerateSitemap.php
Browse files Browse the repository at this point in the history
used the Magento methods to check if a directory exists/create a directory
  • Loading branch information
tajveez-73 authored Jun 9, 2021
1 parent b078680 commit 6c14f9a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Cron/GenerateSitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Vendic\VueStorefrontSitemap\Model\Configuration;
use Vendic\VueStorefrontSitemap\Model\ProductCollection;
use Vendic\VueStorefrontSitemap\Model\SitemapFactory;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Filesystem\Io\File as Io;

class GenerateSitemap
{
Expand Down Expand Up @@ -45,19 +47,32 @@ class GenerateSitemap
* @var CategoryCollection
*/
protected $categoryCollection;
/**
* @var File
*/
protected $fileDriver;
/**
* @var Io
*/
protected $io;

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

}

public function execute() : void
Expand All @@ -67,9 +82,7 @@ public function execute() : void
$path = $this->getPubPath();

// Create directory at Path if doesn't exists
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
if (!$this->fileDriver->isExists($path)) $this->io->mkdir($path, 0775);

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

0 comments on commit 6c14f9a

Please sign in to comment.