Skip to content

Commit

Permalink
Fix unrelease regression - malformed MapField without skipColumnHeaders
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 9, 2022
1 parent 8720f08 commit 00a279f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
8 changes: 4 additions & 4 deletions CRM/Import/DataSource/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function buildQuickForm(&$form) {
* @throws \CRM_Core_Exception
*/
public function initialize(): void {
$result = self::_CsvToTable(
$result = $this->csvToTable(
$this->getSubmittedValue('uploadFile')['name'],
$this->getSubmittedValue('skipColumnHeader'),
$this->getSubmittedValue('fieldSeparator') ?? ','
Expand All @@ -83,7 +83,7 @@ public function initialize(): void {

$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'],
]);
}
Expand All @@ -102,7 +102,7 @@ public function initialize(): void {
* name of the created table
* @throws \CRM_Core_Exception
*/
private static function _CsvToTable(
private function csvToTable(
$file,
$headers = FALSE,
$fieldSeparator = ','
Expand All @@ -124,7 +124,7 @@ private static function _CsvToTable(
}

$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.
Expand Down
1 change: 1 addition & 0 deletions CRM/Import/Forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ protected function assignMapFieldVariables(): void {
$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);
Expand Down
4 changes: 2 additions & 2 deletions templates/CRM/Import/Form/MapTableCommon.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
26 changes: 1 addition & 25 deletions templates/CRM/Member/Import/Form/MapField.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"}

0 comments on commit 00a279f

Please sign in to comment.