Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-16205

Manage ini with multi environment

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Medium Medium
    • None
    • 4.1.3
    • Caching
    • 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';
                      }
      
                  }
              }
      
      
      }
      

      Attachments

        Activity

          People

            unknown unknown
            8bc12bd8-4b86-4b97-8f96-13978c04c7fa@accounts.ibexa.co Jérémy Poulain
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: