csv importer - create tests for different document types and fix index error on process item
This commit is contained in:
parent
78497d66ba
commit
7fd2138485
|
@ -106,14 +106,14 @@ class CSV extends Importer {
|
||||||
|
|
||||||
foreach ( $headers as $indexRaw => $headerRaw ) {
|
foreach ( $headers as $indexRaw => $headerRaw ) {
|
||||||
if( $headerRaw === $header ){
|
if( $headerRaw === $header ){
|
||||||
$index = $indexRaw;
|
$column = $indexRaw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!isset($index))
|
if(!isset($column))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$valueToInsert = $this->handle_encoding( $values[ $index ] );
|
$valueToInsert = $this->handle_encoding( $values[ $column ] );
|
||||||
|
|
||||||
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ?
|
$processedItem[ $header ] = ( $metadatum->is_multiple() ) ?
|
||||||
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert;
|
explode( $this->get_option('multivalued_delimiter'), $valueToInsert) : $valueToInsert;
|
||||||
|
@ -137,8 +137,14 @@ class CSV extends Importer {
|
||||||
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
$file = new \SplFileObject( $this->tmp_file, 'r' );
|
||||||
$file->setFlags(\SplFileObject::SKIP_EMPTY);
|
$file->setFlags(\SplFileObject::SKIP_EMPTY);
|
||||||
$file->seek( $index );
|
$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) ){
|
if( is_array($values) && !empty($column_document) ){
|
||||||
$this->handle_document( $values[$column_document], $inserted_item);
|
$this->handle_document( $values[$column_document], $inserted_item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -483,6 +483,16 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
||||||
$_SESSION['tainacan_importer'][$id]->add_collection( $collection_definition );
|
$_SESSION['tainacan_importer'][$id]->add_collection( $collection_definition );
|
||||||
$_SESSION['tainacan_importer'][$id]->set_option('encode','iso88591');
|
$_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) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue