![]() 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-search/Controller/Adminhtml/Term/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Search\Controller\Adminhtml\Term; use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface; use Magento\Backend\App\Action\Context; use Magento\Framework\Controller\ResultFactory; use Magento\Search\Model\QueryFactory; use Magento\Search\Controller\Adminhtml\Term as TermController; use Magento\Framework\Exception\LocalizedException; class Save extends TermController implements HttpPostActionInterface { /** * @var QueryFactory */ private $queryFactory; /** * @param Context $context * @param QueryFactory $queryFactory */ public function __construct( Context $context, QueryFactory $queryFactory ) { parent::__construct($context); $this->queryFactory = $queryFactory; } /** * Save search query * * @return \Magento\Backend\Model\View\Result\Redirect * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { $data = $this->getRequest()->getPostValue(); if ($this->getRequest()->isPost() && $data) { try { $model = $this->loadQuery(); $model->addData($data); $model->setIsProcessed(0); $model->save(); $this->messageManager->addSuccessMessage(__('You saved the search term.')); } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); return $this->proceedToEdit($data); } catch (\Exception $e) { $this->messageManager->addExceptionMessage( $e, __('Something went wrong while saving the search query.') ); return $this->proceedToEdit($data); } } /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $redirectResult->setPath('search/*'); } /** * Create\Load Query model instance * * @return \Magento\Search\Model\Query * @throws \Magento\Framework\Exception\LocalizedException */ private function loadQuery() { //validate query $queryText = $this->getRequest()->getPost('query_text', false); $queryId = $this->getRequest()->getPost('query_id', null); /* @var $model \Magento\Search\Model\Query */ $model = $this->queryFactory->create(); if ($queryText) { $storeId = $this->getRequest()->getPost('store_id', false); $model->setStoreId($storeId); $model->loadByQueryText($queryText); if ($model->getId() && $model->getId() != $queryId) { throw new \Magento\Framework\Exception\LocalizedException( __('You already have an identical search term query.') ); } } if ($queryId && !$model->getId()) { $model->load($queryId); } return $model; } /** * Redirect to Edit page * * @param array $data * @return \Magento\Backend\Model\View\Result\Redirect */ private function proceedToEdit($data) { $this->_getSession()->setPageData($data); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $redirectResult = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $redirectResult->setPath('search/*/edit', ['id' => $this->getRequest()->getPost('query_id', null)]); } }