7
7
8
8
namespace Magento \EncryptionKey \Setup \Patch \Data ;
9
9
10
+ use Magento \Config \Model \Config \Backend \Encrypted ;
11
+ use Magento \Config \Model \Config \Structure ;
12
+ use Magento \Framework \App \Area ;
13
+ use Magento \Framework \App \State ;
14
+ use Magento \Framework \Config \ScopeInterface ;
15
+ use Magento \Framework \Encryption \EncryptorInterface ;
16
+ use Magento \Framework \Setup \ModuleDataSetupInterface ;
10
17
use Magento \Framework \Setup \Patch \DataPatchInterface ;
11
- use Magento \Framework \App \ObjectManager ;
12
18
13
19
/**
14
20
* Migrate encrypted configuration values to the latest cipher
15
21
*/
16
22
class SodiumChachaPatch implements DataPatchInterface
17
23
{
18
24
/**
19
- * @var \Magento\Framework\Config\ScopeInterface
20
- */
21
- private $ scope ;
22
-
23
- /**
24
- * @var \Magento\Framework\Setup\ModuleDataSetupInterface
25
+ * @var ModuleDataSetupInterface
25
26
*/
26
27
private $ moduleDataSetup ;
27
28
28
29
/**
29
- * @var \Magento\Config\Model\Config\ Structure
30
+ * @var Structure
30
31
*/
31
32
private $ structure ;
32
33
33
34
/**
34
- * @var \Magento\Framework\Encryption\ EncryptorInterface
35
+ * @var EncryptorInterface
35
36
*/
36
37
private $ encryptor ;
37
38
38
39
/**
39
- * @var \Magento\Framework\App\ State
40
+ * @var State
40
41
*/
41
42
private $ state ;
42
43
44
+ /**
45
+ * @var ScopeInterface
46
+ */
47
+ private $ scope ;
48
+
43
49
/**
44
50
* SodiumChachaPatch constructor.
45
- * @param \Magento\Framework\Setup\ ModuleDataSetupInterface $moduleDataSetup
46
- * @param \Magento\Config\Model\Config\ Structure\Proxy $structure
47
- * @param \Magento\Framework\Encryption\ EncryptorInterface $encryptor
48
- * @param \Magento\Framework\App\ State $state
49
- * @param \Magento\Framework\Config\ ScopeInterface|null $scope
51
+ * @param ModuleDataSetupInterface $moduleDataSetup
52
+ * @param Structure $structure
53
+ * @param EncryptorInterface $encryptor
54
+ * @param State $state
55
+ * @param ScopeInterface $scope
50
56
*/
51
57
public function __construct (
52
- \ Magento \ Framework \ Setup \ ModuleDataSetupInterface $ moduleDataSetup ,
53
- \ Magento \ Config \ Model \ Config \ Structure \ Proxy $ structure ,
54
- \ Magento \ Framework \ Encryption \ EncryptorInterface $ encryptor ,
55
- \ Magento \ Framework \ App \ State $ state ,
56
- \ Magento \ Framework \ Config \ ScopeInterface $ scope = null
58
+ ModuleDataSetupInterface $ moduleDataSetup ,
59
+ Structure $ structure ,
60
+ EncryptorInterface $ encryptor ,
61
+ State $ state ,
62
+ ScopeInterface $ scope
57
63
) {
58
64
$ this ->moduleDataSetup = $ moduleDataSetup ;
59
65
$ this ->structure = $ structure ;
60
66
$ this ->encryptor = $ encryptor ;
61
67
$ this ->state = $ state ;
62
- $ this ->scope = $ scope ?? ObjectManager:: getInstance ()-> get (\ Magento \ Framework \ Config \ScopeInterface::class) ;
68
+ $ this ->scope = $ scope ;
63
69
}
64
70
65
71
/**
@@ -72,6 +78,8 @@ public function apply()
72
78
$ this ->reEncryptSystemConfigurationValues ();
73
79
74
80
$ this ->moduleDataSetup ->endSetup ();
81
+
82
+ return $ this ;
75
83
}
76
84
77
85
/**
@@ -106,19 +114,25 @@ private function reEncryptSystemConfigurationValues()
106
114
$ currentScope = $ this ->scope ->getCurrentScope ();
107
115
$ structure = $ this ->structure ;
108
116
$ paths = $ this ->state ->emulateAreaCode (
109
- \ Magento \ Framework \ App \ Area::AREA_ADMINHTML ,
117
+ Area::AREA_ADMINHTML ,
110
118
function () use ($ structure ) {
111
- $ this ->scope ->setCurrentScope (\ Magento \ Framework \ App \ Area::AREA_ADMINHTML );
119
+ $ this ->scope ->setCurrentScope (Area::AREA_ADMINHTML );
112
120
/** Returns list of structure paths to be re encrypted */
113
121
$ paths = $ structure ->getFieldPathsByAttribute (
114
122
'backend_model ' ,
115
- \ Magento \ Config \ Model \ Config \ Backend \ Encrypted::class
123
+ Encrypted::class
116
124
);
117
125
/** Returns list of mapping between configPath => [structurePaths] */
118
126
$ mappedPaths = $ structure ->getFieldPaths ();
119
127
foreach ($ mappedPaths as $ mappedPath => $ data ) {
120
128
foreach ($ data as $ structurePath ) {
121
- if ($ structurePath !== $ mappedPath && $ key = array_search ($ structurePath , $ paths )) {
129
+ if ($ structurePath === $ mappedPath ) {
130
+ continue ;
131
+ }
132
+
133
+ $ key = array_search ($ structurePath , $ paths );
134
+
135
+ if ($ key ) {
122
136
$ paths [$ key ] = $ mappedPath ;
123
137
}
124
138
}
0 commit comments