From 8d1e5fa7d9e972a72ae41625443d8503521cd488 Mon Sep 17 00:00:00 2001 From: eduardohumberto Date: Mon, 23 Apr 2018 21:32:14 -0300 Subject: [PATCH 01/27] Fix error in field type relationship, repeating fields selected and not saving the collection --- src/classes/field-types/relationship/FormRelationship.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/classes/field-types/relationship/FormRelationship.vue b/src/classes/field-types/relationship/FormRelationship.vue index a0f1c40de..0d4a57c5a 100644 --- a/src/classes/field-types/relationship/FormRelationship.vue +++ b/src/classes/field-types/relationship/FormRelationship.vue @@ -67,7 +67,7 @@ :message="$i18n.getHelperMessage('tainacan-relationship', 'repeated')"/>
- 0 ){ + this.fields = []; for( let field of fields ){ if( field.field_type !== "Tainacan\\Field_Types\\Relationship"){ @@ -227,8 +229,8 @@ collection_id: this.collection, search: this.modelSearch, repeated: this.modelRepeated - }) + }); } } } - \ No newline at end of file + From f3a413a2898eeb978a1548b0ca6f9f61cf4796be Mon Sep 17 00:00:00 2001 From: andre2ar Date: Tue, 24 Apr 2018 10:21:09 -0300 Subject: [PATCH 02/27] Importer fix --- .../repositories/class-tainacan-items.php | 3 +- src/importer/class-tainacan-importer.php | 13 +++--- tests/test-core-field-types.php | 45 +++++++++++++++++++ tests/test-importer.php | 8 ++-- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/classes/repositories/class-tainacan-items.php b/src/classes/repositories/class-tainacan-items.php index 5b03d9e74..9ac179af7 100644 --- a/src/classes/repositories/class-tainacan-items.php +++ b/src/classes/repositories/class-tainacan-items.php @@ -220,10 +220,9 @@ class Items extends Repository { $collections_objects[] = $col; } } - } - foreach ( $collections_objects as $collection ) { + foreach ( $collections_objects as $collection ) { /** * If no specific status is defined in the query, WordPress will fetch * public items and private items for users withe the correct permission. diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index fe6cee47a..64cea57e9 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -401,19 +401,18 @@ abstract class Importer { } } - $item->set_status('publish' ); + $insertedItem->set_status('publish' ); // inserted the id on processed item with its index as array index - $this->processed_items[ $index ] = $item->get_id(); - - if($item->validate()) { - $Tainacan_Items->update( $item ); + $this->processed_items[ $index ] = $insertedItem->get_id(); + if($insertedItem->validate()) { + $Tainacan_Items->update( $insertedItem ); } else { - $this->add_log( 'error', 'Item ' . $index . ': ' ); // TODO add the $item->get_errors() array + $this->add_log( 'error', 'Item ' . $index . ': ' . $insertedItem->get_errors()[0] ); // TODO add the $item->get_errors() array return false; } - return $item; + return $insertedItem; } else { $this->add_log( 'error', 'Collection not set'); return false; diff --git a/tests/test-core-field-types.php b/tests/test-core-field-types.php index 2697261a5..8b29f73af 100644 --- a/tests/test-core-field-types.php +++ b/tests/test-core-field-types.php @@ -92,5 +92,50 @@ class CoreFieldTypes extends TAINACAN_UnitTestCase { $this->assertEquals('changed description', $check_item_metadata->get_value()); } + + function test_validate_required_title() { + + $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance(); + $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); + $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); + + $collection = $this->tainacan_entity_factory->create_entity( + 'collection', + array( + 'name' => 'test', + ), + true + ); + + $i = $this->tainacan_entity_factory->create_entity( + 'item', + array( + 'description' => 'adasdasdsa', + 'collection' => $collection, + 'status' => 'draft' + ), + true + ); + + $fields = $Tainacan_Fields->fetch_by_collection( $collection, [], 'OBJECT' ) ; + + foreach ( $fields as $index => $field ){ + if ( $field->get_field_type_object()->get_core() && $field->get_field_type_object()->get_related_mapped_prop() == 'title') { + $core_title = $field; + } + } + + + + $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($i, $core_title); + $item_metadata->set_value('title'); + $item_metadata->validate(); + $Tainacan_Item_Metadata->insert($item_metadata); + + $i->set_status('publish' ); + + $this->assertTrue($i->validate(), 'Item with empy title should validate because core title field has value'); + + } } \ No newline at end of file diff --git a/tests/test-importer.php b/tests/test-importer.php index ac8f323d7..cdeca4e88 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { $this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() ); } - /*public function test_automapping_old_tainacan() + /* public function test_automapping_old_tainacan() { $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); @@ -228,13 +228,11 @@ class ImporterTests extends TAINACAN_UnitTestCase { $this->assertEquals(2, $_SESSION['tainacan_importer'][$id]->run(), 'first step should import 2 items'); $this->assertEquals(4, $_SESSION['tainacan_importer'][$id]->run(), 'second step should import 2 items'); $this->assertEquals(5, $_SESSION['tainacan_importer'][$id]->run(), 'third step should import 3 items'); - $this->assertEquals(5, $_SESSION['tainacan_importer'][$id]->run(), 'if call run again after finish, do nothing'); $items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' ); $this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) ); - } /** @@ -243,7 +241,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { public function test_fetch_file(){ $csv_importer = new Importer\CSV(); $id = $csv_importer->get_id(); - //$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wordpress-test/wp-json' ); - //$this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) ); + $_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wordpress-test/wp-json' ); + $this->assertTrue( isset( $_SESSION['tainacan_importer'][$id]->tmp_file ) ); } } \ No newline at end of file From 2c450a6b477ab1b447a4c7a535c796c5dd90f339 Mon Sep 17 00:00:00 2001 From: andre2ar Date: Tue, 24 Apr 2018 13:15:19 -0300 Subject: [PATCH 03/27] Old Tainacan Importer: corrections --- src/importer/class-tainacan-importer.php | 4 +- src/importer/class-tainacan-old-tainacan.php | 77 +++++++++++++------- tests/test-importer.php | 2 +- 3 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/importer/class-tainacan-importer.php b/src/importer/class-tainacan-importer.php index 64cea57e9..652cd4b09 100644 --- a/src/importer/class-tainacan-importer.php +++ b/src/importer/class-tainacan-importer.php @@ -406,9 +406,9 @@ abstract class Importer { // inserted the id on processed item with its index as array index $this->processed_items[ $index ] = $insertedItem->get_id(); if($insertedItem->validate()) { - $Tainacan_Items->update( $insertedItem ); + $insertedItem = $Tainacan_Items->update( $insertedItem ); } else { - $this->add_log( 'error', 'Item ' . $index . ': ' . $insertedItem->get_errors()[0] ); // TODO add the $item->get_errors() array + $this->add_log( 'error', 'Item ' . $index . ': ' . $insertedItem->get_errors()[0]['title'] ); // TODO add the $item->get_errors() array return false; } diff --git a/src/importer/class-tainacan-old-tainacan.php b/src/importer/class-tainacan-old-tainacan.php index 657a6267b..d61237742 100644 --- a/src/importer/class-tainacan-old-tainacan.php +++ b/src/importer/class-tainacan-old-tainacan.php @@ -11,7 +11,31 @@ namespace Tainacan\Importer; class Old_Tainacan extends Importer { - public function __construct($import_structure_and_mapping = false) { + public $avoid = [ + 'ID', + 'post_author', + 'post_date', + 'post_date_gmt', + /*'post_content', + 'post_title',*/ + 'post_excerpt', + 'post_status', + 'comment_status', + 'ping_status', + 'post_name', + 'post_modified', + 'post_modified_gmt', + 'post_content_filtered', + 'post_parent', + 'guid', + 'comment_count', + 'filter', + 'link', + 'thumbnail' + ]; + + public function __construct($import_structure_and_mapping = false) + { parent::__construct(); $this->remove_import_method('file'); @@ -50,7 +74,6 @@ class Old_Tainacan extends Importer if(!empty($link)) { $items = wp_remote_get( $link."/items/?includeMetadata=1" ); - if(isset($items['body'])) { $items_array = json_decode($items['body']); @@ -78,8 +101,18 @@ class Old_Tainacan extends Importer $item = $file_content->items[0]; - $fields = array_keys((array)$item->item); + $fields = []; + //Default meta + foreach ($item->item as $meta_name => $value) + { + if(!in_array($meta_name, $this->avoid)) + { + $fields[] = $meta_name; + } + } + + //Added meta foreach ($item->metadata as $metadata) { $fields[] = ['name' => $metadata->name, 'type' => $metadata->type]; @@ -105,7 +138,6 @@ class Old_Tainacan extends Importer // search the index in the file and get values $file = new \SplFileObject( $this->tmp_file, 'r' ); $file_content = unserialize($file->fread($file->getSize())); - $values = $file_content->items[$index]; foreach ($headers as $header) { @@ -147,31 +179,10 @@ class Old_Tainacan extends Importer public function create_fields_and_mapping() { + $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); $fields_repository = \Tainacan\Repositories\Fields::get_instance(); $file_fields = $this->get_fields(); - $avoid = [ - /*'ID', - 'post_author', - 'post_date', - 'post_date_gmt', - 'post_content', - 'post_title', - 'post_excerpt', - 'post_status', - 'comment_status', - 'ping_status', - 'post_name', - 'post_modified', - 'post_modified_gmt', - 'post_content_filtered', - 'post_parent', - 'guid', - 'comment_count', - 'filter', - 'link', - 'thumbnail'*/ - ]; foreach($file_fields as $index => $meta_info) { @@ -186,7 +197,7 @@ class Old_Tainacan extends Importer $type = 'Text'; } - if(!in_array($meta_name, $avoid)) + if(!in_array($meta_name, $this->avoid)) { $newField = new \Tainacan\Entities\Field(); @@ -200,6 +211,16 @@ class Old_Tainacan extends Importer $newField = $fields_repository->insert($newField); $mapping[$newField->get_id()] = $file_fields[$index]; + }else + { + $fields = $Tainacan_Fields->fetch_by_collection( $this->collection, [], 'OBJECT' ) ; + foreach ($fields as $field) + { + if($field->WP_Post->post_name === 'title' || $field->WP_Post->post_name === 'description') + { + $mapping[$field->get_id()] = $file_fields[$meta_name]; + } + } } } @@ -209,7 +230,7 @@ class Old_Tainacan extends Importer public function define_type($type) { $type = strtolower($type); - $tainacan_types = ['text', 'textarea', 'numerica', 'date']; + $tainacan_types = ['text', 'textarea', 'numeric', 'date']; $types_to_work = ['item', 'tree']; if(in_array($type, $tainacan_types)) diff --git a/tests/test-importer.php b/tests/test-importer.php index cdeca4e88..f043b9d8d 100644 --- a/tests/test-importer.php +++ b/tests/test-importer.php @@ -29,7 +29,7 @@ class ImporterTests extends TAINACAN_UnitTestCase { $this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() ); } - /* public function test_automapping_old_tainacan() + /*public function test_automapping_old_tainacan() { $Tainacan_Items = \Tainacan\Repositories\Items::get_instance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance(); From fe253f24e9c3cd942f094a55a4ce6e5b90f3274c Mon Sep 17 00:00:00 2001 From: Mateus Machado Luna Date: Fri, 20 Apr 2018 10:12:11 -0300 Subject: [PATCH 04/27] Begins implementation of default displayed fields in collection edition form. --- .../edition/collection-edition-form.vue | 117 +++++++++++------- src/admin/js/main.js | 2 +- src/admin/js/testes-upload.js | 38 ++++++ src/admin/tainacan-admin-i18n.php | 1 + src/js/store/modules/collection/actions.js | 17 ++- 5 files changed, 123 insertions(+), 52 deletions(-) create mode 100644 src/admin/js/testes-upload.js diff --git a/src/admin/components/edition/collection-edition-form.vue b/src/admin/components/edition/collection-edition-form.vue index 8f4e63ead..4067886b6 100644 --- a/src/admin/components/edition/collection-edition-form.vue +++ b/src/admin/components/edition/collection-edition-form.vue @@ -72,39 +72,6 @@ class="buttton" @click="openFrameUploader($event)">Enviar - - -
- -
- - -

- - Set custom image - - - Remove this image - -

- - - -