• Resolved lbov

    (@lbov)


    Hi, is there an easy way to do a bulk creation of collections?, I mean, something like using a csv or xml file, or through an api or programmatically?

    I found this:

    Tainacan Import: Import structure from legacy version Tainacan

    Is the specification of the input file for this option available on internet?

    Thanks!

    • This topic was modified 3 years, 5 months ago by lbov.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author vnmedeiros

    (@vnmedeiros)

    Hi, when importing a CSV file you can define the metadata that will be created in the collection, maybe it helps.
    See more here: https://tainacan.github.io/tainacan-wiki/#/importers?id=automatic-creation-of-metadata

    🙂

    • This reply was modified 3 years, 5 months ago by vnmedeiros.
    Thread Starter lbov

    (@lbov)

    Thanks vnmedeiros!, what I’m looking for is a way to create many collections at once. I’m a little confused because the automatic-creation-of-metadata talks about categories and taxonomies, Categories and collections are the same?

    Thanks

    Plugin Author leogermani

    (@leogermani)

    Hi ibov,

    In the context of that documentation, “category” is just a name for a taxonomy.

    As for creating multiple collections at once, you can do this via REST API:

    https://tainacan.org/api-docs/endpoints/tainacan/v2/collections/#POST

    Or you can use the internal API to write a PHP script to do that as well:

    https://tainacan.github.io/tainacan-wiki/#/dev/internal-api

    Thread Starter lbov

    (@lbov)

    Hello, I created 300 empty collections to import items in each one with CSV files, but for some reason after collections are created tainacan starts to run too slow, mainly when I try to open a collection for editing it and item list and filters take a lot of time to load, even if there is no items at all in the repository. I can’t find why?

    I did another test, I created another wordpress instance with tainacan and created a single collection, then I imported 1700 items with its respective pdf (special document) to this collections. In this case, I have not experimented slow speed problems.

    So, I think it is something related with the collections creation process I’m doing, maybe I’m doing something wrong.

    For collection creation I run the following code with wp-cli:
    wp eval-file test.php –user=1

    Its a wrong way to do it? I really appreciate any hint you could give me.

    code of test.php:

    <?php
    
    namespace Tainacan\Importer;
    use \Tainacan\Entities;
    
    class Test_Collections extends Importer {
    
    	public function __construct($attributes = array()) {
    			parent::__construct($attributes);
    
    			$this->tax_repo = \Tainacan\Repositories\Taxonomies::get_instance();
    			$this->col_repo = \Tainacan\Repositories\Collections::get_instance();
    			$this->items_repo = \Tainacan\Repositories\Items::get_instance();
    			$this->metadata_repo = \Tainacan\Repositories\Metadata::get_instance();
    			$this->item_metadata_repo = \Tainacan\Repositories\Item_Metadata::get_instance();
    
    			$this->remove_import_method('file');
    			$this->remove_import_method('url');
    	}
    
    	public function bulk_collectionss() {
    		for ($c = 1; $c <= 300; $c++) {
    			$collection = new \Tainacan\Entities\Collection();
    			$collection->set_name("col-name-" . $c);
    			$collection->set_status("publish");
    						
    			if ($collection->validate()) {
    				$collection = $this->col_repo->insert($collection);
    				echo "Success: " . $collection->get_id() . "\n";
    			} else {
    				$errors = $collection->get_errors();
    				echo "Error on:" . $collection->get_id() . "\n" . $errors;
    				exit();
    			}
    
    			$col_map = [];
    			$core_title = $collection->get_core_title_metadatum();
    			$core_description = $collection->get_core_description_metadatum();			
    			$col_map[$core_title->get_id()] = 'field1';
    			$col_map[$core_description->get_id()] = 'field12';					
    
    			$this->add_collection([
    					'id' => $collection->get_id(),
    					'mapping' => $col_map,
    					'total_items' => 0,
    					'source_id' => 'col' . $c
    			]);
    		}
    	}
    	
    
    	public function process_item($index, $collection_definition) {
    		$method = 'get_' . $collection_definition['source_id'] . '_item';
    		$item = $this->$method($index);
    		return $item;
    	}
    	
    
    }
    
    // TEST
    
    $bc = new Test_Collections();
    $bc->bulk_collectionss();
    
    • This reply was modified 3 years, 2 months ago by lbov.
    • This reply was modified 3 years, 2 months ago by lbov.
    • This reply was modified 3 years, 2 months ago by lbov.
    • This reply was modified 3 years, 2 months ago by lbov.
    • This reply was modified 3 years, 2 months ago by lbov.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Bulk creation of collections’ is closed to new replies.