create step for tainacan old structure

This commit is contained in:
eduardohumberto 2018-06-07 22:52:46 -03:00
parent 608da65c9b
commit 9be7d8521a
2 changed files with 48 additions and 27 deletions

View File

@ -34,14 +34,9 @@ class Old_Tainacan extends Importer{
'socialdb_property_fixed_attachments' 'socialdb_property_fixed_attachments'
], ],
$steps = [ $steps = [
//'Creating all categories' => 'create_categories',
//'Create empty collections' => 'create_collections',
//'Creating relationships metadata' => 'create_relationships_meta',
//'Create repository metadata' => 'treat_repo_meta',
//'Create collections metadata' => 'treat_collection_metas',
[ [
'name' => 'Create categories, collections and metadata', 'name' => 'Create categories, collections and metadata',
'callback' => 'process_collections' 'callback' => 'create_structure'
], ],
[ [
'name' => 'Import Items', 'name' => 'Import Items',
@ -51,8 +46,27 @@ class Old_Tainacan extends Importer{
'name' => 'Finishing', 'name' => 'Finishing',
'callback' => 'clear' 'callback' => 'clear'
] ]
], $tainacan_api_address, $wordpress_api_address; ], $tainacan_api_address, $wordpress_api_address, $actual_collection;
/**
* create structure tainacan
*/
public function create_structure(){
$this->create_categories();
$this->create_collections();
$this->create_relationships_meta();
$this->treat_repo_meta();
$this->treat_collection_metas();
return false;
}
/**
* helper method to set the actual collection in loop
*/
public function set_actual_collection($collection){
$this->actual_collection = $collection;
}
public function create_categories() public function create_categories()
{ {
@ -67,8 +81,10 @@ class Old_Tainacan extends Importer{
$categories_array = $this->remove_same_name($categories_array); $categories_array = $this->remove_same_name($categories_array);
list($inside_step_pointer, $end) = $this->get_begin_end($categories_array); // list($inside_step_pointer, $end) = $this->get_begin_end($categories_array);
if($inside_step_pointer === false) return false; // if($inside_step_pointer === false) return false;
$inside_step_pointer = 0;
$end = ( $categories_array ) ? count( $categories_array) : 0;
$created_categories = []; $created_categories = [];
while($inside_step_pointer < $end) while($inside_step_pointer < $end)
@ -110,8 +126,10 @@ class Old_Tainacan extends Importer{
$created_collections = []; $created_collections = [];
if($collections_array) if($collections_array)
{ {
list($inside_step_pointer, $end) = $this->get_begin_end($collections_array); // list($inside_step_pointer, $end) = $this->get_begin_end($collections_array);
if($inside_step_pointer === false) return false; // if($inside_step_pointer === false) return false;
$inside_step_pointer = 0;
$end = ( $collections_array ) ? count( $collections_array) : 0;
while($inside_step_pointer < $end) while($inside_step_pointer < $end)
{ {
@ -206,17 +224,19 @@ class Old_Tainacan extends Importer{
$created_categories = $this->read_from_file("categories"); $created_categories = $this->read_from_file("categories");
$relationships = $this->read_from_file("relationships"); $relationships = $this->read_from_file("relationships");
list($inside_step_pointer, $end) = $this->get_begin_end($created_collections); // list($inside_step_pointer, $end) = $this->get_begin_end($created_collections);
if($inside_step_pointer === false) return false; // if($inside_step_pointer === false) return false;
$inside_step_pointer = 0;
$end = ( $created_collections ) ? count( $created_collections) : 0;
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Fields_Repository = \Tainacan\Repositories\Fields::get_instance(); $Fields_Repository = \Tainacan\Repositories\Fields::get_instance();
$Repository_Collections = \Tainacan\Repositories\Collections::get_instance(); $Repository_Collections = \Tainacan\Repositories\Collections::get_instance();
for($i = 0; $i < $inside_step_pointer; $i++) //for($i = 0; $i < $inside_step_pointer; $i++)
{ // {
next($created_collections); // next($created_collections);
} // }
while($inside_step_pointer < $end) while($inside_step_pointer < $end)
{ {
@ -224,13 +244,15 @@ class Old_Tainacan extends Importer{
$new_collection_id = $collection_info['new_id']; $new_collection_id = $collection_info['new_id'];
$old_collection_id = key($created_collections); $old_collection_id = key($created_collections);
$collection = $Repository_Collections->fetch($new_collection_id); $collection = $Repository_Collections->fetch($new_collection_id);
$this->set_collection($collection); $this->set_actual_collection($collection);
$file_fields = $this->get_collection_fields($old_collection_id); $file_fields = $this->get_collection_fields($old_collection_id);
$mapping = $this->create_collection_meta($file_fields, $Fields_Repository, $Tainacan_Fields, $created_repository_fields, $created_categories, $relationships); $mapping = $this->create_collection_meta($file_fields, $Fields_Repository, $Tainacan_Fields, $created_repository_fields, $created_categories, $relationships);
$this->set_repository_mapping($mapping, $old_collection_id); //TODO: add collection definition
// $this->set_repository_mapping($mapping, $old_collection_id);
next($created_collections); next($created_collections);
$inside_step_pointer++; $inside_step_pointer++;
} }
@ -280,7 +302,7 @@ class Old_Tainacan extends Importer{
$mapping[$new_id] = $created_repository_fields[$old_field_id]['name']; $mapping[$new_id] = $created_repository_fields[$old_field_id]['name'];
}else }else
{ {
$fields = $Tainacan_Fields->fetch_by_collection( $this->collection, [], 'OBJECT' ); $fields = $Tainacan_Fields->fetch_by_collection( $this->actual_collection, [], 'OBJECT' );
foreach ($fields as $field) foreach ($fields as $field)
{ {
@ -367,7 +389,7 @@ class Old_Tainacan extends Importer{
$newField->set_collection_id('default'); $newField->set_collection_id('default');
}else }else
{ {
$newField->set_collection($this->collection); $newField->set_collection($this->actual_collection);
} }
}else //Set compound as field parent }else //Set compound as field parent
{ {
@ -413,7 +435,7 @@ class Old_Tainacan extends Importer{
$new_collection_id = $collection_info['new_id']; $new_collection_id = $collection_info['new_id'];
$old_collection_id = key($created_collections); $old_collection_id = key($created_collections);
$collection = $Repository_Collections->fetch($new_collection_id); $collection = $Repository_Collections->fetch($new_collection_id);
$this->set_collection($collection); $this->set_actual_collection($collection);
$mapping = $this->get_repository_mapping($old_collection_id); $mapping = $this->get_repository_mapping($old_collection_id);
$this->set_mapping($mapping); $this->set_mapping($mapping);
@ -679,7 +701,7 @@ class Old_Tainacan extends Importer{
$headers = $this->get_fields(); $headers = $this->get_fields();
// search the index in the file and get values // search the index in the file and get values
$file = new \SplFileObject( $this->tmp_file, 'r' ); /*$file = new \SplFileObject( $this->tmp_file, 'r' );
$file_content = unserialize($file->fread($file->getSize())); $file_content = unserialize($file->fread($file->getSize()));
$values = $file_content->items[$index]; $values = $file_content->items[$index];
foreach ($headers as $header) foreach ($headers as $header)
@ -702,7 +724,7 @@ class Old_Tainacan extends Importer{
$processedItem[$header] = $values->item->{$header}; $processedItem[$header] = $values->item->{$header};
} }
} }
} }*/
return $processedItem; return $processedItem;
} }
@ -748,7 +770,7 @@ class Old_Tainacan extends Importer{
$newField->set_field_type('Tainacan\Field_Types\\'.$type); $newField->set_field_type('Tainacan\Field_Types\\'.$type);
$newField->set_collection($this->collection); $newField->set_collection($this->actual_collection);
$newField->validate(); // there is no user input here, so we can be sure it will validate. $newField->validate(); // there is no user input here, so we can be sure it will validate.
$newField = $fields_repository->insert($newField); $newField = $fields_repository->insert($newField);

View File

@ -47,8 +47,7 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$url_repository = 'http://localhost/wordpress_tainacan/'; $url_repository = 'http://localhost/wordpress_tainacan/';
$url_repository = ''; $url_repository = '';
if( $url_repository !== '' ){ if( $url_repository !== '' ){
$_SESSION['tainacan_importer'][$id]->set_url($url); $_SESSION['tainacan_importer'][$id]->set_url($url_repository);
$_SESSION['tainacan_importer'][$id]->set_repository();
while (!$_SESSION['tainacan_importer'][$id]->is_finished()) while (!$_SESSION['tainacan_importer'][$id]->is_finished())
{ {