Merge branch 'feature/advanced-search-shortcut-in-header' into develop
This commit is contained in:
commit
7795f39c37
|
@ -15,7 +15,9 @@
|
||||||
grouped>
|
grouped>
|
||||||
|
|
||||||
<!-- Metadata (Search criteria) -->
|
<!-- Metadata (Search criteria) -->
|
||||||
<b-field class="column">
|
<b-field
|
||||||
|
:class="{'is-3': isHeader}"
|
||||||
|
class="column">
|
||||||
<b-select
|
<b-select
|
||||||
:placeholder="$i18n.get('instruction_select_a_metadatum')"
|
:placeholder="$i18n.get('instruction_select_a_metadatum')"
|
||||||
:disabled="advancedSearchQuery.taxquery[searchCriterion] ||
|
:disabled="advancedSearchQuery.taxquery[searchCriterion] ||
|
||||||
|
@ -34,7 +36,8 @@
|
||||||
|
|
||||||
<!-- Inputs -->
|
<!-- Inputs -->
|
||||||
<b-field
|
<b-field
|
||||||
class="column is-two-thirds">
|
:class="{'is-two-thirds': !isHeader}"
|
||||||
|
class="column">
|
||||||
<b-input
|
<b-input
|
||||||
v-if="advancedSearchQuery.metaquery[searchCriterion] &&
|
v-if="advancedSearchQuery.metaquery[searchCriterion] &&
|
||||||
advancedSearchQuery.metaquery[searchCriterion].ptype != 'date'"
|
advancedSearchQuery.metaquery[searchCriterion].ptype != 'date'"
|
||||||
|
@ -71,6 +74,7 @@
|
||||||
|
|
||||||
<!-- Comparators -->
|
<!-- Comparators -->
|
||||||
<b-field
|
<b-field
|
||||||
|
:class="{'is-3': isHeader}"
|
||||||
class="column">
|
class="column">
|
||||||
<b-select
|
<b-select
|
||||||
v-if="advancedSearchQuery.taxquery[searchCriterion] ||
|
v-if="advancedSearchQuery.taxquery[searchCriterion] ||
|
||||||
|
@ -104,15 +108,13 @@
|
||||||
<!-- Add button -->
|
<!-- Add button -->
|
||||||
<div
|
<div
|
||||||
v-show="!advancedSearchResults"
|
v-show="!advancedSearchResults"
|
||||||
:style="{
|
:class="{'add-link-advanced-search-header': isHeader, 'add-link-advanced-search': !isHeader }"
|
||||||
'margin-top': '-15px !important',
|
|
||||||
'padding-left': '25px !important'
|
|
||||||
}"
|
|
||||||
class="field column is-12">
|
class="field column is-12">
|
||||||
<a
|
<a
|
||||||
@click="addSearchCriteria"
|
@click="addSearchCriteria"
|
||||||
class="is-secondary is-small add-link">
|
class="is-secondary add-link">
|
||||||
<b-icon
|
<b-icon
|
||||||
|
class="add-i"
|
||||||
icon="plus-circle"
|
icon="plus-circle"
|
||||||
size="is-small"
|
size="is-small"
|
||||||
type="is-secondary"/>
|
type="is-secondary"/>
|
||||||
|
@ -188,6 +190,7 @@
|
||||||
props: {
|
props: {
|
||||||
metadata: Array,
|
metadata: Array,
|
||||||
isRepositoryLevel: false,
|
isRepositoryLevel: false,
|
||||||
|
isHeader: false,
|
||||||
advancedSearchResults: false,
|
advancedSearchResults: false,
|
||||||
openFormAdvancedSearch: false,
|
openFormAdvancedSearch: false,
|
||||||
isDoSearch: false,
|
isDoSearch: false,
|
||||||
|
@ -407,6 +410,19 @@
|
||||||
this.addToAdvancedSearchQuery(value, type, searchCriterion);
|
this.addToAdvancedSearchQuery(value, type, searchCriterion);
|
||||||
}, 900),
|
}, 900),
|
||||||
searchAdvanced(){
|
searchAdvanced(){
|
||||||
|
|
||||||
|
if(this.isHeader){
|
||||||
|
if(this.$route.path == '/items') {
|
||||||
|
this.$root.$emit('openAdvancedSearch', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this.$route.path != '/items') {
|
||||||
|
this.$router.push({
|
||||||
|
path: '/items',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(Object.keys(this.advancedSearchQuery.taxquery).length > 0 &&
|
if(Object.keys(this.advancedSearchQuery.taxquery).length > 0 &&
|
||||||
Object.keys(this.advancedSearchQuery.metaquery).length > 0){
|
Object.keys(this.advancedSearchQuery.metaquery).length > 0){
|
||||||
this.advancedSearchQuery.relation = 'AND';
|
this.advancedSearchQuery.relation = 'AND';
|
||||||
|
@ -551,6 +567,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.add-link-advanced-search {
|
||||||
|
margin-top: -15px !important;
|
||||||
|
padding-left: 25px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-link-advanced-search-header {
|
||||||
|
margin-top: -20px !important;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
|
@ -21,38 +21,41 @@
|
||||||
<input
|
<input
|
||||||
autocomplete="on"
|
autocomplete="on"
|
||||||
:placeholder="$i18n.get('instruction_search_in_repository')"
|
:placeholder="$i18n.get('instruction_search_in_repository')"
|
||||||
class="input is-small"
|
class="input is-small search-header"
|
||||||
type="search"
|
type="search"
|
||||||
:value="searchQuery"
|
:value="searchQuery"
|
||||||
@input="futureSearchQuery = $event.target.value"
|
@input="futureSearchQuery = $event.target.value"
|
||||||
@keyup.enter="updateSearch()">
|
@keyup.enter="updateSearch()">
|
||||||
<span class="icon is-right">
|
<!--<span class="icon is-right">-->
|
||||||
<i
|
<!--<i-->
|
||||||
@click="updateSearch()"
|
<!--@click="updateSearch()"-->
|
||||||
class="mdi mdi-magnify"/>
|
<!--class="mdi mdi-magnify"/>-->
|
||||||
</span>
|
<!--</span>-->
|
||||||
<!--<b-dropdown-->
|
<b-dropdown
|
||||||
<!--position="is-bottom-left">-->
|
class="advanced-search-header-dropdown"
|
||||||
<!--<b-icon-->
|
position="is-bottom-left">
|
||||||
<!--class="is-right"-->
|
<b-icon
|
||||||
<!--slot="trigger"-->
|
class="is-right"
|
||||||
<!--size="is-small"-->
|
slot="trigger"
|
||||||
<!--icon="menu-down"/>-->
|
size="is-small"
|
||||||
<!--<b-dropdown-item>-->
|
icon="menu-down"/>
|
||||||
<!--<p class="is-left">{{ $i18n.get('advanced_search') }}</p>-->
|
<b-dropdown-item>
|
||||||
<!--<b-icon-->
|
<p class="is-left">{{ $i18n.get('advanced_search') }}</p>
|
||||||
<!--icon="menu-up"-->
|
<b-icon
|
||||||
<!--class="is-right" />-->
|
icon="menu-up"
|
||||||
<!--</b-dropdown-item>-->
|
class="is-right" />
|
||||||
<!--<b-dropdown-item-->
|
</b-dropdown-item>
|
||||||
<!--:custom="true">-->
|
<b-dropdown-item
|
||||||
<!--<advanced-search />-->
|
:custom="true">
|
||||||
<!--</b-dropdown-item>-->
|
<advanced-search
|
||||||
<!--</b-dropdown>-->
|
:metadata="metadata"
|
||||||
|
:is-header="true"/>
|
||||||
|
</b-dropdown-item>
|
||||||
|
</b-dropdown>
|
||||||
</div>
|
</div>
|
||||||
<a
|
<!--<a-->
|
||||||
:style="{color: 'white'}"
|
<!--:style="{color: 'white'}"-->
|
||||||
@click="toItemsPage">{{ $i18n.get('advanced_search') }}</a>
|
<!--@click="toItemsPage">{{ $i18n.get('advanced_search') }}</a>-->
|
||||||
</div>
|
</div>
|
||||||
<a
|
<a
|
||||||
:style="{color: 'white'}"
|
:style="{color: 'white'}"
|
||||||
|
@ -67,6 +70,7 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
import AdvancedSearch from '../advanced-search/advanced-search.vue';
|
import AdvancedSearch from '../advanced-search/advanced-search.vue';
|
||||||
|
import { mapActions } from 'vuex';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'TainacanHeader',
|
name: 'TainacanHeader',
|
||||||
|
@ -76,26 +80,30 @@
|
||||||
wordpressAdmin: window.location.origin + window.location.pathname.replace('admin.php', ''),
|
wordpressAdmin: window.location.origin + window.location.pathname.replace('admin.php', ''),
|
||||||
searchQuery: '',
|
searchQuery: '',
|
||||||
futureSearchQuery: '',
|
futureSearchQuery: '',
|
||||||
|
metadata: Array,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
AdvancedSearch,
|
AdvancedSearch,
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toItemsPage() {
|
...mapActions('metadata', [
|
||||||
if(this.$route.path == '/items') {
|
'fetchMetadata'
|
||||||
this.$root.$emit('openAdvancedSearch', true);
|
]),
|
||||||
}
|
// toItemsPage() {
|
||||||
|
// if(this.$route.path == '/items') {
|
||||||
if(this.$route.path != '/items') {
|
// this.$root.$emit('openAdvancedSearch', true);
|
||||||
this.$router.push({
|
// }
|
||||||
path: '/items',
|
//
|
||||||
query: {
|
// if(this.$route.path != '/items') {
|
||||||
advancedSearch: true
|
// this.$router.push({
|
||||||
}
|
// path: '/items',
|
||||||
});
|
// query: {
|
||||||
}
|
// advancedSearch: true
|
||||||
},
|
// }
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// },
|
||||||
updateSearch() {
|
updateSearch() {
|
||||||
if (this.$route.path != '/items') {
|
if (this.$route.path != '/items') {
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
|
@ -108,7 +116,18 @@
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
isMenuCompressed: false
|
isMenuCompressed: false
|
||||||
}
|
},
|
||||||
|
created(){
|
||||||
|
this.fetchMetadata({
|
||||||
|
collectionId: false,
|
||||||
|
isRepositoryLevel: true,
|
||||||
|
isContextEdit: false,
|
||||||
|
includeDisabled: false,
|
||||||
|
})
|
||||||
|
.then((metadata) => {
|
||||||
|
this.metadata = metadata;
|
||||||
|
});
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -146,7 +165,7 @@
|
||||||
}
|
}
|
||||||
.tainacan-logo {
|
.tainacan-logo {
|
||||||
max-height: 22px;
|
max-height: 22px;
|
||||||
padding: 0px 24px;
|
padding: 0 24px;
|
||||||
transition: padding 0.15s;
|
transition: padding 0.15s;
|
||||||
-webkit-transition: padding linear 0.15s;
|
-webkit-transition: padding linear 0.15s;
|
||||||
}
|
}
|
||||||
|
@ -159,8 +178,8 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
margin-right: 36px;
|
margin-right: 36px;
|
||||||
|
|
||||||
.control:not(.tnc-advanced-search-container) {
|
.control {
|
||||||
input {
|
.search-header {
|
||||||
border-width: 0 !important;
|
border-width: 0 !important;
|
||||||
height: 27px;
|
height: 27px;
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
|
@ -169,10 +188,10 @@
|
||||||
-webkit-transition: width linear 0.15s;
|
-webkit-transition: width linear 0.15s;
|
||||||
width: 160px;
|
width: 160px;
|
||||||
}
|
}
|
||||||
input:focus, input:active {
|
.search-header:focus, .search-header:active {
|
||||||
width: 220px !important;
|
width: 220px !important;
|
||||||
}
|
}
|
||||||
.icon {
|
.icon:not(.add-i) {
|
||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
color: $tertiary;
|
color: $tertiary;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
@ -182,18 +201,24 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*.dropdown-content {*/
|
.dropdown-content {
|
||||||
/*width: 800px !important;*/
|
width: 800px !important;
|
||||||
/*}*/
|
|
||||||
|
|
||||||
/*.dropdown-item:hover {*/
|
|
||||||
/*background-color: white;*/
|
|
||||||
/*}*/
|
|
||||||
|
|
||||||
a {
|
|
||||||
margin: 0px 12px;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dropdown-item:hover {
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-item {
|
||||||
|
span.icon:not(.is-right) {
|
||||||
|
position: relative !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*a {*/
|
||||||
|
/*margin: 0px 12px;*/
|
||||||
|
/*font-size: 12px;*/
|
||||||
|
/*}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.menu-compressed {
|
&.menu-compressed {
|
||||||
|
@ -201,20 +226,20 @@
|
||||||
width: 220px;
|
width: 220px;
|
||||||
background-color: $secondary;
|
background-color: $secondary;
|
||||||
.tainacan-logo {
|
.tainacan-logo {
|
||||||
padding: 0px 42px;
|
padding: 0 42px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 769px) {
|
@media screen and (max-width: 769px) {
|
||||||
padding: 0px;
|
padding: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
.level-left {
|
.level-left {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
margin-left: 0px !important;
|
margin-left: 0 !important;
|
||||||
.level-item {
|
.level-item {
|
||||||
margin-left: 0px;
|
margin-left: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.level-right {
|
.level-right {
|
||||||
|
@ -222,8 +247,8 @@
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
top: 0px;
|
top: 0;
|
||||||
margin-bottom: 0px !important;
|
margin-bottom: 0 !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ a:hover {
|
||||||
&.disabled {
|
&.disabled {
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
color: $tainacan-input-background;
|
color: $tainacan-input-background !important;
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
color: $tainacan-input-background !important;
|
color: $tainacan-input-background !important;
|
||||||
|
|
|
@ -265,7 +265,7 @@ class Collections extends Repository {
|
||||||
$this->pre_update_moderators( $collection );
|
$this->pre_update_moderators( $collection );
|
||||||
$new_collection = parent::insert( $collection );
|
$new_collection = parent::insert( $collection );
|
||||||
|
|
||||||
$Tainacan_Metadata->register_core_metadata( $new_collection );
|
//$Tainacan_Metadata->register_core_metadata( $new_collection );
|
||||||
$collection->register_collection_item_post_type();
|
$collection->register_collection_item_post_type();
|
||||||
flush_rewrite_rules(false); // needed to activate items post type archive url
|
flush_rewrite_rules(false); // needed to activate items post type archive url
|
||||||
$this->update_moderators( $new_collection );
|
$this->update_moderators( $new_collection );
|
||||||
|
|
|
@ -52,8 +52,8 @@ class Item_Metadata extends Repository {
|
||||||
if ($metadata_type->get_core()) {
|
if ($metadata_type->get_core()) {
|
||||||
$this->save_core_metadatum_value($item_metadata);
|
$this->save_core_metadatum_value($item_metadata);
|
||||||
// Core metadata are also stored as regular metadata (in the code following below)
|
// Core metadata are also stored as regular metadata (in the code following below)
|
||||||
// This is usefull to create queries via filters, advanced search or apis
|
// This is useful to create queries via filters, advanced search or APIs
|
||||||
// si you can search for title and content with meta_query as if they were regular metadata
|
// if you can search for title and content with meta_query as if they were regular metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($metadata_type->get_primitive_type() == 'term') {
|
if ($metadata_type->get_primitive_type() == 'term') {
|
||||||
|
@ -122,11 +122,14 @@ class Item_Metadata extends Repository {
|
||||||
|
|
||||||
public function save_core_metadatum_value(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
|
public function save_core_metadatum_value(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
|
||||||
$metadata_type = $item_metadata->get_metadatum()->get_metadata_type_object();
|
$metadata_type = $item_metadata->get_metadatum()->get_metadata_type_object();
|
||||||
|
|
||||||
if ($metadata_type->get_core()) {
|
if ($metadata_type->get_core()) {
|
||||||
$item = $item_metadata->get_item();
|
$item = $item_metadata->get_item();
|
||||||
$set_method = 'set_' . $metadata_type->get_related_mapped_prop();
|
$set_method = 'set_' . $metadata_type->get_related_mapped_prop();
|
||||||
|
|
||||||
$value = $item_metadata->get_value();
|
$value = $item_metadata->get_value();
|
||||||
$item->$set_method( is_array( $value ) ? $value[0] : $value );
|
$item->$set_method( is_array( $value ) ? $value[0] : $value );
|
||||||
|
|
||||||
if ($item->validate_core_metadata()) {
|
if ($item->validate_core_metadata()) {
|
||||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||||
$Tainacan_Items->insert($item);
|
$Tainacan_Items->insert($item);
|
||||||
|
|
|
@ -37,6 +37,8 @@ class Metadata extends Repository {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
add_filter('pre_trash_post', array( &$this, 'disable_delete_core_metadata' ), 10, 2 );
|
add_filter('pre_trash_post', array( &$this, 'disable_delete_core_metadata' ), 10, 2 );
|
||||||
add_filter('pre_delete_post', array( &$this, 'force_delete_core_metadata' ), 10, 3 );
|
add_filter('pre_delete_post', array( &$this, 'force_delete_core_metadata' ), 10, 3 );
|
||||||
|
|
||||||
|
add_action('tainacan-collection-parent-updated', array(&$this, 'update_core_metadata_meta_keys'), 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_map() {
|
public function get_map() {
|
||||||
|
@ -496,6 +498,154 @@ class Metadata extends Repository {
|
||||||
return $this->metadata_types;
|
return $this->metadata_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* That function update the core metadatum meta key, in case of changing the collection parent
|
||||||
|
*
|
||||||
|
* @param Entities\Collection $collection
|
||||||
|
* @param $parent_collection_id
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
|
public function update_core_metadata_meta_keys($collection_old, Entities\Collection $collection_new){
|
||||||
|
|
||||||
|
global $wpdb;
|
||||||
|
|
||||||
|
$wpdb->flush();
|
||||||
|
|
||||||
|
$item_post_type = "%%{$collection_new->get_id()}_item";
|
||||||
|
$parent_collection_id = $collection_new->get_parent();
|
||||||
|
|
||||||
|
if($parent_collection_id != 0){
|
||||||
|
|
||||||
|
$metadata = $this->get_core_metadata( $collection_new );
|
||||||
|
|
||||||
|
$data_core_metadata = $this->get_data_core_metadata($collection_new);
|
||||||
|
|
||||||
|
$parent_collection = new Entities\Collection($parent_collection_id);
|
||||||
|
|
||||||
|
$parent_cores = $this->get_core_metadata($parent_collection);
|
||||||
|
|
||||||
|
if(!empty($metadata)){
|
||||||
|
|
||||||
|
foreach ( $data_core_metadata as $index => $data_core_metadatum ) {
|
||||||
|
foreach ( $metadata as $metadatum ){
|
||||||
|
if ( $metadatum->get_metadata_type() === $data_core_metadatum['metadata_type'] ) {
|
||||||
|
foreach ($parent_cores as $parent_core){
|
||||||
|
if($metadatum->get_metadata_type() === $parent_core->get_metadata_type()){
|
||||||
|
|
||||||
|
$old_metadatum_id = $metadatum->get_id();
|
||||||
|
$new_metadatum_id = $parent_core->get_id();
|
||||||
|
|
||||||
|
$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 LIKE %s
|
||||||
|
)", $new_metadatum_id, $old_metadatum_id, $item_post_type
|
||||||
|
);
|
||||||
|
|
||||||
|
$res = $wpdb->query($sql_statement);
|
||||||
|
|
||||||
|
wp_cache_flush();
|
||||||
|
|
||||||
|
if($res !== false) {
|
||||||
|
update_post_meta( $metadatum->get_id(), 'metadata_type', 'to_delete', $data_core_metadatum['metadata_type'] );
|
||||||
|
wp_delete_post( $metadatum->get_id(), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$old_parent = 0;
|
||||||
|
|
||||||
|
if (!$collection_old) {
|
||||||
|
$this->register_core_metadata($collection_new);
|
||||||
|
} else {
|
||||||
|
$old_parent = $collection_old->get_parent();
|
||||||
|
|
||||||
|
$this->register_core_metadata($collection_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($old_parent != 0) {
|
||||||
|
$metadata = $this->get_core_metadata( $collection_new );
|
||||||
|
|
||||||
|
$data_core_metadata = $this->get_data_core_metadata( $collection_new );
|
||||||
|
|
||||||
|
$parent_collection = new Entities\Collection( $old_parent );
|
||||||
|
|
||||||
|
$parent_cores = $this->get_core_metadata( $parent_collection );
|
||||||
|
|
||||||
|
foreach ( $data_core_metadata as $index => $data_core_metadatum ) {
|
||||||
|
foreach ( $metadata as $metadatum ) {
|
||||||
|
if ( $metadatum->get_metadata_type() === $data_core_metadatum['metadata_type'] ) {
|
||||||
|
foreach ( $parent_cores as $parent_core ) {
|
||||||
|
if ( $metadatum->get_metadata_type() === $parent_core->get_metadata_type() ) {
|
||||||
|
|
||||||
|
$old_metadatum_id = $parent_core->get_id();
|
||||||
|
$new_metadatum_id = $metadatum->get_id();
|
||||||
|
|
||||||
|
$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 LIKE %s
|
||||||
|
)", $new_metadatum_id, $old_metadatum_id, $item_post_type
|
||||||
|
);
|
||||||
|
|
||||||
|
$res = $wpdb->query($sql_statement);
|
||||||
|
|
||||||
|
wp_cache_flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Entities\Collection $collection
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function get_data_core_metadata(Entities\Collection $collection){
|
||||||
|
|
||||||
|
return $data_core_metadata = [
|
||||||
|
'core_description' => [
|
||||||
|
'name' => 'Description',
|
||||||
|
'description' => 'description',
|
||||||
|
'collection_id' => $collection->get_id(),
|
||||||
|
'metadata_type' => 'Tainacan\Metadata_Types\Core_Description',
|
||||||
|
'status' => 'publish',
|
||||||
|
'exposer_mapping' => [
|
||||||
|
'dublin-core' => 'description'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'core_title' => [
|
||||||
|
'name' => 'Title',
|
||||||
|
'description' => 'title',
|
||||||
|
'collection_id' => $collection->get_id(),
|
||||||
|
'metadata_type' => 'Tainacan\Metadata_Types\Core_Title',
|
||||||
|
'status' => 'publish',
|
||||||
|
'exposer_mapping' => [
|
||||||
|
'dublin-core' => 'title'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Entities\Collection $collection
|
* @param Entities\Collection $collection
|
||||||
*
|
*
|
||||||
|
@ -507,45 +657,7 @@ class Metadata extends Repository {
|
||||||
|
|
||||||
$metadata = $this->get_core_metadata( $collection );
|
$metadata = $this->get_core_metadata( $collection );
|
||||||
|
|
||||||
// TODO: create a better way to retrieve this data
|
$data_core_metadata = $this->get_data_core_metadata($collection);
|
||||||
$data_core_metadata = [
|
|
||||||
'core_description' => [
|
|
||||||
'name' => 'Description',
|
|
||||||
'description' => 'description',
|
|
||||||
'collection_id' => $collection->get_id(),
|
|
||||||
'metadata_type' => 'Tainacan\Metadata_Types\Core_Description',
|
|
||||||
'status' => 'publish',
|
|
||||||
'exposer_mapping' => [
|
|
||||||
'dublin-core' => 'description'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
'core_title' => [
|
|
||||||
'name' => 'Title',
|
|
||||||
'description' => 'title',
|
|
||||||
'collection_id' => $collection->get_id(),
|
|
||||||
'metadata_type' => 'Tainacan\Metadata_Types\Core_Title',
|
|
||||||
'status' => 'publish',
|
|
||||||
'exposer_mapping' => [
|
|
||||||
'dublin-core' => 'title'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
if( $collection->get_parent() != 0 ){
|
|
||||||
|
|
||||||
if(!empty($metadata)){
|
|
||||||
foreach ( $data_core_metadata as $index => $data_core_metadatum ) {
|
|
||||||
foreach ( $metadata as $metadatum ){
|
|
||||||
if ( $metadatum->get_metadata_type() === $data_core_metadatum['metadata_type'] ) {
|
|
||||||
update_post_meta($metadatum->get_id(), 'metadata_type', 'to_delete', $data_core_metadatum['metadata_type']);
|
|
||||||
wp_delete_post($metadatum->get_id(), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ( $data_core_metadata as $index => $data_core_metadatum ) {
|
foreach ( $data_core_metadata as $index => $data_core_metadatum ) {
|
||||||
if( empty( $metadata ) ){
|
if( empty( $metadata ) ){
|
||||||
|
|
|
@ -77,8 +77,15 @@ abstract class Repository {
|
||||||
// TODO: Throw Warning saying you must validate object before insert()
|
// TODO: Throw Warning saying you must validate object before insert()
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_update = false;
|
$is_update = false;
|
||||||
$diffs = [];
|
$is_updated_parent = false;
|
||||||
|
$old = '';
|
||||||
|
|
||||||
|
if ( $obj instanceof Entities\Collection && $obj->get_status() != 'auto-draft' ) {
|
||||||
|
$is_updated_parent = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$diffs = [];
|
||||||
if ( $obj->get_id() ) {
|
if ( $obj->get_id() ) {
|
||||||
|
|
||||||
$old = $obj->get_repository()->fetch( $obj->get_id() );
|
$old = $obj->get_repository()->fetch( $obj->get_id() );
|
||||||
|
@ -109,15 +116,15 @@ abstract class Repository {
|
||||||
$obj->WP_Post->post_status = 'publish';
|
$obj->WP_Post->post_status = 'publish';
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $obj instanceof Entities\Item ){
|
if ( $obj instanceof Entities\Item ) {
|
||||||
// get collection to determine post type
|
// get collection to determine post type
|
||||||
$collection = $obj->get_collection();
|
$collection = $obj->get_collection();
|
||||||
|
|
||||||
if ( !$collection ) {
|
if ( ! $collection ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$post_t = $collection->get_db_identifier();
|
$post_t = $collection->get_db_identifier();
|
||||||
$obj->WP_Post->post_type = $post_t;
|
$obj->WP_Post->post_type = $post_t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,8 +141,11 @@ abstract class Repository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Logs for header image insert and update
|
if($is_updated_parent){
|
||||||
|
do_action('tainacan-collection-parent-updated', $old, $obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Logs for header image insert and update
|
||||||
do_action( 'tainacan-insert', $obj, $diffs, $is_update );
|
do_action( 'tainacan-insert', $obj, $diffs, $is_update );
|
||||||
do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj );
|
do_action( 'tainacan-insert-' . $obj->get_post_type(), $obj );
|
||||||
|
|
||||||
|
|
|
@ -7,16 +7,16 @@ class Item_Metadata_Factory {
|
||||||
|
|
||||||
public function create_item_metadata(\Tainacan\Entities\Item $item, \Tainacan\Entities\Metadatum $metadatum, $value = ''){
|
public function create_item_metadata(\Tainacan\Entities\Item $item, \Tainacan\Entities\Metadatum $metadatum, $value = ''){
|
||||||
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
|
||||||
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum);
|
$this->item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadatum);
|
||||||
|
|
||||||
if (!empty($value))
|
if (!empty($value))
|
||||||
$item_metadata->set_value($value);
|
$this->item_metadata->set_value($value);
|
||||||
|
|
||||||
if ($item_metadata->validate()) {
|
if ($this->item_metadata->validate()) {
|
||||||
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
$this->item_metadata = $Tainacan_Item_Metadata->insert($this->item_metadata);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $item_metadata; // If not validated, get_error() method should return the errors. Its up to the tests to use it or not
|
return $this->item_metadata; // If not validated, get_error() method should return the errors. Its up to the tests to use it or not
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,4 +209,131 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_collection_parent_change_and_update_core_metadata(){
|
||||||
|
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
|
||||||
|
|
||||||
|
$collection_parent2 = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'collection',
|
||||||
|
array(
|
||||||
|
'name' => 'Parent2',
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$collection_parent = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'collection',
|
||||||
|
array(
|
||||||
|
'name' => 'Parent',
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$collection_parent_item = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'item',
|
||||||
|
array(
|
||||||
|
'title' => 'Par',
|
||||||
|
'description' => 'par',
|
||||||
|
'status' => 'publish',
|
||||||
|
'collection' => $collection_parent,
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$core_metadata_parent = $collection_parent->get_core_metadata();
|
||||||
|
|
||||||
|
$item_metadatum_title0 = $this->tainacan_item_metadata_factory->create_item_metadata(
|
||||||
|
$collection_parent_item,
|
||||||
|
$core_metadata_parent[1], 'Son of son');
|
||||||
|
|
||||||
|
$item_metadatum_desc0 = $this->tainacan_item_metadata_factory->create_item_metadata(
|
||||||
|
$collection_parent_item, $core_metadata_parent[0],
|
||||||
|
'Desc of son of son');
|
||||||
|
|
||||||
|
$collection_son = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'collection',
|
||||||
|
array(
|
||||||
|
'name' => 'Son',
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$core_metadata_son = $collection_son->get_core_metadata();
|
||||||
|
|
||||||
|
# Creates a item
|
||||||
|
$collection_son_item = $this->tainacan_entity_factory->create_entity(
|
||||||
|
'item',
|
||||||
|
array(
|
||||||
|
'title' => 'Son of son',
|
||||||
|
'description' => 'Desc of son of son',
|
||||||
|
'collection' => $collection_son,
|
||||||
|
'status' => 'publish'
|
||||||
|
),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$item_metadatum_title = $this->tainacan_item_metadata_factory->create_item_metadata($collection_son_item,
|
||||||
|
$core_metadata_son[1], 'Son of son');
|
||||||
|
|
||||||
|
$item_metadatum_desc = $this->tainacan_item_metadata_factory->create_item_metadata($collection_son_item, $core_metadata_son[0],
|
||||||
|
'Desc of son of son');
|
||||||
|
|
||||||
|
$this->assertEquals($core_metadata_son[0]->get_id(), $item_metadatum_desc->get_metadatum()->get_id());
|
||||||
|
$this->assertEquals($core_metadata_son[1]->get_id(), $item_metadatum_title->get_metadatum()->get_id());
|
||||||
|
|
||||||
|
$this->assertNotEquals($core_metadata_parent[0]->get_id(), $item_metadatum_desc->get_metadatum()->get_id());
|
||||||
|
$this->assertNotEquals($core_metadata_parent[1]->get_id(), $item_metadatum_title->get_metadatum()->get_id());
|
||||||
|
|
||||||
|
# When updated the parent, the item metadata key, have to be update too
|
||||||
|
$collection_son->set_parent($collection_parent->get_id());
|
||||||
|
|
||||||
|
$collection_son->validate();
|
||||||
|
$collection_son = $Tainacan_Collections->update($collection_son);
|
||||||
|
|
||||||
|
$core_metadata_son = $collection_son->get_core_metadata();
|
||||||
|
|
||||||
|
$this->assertNotEquals($core_metadata_son[0]->get_id(), $item_metadatum_desc->get_metadatum()->get_id());
|
||||||
|
$this->assertNotEquals($core_metadata_son[1]->get_id(), $item_metadatum_title->get_metadatum()->get_id());
|
||||||
|
|
||||||
|
$it = get_post_meta($collection_son_item->get_id());
|
||||||
|
|
||||||
|
$this->assertArrayHasKey($core_metadata_parent[0]->get_id(), $it);
|
||||||
|
$this->assertArrayHasKey($core_metadata_parent[1]->get_id(), $it);
|
||||||
|
|
||||||
|
# Changes parent again
|
||||||
|
$collection_son->set_parent(0);
|
||||||
|
|
||||||
|
$collection_son->validate();
|
||||||
|
$collection_son = $Tainacan_Collections->update($collection_son);
|
||||||
|
|
||||||
|
$core_metadata_son2 = $collection_son->get_core_metadata();
|
||||||
|
|
||||||
|
$it2 = get_post_meta($collection_son_item->get_id());
|
||||||
|
|
||||||
|
$this->assertArrayHasKey($core_metadata_son2[0]->get_id(), $it2);
|
||||||
|
$this->assertArrayHasKey($core_metadata_son2[1]->get_id(), $it2);
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey($core_metadata_parent[0]->get_id(), $it2);
|
||||||
|
$this->assertArrayNotHasKey($core_metadata_parent[1]->get_id(), $it2);
|
||||||
|
|
||||||
|
# Changes parent again
|
||||||
|
$collection_son->set_parent($collection_parent2->get_id());
|
||||||
|
|
||||||
|
$collection_son->validate();
|
||||||
|
$collection_son = $Tainacan_Collections->update($collection_son);
|
||||||
|
|
||||||
|
$core_metadata_son3 = $collection_son->get_core_metadata();
|
||||||
|
|
||||||
|
$it3 = get_post_meta($collection_son_item->get_id());
|
||||||
|
|
||||||
|
$this->assertArrayHasKey($core_metadata_son3[0]->get_id(), $it3);
|
||||||
|
$this->assertArrayHasKey($core_metadata_son3[1]->get_id(), $it3);
|
||||||
|
|
||||||
|
$this->assertArrayNotHasKey($core_metadata_parent[0]->get_id(), $it3);
|
||||||
|
$this->assertArrayNotHasKey($core_metadata_parent[1]->get_id(), $it3);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -81,7 +81,7 @@ const production = false;
|
||||||
if (production === true) {
|
if (production === true) {
|
||||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||||
|
|
||||||
console.log({'production': production});
|
console.log(`production: ${production}`);
|
||||||
|
|
||||||
module.exports.mode = 'production';
|
module.exports.mode = 'production';
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ if (production === true) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log({'production': production});
|
console.log(`production: ${production}`);
|
||||||
|
|
||||||
module.exports.devtool = '';
|
module.exports.devtool = '';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue