Commit c1529b42 authored by claudiu.cristea's avatar claudiu.cristea

Issue #2818923 by claudiu.cristea: Row index passed to keys triggers exception

parent 6fc89cb3
......@@ -99,6 +99,9 @@ class Spreadsheet extends SourcePluginBase implements ConfigurablePluginInterfac
*/
public function fields() {
$columns = $this->getConfiguration()['columns'];
if (!empty($row_index_column = $this->getConfiguration()['row_index_colums'])) {
$columns[] = $row_index_column;
}
return array_combine($columns, $columns);
}
......
......@@ -97,14 +97,16 @@ class SpreadsheetIterator implements SpreadsheetIteratorInterface {
* {@inheritdoc}
*/
public function current() {
if (empty($keys = $this->getKeys())) {
$row_index_column = $this->getRowIndexColumn();
if (!$row_index_column) {
$all_columns = $this->getKeys() + $this->getColumns();
if ($row_index_column = $this->getRowIndexColumn()) {
$all_columns[$row_index_column] = -1;
}
else {
if (empty($keys = $this->getKeys())) {
throw new \InvalidArgumentException("Row index should act as key but no name has been provided. Pass a string in \$config['row_index_column'] key when setting the configuration in SpreadsheetIterator::setConfiguration(\$config), to provide a name for this column.");
}
$keys = [$row_index_column => -1];
}
$all_columns = $keys + $this->getColumns();
// Arrange columns in their spreadsheet native order.
asort($all_columns);
......@@ -192,7 +194,7 @@ class SpreadsheetIterator implements SpreadsheetIteratorInterface {
$headers = $this->getHeaders();
$this->keys = [];
foreach ($this->configuration['keys'] as $key) {
if (!isset($headers[$key])) {
if ($key != $this->getRowIndexColumn() && !isset($headers[$key])) {
throw new \InvalidArgumentException("Key '$key' doesn't exist in the table header.");
}
$this->keys[$key] = $headers[$key];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment