Skip to content

Commit e093eff

Browse files
authored
Merge branch '2.4-develop' into patch-2
2 parents 253fa76 + f37b43c commit e093eff

File tree

751 files changed

+25411
-6211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

751 files changed

+25411
-6211
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsyncConfig\Api;
9+
10+
use Magento\Framework\Exception\FileSystemException;
11+
12+
interface AsyncConfigPublisherInterface
13+
{
14+
/**
15+
* Save Configuration Data
16+
*
17+
* @param array $configData
18+
* @return void
19+
* @throws FileSystemException
20+
*/
21+
public function saveConfigData(array $configData);
22+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsyncConfig\Api\Data;
9+
10+
interface AsyncConfigMessageInterface
11+
{
12+
/**
13+
* Get Configuration data
14+
*
15+
* @return string
16+
*/
17+
public function getConfigData();
18+
19+
/**
20+
* Set Configuration data
21+
*
22+
* @param string $data
23+
* @return void
24+
*/
25+
public function setConfigData(string $data);
26+
}

app/code/Magento/Elasticsearch8/LICENSE.txt renamed to app/code/Magento/AsyncConfig/LICENSE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Licensed under the Open Software License version 3.0
1515

1616
4. to perform the Original Work publicly; and
1717

18-
5. to display the Original Work publicly.
18+
5. to display the Original Work publicly.
1919

2020
2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works.
2121

@@ -45,4 +45,4 @@ Licensed under the Open Software License version 3.0
4545

4646
15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
4747

48-
16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
48+
16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under <insert your license name here>" or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsyncConfig\Model;
9+
10+
use Magento\AsyncConfig\Api\Data\AsyncConfigMessageInterfaceFactory;
11+
use Magento\Framework\App\Filesystem\DirectoryList;
12+
use Magento\Framework\Exception\FileSystemException;
13+
use Magento\Framework\Filesystem\Io\File;
14+
use Magento\Framework\MessageQueue\PublisherInterface;
15+
use Magento\Framework\Serialize\Serializer\Json;
16+
17+
class AsyncConfigPublisher implements \Magento\AsyncConfig\Api\AsyncConfigPublisherInterface
18+
{
19+
/**
20+
* @var PublisherInterface
21+
*/
22+
private $messagePublisher;
23+
24+
/**
25+
* @var AsyncConfigMessageInterfaceFactory
26+
*/
27+
private $asyncConfigFactory;
28+
29+
/**
30+
* @var Json
31+
*/
32+
private $serializer;
33+
34+
/**
35+
* @var \Magento\Framework\Filesystem\DirectoryList
36+
*/
37+
private $dir;
38+
39+
/**
40+
* @var File
41+
*/
42+
private $file;
43+
44+
/**
45+
*
46+
* @param AsyncConfigMessageInterfaceFactory $asyncConfigFactory
47+
* @param PublisherInterface $publisher
48+
* @param Json $json
49+
* @param \Magento\Framework\Filesystem\DirectoryList $dir
50+
* @param File $file
51+
*/
52+
public function __construct(
53+
AsyncConfigMessageInterfaceFactory $asyncConfigFactory,
54+
PublisherInterface $publisher,
55+
Json $json,
56+
\Magento\Framework\Filesystem\DirectoryList $dir,
57+
File $file
58+
) {
59+
$this->asyncConfigFactory = $asyncConfigFactory;
60+
$this->messagePublisher = $publisher;
61+
$this->serializer = $json;
62+
$this->dir = $dir;
63+
$this->file = $file;
64+
}
65+
66+
/**
67+
* @inheritDoc
68+
*/
69+
public function saveConfigData(array $configData)
70+
{
71+
$asyncConfig = $this->asyncConfigFactory->create();
72+
$this->saveImages($configData);
73+
$asyncConfig->setConfigData($this->serializer->serialize($configData));
74+
$this->messagePublisher->publish('async_config.saveConfig', $asyncConfig);
75+
}
76+
77+
/**
78+
* Save Images to temporary Path
79+
*
80+
* @param array $configData
81+
* @return void
82+
* @throws FileSystemException
83+
*/
84+
private function saveImages(array &$configData)
85+
{
86+
if (isset($configData['groups']['placeholder'])) {
87+
$this->changeImagePath($configData['groups']['placeholder']['fields']);
88+
} elseif (isset($configData['groups']['identity'])) {
89+
$this->changeImagePath($configData['groups']['identity']['fields']);
90+
}
91+
}
92+
93+
/**
94+
* Change Placeholder Data path if exists
95+
*
96+
* @param array $fields
97+
* @return void
98+
* @throws FileSystemException
99+
*/
100+
private function changeImagePath(array &$fields)
101+
{
102+
foreach ($fields as &$data) {
103+
if (!empty($data['value']['tmp_name'])) {
104+
$newPath =
105+
$this->dir->getPath(DirectoryList::MEDIA) . '/' .
106+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
107+
pathinfo($data['value']['tmp_name'])['filename'];
108+
$this->file->mv(
109+
$data['value']['tmp_name'],
110+
$newPath
111+
);
112+
$data['value']['tmp_name'] = $newPath;
113+
}
114+
}
115+
}
116+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsyncConfig\Model;
9+
10+
use Magento\AsyncConfig\Api\Data\AsyncConfigMessageInterface;
11+
use Magento\Config\Controller\Adminhtml\System\Config\Save;
12+
use Magento\Config\Model\Config\Factory;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\Config\ScopeInterface;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Serialize\Serializer\Json;
17+
use Symfony\Component\Console\Output\ConsoleOutput;
18+
19+
class Consumer
20+
{
21+
/**
22+
* Backend Config Model Factory
23+
*
24+
* @var Factory
25+
*/
26+
private $configFactory;
27+
28+
/**
29+
* @var Json
30+
*/
31+
private $serializer;
32+
33+
/**
34+
* @var ScopeInterface
35+
*/
36+
private $scope;
37+
38+
/**
39+
* @var Save
40+
*/
41+
private $save;
42+
43+
/**
44+
* @var ConsoleOutput
45+
*/
46+
private $output;
47+
48+
/**
49+
* @param Factory $configFactory
50+
* @param Json $json
51+
* @param ScopeInterface $scope
52+
* @param ConsoleOutput $output
53+
*/
54+
public function __construct(
55+
Factory $configFactory,
56+
Json $json,
57+
ScopeInterface $scope,
58+
ConsoleOutput $output
59+
) {
60+
$this->configFactory = $configFactory;
61+
$this->serializer = $json;
62+
$this->scope = $scope;
63+
$this->output = $output;
64+
$this->scope->setCurrentScope('adminhtml');
65+
$this->save = ObjectManager::getInstance()->get(Save::class);
66+
$this->scope->setCurrentScope('global');
67+
}
68+
/**
69+
* Process Consumer
70+
*
71+
* @param AsyncConfigMessageInterface $asyncConfigMessage
72+
* @return void
73+
* @throws \Exception
74+
*/
75+
public function process(AsyncConfigMessageInterface $asyncConfigMessage): void
76+
{
77+
$configData = $asyncConfigMessage->getConfigData();
78+
$data = $this->serializer->unserialize($configData);
79+
$data = $this->save->filterNodes($data);
80+
/** @var \Magento\Config\Model\Config $configModel */
81+
$configModel = $this->configFactory->create(['data' => $data]);
82+
try {
83+
$configModel->save();
84+
} catch (LocalizedException $exception) {
85+
$message = $exception->getMessage();
86+
$this->output->writeln(' Config couldn\'t be saved: ' . $message);
87+
}
88+
}
89+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsyncConfig\Model\Entity;
9+
10+
use Magento\AsyncConfig\Api\Data\AsyncConfigMessageInterface;
11+
12+
class AsyncConfigMessage implements AsyncConfigMessageInterface
13+
{
14+
/**
15+
* @var string
16+
*/
17+
private $data;
18+
19+
/**
20+
* @inheritDoc
21+
*/
22+
public function getConfigData()
23+
{
24+
return $this->data;
25+
}
26+
27+
/**
28+
* @inheritDoc
29+
*/
30+
public function setConfigData($data)
31+
{
32+
$this->data = $data;
33+
}
34+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\AsyncConfig\Plugin\Controller\System\Config;
9+
10+
use Magento\AsyncConfig\Api\AsyncConfigPublisherInterface;
11+
use Magento\AsyncConfig\Setup\ConfigOptionsList;
12+
use Magento\Config\Controller\Adminhtml\System\Config\Save;
13+
use Magento\Framework\App\DeploymentConfig;
14+
use Magento\Framework\Controller\Result\RedirectFactory;
15+
use Magento\Framework\Exception\FileSystemException;
16+
use Magento\Framework\Exception\LocalizedException;
17+
use Magento\Framework\Exception\RuntimeException;
18+
use Magento\Framework\Message\ManagerInterface;
19+
20+
class SaveAsyncConfigPlugin
21+
{
22+
/**
23+
* @var DeploymentConfig
24+
*/
25+
private $deploymentConfig;
26+
27+
/**
28+
* @var AsyncConfigPublisherInterface
29+
*/
30+
private $asyncConfigPublisher;
31+
32+
/**
33+
* @var RedirectFactory
34+
*/
35+
private $resultRedirectFactory;
36+
37+
/**
38+
* @var ManagerInterface
39+
*/
40+
private $messageManager;
41+
42+
/**
43+
*
44+
* @param DeploymentConfig $deploymentConfig
45+
* @param AsyncConfigPublisherInterface $asyncConfigPublisher
46+
* @param RedirectFactory $resultRedirectFactory
47+
* @param ManagerInterface $messageManager
48+
*/
49+
public function __construct(
50+
DeploymentConfig $deploymentConfig,
51+
AsyncConfigPublisherInterface $asyncConfigPublisher,
52+
RedirectFactory $resultRedirectFactory,
53+
ManagerInterface $messageManager
54+
) {
55+
$this->deploymentConfig = $deploymentConfig;
56+
$this->asyncConfigPublisher = $asyncConfigPublisher;
57+
$this->resultRedirectFactory = $resultRedirectFactory;
58+
$this->messageManager = $messageManager;
59+
}
60+
61+
/**
62+
* Around Config save controller
63+
*
64+
* @param Save $subject
65+
* @param callable $proceed
66+
* @return \Magento\Backend\Model\View\Result\Redirect
67+
* @throws FileSystemException
68+
* @throws LocalizedException
69+
* @throws RuntimeException
70+
*/
71+
public function aroundExecute(Save $subject, callable $proceed)
72+
{
73+
if (!$this->deploymentConfig->get(ConfigOptionsList::CONFIG_PATH_ASYNC_CONFIG_SAVE)) {
74+
return $proceed();
75+
} else {
76+
$configData = $subject->getConfigData();
77+
$this->asyncConfigPublisher->saveConfigData($configData);
78+
$this->messageManager->addSuccessMessage(__('Configuration changes will be applied by consumer soon.'));
79+
$subject->_saveState($subject->getRequest()->getPost('config_state'));
80+
/** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
81+
$resultRedirect = $this->resultRedirectFactory->create();
82+
return $resultRedirect->setPath(
83+
'adminhtml/system_config/edit',
84+
[
85+
'_current' => ['section', 'website', 'store'],
86+
'_nosid' => true
87+
]
88+
);
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)