Fix column names option for CSV Export
Previously work was done to enable column names in CSV exports by default. This change actually ended up overwriting the column name value so that column names were included in all exports regardless of whether or not the property was disabled. This commit changes the default for column names to enabled as the original change intended, and removes the property overwrite. Signed-off-by: Scott McGowan mcgowanscott16@gmail.com
This commit is contained in:
parent
efae3a98e0
commit
6fc1401ee2
@ -1011,7 +1011,7 @@ final class Export
|
||||
private function setCsvColumns(array $export): bool
|
||||
{
|
||||
if (! isset($export['csv_columns'])) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return (bool) $export['csv_columns'];
|
||||
|
||||
@ -105,10 +105,6 @@ class ExportCsv extends ExportPlugin
|
||||
public function exportHeader(): bool
|
||||
{
|
||||
global $what, $csv_terminated, $csv_separator, $csv_enclosed, $csv_escaped;
|
||||
//Enable columns names by default for CSV
|
||||
if ($what === 'csv') {
|
||||
$GLOBALS['csv_columns'] = 'yes';
|
||||
}
|
||||
|
||||
// Here we just prepare some values for export
|
||||
if ($what === 'excel') {
|
||||
@ -129,7 +125,7 @@ class ExportCsv extends ExportPlugin
|
||||
$csv_enclosed = '"';
|
||||
$csv_escaped = '"';
|
||||
if (isset($GLOBALS['excel_columns'])) {
|
||||
$GLOBALS['csv_columns'] = 'yes';
|
||||
$GLOBALS['csv_columns'] = true;
|
||||
}
|
||||
} else {
|
||||
if (empty($csv_terminated) || mb_strtolower($csv_terminated) === 'auto') {
|
||||
@ -226,7 +222,7 @@ class ExportCsv extends ExportPlugin
|
||||
$fields_cnt = $result->numFields();
|
||||
|
||||
// If required, get fields name at the first line
|
||||
if (isset($GLOBALS['csv_columns'])) {
|
||||
if (isset($GLOBALS['csv_columns']) && $GLOBALS['csv_columns']) {
|
||||
$schema_insert = '';
|
||||
foreach ($result->getFieldNames() as $col_as) {
|
||||
if (! empty($aliases[$db]['tables'][$table]['columns'][$col_as])) {
|
||||
|
||||
@ -1677,7 +1677,7 @@ $cfg['Export']['texytext_null'] = 'NULL';
|
||||
/**
|
||||
* @global boolean $cfg['Export']['csv_columns']
|
||||
*/
|
||||
$cfg['Export']['csv_columns'] = false;
|
||||
$cfg['Export']['csv_columns'] = true;
|
||||
|
||||
/**
|
||||
* @global string $cfg['Export']['csv_structure_or_data']
|
||||
|
||||
@ -48,7 +48,7 @@ class ExportTest extends TestCase
|
||||
'texytext_structure_or_data' => 'structure_and_data',
|
||||
'texytext_columns' => false,
|
||||
'texytext_null' => 'NULL',
|
||||
'csv_columns' => false,
|
||||
'csv_columns' => true,
|
||||
'csv_structure_or_data' => 'data',
|
||||
'csv_null' => 'NULL',
|
||||
'csv_separator' => ',',
|
||||
@ -193,7 +193,7 @@ class ExportTest extends TestCase
|
||||
['texytext_structure_or_data', null, 'structure_and_data'],
|
||||
['texytext_columns', null, false],
|
||||
['texytext_null', null, 'NULL'],
|
||||
['csv_columns', null, false],
|
||||
['csv_columns', null, true],
|
||||
['csv_structure_or_data', null, 'data'],
|
||||
['csv_null', null, 'NULL'],
|
||||
['csv_separator', null, ','],
|
||||
@ -305,7 +305,7 @@ class ExportTest extends TestCase
|
||||
['texytext_structure_or_data', 'structure', 'structure'],
|
||||
['texytext_columns', false, false],
|
||||
['texytext_null', 'test', 'test'],
|
||||
['csv_columns', false, false],
|
||||
['csv_columns', true, true],
|
||||
['csv_structure_or_data', 'structure', 'structure'],
|
||||
['csv_null', 'test', 'test'],
|
||||
['csv_separator', 'test', 'test'],
|
||||
@ -409,7 +409,7 @@ class ExportTest extends TestCase
|
||||
['htmlword_columns', true, true],
|
||||
['texytext_structure_or_data', 'data', 'data'],
|
||||
['texytext_columns', true, true],
|
||||
['csv_columns', true, true],
|
||||
['csv_columns', false, false],
|
||||
['csv_structure_or_data', 'data', 'data'],
|
||||
['csv_removeCRLF', true, true],
|
||||
['excel_columns', false, false],
|
||||
|
||||
@ -233,13 +233,13 @@ class ExportCsvTest extends AbstractTestCase
|
||||
|
||||
$this->assertEquals('"', $GLOBALS['csv_escaped']);
|
||||
|
||||
$this->assertEquals('yes', $GLOBALS['csv_columns']);
|
||||
$this->assertEquals(true, $GLOBALS['csv_columns']);
|
||||
|
||||
// case 2
|
||||
|
||||
$GLOBALS['excel_edition'] = 'mac_excel2003';
|
||||
unset($GLOBALS['excel_columns']);
|
||||
$GLOBALS['csv_columns'] = 'no';
|
||||
$GLOBALS['csv_columns'] = false;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->object->exportHeader()
|
||||
@ -253,7 +253,7 @@ class ExportCsvTest extends AbstractTestCase
|
||||
|
||||
$this->assertEquals('"', $GLOBALS['csv_escaped']);
|
||||
|
||||
$this->assertEquals('no', $GLOBALS['csv_columns']);
|
||||
$this->assertEquals(false, $GLOBALS['csv_columns']);
|
||||
|
||||
// case 3
|
||||
|
||||
@ -271,7 +271,7 @@ class ExportCsvTest extends AbstractTestCase
|
||||
|
||||
$this->assertEquals('"', $GLOBALS['csv_escaped']);
|
||||
|
||||
$this->assertEquals('no', $GLOBALS['csv_columns']);
|
||||
$this->assertEquals(false, $GLOBALS['csv_columns']);
|
||||
|
||||
// case 4
|
||||
|
||||
@ -353,7 +353,7 @@ class ExportCsvTest extends AbstractTestCase
|
||||
public function testExportData(): void
|
||||
{
|
||||
// case 1
|
||||
$GLOBALS['csv_columns'] = 'yes';
|
||||
$GLOBALS['csv_columns'] = true;
|
||||
$GLOBALS['csv_terminated'] = ';';
|
||||
|
||||
$GLOBALS['output_kanji_conversion'] = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user