/**
  * Using the $old_db_to_new_db_mapping array, replaces all the temporary IDs
  * with their mapped real IDs. Eg, if importing from site A to B, the mapping
  * file may indicate that the ID "my_event_id" maps to an actual event ID of 123.
  * So this function searches for any event temp Ids called "my_event_id" and
  * replaces them with 123.
  * Also, if there is no temp ID for the INT foreign keys from another database,
  * replaces them with 0 or the field's default.
  * @param type $model_object_data
  * @param EEM_Base $model
  * @param type $old_db_to_new_db_mapping
  * @param boolean $export_from_site_a_to_b
  * @return array updated model object data with temp IDs removed
  */
 protected function _replace_temp_ids_with_mappings($model_object_data, $model, $old_db_to_new_db_mapping, $export_from_site_a_to_b)
 {
     //if this model object's primary key is in the mapping, replace it
     if ($model->has_primary_key_field() && $model->get_primary_key_field()->is_auto_increment() && isset($old_db_to_new_db_mapping[$model->get_this_model_name()]) && isset($old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]])) {
         $model_object_data[$model->primary_key_name()] = $old_db_to_new_db_mapping[$model->get_this_model_name()][$model_object_data[$model->primary_key_name()]];
     }
     try {
         $model_name_field = $model->get_field_containing_related_model_name();
         $models_pointed_to_by_model_name_field = $model_name_field->get_model_names_pointed_to();
     } catch (EE_Error $e) {
         $model_name_field = NULL;
         $models_pointed_to_by_model_name_field = array();
     }
     foreach ($model->field_settings(true) as $field_obj) {
         if ($field_obj instanceof EE_Foreign_Key_Int_Field) {
             $models_pointed_to = $field_obj->get_model_names_pointed_to();
             $found_a_mapping = false;
             foreach ($models_pointed_to as $model_pointed_to_by_fk) {
                 if ($model_name_field) {
                     $value_of_model_name_field = $model_object_data[$model_name_field->get_name()];
                     if ($value_of_model_name_field == $model_pointed_to_by_fk) {
                         $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in($model_object_data[$field_obj->get_name()], $model_pointed_to_by_fk, $old_db_to_new_db_mapping, $export_from_site_a_to_b);
                         $found_a_mapping = true;
                         break;
                     }
                 } else {
                     $model_object_data[$field_obj->get_name()] = $this->_find_mapping_in($model_object_data[$field_obj->get_name()], $model_pointed_to_by_fk, $old_db_to_new_db_mapping, $export_from_site_a_to_b);
                     $found_a_mapping = true;
                 }
                 //once we've found a mapping for this field no need to continue
                 if ($found_a_mapping) {
                     break;
                 }
             }
         } else {
             //it's a string foreign key (which we leave alone, because those are things
             //like country names, which we'd really rather not make 2 USAs etc (we'd actually
             //prefer to just update one)
             //or it's just a regular value that ought to be replaced
         }
     }
     //
     if ($model instanceof EEM_Term_Taxonomy) {
         $model_object_data = $this->_handle_split_term_ids($model_object_data);
     }
     return $model_object_data;
 }