New emoncms settings format - help testing needed

I ran into a different issue when playing with a completely different docker system. The issue was the environment stuff was not available from within the container. Are the Env Vars available within the container? Just a thought - don’t really understand dockers TBH :slight_smile:

You could put some debug statements into the process_settings.php file to check it is actually doing something.

Final thought, you don’t have a settings.php file do you…

Hi!
Yes, the env vars are in the container. They are listed with correct values when attaching to container and running the env command.
No, no settings.php

I have little to no clue about PHP. But I see the function concatinates string to some $error_out variable so I did the same. Where would that be displayed? Can’t see it in /var/log/emoncms/emoncms.log

   function ini_check_envvars($config) {
    global $error_out;
    $error_out .= "I'm in ini_check_envvars";
    foreach ($config as $section => $options) {
    $error_out .= "Looping config";
        foreach ($options as $key => $value) {
            // Find {{ }} vars and replace what's within them with the
            // named environment var
    $error_out .= "check options";
            if (strpos($value, '{{') !== false && strpos($value, '}}') !== false) {
                preg_match_all( '/{{([^}]*)}}/', $value, $matches);
                foreach ($matches[1] as $match) {
    $error_out .= "Matched {{ }} and found ${match}";
                    if (!isset($_ENV[$match])) {
                        $error_out .= "<p>Error: environment var '${match}' not defined in config section [${section}], setting '${key}'</p>";
                    } else {
                        $newval = str_replace('{{'.$match.'}}', $_ENV[$match], $value);

                        // Convert booleans from strings
                        if ($newval === 'true') {

That is why. If a settings.php exists it gets processed and not the settings.ini.

There is no settings.php

But I looked more closely at the process_settings.php
This line is interesting…

Un-commenting that line however gives loads of errors.

**Warning** : Invalid argument supplied for foreach() in  **/var/www/emoncms/process_settings.php**  on line  **93**

**Warning** : Invalid argument supplied for foreach() in  **/var/www/emoncms/process_settings.php**  on line  **93**

**Warning** : Invalid argument supplied for foreach() in  **/var/www/emoncms/process_settings.php**  on line  **93**

**Warning** : Invalid argument supplied for foreach() in  **/var/www/emoncms/process_settings.php**  on line  **93**

**Warning** : strpos() expects parameter 1 to be string, array given in  **/var/www/emoncms/process_settings.php**  on line  **96**

**Warning** : strpos() expects parameter 1 to be string, array given in  **/var/www/emoncms/process_settings.php**  on line  **96**

**Warning** : preg_match_all() expects parameter 2 to be string, array given in  **/var/www/emoncms/process_settings.php**  on line  **97**

@TrystanLea seems the envars part is commented out and never used ATM.

[edit]
I have added an Issue with a potential solution.

So it is! Hmm not sure why that is.

@anna_carboncoop is there any chance you could help with this? Im not sure that I know enough about the env vars to get this right.

Have a look at my proposed solution. Pretty sure it will work if done from within the merge.

I think the original does not work because not everything is in an array - hence the check in the merge function.

1 Like

Thanks @borpin

1 Like

I don’t really remember writing the code at this point :slight_smile: But I’ve posted a simplified version of the function along the lines borpin suggested.

2 Likes

Sounds great! Just ping me if there is something to test and I’ll try it out.