Block empty values in csv importer (#221)

This commit is contained in:
Eduardo Humberto 2019-04-05 20:31:27 -03:00
parent 48cc148f2d
commit 923ab57915
1 changed files with 15 additions and 1 deletions

View File

@ -575,6 +575,8 @@ class CSV extends Importer {
$tainacan_metadatum_id = array_search( $metadatum_source, $collection_definition['mapping'] );
$metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id );
if( $this->is_empty_value( $values ) ) continue;
if( $metadatum instanceof Entities\Metadatum ) {
$singleItemMetadata = new Entities\Item_Metadata_Entity( $item, $metadatum); // *empty item will be replaced by inserted in the next foreach
if( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Taxonomy' ) {
@ -648,7 +650,19 @@ class CSV extends Importer {
return false;
}
}
/**
* @param $value
* @return bool
*/
public function is_empty_value( $value ){
if( is_array( $value ) ){
return ( empty( array_filter( $value ) ) );
} else {
return ( trim( $value ) === '' );
}
}
/**
* @param $metadatum the metadata
* @param $values the categories names