fix bg importer to instantiate the class from arg data

This commit is contained in:
eduardohumberto 2018-06-08 21:16:52 -03:00
parent 905f9c76c0
commit 8faf4484e0
2 changed files with 10 additions and 12 deletions

View File

@ -13,7 +13,7 @@ class Background_Importer extends Background_Process {
$className = $data['class_name']; $className = $data['class_name'];
if (class_exists($className)) { if (class_exists($className)) {
$object = new \Tainacan\Importer\Test_Importer($data); $object = new $className($data);
$runned = $object->run(); $runned = $object->run();
if (false === $runned) { if (false === $runned) {
return false; return false;

View File

@ -248,7 +248,11 @@ class Old_Tainacan extends Importer{
$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);
//TODO: add collection definition $this->add_collection([
'id' => $new_collection_id,
'map' => $mapping,
'total_items' => $this->get_total_items_from_source( $old_collection_id )
]);
// $this->set_repository_mapping($mapping, $old_collection_id); // $this->set_repository_mapping($mapping, $old_collection_id);
next($created_collections); next($created_collections);
@ -799,16 +803,10 @@ class Old_Tainacan extends Importer{
* Method implemented by the child importer class to return the number of items to be imported * Method implemented by the child importer class to return the number of items to be imported
* @return int * @return int
*/ */
public function get_total_items_from_source() public function get_total_items_from_source( $collection_id ) {
{ $info = wp_remote_get( $this->get_url() . $this->tainacan_api_address . "/collections/".$collection_id."/items" );
if(!isset($this->tmp_file)){ $info = json_decode($info['body']);
return 0; return $this->total_items = $info->found_items;
}
$file = new \SplFileObject( $this->tmp_file, 'r' );
$file_content = unserialize($file->fread($file->getSize()));
return $this->total_items = $file_content->found_items;
} }
/** /**