From c503863907d7d40b6f3d7c1acaf4977ff5c4d82d Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Thu, 16 Jan 2020 15:20:41 -0300 Subject: [PATCH] remove the abstract class `CommunImportExport` #343 --- .gitignore | 4 + src/exporter/class-tainacan-exporter.php | 190 ++++++++++------------- 2 files changed, 89 insertions(+), 105 deletions(-) diff --git a/.gitignore b/.gitignore index 3b3f9ebf3..7dcb00c0e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ src/vendor node_modules npm-debug.log src/assets/js/*.js +src/assets/*.js last-js-build.md5 last-sass-build.md5 last-composer-build.md5 @@ -19,11 +20,14 @@ src/views/admin/scss/.sass-cache src/assets/css/tainacan-admin.css src/assets/css/tainacan-admin.css.map src/assets/js/report.html +src/assets/report.html .vscode src/pdf-viewer/pdfjs-dist report.txt .tmp demosaved.csv +src/assets/css/tainacan-embeds.css +src/assets/css/tainacan-embeds.css.map .DS_Store src/.DS_Store src/assets/css/tainacan-gutenberg-block-dynamic-items-list.css diff --git a/src/exporter/class-tainacan-exporter.php b/src/exporter/class-tainacan-exporter.php index e35ff4dd7..9fc38c3ea 100644 --- a/src/exporter/class-tainacan-exporter.php +++ b/src/exporter/class-tainacan-exporter.php @@ -3,14 +3,31 @@ namespace Tainacan\Exporter; use Tainacan; use Tainacan\Entities; -abstract class CommunImportExport { +abstract class Exporter { - public function __construct( ) { + public function __construct($attributess = array()) { $this->id = uniqid(); $author = get_current_user_id(); if($author) { $this->add_transient('author', $author); } + + $this->array_attributes = array_merge($this->array_attributes, [ + 'mapping_selected', + 'current_collection_item', + 'current_collection', + 'output_files', + 'send_email' + ]); + + if (!empty($attributess)) { + foreach ($attributess as $attr => $value) { + $method = 'set_' . $attr; + if (method_exists($this, $method)) { + $this->$method($value); + } + } + } } /** @@ -49,9 +66,17 @@ abstract class CommunImportExport { */ protected $steps = [ [ + 'name' => 'Begin Exporter', + 'progress_label' => 'Begin Exporter Process', + 'callback' => 'begin_exporter' + ],[ 'name' => 'Process Items', 'progress_label' => 'Process Items', 'callback' => 'process_collections' + ],[ + 'name' => 'End Exporter', + 'progress_label' => 'End Exporter Process', + 'callback' => 'end_exporter' ] ]; @@ -79,6 +104,63 @@ abstract class CommunImportExport { */ protected $collections = []; + private $output_files = []; + + private $mapping_accept = [ + 'any' => true, + 'list' => false + ]; + + private $send_email = null; + + protected $mapping_list = []; + + public $mapping_selected = ""; + + protected $accept_no_mapping = true; + + /** + * Transients is used to store temporary data to be used accross multiple requests + * + * Add and remove transient data using add_transient() and delete_transient() methods + * + * Transitens can be strings, numbers or arrays. Avoid storing objects. + * + * @var array + */ + protected $transients = []; + + /** + * Wether to abort importer/exporter execution. + * @var bool + */ + protected $abort = false; + + protected $current_step = 0; + + protected $in_step_count = 0; + + protected $current_collection = 0; + + protected $current_collection_item = 0; + + protected $log = []; + + protected $error_log = []; + + /** + * List of attributes that are saved in DB and that are used to + * reconstruct the object, this property need be overwrite in custom import/export. + * @var array + */ + protected $array_attributes = [ + 'in_step_count', + 'current_step', + 'transients', + 'options', + 'collections', + ]; + public function add_collection(array $collection) { if (isset($collection['id'])) { $this->remove_collection($collection['id']); @@ -131,45 +213,6 @@ abstract class CommunImportExport { return false; } - /** - * Transients is used to store temporary data to be used accross multiple requests - * - * Add and remove transient data using add_transient() and delete_transient() methods - * - * Transitens can be strings, numbers or arrays. Avoid storing objects. - * - * @var array - */ - protected $transients = []; - - /** - * Wether to abort importer/exporter execution. - * @var bool - */ - protected $abort = false; - - protected $current_step = 0; - protected $in_step_count = 0; - - protected $current_collection = 0; - protected $current_collection_item = 0; - - protected $log = []; - protected $error_log = []; - - /** - * List of attributes that are saved in DB and that are used to - * reconstruct the object, this property need be overwrite in custom import/export. - * @var array - */ - protected $array_attributes = [ - 'in_step_count', - 'current_step', - 'transients', - 'options', - 'collections', - ]; - /** * @return string */ @@ -470,60 +513,6 @@ abstract class CommunImportExport { return false; } - // Abstract methods - abstract public function _to_Array($short = false); - -} - -//////////////////////////////////// -class Exporter extends CommunImportExport { - - private $output_files = []; - private $mapping_accept = [ - 'any' => true, - 'list' => false - ]; - private $send_email = null; - protected $mapping_list = []; - public $mapping_selected = ""; - protected $accept_no_mapping = true; - - protected $steps = [ - [ - 'name' => 'Begin Exporter', - 'progress_label' => 'Begin Exporter Process', - 'callback' => 'begin_exporter' - ],[ - 'name' => 'Process Items', - 'progress_label' => 'Process Items', - 'callback' => 'process_collections' - ],[ - 'name' => 'End Exporter', - 'progress_label' => 'End Exporter Process', - 'callback' => 'end_exporter' - ] - ]; - - public function __construct($attributess = array()) { - $this->array_attributes = array_merge($this->array_attributes, [ - 'mapping_selected', - 'current_collection_item', - 'current_collection', - 'output_files', - 'send_email' - ]); - parent::__construct(); - - if (!empty($attributess)) { - foreach ($attributess as $attr => $value) { - $method = 'set_' . $attr; - if (method_exists($this, $method)) { - $this->$method($value); - } - } - } - } - public function _to_Array($short = false) { $return = ['id' => $this->get_id()]; foreach ($this->array_attributes as $attr) { @@ -546,13 +535,6 @@ class Exporter extends CommunImportExport { return $return; } - public function add_collection(array $collection) { - // if (!isset($collection['total_items'])) { - // $collection['total_items'] = 10; - // } - parent::add_collection($collection); - } - /** * Gets the current mapper object, if one was chosen by the user, false Otherwise */ @@ -593,9 +575,7 @@ class Exporter extends CommunImportExport { return $this->next_item(); } - public function process_item( $item, $metadata ) { - - } + abstract public function process_item( $item, $metadata ); private function process_header($current_collection_item, $collection_definition) { if ($current_collection_item == 0) {