store core metadata values also in metadata table

This commit is contained in:
Leo Germani 2018-06-12 11:44:42 -03:00
parent 43f1fbe1ed
commit 7e78668225
2 changed files with 26 additions and 23 deletions

View File

@ -48,9 +48,15 @@ class Item_Metadata extends Repository {
$unique = !$item_metadata->is_multiple(); $unique = !$item_metadata->is_multiple();
$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()) {
$this->save_core_metadatum_value($item_metadata); $this->save_core_metadatum_value($item_metadata);
} elseif ($metadata_type->get_primitive_type() == 'term') { // 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
}
if ($metadata_type->get_primitive_type() == 'term') {
$this->save_terms_metadatum_value($item_metadata); $this->save_terms_metadatum_value($item_metadata);
} elseif ($metadata_type->get_primitive_type() == 'compound') { } elseif ($metadata_type->get_primitive_type() == 'compound') {
// do nothing. Compound values are updated when its child metadata are updated // do nothing. Compound values are updated when its child metadata are updated

View File

@ -25,31 +25,14 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
'collection', 'collection',
array( array(
'name' => 'test', 'name' => 'test',
'status' => 'publish'
), ),
true true
); );
$metadatum = $this->tainacan_entity_factory->create_entity( $metadatum = $collection->get_core_title_metadatum();
'metadatum',
array(
'name' => 'metadado',
'description' => 'title',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Core_Title'
),
true
);
$metadatumDescription = $this->tainacan_entity_factory->create_entity( $metadatumDescription = $collection->get_core_description_metadatum();
'metadatum',
array(
'name' => 'metadado_desc',
'description' => 'description',
'collection' => $collection,
'metadata_type' => 'Tainacan\Metadata_Types\Core_Description'
),
true
);
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
@ -57,7 +40,8 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
array( array(
'title' => 'item test', 'title' => 'item test',
'description' => 'adasdasdsa', 'description' => 'adasdasdsa',
'collection' => $collection 'collection' => $collection,
'status' => 'publish'
), ),
true true
); );
@ -91,6 +75,19 @@ class CoreMetadatumTypes extends TAINACAN_UnitTestCase {
$check_item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($checkItem, $metadatumDescription); $check_item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($checkItem, $metadatumDescription);
$this->assertEquals('changed description', $check_item_metadata->get_value()); $this->assertEquals('changed description', $check_item_metadata->get_value());
// check that the value was also stored in postmeta table
$checkMeta = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $metadatumDescription->get_id(),
'value' => 'changed description'
]
]
], [], 'OBJECT');
$this->assertEquals(1, sizeof($checkMeta));
$this->assertEquals('changed description', $checkMeta[0]->get_description());
} }
function test_validate_required_title() { function test_validate_required_title() {