Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(TB Export) fix csv exports twig definitions
Browse files Browse the repository at this point in the history
Change-Id: I5671fe7ec2ccfdd192612567a60a566474057d8b
Reviewed-on: http://gerrit.tine20.com/customers/18931
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
Reviewed-by: Paul Mehrer <p.mehrer@metaways.de>
  • Loading branch information
paulmhh committed Jan 25, 2021
1 parent 1fa6e14 commit 470d617
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
28 changes: 26 additions & 2 deletions tests/tine20/Addressbook/Export/CsvTest.php
Expand Up @@ -27,7 +27,8 @@ protected function _genericExportTest($_config)
'adr_one_street' => 'Montgomerie',
'n_given' => 'Paul',
'n_family' => 'test',
'email' => 'tmpPaul@test.de'
'email' => 'tmpPaul@test.de',
'tel_home' => '1234'
)));
Addressbook_Controller_Contact::getInstance()->create(new Addressbook_Model_Contact(array(
'adr_one_street' => 'Montgomerie',
Expand Down Expand Up @@ -76,4 +77,27 @@ public function testNewCsvExport()
fclose($fh);
}
}
}

public function testNewCsvTwigExport()
{
$fh = $this->_genericExportTest([
'definition' => __DIR__ . '/definitions/adb_csv_test_twig.xml',
]);
try {
rewind($fh);

$row = fgetcsv($fh, 0, "\t", '"');
static::assertTrue(is_array($row), 'could not read csv ');
static::assertEquals('Adam', $row[0]);
static::assertEquals('tmpadam@test.de', $row[1]);

$row = fgetcsv($fh, 0, "\t", '"');
static::assertTrue(is_array($row), 'could not read csv: ');
static::assertEquals('Paul', $row[0]);
static::assertEquals('tmppaul@test.de', $row[1]);
static::assertSame('0000001234', $row[2]);
} finally {
fclose($fh);
}
}
}
29 changes: 29 additions & 0 deletions tests/tine20/Addressbook/Export/definitions/adb_csv_test_twig.xml
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<model>Addressbook_Model_Contact</model>
<name>adb_csv_test</name>
<type>export</type>
<plugin>Tinebase_Export_Csv</plugin>
<sort>
<field>n_given</field>
<direction>ASC</direction>
</sort>
<header>0</header>
<delimiter>&#x09;</delimiter>
<enclosure>"</enclosure>
<columns>
<column>
<identifier>n_given</identifier>
<header>Given Name</header>
</column>
<column>
<identifier>email</identifier>
<header>Email address</header>
</column>
<column>
<identifier>tel_home</identifier>
<header>telefone home</header>
<twig>{{ '%010d'|format(record.tel_home) }}</twig>
</column>
</columns>
</config>
4 changes: 3 additions & 1 deletion tine20/Tinebase/Export/Abstract.php
Expand Up @@ -771,7 +771,7 @@ public function _getTwigSource()
if (true !== $this->_hasTemplate && $this->_config->columns) {
foreach (Tinebase_Helper_ZendConfig::getChildrenConfigs($this->_config->columns, 'column') as $column) {
if ($column->twig) {
$source .= ($source!=='' ? ',"' : '""') . (string)$column->twig . '"';
$source .= ($source!=='[' ? ',' : '') . (string)$column->twig;
}
}
}
Expand Down Expand Up @@ -1405,6 +1405,8 @@ protected function _processRecord(Tinebase_Record_Interface $_record)
}
} elseif ($column->recordProperty) {
$this->_writeValue($this->_convertToString($_record->{$column->recordProperty}));
} elseif ($column->identifier) {
$this->_writeValue($this->_convertToString($_record->{$column->identifier}));
} else {
if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ .
' pointless column found: ' . print_r($column, true));
Expand Down
4 changes: 4 additions & 0 deletions tine20/Tinebase/Export/CsvNew.php
Expand Up @@ -74,6 +74,10 @@ public function __construct(
$this->_fields[] = $column->identifier;
}
}

if ($this->_hasTwig()) {
$this->_dumpRecords = false;
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tine20/Tinebase/Helper/ZendConfig.php
Expand Up @@ -62,17 +62,18 @@ public static function getChildrenConfigs($_config, $_name)
return [];
} elseif (!$data instanceof Zend_Config) {
throw new Tinebase_Exception_InvalidArgument('bad configuration, expected Zend_Config value');
} elseif (is_int($data->key())) {
} elseif ($data->rewind() || is_int($data->key())) {
$result = [];
do {
$result[] = $child = $data->current();
if (!$child instanceof Zend_Config) {
throw new Tinebase_Exception_InvalidArgument('bad configuration, expected Zend_Config value');
}
} while ($data->next() || $data->valid());
$data->rewind();
return $result;
} else {
return [$data];
}
}
}
}

0 comments on commit 470d617

Please sign in to comment.