Merge pull request #23227 from eileenmcnaughton/inbetween_4
[civicrm-core.git] / CRM / Custom / Import / Parser.php
index 0ee0ccf2e06286347aef673b9a7c1b0fa13f30db..084937081f37a75786ef2525e7e9bb376946620e 100644 (file)
@@ -14,7 +14,7 @@
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
-abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
+abstract class CRM_Custom_Import_Parser extends CRM_Import_Parser {
 
   protected $_fileName;
 
@@ -58,8 +58,8 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
    */
   public function run(
     $fileName,
-    $separator = ',',
-    &$mapper,
+    $separator,
+    $mapper,
     $skipColumnHeader = FALSE,
     $mode = self::MODE_PREVIEW,
     $contactType = self::CONTACT_INDIVIDUAL,
@@ -167,7 +167,7 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
       if ($returnCode & self::WARNING) {
         $this->_warningCount++;
         if ($this->_warningCount < $this->_maxWarningCount) {
-          $this->_warningCount[] = $line;
+          $this->_warnings[] = $this->_lineCount;
         }
       }
 
@@ -192,10 +192,6 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
       }
 
       if ($returnCode & self::DUPLICATE) {
-        if ($returnCode & self::MULTIPLE_DUPE) {
-          /* TODO: multi-dupes should be counted apart from singles
-           * on non-skip action */
-        }
         $this->_duplicateCount++;
         $recordNumber = $this->_lineCount;
         if ($this->_haveColumnHeader) {
@@ -238,7 +234,7 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
           ts('Reason'),
         ], $customHeaders);
         $this->_errorFileName = self::errorFileName(self::ERROR);
-        self::exportCSV($this->_errorFileName, $headers, $this->_errors);
+        CRM_Contact_Import_Parser_Contact::exportCSV($this->_errorFileName, $headers, $this->_errors);
       }
       if ($this->_conflictCount) {
         $headers = array_merge([
@@ -246,7 +242,7 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
           ts('Reason'),
         ], $customHeaders);
         $this->_conflictFileName = self::errorFileName(self::CONFLICT);
-        self::exportCSV($this->_conflictFileName, $headers, $this->_conflicts);
+        CRM_Contact_Import_Parser_Contact::exportCSV($this->_conflictFileName, $headers, $this->_conflicts);
       }
       if ($this->_duplicateCount) {
         $headers = array_merge([
@@ -255,7 +251,7 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
         ], $customHeaders);
 
         $this->_duplicateFileName = self::errorFileName(self::DUPLICATE);
-        self::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates);
+        CRM_Contact_Import_Parser_Contact::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates);
       }
     }
     return $this->fini();
@@ -356,4 +352,23 @@ abstract class CRM_Custom_Import_Parser extends CRM_Contact_Import_Parser {
     }
   }
 
+  /**
+   * @param string $name
+   * @param $title
+   * @param int $type
+   * @param string $headerPattern
+   * @param string $dataPattern
+   * @param bool $hasLocationType
+   */
+  public function addField(
+    $name, $title, $type = CRM_Utils_Type::T_INT,
+    $headerPattern = '//', $dataPattern = '//',
+    $hasLocationType = FALSE
+  ) {
+    $this->_fields[$name] = new CRM_Custom_Import_Field($name, $title, $type, $headerPattern, $dataPattern, $hasLocationType);
+    if (empty($name)) {
+      $this->_fields['doNotImport'] = new CRM_Custom_Import_Field($name, $title, $type, $headerPattern, $dataPattern, $hasLocationType);
+    }
+  }
+
 }