Fixes return of update metadata

This commit is contained in:
weryques 2018-02-14 16:52:50 -02:00
parent 60e362e624
commit 195133a02c
2 changed files with 16 additions and 6 deletions

View File

@ -55,10 +55,10 @@ class Item_Metadata extends Repository {
$values = $item_metadata->get_value();
foreach ($values as $value){
if(array_key_exists('prev', $value)) {
if(array_key_exists('prev', $value) && !empty($value['prev'])) {
update_post_meta( $item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value['new'] ), wp_slash($value['prev']) );
} else {
add_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value ));
add_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value['new'] ));
}
}
}
@ -67,7 +67,11 @@ class Item_Metadata extends Repository {
do_action('tainacan-update', $item_metadata);
do_action('tainacan-update-Item_Metadata_Entity', $item_metadata);
return new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field());
$value = get_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id());
$item_metadata = new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field());
$item_metadata->set_value($value);
return $item_metadata;
}
/**

View File

@ -148,13 +148,17 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
'collection' => $collection,
'status' => 'publish',
'field_type' => 'Tainacan\Field_Types\Text',
'multiple' => 'yes'
),
true
);
$meta_values = json_encode(
array(
'values' => '19/01/2018'
'values' => array(
array('new' => '19/01/2018', 'prev' => ''),
array('new' => '19/02/2018', 'prev' => '')
)
)
);
@ -172,9 +176,11 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals($field->get_id(), $field_updated['id']);
$metav = get_post_meta($item->get_id(), $field_updated['id'], true);
$metav = get_post_meta($item->get_id(), $field_updated['id']);
$this->assertEquals('19/01/2018', $metav);
var_dump($metav);
$this->assertEquals('19/01/2018', $metav[0]);
#### UPDATE FIELD IN COLLECTION ####