/**
  * Create a new FileFormatConverter, using old or new converters.
  * This function looks for converters in the 'converters' table in the db.
  * $converterVersion can be "legacy", "latest", or something like "1.0.0".
  * In the first case legacy converters will be used; in the second case,
  * the latest version of new converters will be used; in the third case,
  * this function will look for the converters with the provided version,
  * and if not found will use the converters with higher but closest version.
  * Version check is done on the conversion_api_version field of the
  * converters db table; new converters are expected to have a value like
  * "open 1.0.0".
  */
 public function __construct($converterVersion = null)
 {
     $this->converterVersion = $converterVersion;
     $this->opt['httpheader'] = array("Content-Type:multipart/form-data;charset=UTF-8");
     $this->lang_handler = Langs_Languages::getInstance();
     $this->conversionObject = new ArrayObject(array('ip_machine' => null, 'ip_client' => null, 'path_name' => null, 'file_name' => null, 'path_backup' => null, 'file_size' => 0, 'direction' => null, 'error_message' => null, 'src_lang' => null, 'trg_lang' => null, 'status' => 'ok', 'conversion_time' => 0), ArrayObject::ARRAY_AS_PROPS);
     // Get converters instances list from database,
     $db = Database::obtain();
     // The base query to obtain the converters
     $baseQuery = 'SELECT ip_converter, cpu_weight, ip_storage, segmentation_rule' . ' FROM converters' . ' WHERE status_active = 1 AND status_offline = 0';
     // Complete the $baseQuery according to the converter's version
     if ($this->converterVersion == Constants_ConvertersVersions::LEGACY) {
         // Retrieve only old converters
         $query = $baseQuery . (INIT::$USE_ONLY_STABLE_CONVERTERS ? ' AND stable = 1' : '') . ' AND conversion_api_version NOT LIKE "open %"';
     } else {
         // Here we use new converters
         if ($this->converterVersion == Constants_ConvertersVersions::LATEST) {
             // Get the converters with the latest version
             $query = $baseQuery . ' AND conversion_api_version = (' . 'SELECT MAX(conversion_api_version)' . ' FROM converters' . ' WHERE conversion_api_version LIKE "open %"' . (INIT::$USE_ONLY_STABLE_CONVERTERS ? ' AND stable = 1' : '') . ' AND status_active = 1 AND status_offline = 0' . ')';
         } else {
             $closest_conversion_api_version = self::getClosestConversionApiVersion($this->converterVersion);
             $query = $baseQuery . (INIT::$USE_ONLY_STABLE_CONVERTERS ? ' AND stable = 1' : '') . ' AND conversion_api_version = "' . $closest_conversion_api_version . '"';
         }
     }
     $converters = $db->fetch_array($query);
     // SUUUPER ugly, those variables should not be static at all! No way!
     // But now the class works around these 3 static variables, and a
     // refactoring is too risky. Enter this patch: I empty these 3 vars
     // every time I create a new FileFormatConverter to be sure that new
     // converters never mix with old converters
     self::$converters = array();
     self::$Storage_Lookup_IP_Map = array();
     self::$converter2segmRule = array();
     foreach ($converters as $converter_storage) {
         self::$converters[$converter_storage['ip_converter']] = $converter_storage['cpu_weight'];
         self::$Storage_Lookup_IP_Map[$converter_storage['ip_converter']] = $converter_storage['ip_storage'];
         self::$converter2segmRule[$converter_storage['ip_converter']] = $converter_storage['segmentation_rule'];
     }
     //        self::$converters = array('10.30.1.32' => 1);//for debugging purposes
     //        self::$Storage_Lookup_IP_Map = array('10.30.1.32' => '10.30.1.32');//for debugging purposes
     $this->storage_lookup_map = self::$Storage_Lookup_IP_Map;
 }