Skip to content

Commit fb6a73e

Browse files
MC-41604: Settings migration in System configuration
- remove display and move code to a different method
1 parent 54463f3 commit fb6a73e

File tree

1 file changed

+58
-41
lines changed

1 file changed

+58
-41
lines changed

app/code/Magento/Paypal/Setup/Patch/Data/UpdateBmltoPayLater.php

Lines changed: 58 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,10 @@ class UpdateBmltoPayLater implements DataPatchInterface
2828
/**
2929
* @var array
3030
*/
31-
private $bmlToPayLaterSettings = [
31+
private $bmlToPayLater = [
3232
[
3333
'pages' => ['productpage'],
3434
'data' => [
35-
'display' => [
36-
'name' => 'display',
37-
'values' => ['0' => '0', '1' => '1']
38-
],
3935
'position' => [
4036
'name' =>'position',
4137
'values' => ['0' => 'header', '1' => 'near_pp_button'],
@@ -103,52 +99,73 @@ public function apply()
10399
continue;
104100
}
105101

106-
foreach ($this->bmlToPayLaterSettings as $bmlToPayLaterSetting) {
102+
foreach ($this->bmlToPayLater as $bmlToPayLaterSetting) {
107103
if (in_array($page, $bmlToPayLaterSetting['pages'])
108104
&& array_key_exists($setting, $bmlToPayLaterSetting['data'])
109105
) {
110106
$pageSetting = $bmlToPayLaterSetting['data'][$setting];
111-
$dependsPath = isset($pageSetting['depends'])
112-
? self::BMLPATH . $page . '_' . $pageSetting['depends']['name']
113-
: '';
114-
115-
if (!array_key_exists('depends', $pageSetting)
116-
|| (array_key_exists($dependsPath, $bmlSettings)
117-
&& $bmlSettings[$dependsPath] === $pageSetting['depends']['value'])
118-
) {
119-
$path = $payLaterPath . '_' . $pageSetting['name'];
120-
$value = $pageSetting['values'][$bmlValue];
121-
$this->moduleDataSetup->getConnection()->insertOnDuplicate(
122-
$this->moduleDataSetup->getTable('core_config_data'),
123-
[
124-
'scope' => 'default',
125-
'scope_id' => 0,
126-
'path' => $path,
127-
'value' => $value
128-
]
129-
);
130-
if (array_key_exists('requires', $pageSetting)
131-
&& array_key_exists($value, $pageSetting['requires'])
132-
) {
133-
$requiredPath = $payLaterPath . '_' . $pageSetting['requires'][$value]['name'];
134-
$requiredValue = $pageSetting['requires'][$value]['value'];
135-
$this->moduleDataSetup->getConnection()->insertOnDuplicate(
136-
$this->moduleDataSetup->getTable('core_config_data'),
137-
[
138-
'scope' => 'default',
139-
'scope_id' => 0,
140-
'path' => $requiredPath,
141-
'value' => $requiredValue
142-
]
143-
);
144-
}
145-
}
107+
108+
$this->convertAndSaveConfigValues($bmlSettings, $pageSetting, $payLaterPath, $page, $bmlValue);
146109
}
147110
}
148111
}
112+
149113
return $this->moduleDataSetup->getConnection()->endSetup();
150114
}
151115

116+
/**
117+
* Convert BML settings to PayLater and save
118+
*
119+
* @param array $bmlSettings
120+
* @param array $pageSetting
121+
* @param string $payLaterPath
122+
* @param string $page
123+
* @param string $bmlValue
124+
*/
125+
private function convertAndSaveConfigValues(
126+
array $bmlSettings,
127+
array $pageSetting,
128+
string $payLaterPath,
129+
string $page,
130+
string $bmlValue
131+
) {
132+
$dependsPath = isset($pageSetting['depends'])
133+
? self::BMLPATH . $page . '_' . $pageSetting['depends']['name']
134+
: '';
135+
136+
if (!array_key_exists('depends', $pageSetting)
137+
|| (array_key_exists($dependsPath, $bmlSettings)
138+
&& $bmlSettings[$dependsPath] === $pageSetting['depends']['value'])
139+
) {
140+
$path = $payLaterPath . '_' . $pageSetting['name'];
141+
$value = $pageSetting['values'][$bmlValue];
142+
$this->moduleDataSetup->getConnection()->insertOnDuplicate(
143+
$this->moduleDataSetup->getTable('core_config_data'),
144+
[
145+
'scope' => 'default',
146+
'scope_id' => 0,
147+
'path' => $path,
148+
'value' => $value
149+
]
150+
);
151+
if (array_key_exists('requires', $pageSetting)
152+
&& array_key_exists($value, $pageSetting['requires'])
153+
) {
154+
$requiredPath = $payLaterPath . '_' . $pageSetting['requires'][$value]['name'];
155+
$requiredValue = $pageSetting['requires'][$value]['value'];
156+
$this->moduleDataSetup->getConnection()->insertOnDuplicate(
157+
$this->moduleDataSetup->getTable('core_config_data'),
158+
[
159+
'scope' => 'default',
160+
'scope_id' => 0,
161+
'path' => $requiredPath,
162+
'value' => $requiredValue
163+
]
164+
);
165+
}
166+
}
167+
}
168+
152169
/**
153170
* @inheritdoc
154171
*/

0 commit comments

Comments
 (0)