changing return of insert term repository for consistency

This commit is contained in:
Leo Germani 2018-03-05 13:06:01 -03:00
parent 2f23fd9d35
commit 65e2819ecc
6 changed files with 18 additions and 16 deletions

View File

@ -105,9 +105,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
$this->prepare_item_for_database($to_prepare);
if($this->term->validate()){
$term_id = $this->terms_repository->insert($this->term);
$term_inserted = $this->terms_repository->fetch($term_id, $taxonomy);
$term_inserted = $this->terms_repository->insert($this->term);
return new WP_REST_Response($this->prepare_item_for_response($term_inserted, $request), 200);
} else {

View File

@ -53,6 +53,9 @@ class Term extends Entity {
* @return integer
*/
function get_id() {
return $this->get_term_id();
}
function get_term_id() {
return $this->get_mapped_property('term_id');
}

View File

@ -35,6 +35,7 @@ class Terms extends Repository {
'title' => __('Parent', 'tainacan'),
'type' => 'integer',
'description'=> __('The parent of the term', 'tainacan'),
'default' => 0,
'validation' => ''
],
'description' => [
@ -86,9 +87,9 @@ class Terms extends Repository {
}
// save post and get its ID
$term_inserted = wp_insert_term( $term->WP_Term->name, $term->WP_Term->taxonomy, [
'parent' => ( isset( $term->WP_Term->parent ) ) ? $term->WP_Term->parent : 0,
'description' => ( isset( $term->WP_Term->description ) ) ? $term->WP_Term->description : '',
$term_inserted = wp_insert_term( $term->get_name(), $term->get_taxonomy(), [
'parent' => $term->get_parent(),
'description' => $term->get_description(),
]);
// Now run through properties stored as postmeta
@ -100,8 +101,8 @@ class Terms extends Repository {
do_action('tainacan-insert', $term);
do_action('tainacan-insert-Term', $term);
return $term_inserted['term_id'];
//var_dump($term);
return new Entities\Term($term_inserted['term_id'], $term->get_taxonomy());
}
/**
@ -161,7 +162,7 @@ class Terms extends Repository {
}
public function update($object, $tax_name = null){
return new Entities\Term($this->insert($object), $tax_name);
return $this->insert($object);
}
public function delete($args){

View File

@ -283,8 +283,8 @@ class TAINACAN_REST_Queries extends TAINACAN_UnitApiTestCase {
]
];
wp_set_post_terms($itemA1->get_id(), $termA, $taxonomyA->get_db_identifier());
wp_set_post_terms($itemA2->get_id(), $termA, $taxonomyA->get_db_identifier());
wp_set_post_terms($itemA1->get_id(), $termA->get_term_id(), $taxonomyA->get_db_identifier());
wp_set_post_terms($itemA2->get_id(), $termA->get_term_id(), $taxonomyA->get_db_identifier());
$tax_query_request_collections = new \WP_REST_Request('GET', $this->namespace . '/collection/' . $collectionA->get_id() . '/items');
$tax_query_request_collections->set_query_params($tax_query);

View File

@ -61,7 +61,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
true
);
$request = new \WP_REST_Request('DELETE', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term);
$request = new \WP_REST_Request('DELETE', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term->get_term_id());
$response = $this->server->dispatch($request);
@ -69,7 +69,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
$this->assertTrue($data);
$term = get_term($term);
$term = get_term($term->get_term_id());
$this->assertNull($term);
}
@ -101,7 +101,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
]);
$request = new \WP_REST_Request(
'PATCH', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term
'PATCH', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term->get_term_id()
);
$request->set_body($new_attributes);
@ -169,7 +169,7 @@ class TAINACAN_REST_Terms extends TAINACAN_UnitApiTestCase {
#### FETCH A TERM ####
$request = new \WP_REST_Request(
'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term2
'GET', $this->namespace . '/taxonomy/' . $taxonomy->get_id() . '/terms/' . $term2->get_term_id()
);
$response = $this->server->dispatch($request);

View File

@ -64,7 +64,7 @@ class Taxonomies extends TAINACAN_UnitTestCase {
);
//retorna um objeto da classe Tainacan_Term
$test = $Tainacan_Terms->fetch($term, $taxonomy_test);
$test = $Tainacan_Terms->fetch($term->get_term_id(), $taxonomy_test);
$this->assertEquals( $test->get_name(), 'Rock' );
$this->assertEquals( $test->get_user(), 56 );
}