changes the way importers props are declared and exposes it
This commit is contained in:
parent
ab0b7915ab
commit
dd0796e590
|
@ -5,10 +5,6 @@ use Tainacan;
|
||||||
|
|
||||||
class CSV extends Importer {
|
class CSV extends Importer {
|
||||||
|
|
||||||
protected $manual_mapping = true;
|
|
||||||
|
|
||||||
protected $manual_collection = true;
|
|
||||||
|
|
||||||
public function __construct($attributes = array()) {
|
public function __construct($attributes = array()) {
|
||||||
parent::__construct($attributes);
|
parent::__construct($attributes);
|
||||||
|
|
||||||
|
|
|
@ -20,20 +20,26 @@ class Importer_Handler {
|
||||||
'name' => 'CSV',
|
'name' => 'CSV',
|
||||||
'description' => __('Import items from a CSV file to a chosen collection', 'tainacan'),
|
'description' => __('Import items from a CSV file to a chosen collection', 'tainacan'),
|
||||||
'slug' => 'csv',
|
'slug' => 'csv',
|
||||||
'class_name' => '\Tainacan\Importer\CSV'
|
'class_name' => '\Tainacan\Importer\CSV',
|
||||||
|
'manual_collection' => true,
|
||||||
|
'manual_mapping' => true,
|
||||||
]);
|
]);
|
||||||
$this->register_importer([
|
$this->register_importer([
|
||||||
'name' => 'Test',
|
'name' => 'Test',
|
||||||
'description' => __('Create 2 test colletions with random items', 'tainacan'),
|
'description' => __('Create 2 test colletions with random items', 'tainacan'),
|
||||||
'slug' => 'test',
|
'slug' => 'test',
|
||||||
'class_name' => '\Tainacan\Importer\Test_Importer'
|
'class_name' => '\Tainacan\Importer\Test_Importer',
|
||||||
|
'manual_collection' => false,
|
||||||
|
'manual_mapping' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->register_importer([
|
$this->register_importer([
|
||||||
'name' => 'Tainacan Legacy',
|
'name' => 'Tainacan Legacy',
|
||||||
'description' => __('Import structure from legacy version of Tainacan', 'tainacan'),
|
'description' => __('Import structure from legacy version of Tainacan', 'tainacan'),
|
||||||
'slug' => 'tainacan_old',
|
'slug' => 'tainacan_old',
|
||||||
'class_name' => '\Tainacan\Importer\Old_Tainacan'
|
'class_name' => '\Tainacan\Importer\Old_Tainacan',
|
||||||
|
'manual_collection' => false,
|
||||||
|
'manual_mapping' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
do_action('tainacan_register_importers');
|
do_action('tainacan_register_importers');
|
||||||
|
@ -58,14 +64,48 @@ class Importer_Handler {
|
||||||
/**
|
/**
|
||||||
* Register Importer
|
* Register Importer
|
||||||
*
|
*
|
||||||
* @param array $importer
|
*
|
||||||
* [
|
*
|
||||||
* 'slug' => 'example-importer',
|
* @param array $importer {
|
||||||
* 'class_name' => '\Tainacan\Importer\Test_Importer'
|
* Required. Array or string of arguments describing the importer
|
||||||
* ]
|
*
|
||||||
|
* @type string $name The name of the importer. e.g. 'Example Importer'
|
||||||
|
* @type string $slug A unique slug for the importer. e.g. 'This is an example importer description'
|
||||||
|
* @type string $description The importer description. e.g. 'example-importer'
|
||||||
|
* @type string $class_name The Importer Class. e.g. '\Tainacan\Importer\Test_Importer'
|
||||||
|
* @type bool $manual_mapping Wether Tainacan must present the user with an interface to manually map
|
||||||
|
* the metadata from the source to the target collection.
|
||||||
|
*
|
||||||
|
* If set to true, Importer Class must implement the method
|
||||||
|
* get_source_metadata() to return the metadatum found in the source.
|
||||||
|
*
|
||||||
|
* Note that this will only work when importing items to one single collection.
|
||||||
|
*
|
||||||
|
* @type bool $manual_collection Wether Tainacan will let the user choose a destination collection.
|
||||||
|
*
|
||||||
|
* If set to true, the API endpoints will handle Collection creation and will assign it to
|
||||||
|
* the importer object using add_collection() method.
|
||||||
|
*
|
||||||
|
* Otherwise, the child importer class must create the collections and add them to the collections property also
|
||||||
|
* using add_collection()
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public function register_importer(array $importer) {
|
public function register_importer(array $importer) {
|
||||||
$this->registered_importers[$importer['slug']] = $importer;
|
|
||||||
|
$defaults = [
|
||||||
|
'manual_mapping' => false,
|
||||||
|
'manual_collection' => true
|
||||||
|
];
|
||||||
|
|
||||||
|
$attrs = wp_parse_args($importer, $defaults);
|
||||||
|
|
||||||
|
if (!isset($attrs['slug']) || !isset($attrs['class_name']) || !isset($attrs['name'])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->registered_importers[$importer['slug']] = $attrs;
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unregister_importer($importer_slug) {
|
public function unregister_importer($importer_slug) {
|
||||||
|
|
|
@ -21,31 +21,6 @@ abstract class Importer {
|
||||||
*/
|
*/
|
||||||
protected $tmp_file;
|
protected $tmp_file;
|
||||||
|
|
||||||
/**
|
|
||||||
* Wether Tainacan must present the user with an interface to manually map
|
|
||||||
* the metadata from the source to the target collection.
|
|
||||||
*
|
|
||||||
* If set to true in the child class, it must implement the method
|
|
||||||
* get_source_metadata() to return the metadatum found in the source.
|
|
||||||
*
|
|
||||||
* Note that this will only work when importing items to one single collection.
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $manual_mapping = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wether Tainacan will let the user choose a destination collection.
|
|
||||||
*
|
|
||||||
* If set to true, the API endpoints will handle Collection creation and will assign it to
|
|
||||||
* the importer object using add_collection() method.
|
|
||||||
*
|
|
||||||
* Otherwise, the child importer class must create the collections and add them to the collections property also
|
|
||||||
* using add_collection()
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $manual_collection = true;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This array holds the structure that the default step 'process_collections' will handle.
|
* This array holds the structure that the default step 'process_collections' will handle.
|
||||||
|
@ -188,9 +163,12 @@ abstract class Importer {
|
||||||
}
|
}
|
||||||
$return['class_name'] = get_class($this);
|
$return['class_name'] = get_class($this);
|
||||||
|
|
||||||
|
global $Tainacan_Importer_Handler;
|
||||||
|
$importer_definition = $Tainacan_Importer_Handler->get_importer_by_object($this);
|
||||||
|
|
||||||
if ($short === false) {
|
if ($short === false) {
|
||||||
$return['manual_collection'] = $this->manual_collection;
|
$return['manual_collection'] = $importer_definition['manual_collection'];
|
||||||
$return['manual_mapping'] = $this->manual_mapping;
|
$return['manual_mapping'] = $importer_definition['manual_mapping'];
|
||||||
$return['accepts'] = $this->accepts;
|
$return['accepts'] = $this->accepts;
|
||||||
$return['options_form'] = $this->options_form();
|
$return['options_form'] = $this->options_form();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,6 @@ use \Tainacan\Entities;
|
||||||
|
|
||||||
class Old_Tainacan extends Importer{
|
class Old_Tainacan extends Importer{
|
||||||
|
|
||||||
protected $manual_mapping = false;
|
|
||||||
protected $manual_collection = false;
|
|
||||||
|
|
||||||
protected $steps = [
|
protected $steps = [
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
@ -15,9 +15,6 @@ use \Tainacan\Entities;
|
||||||
|
|
||||||
class Test_Importer extends Importer {
|
class Test_Importer extends Importer {
|
||||||
|
|
||||||
protected $manual_mapping = false;
|
|
||||||
protected $manual_collection = false;
|
|
||||||
|
|
||||||
protected $steps = [
|
protected $steps = [
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue