diff --git a/src/importer/class-tainacan-csv.php b/src/importer/class-tainacan-csv.php index 8668b1aff..5decabd0d 100644 --- a/src/importer/class-tainacan-csv.php +++ b/src/importer/class-tainacan-csv.php @@ -106,14 +106,14 @@ class CSV extends Importer { foreach ( $headers as $indexRaw => $headerRaw ) { if( $headerRaw === $header ){ - $index = $indexRaw; + $column = $indexRaw; } } - if(!isset($index)) + if(!isset($column)) continue; - $valueToInsert = $this->handle_encoding( $values[ $index ] ); + $valueToInsert = $this->handle_encoding( $values[ $column ] ); $processedItem[ $header ] = ( $metadatum->is_multiple() ) ? explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert; @@ -137,8 +137,14 @@ class CSV extends Importer { $file = new \SplFileObject( $this->tmp_file, 'r' ); $file->setFlags(\SplFileObject::SKIP_EMPTY); $file->seek( $index ); - $values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') ); + if( $index === 0 ){ + $file->current(); + $file->next(); + } + + $values = str_getcsv( rtrim($file->fgets()), $this->get_option('delimiter'), $this->get_option('enclosure') ); + if( is_array($values) && !empty($column_document) ){ $this->handle_document( $values[$column_document], $inserted_item); } diff --git a/tests/test-importer.php b/tests/test-importer.php index 498c9504a..9632c0577 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -483,6 +483,16 @@ class ImporterTests extends TAINACAN_UnitTestCase { $_SESSION['tainacan_importer'][$id]->add_collection( $collection_definition ); $_SESSION['tainacan_importer'][$id]->set_option('encode','iso88591'); - $this->assertEquals(1, $_SESSION['tainacan_importer'][$id]->run(), 'first step should import 1 item'); + while($_SESSION['tainacan_importer'][$id]->run()){ + continue; + } + + $items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' ); + + $this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_source_number_of_items(), count( $items ) ); + + // test row 5 + $document_id = $items[0]->get_document(); + $this->assertFalse( is_numeric($document_id) ); } }