static function GetPreviousInstance($sDir)
 {
     $bFound = false;
     $sSourceDir = '';
     $sSourceEnvironement = '';
     $sConfigFile = '';
     $aResult = array('found' => false);
     if (file_exists($sDir . '/config-itop.php')) {
         $sSourceDir = $sDir;
         $sSourceEnvironment = '';
         $sConfigFile = $sDir . '/config-itop.php';
         $aResult['found'] = true;
     } else {
         if (file_exists($sDir . '/conf/production/config-itop.php')) {
             $sSourceDir = $sDir;
             $sSourceEnvironment = 'production';
             $sConfigFile = $sDir . '/conf/production/config-itop.php';
             $aResult['found'] = true;
         }
     }
     if ($aResult['found']) {
         $oPrevConf = new Config($sConfigFile);
         $aResult = array('found' => true, 'source_dir' => $sSourceDir, 'source_environment' => $sSourceEnvironment, 'configuration_file' => $sConfigFile, 'db_server' => $oPrevConf->GetDBHost(), 'db_user' => $oPrevConf->GetDBUser(), 'db_pwd' => $oPrevConf->GetDBPwd(), 'db_name' => $oPrevConf->GetDBName(), 'db_prefix' => $oPrevConf->GetDBSubname());
     }
     return $aResult;
 }
 public function GetApplicationVersion(Config $oConfig)
 {
     $aResult = false;
     try {
         require_once APPROOT . '/core/cmdbsource.class.inc.php';
         CMDBSource::Init($oConfig->GetDBHost(), $oConfig->GetDBUser(), $oConfig->GetDBPwd(), $oConfig->GetDBName());
         CMDBSource::SetCharacterSet($oConfig->GetDBCharacterSet(), $oConfig->GetDBCollation());
         $sSQLQuery = "SELECT * FROM " . $oConfig->GetDBSubname() . "priv_module_install";
         $aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);
     } catch (MySQLException $e) {
         // No database or erroneous information
         $this->log_error('Can not connect to the database: host: ' . $oConfig->GetDBHost() . ', user:'******', pwd:' . $oConfig->GetDBPwd() . ', db name:' . $oConfig->GetDBName());
         $this->log_error('Exception ' . $e->getMessage());
         return false;
     }
     // Scan the list of installed modules to get the version of the 'ROOT' module which holds the main application version
     foreach ($aSelectInstall as $aInstall) {
         $sModuleVersion = $aInstall['version'];
         if ($sModuleVersion == '') {
             // Though the version cannot be empty in iTop 2.0, it used to be possible
             // therefore we have to put something here or the module will not be considered
             // as being installed
             $sModuleVersion = '0.0.0';
         }
         if ($aInstall['parent_id'] == 0) {
             if ($aInstall['name'] == DATAMODEL_MODULE) {
                 $aResult['datamodel_version'] = $sModuleVersion;
                 $aComments = json_decode($aInstall['comment'], true);
                 if (is_array($aComments)) {
                     $aResult = array_merge($aResult, $aComments);
                 }
             } else {
                 $aResult['product_name'] = $aInstall['name'];
                 $aResult['product_version'] = $sModuleVersion;
             }
         }
     }
     if (!array_key_exists('datamodel_version', $aResult)) {
         // Versions prior to 2.0 did not record the version of the datamodel
         // so assume that the datamodel version is equal to the application version
         $aResult['datamodel_version'] = $aResult['product_version'];
     }
     $this->log_info("GetApplicationVersion returns: product_name: " . $aResult['product_name'] . ', product_version: ' . $aResult['product_version']);
     return $aResult;
 }