Trash metadata

This commit is contained in:
weryques 2018-02-23 11:59:13 -03:00
parent d7b81590f2
commit 20570a64a0
5 changed files with 45 additions and 56 deletions

View File

@ -230,14 +230,13 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
if(!empty($request->get_body())){
$body = json_decode($request->get_body());
$field_id = $request['field_id'];
$collection_id = $request['collection_id'];
$field_id = $body['field_id'];
$field_trashed = $this->field_repository->delete($field_id);
return new WP_REST_Response(['error' => 'Not Implemented.'], 400);
}
$prepared = $this->prepare_item_for_response($field_trashed, $request);
return new WP_REST_Response($prepared, 200);
}
/**

View File

@ -142,41 +142,6 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
return parent::get_collection_params(); // TODO: Change the autogenerated stub
}
/**
* @param WP_REST_Request $request
*
* @return WP_Error|WP_REST_Response
*/
public function delete_item( $request ) {
if(!empty($request->get_body())){
$body = json_decode($request->get_body());
$collection_id = $request['collection_id'];
$field_id = $body['metadata_id'];
return new WP_REST_Response(['error' => 'Not Implemented.'], 400);
}
}
/**
* @param WP_REST_Request $request
*
* @return bool|WP_Error
* @throws Exception
*/
public function delete_item_permissions_check( $request ) {
if(isset($request['item_id'])){
$item = $this->item_repository->fetch($request['item_id']);
if($item instanceof Entities\Item) {
return $item->can_delete();
}
}
return false;
}
/**
* @param WP_REST_Request $request
*

View File

@ -414,8 +414,8 @@ class Fields extends Repository {
return $this->insert($object);
}
public function delete($object){
public function delete($field_id){
return new Entities\Field( wp_trash_post( $field_id ) );
}
/**

View File

@ -39,23 +39,11 @@ class Item_Metadata extends Repository {
}
/**
* Delete Item Field
*
* @param $item_metadata
*
* @return mixed|void
*/
public function delete($item_metadata){
// if(is_array($item_metadata->get_value())){
// $values = $item_metadata->get_value();
//
// foreach ($values as $value){
// delete_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash($value));
// }
// } else {
// delete_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash($item_metadata->get_value()));
// }
}
public function delete($item_metadata){}
public function save_core_field_value(\Tainacan\Entities\Item_Metadata_Entity $item_metadata) {
$field_type = $item_metadata->get_field()->get_field_type_object();

View File

@ -210,6 +210,43 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
}
public function test_trash_field(){
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'Statement',
'description' => 'No Statement'
),
true
);
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Field Statement',
'description' => 'No Statement',
'collection' => $collection,
'status' => 'publish',
'field_type' => 'Tainacan\Field_Types\Text',
'multiple' => 'yes'
),
true
);
$trash_field_request = new \WP_REST_Request(
'DELETE',
$this->namespace . '/collection/'. $collection->get_id() . '/fields/' . $field->get_id()
);
$trash_field_response = $this->server->dispatch($trash_field_request);
$data1 = $trash_field_response->get_data();
$this->assertEquals($field->get_id(), $data1['id']);
$field_trashed = get_post($data1['id']);
$this->assertEquals('trash', $field_trashed->post_status);
}
}
?>