![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-sitemap/Controller/Adminhtml/Sitemap/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; use Magento\Backend\App\Action; use Magento\Framework\App\Action\HttpGetActionInterface; use Magento\Framework\App\Area; use Magento\Sitemap\Controller\Adminhtml\Sitemap; use Magento\Store\Model\App\Emulation; /** * Generate sitemap file */ class Generate extends Sitemap implements HttpGetActionInterface { /** * @var Emulation */ private $appEmulation; /** * @param Action\Context $context * @param Emulation $appEmulation */ public function __construct( Action\Context $context, Emulation $appEmulation ) { parent::__construct($context); $this->appEmulation = $appEmulation; } /** * Generate sitemap * * @return void */ public function execute() { // init and load sitemap model $id = $this->getRequest()->getParam('sitemap_id'); $sitemap = $this->_objectManager->create(\Magento\Sitemap\Model\Sitemap::class); /* @var $sitemap \Magento\Sitemap\Model\Sitemap */ $sitemap->load($id); // if sitemap record exists if ($sitemap->getId()) { try { $this->appEmulation->startEnvironmentEmulation( $sitemap->getStoreId(), Area::AREA_FRONTEND, true ); $sitemap->generateXml(); $this->appEmulation->stopEnvironmentEmulation(); $this->messageManager->addSuccessMessage( __('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename()) ); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addExceptionMessage($e, __('We can\'t generate the sitemap right now.')); } } else { $this->messageManager->addErrorMessage(__('We can\'t find a sitemap to generate.')); } // go to grid $this->_redirect('adminhtml/*/'); } }