csv importer - create tests for different document types and fix index error on process item

This commit is contained in:
eduardohumberto 2018-07-30 21:57:01 -03:00
parent 78497d66ba
commit 7fd2138485
2 changed files with 21 additions and 5 deletions

View File

@ -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);
}

View File

@ -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) );
}
}