Enables create repository metadata from mapping

This commit is contained in:
Rodrigo Guimarães 2020-12-03 00:51:17 -03:00
parent 596aa88437
commit d4af360895
3 changed files with 21 additions and 23 deletions

View File

@ -184,7 +184,6 @@ class REST_Importers_Controller extends REST_Controller {
*/ */
public function update_item( $request ) { public function update_item( $request ) {
$session_id = $request['session_id']; $session_id = $request['session_id'];
$body = json_decode($request->get_body(), true); $body = json_decode($request->get_body(), true);
if (!empty($body)) { if (!empty($body)) {
@ -198,9 +197,7 @@ class REST_Importers_Controller extends REST_Controller {
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id); $importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
if ($importer) { if ($importer) {
foreach ($body as $att => $value) { foreach ($body as $att => $value) {
if ($att == 'collection') { if ($att == 'collection') {
if (is_array($value) && isset($value['id'])) { if (is_array($value) && isset($value['id'])) {
if ($importer->add_collection($value) === false ) { if ($importer->add_collection($value) === false ) {
@ -383,8 +380,5 @@ class REST_Importers_Controller extends REST_Controller {
return new \WP_REST_Response( $importers, 200 ); return new \WP_REST_Response( $importers, 200 );
} }
} }
?>

View File

@ -653,7 +653,7 @@ class CSV extends Importer {
* *
* @param array $processed_item Associative array with metadatum source's as index with * @param array $processed_item Associative array with metadatum source's as index with
* its value or values * its value or values
* @param integet $collection_index The index in the $this->collections array of the collection the item is beeing inserted into * @param integer $collection_index The index in the $this->collections array of the collection the item is being inserted into
* *
* @return Tainacan\Entities\Item Item inserted * @return Tainacan\Entities\Item Item inserted
*/ */
@ -963,12 +963,19 @@ class CSV extends Importer {
foreach( $collection['mapping'] as $metadatum_id => $header ){ foreach( $collection['mapping'] as $metadatum_id => $header ){
if (!is_numeric($metadatum_id)) { if (!is_numeric($metadatum_id)) {
$metadatum = $this->create_new_metadata( $header, $collection['id']); $repo_key = "create_repository_metadata";
$_collection_id = $collection['id'];
if (strpos($metadatum_id, $repo_key) !== false) {
$_collection_id = "default";
}
$metadatum = $this->create_new_metadata($header, $_collection_id);
if ($metadatum == false) { if ($metadatum == false) {
$this->add_error_log( __("Error while creating metadatum, please review the metadatum description.", 'tainacan') ); $this->add_error_log( __("Error while creating metadatum, please review the metadatum description.", 'tainacan') );
$this->abort(); $this->abort();
return false; return false;
} }
if (is_object($metadatum) && $metadatum instanceof \Tainacan\Entities\Metadatum) { if (is_object($metadatum) && $metadatum instanceof \Tainacan\Entities\Metadatum) {
$collection['mapping'][$metadatum->get_id()] = $header; $collection['mapping'][$metadatum->get_id()] = $header;
} elseif ( is_array($metadatum) && sizeof($metadatum) == 2) { } elseif ( is_array($metadatum) && sizeof($metadatum) == 2) {

View File

@ -11,7 +11,6 @@ class Importer_Handler {
$this->bg_importer = new Background_Importer(); $this->bg_importer = new Background_Importer();
add_action('init', array(&$this, 'init')); add_action('init', array(&$this, 'init'));
} }
public function init() { public function init() {
@ -220,5 +219,3 @@ class Importer_Handler {
global $Tainacan_Importer_Handler; global $Tainacan_Importer_Handler;
$Tainacan_Importer_Handler = new Importer_Handler(); $Tainacan_Importer_Handler = new Importer_Handler();
?>