Merge pull request #23744 from eileenmcnaughton/import_csv
authorEileen McNaughton <emcnaughton@wikimedia.org>
Fri, 10 Jun 2022 02:59:43 +0000 (14:59 +1200)
committerGitHub <noreply@github.com>
Fri, 10 Jun 2022 02:59:43 +0000 (14:59 +1200)
Fix unrelease regression - malformed MapField without skipColumnHeaders

CRM/Import/DataSource/CSV.php
CRM/Import/Form/Preview.php
CRM/Import/Forms.php
templates/CRM/Import/Form/MapTableCommon.tpl
templates/CRM/Member/Import/Form/MapField.tpl

index 79e68a0d7ff21af016d3f4153316d18906047766..f084d65c73976f070c7573d2493a608ed4d572ee 100644 (file)
@@ -74,7 +74,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
    * @throws \CRM_Core_Exception
    */
   public function initialize(): void {
-    $result = self::_CsvToTable(
+    $result = $this->csvToTable(
       $this->getSubmittedValue('uploadFile')['name'],
       $this->getSubmittedValue('skipColumnHeader'),
       $this->getSubmittedValue('fieldSeparator') ?? ','
@@ -83,7 +83,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
 
     $this->updateUserJobMetadata('DataSource', [
       'table_name' => $result['import_table_name'],
-      'column_headers' => $this->getSubmittedValue('skipColumnHeader') ? $result['column_headers'] : [],
+      'column_headers' => $result['column_headers'],
       'number_of_columns' => $result['number_of_columns'],
     ]);
   }
@@ -102,7 +102,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
    *   name of the created table
    * @throws \CRM_Core_Exception
    */
-  private static function _CsvToTable(
+  private function csvToTable(
     $file,
     $headers = FALSE,
     $fieldSeparator = ','
@@ -124,7 +124,7 @@ class CRM_Import_DataSource_CSV extends CRM_Import_DataSource {
     }
 
     $firstrow = fgetcsv($fd, 0, $fieldSeparator);
-
+    $result['column_headers'] = array_fill(0, count($firstrow), '');
     // create the column names from the CSV header or as col_0, col_1, etc.
     if ($headers) {
       //need to get original headers.
index 24aa09977ce7b8ca58f6b20eb5d0ec9d5db55a45..92959b83577d775d03b8389e93201846211e6c8a 100644 (file)
@@ -113,6 +113,7 @@ abstract class CRM_Import_Form_Preview extends CRM_Import_Forms {
     }
     $this->assign('savedMappingName', $mappingId ? $mapDAO->name : NULL);
     $this->assign('skipColumnHeader', $this->getSubmittedValue('skipColumnHeader'));
+    $this->assign('showColumnNames', $this->getSubmittedValue('skipColumnHeader'));
     // rowDisplayCount is deprecated - it used to be used with {section} but we have nearly gotten rid of it.
     $this->assign('rowDisplayCount', $this->getSubmittedValue('skipColumnHeader') ? 3 : 2);
   }
index 0b37ea76b221e8e4ffae146d797c176a319a77a0..f07a203297e3c32b456dd77d5e07ec25e850b718 100644 (file)
@@ -597,6 +597,7 @@ class CRM_Import_Forms extends CRM_Core_Form {
     $this->_columnNames = $this->getColumnHeaders();
     $this->_dataValues = array_values($this->getDataRows([], 2));
     $this->assign('columnNames', $this->getColumnHeaders());
+    $this->assign('showColumnNames', $this->getSubmittedValue('skipColumnHeader'));
     $this->assign('highlightedFields', $this->getHighlightedFields());
     $this->assign('columnCount', $this->_columnCount);
     $this->assign('dataValues', $this->_dataValues);
index 83fa1fcc8e48279a3a490b27f134ed37b99b44ed..8be853aa87fc1d70a18bd4840b685906765885ae 100644 (file)
@@ -10,7 +10,7 @@
 
             {* Header row - has column for column names if they have been supplied *}
           <tr class="columnheader">
-              {if $columnNames}
+              {if $showColumnNames}
                 <td>{ts}Column Names{/ts}</td>
               {/if}
               {foreach from=$dataValues item=row key=index}
@@ -23,7 +23,7 @@
             {*Loop on columns parsed from the import data rows*}
             {foreach from=$mapper key=i item=mapperField}
               <tr style="border: 1px solid #DDDDDD;">
-                  {if array_key_exists($i, $columnNames)}
+                  {if $showColumnNames}
                     <td class="even-row labels">{$columnNames[$i]}</td>
                   {/if}
                   {foreach from=$dataValues item=row key=index}
index 287e40ba0dfe095f5308ab3b50c1ca998ef5254e..8564c9b70f2075dbe84c68484e7c26120d15acc5 100644 (file)
@@ -7,28 +7,4 @@
  | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
 *}
-<div class="crm-block crm-form-block crm-member-import-mapfield-form-block">
-{* WizardHeader.tpl provides visual display of steps thru the wizard as well as title for current step *}
-{include file="CRM/common/WizardHeader.tpl"}
-<div class="help">
-    <p>{ts}Review the values shown below from the first 2 rows of your import file and select the matching CiviCRM database fields from the drop-down lists in the right-hand column. Select '- do not import -' for any columns in the import file that you want ignored.{/ts}</p>
-    <p>{ts}If you think you may be importing additional data from the same data source, check 'Save this field mapping' at the bottom of the page before continuing. The saved mapping can then be easily reused the next time data is imported.{/ts}</p>
-</div>
-<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
-{* Membership Import Wizard - Step 2 (map incoming data fields) *}
-{* @var $form Contains the array for the form elements and other form associated information assigned to the template by the controller *}
-
- {* Table for mapping data to CRM fields *}
- {include file="CRM/Import/Form/MapTableCommon.tpl" mapper=$form.mapper}
-
-<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
-</div>
- {$initHideBoxes|smarty:nodefaults}
-{literal}
-<script type="text/javascript" >
-if ( document.getElementsByName("saveMapping")[0].checked ) {
-    document.getElementsByName("updateMapping")[0].checked = true;
-    document.getElementsByName("saveMapping")[0].checked = false;
-}
-</script>
-{/literal}
+{include file="CRM/Import/Form/MapField.tpl"}