1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MagePrince |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the mageprince.com license that is |
8
|
|
|
* available through the world-wide-web at this URL: |
9
|
|
|
* https://mageprince.com/end-user-license-agreement |
10
|
|
|
* |
11
|
|
|
* DISCLAIMER |
12
|
|
|
* |
13
|
|
|
* Do not edit or add to this file if you wish to upgrade this extension to newer |
14
|
|
|
* version in the future. |
15
|
|
|
* |
16
|
|
|
* @category MagePrince |
17
|
|
|
* @package Mageprince_Faq |
18
|
|
|
* @copyright Copyright (c) MagePrince (https://mageprince.com/) |
19
|
|
|
* @license https://mageprince.com/end-user-license-agreement |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Mageprince\Faq\Controller\Adminhtml\Faq; |
23
|
|
|
|
24
|
|
|
use Magento\Backend\App\Action; |
|
|
|
|
25
|
|
|
use Magento\Backend\Model\View\Result\Redirect; |
|
|
|
|
26
|
|
|
use Magento\Framework\App\Request\DataPersistorInterface; |
|
|
|
|
27
|
|
|
use Magento\Framework\Controller\ResultInterface; |
|
|
|
|
28
|
|
|
use Magento\Framework\Exception\LocalizedException; |
|
|
|
|
29
|
|
|
use Mageprince\Faq\Api\FaqRepositoryInterface; |
30
|
|
|
use Mageprince\Faq\Model\FaqFactory; |
|
|
|
|
31
|
|
|
|
32
|
|
|
class Save extends Faq |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var DataPersistorInterface |
36
|
|
|
*/ |
37
|
|
|
protected $dataPersistor; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var FaqFactory |
41
|
|
|
*/ |
42
|
|
|
protected $faqFactory; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var FaqRepositoryInterface |
46
|
|
|
*/ |
47
|
|
|
protected $faqRepository; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Save constructor. |
51
|
|
|
* @param Action\Context $context |
52
|
|
|
* @param DataPersistorInterface $dataPersistor |
53
|
|
|
* @param FaqFactory $faqFactory |
54
|
|
|
* @param FaqRepositoryInterface $faqRepository |
55
|
|
|
*/ |
56
|
|
|
public function __construct( |
57
|
|
|
Action\Context $context, |
|
|
|
|
58
|
|
|
DataPersistorInterface $dataPersistor, |
59
|
|
|
FaqFactory $faqFactory, |
60
|
|
|
FaqRepositoryInterface $faqRepository |
61
|
|
|
) { |
62
|
|
|
$this->dataPersistor = $dataPersistor; |
63
|
|
|
$this->faqFactory = $faqFactory; |
64
|
|
|
$this->faqRepository = $faqRepository; |
65
|
|
|
parent::__construct($context); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Save action |
70
|
|
|
* |
71
|
|
|
* @return ResultInterface |
72
|
|
|
*/ |
73
|
|
|
public function execute() |
74
|
|
|
{ |
75
|
|
|
/** @var Redirect $resultRedirect */ |
76
|
|
|
$resultRedirect = $this->resultRedirectFactory->create(); |
77
|
|
|
if ($data = $this->getRequest()->getPostValue()) { |
78
|
|
|
$model = $this->faqFactory->create(); |
79
|
|
|
try { |
80
|
|
|
if ($id = (int) $this->getRequest()->getParam('faq_id')) { |
81
|
|
|
$model = $this->faqRepository->getById($id); |
82
|
|
|
if ($id != $model->getFaqId()) { |
83
|
|
|
$this->messageManager->addErrorMessage(__('This FAQ no longer exists.')); |
|
|
|
|
84
|
|
|
return $resultRedirect->setPath('*/*/'); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$data = $this->_filterFaqData($data); |
89
|
|
|
$model->addData($data); |
90
|
|
|
$this->faqRepository->save($model); |
91
|
|
|
$this->messageManager->addSuccessMessage(__('You saved the FAQ.')); |
92
|
|
|
$this->dataPersistor->clear('prince_faq_faq'); |
93
|
|
|
|
94
|
|
|
if ($this->getRequest()->getParam('back')) { |
95
|
|
|
return $resultRedirect->setPath('*/*/edit', ['faq_id' => $model->getId()]); |
96
|
|
|
} |
97
|
|
|
return $resultRedirect->setPath('*/*/'); |
98
|
|
|
} catch (LocalizedException $e) { |
99
|
|
|
$this->messageManager->addErrorMessage($e->getMessage()); |
100
|
|
|
} catch (\Exception $e) { |
101
|
|
|
$this->messageManager->addExceptionMessage($e, __('Something went wrong while saving the FAQ.')); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
$this->dataPersistor->set('prince_faq_faq', $data); |
105
|
|
|
return $resultRedirect->setPath('*/*/edit', ['faq_id' => $this->getRequest()->getParam('faq_id')]); |
106
|
|
|
} |
107
|
|
|
return $resultRedirect->setPath('*/*/'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Filter faq data |
112
|
|
|
* |
113
|
|
|
* @param array $data |
114
|
|
|
* @return mixed |
115
|
|
|
*/ |
116
|
|
|
protected function _filterFaqData($data) |
117
|
|
|
{ |
118
|
|
|
$groups = implode(',', $data['group']); |
119
|
|
|
$data['group'] = $groups; |
120
|
|
|
$cGroup = $data['customer_group']; |
121
|
|
|
if (isset($cGroup)) { |
122
|
|
|
$customerGroup = implode(',', $data['customer_group']); |
123
|
|
|
$data['customer_group'] = $customerGroup; |
124
|
|
|
} |
125
|
|
|
$stores = $data['storeview']; |
126
|
|
|
if (isset($stores)) { |
127
|
|
|
$store = implode(',', $data['storeview']); |
128
|
|
|
$data['storeview'] = $store; |
129
|
|
|
} |
130
|
|
|
return $data; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths