5
5
*/
6
6
declare (strict_types=1 );
7
7
8
- namespace Magento \AsyncConfig \Controller \ Adminhtml \System \Config ;
8
+ namespace Magento \AsyncConfig \Plugin \ Controller \System \Config ;
9
9
10
10
use Magento \AsyncConfig \Api \AsyncConfigPublisherInterface ;
11
- use Magento \Framework \ App \ Action \ HttpPostActionInterface ;
11
+ use Magento \Config \ Controller \ Adminhtml \ System \ Config \ Save ;
12
12
use Magento \Framework \App \DeploymentConfig ;
13
13
use Magento \Framework \App \ObjectManager ;
14
+ use Magento \Framework \Controller \Result \RedirectFactory ;
14
15
use Magento \Framework \Exception \FileSystemException ;
15
16
use Magento \Framework \Exception \LocalizedException ;
16
17
use Magento \Framework \Exception \RuntimeException ;
18
+ use Magento \Framework \Message \ManagerInterface ;
17
19
18
- class Save extends \ Magento \ Config \ Controller \ Adminhtml \ System \ Config \Save implements HttpPostActionInterface
20
+ class SaveAsyncConfigPlugin
19
21
{
20
22
/**
21
23
* @var DeploymentConfig
@@ -27,61 +29,56 @@ class Save extends \Magento\Config\Controller\Adminhtml\System\Config\Save imple
27
29
*/
28
30
private $ asyncConfigPublisher ;
29
31
32
+ /**
33
+ * @var RedirectFactory
34
+ */
35
+ private RedirectFactory $ resultRedirectFactory ;
36
+
37
+ /**
38
+ * @var ManagerInterface
39
+ */
40
+ private $ messageManager ;
41
+
30
42
/**
31
43
* @var const
32
44
*/
33
45
public const ASYNC_CONFIG_OPTION_PATH = 'config/async ' ;
34
46
35
47
/**
36
- * @param \Magento\Backend\App\Action\Context $context
37
- * @param \Magento\Config\Model\Config\Structure $configStructure
38
- * @param \Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker $sectionChecker
39
- * @param \Magento\Config\Model\Config\Factory $configFactory
40
- * @param \Magento\Framework\Cache\FrontendInterface $cache
41
- * @param \Magento\Framework\Stdlib\StringUtils $string
42
48
* @param DeploymentConfig|null $deploymentConfig
43
49
* @param AsyncConfigPublisherInterface|null $asyncConfigPublisher
44
50
*/
45
51
public function __construct (
46
- \Magento \Backend \App \Action \Context $ context ,
47
- \Magento \Config \Model \Config \Structure $ configStructure ,
48
- \Magento \Config \Controller \Adminhtml \System \ConfigSectionChecker $ sectionChecker ,
49
- \Magento \Config \Model \Config \Factory $ configFactory ,
50
- \Magento \Framework \Cache \FrontendInterface $ cache ,
51
- \Magento \Framework \Stdlib \StringUtils $ string ,
52
52
DeploymentConfig $ deploymentConfig = null ,
53
- AsyncConfigPublisherInterface $ asyncConfigPublisher = null
53
+ AsyncConfigPublisherInterface $ asyncConfigPublisher = null ,
54
+ RedirectFactory $ resultRedirectFactory ,
55
+ ManagerInterface $ messageManager
54
56
) {
55
- parent ::__construct (
56
- $ context ,
57
- $ configStructure ,
58
- $ sectionChecker ,
59
- $ configFactory ,
60
- $ cache ,
61
- $ string
62
- );
63
57
$ this ->deploymentConfig = $ deploymentConfig
64
58
?? ObjectManager::getInstance ()->get (DeploymentConfig::class);
65
59
$ this ->asyncConfigPublisher = $ asyncConfigPublisher
66
60
?? ObjectManager::getInstance ()->get (AsyncConfigPublisherInterface::class);
61
+ $ this ->resultRedirectFactory = $ resultRedirectFactory ;
62
+ $ this ->messageManager = $ messageManager ;
67
63
}
68
64
69
65
/**
70
66
* Execute Save action
71
67
*
68
+ * @param Save $subject
72
69
* @throws LocalizedException
73
70
* @throws FileSystemException
74
71
* @throws RuntimeException
75
72
*/
76
- public function execute ( )
73
+ public function aroundExecute ( Save $ subject , callable $ proceed )
77
74
{
78
75
if (!$ this ->deploymentConfig ->get (self ::ASYNC_CONFIG_OPTION_PATH )) {
79
- return parent :: execute ();
76
+ return $ proceed ();
80
77
} else {
81
- $ configData = $ this ->getConfigData ();
78
+ $ configData = $ subject ->getConfigData ();
82
79
$ this ->asyncConfigPublisher ->saveConfigData ($ configData );
83
80
$ this ->messageManager ->addSuccess (__ ('Configuration changes will be applied by consumer soon. ' ));
84
- $ this ->_saveState ($ this ->getRequest ()->getPost ('config_state ' ));
81
+ $ subject ->_saveState ($ subject ->getRequest ()->getPost ('config_state ' ));
85
82
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
86
83
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
87
84
return $ resultRedirect ->setPath (
0 commit comments