Enables create repository metadata from mapping
This commit is contained in:
parent
596aa88437
commit
d4af360895
|
@ -183,11 +183,10 @@ class REST_Importers_Controller extends REST_Controller {
|
|||
* @return string|\WP_Error|\WP_REST_Response
|
||||
*/
|
||||
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)) {
|
||||
$attributes = [];
|
||||
|
||||
foreach ($body as $att => $value){
|
||||
|
@ -197,10 +196,8 @@ class REST_Importers_Controller extends REST_Controller {
|
|||
global $Tainacan_Importer_Handler;
|
||||
$importer = $Tainacan_Importer_Handler->get_importer_instance_by_session_id($session_id);
|
||||
|
||||
if($importer) {
|
||||
|
||||
foreach ($body as $att => $value){
|
||||
|
||||
if ($importer) {
|
||||
foreach ($body as $att => $value) {
|
||||
if ($att == 'collection') {
|
||||
if (is_array($value) && isset($value['id'])) {
|
||||
if ($importer->add_collection($value) === false ) {
|
||||
|
@ -383,8 +380,5 @@ class REST_Importers_Controller extends REST_Controller {
|
|||
return new \WP_REST_Response( $importers, 200 );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -653,7 +653,7 @@ class CSV extends Importer {
|
|||
*
|
||||
* @param array $processed_item Associative array with metadatum source's as index with
|
||||
* 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
|
||||
*/
|
||||
|
@ -721,7 +721,7 @@ class CSV extends Importer {
|
|||
if( is_array( $processed_item ) ) {
|
||||
foreach ( $processed_item as $metadatum_source => $values ) {
|
||||
|
||||
if ( $metadatum_source == 'special_document' ||
|
||||
if ($metadatum_source == 'special_document' ||
|
||||
$metadatum_source == 'special_attachments' ||
|
||||
$metadatum_source == 'special_item_status' ||
|
||||
$metadatum_source == 'special_comment_status') {
|
||||
|
@ -735,9 +735,9 @@ class CSV extends Importer {
|
|||
}
|
||||
$metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id );
|
||||
|
||||
if( $this->is_empty_value( $values ) ) continue;
|
||||
if ($this->is_empty_value($values)) continue;
|
||||
|
||||
if( $metadatum instanceof Entities\Metadatum ) {
|
||||
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' ) {
|
||||
if( !is_array( $values ) ) {
|
||||
|
@ -958,18 +958,25 @@ class CSV extends Importer {
|
|||
public function add_collection(array $collection) {
|
||||
if (isset($collection['id'])) {
|
||||
|
||||
if( isset($collection['mapping']) && is_array($collection['mapping']) ){
|
||||
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 ( $metadatum == false ) {
|
||||
if (!is_numeric($metadatum_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) {
|
||||
$this->add_error_log( __("Error while creating metadatum, please review the metadatum description.", 'tainacan') );
|
||||
$this->abort();
|
||||
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;
|
||||
} elseif ( is_array($metadatum) && sizeof($metadatum) == 2) {
|
||||
$parent_header = key($header);
|
||||
|
|
|
@ -11,7 +11,6 @@ class Importer_Handler {
|
|||
$this->bg_importer = new Background_Importer();
|
||||
|
||||
add_action('init', array(&$this, 'init'));
|
||||
|
||||
}
|
||||
|
||||
public function init() {
|
||||
|
@ -220,5 +219,3 @@ class Importer_Handler {
|
|||
|
||||
global $Tainacan_Importer_Handler;
|
||||
$Tainacan_Importer_Handler = new Importer_Handler();
|
||||
|
||||
?>
|
Loading…
Reference in New Issue