Old Tainacan importer: repository mapping

This commit is contained in:
andre2ar 2018-05-09 15:49:22 -03:00
parent faa5ed9617
commit 0926ff562e
2 changed files with 32 additions and 9 deletions

View File

@ -36,6 +36,7 @@ abstract class Importer {
* @var array
*/
public $mapping;
private $repository_mapping;
/**
* The path to the temporary file created when user uploads a file
@ -165,16 +166,28 @@ abstract class Importer {
*
* @param array $mapping Mapping importer-fields
*/
public function set_mapping( $mapping, $item_id = false ){
if($item_id === false)
public function set_mapping( $mapping){
if(!empty($mapping))
{
$this->mapping = $mapping;
}else
{
$this->mapping[$item_id] = $mapping;
}
}
public function set_repository_mapping( $mapping, $item_id ){
if(!empty($mapping) && !empty($item_id))
{
$this->repository_mapping[$item_id] = $mapping;
}else return false;
}
public function get_repository_mapping($item_id)
{
if(!empty($item_id))
{
return $this->repository_mapping[$item_id];
}else return false;
}
/**
* set how many items should be processes in each step
*

View File

@ -216,7 +216,7 @@ class Old_Tainacan extends Importer
$mapping = $this->create_collection_meta($file_fields, $Fields_Repository, $Tainacan_Fields, $created_repository_fields, $created_categories, $relationships);
$this->set_mapping($mapping, $old_collection_id);
$this->set_repository_mapping($mapping, $old_collection_id);
next($created_collections);
$inside_step_pointer++;
}
@ -391,12 +391,22 @@ class Old_Tainacan extends Importer
public function create_collection_items()
{
$collections = $this->read_from_file('collections');
if(!empty($collections))
$created_collections = $this->read_from_file("collections");
if(!empty($created_collections))
{
$Repository_Collections = \Tainacan\Repositories\Collections::get_instance();
$collection_info = current($created_collections);
$new_collection_id = $collection_info['new_id'];
$old_collection_id = key($created_collections);
$collection = $Repository_Collections->fetch($new_collection_id);
$this->set_collection($collection);
$mapping = $this->get_repository_mapping($old_collection_id);
$this->set_mapping($mapping);
$this->process($this->get_start());
}
/*Use standard method*/
return false;
}