From 69a88e1b34b7f69461e5c441555e659faa921bce Mon Sep 17 00:00:00 2001 From: andre2ar Date: Thu, 3 May 2018 14:37:20 -0300 Subject: [PATCH] Old Tainacan importer: Create empty collections and repository metadata --- src/importer/class-tainacan-old-tainacan.php | 77 +++++++++++++++++++- tests/test-importer.php | 17 ++++- 2 files changed, 88 insertions(+), 6 deletions(-) diff --git a/src/importer/class-tainacan-old-tainacan.php b/src/importer/class-tainacan-old-tainacan.php index 3d5a0d412..18bbce373 100644 --- a/src/importer/class-tainacan-old-tainacan.php +++ b/src/importer/class-tainacan-old-tainacan.php @@ -158,11 +158,71 @@ class Old_Tainacan extends Importer public function create_collections() { + $collections_link = $this->get_url() . $this->tainacan_api_address . "/collections"; + $collections = wp_remote_get($collections_link); + + $collections_array = $this->verify_process_result($collections); + if($collections_array) + { + foreach ($collections_array as $collection) + { + $new_collection = new \Tainacan\Entities\Collection(); + $new_collection->set_name($collection->post_title); + $new_collection->set_status('publish'); + $new_collection->validate(); + $new_collection = \Tainacan\Repositories\Collections::get_instance()->insert($new_collection); + + /*Add old id*/ + add_post_meta($new_collection->get_id(), "old_tainacan_collection_id", $collection->ID); + } + } + return false; } public function create_repo_meta() { + $repository_meta_link = $this->get_url() . $this->tainacan_api_address . "/repository/metadata"; + $repo_meta = wp_remote_get($repository_meta_link); + + $repo_meta_array = $this->verify_process_result($repo_meta); + if($repo_meta_array) + { + $Fields_Repository = \Tainacan\Repositories\Fields::get_instance(); + foreach ($repo_meta_array as $meta) + { + $avoid = [ + 'socialdb_property_fixed_title', + 'socialdb_property_fixed_description', + 'socialdb_property_fixed_content', + 'socialdb_property_fixed_thumbnail', + 'socialdb_property_fixed_attachments', + 'stars', + 'item', + 'tree', + 'compound' + ]; + + $special = [ + 'socialdb_property_fixed_type' + ]; + if(!in_array($meta->slug, $avoid) && !in_array($meta->type, $avoid)) + { + $newField = new \Tainacan\Entities\Field(); + + $type = $this->define_type($meta->type); + $newField->set_name($meta->name); + + $newField->set_field_type('Tainacan\Field_Types\\'.$type); + + $newField->set_collection_id('default'); + $newField->validate(); // there is no user input here, so we can be sure it will validate. + + $newField = $Fields_Repository->insert($newField); + print $meta->type; + } + } + } return false; } @@ -173,6 +233,7 @@ class Old_Tainacan extends Importer public function create_collection_items() { + /*Use standard method*/ return false; } @@ -383,11 +444,23 @@ class Old_Tainacan extends Importer $type = strtolower($type); $tainacan_types = ['text', 'textarea', 'numeric', 'date']; - $types_to_work = ['item', 'tree']; if(in_array($type, $tainacan_types)) { $type = ucfirst($type); - }else $type = 'Text'; + }else if(strcmp($type, 'autoincrement') === 0) + { + $type = "Numeric"; + }else if(strcmp($type, 'item')) + { + $type = "Relationship"; + }else if(strcmp($type, 'tree')) + { + $type = "Category"; + }else if(strcmp($type, 'compound')) + { + $type = "Compound"; + } + else $type = 'Text'; return $type; } diff --git a/tests/test-importer.php b/tests/test-importer.php index ee375db79..9d65356c3 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -39,16 +39,25 @@ class ImporterTests extends TAINACAN_UnitTestCase { $_SESSION['tainacan_importer'][$id]->set_items_per_step(50); -// if(!copy('./tests/attachment/json_old_tainacan_base.txt', './tests/attachment/json_old_tainacan.txt')) -// { -// return false; -// } + //if(!copy('./tests/attachment/json_old_tainacan_base.txt', './tests/attachment/json_old_tainacan.txt')) + //{ + //return false; + //} //$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' ); $url = 'http://localhost/'; $_SESSION['tainacan_importer'][$id]->set_url($url); + // One run for each step + //Create categories $_SESSION['tainacan_importer'][$id]->run(); + + //Create empty collections + $_SESSION['tainacan_importer'][$id]->run(); + + //Create repository metadata + $_SESSION['tainacan_importer'][$id]->run(); + $this->assertTrue(true); }*/