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
|
* @return string|\WP_Error|\WP_REST_Response
|
||||||
*/
|
*/
|
||||||
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)){
|
|
||||||
$attributes = [];
|
$attributes = [];
|
||||||
|
|
||||||
foreach ($body as $att => $value){
|
foreach ($body as $att => $value){
|
||||||
|
@ -197,10 +196,8 @@ class REST_Importers_Controller extends REST_Controller {
|
||||||
global $Tainacan_Importer_Handler;
|
global $Tainacan_Importer_Handler;
|
||||||
$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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
|
@ -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
|
||||||
*/
|
*/
|
||||||
|
@ -721,7 +721,7 @@ class CSV extends Importer {
|
||||||
if( is_array( $processed_item ) ) {
|
if( is_array( $processed_item ) ) {
|
||||||
foreach ( $processed_item as $metadatum_source => $values ) {
|
foreach ( $processed_item as $metadatum_source => $values ) {
|
||||||
|
|
||||||
if ( $metadatum_source == 'special_document' ||
|
if ($metadatum_source == 'special_document' ||
|
||||||
$metadatum_source == 'special_attachments' ||
|
$metadatum_source == 'special_attachments' ||
|
||||||
$metadatum_source == 'special_item_status' ||
|
$metadatum_source == 'special_item_status' ||
|
||||||
$metadatum_source == 'special_comment_status') {
|
$metadatum_source == 'special_comment_status') {
|
||||||
|
@ -735,9 +735,9 @@ class CSV extends Importer {
|
||||||
}
|
}
|
||||||
$metadatum = $Tainacan_Metadata->fetch( $tainacan_metadatum_id );
|
$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
|
$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( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Taxonomy' ) {
|
||||||
if( !is_array( $values ) ) {
|
if( !is_array( $values ) ) {
|
||||||
|
@ -958,18 +958,25 @@ class CSV extends Importer {
|
||||||
public function add_collection(array $collection) {
|
public function add_collection(array $collection) {
|
||||||
if (isset($collection['id'])) {
|
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 ){
|
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";
|
||||||
if ( $metadatum == false ) {
|
$_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->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) {
|
||||||
$parent_header = key($header);
|
$parent_header = key($header);
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
?>
|
|
Loading…
Reference in New Issue