Completed
Pull Request — develop (#1328)
by Naveen
03:16
created

Legacy_Entity::clear_data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Vocabulary\Data\Entity;
4
5
use Wordlift\Vocabulary\Api\Entity_Rest_Endpoint;
6
7
/**
8
 * This class is created to provide compatibility for the legacy matches stored on the db,
9
 * for saving the data from match entity endpoint, this wont be used.
10
 * @since 3.30.0
11
 * @author Naveen Muthusamy <[email protected]>
12
 */
13
class Legacy_Entity extends Entity {
14
15
	/**
16
	 * This function is called when default entity doesnt find any data.
17
	 * @return array
18
	 */
19
	public function get_jsonld_data() {
20
		$tag = get_term( $this->term_id );
21
22
		return array(
23
			'@id'           => get_term_link( $tag->term_id ) . '#id',
24
			'@type'         => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::TYPE_META_KEY, true ),
25
			'name'          => $tag->name,
26
			'description'   => ! empty( $tag->description ) ?: get_term_meta( $tag->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY, true ),
27
			'sameAs'        => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY ),
28
			'alternateName' => get_term_meta( $tag->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY )
29
		);
30
	}
31
32
	/**
33
	 * This function is never used.
34
	 *
35
	 * @param \WP_REST_Request $request
36
	 *
37
	 * @return bool
38
	 */
39
	public function save_jsonld_data( $request ) {
40
		return false;
41
	}
42
43
	public function clear_data() {
44
		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::SAME_AS_META_KEY );
45
		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::ALTERNATIVE_LABEL_META_KEY );
46
		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::DESCRIPTION_META_KEY );
47
		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::TYPE_META_KEY );
48
		delete_term_meta( $this->term_id, Entity_Rest_Endpoint::EXTERNAL_ENTITY_META_KEY );
49
	}
50
}
51