Merge branch 'feature/advanced-search-shortcut-in-header' into develop
This commit is contained in:
commit
7795f39c37
|
@ -15,7 +15,9 @@
|
|||
grouped>
|
||||
|
||||
<!-- Metadata (Search criteria) -->
|
||||
<b-field class="column">
|
||||
<b-field
|
||||
:class="{'is-3': isHeader}"
|
||||
class="column">
|
||||
<b-select
|
||||
:placeholder="$i18n.get('instruction_select_a_metadatum')"
|
||||
:disabled="advancedSearchQuery.taxquery[searchCriterion] ||
|
||||
|
@ -34,7 +36,8 @@
|
|||
|
||||
<!-- Inputs -->
|
||||
<b-field
|
||||
class="column is-two-thirds">
|
||||
:class="{'is-two-thirds': !isHeader}"
|
||||
class="column">
|
||||
<b-input
|
||||
v-if="advancedSearchQuery.metaquery[searchCriterion] &&
|
||||
advancedSearchQuery.metaquery[searchCriterion].ptype != 'date'"
|
||||
|
@ -71,6 +74,7 @@
|
|||
|
||||
<!-- Comparators -->
|
||||
<b-field
|
||||
:class="{'is-3': isHeader}"
|
||||
class="column">
|
||||
<b-select
|
||||
v-if="advancedSearchQuery.taxquery[searchCriterion] ||
|
||||
|
@ -104,15 +108,13 @@
|
|||
<!-- Add button -->
|
||||
<div
|
||||
v-show="!advancedSearchResults"
|
||||
:style="{
|
||||
'margin-top': '-15px !important',
|
||||
'padding-left': '25px !important'
|
||||
}"
|
||||
:class="{'add-link-advanced-search-header': isHeader, 'add-link-advanced-search': !isHeader }"
|
||||
class="field column is-12">
|
||||
<a
|
||||
@click="addSearchCriteria"
|
||||
class="is-secondary is-small add-link">
|
||||
class="is-secondary add-link">
|
||||
<b-icon
|
||||
class="add-i"
|
||||
icon="plus-circle"
|
||||
size="is-small"
|
||||
type="is-secondary"/>
|
||||
|
@ -188,6 +190,7 @@
|
|||
props: {
|
||||
metadata: Array,
|
||||
isRepositoryLevel: false,
|
||||
isHeader: false,
|
||||
advancedSearchResults: false,
|
||||
openFormAdvancedSearch: false,
|
||||
isDoSearch: false,
|
||||
|
@ -407,6 +410,19 @@
|
|||
this.addToAdvancedSearchQuery(value, type, searchCriterion);
|
||||
}, 900),
|
||||
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 &&
|
||||
Object.keys(this.advancedSearchQuery.metaquery).length > 0){
|
||||
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>
|
|
@ -21,38 +21,41 @@
|
|||
<input
|
||||
autocomplete="on"
|
||||
:placeholder="$i18n.get('instruction_search_in_repository')"
|
||||
class="input is-small"
|
||||
class="input is-small search-header"
|
||||
type="search"
|
||||
:value="searchQuery"
|
||||
@input="futureSearchQuery = $event.target.value"
|
||||
@keyup.enter="updateSearch()">
|
||||
<span class="icon is-right">
|
||||
<i
|
||||
@click="updateSearch()"
|
||||
class="mdi mdi-magnify"/>
|
||||
</span>
|
||||
<!--<b-dropdown-->
|
||||
<!--position="is-bottom-left">-->
|
||||
<!--<b-icon-->
|
||||
<!--class="is-right"-->
|
||||
<!--slot="trigger"-->
|
||||
<!--size="is-small"-->
|
||||
<!--icon="menu-down"/>-->
|
||||
<!--<b-dropdown-item>-->
|
||||
<!--<p class="is-left">{{ $i18n.get('advanced_search') }}</p>-->
|
||||
<!--<b-icon-->
|
||||
<!--icon="menu-up"-->
|
||||
<!--class="is-right" />-->
|
||||
<!--</b-dropdown-item>-->
|
||||
<!--<b-dropdown-item-->
|
||||
<!--:custom="true">-->
|
||||
<!--<advanced-search />-->
|
||||
<!--</b-dropdown-item>-->
|
||||
<!--</b-dropdown>-->
|
||||
<!--<span class="icon is-right">-->
|
||||
<!--<i-->
|
||||
<!--@click="updateSearch()"-->
|
||||
<!--class="mdi mdi-magnify"/>-->
|
||||
<!--</span>-->
|
||||
<b-dropdown
|
||||
class="advanced-search-header-dropdown"
|
||||
position="is-bottom-left">
|
||||
<b-icon
|
||||
class="is-right"
|
||||
slot="trigger"
|
||||
size="is-small"
|
||||
icon="menu-down"/>
|
||||
<b-dropdown-item>
|
||||
<p class="is-left">{{ $i18n.get('advanced_search') }}</p>
|
||||
<b-icon
|
||||
icon="menu-up"
|
||||
class="is-right" />
|
||||
</b-dropdown-item>
|
||||
<b-dropdown-item
|
||||
:custom="true">
|
||||
<advanced-search
|
||||
:metadata="metadata"
|
||||
:is-header="true"/>
|
||||
</b-dropdown-item>
|
||||
</b-dropdown>
|
||||
</div>
|
||||
<a
|
||||
:style="{color: 'white'}"
|
||||
@click="toItemsPage">{{ $i18n.get('advanced_search') }}</a>
|
||||
<!--<a-->
|
||||
<!--:style="{color: 'white'}"-->
|
||||
<!--@click="toItemsPage">{{ $i18n.get('advanced_search') }}</a>-->
|
||||
</div>
|
||||
<a
|
||||
:style="{color: 'white'}"
|
||||
|
@ -67,6 +70,7 @@
|
|||
<script>
|
||||
|
||||
import AdvancedSearch from '../advanced-search/advanced-search.vue';
|
||||
import { mapActions } from 'vuex';
|
||||
|
||||
export default {
|
||||
name: 'TainacanHeader',
|
||||
|
@ -76,26 +80,30 @@
|
|||
wordpressAdmin: window.location.origin + window.location.pathname.replace('admin.php', ''),
|
||||
searchQuery: '',
|
||||
futureSearchQuery: '',
|
||||
metadata: Array,
|
||||
}
|
||||
},
|
||||
components: {
|
||||
AdvancedSearch,
|
||||
},
|
||||
methods: {
|
||||
toItemsPage() {
|
||||
if(this.$route.path == '/items') {
|
||||
this.$root.$emit('openAdvancedSearch', true);
|
||||
}
|
||||
|
||||
if(this.$route.path != '/items') {
|
||||
this.$router.push({
|
||||
path: '/items',
|
||||
query: {
|
||||
advancedSearch: true
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
...mapActions('metadata', [
|
||||
'fetchMetadata'
|
||||
]),
|
||||
// toItemsPage() {
|
||||
// if(this.$route.path == '/items') {
|
||||
// this.$root.$emit('openAdvancedSearch', true);
|
||||
// }
|
||||
//
|
||||
// if(this.$route.path != '/items') {
|
||||
// this.$router.push({
|
||||
// path: '/items',
|
||||
// query: {
|
||||
// advancedSearch: true
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
updateSearch() {
|
||||
if (this.$route.path != '/items') {
|
||||
this.$router.push({
|
||||
|
@ -108,7 +116,18 @@
|
|||
},
|
||||
props: {
|
||||
isMenuCompressed: false
|
||||
}
|
||||
},
|
||||
created(){
|
||||
this.fetchMetadata({
|
||||
collectionId: false,
|
||||
isRepositoryLevel: true,
|
||||
isContextEdit: false,
|
||||
includeDisabled: false,
|
||||
})
|
||||
.then((metadata) => {
|
||||
this.metadata = metadata;
|
||||
});
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -146,7 +165,7 @@
|
|||
}
|
||||
.tainacan-logo {
|
||||
max-height: 22px;
|
||||
padding: 0px 24px;
|
||||
padding: 0 24px;
|
||||
transition: padding 0.15s;
|
||||
-webkit-transition: padding linear 0.15s;
|
||||
}
|
||||
|
@ -159,8 +178,8 @@
|
|||
align-items: center;
|
||||
margin-right: 36px;
|
||||
|
||||
.control:not(.tnc-advanced-search-container) {
|
||||
input {
|
||||
.control {
|
||||
.search-header {
|
||||
border-width: 0 !important;
|
||||
height: 27px;
|
||||
font-size: 11px;
|
||||
|
@ -169,10 +188,10 @@
|
|||
-webkit-transition: width linear 0.15s;
|
||||
width: 160px;
|
||||
}
|
||||
input:focus, input:active {
|
||||
.search-header:focus, .search-header:active {
|
||||
width: 220px !important;
|
||||
}
|
||||
.icon {
|
||||
.icon:not(.add-i) {
|
||||
pointer-events: all;
|
||||
color: $tertiary;
|
||||
cursor: pointer;
|
||||
|
@ -182,18 +201,24 @@
|
|||
}
|
||||
}
|
||||
|
||||
/*.dropdown-content {*/
|
||||
/*width: 800px !important;*/
|
||||
/*}*/
|
||||
|
||||
/*.dropdown-item:hover {*/
|
||||
/*background-color: white;*/
|
||||
/*}*/
|
||||
|
||||
a {
|
||||
margin: 0px 12px;
|
||||
font-size: 12px;
|
||||
.dropdown-content {
|
||||
width: 800px !important;
|
||||
}
|
||||
|
||||
.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 {
|
||||
|
@ -201,20 +226,20 @@
|
|||
width: 220px;
|
||||
background-color: $secondary;
|
||||
.tainacan-logo {
|
||||
padding: 0px 42px;
|
||||
padding: 0 42px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@media screen and (max-width: 769px) {
|
||||
padding: 0px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
.level-left {
|
||||
display: inline-block;
|
||||
margin-left: 0px !important;
|
||||
margin-left: 0 !important;
|
||||
.level-item {
|
||||
margin-left: 0px;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
.level-right {
|
||||
|
@ -222,8 +247,8 @@
|
|||
display: inline-block;
|
||||
}
|
||||
|
||||
top: 0px;
|
||||
margin-bottom: 0px !important;
|
||||
top: 0;
|
||||
margin-bottom: 0 !important;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ a:hover {
|
|||
&.disabled {
|
||||
pointer-events: none;
|
||||
cursor: default;
|
||||
color: $tainacan-input-background;
|
||||
color: $tainacan-input-background !important;
|
||||
|
||||
.icon {
|
||||
color: $tainacan-input-background !important;
|
||||
|
|
|
@ -265,7 +265,7 @@ class Collections extends Repository {
|
|||
$this->pre_update_moderators( $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();
|
||||
flush_rewrite_rules(false); // needed to activate items post type archive url
|
||||
$this->update_moderators( $new_collection );
|
||||
|
|
|
@ -52,8 +52,8 @@ class Item_Metadata extends Repository {
|
|||
if ($metadata_type->get_core()) {
|
||||
$this->save_core_metadatum_value($item_metadata);
|
||||
// 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
|
||||
// si you can search for title and content with meta_query as if they were regular metadata
|
||||
// This is useful to create queries via filters, advanced search or APIs
|
||||
// if you can search for title and content with meta_query as if they were regular metadata
|
||||
}
|
||||
|
||||
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) {
|
||||
$metadata_type = $item_metadata->get_metadatum()->get_metadata_type_object();
|
||||
|
||||
if ($metadata_type->get_core()) {
|
||||
$item = $item_metadata->get_item();
|
||||
$set_method = 'set_' . $metadata_type->get_related_mapped_prop();
|
||||
|
||||
$value = $item_metadata->get_value();
|
||||
$item->$set_method( is_array( $value ) ? $value[0] : $value );
|
||||
|
||||
if ($item->validate_core_metadata()) {
|
||||
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
|
||||
$Tainacan_Items->insert($item);
|
||||
|
|
|
@ -37,6 +37,8 @@ class Metadata extends Repository {
|
|||
parent::__construct();
|
||||
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_action('tainacan-collection-parent-updated', array(&$this, 'update_core_metadata_meta_keys'), 10, 2);
|
||||
}
|
||||
|
||||
public function get_map() {
|
||||
|
@ -496,19 +498,130 @@ class Metadata extends Repository {
|
|||
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 bool
|
||||
* @throws \ErrorException
|
||||
* @throws \Exception
|
||||
* @return array
|
||||
*/
|
||||
public function register_core_metadata( Entities\Collection $collection ){
|
||||
private function get_data_core_metadata(Entities\Collection $collection){
|
||||
|
||||
$metadata = $this->get_core_metadata( $collection );
|
||||
|
||||
// TODO: create a better way to retrieve this data
|
||||
$data_core_metadata = [
|
||||
return $data_core_metadata = [
|
||||
'core_description' => [
|
||||
'name' => 'Description',
|
||||
'description' => 'description',
|
||||
|
@ -531,21 +644,20 @@ class Metadata extends Repository {
|
|||
]
|
||||
];
|
||||
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* @param Entities\Collection $collection
|
||||
*
|
||||
* @return bool
|
||||
* @throws \ErrorException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function register_core_metadata( Entities\Collection $collection ){
|
||||
|
||||
$metadata = $this->get_core_metadata( $collection );
|
||||
|
||||
$data_core_metadata = $this->get_data_core_metadata($collection);
|
||||
|
||||
foreach ( $data_core_metadata as $index => $data_core_metadatum ) {
|
||||
if( empty( $metadata ) ){
|
||||
|
|
|
@ -78,6 +78,13 @@ abstract class Repository {
|
|||
}
|
||||
|
||||
$is_update = false;
|
||||
$is_updated_parent = false;
|
||||
$old = '';
|
||||
|
||||
if ( $obj instanceof Entities\Collection && $obj->get_status() != 'auto-draft' ) {
|
||||
$is_updated_parent = true;
|
||||
}
|
||||
|
||||
$diffs = [];
|
||||
if ( $obj->get_id() ) {
|
||||
|
||||
|
@ -109,11 +116,11 @@ abstract class Repository {
|
|||
$obj->WP_Post->post_status = 'publish';
|
||||
}
|
||||
|
||||
if( $obj instanceof Entities\Item ){
|
||||
if ( $obj instanceof Entities\Item ) {
|
||||
// get collection to determine post type
|
||||
$collection = $obj->get_collection();
|
||||
|
||||
if ( !$collection ) {
|
||||
if ( ! $collection ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -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->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 = ''){
|
||||
$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))
|
||||
$item_metadata->set_value($value);
|
||||
$this->item_metadata->set_value($value);
|
||||
|
||||
if ($item_metadata->validate()) {
|
||||
$item_metadata = $Tainacan_Item_Metadata->insert($item_metadata);
|
||||
if ($this->item_metadata->validate()) {
|
||||
$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) {
|
||||
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
|
||||
|
||||
console.log({'production': production});
|
||||
console.log(`production: ${production}`);
|
||||
|
||||
module.exports.mode = 'production';
|
||||
|
||||
|
@ -109,7 +109,7 @@ if (production === true) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
console.log({'production': production});
|
||||
console.log(`production: ${production}`);
|
||||
|
||||
module.exports.devtool = '';
|
||||
|
||||
|
|
Loading…
Reference in New Issue