21 private $sitemapFactory;
33 parent::__construct($context);
34 $this->sitemapFactory = $sitemapFactory ?: ObjectManager::getInstance()
45 $directory = $this->getFilesystem()->getDirectoryWrite(DirectoryList::ROOT);
52 $sitemap = $this->sitemapFactory->create();
55 $sitemapPath = $sitemap->getSitemapPath();
56 if ($sitemapPath && $sitemapPath[0] === DIRECTORY_SEPARATOR) {
57 $sitemapPath = mb_substr($sitemapPath, 1);
59 $sitemapFilename = $sitemap->getSitemapFilename();
60 $path = $directory->getRelativePath(
61 $sitemapPath .$sitemapFilename
63 if ($sitemap->getSitemapFilename() && $directory->isFile(
$path)) {
64 $directory->delete(
$path);
68 $this->messageManager->addSuccessMessage(
__(
'You deleted the sitemap.'));
72 }
catch (\Exception $e) {
74 $this->messageManager->addErrorMessage($e->getMessage());
76 $this->
_redirect(
'adminhtml/*/edit', [
'sitemap_id' =>
$id]);
81 $this->messageManager->addErrorMessage(
__(
'We can\'t find a sitemap to delete.'));
92 private function getFilesystem()
94 if (
null === $this->filesystem) {
96 \
Magento\Framework\Filesystem::class
99 return $this->filesystem;
_redirect($path, $arguments=[])
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Sitemap\Model\SitemapFactory $sitemapFactory=null)