diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index 5d844e04f..c7c476a79 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -84,6 +84,8 @@ abstract class Importer { private $current_step = 0; + private $url = ''; + public function __construct() { if (!session_id()) { @session_start(); @@ -100,6 +102,34 @@ abstract class Importer { return $this->id; } + /** + * Set URL + * @param $url string + * @return bool + */ + public function set_url($url) + { + if(!empty($url) && !is_array($url)) + { + $this->url = rtrim(trim($url), "/"); + return true; + } + + return false; + } + + /** + * @return string or bool + */ + public function get_url() + { + if(!empty($this->url)) + { + return $this->url; + } + + return false; + } /** * @return array Mapping diff --git a/src/importer/class-tainacan-old-tainacan.php b/src/importer/class-tainacan-old-tainacan.php index b76fc0be7..e4509cfdc 100644 --- a/src/importer/class-tainacan-old-tainacan.php +++ b/src/importer/class-tainacan-old-tainacan.php @@ -41,7 +41,7 @@ class Old_Tainacan extends Importer 'Create collections metadata' => 'create_collection_metas', 'Create collections items' => 'create_collection_items', 'Setting relationships' => 'set_relationships' - ]; + ], $tainacan_api_address, $wordpress_api_address; public function __construct() { @@ -50,10 +50,38 @@ class Old_Tainacan extends Importer $this->set_steps($this->steps); $this->remove_import_method('file'); $this->add_import_method('url'); + $this->tainacan_api_address = "/wp-json/tainacan/v1"; + $this->wordpress_api_address = "/wp-json/wp/v2"; } + public function verify_process_result($result) + { + if(is_wp_error($result)) + { + $this->add_log('error', $result->get_error_message()); + return false; + }else if(isset($result['body'])) + { + return json_decode($result['body']); + } + + return false; + } + + public function create_taxonomies() { + $taxonomies_link = $this->get_url() . $this->wordpress_api_address . "/taxonomies"; + $taxonomies_link = wp_nonce_url($taxonomies_link); + + $taxonomies = wp_remote_get($taxonomies_link); + + $taxonomies_array = $this->verify_process_result($taxonomies); + if($taxonomies_array) + { + + } + return false; } diff --git a/tests/test-importer.php b/tests/test-importer.php index e39231430..818f0ab84 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -45,7 +45,8 @@ class ImporterTests extends TAINACAN_UnitTestCase { // } //$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' ); - $_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/colecao/colecao-to-import/' ); + $url = 'http://localhost/'; + $_SESSION['tainacan_importer'][$id]->set_url($url); $_SESSION['tainacan_importer'][$id]->run(); }*/