Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Medium Medium
    • Resolution: Unresolved
    • Affects Version/s: 4.1.3
    • Fix Version/s: None
    • Component/s: Caching
    • Labels:
      None

      Description

      Managing ini files on several environment can be tricky. It's easy to make mistake. Each time you want to push ini files from one environment to another, you need to check manually (with a quick diff for example) whether or not files are different.

      On a development server, you can use different database settings in site.ini. These settings are different on production server.

      We can bypass this by modifying the ini class and the config.php file.

      +++ Step 1 : Set an environment variable in your vhost

      You need to add in your vhost file the following code.

      SetEnv APPLICATION_ENV local
      

      +++ Step 2 : Get the value in config.php

      The value set in vhost files is set in a central file : config.php.

      defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'prod'));
      

      +++ Step 3 : Add ini file to parse

      eZ Publish finds all the ini file to parse when you use eZINI class or ezini template operator. The purpose of the modification is to add new additional files to parse after the basic ini file.
      Let's take an example. You ask a value in site.ini file. eZ Publish will find all the site.ini file in

      • settings/
      • settings/siteaccess/name/
      • settings/override/
      • extension/.../settings/
      • extension/.../settings/siteaccess/name/
      • extension/.../settings/override/

      The idea is to add a file to parse following this pattern name (with SetEnv APPLICATION_ENV local in vhost) :

        • site.ini.local.append.php **

      The file is added in the ini file to parse after the others which means it will override previous values.

      function findInputFiles( &$inputFiles, &$iniFile ) {
       
              if ( $this->RootDir !== false )
                  $iniFile = eZDir::path( array( $this->RootDir, $this->FileName ) );
              else
                  $iniFile = eZDir::path( array( $this->FileName ) );
       
              $inputFiles = array();
       
              if ( $this->FileName === 'override.ini' )
              {
                  eZExtension::prependExtensionSiteAccesses( false, $this, true, false, false );
              }
       
              if ( file_exists( $iniFile ) )
                  $inputFiles[] = $iniFile;
       
              // try the same file name with '.append.php' replace with '.append'
              if ( strpos($iniFile, '.append.php') !== false && preg_match('#^(.+.append).php$#i', $iniFile, $matches ) && file_exists( $matches[1] ) )
                  $inputFiles[] = $matches[1];
       
              if ( strpos($iniFile, '.php') === false && file_exists ( $iniFile . '.php' ) )
                  $inputFiles[] = $iniFile . '.php';
       
              if ( $this->DirectAccess )
              {
              	if ( file_exists ( $iniFile . '.append' ) )
                      $inputFiles[] = $iniFile . '.append';
       
                  if ( file_exists ( $iniFile . '.append.php' ) )
                      $inputFiles[] = $iniFile . '.append.php';
       
                  // HACK to manage different settings environment
                  if ( defined('APPLICATION_ENV') && APPLICATION_ENV != 'prod' && file_exists ( $iniFile . '.'.APPLICATION_ENV.'.append.php' ) ) {
                      $inputFiles[] = $iniFile . '.'.APPLICATION_ENV.'.append.php';
                  }
              }
              else
              {
              	
                  $overrideDirs = $this->overrideDirs();
                  $fileName = $this->FileName;
                  $rootDir = $this->RootDir;
                  foreach ( $overrideDirs as $overrideDirItem )
                  {
                      $overrideDir = $overrideDirItem[0];
                      $isGlobal = $overrideDirItem[1];
                      if ( $isGlobal )
                          $overrideFile = eZDir::path( array( $overrideDir, $fileName ) );
                       else
                          $overrideFile = eZDir::path( array( $rootDir, $overrideDir, $fileName ) );
       
                      if ( file_exists( $overrideFile . '.php' ) )
                      {
                          $inputFiles[] = $overrideFile . '.php';
                      }
       
                      if ( file_exists( $overrideFile ) )
                      {
                          $inputFiles[] = $overrideFile;
                      }
       
                      if ( file_exists( $overrideFile . '.append.php' ) )
                      {
                          $inputFiles[] = $overrideFile . '.append.php';
                      }
       
                      if ( file_exists( $overrideFile . '.append' ) )
                      {
                          $inputFiles[] = $overrideFile . '.append';
                      }
       
                      // HACK to manage different settings environment
                      if ( defined('APPLICATION_ENV') && APPLICATION_ENV != 'prod' && file_exists( $overrideFile . '.'.APPLICATION_ENV.'.append.php' ) )
                      {
                          $inputFiles[] = $overrideFile . '.'.APPLICATION_ENV.'.append.php';
                      }
       
                  }
              }
       
       
      }
      

        Issue Links

          Activity

          Hide
          Gaetano Giunta added a comment -

          or you can use a different set of siteaccesses for every environment....

          Show
          Gaetano Giunta added a comment - or you can use a different set of siteaccesses for every environment....
          Hide
          Jérémy Poulain added a comment -

          Sure we could.

          But using different siteaccess means you duplicate every ini file, for nothing...

          We only want to override some values.

          Show
          Jérémy Poulain added a comment - Sure we could. But using different siteaccess means you duplicate every ini file, for nothing... We only want to override some values.
          Hide
          Gaetano Giunta added a comment -

          Maybe you can use one extension that is only used to hold the per-environment settings, eg mySettingsExt.
          Then you can just change the list of active extensions in site.ini in override, and have 3 extensions where you put all of the different settings...

          Show
          Gaetano Giunta added a comment - Maybe you can use one extension that is only used to hold the per-environment settings, eg mySettingsExt. Then you can just change the list of active extensions in site.ini in override, and have 3 extensions where you put all of the different settings...
          Hide
          Jérémy Poulain added a comment -

          This could be a solution on a single instance. It could'nt be when you use many extensions with svn:externals.

          The settings of these extensions should remain in the extensions. Getting them out of the extension there used in would increase the complexity.

          Here we only propose to add an suffix after the short name of the ini.

          Let's guess that we use the ezsi extensions. In production mode, we use ESI whereas in the preproduction and local we use SSI. We would only have to create three files

          ezsi.ini.append.php
          ezsi.ini.preprod.append.php
          ezsi.ini.local.append.php

          All the ini sections and in values would be set ini ezsi.ini.append.php. We would only have to set the modified values ini the two others ini.

          Every ini are regrouped and you can easely use publication script like rsync to send your files.

          Show
          Jérémy Poulain added a comment - This could be a solution on a single instance. It could'nt be when you use many extensions with svn:externals. The settings of these extensions should remain in the extensions. Getting them out of the extension there used in would increase the complexity. Here we only propose to add an suffix after the short name of the ini. Let's guess that we use the ezsi extensions. In production mode, we use ESI whereas in the preproduction and local we use SSI. We would only have to create three files ezsi.ini.append.php ezsi.ini.preprod.append.php ezsi.ini.local.append.php All the ini sections and in values would be set ini ezsi.ini.append.php. We would only have to set the modified values ini the two others ini. Every ini are regrouped and you can easely use publication script like rsync to send your files.
          Hide
          Gaetano Giunta added a comment -

          This is a complex topic, that has been discussed already a lot, both in other issues here in the tracker and in the forums.

          I'd suggest to open a request in the community roadmap, and centralize there all the discussions.

          Pointers:

          • supporting multi-site installations (different databases and single databases)
          • reducing code complexity and limiting scanned files / directories
          • reordering precedence (having extension settings higher than siteaccess makes no sense)
          • adding a folder for common settings
          Show
          Gaetano Giunta added a comment - This is a complex topic, that has been discussed already a lot, both in other issues here in the tracker and in the forums. I'd suggest to open a request in the community roadmap, and centralize there all the discussions. Pointers: supporting multi-site installations (different databases and single databases) reducing code complexity and limiting scanned files / directories reordering precedence (having extension settings higher than siteaccess makes no sense) adding a folder for common settings
          Hide
          Eduardo Fernandes added a comment -

          Hey,

          Maybe it could be possible to define an array of environments. Something like:

          [EnvironmentSettings]
          DefaultEnvironment=production
          Environments=[]
          Environment[development]=1.1.1.1
          Environment[stage]=stage.hostname
          Environment[production]=production.hostname;1.1.1.2
           
          [DatabaseSettings_development]
          Server=localhost
           
          [DatabaseSettings_production]
          Server=1.1.1.3
          

          And eZ Publish could use the settings according to the current environment.

          Show
          Eduardo Fernandes added a comment - Hey, Maybe it could be possible to define an array of environments. Something like: [EnvironmentSettings] DefaultEnvironment=production Environments=[] Environment[development]=1.1.1.1 Environment[stage]=stage.hostname Environment[production]=production.hostname;1.1.1.2   [DatabaseSettings_development] Server=localhost   [DatabaseSettings_production] Server=1.1.1.3 And eZ Publish could use the settings according to the current environment.

            People

            • Assignee:
              unknown
              Reporter:
              Jérémy Poulain
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: