From 87912f315352dc92d9ca95688378d6a9781be1d9 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sat, 17 Apr 2021 17:58:52 -0300 Subject: [PATCH 01/82] Tiny lints and indentations --- .../importer/class-tainacan-old-tainacan.php | 69 ++++++++----------- 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/src/classes/importer/class-tainacan-old-tainacan.php b/src/classes/importer/class-tainacan-old-tainacan.php index eccf0b8e5..70044e5ef 100644 --- a/src/classes/importer/class-tainacan-old-tainacan.php +++ b/src/classes/importer/class-tainacan-old-tainacan.php @@ -6,7 +6,6 @@ use \Tainacan\Entities; class Old_Tainacan extends Importer{ protected $steps = [ - [ 'name' => 'Create Taxonomies', 'progress_label' => 'Creating taxonomies', @@ -33,7 +32,6 @@ class Old_Tainacan extends Importer{ 'callback' => 'link_relationships', 'total' => 5 ] - ]; protected $tainacan_api_address, $wordpress_api_address, $actual_collection; @@ -64,8 +62,7 @@ class Old_Tainacan extends Importer{ * */ public function create_taxonomies() { - - if(!$this->get_url()){ + if (!$this->get_url()) { $this->add_error_log('Site url not found'); $this->abort(); return false; @@ -74,57 +71,49 @@ class Old_Tainacan extends Importer{ $this->add_log('Creating taxonomies'); foreach ($this->get_taxonomies() as $taxonomy) { + $tax = new Entities\Taxonomy(); + $tax->set_name( $taxonomy->name ); + $tax->set_description( $taxonomy->description ); + $tax->set_allow_insert('yes'); + $tax->set_status('publish'); - $tax = new Entities\Taxonomy(); - $tax->set_name( $taxonomy->name ); - $tax->set_description( $taxonomy->description ); - $tax->set_allow_insert('yes'); - $tax->set_status('publish'); - - if ($tax->validate()) { - $tax = $this->tax_repo->insert($tax); + if ($tax->validate()) { + $tax = $this->tax_repo->insert($tax); $this->add_log('Taxonomy ' . $tax->get_name() . ' created, id from Old'. $taxonomy->term_id ); + $this->add_transient('tax_' . $taxonomy->term_id . '_id', $tax->get_id()); + $this->add_transient('tax_' . $taxonomy->term_id . '_name', $tax->get_name()); - $this->add_transient('tax_' . $taxonomy->term_id . '_id', $tax->get_id()); - $this->add_transient('tax_' . $taxonomy->term_id . '_name', $tax->get_name()); - - if (isset($taxonomy->children) && $tax) { - $this->add_all_terms($tax, $taxonomy->children); - } - + if (isset($taxonomy->children) && $tax) { + $this->add_all_terms($tax, $taxonomy->children); + } } else { - $this->add_log('Error creating taxonomy ' . $taxonomy->name ); - $this->add_log($tax->get_errors()); - - } + $this->add_log('Error creating taxonomy ' . $taxonomy->name ); + $this->add_log($tax->get_errors()); + } + } - } - return false; - } + } /** * create the repository metadata which each collection inherits by default * */ - public function create_repo_metadata(){ - - $this->add_log('Creating repository metadata'); + public function create_repo_metadata() { + $this->add_log('Creating repository metadata'); foreach ($this->get_repo_metadata() as $metadata) { + if (isset($metadata->slug) && strpos($metadata->slug, 'socialdb_property_fixed') === false) { + $metadatum_id = $this->create_metadata( $metadata ); + } elseif ( strpos($metadata->slug, 'socialdb_property_fixed_tags') !== false ) { + $metadatum_id = $this->create_metadata( $metadata ); + } + } - if (isset($metadata->slug) && strpos($metadata->slug, 'socialdb_property_fixed') === false) { - $metadatum_id = $this->create_metadata( $metadata ); - } elseif ( strpos($metadata->slug, 'socialdb_property_fixed_tags') !== false ){ - $metadatum_id = $this->create_metadata( $metadata ); - } - - } - - $this->add_log('FInished repository metadata'); - return false; - } + $this->add_log('FInished repository metadata'); + return false; + } /** * create all collections and its metadata From faa6783af0c5dbbff988027ba45a2df2b45c70f6 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sat, 17 Apr 2021 18:05:11 -0300 Subject: [PATCH 02/82] fixes indents whole file --- .../class-tainacan-oaipmh-importer.php | 1730 ++++++++--------- 1 file changed, 863 insertions(+), 867 deletions(-) diff --git a/src/classes/importer/class-tainacan-oaipmh-importer.php b/src/classes/importer/class-tainacan-oaipmh-importer.php index d9db9e3ab..fc3a702d5 100644 --- a/src/classes/importer/class-tainacan-oaipmh-importer.php +++ b/src/classes/importer/class-tainacan-oaipmh-importer.php @@ -5,872 +5,868 @@ use Tainacan\Entities; class Oaipmh_Importer extends Importer { - protected $steps = [ - [ - 'name' => 'Create Collections', - 'progress_label' => 'Create Collections', - 'callback' => 'create_collections' - ], - [ - 'name' => 'Import Items', - 'progress_label' => 'Import Items', - 'callback' => 'process_collections', - 'total' => 2 - ], - ]; - - protected $NAME_FOR_SETS = 'Sets'; - protected $tainacan_api_address, $wordpress_api_address, $actual_collection; - protected $has_sets = true; - protected $items_per_page = 100; - - /** - * tainacan old importer construct - */ - public function __construct($attributes = array()) { - parent::__construct($attributes); - $this->set_default_options([ - 'delimiter' => ',' - ]); - - $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->tax_repo = \Tainacan\Repositories\Taxonomies::get_instance(); - $this->term_repo = \Tainacan\Repositories\Terms::get_instance(); - - $this->remove_import_method('file'); - $this->add_import_method('url'); - - } - - /** - * Method implemented by the child importer class to proccess each item - * @return int - */ - public function process_item( $index, $collection_id ){ - $this->add_log('Proccess item index' . $index . ' in set ' . $collection_id['source_id'] ); - $records = [ 'records' => [] , 'collection_definition' => $collection_id ]; - $record_processed = []; - - if( $index === 0 ){ - - if( $collection_id['source_id'] !== 'sets' && $this->has_sets ){ - $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $collection_id['source_id'] ); - $this->add_log('fetching ' . $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $collection_id['source_id']); - } else { - $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc" ); - $this->add_log('fetching ' . $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc"); - } - - } else { - $token = $this->get_transient('resumptionToken'); - $info = $this->requester( $this->get_url() . "?verb=ListRecords&resumptionToken=" . $token); - $this->add_log('fetching ' . $this->get_url() . "?verb=ListRecords&resumptionToken=" . $token); - } - - if( !isset($info['body']) ){ - $this->add_log('no answer'); - return false; - } - - - try { - $xml = new \SimpleXMLElement($info['body']); - - if ( isset($xml->ListRecords) && isset($xml->ListRecords->resumptionToken) ){ - - $resumptionToken = $xml->ListRecords->resumptionToken; - if ($resumptionToken) { - $this->add_transient('resumptionToken',(string) $resumptionToken); - } - - // if there is no total in resumption token and exists cursor - // it will change dynamic the total of items - - $resumptionToken_attributes = $xml->ListRecords->resumptionToken->attributes(); - $real_total = $this->get_transient('total_general'); - - foreach ($resumptionToken_attributes as $tag => $attribute) { - - if ( $tag == 'cursor' && $real_total == ( (string) $attribute ) && !$this->hasCompleteSize( $resumptionToken_attributes ) ) { - - $real_total = $real_total + intval($this->get_transient('items_per_page')); - $this->add_transient('total_general', $real_total); - - $total = ( $this->get_transient('change_total') ) ? $this->get_transient('change_total') : 1; - - $this->add_transient('change_total', $total + 1); - break; - } - } - } - - } catch (Exception $e) { - $this->add_log('error on read xml and get '); - return false; - } - - if( $xml->ListRecords ){ - $j = 0; - - while ( isset($xml->ListRecords->record[$j]) ) { - $record = $record = $xml->ListRecords->record[$j]; - $dc = $record->metadata->children("http://www.openarchives.org/OAI/2.0/oai_dc/"); - $header = $record->header; - - $is_inserted = $this->get_transient($header->identifier); - if( $is_inserted ){ - continue; - } - - if( $this->get_option('using_set') == 'taxonomy' && ( isset($header) && isset($header->setSpec) ) ){ - foreach ($header->setSpec as $item ) { - $record_processed['sets'][] = (string) $item; - } - } - - if ($record->metadata->Count() > 0 ) { - $metadata = $dc->children('http://purl.org/dc/elements/1.1/'); - $tam_metadata = count($metadata); - for ($i = 0; $i < $tam_metadata; $i++) { - - $value = (string) $metadata[$i]; - $identifier = $this->get_identifier($metadata[$i]); - $record_processed['dc:' . $identifier ][] = $value; + protected $steps = [ + [ + 'name' => 'Create Collections', + 'progress_label' => 'Create Collections', + 'callback' => 'create_collections' + ], + [ + 'name' => 'Import Items', + 'progress_label' => 'Import Items', + 'callback' => 'process_collections', + 'total' => 2 + ], + ]; + + protected $NAME_FOR_SETS = 'Sets'; + protected $tainacan_api_address, $wordpress_api_address, $actual_collection; + protected $has_sets = true; + protected $items_per_page = 100; + + /** + * tainacan old importer construct + */ + public function __construct($attributes = array()) { + parent::__construct($attributes); + $this->set_default_options([ + 'delimiter' => ',' + ]); + + $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->tax_repo = \Tainacan\Repositories\Taxonomies::get_instance(); + $this->term_repo = \Tainacan\Repositories\Terms::get_instance(); + + $this->remove_import_method('file'); + $this->add_import_method('url'); + } + + /** + * Method implemented by child importer class to proccess each item + * @return int + */ + public function process_item( $index, $collection_id ){ + $this->add_log('Proccess item index' . $index . ' in set ' . $collection_id['source_id'] ); + $records = [ 'records' => [] , 'collection_definition' => $collection_id ]; + $record_processed = []; + + if ($index === 0) { + if( $collection_id['source_id'] !== 'sets' && $this->has_sets ){ + $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $collection_id['source_id'] ); + $this->add_log('fetching ' . $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $collection_id['source_id']); + } else { + $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc" ); + $this->add_log('fetching ' . $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc"); + } + } else { + $token = $this->get_transient('resumptionToken'); + $info = $this->requester( $this->get_url() . "?verb=ListRecords&resumptionToken=" . $token); + $this->add_log('fetching ' . $this->get_url() . "?verb=ListRecords&resumptionToken=" . $token); + } + + if (!isset($info['body'])) { + $this->add_log('no answer'); + return false; + } + + try { + $xml = new \SimpleXMLElement($info['body']); + + if ( isset($xml->ListRecords) && isset($xml->ListRecords->resumptionToken) ){ + + $resumptionToken = $xml->ListRecords->resumptionToken; + if ($resumptionToken) { + $this->add_transient('resumptionToken',(string) $resumptionToken); + } + + // if there is no total in resumption token and exists cursor + // it will change dynamic the total of items + + $resumptionToken_attributes = $xml->ListRecords->resumptionToken->attributes(); + $real_total = $this->get_transient('total_general'); + + foreach ($resumptionToken_attributes as $tag => $attribute) { + + if ( $tag == 'cursor' && $real_total == ( (string) $attribute ) && !$this->hasCompleteSize( $resumptionToken_attributes ) ) { + + $real_total = $real_total + intval($this->get_transient('items_per_page')); + $this->add_transient('total_general', $real_total); + + $total = ( $this->get_transient('change_total') ) ? $this->get_transient('change_total') : 1; + + $this->add_transient('change_total', $total + 1); + break; + } + } + } + + } catch (Exception $e) { + $this->add_log('error on read xml and get '); + return false; + } + + if( $xml->ListRecords ){ + $j = 0; + + while ( isset($xml->ListRecords->record[$j]) ) { + $record = $record = $xml->ListRecords->record[$j]; + $dc = $record->metadata->children("http://www.openarchives.org/OAI/2.0/oai_dc/"); + $header = $record->header; + + $is_inserted = $this->get_transient($header->identifier); + if( $is_inserted ){ + continue; + } + + if( $this->get_option('using_set') == 'taxonomy' && ( isset($header) && isset($header->setSpec) ) ){ + foreach ($header->setSpec as $item ) { + $record_processed['sets'][] = (string) $item; + } + } + + if ($record->metadata->Count() > 0 ) { + $metadata = $dc->children('http://purl.org/dc/elements/1.1/'); + $tam_metadata = count($metadata); + for ($i = 0; $i < $tam_metadata; $i++) { + + $value = (string) $metadata[$i]; + $identifier = $this->get_identifier($metadata[$i]); + $record_processed['dc:' . $identifier ][] = $value; + + } + } + + if( $record_processed ){ + $records['records'][] = $record_processed; + $record_processed = []; + } + + $j++; + } + } + + if( $records['records'] ){ + return $records; + } else { + $this->add_log('proccessing an item empty or xml not found'); + return false; + } + } + + /** + * create all collections and its metadata + * + */ + public function create_collections(){ + + $this->add_log('Creating collections'); + $collection_xml = $this->fetch_collections(); + + if( $collection_xml ){ + + if( !$this->get_option('using_set') || $this->get_option('using_set') == 'collection' ){ + + foreach ($collection_xml as $set ) { - } - } - - if( $record_processed ){ - $records['records'][] = $record_processed; - $record_processed = []; - } - - $j++; - } - } - - if( $records['records'] ){ - return $records; - } else { - $this->add_log('proccessing an item empty or xml not found'); - return false; - } - } - - /** - * create all collections and its metadata - * - */ - public function create_collections(){ - - $this->add_log('Creating collections'); - $collection_xml = $this->fetch_collections(); - - if( $collection_xml ){ - - if( !$this->get_option('using_set') || $this->get_option('using_set') == 'collection' ){ - - foreach ($collection_xml as $set ) { - - $setSpec = (string) $set->setSpec; - $setName = (string) $set->setName; - - $collection = $this->create_collection( $setSpec, $setName ); - - $metadata_map = $this->create_collection_metadata($collection); - $total = intval($this->get_total_items_from_source($setSpec)); - $this->add_log('total in collection: ' . $total); - $this->add_log('collection id ' . (string) $collection->get_id()); - - $this->add_collection([ - 'id' => $collection->get_id(), - 'mapping' => $metadata_map, - 'total_items' => ceil( $total / $this->items_per_page ), - 'source_id' => $setSpec, - ]); - } - } else if( $this->get_option('using_set') == 'taxonomy') { - - $collection = $this->create_collection( 'set', $this->getRepoName() ); - $metadata_map = $this->create_collection_metadata($collection); - $total = intval( $this->get_total_items_from_source(false) ); - $this->add_log('total in collection: ' . $total); - $this->add_log('collection id ' . (string) $collection->get_id()); - - $tax = new Entities\Taxonomy(); - $tax->set_name( $this->NAME_FOR_SETS ); - $tax->set_allow_insert('yes'); - $tax->set_status('publish'); - - if ($tax->validate()) { - - $is_tax_created = $this->get_transient('set_taxonomy_id'); - if( $is_tax_created ){ - $tax = new Entities\Taxonomy( $is_tax_created ); - } else { - $tax = $this->tax_repo->insert($tax); - $this->add_transient('set_taxonomy_id', $tax->get_id()); - } - - $metadatum_set_id = $this->create_set_metadata( $collection->get_id(), $tax->get_id() ); - - if( $metadatum_set_id ){ - $this->add_transient('set_metadatum_id', $metadatum_set_id); - - $this->add_collection([ - 'id' => $collection->get_id(), - 'mapping' => $metadata_map, - 'total_items' =>ceil( $total / $this->items_per_page ), - 'source_id' => 'sets', - 'metadatum_id' => $metadatum_set_id - ]); - } - - $this->add_log('Taxonomy ' . $tax->get_name() . ' created' ); - - foreach ($collection_xml as $set) { - - $setSpec = (string)$set->setSpec; - $setName = (string)$set->setName; - - $this->createTerms( $tax, $setName, $setSpec ); - } - - } else { - $this->add_log('Error creating taxonomy Sets' ); - $this->add_log($tax->get_errors()); - - } - - } - - } - // if there is no set - else { - $collection = $this->create_collection( 'set', $this->getRepoName() ); - $metadata_map = $this->create_collection_metadata($collection); - $total = intval( $this->get_total_items_from_source(false) ); - $this->add_log('total in collection: ' . $total); - $this->add_log('collection id ' . (string) $collection->get_id()); - - $this->add_collection([ - 'id' => $collection->get_id(), - 'mapping' => $metadata_map, - 'total_items' =>ceil( $total / $this->items_per_page ), - ]); - - $this->has_sets = false; - } - - $resumptionToken = $this->get_transient('collection_resump'); - if( $resumptionToken !== ''){ - return 1; - } else { - return false; - } - - } - - /** - * insert processed item from source to Tainacan - * - * @param array $processed_item Associative array with metadatum source's as index with - * its value or values - * @param integet $collection_index The index in the $this->collections array of the collection the item is beeing inserted into - * - * @return Tainacan\Entities\Item Item inserted - */ - public function insert( $processed_item, $collection_index ) { - $this->items_repo->disable_logs(); - $records = $processed_item['records']; - $collection_id = $processed_item['collection_definition']; - $collection = new Entities\Collection($collection_id['id']); - $map = $collection_id['mapping']; - - foreach ( $records as $record ) { - $item = new Entities\Item(); - $item->set_status('publish'); - $item->set_collection( $collection ); - $item->set_title( ( isset($record['dc:title']) ) ? $record['dc:title'][0] : 'title' ); - $item->set_description( '' ); - - $this->add_log( ( isset($record['dc:title']) ) ? $record['dc:title'][0] : 'title' ); - if( $record && $item->validate() ){ - $insertedItem = $this->items_repo->insert( $item ); - - if( isset($record['sets']) ){ - $terms = []; - $metadatum_set_id = $this->get_transient('set_metadatum_id'); - - foreach ($record['sets'] as $set) { - $term_id = $this->get_transient($set); - - if( $term_id ) $terms[] = $term_id; - } - - if( $metadatum_set_id && $terms ){ - $newMetadatum = new Entities\Metadatum($metadatum_set_id); - - $item_metadata = new Entities\Item_Metadata_Entity( $insertedItem, $newMetadatum ); - $item_metadata->set_value($terms); - - if( $item_metadata->validate() ){ - $this->item_metadata_repo->insert( $item_metadata ); - } - } - - unset($record['sets']); - } - - foreach ( $record as $index => $value ){ - - if( in_array( $index, $map ) && $insertedItem->get_id()){ - $metadatum_id = array_search($index, $map ); - $newMetadatum = new Entities\Metadatum($metadatum_id); - - $item_metadata = new Entities\Item_Metadata_Entity( $insertedItem, $newMetadatum ); - - $unique = !$item_metadata->is_multiple(); - $value_final = ( is_array($value) && $unique ) ? $value[0] : $value; - $item_metadata->set_value($value_final); - - if( $item_metadata->validate() ){ - $inserted = $this->item_metadata_repo->insert( $item_metadata ); - // $this->add_log('Item Metadata inserted for item ' .$item->get_title() . ' and metadata ' . $newMetadatum->get_name() ); - } else { - $this->add_log( 'Error inserting metadatum' . $newMetadatum->get_name() ); - $this->add_log( 'Values' . $value ); - $this->add_log( $item_metadata->get_errors() ); - } - } - - } - } else { - $this->add_log('item not inserted '); - } - - } - - return isset($insertedItem) ? $insertedItem : false; - } - - //protected functions - - /** - * @signature - get_identifyier($metadata) - * @param \SimpleXMLElement $metadata - * @return string O identifier - */ - protected function get_identifier($metadata) { - $attributes = $metadata->attributes(); // atributos - if ($attributes) { - foreach ($attributes as $a => $b) { - return $metadata->getName().'_'.(string) $b; - } - } else { - return $metadata->getName(); - } - } - - - /** - * Method implemented by the child importer class to return the number of items to be imported - * @return int - */ - public function get_total_items_from_source( $setSpec ) { - - if($setSpec) - $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $setSpec); - else - $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc"); - - if( !isset($info['body']) ){ - $this->add_log('ERROR'); - $this->add_error_log('Error in fetch remote total items'); - $this->abort(); - return false; - } - - try { - $xml = new \SimpleXMLElement($info['body']); - - if( isset($xml->ListRecords) && !isset($xml->ListRecords->resumptionToken) ){ - $cont = 0; - foreach ($xml->ListRecords->record as $record) $cont++; - - $this->add_transient('total_general', (string) $cont ); - return $cont; - } elseif ( isset($xml->ListRecords) && isset($xml->ListRecords->resumptionToken) ){ - - $resumptionToken_attributes = $xml->ListRecords->resumptionToken->attributes(); - - foreach ($resumptionToken_attributes as $tag => $attribute) { - if ($tag == 'completeListSize') { - $this->add_transient('total_general', (string) $attribute); - return (string) $attribute; - } - } - - foreach ($resumptionToken_attributes as $tag => $attribute) { - if ($tag == 'cursor') { - $this->items_per_page = $attribute; - $this->add_transient('items_per_page', (string) $this->items_per_page); - } - } - - // if the total is not found - $this->add_transient('total_general', (string) $this->items_per_page); - return $this->items_per_page; - } - } catch (Exception $e) { - $this->add_log('ERROR'); - return 0; - } - - return 0; - } - - /** - * create the collection in tainacan - * - * @return Entities\Collection - */ - protected function create_collection( $setSpec, $setName ){ - $is_created = $this->get_transient('collection_' . $setSpec. '_name'); - if( $is_created ){ - $new_collection = new Entities\Collection( $is_created ); - return $new_collection; - } - - $new_collection = new Entities\Collection(); - $new_collection->set_name($setName); - $new_collection->set_status('publish'); - $new_collection->validate(); - - - if($new_collection->validate()){ - $new_collection =$this->col_repo->insert($new_collection); - - $this->add_log('Collection created: ' . $new_collection->get_name()); - - if( $new_collection ) - $this->add_transient('collection_' . $setSpec. '_name', $new_collection->get_id()); - - return $new_collection; - } else{ - $this->add_error_log('Error creating collection ' . $setName ); - $this->add_error_log($new_collection->get_errors()); - $this->abort(); - return false; - } - - } - - /** - * @param $collection_object - * @throws \ErrorException - */ - protected function create_collection_metadata( $collection_object ){ - $Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance(); - $mapper_obj = $Tainacan_Mappers->check_class_name('dublin-core', true, $Tainacan_Mappers::MAPPER_CLASS_PREFIX); - $mapper = new $mapper_obj; - $array_metadata = []; - - $mapper_metadata = $mapper->metadata; - if(is_array($mapper_metadata) ) { - $id = $collection_object->get_id(); - - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - foreach ($mapper_metadata as $slug => $mapper_metadatum) { - if( array_key_exists('core_metadatum', $mapper_metadatum) ) { - $method = 'get_core_' . $mapper_metadatum['core_metadatum'] . '_metadatum'; - if (method_exists($collection_object, $method)) { - $core_meta = $collection_object->$method(); - if ( ! $core_meta ) { - $Tainacan_Metadata->register_core_metadata( $collection_object, true ); - $core_meta = $collection_object->$method(); - } - $_meta_mapping = $core_meta->get_exposer_mapping(); - $_meta_mapping[$mapper->slug] = $slug; - $core_meta->set_exposer_mapping($_meta_mapping); - if ($core_meta->validate()) { - $new_metadata = $Tainacan_Metadata->insert($core_meta); - $array_metadata[$new_metadata->get_id()] = $slug; - } - } - continue; - } - - $metadatum = new \Tainacan\Entities\Metadatum(); - if( - array_key_exists('metadata_type', $mapper_metadatum) && - $mapper_metadatum['metadata_type'] != false && - class_exists($mapper_metadatum['metadata_type']) - ) { - $metadatum->set_metadata_type($mapper_metadatum['metadata_type']); - } else { - $metadatum->set_metadata_type('Tainacan\Metadata_Types\Text'); - } - $metadatum->set_name($mapper_metadatum['label']); - $metadatum->set_semantic_uri($mapper->get_url($slug)); - $metadatum->set_exposer_mapping([ - $mapper->slug => $slug - ]); - $metadatum->set_status('publish'); - $metadatum->set_collection_id($id); - $metadatum->set_slug($slug); - - if($metadatum->validate()){ - - $metadatum_id_created = $this->get_transient('collection_' . $id . '_' . $slug ); - if( $metadatum_id_created ){ - $array_metadata[$metadatum_id_created] = $slug; - } else { - $new_metadata = $Tainacan_Metadata->insert($metadatum); - $array_metadata[$new_metadata->get_id()] = $slug; - } - - } - } - } - - return $array_metadata; - } - - /** - * return all taxonomies from tainacan old - * @return array - */ - protected function fetch_collections(){ - - $collections_array = []; - // block terms with same set spec - $resumptionToken = $this->get_transient('collection_resump'); - if( $resumptionToken ){ - $collections_link = $this->get_url() . "?verb=ListSets&resumptionToken=" . $resumptionToken; - } else { - $collections_link = $this->get_url() . "?verb=ListSets"; - } - - $collections = $this->requester($collections_link); - $xml = $this->decode_request($collections, $collections_link); - - if( isset($xml->ListSets->set) ) { - foreach ($xml->ListSets->set as $set) { - - $collections_array[] = $set; - } - } - - if( isset($xml->ListSets) && isset($xml->ListSets->resumptionToken) ){ - $this->add_transient('collection_resump',(string) $xml->ListSets->resumptionToken); - } else { - $this->add_transient('collection_resump', (string) $xml->ListSets->resumptionToken); - } - - // TODO: verify if exists resumption token - - return ($collections_array) ? $collections_array : []; - } - - /** - * decode request from wp_remote - * @return array/bool - */ - protected function decode_request($result, $url){ - if (is_wp_error($result)) { - - $this->add_error_log($result->get_error_message()); - $this->add_error_log('Error in fetch remote' . $url); - $this->abort(); - return false; - - } else if (isset($result['body'])){ - - try { - $xml = new \SimpleXMLElement($result['body']); - return $xml; - } catch (Exception $e) { - return false; - } - } - - $this->add_error_log('Error in fetch remote'); - $this->abort(); - return false; - } - - /** - * executes the request - */ - protected function requester( $link ){ - $has_response = false; - $requests = 0; - - $args = array( - 'timeout' => 60, - 'redirection' => 30, - 'sslverify' => false - ); - - $this->add_log('fetching init ' . $link ); - $result = wp_remote_get($link, $args); - - while( !$has_response ){ - - if (is_wp_error($result)) { - - $this->add_log($result->get_error_message()); - $this->add_log('Error in fetch remote' . $link); - $this->add_log('request number ' . $requests); - - } else if (isset($result['body'])){ - $this->add_log('fetch OK '); - return $result; - } - - if( $requests > 10 ){ - break; - } - - if( $requests > 3 ){ - $this->add_log('taking a moment to breathe, waiting for ' . ( $requests * 10 ) . ' seconds ' ); - sleep( $requests * 10 ); - } - - $args = array( - 'timeout' => 60, - 'redirection' => 30, - 'sslverify' => false - ); - - $result = wp_remote_get($link, $args); - - $requests++; - $this->add_log('going to ' . $requests ); - } - - - - $this->add_error_log('Error in fetch remote, expired the 10 requests limit ' . $link); - $this->abort(); - return false; - } - - /** - * @param $taxonomy_father - * @param $name - * @param $slug - * @return bool - */ - public function createTerms( $taxonomy_father, $name, $slug ){ - $new_term = new Entities\Term(); - $new_term->set_taxonomy($taxonomy_father->get_db_identifier()); - $new_term->set_name($name); - - // block terms with same set spec - $map = $this->get_transient($slug); - - if($map){ - return false; - } - - if ($new_term->validate()) { - $inserted_term = $this->term_repo->insert($new_term); - } else { - $this->add_log( implode(',', $new_term->get_errors()) ); - return false; - } - - - if (is_wp_error($inserted_term)) { - - $this->add_log($inserted_term->get_error_message()); - - } else { - $this->add_transient($slug, $inserted_term->get_id()); - $this->add_log('Added term: ' . $inserted_term->get_name() . ' in tax: ' . $taxonomy_father->get_name()); - return true; - } - - return false; - } - - /** - * @param $collection_id - * @param $taxonomy_id - * @return bool|int - * @throws \Exception - */ - public function create_set_metadata( $collection_id, $taxonomy_id ){ - $newMetadatum = new Entities\Metadatum(); - - $name = $this->NAME_FOR_SETS; - $type = 'Taxonomy'; - - $newMetadatum->set_name($name); - $newMetadatum->set_metadata_type('Tainacan\Metadata_Types\\'.$type); - $newMetadatum->set_collection_id( (isset($collection_id)) ? $collection_id : 'default'); - $newMetadatum->set_status('publish'); - $newMetadatum->set_metadata_type_options(['taxonomy_id' => $taxonomy_id ]); - $newMetadatum->set_multiple('yes'); - - if($newMetadatum->validate()){ - $is_meta_created = $this->get_transient('set_metadatum_id'); - if( $is_meta_created ){ - $inserted_metadata = new Entities\Metadatum($is_meta_created); - - $this->add_log('Metadata get: ' . $inserted_metadata->get_name()); - } else { - $inserted_metadata = $this->metadata_repo->insert( $newMetadatum ); - - $this->add_log('Metadata created: ' . $inserted_metadata->get_name()); - } - - return $inserted_metadata->get_id(); - } else{ - return false; - } - } - - public function getRepoName(){ - $info = $this->requester( $this->get_url() . "?verb=Identify"); - - if( !isset($info['body']) ){ - $this->add_log('ERROR on get repo name'); - $this->add_error_log('Error in fetch remote total items'); - $this->abort(); - return __('Imported Repo'); - } else { - - try { - $xml = new \SimpleXMLElement($info['body']); - - if( isset($xml->Identify) && isset($xml->Identify->repositoryName) && !empty($xml->Identify->repositoryName) ){ - return (string) $xml->Identify->repositoryName; - } - } catch (Exception $e) { - return __('Imported Repo'); - } - - return __('Imported Repo'); - - } - } - - /** - * @param $attributes - * @return bool - */ - public function hasCompleteSize( $attributes ) { - foreach ( $attributes as $tag => $attribute ) { - if ( $tag == 'completeListSize' ) { - return true; - } - } - return false; - } - - /** - * Gets the current value to build the progress bar and give feedback to the user - * on the background process that is running the importer. - * - * It does so by comparing the "size" attribute with the $in_step_count class attribute - * where size indicates the total size of iterations the step will take and $this->in_step_count - * is the current iteration. - * - * For the step with "process_items" as a callback, this method will look for the the $this->collections array - * and sum the value of all "total_items" attributes of each collection. Then it will look for - * $this->get_current_collection and $this->set_current_collection_item to calculate the progress. - * - * The value must be from 0 to 100 - * - * If a negative value is passed, it is assumed that the progress is unknown - */ - public function get_progress_value() { - $current_step = $this->get_current_step(); - $steps = $this->get_steps(); - $value = -1; - - if ( isset($steps[$current_step]) ) { - $step = $steps[$current_step]; - - if ($step['callback'] == 'process_collections') { - - $totalItems = 0; - $currentItem = $this->get_current_collection_item(); - $current_collection = $this->get_current_collection(); - $collections = $this->get_collections(); - - foreach ($collections as $i => $col) { - if ( isset($col['total_items']) && is_numeric($col['total_items']) ) { - $totalItems += intval($col['total_items']); - if ($i < $current_collection) { - $currentItem += $col['total_items']; - } - } - } - - if ($totalItems > 0) { - $totalItems = ($this->get_transient('change_total')) ? $this->get_transient('change_total') : $totalItems; - $value = round( ($currentItem/$totalItems) * 100 ); - } - - - } else { - - if ( isset($step['total']) && is_numeric($step['total']) && $step['total'] > 0 ) { - $total = ($this->get_transient('change_total')) ? $this->get_transient('change_total') : $step['total']; - - $current = $this->get_in_step_count(); - $value = round( ($current/$total) * 100 ); - } - - } - - - } - return $value; - } - - public function options_form(){ - ob_start(); - ?> -
-
-
- - - - - - - - -
-
-
-
-

-
-
-
-
-
- -
-
-
-
-
- setSpec; + $setName = (string) $set->setName; + + $collection = $this->create_collection( $setSpec, $setName ); + + $metadata_map = $this->create_collection_metadata($collection); + $total = intval($this->get_total_items_from_source($setSpec)); + $this->add_log('total in collection: ' . $total); + $this->add_log('collection id ' . (string) $collection->get_id()); + + $this->add_collection([ + 'id' => $collection->get_id(), + 'mapping' => $metadata_map, + 'total_items' => ceil( $total / $this->items_per_page ), + 'source_id' => $setSpec, + ]); + } + } else if( $this->get_option('using_set') == 'taxonomy') { + + $collection = $this->create_collection( 'set', $this->getRepoName() ); + $metadata_map = $this->create_collection_metadata($collection); + $total = intval( $this->get_total_items_from_source(false) ); + $this->add_log('total in collection: ' . $total); + $this->add_log('collection id ' . (string) $collection->get_id()); + + $tax = new Entities\Taxonomy(); + $tax->set_name( $this->NAME_FOR_SETS ); + $tax->set_allow_insert('yes'); + $tax->set_status('publish'); + + if ($tax->validate()) { + + $is_tax_created = $this->get_transient('set_taxonomy_id'); + if( $is_tax_created ){ + $tax = new Entities\Taxonomy( $is_tax_created ); + } else { + $tax = $this->tax_repo->insert($tax); + $this->add_transient('set_taxonomy_id', $tax->get_id()); + } + + $metadatum_set_id = $this->create_set_metadata( $collection->get_id(), $tax->get_id() ); + + if( $metadatum_set_id ){ + $this->add_transient('set_metadatum_id', $metadatum_set_id); + + $this->add_collection([ + 'id' => $collection->get_id(), + 'mapping' => $metadata_map, + 'total_items' =>ceil( $total / $this->items_per_page ), + 'source_id' => 'sets', + 'metadatum_id' => $metadatum_set_id + ]); + } + + $this->add_log('Taxonomy ' . $tax->get_name() . ' created' ); + + foreach ($collection_xml as $set) { + + $setSpec = (string)$set->setSpec; + $setName = (string)$set->setName; + + $this->createTerms( $tax, $setName, $setSpec ); + } + + } else { + $this->add_log('Error creating taxonomy Sets' ); + $this->add_log($tax->get_errors()); + + } + + } + + } + // if there is no set + else { + $collection = $this->create_collection( 'set', $this->getRepoName() ); + $metadata_map = $this->create_collection_metadata($collection); + $total = intval( $this->get_total_items_from_source(false) ); + $this->add_log('total in collection: ' . $total); + $this->add_log('collection id ' . (string) $collection->get_id()); + + $this->add_collection([ + 'id' => $collection->get_id(), + 'mapping' => $metadata_map, + 'total_items' =>ceil( $total / $this->items_per_page ), + ]); + + $this->has_sets = false; + } + + $resumptionToken = $this->get_transient('collection_resump'); + if( $resumptionToken !== ''){ + return 1; + } else { + return false; + } + + } + + /** + * insert processed item from source to Tainacan + * + * @param array $processed_item Associative array with metadatum source's as index with + * its value or values + * @param integet $collection_index The index in the $this->collections array of the collection the item is beeing inserted into + * + * @return Tainacan\Entities\Item Item inserted + */ + public function insert( $processed_item, $collection_index ) { + $this->items_repo->disable_logs(); + $records = $processed_item['records']; + $collection_id = $processed_item['collection_definition']; + $collection = new Entities\Collection($collection_id['id']); + $map = $collection_id['mapping']; + + foreach ( $records as $record ) { + $item = new Entities\Item(); + $item->set_status('publish'); + $item->set_collection( $collection ); + $item->set_title( ( isset($record['dc:title']) ) ? $record['dc:title'][0] : 'title' ); + $item->set_description( '' ); + + $this->add_log( ( isset($record['dc:title']) ) ? $record['dc:title'][0] : 'title' ); + if( $record && $item->validate() ){ + $insertedItem = $this->items_repo->insert( $item ); + + if( isset($record['sets']) ){ + $terms = []; + $metadatum_set_id = $this->get_transient('set_metadatum_id'); + + foreach ($record['sets'] as $set) { + $term_id = $this->get_transient($set); + + if( $term_id ) $terms[] = $term_id; + } + + if( $metadatum_set_id && $terms ){ + $newMetadatum = new Entities\Metadatum($metadatum_set_id); + + $item_metadata = new Entities\Item_Metadata_Entity( $insertedItem, $newMetadatum ); + $item_metadata->set_value($terms); + + if( $item_metadata->validate() ){ + $this->item_metadata_repo->insert( $item_metadata ); + } + } + + unset($record['sets']); + } + + foreach ( $record as $index => $value ){ + + if( in_array( $index, $map ) && $insertedItem->get_id()){ + $metadatum_id = array_search($index, $map ); + $newMetadatum = new Entities\Metadatum($metadatum_id); + + $item_metadata = new Entities\Item_Metadata_Entity( $insertedItem, $newMetadatum ); + + $unique = !$item_metadata->is_multiple(); + $value_final = ( is_array($value) && $unique ) ? $value[0] : $value; + $item_metadata->set_value($value_final); + + if( $item_metadata->validate() ){ + $inserted = $this->item_metadata_repo->insert( $item_metadata ); + // $this->add_log('Item Metadata inserted for item ' .$item->get_title() . ' and metadata ' . $newMetadatum->get_name() ); + } else { + $this->add_log( 'Error inserting metadatum' . $newMetadatum->get_name() ); + $this->add_log( 'Values' . $value ); + $this->add_log( $item_metadata->get_errors() ); + } + } + + } + } else { + $this->add_log('item not inserted '); + } + + } + + return isset($insertedItem) ? $insertedItem : false; + } + + //protected functions + + /** + * @signature - get_identifyier($metadata) + * @param \SimpleXMLElement $metadata + * @return string O identifier + */ + protected function get_identifier($metadata) { + $attributes = $metadata->attributes(); // atributos + if ($attributes) { + foreach ($attributes as $a => $b) { + return $metadata->getName().'_'.(string) $b; + } + } else { + return $metadata->getName(); + } + } + + + /** + * Method implemented by the child importer class to return the number of items to be imported + * @return int + */ + public function get_total_items_from_source( $setSpec ) { + + if($setSpec) + $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc&set=" . $setSpec); + else + $info = $this->requester( $this->get_url() . "?verb=ListRecords&metadataPrefix=oai_dc"); + + if( !isset($info['body']) ){ + $this->add_log('ERROR'); + $this->add_error_log('Error in fetch remote total items'); + $this->abort(); + return false; + } + + try { + $xml = new \SimpleXMLElement($info['body']); + + if( isset($xml->ListRecords) && !isset($xml->ListRecords->resumptionToken) ){ + $cont = 0; + foreach ($xml->ListRecords->record as $record) $cont++; + + $this->add_transient('total_general', (string) $cont ); + return $cont; + } elseif ( isset($xml->ListRecords) && isset($xml->ListRecords->resumptionToken) ){ + + $resumptionToken_attributes = $xml->ListRecords->resumptionToken->attributes(); + + foreach ($resumptionToken_attributes as $tag => $attribute) { + if ($tag == 'completeListSize') { + $this->add_transient('total_general', (string) $attribute); + return (string) $attribute; + } + } + + foreach ($resumptionToken_attributes as $tag => $attribute) { + if ($tag == 'cursor') { + $this->items_per_page = $attribute; + $this->add_transient('items_per_page', (string) $this->items_per_page); + } + } + + // if the total is not found + $this->add_transient('total_general', (string) $this->items_per_page); + return $this->items_per_page; + } + } catch (Exception $e) { + $this->add_log('ERROR'); + return 0; + } + + return 0; + } + + /** + * create the collection in tainacan + * + * @return Entities\Collection + */ + protected function create_collection( $setSpec, $setName ){ + $is_created = $this->get_transient('collection_' . $setSpec. '_name'); + if( $is_created ){ + $new_collection = new Entities\Collection( $is_created ); + return $new_collection; + } + + $new_collection = new Entities\Collection(); + $new_collection->set_name($setName); + $new_collection->set_status('publish'); + $new_collection->validate(); + + + if($new_collection->validate()){ + $new_collection =$this->col_repo->insert($new_collection); + + $this->add_log('Collection created: ' . $new_collection->get_name()); + + if( $new_collection ) + $this->add_transient('collection_' . $setSpec. '_name', $new_collection->get_id()); + + return $new_collection; + } else{ + $this->add_error_log('Error creating collection ' . $setName ); + $this->add_error_log($new_collection->get_errors()); + $this->abort(); + return false; + } + + } + + /** + * @param $collection_object + * @throws \ErrorException + */ + protected function create_collection_metadata( $collection_object ){ + $Tainacan_Mappers = \Tainacan\Mappers_Handler::get_instance(); + $mapper_obj = $Tainacan_Mappers->check_class_name('dublin-core', true, $Tainacan_Mappers::MAPPER_CLASS_PREFIX); + $mapper = new $mapper_obj; + $array_metadata = []; + + $mapper_metadata = $mapper->metadata; + if(is_array($mapper_metadata) ) { + $id = $collection_object->get_id(); + + $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); + foreach ($mapper_metadata as $slug => $mapper_metadatum) { + if( array_key_exists('core_metadatum', $mapper_metadatum) ) { + $method = 'get_core_' . $mapper_metadatum['core_metadatum'] . '_metadatum'; + if (method_exists($collection_object, $method)) { + $core_meta = $collection_object->$method(); + if ( ! $core_meta ) { + $Tainacan_Metadata->register_core_metadata( $collection_object, true ); + $core_meta = $collection_object->$method(); + } + $_meta_mapping = $core_meta->get_exposer_mapping(); + $_meta_mapping[$mapper->slug] = $slug; + $core_meta->set_exposer_mapping($_meta_mapping); + if ($core_meta->validate()) { + $new_metadata = $Tainacan_Metadata->insert($core_meta); + $array_metadata[$new_metadata->get_id()] = $slug; + } + } + continue; + } + + $metadatum = new \Tainacan\Entities\Metadatum(); + if( + array_key_exists('metadata_type', $mapper_metadatum) && + $mapper_metadatum['metadata_type'] != false && + class_exists($mapper_metadatum['metadata_type']) + ) { + $metadatum->set_metadata_type($mapper_metadatum['metadata_type']); + } else { + $metadatum->set_metadata_type('Tainacan\Metadata_Types\Text'); + } + $metadatum->set_name($mapper_metadatum['label']); + $metadatum->set_semantic_uri($mapper->get_url($slug)); + $metadatum->set_exposer_mapping([ + $mapper->slug => $slug + ]); + $metadatum->set_status('publish'); + $metadatum->set_collection_id($id); + $metadatum->set_slug($slug); + + if($metadatum->validate()){ + + $metadatum_id_created = $this->get_transient('collection_' . $id . '_' . $slug ); + if( $metadatum_id_created ){ + $array_metadata[$metadatum_id_created] = $slug; + } else { + $new_metadata = $Tainacan_Metadata->insert($metadatum); + $array_metadata[$new_metadata->get_id()] = $slug; + } + + } + } + } + + return $array_metadata; + } + + /** + * return all taxonomies from tainacan old + * @return array + */ + protected function fetch_collections(){ + + $collections_array = []; + // block terms with same set spec + $resumptionToken = $this->get_transient('collection_resump'); + if( $resumptionToken ){ + $collections_link = $this->get_url() . "?verb=ListSets&resumptionToken=" . $resumptionToken; + } else { + $collections_link = $this->get_url() . "?verb=ListSets"; + } + + $collections = $this->requester($collections_link); + $xml = $this->decode_request($collections, $collections_link); + + if( isset($xml->ListSets->set) ) { + foreach ($xml->ListSets->set as $set) { + + $collections_array[] = $set; + } + } + + if( isset($xml->ListSets) && isset($xml->ListSets->resumptionToken) ){ + $this->add_transient('collection_resump',(string) $xml->ListSets->resumptionToken); + } else { + $this->add_transient('collection_resump', (string) $xml->ListSets->resumptionToken); + } + + // TODO: verify if exists resumption token + + return ($collections_array) ? $collections_array : []; + } + + /** + * decode request from wp_remote + * @return array/bool + */ + protected function decode_request($result, $url){ + if (is_wp_error($result)) { + + $this->add_error_log($result->get_error_message()); + $this->add_error_log('Error in fetch remote' . $url); + $this->abort(); + return false; + + } else if (isset($result['body'])){ + + try { + $xml = new \SimpleXMLElement($result['body']); + return $xml; + } catch (Exception $e) { + return false; + } + } + + $this->add_error_log('Error in fetch remote'); + $this->abort(); + return false; + } + + /** + * executes the request + */ + protected function requester( $link ){ + $has_response = false; + $requests = 0; + + $args = array( + 'timeout' => 60, + 'redirection' => 30, + 'sslverify' => false + ); + + $this->add_log('fetching init ' . $link ); + $result = wp_remote_get($link, $args); + + while( !$has_response ){ + + if (is_wp_error($result)) { + + $this->add_log($result->get_error_message()); + $this->add_log('Error in fetch remote' . $link); + $this->add_log('request number ' . $requests); + + } else if (isset($result['body'])){ + $this->add_log('fetch OK '); + return $result; + } + + if( $requests > 10 ){ + break; + } + + if( $requests > 3 ){ + $this->add_log('taking a moment to breathe, waiting for ' . ( $requests * 10 ) . ' seconds ' ); + sleep( $requests * 10 ); + } + + $args = array( + 'timeout' => 60, + 'redirection' => 30, + 'sslverify' => false + ); + + $result = wp_remote_get($link, $args); + + $requests++; + $this->add_log('going to ' . $requests ); + } + + + + $this->add_error_log('Error in fetch remote, expired the 10 requests limit ' . $link); + $this->abort(); + return false; + } + + /** + * @param $taxonomy_father + * @param $name + * @param $slug + * @return bool + */ + public function createTerms( $taxonomy_father, $name, $slug ){ + $new_term = new Entities\Term(); + $new_term->set_taxonomy($taxonomy_father->get_db_identifier()); + $new_term->set_name($name); + + // block terms with same set spec + $map = $this->get_transient($slug); + + if($map){ + return false; + } + + if ($new_term->validate()) { + $inserted_term = $this->term_repo->insert($new_term); + } else { + $this->add_log( implode(',', $new_term->get_errors()) ); + return false; + } + + + if (is_wp_error($inserted_term)) { + + $this->add_log($inserted_term->get_error_message()); + + } else { + $this->add_transient($slug, $inserted_term->get_id()); + $this->add_log('Added term: ' . $inserted_term->get_name() . ' in tax: ' . $taxonomy_father->get_name()); + return true; + } + + return false; + } + + /** + * @param $collection_id + * @param $taxonomy_id + * @return bool|int + * @throws \Exception + */ + public function create_set_metadata( $collection_id, $taxonomy_id ){ + $newMetadatum = new Entities\Metadatum(); + + $name = $this->NAME_FOR_SETS; + $type = 'Taxonomy'; + + $newMetadatum->set_name($name); + $newMetadatum->set_metadata_type('Tainacan\Metadata_Types\\'.$type); + $newMetadatum->set_collection_id( (isset($collection_id)) ? $collection_id : 'default'); + $newMetadatum->set_status('publish'); + $newMetadatum->set_metadata_type_options(['taxonomy_id' => $taxonomy_id ]); + $newMetadatum->set_multiple('yes'); + + if($newMetadatum->validate()){ + $is_meta_created = $this->get_transient('set_metadatum_id'); + if( $is_meta_created ){ + $inserted_metadata = new Entities\Metadatum($is_meta_created); + + $this->add_log('Metadata get: ' . $inserted_metadata->get_name()); + } else { + $inserted_metadata = $this->metadata_repo->insert( $newMetadatum ); + + $this->add_log('Metadata created: ' . $inserted_metadata->get_name()); + } + + return $inserted_metadata->get_id(); + } else{ + return false; + } + } + + public function getRepoName(){ + $info = $this->requester( $this->get_url() . "?verb=Identify"); + + if( !isset($info['body']) ){ + $this->add_log('ERROR on get repo name'); + $this->add_error_log('Error in fetch remote total items'); + $this->abort(); + return __('Imported Repo'); + } else { + + try { + $xml = new \SimpleXMLElement($info['body']); + + if( isset($xml->Identify) && isset($xml->Identify->repositoryName) && !empty($xml->Identify->repositoryName) ){ + return (string) $xml->Identify->repositoryName; + } + } catch (Exception $e) { + return __('Imported Repo'); + } + + return __('Imported Repo'); + + } + } + + /** + * @param $attributes + * @return bool + */ + public function hasCompleteSize( $attributes ) { + foreach ( $attributes as $tag => $attribute ) { + if ( $tag == 'completeListSize' ) { + return true; + } + } + return false; + } + + /** + * Gets the current value to build the progress bar and give feedback to the user + * on the background process that is running the importer. + * + * It does so by comparing the "size" attribute with the $in_step_count class attribute + * where size indicates the total size of iterations the step will take and $this->in_step_count + * is the current iteration. + * + * For the step with "process_items" as a callback, this method will look for the the $this->collections array + * and sum the value of all "total_items" attributes of each collection. Then it will look for + * $this->get_current_collection and $this->set_current_collection_item to calculate the progress. + * + * The value must be from 0 to 100 + * + * If a negative value is passed, it is assumed that the progress is unknown + */ + public function get_progress_value() { + $current_step = $this->get_current_step(); + $steps = $this->get_steps(); + $value = -1; + + if ( isset($steps[$current_step]) ) { + $step = $steps[$current_step]; + + if ($step['callback'] == 'process_collections') { + + $totalItems = 0; + $currentItem = $this->get_current_collection_item(); + $current_collection = $this->get_current_collection(); + $collections = $this->get_collections(); + + foreach ($collections as $i => $col) { + if ( isset($col['total_items']) && is_numeric($col['total_items']) ) { + $totalItems += intval($col['total_items']); + if ($i < $current_collection) { + $currentItem += $col['total_items']; + } + } + } + + if ($totalItems > 0) { + $totalItems = ($this->get_transient('change_total')) ? $this->get_transient('change_total') : $totalItems; + $value = round( ($currentItem/$totalItems) * 100 ); + } + + + } else { + + if ( isset($step['total']) && is_numeric($step['total']) && $step['total'] > 0 ) { + $total = ($this->get_transient('change_total')) ? $this->get_transient('change_total') : $step['total']; + + $current = $this->get_in_step_count(); + $value = round( ($current/$total) * 100 ); + } + + } + + + } + return $value; + } + + public function options_form(){ + ob_start(); + ?> +
+
+
+ + + + + + + + +
+
+
+
+

+
+
+
+
+
+ +
+
+
+
+
+ Date: Sun, 18 Apr 2021 13:24:30 -0300 Subject: [PATCH 03/82] Tiny lints --- tests/__test-api-exposers.php | 2 -- tests/test-api-importers.php | 10 +++------- tests/test-taxonomies.php | 13 ++----------- tests/test-utilities.php | 6 +----- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/tests/__test-api-exposers.php b/tests/__test-api-exposers.php index fb61f84ca..bfedf2239 100644 --- a/tests/__test-api-exposers.php +++ b/tests/__test-api-exposers.php @@ -536,5 +536,3 @@ class TAINACAN_REST_Exposers extends TAINACAN_UnitApiTestCase { } */// TODO automate test this } - -?> \ No newline at end of file diff --git a/tests/test-api-importers.php b/tests/test-api-importers.php index 1e064b01f..0efc9522b 100644 --- a/tests/test-api-importers.php +++ b/tests/test-api-importers.php @@ -7,10 +7,8 @@ namespace Tainacan\Tests; */ class TAINACAN_REST_Importers_Controller extends TAINACAN_UnitApiTestCase { - public function test_create(){ - $params = json_encode([ - 'importer_slug' => 'csv' - ]); + public function test_create() { + $params = json_encode([ 'importer_slug' => 'csv' ]); $request = new \WP_REST_Request('POST', $this->namespace . '/importers/session'); $request->set_body($params); @@ -54,6 +52,4 @@ class TAINACAN_REST_Importers_Controller extends TAINACAN_UnitApiTestCase { $this->assertEquals(1234, $__importer->get_collections()[0]['total_items']); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/tests/test-taxonomies.php b/tests/test-taxonomies.php index e02ab29ba..8463d2041 100644 --- a/tests/test-taxonomies.php +++ b/tests/test-taxonomies.php @@ -3,17 +3,16 @@ namespace Tainacan\Tests; /** - * Class TestCollections + * Class Taxonomies * * @package Test_Tainacan */ /** - * Sample test case. + * Taxonomies test case. */ class Taxonomies extends TAINACAN_UnitTestCase { - /** * Teste da insercao de uma taxonomia simples */ @@ -334,7 +333,6 @@ class Taxonomies extends TAINACAN_UnitTestCase { } function test_brackets_2() { - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $collection = $this->tainacan_entity_factory->create_entity( @@ -411,9 +409,6 @@ class Taxonomies extends TAINACAN_UnitTestCase { $itemMeta2_check = new \Tainacan\Entities\Item_Metadata_Entity($i2, $metadatum); $this->assertEquals('[Rock]', $itemMeta2_check->get_value()->get_name()); - - - } function test_metadata_taxonomy_term_count() { @@ -538,7 +533,6 @@ class Taxonomies extends TAINACAN_UnitTestCase { $itemMeta1_repo->validate(); $Tainacan_Item_Metadata->insert($itemMeta1_repo); - $i2 = $this->tainacan_entity_factory->create_entity( 'item', array( @@ -587,8 +581,6 @@ class Taxonomies extends TAINACAN_UnitTestCase { function test_term_taxonomy_filtered_by_collections() { $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance(); - $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance(); - $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $tax = $this->tainacan_entity_factory->create_entity( 'taxonomy', @@ -704,7 +696,6 @@ class Taxonomies extends TAINACAN_UnitTestCase { $response = $matches[3][0]; $this->assertEquals($response, $expected_response); - $meta_query = [ 'metaquery' => [ [ diff --git a/tests/test-utilities.php b/tests/test-utilities.php index b4434bf31..94d230e65 100644 --- a/tests/test-utilities.php +++ b/tests/test-utilities.php @@ -9,14 +9,11 @@ namespace Tainacan\Tests; */ /** - * Sample test case. + * TestUtilities */ class TestUtilities extends TAINACAN_UnitTestCase { - function test_initials() { - - $string = 'Roberto Carlos'; $this->assertEquals('RC', tainacan_get_initials($string)); @@ -42,7 +39,6 @@ class TestUtilities extends TAINACAN_UnitTestCase { $string = ''; $this->assertEquals('', tainacan_get_initials($string)); - } function test_get_descendants_ids() { From a6e052e216efd3f1698bf868ae11fb7ae527a05d Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sun, 18 Apr 2021 13:46:11 -0300 Subject: [PATCH 04/82] indentations and wipes out empty lines --- .../importer/class-tainacan-test-importer.php | 19 ++----- tests/test-api-logs.php | 2 - tests/test-api-metadata.php | 2 - tests/test-api-metadatum-types.php | 9 --- tests/test-api-private-files.php | 10 ---- tests/test-api-queries.php | 27 +-------- tests/test-api-roles.php | 57 +------------------ 7 files changed, 7 insertions(+), 119 deletions(-) diff --git a/src/classes/importer/class-tainacan-test-importer.php b/src/classes/importer/class-tainacan-test-importer.php index b129691a5..db47658f3 100644 --- a/src/classes/importer/class-tainacan-test-importer.php +++ b/src/classes/importer/class-tainacan-test-importer.php @@ -316,11 +316,9 @@ class Test_Importer extends Importer { - validate()) { $tax1 = $this->tax_repo->insert($tax1); } else { - /** * In these set up steps, if we have an error adding * a taxonomy, collection or metadatum, there is no point @@ -345,14 +342,12 @@ class Test_Importer extends Importer { $this->add_error_log('Error creating taxonomy Color'); $this->add_error_log($tax1->get_errors()); $this->abort(); - return false; - + return false; } $this->add_transient('tax_1_id', $tax1->get_id()); return false; - } public function create_collections() { @@ -366,11 +361,9 @@ class Test_Importer extends Importer { $this->add_error_log('Error creating Collection 1'); $this->add_error_log($col1->get_errors()); $this->abort(); - return false; - + return false; } - $col1_map = []; // metadata @@ -696,8 +689,7 @@ class Test_Importer extends Importer { * @param $collection * */ - private function create_metadata( $args, $collection ){ - + private function create_metadata( $args, $collection ) { $metadatum = new Entities\Metadatum(); $metadatum->set_name($args['name']); $metadatum->set_collection($collection); @@ -758,7 +750,6 @@ class Test_Importer extends Importer { return $array; } - public function get_col2_item($index) { return [ 'field1' => 'Collection 2 item ' . $index, @@ -766,7 +757,5 @@ class Test_Importer extends Importer { 'field3' => 'Collection 2 whatever ' . $index, ]; } - - - + } \ No newline at end of file diff --git a/tests/test-api-logs.php b/tests/test-api-logs.php index 0fd20684c..a31022047 100644 --- a/tests/test-api-logs.php +++ b/tests/test-api-logs.php @@ -64,5 +64,3 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_UnitApiTestCase { } } - -?> \ No newline at end of file diff --git a/tests/test-api-metadata.php b/tests/test-api-metadata.php index 72a0b47a2..83ff55873 100644 --- a/tests/test-api-metadata.php +++ b/tests/test-api-metadata.php @@ -952,5 +952,3 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase { } } - -?> diff --git a/tests/test-api-metadatum-types.php b/tests/test-api-metadatum-types.php index 03334c514..ab06f8c53 100644 --- a/tests/test-api-metadatum-types.php +++ b/tests/test-api-metadatum-types.php @@ -8,23 +8,14 @@ namespace Tainacan\Tests; class TAINACAN_REST_Metadata_Types_Controller extends TAINACAN_UnitApiTestCase { public function test_get_metadata_types(){ - $ftype_request = new \WP_REST_Request('GET', $this->namespace . '/metadata-types'); - $ftype_response = $this->server->dispatch($ftype_request); - $data = $ftype_response->get_data(); - $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); - $metadata_types = $Tainacan_Metadata->fetch_metadata_types('NAME'); - $this->assertEquals(count($metadata_types), count($data)); - foreach ($data as $ftype){ $this->assertContains($ftype['name'], $metadata_types); } } } - -?> \ No newline at end of file diff --git a/tests/test-api-private-files.php b/tests/test-api-private-files.php index 3e21024e9..a8b18301b 100644 --- a/tests/test-api-private-files.php +++ b/tests/test-api-private-files.php @@ -7,8 +7,6 @@ namespace Tainacan\Tests; */ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase { - - public function test_create_item() { $orig_file = './tests/attachment/codeispoetrywp.jpg'; @@ -62,12 +60,9 @@ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase { $folder = 'tainacan-items/' . $this->collection->get_id() . '/' . $this->item->get_id(); $this->assertContains( $folder, $attachment_data['file'] ); - - } function test_internal_api() { - $orig_file = './tests/attachment/codeispoetrywp.jpg'; $this->test_file = '/tmp/codeispoetrywp.jpg'; copy( $orig_file, $this->test_file ); @@ -94,15 +89,10 @@ class TAINACAN_REST_Private_Files extends TAINACAN_UnitApiTestCase { ); $attachment_id = \Tainacan\Media::get_instance()->insert_attachment_from_file($this->test_file, $this->item->get_id()); - $attachment_data = wp_get_attachment_metadata($attachment_id); - $folder = 'tainacan-items/' . $this->collection->get_id() . '/' . $this->item->get_id(); $this->assertContains( $folder, $attachment_data['file'] ); - } } - -?> \ No newline at end of file diff --git a/tests/test-api-queries.php b/tests/test-api-queries.php index 29a47542b..c9040643d 100644 --- a/tests/test-api-queries.php +++ b/tests/test-api-queries.php @@ -8,9 +8,7 @@ namespace Tainacan\Tests; class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { public function test_queries(){ - // Populate the database - $collectionB = $this->tainacan_entity_factory->create_entity( 'collection', [ @@ -57,8 +55,8 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { ), true ); - // Create Term + // Create Term $termA = $this->tainacan_entity_factory->create_entity( 'term', array( @@ -173,8 +171,6 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { $this->assertCount(1, $data1); $this->assertEquals($collectionB->get_name(), $data1[0]['name']); - - // Search collection with a specific keyword and not other keyword $search_query = ['search' => 'Collection -A']; @@ -190,14 +186,9 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { $names = [$data2[0]['name'], $data2[1]['name']]; $this->assertNotContains('A', $names); - - /* Meta Query: - * * Fetch items from a collection desc ordered by metadatumA1 and its only in range A to F. - * * */ - $meta_query = [ 'metakey' => $metadatumA1->get_id(), 'orderby' => 'meta_value', @@ -212,16 +203,11 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { ]; $meta_query_request = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items'); - $meta_query_request->set_query_params($meta_query); - $meta_query_response = $this->server->dispatch($meta_query_request); $data3 = $meta_query_response->get_data()['items']; - $this->assertCount(2, $data3); - $metadatumA1_slug = $metadatumA1->get_slug(); - $values = [$data3[0]['metadata'][$metadatumA1_slug]['value'], $data3[1]['metadata'][$metadatumA1_slug]['value']]; $this->assertNotContains('G', $values); @@ -230,13 +216,9 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { $this->assertEquals('E', $data3[0]['metadata'][$metadatumA1_slug]['value']); $this->assertEquals('D', $data3[1]['metadata'][$metadatumA1_slug]['value']); - /* Date Query: - * * Fetch posts for today - * * */ - $today = getdate(); $date_query = [ @@ -268,11 +250,8 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { $this->assertCount(0, $data5); /* Tax Query - * * Fetch items under a taxonomy with a specific term - * * */ - $tax_query = [ 'taxquery' => [ [ @@ -300,6 +279,4 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase { $this->assertContains('Item A-2', $itemsA1_A2); $this->assertNotContains('Item A-3', $itemsA1_A2); } -} - -?> \ No newline at end of file +} \ No newline at end of file diff --git a/tests/test-api-roles.php b/tests/test-api-roles.php index 09c66eed9..7acd7fa6c 100644 --- a/tests/test-api-roles.php +++ b/tests/test-api-roles.php @@ -7,8 +7,6 @@ namespace Tainacan\Tests; * */ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { - - public function setUp() { parent::setUp(); // reset WP_Roles object. Possible bug was cleaning database between tests, but not the object @@ -35,7 +33,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $data = $name_response->get_data(); $this->assertArrayHasKey('tainacan-new-role', $data); $this->assertEquals('New role', $data['tainacan-new-role']['name']); - } public function test_create_remove_roles() { @@ -58,13 +55,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $name_response = $this->server->dispatch($request); $data = $name_response->get_data(); $this->assertArrayNotHasKey('tainacan-super-role', $data); - - - } public function test_edit_role() { - $request = new \WP_REST_Request('POST', $this->namespace . '/roles'); $request->set_query_params(['name' => 'New role']); @@ -92,29 +85,24 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertEquals('Changed name', $role['name']); $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role'); - $request->set_query_params( [ 'add_cap' => 'manage_options' ] ); - $response = $this->server->dispatch($request); $this->assertEquals( 400, $response->get_status() ); $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role'); - $request->set_query_params( [ 'add_cap' => 'manage_tainacan_collection_234' ] ); - $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status() ); - } public function test_edit_role_validation() { @@ -171,33 +159,27 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status() ); - } public function test_get_role() { $request = new \WP_REST_Request('GET', $this->namespace . '/roles/administrator'); - $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status() ); $data = $response->get_data(); - $this->assertEquals( translate_user_role('Administrator'), $data['name'] ); $this->assertArrayHasKey('manage_tainacan', $data['capabilities']); $this->assertTrue($data['capabilities']['manage_tainacan']); - } public function test_get_roles() { $request = new \WP_REST_Request('GET', $this->namespace . '/roles'); - $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status() ); $data = $response->get_data(); - foreach (\tainacan_roles()->get_tainacan_roles() as $role => $r) { $this->assertArrayHasKey($role, $data); } @@ -210,7 +192,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $request->set_query_params(['name' => 'New role']); $create = $this->server->dispatch($request); - //var_dump($create); $this->assertEquals( 201, $create->get_status() ); $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role'); @@ -267,7 +248,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { } public function test_get_collection_caps() { - $collection = $this->tainacan_entity_factory->create_entity( 'collection', array( @@ -290,9 +270,7 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $contributor->add_cap( 'tnc_col_all_edit_items' ); $contributor->add_cap( 'tnc_col_all_edit_published_items' ); - $request = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collection->get_id() . '/capabilities'); - $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status() ); @@ -308,11 +286,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertArrayHasKey('contributor', $caps['tnc_col_' . $collection->get_id() . '_edit_published_items']['roles_inherited']); $this->assertArrayHasKey('administrator', $caps['tnc_col_' . $collection->get_id() . '_delete_published_items']['roles_inherited']); - } function test_get_repo_capabilities() { - $role = add_role('test', 'test', ['tnc_rep_edit_metadata'=>true]); $request = new \WP_REST_Request('GET', $this->namespace . '/capabilities'); @@ -329,12 +305,9 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertArrayNotHasKey('editor', $caps['manage_tainacan']['roles_inherited']); $this->assertArrayNotHasKey('administrator', $caps['manage_tainacan']['roles_inherited']); - - } function test_edit_collection_users_permission() { - global $current_user; $subscriber = $this->factory()->user->create(array( 'role' => 'subscriber' )); @@ -349,7 +322,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { 'add_cap' => 'tnc_col_12_edit_items' ] ); - $response = $this->server->dispatch($request); $this->assertEquals( 403, $response->get_status(), 'should not be permitted'); @@ -358,21 +330,17 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $current_user = $sub_user; $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/contributor'); - $request->set_query_params( [ 'name' => 'Changed name', 'add_cap' => 'tnc_col_12_edit_items' ] ); - $response = $this->server->dispatch($request); $this->assertEquals( 403, $response->get_status(), 'should still not be permitted because edits name'); - $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/contributor'); - $request->set_query_params( [ 'add_cap' => 'tnc_rep_edit_metadata' @@ -383,9 +351,7 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertEquals( 403, $response->get_status(), 'should not be permitted'); - $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/contributor'); - $request->set_query_params( [ 'add_cap' => 'tnc_col_12_edit_items' @@ -395,13 +361,8 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status(), 'should be permitted'); - - } - /** - * @group xis - */ public function test_create_get_roles_with_caps() { $request = new \WP_REST_Request('POST', $this->namespace . '/roles'); @@ -418,7 +379,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertEquals( 201, $create->get_status() ); $request = new \WP_REST_Request('GET', $this->namespace . '/roles'); - //$request->set_query_params($name_query); $name_response = $this->server->dispatch($request); @@ -430,13 +390,10 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertArrayHasKey('tnc_rep_edit_collections', $role['capabilities']); $this->assertTrue($role['capabilities']['tnc_rep_edit_collections']); - } public function test_edit_role_with_caps() { - $request = new \WP_REST_Request('POST', $this->namespace . '/roles'); - $request->set_query_params([ 'name' => 'New role', 'capabilities' => [ @@ -468,8 +425,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertArrayHasKey('manage_tainacan_collection_123', $data['capabilities']); $this->assertTrue($data['capabilities']['manage_tainacan_collection_123']); - - // EDIT $request = new \WP_REST_Request('PATCH', $this->namespace . '/roles/tainacan-new-role'); @@ -491,7 +446,6 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertEquals( 200, $response->get_status() ); $request = new \WP_REST_Request('GET', $this->namespace . '/roles/tainacan-new-role'); - $response = $this->server->dispatch($request); $this->assertEquals( 200, $response->get_status() ); @@ -510,27 +464,18 @@ class TAINACAN_REST_Roles_Controller extends TAINACAN_UnitApiTestCase { $this->assertArrayNotHasKey('tnc_rep_edit_taxonomies', $data['capabilities']); $this->assertArrayNotHasKey('manage_tainacan_collection_123', $data['capabilities']); - - - } function test_new_role_can_read() { $request = new \WP_REST_Request('POST', $this->namespace . '/roles'); - $request->set_query_params(['name' => 'New role']); - $create = $this->server->dispatch($request); $this->assertEquals( 201, $create->get_status() ); - $role = get_role('tainacan-new-role'); $this->assertTrue( $role->has_cap( 'read' ) ); - } -} - -?> +} \ No newline at end of file From c7c4c518a4a1771f2359ce25d61a164cf2484993 Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Sun, 18 Apr 2021 14:28:04 -0300 Subject: [PATCH 05/82] Fixes expand/collapse tainacan's admin menu title --- src/views/admin/admin.vue | 9 +++++---- src/views/tainacan-admin-i18n.php | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/views/admin/admin.vue b/src/views/admin/admin.vue index b5d446c6c..48b7ae0f6 100644 --- a/src/views/admin/admin.vue +++ b/src/views/admin/admin.vue @@ -20,15 +20,16 @@ @click="isMenuCompressed = !isMenuCompressed"> - + diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index a8b91ccd1..bf714f80c 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -472,6 +472,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_page' => __( 'Page', 'tainacan' ), 'label_current_page' => __( 'Current page', 'tainacan' ), 'label_shrink_menu' => __( 'Shrink menu', 'tainacan' ), + 'label_expand_menu' => __( 'Expand menu', 'tainacan' ), 'label_document_uploaded' => __( 'Document uploaded', 'tainacan' ), /* translators: Filter of the repository, not a repository of filter! */ 'label_repository_filter' => __( 'Repository filter', 'tainacan' ), From 4c45355fc54278d0549bcd715bb3de42675a2f19 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 26 Apr 2021 15:31:50 -0300 Subject: [PATCH 06/82] release: update version to RC --- src/tainacan.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tainacan.php b/src/tainacan.php index 9cce31da1..668a013d4 100644 --- a/src/tainacan.php +++ b/src/tainacan.php @@ -4,13 +4,13 @@ Plugin Name: Tainacan Plugin URI: https://tainacan.org/ Description: Open source, powerful and flexible repository platform for WordPress. Manage and publish you digital collections as easily as publishing a post to your blog, while having all the tools of a professional repository platform. Author: Tainacan.org -Version: 0.17.4 +Version: 0.18RC Text Domain: tainacan License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-3.0.html */ -const TAINACAN_VERSION = '0.17.4'; +const TAINACAN_VERSION = '0.18RC'; defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); $TAINACAN_BASE_URL = plugins_url('', __FILE__); From bf6a1aef7d06194da7271a2768752221086dfdf3 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 27 Apr 2021 11:35:53 -0300 Subject: [PATCH 07/82] Reduces one year from max year. #483 --- src/views/reports/components/activities-block.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/reports/components/activities-block.vue b/src/views/reports/components/activities-block.vue index 53a6b49f4..273f62ad0 100644 --- a/src/views/reports/components/activities-block.vue +++ b/src/views/reports/components/activities-block.vue @@ -101,7 +101,7 @@ export default { return { chartSeriesByUser: [], chartOptionsByUser: [], - maxYear: new Date().getFullYear(), + maxYear: new Date().getFullYear() - 1, minYear: 2017, currentStart: '', currentEnd: '' From 0c517c300cb4eeee85d47282b7f01f9d92ffea02 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 27 Apr 2021 17:19:30 -0300 Subject: [PATCH 08/82] Adds button to set all metadata as tobe created on the importer mapper screen. #529. --- .../edition/importer-mapping-form.vue | 21 ++++++++++++++++--- src/views/tainacan-admin-i18n.php | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/views/admin/components/edition/importer-mapping-form.vue b/src/views/admin/components/edition/importer-mapping-form.vue index 514917566..c5595ffc4 100644 --- a/src/views/admin/components/edition/importer-mapping-form.vue +++ b/src/views/admin/components/edition/importer-mapping-form.vue @@ -37,7 +37,6 @@

{{ $i18n.get('info_metadata_mapping_helper') }}


- + + + + {{ $i18n.get('label_set_all_create_metadada') }} + + @@ -404,7 +413,7 @@ export default { metadataSearchCancel: undefined, showTitlePromptModal: false, selectedTitle: undefined, - formErrorMessage: '' + formErrorMessage: '', } }, computed: { @@ -785,6 +794,12 @@ export default { this.showTitlePromptModal = false; this.onRunImporter(); + }, + createAllMetadata() { + this.mappedCollection['mapping'] = {}; + this.importerSourceInfo.source_metadata.forEach((metadatum, index) => { + this.mappedCollection['mapping']['create_metadata'+ index] = metadatum; + }); } } } diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index 5ae6529f8..023c263b4 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -576,6 +576,7 @@ return apply_filters( 'tainacan-admin-i18n', [ 'label_get_latest_report' => __( 'Get latest report', 'tainacan'), 'label_decrease' => __( 'Decrease', 'tainacan'), 'label_increase' => __( 'Increase', 'tainacan'), + 'label_set_all_create_metadada' => __( 'Set every metadata to be created', 'tainacan'), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), From 10459cfb168098355f592acd3234d3cca4b929dd Mon Sep 17 00:00:00 2001 From: Rodrigo de Oliveira Date: Wed, 28 Apr 2021 00:56:19 -0300 Subject: [PATCH 09/82] lint --- .../importer/class-tainacan-importer.php | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/classes/importer/class-tainacan-importer.php b/src/classes/importer/class-tainacan-importer.php index 02aaaf2ae..67ccb19de 100644 --- a/src/classes/importer/class-tainacan-importer.php +++ b/src/classes/importer/class-tainacan-importer.php @@ -59,7 +59,7 @@ abstract class Importer { private $options = []; /** - * Stores the default options for the importer options + * Stores default options for importer options * @var array */ protected $default_options = []; @@ -114,7 +114,7 @@ abstract class Importer { private $error_log = []; /** - * Wether to abort importer execution. + * Whether to abort importer execution. * @var bool */ private $abort = false; @@ -137,7 +137,6 @@ abstract class Importer { ]; public function __construct($attributess = array()) { - $this->id = uniqid(); $author = get_current_user_id(); @@ -153,8 +152,6 @@ abstract class Importer { } } } - - } public function _to_Array($short = false) { @@ -193,8 +190,7 @@ abstract class Importer { * @param $url string * @return bool */ - public function set_url($url) - { + public function set_url($url) { if(!empty($url) && !is_array($url)) { $this->url = rtrim(trim($url), "/"); @@ -207,8 +203,7 @@ abstract class Importer { /** * @return string or bool */ - public function get_url() - { + public function get_url() { if(!empty($this->url)) { return $this->url; @@ -559,7 +554,6 @@ abstract class Importer { $step = $steps[$current_step]; if ($step['callback'] == 'process_collections') { - $totalItems = 0; $currentItem = $this->get_current_collection_item(); $current_collection = $this->get_current_collection(); @@ -577,18 +571,12 @@ abstract class Importer { if ($totalItems > 0) { $value = round( ($currentItem/$totalItems) * 100 ); } - - } else { - if ( isset($step['total']) && is_numeric($step['total']) && $step['total'] > 0 ) { $current = $this->get_in_step_count(); $value = round( ($current/$step['total']) * 100 ); } - } - - } return $value; } From 1893aecd5bef5e5be089bce0e7755d3f3e94782d Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 28 Apr 2021 10:56:24 -0300 Subject: [PATCH 10/82] Adds apexchart support for some locales --- src/views/reports/js/reports-main.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/views/reports/js/reports-main.js b/src/views/reports/js/reports-main.js index cbe7b4ee1..d965f956f 100644 --- a/src/views/reports/js/reports-main.js +++ b/src/views/reports/js/reports-main.js @@ -41,6 +41,30 @@ Apex.colors = [ '#454647' // Tainacan Dark Gray ]; +/* Sets some locale configs */ +import enLocaleConfig from 'apexcharts/dist/locales/en.json'; +import esLocaleConfig from 'apexcharts/dist/locales/es.json'; +import frLocaleConfig from 'apexcharts/dist/locales/fr.json'; +import ptBrLocaleConfig from 'apexcharts/dist/locales/pt-br.json'; + +const availableLocales = ['en', 'es', 'fr', 'pt-br']; +const browserLanguage = navigator.language.toLocaleLowerCase(); + +if (availableLocales.indexOf(browserLanguage) >= 0) { + let localeConfig = {}; + + switch(browserLanguage) { + case 'es': localeConfig = esLocaleConfig; break; + case 'fr': localeConfig = frLocaleConfig; break; + case 'pt-br': localeConfig = ptBrLocaleConfig; break; + case 'en': default: localeConfig = enLocaleConfig; break; + } + Apex.chart = { + defaultLocale: browserLanguage, + locales: [ localeConfig ] + } +} + Vue.use(I18NPlugin); Vue.use(UserCapabilitiesPlugin); Vue.use(StatusHelperPlugin); From 4482555931dda51dc6739d04d9b5a57178a8762a Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 28 Apr 2021 11:25:15 -0300 Subject: [PATCH 11/82] Removes unecessary locales for moment js (so far) --- package-lock.json | 15 +++++++++++++++ package.json | 1 + webpack.common.js | 6 +++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 48fd6890e..28ba6b82e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6463,6 +6463,12 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz", "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ==" }, + "lodash.difference": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", + "integrity": "sha1-nMtOUF1Ia5FlE0V3KIWi3yf9AXw=", + "dev": true + }, "loglevel": { "version": "1.6.8", "resolved": "https://registry.npmjs.org/loglevel/-/loglevel-1.6.8.tgz", @@ -6836,6 +6842,15 @@ "resolved": "https://registry.npmjs.org/moment/-/moment-2.25.3.tgz", "integrity": "sha512-PuYv0PHxZvzc15Sp8ybUCoQ+xpyPWvjOuK72a5ovzp2LI32rJXOiIfyoFoYvG3s6EwwrdkMyWuRiEHSZRLJNdg==" }, + "moment-locales-webpack-plugin": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/moment-locales-webpack-plugin/-/moment-locales-webpack-plugin-1.2.0.tgz", + "integrity": "sha512-QAi5v0OlPUP7GXviKMtxnpBAo8WmTHrUNN7iciAhNOEAd9evCOvuN0g1N7ThIg3q11GLCkjY1zQ2saRcf/43nQ==", + "dev": true, + "requires": { + "lodash.difference": "^4.5.0" + } + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/package.json b/package.json index 9668e5286..7503919bc 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "eslint-loader": "^2.2.1", "eslint-plugin-vue": "^5.2.3", "file-loader": "^2.0.0", + "moment-locales-webpack-plugin": "^1.2.0", "postcss-loader": "^3.0.0", "sass-loader": "^7.3.1", "style-loader": "^0.23.1", diff --git a/webpack.common.js b/webpack.common.js index 545c16876..4d45c12af 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -1,5 +1,6 @@ let path = require('path'); const webpack = require('webpack'); +const MomentLocalesPlugin = require('moment-locales-webpack-plugin'); module.exports = { entry: { @@ -110,6 +111,9 @@ module.exports = { new webpack.ProvidePlugin({ 'Swiper': 'Swiper', 'PhotoSwipe': 'PhotoSwipe' - }) + }), + new MomentLocalesPlugin({ + localesToKeep: ['en', 'en-ca', 'en-nz', 'en-gb', 'es-au', 'es-in', 'pt-br', 'pt', 'es', 'es-us', 'es-do', 'fr', 'fr-ch', 'fr-ca', 'sv'], + }), ] }; \ No newline at end of file From cbaff2eb0148703c8fd60e522873fae06169a3f3 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 28 Apr 2021 16:08:07 -0300 Subject: [PATCH 12/82] Allows tooltip headers to word break --- src/views/admin/components/other/help-button.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/admin/components/other/help-button.vue b/src/views/admin/components/other/help-button.vue index 8de14b5e8..644f2251f 100644 --- a/src/views/admin/components/other/help-button.vue +++ b/src/views/admin/components/other/help-button.vue @@ -72,6 +72,7 @@ export default { color: var(--tainacan-secondary); margin-bottom: 0; margin-top: 0; + white-space: normal; } } From f24ceb87de895d3efc6e1575b277f5c9044c79b1 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 30 Apr 2021 12:01:44 -0300 Subject: [PATCH 13/82] Updates apexcharts to version 3.26.1 --- package-lock.json | 12 ++++++------ package.json | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28ba6b82e..438ec7eeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1666,9 +1666,9 @@ } }, "apexcharts": { - "version": "3.24.0", - "resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.24.0.tgz", - "integrity": "sha512-iT6czJCIVrmAtrcO90MZTQCvC+xi6R6Acf0jNH/d40FVTtCfcqECuKIh5iAMyOTtgUb7+fQ8rbadH2bm1kbL9Q==", + "version": "3.26.1", + "resolved": "https://registry.npmjs.org/apexcharts/-/apexcharts-3.26.1.tgz", + "integrity": "sha512-Z/pfGTsL4YUm1tHd6a0d0G2hX4XUmhEI0b/5BxVK69dEB/XXvVMX9hKCkcIx+kPyVqVFCuo91ZjCdqjMcmSVBA==", "requires": { "svg.draggable.js": "^2.2.2", "svg.easing.js": "^2.0.0", @@ -10816,9 +10816,9 @@ "integrity": "sha512-VfPwgcGABbGAue9+sfrD4PuwFar7gPb1yl1UK1MwXoQPAw0BKSqWfoYCT/ThFrdEVWoI51dBuyCoiNU9bZDZxQ==" }, "vue-apexcharts": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/vue-apexcharts/-/vue-apexcharts-1.6.0.tgz", - "integrity": "sha512-sT6tuVTLBwfH3TA7azecDNS/W70bmz14ZJI7aE7QIqcG9I6OywyH7x3hcOeY1v1DxttI8Svc5RuYj4Dd+A5F4g==" + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/vue-apexcharts/-/vue-apexcharts-1.6.1.tgz", + "integrity": "sha512-ILn3/55IvZQUgsc7+jKDjPfHfGUlcUQi/lDrLjRe5g7gfjj99o8otXoHwMeib3CBHYdQXNG9foe1vzv7RdUzXA==" }, "vue-awesome-swiper": { "version": "4.1.1", diff --git a/package.json b/package.json index 7503919bc..6eba199bc 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build-prod": "cross-env NODE_ENV=production webpack --config webpack.prod.js --display-error-details --progress --hide-modules" }, "dependencies": { - "apexcharts": "^3.24.0", + "apexcharts": "^3.26.1", "countup.js": "^2.0.7", "axios": "^0.21.1", "blurhash": "^1.1.3", @@ -26,7 +26,7 @@ "t": "^0.5.1", "v-tooltip": "^2.0.3", "vue": "^2.6.11", - "vue-apexcharts": "^1.6.0", + "vue-apexcharts": "^1.6.1", "vue-awesome-swiper": "^4.1.1", "vue-blurhash": "^0.1.4", "vue-countup-v2": "^4.0.0", From 2aa82ecb8b43c62618d2f6da669915e26c22a389 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 30 Apr 2021 15:37:43 -0300 Subject: [PATCH 14/82] Adds no pagination when requesting taxonomy metadata to item per term on collection block. --- src/views/admin/js/store/modules/report/actions.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/views/admin/js/store/modules/report/actions.js b/src/views/admin/js/store/modules/report/actions.js index 55e57118c..f223acead 100644 --- a/src/views/admin/js/store/modules/report/actions.js +++ b/src/views/admin/js/store/modules/report/actions.js @@ -55,12 +55,12 @@ export const fetchMetadataList = ({ commit }, { collectionId, onlyTaxonomies } ) let endpoint = ''; if (collectionId && collectionId != 'default') - endpoint += '/collection/' + collectionId + '/metadata/'; + endpoint += '/collection/' + collectionId + '/metadata/?nopaging=1'; else - endpoint += '/metadata/'; + endpoint += '/metadata/?nopaging=1'; if (onlyTaxonomies) - endpoint += '?metaquery[0][key]=metadata_type&metaquery[0][value]=Tainacan\\Metadata_Types\\Taxonomy'; + endpoint += '&metaquery[0][key]=metadata_type&metaquery[0][value]=Tainacan\\Metadata_Types\\Taxonomy'; return new Promise((resolve, reject) => { axios.tainacan.get(endpoint) From 9d597b1cc0e854e87a66bc426dc9c6c8d6fadb71 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 30 Apr 2021 16:51:09 -0300 Subject: [PATCH 15/82] Begins with only one action enabled in activities per user block. Adjustments to child terms pagination and treemap on items per term collection block. --- .../admin/js/store/modules/report/index.js | 7 ++- .../components/activities-per-user-block.vue | 46 +++++++++++++------ .../items-per-term-collection-block.vue | 15 +++++- .../components/metadata-types-block.vue | 7 ++- src/views/tainacan-admin-i18n.php | 1 + 5 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/views/admin/js/store/modules/report/index.js b/src/views/admin/js/store/modules/report/index.js index 500763026..6d4fafd7d 100644 --- a/src/views/admin/js/store/modules/report/index.js +++ b/src/views/admin/js/store/modules/report/index.js @@ -183,7 +183,7 @@ const state = { } } }, - treeMapOptions: { + treeMapChartOptions: { legend: { show: false }, @@ -193,6 +193,11 @@ const state = { }, title: { text: '' + }, + plotOptions: { + treemap: { + enableShades: false + } } } }; diff --git a/src/views/reports/components/activities-per-user-block.vue b/src/views/reports/components/activities-per-user-block.vue index 2e7e9c4eb..ca3fdb073 100644 --- a/src/views/reports/components/activities-per-user-block.vue +++ b/src/views/reports/components/activities-per-user-block.vue @@ -8,6 +8,7 @@ class="postbox activities-per-user-box"> \ No newline at end of file diff --git a/src/views/reports/components/terms-per-taxonomy-block.vue b/src/views/reports/components/terms-per-taxonomy-block.vue index 9790752be..9f8b21bd1 100644 --- a/src/views/reports/components/terms-per-taxonomy-block.vue +++ b/src/views/reports/components/terms-per-taxonomy-block.vue @@ -7,10 +7,24 @@ :series="chartSeries" :options="chartOptions" />
+
+

+ + + +  {{ $i18n.get('taxonomies') }} +

+
+

{{ $i18n.get('info_no_taxonomy_created') }}

+
+
+
-
diff --git a/src/views/reports/tainacan-reports.scss b/src/views/reports/tainacan-reports.scss index de10c5e25..245f1e4fb 100644 --- a/src/views/reports/tainacan-reports.scss +++ b/src/views/reports/tainacan-reports.scss @@ -84,6 +84,20 @@ } } } + + .empty-postbox-placeholder { + display: flex; + align-items: center; + justify-content: center; + padding: 1rem; + min-height: 380px; + flex-direction: column; + opacity: 0.75; + + p { + color: var(--tainacan-block-gray4, #555758); + } + } .graph-mode-switch { display: inline-block; From 0bd68f6e901dbe8d50120450be076b12cd949818 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 14 May 2021 15:56:09 -0300 Subject: [PATCH 40/82] Updates items per taxonomy metadata empty placeholder --- .../reports/components/items-per-term-block.vue | 1 + .../items-per-term-collection-block.vue | 16 ++++++++++++++++ src/views/tainacan-admin-i18n.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/views/reports/components/items-per-term-block.vue b/src/views/reports/components/items-per-term-block.vue index 05b8e8ab3..d12e682dd 100644 --- a/src/views/reports/components/items-per-term-block.vue +++ b/src/views/reports/components/items-per-term-block.vue @@ -1,6 +1,7 @@ + + diff --git a/src/views/reports/js/reports-main.js b/src/views/reports/js/reports-main.js index d965f956f..f9ee0b446 100644 --- a/src/views/reports/js/reports-main.js +++ b/src/views/reports/js/reports-main.js @@ -15,6 +15,7 @@ import { Vue.config.devtools = process && process.env && process.env.NODE_ENV === 'development'; import ReportsPage from '../reports.vue'; +import TainacanReportsSubheader from '../components/tainacan-reports-subheader.vue'; import NumberBlock from '../components/number-block.vue'; import ItemsPerTermBlock from '../components/items-per-term-block.vue'; import ItemsPerTermCollectionBlock from '../components/items-per-term-collection-block.vue'; @@ -72,6 +73,7 @@ Vue.use(VTooltip); Vue.use(Snackbar); Vue.use(Modal); +Vue.component('tainacan-reports-subheader', TainacanReportsSubheader); Vue.component('number-block', NumberBlock); Vue.component('items-per-term-block', ItemsPerTermBlock); Vue.component('items-per-term-collection-block', ItemsPerTermCollectionBlock); diff --git a/src/views/reports/pages/reports-list.vue b/src/views/reports/pages/reports-list.vue index d69eceae3..74b003904 100644 --- a/src/views/reports/pages/reports-list.vue +++ b/src/views/reports/pages/reports-list.vue @@ -24,6 +24,7 @@ {{ $i18n.get('label_manage_collection') }}
+
__( 'Increase', 'tainacan'), 'label_set_all_create_metadada' => __( 'Set every metadata to be created', 'tainacan'), 'label_manage_collection' => __( 'Manage collection', 'tainacan'), + 'label_chart_controls' => __( 'Chart controls', 'tainacan'), + 'label_increase_zoom' => __( 'Increase zoom', 'tainacan'), + 'label_decrease_zoom' => __( 'Decrease zoom', 'tainacan'), + 'label_zoom_by_selection' => __( 'Zoom by selection', 'tainacan'), + 'label_pan_selection' => __( 'Pan selection', 'tainacan'), + 'label_reset_zoom' => __( 'Reset zoom', 'tainacan'), + 'label_chart_export_options' => __( 'Chart export options', 'tainacan'), // Instructions. More complex sentences to guide user and placeholders 'instruction_delete_selected_collections' => __( 'Delete selected collections', 'tainacan' ), From 29113ac9177a85dbba6b1d5232e38a01fe45f5e9 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 18 May 2021 18:07:34 -0300 Subject: [PATCH 51/82] fix: remove HTML link for relationship values whose target is non-public #515 --- .../relationship/class-tainacan-relationship.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php index 13dcc0622..07111ff90 100644 --- a/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php +++ b/src/views/admin/components/metadata-types/relationship/class-tainacan-relationship.php @@ -228,9 +228,15 @@ class Relationship extends Metadata_Type { } if (is_string($link)) { - $return = ""; - $return.= $label; - $return .= ""; + if ( is_user_logged_in() || + \is_post_status_viewable( $item->get_status() ) && + \is_post_status_viewable($item->get_collection()->get_status()) ) { + $return = ""; + $return.= $label; + $return .= ""; + } else { + $return.= $label; + } } } From f54004347d0797cc1e1dc720411c68aef0b114b8 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 19 May 2021 11:12:17 -0300 Subject: [PATCH 52/82] Removes "mineiro" term from function name. --- .../admin/components/metadata-types/taxonomy/FormTaxonomy.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/admin/components/metadata-types/taxonomy/FormTaxonomy.vue b/src/views/admin/components/metadata-types/taxonomy/FormTaxonomy.vue index df4ddaf12..47ec86010 100644 --- a/src/views/admin/components/metadata-types/taxonomy/FormTaxonomy.vue +++ b/src/views/admin/components/metadata-types/taxonomy/FormTaxonomy.vue @@ -79,7 +79,7 @@ :message="$i18n.getHelperMessage('tainacan-taxonomy', 'visible_options_list')"/>   @@ -201,7 +201,7 @@ } return true; }, - isTremCreationAllowedOnCurrentTaxonomy() { + isTermCreationAllowedOnCurrentTaxonomy() { const currentTaxonomy = this.taxonomies.find((taxonomy) => taxonomy.id == this.taxonomy_id); return currentTaxonomy ? currentTaxonomy.allow_insert == 'yes' : false; } From 67d3ae8be49e0c1781fce6097717011166997e78 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 19 May 2021 11:12:55 -0300 Subject: [PATCH 53/82] Replace old visibility labels and adds new open_access and restrict_access concept. --- .../edition/filter-edition-form.vue | 4 +- .../components/edition/item-edition-form.vue | 10 ++-- .../edition/metadatum-edition-form.vue | 4 +- .../components/other/metadatum-details.vue | 7 --- src/views/admin/pages/singles/item-page.vue | 30 ++++++++++-- src/views/reports/components/number-block.vue | 48 ++++++++++++++++++- .../components/tainacan-reports-subheader.vue | 8 ++-- src/views/tainacan-admin-i18n.php | 4 +- 8 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/views/admin/components/edition/filter-edition-form.vue b/src/views/admin/components/edition/filter-edition-form.vue index ee962a6d1..837fc229a 100644 --- a/src/views/admin/components/edition/filter-edition-form.vue +++ b/src/views/admin/components/edition/filter-edition-form.vue @@ -72,7 +72,7 @@ - {{ $i18n.get('publish_visibility') }} + {{ $i18n.get('status_public') }}
- {{ $i18n.get('private_visibility') }} + {{ $i18n.get('status_private') }}
diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index ddcbcb736..26b8f44d5 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -421,11 +421,11 @@ style="flex-wrap: wrap" class="column is-narrow">
- {{ $i18n.get('publish_visibility') }} + {{ $i18n.get('status_public') }} - {{ $i18n.get('private_visibility') }} + {{ $i18n.get('status_private') }}
diff --git a/src/views/admin/components/edition/metadatum-edition-form.vue b/src/views/admin/components/edition/metadatum-edition-form.vue index 63d0e7553..ac85bf85b 100644 --- a/src/views/admin/components/edition/metadatum-edition-form.vue +++ b/src/views/admin/components/edition/metadatum-edition-form.vue @@ -89,7 +89,7 @@ - {{ $i18n.get('publish_visibility') }} + {{ $i18n.get('status_public') }} @@ -102,7 +102,7 @@ - {{ $i18n.get('private_visibility') }} + {{ $i18n.get('status_private') }} diff --git a/src/views/admin/components/other/metadatum-details.vue b/src/views/admin/components/other/metadatum-details.vue index 803e7c6ab..5d8e2ed93 100644 --- a/src/views/admin/components/other/metadatum-details.vue +++ b/src/views/admin/components/other/metadatum-details.vue @@ -12,13 +12,6 @@
{{ $i18n.getHelperTitle('metadata', 'semantic_uri') }}
{{ metadatum.semantic_uri }}
-
{{ $i18n.get('label_display') }}
diff --git a/src/views/admin/pages/singles/item-page.vue b/src/views/admin/pages/singles/item-page.vue index ce9facd5f..5b5dab027 100644 --- a/src/views/admin/pages/singles/item-page.vue +++ b/src/views/admin/pages/singles/item-page.vue @@ -154,23 +154,42 @@
- +
- {{ $i18n.get('publish_visibility') }} + {{ $i18n.get('status_public') }} - {{ $i18n.get('private_visibility') }} + {{ $i18n.get('status_private') }} + +
+
+
+ + +
+ +
+
+ + + + + {{ $i18n.get('label_' + itemVisibility) }}
@@ -369,6 +388,9 @@ }, totalAttachments() { return this.getTotalAttachments(); + }, + itemVisibility() { + return (this.collection && this.collection.status == 'public' && this.item && this.item.status == 'public') ? 'open_access' : 'restrict_access' } }, created() { diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index f58aeeab2..cb9a5af91 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -1,5 +1,7 @@ @@ -65,7 +95,13 @@ export default { 'publish': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].publish ? this.summary.totals[this.entityType].publish : 0, 'private': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].private ? this.summary.totals[this.entityType].private : 0, 'draft': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].draft ? this.summary.totals[this.entityType].draft : 0, - 'trash': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].trash ? this.summary.totals[this.entityType].trash : 0 + 'trash': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].trash ? this.summary.totals[this.entityType].trash : 0, + } + }, + totalByVisibility() { + return { + 'not_restrict': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].not_restrict ? this.summary.totals[this.entityType].not_restrict : 0, + 'restrict': this.summary && this.summary.totals && this.summary.totals[this.entityType] && this.summary.totals[this.entityType].restrict ? this.summary.totals[this.entityType].restrict : 0, } } } @@ -99,5 +135,13 @@ export default { margin: 0 1em; } } + &.number-block--items { + .subtitle { + margin-bottom: 1.25rem; + } + .status-list { + margin: 0.25em 0 0.1em 0; + } + } } \ No newline at end of file diff --git a/src/views/reports/components/tainacan-reports-subheader.vue b/src/views/reports/components/tainacan-reports-subheader.vue index 7fcec5d9c..dbcd3c1c4 100644 --- a/src/views/reports/components/tainacan-reports-subheader.vue +++ b/src/views/reports/components/tainacan-reports-subheader.vue @@ -30,18 +30,18 @@
  • - + - {{ $i18n.get('publish_visibility') }} + {{ $i18n.get('label_open_access') }}
  • - + - {{ $i18n.get('private_visibility') }} + {{ $i18n.get('label_restrict_access') }}
diff --git a/src/views/tainacan-admin-i18n.php b/src/views/tainacan-admin-i18n.php index 4f40db655..8fbcec0fd 100644 --- a/src/views/tainacan-admin-i18n.php +++ b/src/views/tainacan-admin-i18n.php @@ -110,8 +110,8 @@ return apply_filters( 'tainacan-admin-i18n', [ /* translators: The noun for the trash status, not the verb */ 'status_trash' => __( 'Trash', 'tainacan' ), 'status_auto-draft' => __( 'Automatic draft', 'tainacan' ), - 'publish_visibility' => __( 'Public (visible to everyone)', 'tainacan' ), - 'private_visibility' => __( 'Private (visible only for editors)', 'tainacan' ), + 'label_open_access' => __( 'Open access', 'tainacan' ), + 'label_restrict_access' => __( 'Restrict access', 'tainacan' ), // Page Titles (used mainly on Router) 'title_repository_collections_page' => __( 'Repository Collections', 'tainacan' ), From bea86546d0c15d4cc4ebbab5ed696409d33ac542 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 19 May 2021 11:51:39 -0300 Subject: [PATCH 54/82] Removes compound of multiple values from bulk edition and child metadatum from copy options. --- src/views/admin/components/modals/bulk-edition-modal.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/admin/components/modals/bulk-edition-modal.vue b/src/views/admin/components/modals/bulk-edition-modal.vue index 2e3e3af6d..22d7f9d58 100644 --- a/src/views/admin/components/modals/bulk-edition-modal.vue +++ b/src/views/admin/components/modals/bulk-edition-modal.vue @@ -39,7 +39,7 @@ {{ metadatum.name }}
- + + v-if="itemVisibility == 'open_access'" + class="tainacan-icon tainacan-icon-see"/> + + + + + + + + + {{ $i18n.get('label_' + itemVisibility) }} @@ -390,7 +418,7 @@ return this.getTotalAttachments(); }, itemVisibility() { - return (this.collection && this.collection.status == 'public' && this.item && this.item.status == 'public') ? 'open_access' : 'restrict_access' + return (this.collection && this.collection.status == 'publish' && this.item && this.item.status == 'publish') ? 'open_access' : 'restrict_access' } }, created() { diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index cb9a5af91..9074f8ba6 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -134,6 +134,10 @@ export default { li { margin: 0 1em; } + .value { + text-align: center; + display: inline-flex; + } } &.number-block--items { .subtitle { diff --git a/src/views/reports/components/tainacan-reports-subheader.vue b/src/views/reports/components/tainacan-reports-subheader.vue index dbcd3c1c4..ba73fdde6 100644 --- a/src/views/reports/components/tainacan-reports-subheader.vue +++ b/src/views/reports/components/tainacan-reports-subheader.vue @@ -30,7 +30,7 @@
  • - + {{ $i18n.get('label_open_access') }} @@ -38,7 +38,33 @@
  • - + + + + + + + + + {{ $i18n.get('label_restrict_access') }} diff --git a/src/views/reports/tainacan-reports.scss b/src/views/reports/tainacan-reports.scss index 2cbe84140..29fe22543 100644 --- a/src/views/reports/tainacan-reports.scss +++ b/src/views/reports/tainacan-reports.scss @@ -71,6 +71,9 @@ fill: transparent; stroke: var(--tainacan-block-gray4, #555758); } + .apexcharts-reset-icon { + margin-left: 0; + } } .columns { From bafcf99dcf3776b667bd8aa4e2dadcc1cec55686 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 19 May 2021 14:54:01 -0300 Subject: [PATCH 57/82] Better responsiveness for tainacan reports subheader. --- src/assets/css/tainacan-reports.css | 9 +++++++++ src/assets/css/tainacan-reports.css.map | 2 +- src/views/reports/tainacan-reports.scss | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/assets/css/tainacan-reports.css b/src/assets/css/tainacan-reports.css index a34d94ecd..385d6c4b4 100644 --- a/src/assets/css/tainacan-reports.css +++ b/src/assets/css/tainacan-reports.css @@ -33,8 +33,17 @@ flex-wrap: wrap; } #tainacan-reports-app .tainacan-reports-subheader .tainacan-reports-subheader-box__content.tainacan-reports-subheader-box__content--two-columns li { flex-basis: calc(50% - 8px); } + @media screen and (max-width: 986px) { + #tainacan-reports-app .tainacan-reports-subheader .tainacan-reports-subheader-box__content.tainacan-reports-subheader-box__content--two-columns li { + flex-basis: 100%; } } #tainacan-reports-app .tainacan-reports-subheader .tainacan-reports-subheader-box__content.tainacan-reports-subheader-box__content--three-columns li { flex-basis: calc(33.3333% - 8px); } + @media screen and (max-width: 1024px) { + #tainacan-reports-app .tainacan-reports-subheader .tainacan-reports-subheader-box__content.tainacan-reports-subheader-box__content--three-columns li { + flex-basis: calc(50% - 8px); } } + @media screen and (max-width: 768px) { + #tainacan-reports-app .tainacan-reports-subheader .tainacan-reports-subheader-box__content.tainacan-reports-subheader-box__content--three-columns li { + flex-basis: 100%; } } #tainacan-reports-app .tainacan-reports-subheader .tainacan-reports-subheader-box__content li { display: flex; align-items: center; diff --git a/src/assets/css/tainacan-reports.css.map b/src/assets/css/tainacan-reports.css.map index d58faef89..e6d135151 100644 --- a/src/assets/css/tainacan-reports.css.map +++ b/src/assets/css/tainacan-reports.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAAA,qBAAsB;EAClB,OAAO,EAAE,iBAAiB;EAC1B,MAAM,EAAE,CAAC;EAGT,4CAAuB;IACnB,OAAO,EAAE,GAAG;EAGhB,6BAAQ;IACJ,MAAM,EAAE,OAAO;EAGnB,8CAAyB;IACrB,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,aAAa;IAC9B,WAAW,EAAE,MAAM;IACnB,MAAM,EAAE,kBAAkB;IAE1B,iEAAmB;MACf,MAAM,EAAE,IAAI;IAGhB,qDAAO;MACH,YAAY,EAAE,IAAI;MAClB,WAAW,EAAE,GAAG;EAGxB,iDAA4B;IACxB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,MAAM;IACnB,MAAM,EAAE,gBAAgB;IACxB,KAAK,EAAE,oCAAoC;IAE3C,mGAAkD;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EAAE,QAAQ;MACrB,eAAe,EAAE,aAAa;MAC9B,SAAS,EAAE,IAAI;MAEf,4DAAkB;QACd,aAAa,EAAE,IAAI;QACnB,WAAW,EAAE,IAAI;EAK7B,gDAA2B;IACvB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,MAAM;IACnB,eAAe,EAAE,MAAM;IACvB,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,KAAK;IACjB,cAAc,EAAE,MAAM;IACtB,OAAO,EAAE,IAAI;IAEb,kDAAE;MACE,KAAK,EAAE,oCAAoC;EAInD,wCAAmB;IACf,OAAO,EAAE,YAAY;IACrB,+CAAO;MACH,MAAM,EAAE,eAAe;MACvB,UAAU,EAAE,eAAe;MAC3B,UAAU,EAAE,eAAe;MAC3B,OAAO,EAAE,CAAC;MACV,MAAM,EAAE,OAAO;MAEf,uDAAU;QACN,KAAK,EAAE,oCAAoC;EAKvD,8CAAyB;IACrB,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,MAAM;IACvB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,MAAM;IAEtB,+EAAiC;MAC7B,gBAAgB,EAAE,oCAAoC;MACtD,OAAO,EAAE,IAAI;MACb,eAAe,EAAE,UAAU;MAC3B,WAAW,EAAE,MAAM;MACnB,KAAK,EAAE,IAAI;MACX,OAAO,EAAE,iBAAiB;IAG9B,gHAAgE;MAC5D,OAAO,EAAE,iBAAiB;IAE9B,6EAA+B;MAC3B,KAAK,EAAE,IAAI;MACX,OAAO,EAAE,QAAQ;MACjB,OAAO,EAAE,IAAI;MACb,eAAe,EAAE,MAAM;MACvB,WAAW,EAAE,UAAU;MACvB,cAAc,EAAE,MAAM;MAEtB,+EAAE;QACE,aAAa,EAAE,GAAG;QAClB,SAAS,EAAE,OAAO", "sources": ["../../views/reports/tainacan-reports.scss"], "names": [], "file": "tainacan-reports.css" diff --git a/src/views/reports/tainacan-reports.scss b/src/views/reports/tainacan-reports.scss index 29fe22543..2a1858000 100644 --- a/src/views/reports/tainacan-reports.scss +++ b/src/views/reports/tainacan-reports.scss @@ -50,9 +50,20 @@ &.tainacan-reports-subheader-box__content--two-columns li { flex-basis: calc(50% - 8px); + + @media screen and (max-width: 986px) { + flex-basis: 100%; + } } &.tainacan-reports-subheader-box__content--three-columns li { flex-basis: calc(33.3333% - 8px); + + @media screen and (max-width: 1024px) { + flex-basis: calc(50% - 8px); + } + @media screen and (max-width: 768px) { + flex-basis: 100%; + } } } From 6ef50e500314316aba8a551abff51e07e83984b6 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Thu, 20 May 2021 12:40:22 -0300 Subject: [PATCH 58/82] fix: update compound metadata using CSV --- src/classes/importer/class-tainacan-csv.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/classes/importer/class-tainacan-csv.php b/src/classes/importer/class-tainacan-csv.php index afcce8e57..fb119cb40 100644 --- a/src/classes/importer/class-tainacan-csv.php +++ b/src/classes/importer/class-tainacan-csv.php @@ -199,8 +199,10 @@ class CSV extends Importer { $returnValue = []; foreach($valueToInsert as $index => $metadatumValue) { $childrenHeaders = str_getcsv($compoundHeaders[$key], $this->get_option('delimiter'), $this->get_option('enclosure')); - $childrenValue = str_getcsv($metadatumValue, $this->get_option('delimiter'), $this->get_option('enclosure')); - + $childrenValue = $this->is_clear_value($metadatumValue) ? + array_fill(0, sizeof($childrenHeaders), $this->get_option('escape_empty_value') ) : + str_getcsv($metadatumValue, $this->get_option('delimiter'), $this->get_option('enclosure')); + if ( sizeof($childrenHeaders) != sizeof($childrenValue) ) { $this->add_error_log('Mismatch count headers childrens and row columns. file value:' . $metadatumValue); return false; @@ -789,7 +791,12 @@ class CSV extends Importer { foreach($children_mapping as $tainacan_children_metadatum_id => $tainacan_children_header) { $metadatumChildren = $Tainacan_Metadata->fetch( $tainacan_children_metadatum_id, 'OBJECT' ); $compoundItemMetadata = new Entities\Item_Metadata_Entity( $item, $metadatumChildren); - $compoundItemMetadata->set_value($compoundValue[$tainacan_children_header]); + $childrenCompoundvalue = $compoundValue[$tainacan_children_header]; + if ($this->is_clear_value($childrenCompoundvalue)) { + $compoundItemMetadata->set_value(""); + } else { + $compoundItemMetadata->set_value($childrenCompoundvalue); + } $tmp[] = $compoundItemMetadata; } $singleItemMetadata[] = $tmp; @@ -876,12 +883,18 @@ class CSV extends Importer { } } + private function is_assoc(array $arr) { + if (array() === $arr) return false; + return array_keys($arr) !== range(0, count($arr) - 1); + } + private function deleteAllValuesCompoundItemMetadata($item, $compoundMetadataID) { $Tainacan_Metadata = \Tainacan\Repositories\Metadata::get_instance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); $compound_metadata = $Tainacan_Metadata->fetch($compoundMetadataID, 'OBJECT'); $compound_item_metadata = new Entities\Item_Metadata_Entity($item, $compound_metadata); $compound_item_metadata_value = $compound_item_metadata->get_value(); + $compound_item_metadata_value = $this->is_assoc($compound_item_metadata_value) ? [$compound_item_metadata_value] : $compound_item_metadata_value; foreach($compound_item_metadata_value as $item_metadata_value) { foreach ($item_metadata_value as $itemMetadata) { $Tainacan_Item_Metadata->remove_compound_value($item, $compound_metadata, $itemMetadata->get_parent_meta_id()); From fe0551c80afeedffce826dd1b386cea3f129fc5b Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 21 May 2021 10:07:10 -0300 Subject: [PATCH 59/82] Adds new restric access icon to numbers block --- src/views/reports/components/number-block.vue | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index 9074f8ba6..b21969835 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -68,7 +68,33 @@   - + + + + + + + + +
From 8b96a8529a1f89aa9c7b0a82cf5c319bd63096ba Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Fri, 21 May 2021 14:16:36 -0300 Subject: [PATCH 60/82] fix: metadata compound distribution report --- ...class-tainacan-rest-reports-controller.php | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php b/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php index d9877ae0f..ad361cbed 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php @@ -335,6 +335,17 @@ class REST_Reports_Controller extends REST_Controller { $response['totals']['items']['draft'] = intval($total_items->draft); $response['totals']['items']['publish'] = intval($total_items->publish); $response['totals']['items']['private'] = intval($total_items->private); + + if ( \is_post_status_viewable( $collection->get_status() ) === true ) { + $response['totals']['items']['not_restrict'] += isset($total_items->publish) ? intval($total_items->publish) : 0; + } else { + $response['totals']['items']['restrict'] += ( + //(isset($total_items->trash) ? intval($total_items->trash) : 0) + + (isset($total_items->draft) ? intval($total_items->draft) : 0) + + (isset($total_items->publish) ? intval($total_items->publish) : 0) + + (isset($total_items->private) ? intval($total_items->private) : 0) + ); + } } } else { $key_cache_object = 'summary'; @@ -365,7 +376,7 @@ class REST_Reports_Controller extends REST_Controller { $response['totals']['items']['not_restrict'] += isset($total_items->publish) ? intval($total_items->publish) : 0; } else { $response['totals']['items']['restrict'] += ( - (isset($total_items->trash) ? intval($total_items->trash) : 0) + + //(isset($total_items->trash) ? intval($total_items->trash) : 0) + (isset($total_items->draft) ? intval($total_items->draft) : 0) + (isset($total_items->publish) ? intval($total_items->publish) : 0) + (isset($total_items->private) ? intval($total_items->private) : 0) @@ -554,10 +565,22 @@ class REST_Reports_Controller extends REST_Controller { } $response['totals']['metadata'][$metadatum->get_status()]++; - $response['totals']['metadata_per_type'][$meta_type]['name'] = $meta_type_name; + if ( !isset($response['totals']['metadata_per_type'][$meta_type]) ) { + $response['totals']['metadata_per_type'][$meta_type] = array( + 'name' => $meta_type_name, + 'count' => 0, + ); + } $response['totals']['metadata_per_type'][$meta_type]['count']++; - $meta_ids[] = $metadatum->get_id(); + if ( $metadatum->get_metadata_type() == 'Tainacan\Metadata_Types\Compound' ) { + $metadatum_childs = $this->metadatum_repository->fetch(['parent' => $metadatum->get_id()], 'OBJECT'); + foreach($metadatum_childs as $childs) { + $meta_ids[] = $childs->get_id(); + } + } else { + $meta_ids[] = $metadatum->get_id(); + } } $response['distribution'] = $this->query_item_metadata_distribution($meta_ids, $collection->get_db_identifier()); //wp_count_posts() @@ -608,9 +631,11 @@ class REST_Reports_Controller extends REST_Controller { global $wpdb; $string_meta_ids = "'".implode("','", $meta_ids)."'"; $sql_statement = $wpdb->prepare( - "SELECT p.post_title AS 'name', p.id AS id, IFNULL(((m.total/$total_items) * 100), 0) as fill_percentage + "SELECT p.post_title AS 'name', pp.post_title AS 'parent_name', p.id AS id, IFNULL(((m.total/$total_items) * 100), 0) as fill_percentage FROM - $wpdb->posts p LEFT JOIN + $wpdb->posts p + LEFT JOIN $wpdb->posts pp ON (p.post_parent = pp.id) + LEFT JOIN ( SELECT meta_key, count(DISTINCT post_id) AS total FROM $wpdb->postmeta From 28a4db04bc52e73367d4326e2a56bdb22601d82c Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 21 May 2021 15:16:58 -0300 Subject: [PATCH 61/82] Cache refresh button not appearing in reports screen. --- src/views/reports/components/collections-list-block.vue | 1 + src/views/reports/components/terms-per-taxonomy-block.vue | 1 + 2 files changed, 2 insertions(+) diff --git a/src/views/reports/components/collections-list-block.vue b/src/views/reports/components/collections-list-block.vue index 41e9e89e9..7b97231a7 100644 --- a/src/views/reports/components/collections-list-block.vue +++ b/src/views/reports/components/collections-list-block.vue @@ -25,6 +25,7 @@ v-if="isBuildingChart || isFetchingData" style="min-height:380px" class="skeleton postbox" /> +
diff --git a/src/views/reports/components/terms-per-taxonomy-block.vue b/src/views/reports/components/terms-per-taxonomy-block.vue index 9f8b21bd1..567f4b376 100644 --- a/src/views/reports/components/terms-per-taxonomy-block.vue +++ b/src/views/reports/components/terms-per-taxonomy-block.vue @@ -25,6 +25,7 @@ v-if="isBuildingChart || isFetchingData" style="min-height:380px" class="skeleton postbox" /> +
From 3deb0c41ac154b0ae1f0a47745737b55d9b5b968 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 25 May 2021 12:15:19 -0300 Subject: [PATCH 62/82] Adds visibility info to items summary block on repository level. --- .../admin/js/store/modules/report/getters.js | 4 + .../admin/js/store/modules/report/index.js | 74 ++++++++- .../js/store/modules/report/mutations.js | 4 + .../metadata-distribution-block.vue | 5 +- src/views/reports/components/number-block.vue | 145 +++++++++++++++++- src/views/reports/pages/reports-list.vue | 3 +- 6 files changed, 226 insertions(+), 9 deletions(-) diff --git a/src/views/admin/js/store/modules/report/getters.js b/src/views/admin/js/store/modules/report/getters.js index c11f6c80d..514875868 100644 --- a/src/views/admin/js/store/modules/report/getters.js +++ b/src/views/admin/js/store/modules/report/getters.js @@ -42,6 +42,10 @@ export const getHorizontalBarChartOptions = state => { return state.horizontalBarChartOptions; }; +export const getVisibilityHorizontalBarChartOptions = state => { + return state.visibilityHorizontalBarChartOptions; +}; + export const getDonutChartOptions = state => { return state.donutChartOptions; }; diff --git a/src/views/admin/js/store/modules/report/index.js b/src/views/admin/js/store/modules/report/index.js index 3a2510dff..081dbf53d 100644 --- a/src/views/admin/js/store/modules/report/index.js +++ b/src/views/admin/js/store/modules/report/index.js @@ -130,7 +130,6 @@ const state = { }, fill: { opacity: 1 - }, legend: { position: 'top', @@ -200,7 +199,78 @@ const state = { enableShades: false } } - } + }, + visibilityHorizontalBarChartOptions: { + chart: { + type: 'bar', + height: 350, + stacked: true, + stackType: 'normal', + toolbar: { + show: false + }, + zoom: { + type: 'y', + enabled: false, + autoScaleYaxis: true, + } + }, + plotOptions: { + bar: { + horizontal: true, + columnWidth: '100%', + barHeight: '80%' + }, + }, + title: { + text: '' + }, + xaxis: { + type: 'category', + categories: [], + tooltip: { enabled: true }, + axisBorder: { + show: false + }, + axisTicks: { + show: false, + }, + labels: { + show: false + } + }, + yaxis: { + tooltip: { enabled: true }, + axisBorder: { + show: false + }, + axisTicks: { + show: false, + }, + labels: { + show: true, + style: { + fontSize: '17px', + fontFamily: 'TainacanIcons, Arial, sans-serif', + } + } + }, + tooltip: { + enabled: true + }, + fill: { + opacity: 1 + }, + grid: { + show: false + }, + legend: { + position: 'top', + horizontalAlign: 'left', + offsetX: 40 + } + }, + }; export default { diff --git a/src/views/admin/js/store/modules/report/mutations.js b/src/views/admin/js/store/modules/report/mutations.js index de9baf6c8..ef096e340 100644 --- a/src/views/admin/js/store/modules/report/mutations.js +++ b/src/views/admin/js/store/modules/report/mutations.js @@ -44,6 +44,10 @@ export const setHorizontalBarChartOptions = (state, horizontalBarChartOptions) = state.horizontalBarChartOptions = horizontalBarChartOptions; }; +export const setVisibilityHorizontalBarChartOptions = (state, visibilityHorizontalBarChartOptions) => { + state.visibilityHorizontalBarChartOptions = visibilityHorizontalBarChartOptions; +}; + export const setDonutChartOptions = (state, donutChartOptions) => { state.donutChartOptions = donutChartOptions; }; diff --git a/src/views/reports/components/metadata-distribution-block.vue b/src/views/reports/components/metadata-distribution-block.vue index 47851caab..35e9863d7 100644 --- a/src/views/reports/components/metadata-distribution-block.vue +++ b/src/views/reports/components/metadata-distribution-block.vue @@ -112,7 +112,10 @@ export default { dataLabels: { style: { colors: ['#ffffff', '#454647'] - } + }, + formatter(val) { + return (!Number.isNaN(val) && val > 0) ? (val.toFixed(2) + '%') : '' + }, }, states: { normal: { diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index b21969835..a98931b61 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -21,10 +21,13 @@ class="subtitle is-6"> {{ $i18n.get('label_used') + ': ' + summary.totals[entityType].used + ' | ' + $i18n.get('label_not_used') + ': ' + summary.totals[entityType].not_used }}

+
  • + :class="$statusHelper.getIcon(statusOption.slug)" />
-
    +
    + + +  {{ totalByVisibility['not_restrict'] }} + +
    +
    + + + + + + + + + + +  {{ totalByVisibility['restrict'] }} + +
    +
    +
    +
    +
    +
    @@ -171,6 +256,56 @@ export default { } .status-list { margin: 0.25em 0 0.1em 0; + + .tainacan-icon-private { + opacity: 0.75; + } + .tainacan-icon-draft { + opacity: 0.6; + } + .tainacan-icon-delete { + opacity: 0.5; + } + } + } +} +.visibility-charts { + display: flex; + width: calc(100% - 26px); + margin-top: 6px; + padding: 12px; + border-top: 1px solid #cbcbcb; + + &>div { + display: inline-flex; + justify-content: center; + align-items: center; + min-height: 18px; + color: white; + font-weight: bold; + position: relative; + background-color: var(--tainacan-turquoise6, #226f7d); + transition: width 0.2s ease, background-color 0.2s ease; + + &:nth-child(3) { + opacity: 0.75; + } + &:nth-child(4) { + opacity: 0.6; + } + &:nth-child(5) { + opacity: 0.5; + } + &:nth-child(6) { + opacity: 0.35; + } + &:nth-child(7) { + opacity: 0.25; + } + + .icon { + position: absolute; + top: 20px; } } } diff --git a/src/views/reports/pages/reports-list.vue b/src/views/reports/pages/reports-list.vue index 74b003904..539abb83f 100644 --- a/src/views/reports/pages/reports-list.vue +++ b/src/views/reports/pages/reports-list.vue @@ -60,7 +60,8 @@ :class="{ 'skeleton': isFetchingSummary }" class="postbox" :summary="summary" - entity-type="items"/> + entity-type="items" + :is-repository-level="isRepositoryLevel"/>
    From 5d1215cf0b1d95a6ca8d213d30d137a310881adb Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 25 May 2021 15:57:39 -0300 Subject: [PATCH 63/82] Adds status icon to collections chart. --- src/assets/css/tainacan-reports.css | 3 +++ src/assets/css/tainacan-reports.css.map | 2 +- .../components/collections-list-block.vue | 25 +++++++++++++++---- src/views/reports/tainacan-reports.scss | 5 ++++ 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/assets/css/tainacan-reports.css b/src/assets/css/tainacan-reports.css index 385d6c4b4..8d0757161 100644 --- a/src/assets/css/tainacan-reports.css +++ b/src/assets/css/tainacan-reports.css @@ -153,5 +153,8 @@ #tainacan-reports-app .tainacan-custom-tooltip .tainacan-custom-tooltip__body p { margin-bottom: 4px; font-size: 0.85rem; } + #tainacan-reports-app .apexcharts-legend-series { + display: flex; + align-items: center; } /*# sourceMappingURL=tainacan-reports.css.map */ diff --git a/src/assets/css/tainacan-reports.css.map b/src/assets/css/tainacan-reports.css.map index e6d135151..346b11c6f 100644 --- a/src/assets/css/tainacan-reports.css.map +++ b/src/assets/css/tainacan-reports.css.map @@ -1,6 +1,6 @@ { "version": 3, -"mappings": "AAAA,qBAAsB;EAClB,OAAO,EAAE,iBAAiB;EAC1B,MAAM,EAAE,CAAC;EAGT,4CAAuB;IACnB,OAAO,EAAE,GAAG;EAGhB,6BAAQ;IACJ,MAAM,EAAE,OAAO;EAGnB,8CAAyB;IACrB,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,aAAa;IAC9B,WAAW,EAAE,MAAM;IACnB,MAAM,EAAE,kBAAkB;IAE1B,iEAAmB;MACf,MAAM,EAAE,IAAI;IAGhB,qDAAO;MACH,YAAY,EAAE,IAAI;MAClB,WAAW,EAAE,GAAG;EAGxB,iDAA4B;IACxB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,MAAM;IACnB,MAAM,EAAE,gBAAgB;IACxB,KAAK,EAAE,oCAAoC;IAE3C,mGAAkD;MAC9C,YAAY,EAAE,IAAI;MAClB,WAAW,EAAE,8CAA8C;IAG/D,wFAAuC;MACnC,WAAW,EAAE,IAAI;MACjB,WAAW,EAAE,GAAG;IAGpB,0FAAyC;MACrC,OAAO,EAAE,IAAI;MACb,WAAW,EAAE,MAAM;MACnB,MAAM,EAAE,gBAAgB;MACxB,SAAS,EAAE,IAAI;MAEf,kJAA0D;QACtD,UAAU,EAAE,eAAe;QAE3B,oCAAqC;UAHzC,kJAA0D;YAIlD,UAAU,EAAE,IAAI;MAGxB,oJAA4D;QACxD,UAAU,EAAE,oBAAoB;QAEhC,qCAAsC;UAH1C,oJAA4D;YAIpD,UAAU,EAAE,eAAe;QAE/B,oCAAqC;UANzC,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MAAM;IACtB,OAAO,EAAE,IAAI;IAEb,kDAAE;MACE,KAAK,EAAE,oCAAoC;EAInD,wCAAmB;IACf,OAAO,EAAE,YAAY;IACrB,+CAAO;MACH,MAAM,EAAE,eAAe;MACvB,UAAU,EAAE,eAAe;MAC3B,UAAU,EAAE,eAAe;MAC3B,OAAO,EAAE,CAAC;MACV,MAAM,EAAE,OAAO;MAEf,uDAAU;QACN,KAAK,EAAE,oCAAoC;EAKvD,8CAAyB;IACrB,OAAO,EAAE,CAAC;IACV,OAAO,EAAE,IAAI;IACb,eAAe,EAAE,MAAM;IACvB,WAAW,EAAE,UAAU;IACvB,cAAc,EAAE,MAAM;IAEtB,+EAAiC;MAC7B,gBAAgB,EAAE,oCAAoC;MACtD,OAAO,EAAE,IAAI;MACb,eAAe,EAAE,UAAU;MAC3B,WAAW,EAAE,MAAM;MACnB,KAAK,EAAE,IAAI;MACX,OAAO,EAAE,iBAAiB;IAG9B,gHAAgE;MAC5D,OAAO,EAAE,iBAAiB;IAE9B,6EAA+B;MAC3B,KAAK,EAAE,IAAI;MACX,OAAO,EAAE,QAAQ;MACjB,OAAO,EAAE,IAAI;MACb,eAAe,EAAE,MAAM;MACvB,WAAW,EAAE,UAAU;MACvB,cAAc,EAAE,MAAM;MAEtB,+EAAE;QACE,aAAa,EAAE,GAAG;QAClB,SAAS,EAAE,OAAO;EAK9B,+CAA0B;IACtB,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,MAAM", "sources": ["../../views/reports/tainacan-reports.scss"], "names": [], "file": "tainacan-reports.css" diff --git a/src/views/reports/components/collections-list-block.vue b/src/views/reports/components/collections-list-block.vue index 7b97231a7..ff31bbf75 100644 --- a/src/views/reports/components/collections-list-block.vue +++ b/src/views/reports/components/collections-list-block.vue @@ -71,19 +71,19 @@ export default { this.chartSeries = [ { - name: this.$i18n.get('status_publish'), + name: 'public',//this.$i18n.get('status_publish'), data: publicItems }, { - name: this.$i18n.get('status_private'), + name: 'private',//this.$i18n.get('status_private'), data: privateItems }, { - name: this.$i18n.get('status_draft'), + name: 'draft',//this.$i18n.get('status_draft'), data: draftItems }, { - name: this.$i18n.get('status_trash'), + name: 'trash',//this.$i18n.get('status_trash'), data: trashItems } ]; @@ -103,12 +103,27 @@ export default { trim: true, hideOverlappingLabels: false }, - tooltip: { enabled: true } }, yaxis: { title: { text: this.$i18n.get('items') } + }, + tooltip: { + custom: ({ series, seriesIndex, dataPointIndex, w }) => { + return `
    +
    ` + collectionsLabels[dataPointIndex] + `
    +
    + ` + this.$i18n.get('status_' + w.config.series[seriesIndex].name) + `: ` + series[seriesIndex][dataPointIndex] + `` + + `
    `; + } + }, + legend: { + position: 'right', + offsetY: 40, + formatter: (seriesName) => { + return ['' + this.$i18n.get('status_' + seriesName) ] + } } } } diff --git a/src/views/reports/tainacan-reports.scss b/src/views/reports/tainacan-reports.scss index 2a1858000..17772e271 100644 --- a/src/views/reports/tainacan-reports.scss +++ b/src/views/reports/tainacan-reports.scss @@ -219,4 +219,9 @@ } } } + + .apexcharts-legend-series { + display: flex; + align-items: center; + } } \ No newline at end of file From 528cf11d09dddb003f06765991b7fde68440b163 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 25 May 2021 16:24:34 -0300 Subject: [PATCH 64/82] Standart colors for status icons. --- src/views/reports/components/number-block.vue | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index a98931b61..b681713f3 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -16,11 +16,6 @@  {{ $i18n.get(entityType) }}

    -

    - {{ $i18n.get('label_used') + ': ' + summary.totals[entityType].used + ' | ' + $i18n.get('label_not_used') + ': ' + summary.totals[entityType].not_used }} -

    +

    + {{ $i18n.get('label_used') + ': ' + summary.totals[entityType].used + ' | ' + $i18n.get('label_not_used') + ': ' + summary.totals[entityType].not_used }} +

    @@ -250,25 +250,33 @@ export default { display: inline-flex; } } - &.number-block--items { + &.number-block--items .status-list { + .tainacan-icon-private { + color: #01295c !important; + } + .tainacan-icon-draft { + color: #25a189 !important; + } + .tainacan-icon-delete { + color: #e69810 !important; + } + } + &.number-block--items, + &.number-block--taxonomy { .subtitle { margin-bottom: 1.25rem; } .status-list { margin: 0.25em 0 0.1em 0; - - .tainacan-icon-private { - opacity: 0.75; - } - .tainacan-icon-draft { - opacity: 0.6; - } - .tainacan-icon-delete { - opacity: 0.5; - } } } } +.terms-used-info { + border-top: 1px solid #cbcbcb; + margin-top: 6px; + margin-bottom: 0px !important; + padding: 12px; +} .visibility-charts { display: flex; width: calc(100% - 26px); @@ -288,13 +296,13 @@ export default { transition: width 0.2s ease, background-color 0.2s ease; &:nth-child(3) { - opacity: 0.75; + background-color: #01295c; } &:nth-child(4) { - opacity: 0.6; + background-color: #25a189; } &:nth-child(5) { - opacity: 0.5; + background-color: #e69810; } &:nth-child(6) { opacity: 0.35; From 1095b6730abd8548ca935fe2b7be469246accc4b Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 25 May 2021 16:29:25 -0300 Subject: [PATCH 65/82] Fix taxonomies css class --- src/views/reports/components/number-block.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index b681713f3..ed9af8c2b 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -262,7 +262,7 @@ export default { } } &.number-block--items, - &.number-block--taxonomy { + &.number-block--taxonomies { .subtitle { margin-bottom: 1.25rem; } From 69a04fbd0ce0d8f9a22d7896d3cf82b14adb8ed8 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Tue, 25 May 2021 16:44:42 -0300 Subject: [PATCH 66/82] fix: reports permissions check --- .../api/endpoints/class-tainacan-rest-reports-controller.php | 2 +- src/views/class-tainacan-admin.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php b/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php index ad361cbed..c014dfdf9 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-reports-controller.php @@ -264,7 +264,7 @@ class REST_Reports_Controller extends REST_Controller { } public function reports_permissions_check($request) { - return true; + return \is_user_logged_in() && current_user_can('read'); } public function get_collections($request) { diff --git a/src/views/class-tainacan-admin.php b/src/views/class-tainacan-admin.php index 395ea82d5..abbfbeb6e 100644 --- a/src/views/class-tainacan-admin.php +++ b/src/views/class-tainacan-admin.php @@ -62,7 +62,7 @@ class Admin { $this->menu_slug, __('Reports', 'tainacan'), __('Reports', 'tainacan'), - 'read', + 'manage_tainacan', 'tainacan_reports', array( &$this, 'reports_page' ) ); From 058aaaff18f679610142d932ea5a253c7c4fb2eb Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Tue, 25 May 2021 19:28:57 -0300 Subject: [PATCH 67/82] Avoids colored icons on collections level summary block. --- src/views/reports/components/number-block.vue | 7 +++---- src/views/reports/pages/reports-list.vue | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/views/reports/components/number-block.vue b/src/views/reports/components/number-block.vue index ed9af8c2b..cae23b228 100644 --- a/src/views/reports/components/number-block.vue +++ b/src/views/reports/components/number-block.vue @@ -1,6 +1,6 @@