csv importer - move intelligence to create metadata in the Importer Class (ref. #138)

This commit is contained in:
Eduardo Humberto 2018-11-06 21:49:28 -02:00
parent 6c9e00b882
commit f9b214e3f9
2 changed files with 14 additions and 16 deletions

View File

@ -201,22 +201,6 @@ class REST_Importers_Controller extends REST_Controller {
if ($att == 'collection') {
if (is_array($value) && isset($value['id'])) {
if(isset($value['mapping']) && is_array($value['mapping'])){
foreach( $value['mapping'] as $metadatum_id => $header ){
if( !is_numeric($metadatum_id) ) {
$metadatum = $importer->create_new_metadata( $header, $value['id']);
if( is_object($metadatum) ){
unset($value['mapping'][$metadatum_id]);
$value['mapping'][$metadatum->get_id()] = $header;
}
}
}
}
$importer->add_collection($value);
continue;
} else {

View File

@ -715,6 +715,20 @@ class CSV extends Importer {
if (isset($collection['id'])) {
if( isset($collection['mapping']) && is_array($collection['mapping']) ){
foreach( $collection['mapping'] as $metadatum_id => $header ){
if( !is_numeric($metadatum_id) ) {
$metadatum = $this->create_new_metadata( $header, $collection['id']);
if( is_object($metadatum) ){
unset($collection['mapping'][$metadatum_id]);
$collection['mapping'][$metadatum->get_id()] = $header;
}
}
}
$this->save_mapping( $collection['id'], $collection['mapping'] );
}