Separates Colleciton not set error from empty value warning in CSV importer.
This commit is contained in:
parent
f8d7e16f80
commit
6f8989637a
|
@ -697,6 +697,7 @@ class CSV extends Importer {
|
||||||
remove_action( 'post_updated', 'wp_save_post_revision' );
|
remove_action( 'post_updated', 'wp_save_post_revision' );
|
||||||
$collections = $this->get_collections();
|
$collections = $this->get_collections();
|
||||||
$collection_definition = isset($collections[$collection_index]) ? $collections[$collection_index] : false;
|
$collection_definition = isset($collections[$collection_index]) ? $collections[$collection_index] : false;
|
||||||
|
|
||||||
if ( !$collection_definition || !is_array($collection_definition) || !isset($collection_definition['id']) || !isset($collection_definition['mapping']) ) {
|
if ( !$collection_definition || !is_array($collection_definition) || !isset($collection_definition['id']) || !isset($collection_definition['mapping']) ) {
|
||||||
$this->add_error_log('Collection misconfigured');
|
$this->add_error_log('Collection misconfigured');
|
||||||
return false;
|
return false;
|
||||||
|
@ -712,7 +713,7 @@ class CSV extends Importer {
|
||||||
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
$Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance();
|
||||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||||
|
$special_columns = false;
|
||||||
|
|
||||||
$itemMetadataArray = [];
|
$itemMetadataArray = [];
|
||||||
|
|
||||||
|
@ -820,7 +821,17 @@ class CSV extends Importer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (!empty( $itemMetadataArray ) || $special_columns) && $collection instanceof Entities\Collection ) {
|
if ( !( $collection instanceof Entities\Collection ) ) {
|
||||||
|
$this->add_error_log( 'Collection not set');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ( empty( $itemMetadataArray ) && !$special_columns ) ) {
|
||||||
|
$this->add_log( 'Found one empty value' );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$item->set_collection( $collection );
|
$item->set_collection( $collection );
|
||||||
if ( !$updating_item ) {
|
if ( !$updating_item ) {
|
||||||
if( $item->validate() ) {
|
if( $item->validate() ) {
|
||||||
|
@ -833,8 +844,10 @@ class CSV extends Importer {
|
||||||
} else {
|
} else {
|
||||||
$insertedItem = $item;
|
$insertedItem = $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$wpdb->query( 'SET autocommit = 0;' );
|
$wpdb->query( 'SET autocommit = 0;' );
|
||||||
|
|
||||||
foreach ( $itemMetadataArray as $itemMetadata ) {
|
foreach ( $itemMetadataArray as $itemMetadata ) {
|
||||||
if($itemMetadata instanceof Entities\Item_Metadata_Entity ) {
|
if($itemMetadata instanceof Entities\Item_Metadata_Entity ) {
|
||||||
$itemMetadata->set_item( $insertedItem ); // *I told you
|
$itemMetadata->set_item( $insertedItem ); // *I told you
|
||||||
|
@ -891,10 +904,6 @@ class CSV extends Importer {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $insertedItem;
|
return $insertedItem;
|
||||||
} else {
|
|
||||||
$this->add_error_log( 'Collection not set');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function is_assoc(array $arr) {
|
private function is_assoc(array $arr) {
|
||||||
|
|
Loading…
Reference in New Issue