Merge pull request #14706 from ixiam/dev-SmartyCompiled
[civicrm-core.git] / CRM / Contact / Import / Parser.php
index a98a4f2d3e7d33c03ab59b18dc583d2eca6965bd..c8cfc0a84f82e9ead67314306b95a1cc45a58957 100644 (file)
@@ -37,18 +37,20 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser {
   /**
    * Total number of lines in file
    *
-   * @var integer
+   * @var int
    */
   protected $_rowCount;
 
   /**
    * Running total number of un-matched Contacts.
+   *
    * @var int
    */
   protected $_unMatchCount;
 
   /**
-   * Array of unmatched lines
+   * Array of unmatched lines.
+   *
    * @var array
    */
   protected $_unMatch;
@@ -1314,20 +1316,7 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser {
       }
     }
 
-    if ($values['location_type_id'] === 'Primary') {
-      if (!empty($params['id'])) {
-        $primary = civicrm_api3('Address', 'get', [
-          'return' => 'location_type_id',
-          'contact_id' => $params['id'],
-          'is_primary' => 1,
-          'sequential' => 1
-        ]);
-      }
-      $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
-      $params['address'][$values['location_type_id']]['location_type_id'] = (isset($primary) && $primary['count']) ? $primary['values'][0]['location_type_id'] : $defaultLocationType->id;
-      $params['address'][$values['location_type_id']]['is_primary'] = 1;
-
-    }
+    $this->fillPrimary($params['address'][$values['location_type_id']], $values, 'address', CRM_Utils_Array::value('id', $params));
     return TRUE;
   }
 
@@ -1358,7 +1347,9 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser {
    *   Input values
    * @param string $entity
    *  - address, email, phone
-   * @param int|NULL $contactID
+   * @param int|null $contactID
+   *
+   * @throws \CiviCRM_API3_Exception
    */
   protected function fillPrimary(&$params, $values, $entity, $contactID) {
     if ($values['location_type_id'] === 'Primary') {
@@ -1367,7 +1358,7 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser {
           'return' => 'location_type_id',
           'contact_id' => $contactID,
           'is_primary' => 1,
-          'sequential' => 1
+          'sequential' => 1,
         ]);
       }
       $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();