Repository importer

This commit is contained in:
andre2ar 2018-04-27 14:37:57 -03:00
parent 2cf7f357c2
commit e2359f1790
3 changed files with 61 additions and 2 deletions

View File

@ -84,6 +84,8 @@ abstract class Importer {
private $current_step = 0; private $current_step = 0;
private $url = '';
public function __construct() { public function __construct() {
if (!session_id()) { if (!session_id()) {
@session_start(); @session_start();
@ -100,6 +102,34 @@ abstract class Importer {
return $this->id; 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 * @return array Mapping

View File

@ -41,7 +41,7 @@ class Old_Tainacan extends Importer
'Create collections metadata' => 'create_collection_metas', 'Create collections metadata' => 'create_collection_metas',
'Create collections items' => 'create_collection_items', 'Create collections items' => 'create_collection_items',
'Setting relationships' => 'set_relationships' 'Setting relationships' => 'set_relationships'
]; ], $tainacan_api_address, $wordpress_api_address;
public function __construct() public function __construct()
{ {
@ -50,10 +50,38 @@ class Old_Tainacan extends Importer
$this->set_steps($this->steps); $this->set_steps($this->steps);
$this->remove_import_method('file'); $this->remove_import_method('file');
$this->add_import_method('url'); $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() 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; return false;
} }

View File

@ -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]->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(); $_SESSION['tainacan_importer'][$id]->run();
}*/ }*/