Old Tainacan importer: Repository compounds
This commit is contained in:
parent
87b85ec6ed
commit
46bda70e9b
|
@ -45,7 +45,7 @@ class Old_Tainacan extends Importer
|
|||
'Creating all categories' => 'create_categories',
|
||||
'Create empty collections' => 'create_collections',
|
||||
'Creating relationships metadata' => 'create_relationships_meta',
|
||||
'Create repository metadata' => 'create_repo_meta',
|
||||
'Create repository metadata' => 'treat_repo_meta',
|
||||
'Create collections metadata' => 'create_collection_metas',
|
||||
'Create collections items' => 'create_collection_items',
|
||||
"Finishing" => 'clear'
|
||||
|
@ -154,18 +154,26 @@ class Old_Tainacan extends Importer
|
|||
return false;
|
||||
}
|
||||
|
||||
public function create_repo_meta()
|
||||
public function treat_repo_meta()
|
||||
{
|
||||
$repository_meta_link = $this->get_url() . $this->tainacan_api_address . "/repository/metadata?includeMetadata=1";
|
||||
$repo_meta = wp_remote_get($repository_meta_link);
|
||||
|
||||
$repo_meta_array = $this->verify_process_result($repo_meta);
|
||||
|
||||
$Fields_Repository = \Tainacan\Repositories\Fields::get_instance();
|
||||
$created_categories = $this->read_from_file("categories");
|
||||
$relationships = $this->read_from_file("relationships");
|
||||
|
||||
$this->create_meta_repo($repo_meta_array, $Fields_Repository, $created_categories, $relationships);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create_meta_repo($repo_meta_array, $Fields_Repository, $created_categories, $relationships, $compound_id = null)
|
||||
{
|
||||
if($repo_meta_array)
|
||||
{
|
||||
$Fields_Repository = \Tainacan\Repositories\Fields::get_instance();
|
||||
$created_categories = $this->read_from_file("categories");
|
||||
$relationships = $this->read_from_file("relationships");
|
||||
|
||||
foreach ($repo_meta_array as $meta)
|
||||
{
|
||||
$avoid = [
|
||||
|
@ -178,8 +186,7 @@ class Old_Tainacan extends Importer
|
|||
|
||||
$special = [
|
||||
'socialdb_property_fixed_type',
|
||||
'stars',
|
||||
'compound'
|
||||
'stars'
|
||||
];
|
||||
|
||||
if(!in_array($meta->slug, $avoid) && !in_array($meta->type, $special))
|
||||
|
@ -193,25 +200,40 @@ class Old_Tainacan extends Importer
|
|||
if(strcmp($type, "Category") === 0)
|
||||
{
|
||||
$taxonomy_id = $meta->metadata->taxonomy;
|
||||
|
||||
$new_category_id = $created_categories[$taxonomy_id]['new_id'];
|
||||
$newField->set_field_type_options(['taxonomy_id' => $new_category_id]);
|
||||
if(isset($created_categories[$taxonomy_id]))
|
||||
{
|
||||
$new_category_id = $created_categories[$taxonomy_id]['new_id'];
|
||||
$newField->set_field_type_options(['taxonomy_id' => $new_category_id]);
|
||||
}
|
||||
}else if(strcmp($type, "Relationship") === 0)
|
||||
{
|
||||
$taxonomy_id = $meta->metadata->object_category_id;
|
||||
$new_collection_id = $relationships[$taxonomy_id]['new_id'];
|
||||
|
||||
$newField->set_field_type_options(['collection_id' => $new_collection_id]);
|
||||
if(isset($relationships[$taxonomy_id]))
|
||||
{
|
||||
$new_collection_id = $relationships[$taxonomy_id]['new_id'];
|
||||
$newField->set_field_type_options(['collection_id' => $new_collection_id]);
|
||||
}
|
||||
}else if(strcmp($type, "Compound") === 0)
|
||||
{
|
||||
$this->create_meta_repo($meta->metadata->children, $Fields_Repository, $created_categories, $relationships, $newField->get_id());
|
||||
}
|
||||
|
||||
/*Compound treatement*/
|
||||
if($compound_id === null)
|
||||
{
|
||||
$newField->set_collection_id('default');
|
||||
}else //Set compound as field parent
|
||||
{
|
||||
$newField->set_parent($compound_id);
|
||||
}
|
||||
|
||||
$newField->set_collection_id('default');
|
||||
$newField->validate(); // there is no user input here, so we can be sure it will validate.
|
||||
|
||||
$Fields_Repository->insert($newField);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create_collection_metas()
|
||||
|
@ -225,11 +247,6 @@ class Old_Tainacan extends Importer
|
|||
return false;
|
||||
}
|
||||
|
||||
public function set_relationships()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function clear()
|
||||
{
|
||||
unlink($this->get_id()."_categories.txt");
|
||||
|
|
|
@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
|
||||
}
|
||||
|
||||
public function test_automapping_old_tainacan()
|
||||
/*public function test_automapping_old_tainacan()
|
||||
{
|
||||
//$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
//$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
|
||||
|
@ -54,7 +54,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
|
|||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}*/
|
||||
|
||||
/*public function test_file_old_tainacan () {
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
|
|
Loading…
Reference in New Issue