![]() 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/amasty/feed/Controller/Adminhtml/GoogleWizard/ |
<?php /** * @author Amasty Team * @copyright Copyright (c) Amasty (https://www.amasty.com) * @package Product Feed for Magento 2 */ namespace Amasty\Feed\Controller\Adminhtml\GoogleWizard; use Amasty\Feed\Model\RegistryContainer; use Magento\Framework\App\ObjectManager; use Magento\Framework\Serialize\Serializer\Json; class Save extends \Amasty\Feed\Controller\Adminhtml\AbstractGoogleWizard { /** * @var \Amasty\Feed\Model\GoogleWizard */ private $googleWizard; /** * @var array */ private $configSetup = []; /** * @var \Magento\Framework\Encryption\EncryptorInterface */ private $encryptor; /** * @var Json|null */ private $serializer; public function __construct( \Magento\Backend\App\Action\Context $context, \Amasty\Feed\Model\GoogleWizard $googleWizard, \Magento\Framework\Encryption\EncryptorInterface $encryptor, Json $serializer = null // TODO move to not optional ) { parent::__construct($context); $this->googleWizard = $googleWizard; $this->encryptor = $encryptor; // OM for backward compatibility $this->serializer = $serializer ?? ObjectManager::getInstance()->get(Json::class); } public function execute() { if ($this->getRequest()->getPostValue()) { $data = $this->preparePostData(); $args = []; try { $this->configSetup = $this->googleWizard->setup($data); $categoryMapperId = RegistryContainer::VAR_CATEGORY_MAPPER; $args[$categoryMapperId] = $this->getConfigValue($categoryMapperId); $feedId = RegistryContainer::VAR_FEED; $args[$feedId] = $this->getConfigValue($feedId); if ($this->getRequest()->getParam('setup_complete')) { $this->googleWizard->clearSessionData(); $feedId = $args[RegistryContainer::VAR_FEED]; $arguments = [ 'id' => $feedId ]; if ($this->getRequest()->getParam('force_generate')) { $arguments['_fragment'] = 'forcegenerate'; return $this->resultRedirectFactory->create()->setPath('amfeed/feed/edit', $arguments); } return $this->resultRedirectFactory->create()->setPath('amfeed/feed/index'); } return $this->resultRedirectFactory->create()->setPath('amfeed/feed/index', $args); } catch (\Exception $exception) { $this->messageManager->addExceptionMessage( $exception, __('Something went wrong while saving the Google Feed. Please review the error log.') ); return $this->resultRedirectFactory->create()->setPath('amfeed/googleWizard/index'); } } return $this->resultRedirectFactory->create()->setPath('amfeed/feed/index'); } /** * Get prepared POST * * @return array */ private function preparePostData(): array { $data = []; if ($this->getRequest()->getPostValue()) { $postData = $this->getRequest()->getPostValue(); $postDataKeys = array_keys($postData); $data = array_combine($postDataKeys, $postData); if (isset($data['delivery_password'])) { $data['delivery_password'] = $this->encryptor->encrypt($data['delivery_password']); } if (isset($data['mapping'])) { $data['mapping'] = $this->serializer->unserialize($data['mapping']); } } return $data; } private function getConfigValue($key) { $value = ''; if (isset($this->configSetup[$key])) { $value = $this->configSetup[$key]; } return $value; } }