9
9
10
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
11
11
use Magento \Framework \App \Config \Storage \WriterInterface ;
12
+ use Magento \Framework \Encryption \EncryptorInterface ;
12
13
use Magento \Framework \Setup \ModuleDataSetupInterface ;
13
14
use Magento \Framework \Setup \Patch \DataPatchInterface ;
14
15
use Magento \Framework \Setup \Patch \PatchVersionInterface ;
15
16
16
17
/**
17
- * Migrate config from frontend and backend scopes to recaptcha modules.
18
+ * Migrate config from frontend and backend scopes to reCAPTCHA modules.
18
19
*/
19
20
class MigrateConfigToRecaptchaModules implements DataPatchInterface, PatchVersionInterface
20
21
{
@@ -33,19 +34,27 @@ class MigrateConfigToRecaptchaModules implements DataPatchInterface, PatchVersio
33
34
*/
34
35
private $ writer ;
35
36
37
+ /**
38
+ * @var EncryptorInterface
39
+ */
40
+ private $ encryptor ;
41
+
36
42
/**
37
43
* @param ModuleDataSetupInterface $moduleDataSetup
38
44
* @param ScopeConfigInterface $scopeConfig
39
45
* @param WriterInterface $writer
46
+ * @param EncryptorInterface $encryptor
40
47
*/
41
48
public function __construct (
42
49
ModuleDataSetupInterface $ moduleDataSetup ,
43
50
ScopeConfigInterface $ scopeConfig ,
44
- WriterInterface $ writer
51
+ WriterInterface $ writer ,
52
+ EncryptorInterface $ encryptor
45
53
) {
46
54
$ this ->moduleDataSetup = $ moduleDataSetup ;
47
55
$ this ->scopeConfig = $ scopeConfig ;
48
56
$ this ->writer = $ writer ;
57
+ $ this ->encryptor = $ encryptor ;
49
58
}
50
59
51
60
/**
@@ -58,6 +67,7 @@ public function apply()
58
67
$ this ->copyRecaptchaKeys ($ scope );
59
68
$ this ->copyModuleSpecificRecords ($ scope );
60
69
$ this ->copyEnabledRecaptcha ($ scope );
70
+ $ this ->disableLegacyRecaptcha ($ scope );
61
71
}
62
72
}
63
73
@@ -86,21 +96,38 @@ private function copyEnabledRecaptcha(string $scope): void
86
96
}
87
97
}
88
98
99
+ /**
100
+ * Disable legacy reCAPTCHA module to prevent multiple widget rendering.
101
+ *
102
+ * @param string $scope
103
+ */
104
+ private function disableLegacyRecaptcha (string $ scope ): void
105
+ {
106
+ $ this ->writer ->save ("msp_securitysuite_recaptcha/ $ scope/enabled " , 0 );
107
+ }
108
+
89
109
/**
90
110
* Copy reCAPTCHA keys.
91
111
*
92
112
* @param string $scope
93
113
*/
94
114
private function copyRecaptchaKeys (string $ scope ): void
95
115
{
96
- $ keys = ['public_key ' , 'private_key ' ];
97
116
$ type = $ this ->getActiveRecaptchaType ();
98
117
if ($ type ) {
99
- foreach ($ keys as $ key ) {
100
- $ this ->copyRecord (
101
- "msp_securitysuite_recaptcha/general/ $ key " ,
102
- "recaptcha_ $ scope/type_ $ type/ $ key "
103
- );
118
+ $ this ->copyRecord (
119
+ "msp_securitysuite_recaptcha/general/public_key " ,
120
+ "recaptcha_ $ scope/type_ $ type/public_key "
121
+ );
122
+ $ privateKey = $ this ->scopeConfig ->getValue (
123
+ "recaptcha_ $ scope/type_ $ type/private_key "
124
+ );
125
+ $ privateKeyLegacy = $ this ->scopeConfig ->getValue (
126
+ 'msp_securitysuite_recaptcha/general/private_key '
127
+ );
128
+ if (!$ privateKey && $ privateKeyLegacy ) {
129
+ $ privateKeyEncrypted = $ this ->encryptor ->encrypt ($ privateKeyLegacy );
130
+ $ this ->writer ->save ("recaptcha_ $ scope/type_ $ type/private_key " , $ privateKeyEncrypted );
104
131
}
105
132
}
106
133
}
0 commit comments