icecoder/ICEcoder

migrate config from previous versions

Opened this issue · 4 comments

first let me thank your for the recent 8.x release.

we would like to update our redaxo open source cms integration to the latest ice-coder version.
in the past we had a php based configuration file, which we used to integrate the 2 code-bases.

after installing icecoder 8.x it looks like icecoder is using some 'serialized' php commented string format, which feels hard to read/write/change.
is there some tool/documentation on how I can/should configure things, which were configured in a config_settings.php file, like

// ICEcoder redaxo settings
$ICEcoderSettings = array(
    "versionNo"		=> "7.0",
    "codeMirrorDir"		=> "CodeMirror",
    "docRoot"		=> $_SERVER['DOCUMENT_ROOT'],	// Set absolute path of another location if needed
    "demoMode"		=> false,
    "devMode"		=> false,
    "fileDirResOutput"	=> "none",			// Can be none, raw, object, both (all but 'none' output to console)
    "loginRequired"		=> false,
    "password" => bin2hex(openssl_random_pseudo_bytes(4)),
    "multiUser"		=> false,
    "languageBase"		=> "english.php",
    "lineEnding"		=> "\n",
    "newDirPerms"		=> 755,
    "newFilePerms"		=> 644,
    "enableRegistration"	=> true
);

I wasn't able to find documentation on the website on how configuration is meant to be done in the 8.x series

thanks for your feedback in advance.

You're right - there's no documentation at present and it'd be good for us to create some.

In ICEcoder 8 we removed the very fragile settings system which relied on string manipulation of the array structure & data in files and replaced it with a more robust class based system and arrays instead saved as serialized data.

Now there's class methods available to get, set and update global settings and any user config settings to make life easier.

This is a simple example showing requiring the class, outputting the global settings, updating the loginRequired bool and re-outputting the settings to prove it's updated...

<?php
// Load ICEcoders Settings class from wherever you are and set as $icSettings
require "some-dir/more/again/one-more/ICEcoder/classes/Settings.php";
$icSettings = new \ICEcoder\Settings();

// Load and print out the global settings
$ICEcoderSettings = $icSettings->getConfigGlobalSettings();
print_r($ICEcoderSettings);

// Update the loginRequired setting to false
$icSettings->updateConfigGlobalSettings(
    ["loginRequired" => false]
);

// Re-load and print out the global settings to show it's changed
$ICEcoderSettings = $icSettings->getConfigGlobalSettings();
print_r($ICEcoderSettings);
?>

If you look in ICEcoder/classes/Settings.php you can see the class methods available, but a summary for you here...

General info

getDataDirDetails() - return details about the ICEcoder/data dir

Global config: Get/set/update

getConfigGlobalTemplate() - return the serialized global config template
getConfigGlobalFileDetails() - return details about the global config file
getConfigGlobalSettings() - return the global settings
setConfigGlobalSettings($settings) - set your array as the global settings, returns bool of success
updateConfigGlobalSettings($array) - update your array ontop the global settings (as above example), returns bool of success

Users config: Get/set/update

getConfigUsersTemplate() - return the serialized user config template
getConfigUsersFileDetails($fileName) - return details about the users config file
getConfigUsersSettings($fileName) - return the users config file settings
setConfigUsersSettings($fileName, $settings) - set your array as the users config file settings, returns bool of success
updateConfigUsersSettings($fileName, $array) - update your array ontop the users config file settings, returns bool of success

There's also updateConfigUsersCreateDate($fileName),createIPSettingsFileIfNotExist() and serializedFileData($do, $fullPath, $output=null) which you probably don't need and would recommend avoiding, mainly internal functions for ICEcoder to use.

You probably just want to use getConfigGlobalSettings() and updateConfigGlobalSettings($array) as per my previous example. Just ensure you're setting expected values and types else you may get bizarre results. If in doubt about types, get the settings first and then you can find out the types in the array before you change it and then update.

Oh wow, thx for this exhaustive answer. I will check whether this works for us <3

NP, wanted to write something comprehensive anyway to also go into docs.