Last active
December 28, 2020 09:01
-
-
Save ProxiBlue/1b7be3c453edde5ca782c63a0a874ed0 to your computer and use it in GitHub Desktop.
move mageno 2 locked config back to database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
## steps | |
# | |
# fix where app:config:dump was run, adn value sin magento db is outof sync (so they ONLy exist in the dumped configs) | |
# | |
# Copy your app/etc/config.php (or app/etc/env.php) to bin folder | |
# delete from the app/etc/config.php (or env.php) file the values you want to re-import TO DB | |
# run bin/magento app:config:import (to process the changes you just made) | |
# run this script: ./bin/set-config.php --config config.php (or env.php) | |
# The script will process teh config as given, and set the config value to db) | |
# | |
# The end result should be all your file based configs to be existing back in the magento config db values | |
# you cannow doa more selective lock setup, rather than having had it all in the files. | |
<?php | |
if (PHP_SAPI !== 'cli') { | |
echo 'Must be run as a CLI application' . PHP_EOL; | |
exit(1); | |
} | |
$options = getopt('', ['config:']); | |
if (empty($options['config'])) { | |
echo '--config is required' . PHP_EOL; | |
exit(1); | |
} | |
$configFiles = [ | |
__DIR__ . '/' . $options['config'], | |
]; | |
$configValues = []; | |
foreach ($configFiles as $file) { | |
if (file_exists($file)) { | |
$configFile = require($file); | |
if (isset($configFile['system']['default']) && is_array($configFile['system']['default'])) { | |
$configValues = array_merge($configValues, $configFile['system']['default']); | |
} | |
} | |
} | |
if (empty($configValues)) { | |
echo 'Empty config, nothing to set' . PHP_EOL; | |
exit(1); | |
} | |
function flattenData(array &$result, $data, string $key = '') | |
{ | |
if (is_array($data)) { | |
foreach ($data as $k => $v) { | |
flattenData($result, $v, $key . '/' . $k); | |
} | |
return; | |
} | |
$result[ltrim($key, '/')] = $data; | |
} | |
$flatData = []; | |
flattenData($flatData, $configValues); | |
foreach ($flatData as $path => $value) { | |
echo 'Setting ' . $path . PHP_EOL . '> '; | |
system(__DIR__ . '/magento config:set ' . escapeshellarg($path) . ' ' . escapeshellarg($value)); | |
echo PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment