diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php index a36af671d..a0088b972 100644 --- a/src/api/endpoints/class-tainacan-rest-filters-controller.php +++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php @@ -147,7 +147,8 @@ class TAINACAN_REST_Filters_Controller extends WP_REST_Controller { } public function delete_item_permissions_check( $request ) { - return parent::delete_item_permissions_check( $request ); // TODO: Change the autogenerated stub + $filter = $this->filter_repository->fetch($request['filter_id']); + return $this->filter_repository->can_delete($filter); } } diff --git a/src/classes/repositories/class-tainacan-filters.php b/src/classes/repositories/class-tainacan-filters.php index dd7e5d442..5d8964619 100644 --- a/src/classes/repositories/class-tainacan-filters.php +++ b/src/classes/repositories/class-tainacan-filters.php @@ -139,9 +139,9 @@ class Filters extends Repository { update_post_meta($id, $prop, $metadata->get_mapped_property($prop)); } elseif ($mapped['map'] == 'meta_multi') { $values = $metadata->get_mapped_property($prop); - + delete_post_meta($id, $prop); - + if (is_array($values)){ foreach ($values as $value){ add_post_meta($id, $prop, $value); @@ -154,8 +154,17 @@ class Filters extends Repository { return new Entities\Filter($metadata->WP_Post); }*/ + /** + * @param array $args + * @return Entities\Filter + * + */ public function delete($args){ + if(!empty($args[1]) && $args[1]['is_permanently'] === true){ + return new Entities\Filter(wp_delete_post($args[0], $args[1]['is_permanently'])); + } + return new Entities\Filter(wp_trash_post($args[0])); } public function update($object){ diff --git a/tests/test-api-filters.php b/tests/test-api-filters.php index 94c0f4b7a..a072c943f 100644 --- a/tests/test-api-filters.php +++ b/tests/test-api-filters.php @@ -51,7 +51,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase { 'collection', array( 'name' => 'Collection filtered', - 'description' => 'Is filtered' + 'description' => 'Is filtered', ), true ); @@ -60,7 +60,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase { 'metadata', array( 'name' => 'Metadata filtered', - 'description' => 'Is filtered' + 'description' => 'Is filtered', ) ); @@ -73,13 +73,13 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase { 'collection' => $collection, 'description' => 'descricao', 'metadata' => $metadata, - 'filter_type' => $filter_type + 'filter_type' => $filter_type, ), true ); $is_permanently = json_encode([ - 'is_permanently' => true + 'is_permanently' => false ]); $request = new \WP_REST_Request( @@ -91,18 +91,16 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase { $data = $response->get_data(); - $this->markTestIncomplete('Incomplete'); - $this->assertEquals('filtro', $data['name']); $filter_status = get_post($filter->get_id())->post_status; $this->assertEquals('trash', $filter_status); - ##### TRASH ##### + ##### DELETE ##### $is_permanently = json_encode([ - 'is_permanently' => false + 'is_permanently' => true ]); $request = new \WP_REST_Request(