Skip to content

Commit 07dd8e7

Browse files
security-package/issues/101: Migration update.
1 parent 01b1f37 commit 07dd8e7

File tree

2 files changed

+45
-137
lines changed

2 files changed

+45
-137
lines changed

ReCaptchaMigration/Setup/Patch/Data/CopyConfigFromOldModule.php

Lines changed: 0 additions & 112 deletions
This file was deleted.

ReCaptchaMigration/Setup/Patch/Data/MigrateConfigToRecaptchaModules.php

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ private function copyEnabledRecaptcha(string $scope): void
7474
}
7575

7676
$availableRecaptchaPreferences = $this->getAvailableRecaptchaPreferences();
77-
foreach ($availableRecaptchaPreferences[$scope] as $availableRecaptchaPreference) {
78-
$availableRecaptchaPreferencePath = "recaptcha_$scope/type_for/$availableRecaptchaPreference";
77+
foreach ($availableRecaptchaPreferences[$scope] as $availablePreference => $legacyPreference) {
78+
$availableRecaptchaPreferencePath = "recaptcha_$scope/type_for/$availablePreference";
7979
$recaptchaPreferenceEnabled = $this->scopeConfig->getValue($availableRecaptchaPreferencePath);
80-
$recaptchaPreferenceEnabledLegacy = $this->scopeConfig->getValue("recaptcha/general/enabled_for_$availableRecaptchaPreference");
81-
if (null === $recaptchaPreferenceEnabled && null !== $recaptchaPreferenceEnabledLegacy) {
82-
$this->writer->save($availableRecaptchaPreferencePath, (int)$recaptchaPreferenceEnabledLegacy ? $type : null);
80+
$recaptchaPreferenceEnabledLegacy = $this->scopeConfig->getValue(
81+
"msp_securitysuite_recaptcha/$scope/enabled$legacyPreference"
82+
);
83+
if (null === $recaptchaPreferenceEnabled && '0' !== $recaptchaPreferenceEnabledLegacy) {
84+
$this->writer->save($availableRecaptchaPreferencePath, $type);
8385
}
8486
}
8587
}
@@ -93,8 +95,13 @@ private function copyRecaptchaKeys(string $scope): void
9395
{
9496
$keys = ['public_key', 'private_key'];
9597
$type = $this->getActiveRecaptchaType();
96-
foreach ($keys as $key) {
97-
$this->copyRecord("recaptcha/general/$key", "recaptcha_$scope/type_$type/$key");
98+
if ($type) {
99+
foreach ($keys as $key) {
100+
$this->copyRecord(
101+
"msp_securitysuite_recaptcha/general/$key",
102+
"recaptcha_$scope/type_$type/$key"
103+
);
104+
}
98105
}
99106
}
100107

@@ -106,8 +113,11 @@ private function copyRecaptchaKeys(string $scope): void
106113
private function copyModuleSpecificRecords(string $scope): void
107114
{
108115
foreach ($this->getModuleSpecificRecords() as $module => $specificRecords) {
109-
foreach ($specificRecords as $specificRecord) {
110-
$this->copyRecord("recaptcha/general/$specificRecord", "recaptcha_$scope/type_$module/$specificRecord");
116+
foreach ($specificRecords as $actualRecord => $legacyRecord) {
117+
$this->copyRecord(
118+
"msp_securitysuite_recaptcha/$scope/$legacyRecord",
119+
"recaptcha_$scope/type_$module/$actualRecord"
120+
);
111121
}
112122
}
113123
}
@@ -120,9 +130,21 @@ private function copyModuleSpecificRecords(string $scope): void
120130
private function getModuleSpecificRecords(): array
121131
{
122132
return [
123-
'recaptcha' => ['theme', 'lang', 'size'],
124-
'invisible' => ['theme', 'lang', 'position'],
125-
'recaptcha_v3' => ['theme', 'lang', 'score_threshold', 'position'],
133+
'recaptcha' => [
134+
'theme' => 'theme',
135+
'lang' => 'lang',
136+
'size' => 'size'
137+
],
138+
'invisible' => [
139+
'theme' => 'theme',
140+
'lang' => 'lang',
141+
'position' => 'position'
142+
],
143+
'recaptcha_v3' => [
144+
'theme' => 'theme',
145+
'lang' => 'lang',
146+
'score_threshold' => 'min_score',
147+
'position' => 'position'],
126148
];
127149
}
128150

@@ -135,17 +157,17 @@ private function getAvailableRecaptchaPreferences(): array
135157
{
136158
return [
137159
'frontend' => [
138-
'customer_login',
139-
'customer_forgot_password',
140-
'customer_create',
141-
'contact',
142-
'product_review',
143-
'newsletter',
144-
'sendfriend',
160+
'customer_login' => '_login',
161+
'customer_forgot_password' => '_forgot',
162+
'customer_create' => '_create',
163+
'contact' => '_contact',
164+
'product_review' => '_review',
165+
'newsletter' => '_newsletter',
166+
'sendfriend' => '_sendfriend',
145167
],
146168
'backend' => [
147-
'user_login',
148-
'user_forgot_password',
169+
'user_login' => '',
170+
'user_forgot_password' => '',
149171
],
150172
];
151173
}
@@ -157,7 +179,7 @@ private function getAvailableRecaptchaPreferences(): array
157179
*/
158180
private function getActiveRecaptchaType(): ?string
159181
{
160-
return $this->scopeConfig->getValue('recaptcha/general/type');
182+
return $this->scopeConfig->getValue('msp_securitysuite_recaptcha/general/type');
161183
}
162184

163185
/**
@@ -197,9 +219,7 @@ private function copyRecord(string $srcPath, string $dstPath): void
197219
*/
198220
public static function getDependencies()
199221
{
200-
return [
201-
CopyConfigFromOldModule::class,
202-
];
222+
return [];
203223
}
204224

205225
/**

0 commit comments

Comments
 (0)