Merge pull request #11791 from civicrm/4.7.31-rc
[civicrm-core.git] / CRM / Utils / Migrate / Import.php
index 927f82385c6a4f5b502379043dc930ba7f13c171..8a9cf99e74f8d0bdd0fc8d4868afb9ead7cac9d1 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2016                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2016
+ * @copyright CiviCRM LLC (c) 2004-2018
  */
 class CRM_Utils_Migrate_Import {
   /**
@@ -48,7 +48,9 @@ class CRM_Utils_Migrate_Import {
   public function run($file) {
     // read xml file
     $dom = new DomDocument();
-    if (!$dom->load($file)) {
+    $xmlString = file_get_contents($file);
+    $load = $dom->loadXML($xmlString);
+    if (!$load) {
       throw new CRM_Core_Exception("Failed to parse XML file \"$file\"");
     }
     $dom->xinclude();
@@ -155,6 +157,10 @@ class CRM_Utils_Migrate_Import {
       foreach ($optionValuesXML->OptionValue as $optionValueXML) {
         $optionValue = new CRM_Core_DAO_OptionValue();
         $optionValue->option_group_id = $idMap['option_group'][(string ) $optionValueXML->option_group_name];
+        if (empty($optionValue->option_group_id)) {
+          //CRM-17410 check if option group already exist.
+          $optionValue->option_group_id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $optionValueXML->option_group_name, 'id', 'name');
+        }
         $this->copyData($optionValue, $optionValueXML, FALSE, 'label');
         if (!isset($optionValue->value)) {
           $sql = "