From cd4a931d173ead67bee0565e0426b72adf8d3400 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 19 Feb 2020 23:21:28 +0300 Subject: [PATCH] feat(core): copy core `settings` file content from `default` to `custom` folder on core init. --- flextype/bootstrap.php | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/flextype/bootstrap.php b/flextype/bootstrap.php index 37198c19..1d5b3deb 100755 --- a/flextype/bootstrap.php +++ b/flextype/bootstrap.php @@ -52,28 +52,34 @@ $registry = new Registry(); $default_flextype_settings_file_path = PATH['config']['default'] . '/settings.yaml'; $custom_flextype_settings_file_path = PATH['config']['site'] . '/settings.yaml'; -// Set settings if Flextype Default settings and Flextype Custom settings config files exist -if (! Filesystem::has($default_flextype_settings_file_path) || ! Filesystem::has($custom_flextype_settings_file_path)) { - throw new RuntimeException('Flextype Default settings or Flextype Custom settings config files does not exist.'); +// Create config dir +! Filesystem::has(PATH['site'] . '/config/') and Filesystem::createDir(PATH['site'] . '/config/'); + +// Set settings if Flextype Default settings config files exist +if (! Filesystem::has($default_flextype_settings_file_path)) { + throw new RuntimeException('Flextype Default settings config file does not exist.'); } -if (($content = Filesystem::read($default_flextype_settings_file_path)) === false) { +if (($default_flextype_settings_content = Filesystem::read($default_flextype_settings_file_path)) === false) { throw new RuntimeException('Load file: ' . $default_flextype_settings_file_path . ' - failed!'); } else { - if (trim($content) === '') { + if (trim($default_flextype_settings_content) === '') { $default_flextype_settings = []; } else { - $default_flextype_settings = Yaml::decode($content); + $default_flextype_settings = Yaml::decode($default_flextype_settings_content); } } -if (($content = Filesystem::read($custom_flextype_settings_file_path)) === false) { +// Create flextype custom settings file +! Filesystem::has($custom_flextype_settings_file_path) and Filesystem::write($custom_flextype_settings_file_path, $default_flextype_settings_content); + +if (($custom_flextype_settings_content = Filesystem::read($custom_flextype_settings_file_path)) === false) { throw new RuntimeException('Load file: ' . $custom_flextype_settings_file_path . ' - failed!'); } else { - if (trim($content) === '') { + if (trim($custom_flextype_settings_content) === '') { $custom_flextype_settings = []; } else { - $custom_flextype_settings = Yaml::decode($content); + $custom_flextype_settings = Yaml::decode($custom_flextype_settings_content); } }