/** * Clear sitemap * * @param \Magento\Sitemap\Model\Sitemap $model * @return void */ protected function clearSiteMap(\Magento\Sitemap\Model\Sitemap $model) { /** @var \Magento\Framework\Filesystem\Directory\Write $directory */ $directory = $this->_objectManager->get('Magento\\Framework\\Filesystem')->getDirectoryWrite(DirectoryList::ROOT); if ($this->getRequest()->getParam('sitemap_id')) { $model->load($this->getRequest()->getParam('sitemap_id')); $fileName = $model->getSitemapFilename(); $path = $model->getSitemapPath() . '/' . $fileName; if ($fileName && $directory->isFile($path)) { $directory->delete($path); } } }