diff --git a/docs/generate-repo-descriptions.php b/docs/generate-repo-descriptions.php index 4988cd3ac..1861170ec 100644 --- a/docs/generate-repo-descriptions.php +++ b/docs/generate-repo-descriptions.php @@ -63,9 +63,6 @@ $repos = [ [ 'name' => 'get_core_description_metadatum', ], - [ - 'name' => 'get_core_author_metadatum', - ], [ 'name' => 'fetch_all_metadatum_values', ], diff --git a/src/classes/entities/class-tainacan-collection.php b/src/classes/entities/class-tainacan-collection.php index b9cbb99f0..0848a34c8 100644 --- a/src/classes/entities/class-tainacan-collection.php +++ b/src/classes/entities/class-tainacan-collection.php @@ -494,7 +494,7 @@ class Collection extends Entity { } /** - * Get the two core metadata of the collection (title, description and author) + * Get the two core metadata of the collection (title and description) * * @return array[\Tainacan\Entities\Metadatum] */ @@ -527,17 +527,6 @@ class Collection extends Entity { return $repo->get_core_description_metadatum($this); } - /** - * Get the Core Author Metadatum of the collection - * - * @return array[\Tainacan\Entities\Metadatum] - */ - function get_core_author_metadatum() { - $repo = \Tainacan\Repositories\Metadata::get_instance(); - - return $repo->get_core_author_metadatum($this); - } - /** * Checks if comments are allowed for the current Collection. * @return string "open"|"closed" diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index dc5712ba7..494a542fb 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -384,17 +384,6 @@ class Item extends Entity { $this->set_mapped_property('comment_status', $value); } - /** - * Define the author id - * - * @param [integer] $value - * - * @return void - */ - function set_author_id( $value ) { - $this->set_mapped_property( 'author_id', $value ); - } - /** * * {@inheritDoc} diff --git a/src/classes/mappers/class-tainacan-dublin-core.php b/src/classes/mappers/class-tainacan-dublin-core.php index 08beb6716..6563765ae 100644 --- a/src/classes/mappers/class-tainacan-dublin-core.php +++ b/src/classes/mappers/class-tainacan-dublin-core.php @@ -25,7 +25,6 @@ class Dublin_Core extends Mapper { ], 'dc:creator' => [ 'label' => 'Creator', - 'core_metadatum' => 'author' ], 'dc:date' => [ 'label' => 'Date', diff --git a/src/classes/repositories/class-tainacan-collections.php b/src/classes/repositories/class-tainacan-collections.php index aaae01c57..2d556dfa5 100644 --- a/src/classes/repositories/class-tainacan-collections.php +++ b/src/classes/repositories/class-tainacan-collections.php @@ -348,7 +348,6 @@ class Collections extends Repository { $this->old_collection = $this->fetch( $collection->get_id() ); $this->old_core_title = $collection->get_core_title_metadatum(); $this->old_core_description = $collection->get_core_description_metadatum(); - $this->old_core_author = $collection->get_core_author_metadatum(); } @@ -361,10 +360,9 @@ class Collections extends Repository { if ( $this->old_collection instanceof Entities\Collection && $this->old_collection->get_parent() != $collection->get_parent() && $this->old_core_title instanceof Entities\Metadatum && - $this->old_core_description instanceof Entities\Metadatum && - $this->old_core_author instanceof Entities\Metadatum + $this->old_core_description instanceof Entities\Metadatum ) { - $Tainacan_Metadata->maybe_update_core_metadata_meta_keys( $collection, $this->old_collection, $this->old_core_title, $this->old_core_description, $this->old_core_author); + $Tainacan_Metadata->maybe_update_core_metadata_meta_keys( $collection, $this->old_collection, $this->old_core_title, $this->old_core_description ); } } diff --git a/src/classes/repositories/class-tainacan-metadata.php b/src/classes/repositories/class-tainacan-metadata.php index a896d3df7..415b6ffe8 100644 --- a/src/classes/repositories/class-tainacan-metadata.php +++ b/src/classes/repositories/class-tainacan-metadata.php @@ -19,8 +19,7 @@ class Metadata extends Repository { public $core_metadata = [ 'Tainacan\Metadata_Types\Core_Title', - 'Tainacan\Metadata_Types\Core_Description', - 'Tainacan\Metadata_Types\Core_Author' + 'Tainacan\Metadata_Types\Core_Description' ]; private static $instance = null; @@ -666,7 +665,7 @@ class Metadata extends Repository { * @return void * @throws \Exception */ - public function maybe_update_core_metadata_meta_keys( Entities\Collection $collection_new, Entities\Collection $collection_old, Entities\Metadatum $old_title_metadatum, Entities\Metadatum $old_description_metadatum, Entities\Metadatum $old_author_metadatum ) { + public function maybe_update_core_metadata_meta_keys( Entities\Collection $collection_new, Entities\Collection $collection_old, Entities\Metadatum $old_title_metadatum, Entities\Metadatum $old_description_metadatum ) { global $wpdb; @@ -678,13 +677,10 @@ class Metadata extends Repository { wp_delete_post( $old_description_metadatum->get_id(), true ); update_post_meta( $old_title_metadatum->get_id(), 'metadata_type', 'to_delete', $old_title_metadatum->get_metadata_type() ); wp_delete_post( $old_title_metadatum->get_id(), true ); - update_post_meta( $old_author_metadatum->get_id(), 'metadata_type', 'to_delete', $old_author_metadatum->get_metadata_type() ); - wp_delete_post( $old_author_metadatum->get_id(), true ); } $new_title_metadatum = $collection_new->get_core_title_metadatum(); $new_description_metadatum = $collection_new->get_core_description_metadatum(); - $new_author_metadatum = $collection_new->get_core_author_metadatum(); $sql_statement = $wpdb->prepare( "UPDATE $wpdb->postmeta @@ -710,18 +706,6 @@ class Metadata extends Repository { $res = $wpdb->query( $sql_statement ); - $sql_statement = $wpdb->prepare( - "UPDATE $wpdb->postmeta - SET meta_key = %s - WHERE meta_key = %s AND post_id IN ( - SELECT ID - FROM $wpdb->posts - WHERE post_type = %s - )", $new_author_metadatum->get_id(), $old_author_metadatum->get_id(), $item_post_type - ); - - $res = $wpdb->query( $sql_statement ); - wp_cache_flush(); } @@ -749,14 +733,6 @@ class Metadata extends Repository { 'status' => 'publish', 'display' => 'yes', ], - 'core_author' => [ - 'name' => 'Author', - 'description' => 'Author', - 'collection_id' => $collection->get_id(), - 'metadata_type' => 'Tainacan\Metadata_Types\Core_Author', - 'status' => 'private', - 'display' => 'no', - ] ]; } @@ -920,32 +896,6 @@ class Metadata extends Repository { return false; } - /** - * Get the Core Author Metadatum for a collection - * - * @param Entities\Collection $collection - * - * @return \Tainacan\Entities\Metadatum The Core Author Metadatum - * @throws \Exception - */ - public function get_core_author_metadatum( Entities\Collection $collection ) { - - $results = $this->fetch_by_collection( $collection, [ - 'meta_query' => [ - [ - 'key' => 'metadata_type', - 'value' => 'Tainacan\Metadata_Types\Core_Author', - ] - ], - 'posts_per_page' => 1 - ] ); - - if ( is_array( $results ) && sizeof( $results ) == 1 && $results[0] instanceof \Tainacan\Entities\Metadatum ) { - return $results[0]; - } - - return false; - } /** * create a metadatum entity and insert by an associative array ( attribute => value ) diff --git a/src/views/admin/components/metadata-types/core-author/class-tainacan-core-author.php b/src/views/admin/components/metadata-types/core-author/class-tainacan-core-author.php deleted file mode 100644 index e75de85c9..000000000 --- a/src/views/admin/components/metadata-types/core-author/class-tainacan-core-author.php +++ /dev/null @@ -1,71 +0,0 @@ -set_primitive_type('user'); - $this->set_core(true); - $this->set_related_mapped_prop('author_id'); - $this->set_component('tainacan-author'); - $this->set_name( __('Core Author', 'tainacan') ); - $this->set_description( __('The "Core Author" is a compulsory metadata automatically created for all collections by default.', 'tainacan') ); - } - - /** - * generate the metadata for this metadatum type - */ - public function form(){ - - } - - /** - * Core author metadatum type is stored as the item author - * - * Lets validate it as the item title - * - * @param TainacanEntitiesItem_Metadata_Entity $item_metadata - * @return bool Valid or not - * - * Quarantine - Core metadata should be validated as any other metadata - * and item title is no longer mandatory - * public function validate(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { } - */ - - public function validate_options( Metadatum $metadatum ) { - if ( !in_array($metadatum->get_status(), apply_filters('tainacan-status-require-validation', ['publish','future','private'])) ) - return true; - - if ( $metadatum->get_multiple() != 'no') { - return ['multiple' => __('Core Metadata can not accept multiple values', 'tainacan')]; - } - - if ($metadatum->get_required() != 'no') { - return ['multiple' => __('Core Author Metadata is required', 'tainacan')]; - } - - return true; - } - - /** - * Get the value as a HTML string - * @return string - */ - public function get_value_as_html(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) { - $value = $item_metadata->get_value(); - $name = get_the_author_meta( 'display_name', $value ); - return apply_filters("tainacan-item-get-author-name", $name, $this); - } - -} \ No newline at end of file diff --git a/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php b/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php index 601bdfe6b..f073f36da 100644 --- a/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php +++ b/src/views/admin/components/metadata-types/metadata-type-helper/class-tainacan-metadata-type-helper.php @@ -40,6 +40,7 @@ class Metadata_Type_Helper { $this->Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Relationship'); $this->Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Taxonomy'); $this->Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\Compound'); + $this->Tainacan_Metadata->register_metadata_type('Tainacan\Metadata_Types\User'); // the priority should see less than on function // `load_admin_page()` of class `Admin` in file /src/views/class-tainacan-admin.php diff --git a/src/views/admin/components/metadata-types/core-author/Author.vue b/src/views/admin/components/metadata-types/user/User.vue similarity index 98% rename from src/views/admin/components/metadata-types/core-author/Author.vue rename to src/views/admin/components/metadata-types/user/User.vue index 9c094a688..4868f8ba4 100644 --- a/src/views/admin/components/metadata-types/core-author/Author.vue +++ b/src/views/admin/components/metadata-types/user/User.vue @@ -45,6 +45,7 @@ export default { data() { return { users: [], + defaultAuthor: 'no', isLoadingCurrentUser: false, isFetchingUsers: false, userId: null, diff --git a/src/views/admin/components/metadata-types/user/class-tainacan-user.php b/src/views/admin/components/metadata-types/user/class-tainacan-user.php new file mode 100644 index 000000000..0d6b3ea2d --- /dev/null +++ b/src/views/admin/components/metadata-types/user/class-tainacan-user.php @@ -0,0 +1,97 @@ +set_primitive_type('user'); + $this->set_component('tainacan-user'); + $this->set_name( __('User', 'tainacan') ); + $this->set_description( __('A registered user on wordpress', 'tainacan') ); + $this->set_preview_template(' +