Completed
Push — develop ( d86f0d...0a9e6f )
by David
03:31
created

Wordlift_Uri_Service   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A delete_all() 0 9 1
1
<?php
2
/**
3
 * Define the {@link Wordlift_Uri_Service} responsible for managing entity URIs
4
 * (for posts, entities, authors, ...).
5
 */
6
7
/**
8
 */
9
class Wordlift_Uri_Service {
10
11
	/**
12
	 * A {@link Wordlift_Log_Service} instance.
13
	 *
14
	 * @since 3.6.0
15
	 * @access private
16
	 * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance.
17
	 */
18
	private $log;
19
20
	/**
21
	 * The global WordPress database connection.
22
	 *
23
	 * @since 3.6.0
24
	 * @access private
25
	 * @var \wpdb $wpdb The global WordPress database connection.
26
	 */
27
	private $wpdb;
28
29
	/**
30
	 * Create an instance of Wordlift_Uri_Service.
31
	 *
32
	 * @since 3.6.0
33
	 *
34
	 * @param wpdb $wpdb The global WordPress database connection.
35
	 */
36
	public function __construct( $wpdb ) {
37
38
		$this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Uri_Service' );
39
40
		$this->wpdb = $wpdb;
41
42
	}
43
44
	/**
45
	 * Delete all generated URIs from the database.
46
	 *
47
	 * @since 3.6.0
48
	 */
49
	public function delete_all() {
50
51
		// Delete URIs associated with posts/entities.
52
		$this->wpdb->delete( $this->wpdb->postmeta, array( 'meta_key' => 'entity_url' ) );
53
54
		// Delete URIs associated with authors.
55
		$this->wpdb->delete( $this->wpdb->usermeta, array( 'meta_key' => '_wl_uri' ) );
56
57
	}
58
59
}
60