@@ -8,29 +8,29 @@ |
||
8 | 8 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
9 | 9 | abstract class Abstract_Wordpress_Content_Legacy_Service extends Abstract_Wordpress_Content_Service { |
10 | 10 | |
11 | - private $expected_object_type; |
|
12 | - private $get_meta_fn; |
|
13 | - |
|
14 | - protected function __construct( $expected_object_type, $get_meta_fn ) { |
|
15 | - parent::__construct(); |
|
16 | - |
|
17 | - $this->expected_object_type = $expected_object_type; |
|
18 | - $this->get_meta_fn = $get_meta_fn; |
|
19 | - } |
|
20 | - |
|
21 | - public function get_entity_id( $content_id ) { |
|
22 | - Assertions::equals( |
|
23 | - $content_id->get_type(), |
|
24 | - $this->expected_object_type, |
|
25 | - sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) ) |
|
26 | - ); |
|
27 | - |
|
28 | - $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true ); |
|
29 | - return $result ? $result : null; |
|
30 | - } |
|
31 | - |
|
32 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
33 | - public function delete( $content_id ) { |
|
34 | - // do nothing, WP deletes the post meta for us. |
|
35 | - } |
|
11 | + private $expected_object_type; |
|
12 | + private $get_meta_fn; |
|
13 | + |
|
14 | + protected function __construct( $expected_object_type, $get_meta_fn ) { |
|
15 | + parent::__construct(); |
|
16 | + |
|
17 | + $this->expected_object_type = $expected_object_type; |
|
18 | + $this->get_meta_fn = $get_meta_fn; |
|
19 | + } |
|
20 | + |
|
21 | + public function get_entity_id( $content_id ) { |
|
22 | + Assertions::equals( |
|
23 | + $content_id->get_type(), |
|
24 | + $this->expected_object_type, |
|
25 | + sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) ) |
|
26 | + ); |
|
27 | + |
|
28 | + $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true ); |
|
29 | + return $result ? $result : null; |
|
30 | + } |
|
31 | + |
|
32 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
33 | + public function delete( $content_id ) { |
|
34 | + // do nothing, WP deletes the post meta for us. |
|
35 | + } |
|
36 | 36 | } |
@@ -11,26 +11,26 @@ |
||
11 | 11 | private $expected_object_type; |
12 | 12 | private $get_meta_fn; |
13 | 13 | |
14 | - protected function __construct( $expected_object_type, $get_meta_fn ) { |
|
14 | + protected function __construct($expected_object_type, $get_meta_fn) { |
|
15 | 15 | parent::__construct(); |
16 | 16 | |
17 | 17 | $this->expected_object_type = $expected_object_type; |
18 | 18 | $this->get_meta_fn = $get_meta_fn; |
19 | 19 | } |
20 | 20 | |
21 | - public function get_entity_id( $content_id ) { |
|
21 | + public function get_entity_id($content_id) { |
|
22 | 22 | Assertions::equals( |
23 | 23 | $content_id->get_type(), |
24 | 24 | $this->expected_object_type, |
25 | - sprintf( '`content_id` must be of type `%s`.', Object_Type_Enum::to_string( $this->expected_object_type ) ) |
|
25 | + sprintf('`content_id` must be of type `%s`.', Object_Type_Enum::to_string($this->expected_object_type)) |
|
26 | 26 | ); |
27 | 27 | |
28 | - $result = call_user_func( $this->get_meta_fn, $content_id->get_id(), 'entity_url', true ); |
|
28 | + $result = call_user_func($this->get_meta_fn, $content_id->get_id(), 'entity_url', true); |
|
29 | 29 | return $result ? $result : null; |
30 | 30 | } |
31 | 31 | |
32 | 32 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
33 | - public function delete( $content_id ) { |
|
33 | + public function delete($content_id) { |
|
34 | 34 | // do nothing, WP deletes the post meta for us. |
35 | 35 | } |
36 | 36 | } |
@@ -8,73 +8,73 @@ |
||
8 | 8 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
9 | 9 | class Wordpress_Dataset_Content_Service_Hooks { |
10 | 10 | |
11 | - public static function register() { |
|
12 | - add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) ); |
|
13 | - add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) ); |
|
14 | - add_action( 'created_term', array( get_called_class(), 'created_term' ) ); |
|
15 | - add_action( 'delete_term', array( get_called_class(), 'delete_term' ) ); |
|
16 | - add_action( 'user_register', array( get_called_class(), 'user_register' ) ); |
|
17 | - add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) ); |
|
18 | - } |
|
11 | + public static function register() { |
|
12 | + add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) ); |
|
13 | + add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) ); |
|
14 | + add_action( 'created_term', array( get_called_class(), 'created_term' ) ); |
|
15 | + add_action( 'delete_term', array( get_called_class(), 'delete_term' ) ); |
|
16 | + add_action( 'user_register', array( get_called_class(), 'user_register' ) ); |
|
17 | + add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) ); |
|
18 | + } |
|
19 | 19 | |
20 | - /** |
|
21 | - * @throws Exception in case of error. |
|
22 | - */ |
|
23 | - public static function insert_post( $post_id ) { |
|
24 | - if ( ! wp_is_post_revision( $post_id ) ) { |
|
25 | - self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) ); |
|
26 | - } |
|
27 | - } |
|
20 | + /** |
|
21 | + * @throws Exception in case of error. |
|
22 | + */ |
|
23 | + public static function insert_post( $post_id ) { |
|
24 | + if ( ! wp_is_post_revision( $post_id ) ) { |
|
25 | + self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) ); |
|
26 | + } |
|
27 | + } |
|
28 | 28 | |
29 | - public static function after_delete_post( $post_id ) { |
|
30 | - self::delete( Wordpress_Content_Id::create_post( $post_id ) ); |
|
31 | - } |
|
29 | + public static function after_delete_post( $post_id ) { |
|
30 | + self::delete( Wordpress_Content_Id::create_post( $post_id ) ); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * @throws Exception in case of error. |
|
35 | - */ |
|
36 | - public static function created_term( $term_id ) { |
|
37 | - self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) ); |
|
38 | - } |
|
33 | + /** |
|
34 | + * @throws Exception in case of error. |
|
35 | + */ |
|
36 | + public static function created_term( $term_id ) { |
|
37 | + self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) ); |
|
38 | + } |
|
39 | 39 | |
40 | - public static function delete_term( $term_id ) { |
|
41 | - self::delete( Wordpress_Content_Id::create_term( $term_id ) ); |
|
42 | - } |
|
40 | + public static function delete_term( $term_id ) { |
|
41 | + self::delete( Wordpress_Content_Id::create_term( $term_id ) ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @throws Exception in case of error. |
|
46 | - */ |
|
47 | - public static function user_register( $user_id ) { |
|
48 | - self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) ); |
|
49 | - } |
|
44 | + /** |
|
45 | + * @throws Exception in case of error. |
|
46 | + */ |
|
47 | + public static function user_register( $user_id ) { |
|
48 | + self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) ); |
|
49 | + } |
|
50 | 50 | |
51 | - public static function deleted_user( $user_id ) { |
|
52 | - self::delete( Wordpress_Content_Id::create_user( $user_id ) ); |
|
53 | - } |
|
51 | + public static function deleted_user( $user_id ) { |
|
52 | + self::delete( Wordpress_Content_Id::create_user( $user_id ) ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @param Wordpress_Content_Id $content_id |
|
57 | - * |
|
58 | - * @return void |
|
59 | - * @throws Exception in case of error. |
|
60 | - */ |
|
61 | - private static function set_entity_id( $content_id ) { |
|
62 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
63 | - try { |
|
64 | - $existing_id = $content_service->get_entity_id( $content_id ); |
|
65 | - if ( empty( $existing_id ) ) { |
|
66 | - $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
67 | - $content_service->set_entity_id( $content_id, $rel_uri ); |
|
68 | - } |
|
69 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
70 | - } catch ( Exception $e ) { |
|
71 | - // Don't report. |
|
72 | - } |
|
73 | - } |
|
55 | + /** |
|
56 | + * @param Wordpress_Content_Id $content_id |
|
57 | + * |
|
58 | + * @return void |
|
59 | + * @throws Exception in case of error. |
|
60 | + */ |
|
61 | + private static function set_entity_id( $content_id ) { |
|
62 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
63 | + try { |
|
64 | + $existing_id = $content_service->get_entity_id( $content_id ); |
|
65 | + if ( empty( $existing_id ) ) { |
|
66 | + $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
67 | + $content_service->set_entity_id( $content_id, $rel_uri ); |
|
68 | + } |
|
69 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
70 | + } catch ( Exception $e ) { |
|
71 | + // Don't report. |
|
72 | + } |
|
73 | + } |
|
74 | 74 | |
75 | - private static function delete( $content_id ) { |
|
76 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
77 | - $content_service->delete( $content_id ); |
|
78 | - } |
|
75 | + private static function delete( $content_id ) { |
|
76 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
77 | + $content_service->delete( $content_id ); |
|
78 | + } |
|
79 | 79 | |
80 | 80 | } |
@@ -9,47 +9,47 @@ discard block |
||
9 | 9 | class Wordpress_Dataset_Content_Service_Hooks { |
10 | 10 | |
11 | 11 | public static function register() { |
12 | - add_action( 'wp_insert_post', array( get_called_class(), 'insert_post' ) ); |
|
13 | - add_action( 'after_delete_post', array( get_called_class(), 'after_delete_post' ) ); |
|
14 | - add_action( 'created_term', array( get_called_class(), 'created_term' ) ); |
|
15 | - add_action( 'delete_term', array( get_called_class(), 'delete_term' ) ); |
|
16 | - add_action( 'user_register', array( get_called_class(), 'user_register' ) ); |
|
17 | - add_action( 'deleted_user', array( get_called_class(), 'deleted_user' ) ); |
|
12 | + add_action('wp_insert_post', array(get_called_class(), 'insert_post')); |
|
13 | + add_action('after_delete_post', array(get_called_class(), 'after_delete_post')); |
|
14 | + add_action('created_term', array(get_called_class(), 'created_term')); |
|
15 | + add_action('delete_term', array(get_called_class(), 'delete_term')); |
|
16 | + add_action('user_register', array(get_called_class(), 'user_register')); |
|
17 | + add_action('deleted_user', array(get_called_class(), 'deleted_user')); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @throws Exception in case of error. |
22 | 22 | */ |
23 | - public static function insert_post( $post_id ) { |
|
24 | - if ( ! wp_is_post_revision( $post_id ) ) { |
|
25 | - self::set_entity_id( Wordpress_Content_Id::create_post( $post_id ) ); |
|
23 | + public static function insert_post($post_id) { |
|
24 | + if ( ! wp_is_post_revision($post_id)) { |
|
25 | + self::set_entity_id(Wordpress_Content_Id::create_post($post_id)); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | - public static function after_delete_post( $post_id ) { |
|
30 | - self::delete( Wordpress_Content_Id::create_post( $post_id ) ); |
|
29 | + public static function after_delete_post($post_id) { |
|
30 | + self::delete(Wordpress_Content_Id::create_post($post_id)); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | 34 | * @throws Exception in case of error. |
35 | 35 | */ |
36 | - public static function created_term( $term_id ) { |
|
37 | - self::set_entity_id( Wordpress_Content_Id::create_term( $term_id ) ); |
|
36 | + public static function created_term($term_id) { |
|
37 | + self::set_entity_id(Wordpress_Content_Id::create_term($term_id)); |
|
38 | 38 | } |
39 | 39 | |
40 | - public static function delete_term( $term_id ) { |
|
41 | - self::delete( Wordpress_Content_Id::create_term( $term_id ) ); |
|
40 | + public static function delete_term($term_id) { |
|
41 | + self::delete(Wordpress_Content_Id::create_term($term_id)); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @throws Exception in case of error. |
46 | 46 | */ |
47 | - public static function user_register( $user_id ) { |
|
48 | - self::set_entity_id( Wordpress_Content_Id::create_user( $user_id ) ); |
|
47 | + public static function user_register($user_id) { |
|
48 | + self::set_entity_id(Wordpress_Content_Id::create_user($user_id)); |
|
49 | 49 | } |
50 | 50 | |
51 | - public static function deleted_user( $user_id ) { |
|
52 | - self::delete( Wordpress_Content_Id::create_user( $user_id ) ); |
|
51 | + public static function deleted_user($user_id) { |
|
52 | + self::delete(Wordpress_Content_Id::create_user($user_id)); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -58,23 +58,23 @@ discard block |
||
58 | 58 | * @return void |
59 | 59 | * @throws Exception in case of error. |
60 | 60 | */ |
61 | - private static function set_entity_id( $content_id ) { |
|
61 | + private static function set_entity_id($content_id) { |
|
62 | 62 | $content_service = Wordpress_Content_Service::get_instance(); |
63 | 63 | try { |
64 | - $existing_id = $content_service->get_entity_id( $content_id ); |
|
65 | - if ( empty( $existing_id ) ) { |
|
66 | - $rel_uri = Entity_Uri_Generator::create_uri( $content_id->get_type(), $content_id->get_id() ); |
|
67 | - $content_service->set_entity_id( $content_id, $rel_uri ); |
|
64 | + $existing_id = $content_service->get_entity_id($content_id); |
|
65 | + if (empty($existing_id)) { |
|
66 | + $rel_uri = Entity_Uri_Generator::create_uri($content_id->get_type(), $content_id->get_id()); |
|
67 | + $content_service->set_entity_id($content_id, $rel_uri); |
|
68 | 68 | } |
69 | 69 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
70 | - } catch ( Exception $e ) { |
|
70 | + } catch (Exception $e) { |
|
71 | 71 | // Don't report. |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - private static function delete( $content_id ) { |
|
75 | + private static function delete($content_id) { |
|
76 | 76 | $content_service = Wordpress_Content_Service::get_instance(); |
77 | - $content_service->delete( $content_id ); |
|
77 | + $content_service->delete($content_id); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | } |
@@ -9,111 +9,111 @@ |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_Dataset_Content_Service implements Content_Service { |
11 | 11 | |
12 | - /** |
|
13 | - * @var Content_Service[] |
|
14 | - */ |
|
15 | - private $delegates = array(); |
|
16 | - |
|
17 | - protected function __construct() { |
|
18 | - |
|
19 | - } |
|
20 | - |
|
21 | - private static $instance = null; |
|
22 | - |
|
23 | - /** |
|
24 | - * The singleton instance. |
|
25 | - * |
|
26 | - * @return Content_Service |
|
27 | - */ |
|
28 | - public static function get_instance() { |
|
29 | - if ( ! isset( self::$instance ) ) { |
|
30 | - self::$instance = new self(); |
|
31 | - |
|
32 | - self::$instance->register_delegate( Wordpress_Post_Content_Service::get_instance() ); |
|
33 | - self::$instance->register_delegate( Wordpress_Term_Content_Legacy_Service::get_instance() ); |
|
34 | - self::$instance->register_delegate( Wordpress_User_Content_Legacy_Service::get_instance() ); |
|
35 | - |
|
36 | - Wordpress_Dataset_Content_Service_Hooks::register(); |
|
37 | - } |
|
38 | - |
|
39 | - return self::$instance; |
|
40 | - } |
|
41 | - |
|
42 | - public function register_delegate( $delegate ) { |
|
43 | - Assertions::is_a( $delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.' ); |
|
44 | - |
|
45 | - $this->delegates[] = $delegate; |
|
46 | - } |
|
47 | - |
|
48 | - public function get_by_entity_id( $uri ) { |
|
49 | - foreach ( $this->delegates as $delegate ) { |
|
50 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
51 | - if ( isset( $content ) ) { |
|
52 | - return $content; |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - return null; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Get a |
|
61 | - * |
|
62 | - * @throws Exception in case of error. |
|
63 | - */ |
|
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - foreach ( $this->delegates as $delegate ) { |
|
66 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
67 | - if ( isset( $content ) ) { |
|
68 | - return $content; |
|
69 | - } |
|
70 | - } |
|
71 | - |
|
72 | - return null; |
|
73 | - } |
|
74 | - |
|
75 | - public function get_entity_id( $content_id ) { |
|
76 | - foreach ( $this->delegates as $delegate ) { |
|
77 | - if ( ! $delegate->supports( $content_id ) ) { |
|
78 | - continue; |
|
79 | - } |
|
80 | - $uri = $delegate->get_entity_id( $content_id ); |
|
81 | - if ( $uri ) { |
|
82 | - return $uri; |
|
83 | - } |
|
84 | - } |
|
85 | - |
|
86 | - return null; |
|
87 | - } |
|
88 | - |
|
89 | - public function set_entity_id( $content_id, $uri ) { |
|
90 | - foreach ( $this->delegates as $delegate ) { |
|
91 | - if ( $delegate->supports( $content_id ) ) { |
|
92 | - $delegate->set_entity_id( $content_id, $uri ); |
|
93 | - |
|
94 | - return; |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - throw new Exception( 'Not supported' ); |
|
99 | - } |
|
100 | - |
|
101 | - public function supports( $content_id ) { |
|
102 | - foreach ( $this->delegates as $delegate ) { |
|
103 | - if ( $delegate->supports( $content_id ) ) { |
|
104 | - return true; |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - return false; |
|
109 | - } |
|
110 | - |
|
111 | - public function delete( $content_id ) { |
|
112 | - foreach ( $this->delegates as $delegate ) { |
|
113 | - if ( $delegate->supports( $content_id ) ) { |
|
114 | - $delegate->delete( $content_id ); |
|
115 | - break; |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
12 | + /** |
|
13 | + * @var Content_Service[] |
|
14 | + */ |
|
15 | + private $delegates = array(); |
|
16 | + |
|
17 | + protected function __construct() { |
|
18 | + |
|
19 | + } |
|
20 | + |
|
21 | + private static $instance = null; |
|
22 | + |
|
23 | + /** |
|
24 | + * The singleton instance. |
|
25 | + * |
|
26 | + * @return Content_Service |
|
27 | + */ |
|
28 | + public static function get_instance() { |
|
29 | + if ( ! isset( self::$instance ) ) { |
|
30 | + self::$instance = new self(); |
|
31 | + |
|
32 | + self::$instance->register_delegate( Wordpress_Post_Content_Service::get_instance() ); |
|
33 | + self::$instance->register_delegate( Wordpress_Term_Content_Legacy_Service::get_instance() ); |
|
34 | + self::$instance->register_delegate( Wordpress_User_Content_Legacy_Service::get_instance() ); |
|
35 | + |
|
36 | + Wordpress_Dataset_Content_Service_Hooks::register(); |
|
37 | + } |
|
38 | + |
|
39 | + return self::$instance; |
|
40 | + } |
|
41 | + |
|
42 | + public function register_delegate( $delegate ) { |
|
43 | + Assertions::is_a( $delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.' ); |
|
44 | + |
|
45 | + $this->delegates[] = $delegate; |
|
46 | + } |
|
47 | + |
|
48 | + public function get_by_entity_id( $uri ) { |
|
49 | + foreach ( $this->delegates as $delegate ) { |
|
50 | + $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
51 | + if ( isset( $content ) ) { |
|
52 | + return $content; |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + return null; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Get a |
|
61 | + * |
|
62 | + * @throws Exception in case of error. |
|
63 | + */ |
|
64 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | + foreach ( $this->delegates as $delegate ) { |
|
66 | + $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
67 | + if ( isset( $content ) ) { |
|
68 | + return $content; |
|
69 | + } |
|
70 | + } |
|
71 | + |
|
72 | + return null; |
|
73 | + } |
|
74 | + |
|
75 | + public function get_entity_id( $content_id ) { |
|
76 | + foreach ( $this->delegates as $delegate ) { |
|
77 | + if ( ! $delegate->supports( $content_id ) ) { |
|
78 | + continue; |
|
79 | + } |
|
80 | + $uri = $delegate->get_entity_id( $content_id ); |
|
81 | + if ( $uri ) { |
|
82 | + return $uri; |
|
83 | + } |
|
84 | + } |
|
85 | + |
|
86 | + return null; |
|
87 | + } |
|
88 | + |
|
89 | + public function set_entity_id( $content_id, $uri ) { |
|
90 | + foreach ( $this->delegates as $delegate ) { |
|
91 | + if ( $delegate->supports( $content_id ) ) { |
|
92 | + $delegate->set_entity_id( $content_id, $uri ); |
|
93 | + |
|
94 | + return; |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + throw new Exception( 'Not supported' ); |
|
99 | + } |
|
100 | + |
|
101 | + public function supports( $content_id ) { |
|
102 | + foreach ( $this->delegates as $delegate ) { |
|
103 | + if ( $delegate->supports( $content_id ) ) { |
|
104 | + return true; |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + return false; |
|
109 | + } |
|
110 | + |
|
111 | + public function delete( $content_id ) { |
|
112 | + foreach ( $this->delegates as $delegate ) { |
|
113 | + if ( $delegate->supports( $content_id ) ) { |
|
114 | + $delegate->delete( $content_id ); |
|
115 | + break; |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | 119 | } |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @return Content_Service |
27 | 27 | */ |
28 | 28 | public static function get_instance() { |
29 | - if ( ! isset( self::$instance ) ) { |
|
29 | + if ( ! isset(self::$instance)) { |
|
30 | 30 | self::$instance = new self(); |
31 | 31 | |
32 | - self::$instance->register_delegate( Wordpress_Post_Content_Service::get_instance() ); |
|
33 | - self::$instance->register_delegate( Wordpress_Term_Content_Legacy_Service::get_instance() ); |
|
34 | - self::$instance->register_delegate( Wordpress_User_Content_Legacy_Service::get_instance() ); |
|
32 | + self::$instance->register_delegate(Wordpress_Post_Content_Service::get_instance()); |
|
33 | + self::$instance->register_delegate(Wordpress_Term_Content_Legacy_Service::get_instance()); |
|
34 | + self::$instance->register_delegate(Wordpress_User_Content_Legacy_Service::get_instance()); |
|
35 | 35 | |
36 | 36 | Wordpress_Dataset_Content_Service_Hooks::register(); |
37 | 37 | } |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | return self::$instance; |
40 | 40 | } |
41 | 41 | |
42 | - public function register_delegate( $delegate ) { |
|
43 | - Assertions::is_a( $delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.' ); |
|
42 | + public function register_delegate($delegate) { |
|
43 | + Assertions::is_a($delegate, 'Wordlift\Content\Content_Service', 'A `delegate` must implement the `Wordlift\Content\Content_Service` interface.'); |
|
44 | 44 | |
45 | 45 | $this->delegates[] = $delegate; |
46 | 46 | } |
47 | 47 | |
48 | - public function get_by_entity_id( $uri ) { |
|
49 | - foreach ( $this->delegates as $delegate ) { |
|
50 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
51 | - if ( isset( $content ) ) { |
|
48 | + public function get_by_entity_id($uri) { |
|
49 | + foreach ($this->delegates as $delegate) { |
|
50 | + $content = $delegate->get_by_entity_id_or_same_as($uri); |
|
51 | + if (isset($content)) { |
|
52 | 52 | return $content; |
53 | 53 | } |
54 | 54 | } |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @throws Exception in case of error. |
63 | 63 | */ |
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - foreach ( $this->delegates as $delegate ) { |
|
66 | - $content = $delegate->get_by_entity_id_or_same_as( $uri ); |
|
67 | - if ( isset( $content ) ) { |
|
64 | + public function get_by_entity_id_or_same_as($uri) { |
|
65 | + foreach ($this->delegates as $delegate) { |
|
66 | + $content = $delegate->get_by_entity_id_or_same_as($uri); |
|
67 | + if (isset($content)) { |
|
68 | 68 | return $content; |
69 | 69 | } |
70 | 70 | } |
@@ -72,13 +72,13 @@ discard block |
||
72 | 72 | return null; |
73 | 73 | } |
74 | 74 | |
75 | - public function get_entity_id( $content_id ) { |
|
76 | - foreach ( $this->delegates as $delegate ) { |
|
77 | - if ( ! $delegate->supports( $content_id ) ) { |
|
75 | + public function get_entity_id($content_id) { |
|
76 | + foreach ($this->delegates as $delegate) { |
|
77 | + if ( ! $delegate->supports($content_id)) { |
|
78 | 78 | continue; |
79 | 79 | } |
80 | - $uri = $delegate->get_entity_id( $content_id ); |
|
81 | - if ( $uri ) { |
|
80 | + $uri = $delegate->get_entity_id($content_id); |
|
81 | + if ($uri) { |
|
82 | 82 | return $uri; |
83 | 83 | } |
84 | 84 | } |
@@ -86,21 +86,21 @@ discard block |
||
86 | 86 | return null; |
87 | 87 | } |
88 | 88 | |
89 | - public function set_entity_id( $content_id, $uri ) { |
|
90 | - foreach ( $this->delegates as $delegate ) { |
|
91 | - if ( $delegate->supports( $content_id ) ) { |
|
92 | - $delegate->set_entity_id( $content_id, $uri ); |
|
89 | + public function set_entity_id($content_id, $uri) { |
|
90 | + foreach ($this->delegates as $delegate) { |
|
91 | + if ($delegate->supports($content_id)) { |
|
92 | + $delegate->set_entity_id($content_id, $uri); |
|
93 | 93 | |
94 | 94 | return; |
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - throw new Exception( 'Not supported' ); |
|
98 | + throw new Exception('Not supported'); |
|
99 | 99 | } |
100 | 100 | |
101 | - public function supports( $content_id ) { |
|
102 | - foreach ( $this->delegates as $delegate ) { |
|
103 | - if ( $delegate->supports( $content_id ) ) { |
|
101 | + public function supports($content_id) { |
|
102 | + foreach ($this->delegates as $delegate) { |
|
103 | + if ($delegate->supports($content_id)) { |
|
104 | 104 | return true; |
105 | 105 | } |
106 | 106 | } |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | return false; |
109 | 109 | } |
110 | 110 | |
111 | - public function delete( $content_id ) { |
|
112 | - foreach ( $this->delegates as $delegate ) { |
|
113 | - if ( $delegate->supports( $content_id ) ) { |
|
114 | - $delegate->delete( $content_id ); |
|
111 | + public function delete($content_id) { |
|
112 | + foreach ($this->delegates as $delegate) { |
|
113 | + if ($delegate->supports($content_id)) { |
|
114 | + $delegate->delete($content_id); |
|
115 | 115 | break; |
116 | 116 | } |
117 | 117 | } |
@@ -13,32 +13,32 @@ |
||
13 | 13 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
14 | 14 | class Wordpress_Post_Content_Service { |
15 | 15 | |
16 | - private static $instance = null; |
|
17 | - |
|
18 | - /** |
|
19 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
20 | - * the constructor. |
|
21 | - * |
|
22 | - * @return Content_Service |
|
23 | - */ |
|
24 | - public static function get_instance() { |
|
25 | - |
|
26 | - if ( ! isset( self::$instance ) ) { |
|
27 | - |
|
28 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
29 | - if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) { |
|
30 | - self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance(); |
|
31 | - } else { |
|
32 | - // Migrate `entity_url` from post-meta to wl_entities. |
|
33 | - $content_migration = new Content_Migration(); |
|
34 | - $content_migration->migrate(); |
|
35 | - |
|
36 | - // Create the post content service that uses wl_entities. |
|
37 | - self::$instance = Wordpress_Post_Content_Table_Service::get_instance(); |
|
38 | - } |
|
39 | - } |
|
40 | - |
|
41 | - return self::$instance; |
|
42 | - } |
|
16 | + private static $instance = null; |
|
17 | + |
|
18 | + /** |
|
19 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
20 | + * the constructor. |
|
21 | + * |
|
22 | + * @return Content_Service |
|
23 | + */ |
|
24 | + public static function get_instance() { |
|
25 | + |
|
26 | + if ( ! isset( self::$instance ) ) { |
|
27 | + |
|
28 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
29 | + if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) { |
|
30 | + self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance(); |
|
31 | + } else { |
|
32 | + // Migrate `entity_url` from post-meta to wl_entities. |
|
33 | + $content_migration = new Content_Migration(); |
|
34 | + $content_migration->migrate(); |
|
35 | + |
|
36 | + // Create the post content service that uses wl_entities. |
|
37 | + self::$instance = Wordpress_Post_Content_Table_Service::get_instance(); |
|
38 | + } |
|
39 | + } |
|
40 | + |
|
41 | + return self::$instance; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | } |
@@ -23,10 +23,10 @@ |
||
23 | 23 | */ |
24 | 24 | public static function get_instance() { |
25 | 25 | |
26 | - if ( ! isset( self::$instance ) ) { |
|
26 | + if ( ! isset(self::$instance)) { |
|
27 | 27 | |
28 | 28 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
29 | - if ( ! apply_filters( 'wl_feature__enable__rel-item-id', false ) ) { |
|
29 | + if ( ! apply_filters('wl_feature__enable__rel-item-id', false)) { |
|
30 | 30 | self::$instance = Wordpress_Post_Content_Legacy_Service::get_instance(); |
31 | 31 | } else { |
32 | 32 | // Migrate `entity_url` from post-meta to wl_entities. |
@@ -9,47 +9,47 @@ discard block |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_Term_Content_Legacy_Service extends Abstract_Wordpress_Content_Legacy_Service { |
11 | 11 | |
12 | - private static $instance = null; |
|
13 | - |
|
14 | - /** |
|
15 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | - * the constructor. |
|
17 | - * |
|
18 | - * @return Wordpress_Term_Content_Legacy_Service |
|
19 | - */ |
|
20 | - public static function get_instance() { |
|
21 | - |
|
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' ); |
|
24 | - } |
|
25 | - |
|
26 | - return self::$instance; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @param string $uri The entity id, relative or absolute. |
|
31 | - * |
|
32 | - * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null. |
|
33 | - * @throws Exception in case of error. when the uri is not within the dataset URI scope. |
|
34 | - */ |
|
35 | - public function get_by_entity_id( $uri ) { |
|
36 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
37 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
38 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
39 | - |
|
40 | - $abs_uri = $this->make_absolute( $uri ); |
|
41 | - |
|
42 | - Assertions::starts_with( |
|
43 | - $abs_uri, |
|
44 | - $this->get_dataset_uri(), |
|
45 | - sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() ) |
|
46 | - ); |
|
47 | - |
|
48 | - global $wpdb; |
|
49 | - |
|
50 | - $term_id = $wpdb->get_var( |
|
51 | - $wpdb->prepare( |
|
52 | - " |
|
12 | + private static $instance = null; |
|
13 | + |
|
14 | + /** |
|
15 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | + * the constructor. |
|
17 | + * |
|
18 | + * @return Wordpress_Term_Content_Legacy_Service |
|
19 | + */ |
|
20 | + public static function get_instance() { |
|
21 | + |
|
22 | + if ( ! isset( self::$instance ) ) { |
|
23 | + self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' ); |
|
24 | + } |
|
25 | + |
|
26 | + return self::$instance; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @param string $uri The entity id, relative or absolute. |
|
31 | + * |
|
32 | + * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null. |
|
33 | + * @throws Exception in case of error. when the uri is not within the dataset URI scope. |
|
34 | + */ |
|
35 | + public function get_by_entity_id( $uri ) { |
|
36 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
37 | + Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
38 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
39 | + |
|
40 | + $abs_uri = $this->make_absolute( $uri ); |
|
41 | + |
|
42 | + Assertions::starts_with( |
|
43 | + $abs_uri, |
|
44 | + $this->get_dataset_uri(), |
|
45 | + sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() ) |
|
46 | + ); |
|
47 | + |
|
48 | + global $wpdb; |
|
49 | + |
|
50 | + $term_id = $wpdb->get_var( |
|
51 | + $wpdb->prepare( |
|
52 | + " |
|
53 | 53 | SELECT t.term_id |
54 | 54 | FROM $wpdb->terms AS t |
55 | 55 | INNER JOIN $wpdb->termmeta AS tm |
@@ -57,70 +57,70 @@ discard block |
||
57 | 57 | WHERE tm.meta_key = 'entity_url' AND tm.meta_value = %s |
58 | 58 | LIMIT 1 |
59 | 59 | ", |
60 | - $abs_uri |
|
61 | - ) |
|
62 | - ); |
|
63 | - |
|
64 | - if ( isset( $term_id ) ) { |
|
65 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
66 | - } |
|
67 | - |
|
68 | - return null; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @throws Exception in case of error. when `$uri` is not a string. |
|
73 | - */ |
|
74 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
75 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
76 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
77 | - |
|
78 | - // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
79 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
80 | - return $this->get_by_entity_id( $uri ); |
|
81 | - } |
|
82 | - |
|
83 | - global $wpdb; |
|
84 | - |
|
85 | - $term_id = $wpdb->get_var( |
|
86 | - $wpdb->prepare( |
|
87 | - " |
|
60 | + $abs_uri |
|
61 | + ) |
|
62 | + ); |
|
63 | + |
|
64 | + if ( isset( $term_id ) ) { |
|
65 | + return new Wordpress_Content( get_term( $term_id ) ); |
|
66 | + } |
|
67 | + |
|
68 | + return null; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @throws Exception in case of error. when `$uri` is not a string. |
|
73 | + */ |
|
74 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
75 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
76 | + Assertions::not_empty( '`uri` cannot be empty.' ); |
|
77 | + |
|
78 | + // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
79 | + if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
80 | + return $this->get_by_entity_id( $uri ); |
|
81 | + } |
|
82 | + |
|
83 | + global $wpdb; |
|
84 | + |
|
85 | + $term_id = $wpdb->get_var( |
|
86 | + $wpdb->prepare( |
|
87 | + " |
|
88 | 88 | SELECT tm.term_id |
89 | 89 | FROM $wpdb->termmeta tm |
90 | 90 | WHERE tm.meta_key IN ( 'entity_url', 'entity_same_as' ) AND tm.meta_value = %s |
91 | 91 | LIMIT 1 |
92 | 92 | ", |
93 | - $uri |
|
94 | - ) |
|
95 | - ); |
|
96 | - |
|
97 | - if ( isset( $term_id ) ) { |
|
98 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
99 | - } |
|
100 | - |
|
101 | - return null; |
|
102 | - } |
|
103 | - |
|
104 | - public function set_entity_id( $content_id, $uri ) { |
|
105 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' ); |
|
106 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
107 | - |
|
108 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
109 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
110 | - } |
|
111 | - |
|
112 | - $abs_url = $this->make_absolute( $uri ); |
|
113 | - |
|
114 | - update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * @param Wordpress_Content_Id $content_id |
|
119 | - * |
|
120 | - * @return bool |
|
121 | - */ |
|
122 | - public function supports( $content_id ) { |
|
123 | - return $content_id->get_type() === Object_Type_Enum::TERM; |
|
124 | - } |
|
93 | + $uri |
|
94 | + ) |
|
95 | + ); |
|
96 | + |
|
97 | + if ( isset( $term_id ) ) { |
|
98 | + return new Wordpress_Content( get_term( $term_id ) ); |
|
99 | + } |
|
100 | + |
|
101 | + return null; |
|
102 | + } |
|
103 | + |
|
104 | + public function set_entity_id( $content_id, $uri ) { |
|
105 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' ); |
|
106 | + Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
107 | + |
|
108 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
109 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
110 | + } |
|
111 | + |
|
112 | + $abs_url = $this->make_absolute( $uri ); |
|
113 | + |
|
114 | + update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * @param Wordpress_Content_Id $content_id |
|
119 | + * |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | + public function supports( $content_id ) { |
|
123 | + return $content_id->get_type() === Object_Type_Enum::TERM; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function get_instance() { |
21 | 21 | |
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::TERM, 'get_term_meta' ); |
|
22 | + if ( ! isset(self::$instance)) { |
|
23 | + self::$instance = new self(Object_Type_Enum::TERM, 'get_term_meta'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return self::$instance; |
@@ -32,17 +32,17 @@ discard block |
||
32 | 32 | * @return Wordpress_Content|null The term encapsulate within a {@link Wordpress_Content} structure or null. |
33 | 33 | * @throws Exception in case of error. when the uri is not within the dataset URI scope. |
34 | 34 | */ |
35 | - public function get_by_entity_id( $uri ) { |
|
36 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
37 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
38 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
35 | + public function get_by_entity_id($uri) { |
|
36 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
37 | + Assertions::not_empty($uri, '`uri` cannot be empty.'); |
|
38 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
39 | 39 | |
40 | - $abs_uri = $this->make_absolute( $uri ); |
|
40 | + $abs_uri = $this->make_absolute($uri); |
|
41 | 41 | |
42 | 42 | Assertions::starts_with( |
43 | 43 | $abs_uri, |
44 | 44 | $this->get_dataset_uri(), |
45 | - sprintf( 'URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri() ) |
|
45 | + sprintf('URI `%s` must be within the dataset URI scope, `%s` provided.', $abs_uri, $this->get_dataset_uri()) |
|
46 | 46 | ); |
47 | 47 | |
48 | 48 | global $wpdb; |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | ) |
62 | 62 | ); |
63 | 63 | |
64 | - if ( isset( $term_id ) ) { |
|
65 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
64 | + if (isset($term_id)) { |
|
65 | + return new Wordpress_Content(get_term($term_id)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | return null; |
@@ -71,13 +71,13 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * @throws Exception in case of error. when `$uri` is not a string. |
73 | 73 | */ |
74 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
75 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
76 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
74 | + public function get_by_entity_id_or_same_as($uri) { |
|
75 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
76 | + Assertions::not_empty('`uri` cannot be empty.'); |
|
77 | 77 | |
78 | 78 | // If it's a relative URI, or it's an internal URI, look in entity ID. |
79 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
80 | - return $this->get_by_entity_id( $uri ); |
|
79 | + if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) { |
|
80 | + return $this->get_by_entity_id($uri); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | global $wpdb; |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | ) |
95 | 95 | ); |
96 | 96 | |
97 | - if ( isset( $term_id ) ) { |
|
98 | - return new Wordpress_Content( get_term( $term_id ) ); |
|
97 | + if (isset($term_id)) { |
|
98 | + return new Wordpress_Content(get_term($term_id)); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | return null; |
102 | 102 | } |
103 | 103 | |
104 | - public function set_entity_id( $content_id, $uri ) { |
|
105 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.' ); |
|
106 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
104 | + public function set_entity_id($content_id, $uri) { |
|
105 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::TERM, 'Content must be of `term` type.'); |
|
106 | + Assertions::not_empty($uri, "`uri` can't be empty"); |
|
107 | 107 | |
108 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
109 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
108 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
109 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
110 | 110 | } |
111 | 111 | |
112 | - $abs_url = $this->make_absolute( $uri ); |
|
112 | + $abs_url = $this->make_absolute($uri); |
|
113 | 113 | |
114 | - update_term_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
114 | + update_term_meta($content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return bool |
121 | 121 | */ |
122 | - public function supports( $content_id ) { |
|
122 | + public function supports($content_id) { |
|
123 | 123 | return $content_id->get_type() === Object_Type_Enum::TERM; |
124 | 124 | } |
125 | 125 |
@@ -9,37 +9,37 @@ discard block |
||
9 | 9 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
10 | 10 | class Wordpress_User_Content_Legacy_Service extends Abstract_Wordpress_Content_Legacy_Service { |
11 | 11 | |
12 | - private static $instance = null; |
|
12 | + private static $instance = null; |
|
13 | 13 | |
14 | - /** |
|
15 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | - * the constructor. |
|
17 | - * |
|
18 | - * @return Wordpress_User_Content_Legacy_Service |
|
19 | - */ |
|
20 | - public static function get_instance() { |
|
14 | + /** |
|
15 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
16 | + * the constructor. |
|
17 | + * |
|
18 | + * @return Wordpress_User_Content_Legacy_Service |
|
19 | + */ |
|
20 | + public static function get_instance() { |
|
21 | 21 | |
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::USER, 'get_user_meta' ); |
|
24 | - } |
|
22 | + if ( ! isset( self::$instance ) ) { |
|
23 | + self::$instance = new self( Object_Type_Enum::USER, 'get_user_meta' ); |
|
24 | + } |
|
25 | 25 | |
26 | - return self::$instance; |
|
27 | - } |
|
26 | + return self::$instance; |
|
27 | + } |
|
28 | 28 | |
29 | - public function get_by_entity_id( $uri ) { |
|
30 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
31 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
32 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
29 | + public function get_by_entity_id( $uri ) { |
|
30 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
31 | + Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
32 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
33 | 33 | |
34 | - $abs_uri = $this->make_absolute( $uri ); |
|
34 | + $abs_uri = $this->make_absolute( $uri ); |
|
35 | 35 | |
36 | - Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.' ); |
|
36 | + Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.' ); |
|
37 | 37 | |
38 | - global $wpdb; |
|
38 | + global $wpdb; |
|
39 | 39 | |
40 | - $user_id = $wpdb->get_var( |
|
41 | - $wpdb->prepare( |
|
42 | - " |
|
40 | + $user_id = $wpdb->get_var( |
|
41 | + $wpdb->prepare( |
|
42 | + " |
|
43 | 43 | SELECT u.ID |
44 | 44 | FROM $wpdb->users AS u |
45 | 45 | INNER JOIN $wpdb->usermeta AS um |
@@ -47,34 +47,34 @@ discard block |
||
47 | 47 | WHERE um.meta_key = 'entity_url' AND um.meta_value = %s |
48 | 48 | LIMIT 1 |
49 | 49 | ", |
50 | - $abs_uri |
|
51 | - ) |
|
52 | - ); |
|
53 | - |
|
54 | - if ( isset( $user_id ) ) { |
|
55 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
56 | - } |
|
57 | - |
|
58 | - return null; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @throws Exception in case of error. when `$uri` is not a string. |
|
63 | - */ |
|
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
66 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
67 | - |
|
68 | - // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
69 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
70 | - return $this->get_by_entity_id( $uri ); |
|
71 | - } |
|
72 | - |
|
73 | - global $wpdb; |
|
74 | - |
|
75 | - $user_id = $wpdb->get_var( |
|
76 | - $wpdb->prepare( |
|
77 | - " |
|
50 | + $abs_uri |
|
51 | + ) |
|
52 | + ); |
|
53 | + |
|
54 | + if ( isset( $user_id ) ) { |
|
55 | + return new Wordpress_Content( get_userdata( $user_id ) ); |
|
56 | + } |
|
57 | + |
|
58 | + return null; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @throws Exception in case of error. when `$uri` is not a string. |
|
63 | + */ |
|
64 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
66 | + Assertions::not_empty( '`uri` cannot be empty.' ); |
|
67 | + |
|
68 | + // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
69 | + if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
70 | + return $this->get_by_entity_id( $uri ); |
|
71 | + } |
|
72 | + |
|
73 | + global $wpdb; |
|
74 | + |
|
75 | + $user_id = $wpdb->get_var( |
|
76 | + $wpdb->prepare( |
|
77 | + " |
|
78 | 78 | SELECT u.ID |
79 | 79 | FROM $wpdb->users AS u |
80 | 80 | INNER JOIN $wpdb->usermeta AS um |
@@ -82,38 +82,38 @@ discard block |
||
82 | 82 | WHERE um.meta_key IN ( 'entity_url', 'entity_same_as' ) AND um.meta_value = %s |
83 | 83 | LIMIT 1 |
84 | 84 | ", |
85 | - $uri |
|
86 | - ) |
|
87 | - ); |
|
85 | + $uri |
|
86 | + ) |
|
87 | + ); |
|
88 | 88 | |
89 | - if ( isset( $user_id ) ) { |
|
90 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
91 | - } |
|
89 | + if ( isset( $user_id ) ) { |
|
90 | + return new Wordpress_Content( get_userdata( $user_id ) ); |
|
91 | + } |
|
92 | 92 | |
93 | - return null; |
|
94 | - } |
|
93 | + return null; |
|
94 | + } |
|
95 | 95 | |
96 | - public function set_entity_id( $content_id, $uri ) { |
|
97 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.' ); |
|
98 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
96 | + public function set_entity_id( $content_id, $uri ) { |
|
97 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.' ); |
|
98 | + Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
99 | 99 | |
100 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
100 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
101 | 101 | |
102 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
103 | - } |
|
102 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
103 | + } |
|
104 | 104 | |
105 | - $abs_url = $this->make_absolute( $uri ); |
|
105 | + $abs_url = $this->make_absolute( $uri ); |
|
106 | 106 | |
107 | - update_user_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
108 | - } |
|
107 | + update_user_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param Wordpress_Content_Id $content_id |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function supports( $content_id ) { |
|
116 | - return $content_id->get_type() === Object_Type_Enum::USER; |
|
117 | - } |
|
110 | + /** |
|
111 | + * @param Wordpress_Content_Id $content_id |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function supports( $content_id ) { |
|
116 | + return $content_id->get_type() === Object_Type_Enum::USER; |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } |
@@ -19,21 +19,21 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public static function get_instance() { |
21 | 21 | |
22 | - if ( ! isset( self::$instance ) ) { |
|
23 | - self::$instance = new self( Object_Type_Enum::USER, 'get_user_meta' ); |
|
22 | + if ( ! isset(self::$instance)) { |
|
23 | + self::$instance = new self(Object_Type_Enum::USER, 'get_user_meta'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | return self::$instance; |
27 | 27 | } |
28 | 28 | |
29 | - public function get_by_entity_id( $uri ) { |
|
30 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
31 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
32 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
29 | + public function get_by_entity_id($uri) { |
|
30 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
31 | + Assertions::not_empty($uri, '`uri` cannot be empty.'); |
|
32 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
33 | 33 | |
34 | - $abs_uri = $this->make_absolute( $uri ); |
|
34 | + $abs_uri = $this->make_absolute($uri); |
|
35 | 35 | |
36 | - Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.' ); |
|
36 | + Assertions::starts_with($abs_uri, $this->get_dataset_uri(), '`uri` must be within the dataset URI scope.'); |
|
37 | 37 | |
38 | 38 | global $wpdb; |
39 | 39 | |
@@ -51,8 +51,8 @@ discard block |
||
51 | 51 | ) |
52 | 52 | ); |
53 | 53 | |
54 | - if ( isset( $user_id ) ) { |
|
55 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
54 | + if (isset($user_id)) { |
|
55 | + return new Wordpress_Content(get_userdata($user_id)); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | return null; |
@@ -61,13 +61,13 @@ discard block |
||
61 | 61 | /** |
62 | 62 | * @throws Exception in case of error. when `$uri` is not a string. |
63 | 63 | */ |
64 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
65 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
66 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
64 | + public function get_by_entity_id_or_same_as($uri) { |
|
65 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
66 | + Assertions::not_empty('`uri` cannot be empty.'); |
|
67 | 67 | |
68 | 68 | // If it's a relative URI, or it's an internal URI, look in entity ID. |
69 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
70 | - return $this->get_by_entity_id( $uri ); |
|
69 | + if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) { |
|
70 | + return $this->get_by_entity_id($uri); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | global $wpdb; |
@@ -86,25 +86,25 @@ discard block |
||
86 | 86 | ) |
87 | 87 | ); |
88 | 88 | |
89 | - if ( isset( $user_id ) ) { |
|
90 | - return new Wordpress_Content( get_userdata( $user_id ) ); |
|
89 | + if (isset($user_id)) { |
|
90 | + return new Wordpress_Content(get_userdata($user_id)); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | return null; |
94 | 94 | } |
95 | 95 | |
96 | - public function set_entity_id( $content_id, $uri ) { |
|
97 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.' ); |
|
98 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
96 | + public function set_entity_id($content_id, $uri) { |
|
97 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::USER, '`content_id` must be of type user.'); |
|
98 | + Assertions::not_empty($uri, "`uri` can't be empty"); |
|
99 | 99 | |
100 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
100 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
101 | 101 | |
102 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
102 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
103 | 103 | } |
104 | 104 | |
105 | - $abs_url = $this->make_absolute( $uri ); |
|
105 | + $abs_url = $this->make_absolute($uri); |
|
106 | 106 | |
107 | - update_user_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
107 | + update_user_meta($content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * |
113 | 113 | * @return bool |
114 | 114 | */ |
115 | - public function supports( $content_id ) { |
|
115 | + public function supports($content_id) { |
|
116 | 116 | return $content_id->get_type() === Object_Type_Enum::USER; |
117 | 117 | } |
118 | 118 |
@@ -11,132 +11,132 @@ |
||
11 | 11 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
12 | 12 | class Wordpress_Post_Content_Legacy_Service extends Abstract_Wordpress_Content_Legacy_Service { |
13 | 13 | |
14 | - private static $instance = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
18 | - * the constructor. |
|
19 | - * |
|
20 | - * @return Wordpress_Post_Content_Legacy_Service |
|
21 | - */ |
|
22 | - public static function get_instance() { |
|
23 | - |
|
24 | - if ( ! isset( self::$instance ) ) { |
|
25 | - self::$instance = new self( Object_Type_Enum::POST, 'get_post_meta' ); |
|
26 | - } |
|
27 | - |
|
28 | - return self::$instance; |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @param string $uri An absolute or relative URI. When absolute it must be within the dataset URI scope. |
|
33 | - * |
|
34 | - * @return Wordpress_Content|null |
|
35 | - * @throws Exception in case of error. when the URI is not within the dataset URI. |
|
36 | - */ |
|
37 | - public function get_by_entity_id( $uri ) { |
|
38 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
39 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
40 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
41 | - |
|
42 | - $abs_uri = $this->make_absolute( $uri ); |
|
43 | - |
|
44 | - Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must start with dataset URI.' ); |
|
45 | - |
|
46 | - // Look in sameAs. |
|
47 | - $query_args = array( |
|
48 | - // See https://github.com/insideout10/wordlift-plugin/issues/654. |
|
49 | - 'ignore_sticky_posts' => 1, |
|
50 | - 'posts_per_page' => 1, |
|
51 | - 'post_status' => 'any', |
|
52 | - 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
53 | - 'meta_query' => array( |
|
54 | - array( |
|
55 | - 'key' => WL_ENTITY_URL_META_NAME, |
|
56 | - 'value' => $abs_uri, |
|
57 | - 'compare' => '=', |
|
58 | - ), |
|
59 | - ), |
|
60 | - ); |
|
61 | - |
|
62 | - $posts = get_posts( $query_args ); |
|
63 | - |
|
64 | - // Get the current post or allow 3rd parties to provide a replacement. |
|
65 | - $post = current( $posts ); |
|
66 | - $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
67 | - |
|
68 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
69 | - return new Wordpress_Content( current( $posts ) ); |
|
70 | - } |
|
71 | - |
|
72 | - return null; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @throws Exception in case of error. when `$uri` is not a string. |
|
77 | - */ |
|
78 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
79 | - // ATM we're too strict with the assertions here so we return null if the uri isn't provided. |
|
80 | - // Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
81 | - // Assertions::not_empty( '`uri` cannot be empty.' ); |
|
82 | - if ( ! is_string( $uri ) || empty( $uri ) ) { |
|
83 | - return null; |
|
84 | - } |
|
85 | - |
|
86 | - // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
87 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
88 | - return $this->get_by_entity_id( $uri ); |
|
89 | - } |
|
90 | - |
|
91 | - // Look in sameAs. |
|
92 | - $query_args = array( |
|
93 | - // See https://github.com/insideout10/wordlift-plugin/issues/654. |
|
94 | - 'ignore_sticky_posts' => 1, |
|
95 | - 'posts_per_page' => 1, |
|
96 | - 'post_status' => 'any', |
|
97 | - 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
98 | - 'meta_query' => array( |
|
99 | - array( |
|
100 | - 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
|
101 | - 'value' => $uri, |
|
102 | - 'compare' => '=', |
|
103 | - ), |
|
104 | - ), |
|
105 | - ); |
|
106 | - |
|
107 | - $posts = get_posts( $query_args ); |
|
108 | - |
|
109 | - // Get the current post or allow 3rd parties to provide a replacement. |
|
110 | - $post = current( $posts ); |
|
111 | - $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
112 | - |
|
113 | - if ( is_a( $post, '\WP_Post' ) ) { |
|
114 | - return new Wordpress_Content( current( $posts ) ); |
|
115 | - } |
|
116 | - |
|
117 | - return null; |
|
118 | - } |
|
119 | - |
|
120 | - public function set_entity_id( $content_id, $uri ) { |
|
121 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
122 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
123 | - |
|
124 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
125 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
126 | - } |
|
127 | - |
|
128 | - $abs_url = $this->make_absolute( $uri ); |
|
129 | - |
|
130 | - update_post_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @param Wordpress_Content_Id $content_id |
|
135 | - * |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function supports( $content_id ) { |
|
139 | - return $content_id->get_type() === Object_Type_Enum::POST; |
|
140 | - } |
|
14 | + private static $instance = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
18 | + * the constructor. |
|
19 | + * |
|
20 | + * @return Wordpress_Post_Content_Legacy_Service |
|
21 | + */ |
|
22 | + public static function get_instance() { |
|
23 | + |
|
24 | + if ( ! isset( self::$instance ) ) { |
|
25 | + self::$instance = new self( Object_Type_Enum::POST, 'get_post_meta' ); |
|
26 | + } |
|
27 | + |
|
28 | + return self::$instance; |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @param string $uri An absolute or relative URI. When absolute it must be within the dataset URI scope. |
|
33 | + * |
|
34 | + * @return Wordpress_Content|null |
|
35 | + * @throws Exception in case of error. when the URI is not within the dataset URI. |
|
36 | + */ |
|
37 | + public function get_by_entity_id( $uri ) { |
|
38 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
39 | + Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
40 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
41 | + |
|
42 | + $abs_uri = $this->make_absolute( $uri ); |
|
43 | + |
|
44 | + Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must start with dataset URI.' ); |
|
45 | + |
|
46 | + // Look in sameAs. |
|
47 | + $query_args = array( |
|
48 | + // See https://github.com/insideout10/wordlift-plugin/issues/654. |
|
49 | + 'ignore_sticky_posts' => 1, |
|
50 | + 'posts_per_page' => 1, |
|
51 | + 'post_status' => 'any', |
|
52 | + 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
53 | + 'meta_query' => array( |
|
54 | + array( |
|
55 | + 'key' => WL_ENTITY_URL_META_NAME, |
|
56 | + 'value' => $abs_uri, |
|
57 | + 'compare' => '=', |
|
58 | + ), |
|
59 | + ), |
|
60 | + ); |
|
61 | + |
|
62 | + $posts = get_posts( $query_args ); |
|
63 | + |
|
64 | + // Get the current post or allow 3rd parties to provide a replacement. |
|
65 | + $post = current( $posts ); |
|
66 | + $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
67 | + |
|
68 | + if ( is_a( $post, 'WP_Post' ) ) { |
|
69 | + return new Wordpress_Content( current( $posts ) ); |
|
70 | + } |
|
71 | + |
|
72 | + return null; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @throws Exception in case of error. when `$uri` is not a string. |
|
77 | + */ |
|
78 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
79 | + // ATM we're too strict with the assertions here so we return null if the uri isn't provided. |
|
80 | + // Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
81 | + // Assertions::not_empty( '`uri` cannot be empty.' ); |
|
82 | + if ( ! is_string( $uri ) || empty( $uri ) ) { |
|
83 | + return null; |
|
84 | + } |
|
85 | + |
|
86 | + // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
87 | + if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
88 | + return $this->get_by_entity_id( $uri ); |
|
89 | + } |
|
90 | + |
|
91 | + // Look in sameAs. |
|
92 | + $query_args = array( |
|
93 | + // See https://github.com/insideout10/wordlift-plugin/issues/654. |
|
94 | + 'ignore_sticky_posts' => 1, |
|
95 | + 'posts_per_page' => 1, |
|
96 | + 'post_status' => 'any', |
|
97 | + 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
98 | + 'meta_query' => array( |
|
99 | + array( |
|
100 | + 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
|
101 | + 'value' => $uri, |
|
102 | + 'compare' => '=', |
|
103 | + ), |
|
104 | + ), |
|
105 | + ); |
|
106 | + |
|
107 | + $posts = get_posts( $query_args ); |
|
108 | + |
|
109 | + // Get the current post or allow 3rd parties to provide a replacement. |
|
110 | + $post = current( $posts ); |
|
111 | + $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
112 | + |
|
113 | + if ( is_a( $post, '\WP_Post' ) ) { |
|
114 | + return new Wordpress_Content( current( $posts ) ); |
|
115 | + } |
|
116 | + |
|
117 | + return null; |
|
118 | + } |
|
119 | + |
|
120 | + public function set_entity_id( $content_id, $uri ) { |
|
121 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
122 | + Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
123 | + |
|
124 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
125 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
126 | + } |
|
127 | + |
|
128 | + $abs_url = $this->make_absolute( $uri ); |
|
129 | + |
|
130 | + update_post_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @param Wordpress_Content_Id $content_id |
|
135 | + * |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function supports( $content_id ) { |
|
139 | + return $content_id->get_type() === Object_Type_Enum::POST; |
|
140 | + } |
|
141 | 141 | |
142 | 142 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | */ |
22 | 22 | public static function get_instance() { |
23 | 23 | |
24 | - if ( ! isset( self::$instance ) ) { |
|
25 | - self::$instance = new self( Object_Type_Enum::POST, 'get_post_meta' ); |
|
24 | + if ( ! isset(self::$instance)) { |
|
25 | + self::$instance = new self(Object_Type_Enum::POST, 'get_post_meta'); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | return self::$instance; |
@@ -34,14 +34,14 @@ discard block |
||
34 | 34 | * @return Wordpress_Content|null |
35 | 35 | * @throws Exception in case of error. when the URI is not within the dataset URI. |
36 | 36 | */ |
37 | - public function get_by_entity_id( $uri ) { |
|
38 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
39 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
40 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
37 | + public function get_by_entity_id($uri) { |
|
38 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
39 | + Assertions::not_empty($uri, '`uri` cannot be empty.'); |
|
40 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
41 | 41 | |
42 | - $abs_uri = $this->make_absolute( $uri ); |
|
42 | + $abs_uri = $this->make_absolute($uri); |
|
43 | 43 | |
44 | - Assertions::starts_with( $abs_uri, $this->get_dataset_uri(), '`uri` must start with dataset URI.' ); |
|
44 | + Assertions::starts_with($abs_uri, $this->get_dataset_uri(), '`uri` must start with dataset URI.'); |
|
45 | 45 | |
46 | 46 | // Look in sameAs. |
47 | 47 | $query_args = array( |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | ), |
60 | 60 | ); |
61 | 61 | |
62 | - $posts = get_posts( $query_args ); |
|
62 | + $posts = get_posts($query_args); |
|
63 | 63 | |
64 | 64 | // Get the current post or allow 3rd parties to provide a replacement. |
65 | - $post = current( $posts ); |
|
66 | - $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
65 | + $post = current($posts); |
|
66 | + $post = $post ? $post : apply_filters('wl_content_service__post__not_found', null, $uri); |
|
67 | 67 | |
68 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
69 | - return new Wordpress_Content( current( $posts ) ); |
|
68 | + if (is_a($post, 'WP_Post')) { |
|
69 | + return new Wordpress_Content(current($posts)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return null; |
@@ -75,17 +75,17 @@ discard block |
||
75 | 75 | /** |
76 | 76 | * @throws Exception in case of error. when `$uri` is not a string. |
77 | 77 | */ |
78 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
78 | + public function get_by_entity_id_or_same_as($uri) { |
|
79 | 79 | // ATM we're too strict with the assertions here so we return null if the uri isn't provided. |
80 | 80 | // Assertions::is_string( $uri, '`uri` must be a string.' ); |
81 | 81 | // Assertions::not_empty( '`uri` cannot be empty.' ); |
82 | - if ( ! is_string( $uri ) || empty( $uri ) ) { |
|
82 | + if ( ! is_string($uri) || empty($uri)) { |
|
83 | 83 | return null; |
84 | 84 | } |
85 | 85 | |
86 | 86 | // If it's a relative URI, or it's an internal URI, look in entity ID. |
87 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
88 | - return $this->get_by_entity_id( $uri ); |
|
87 | + if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) { |
|
88 | + return $this->get_by_entity_id($uri); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // Look in sameAs. |
@@ -104,30 +104,30 @@ discard block |
||
104 | 104 | ), |
105 | 105 | ); |
106 | 106 | |
107 | - $posts = get_posts( $query_args ); |
|
107 | + $posts = get_posts($query_args); |
|
108 | 108 | |
109 | 109 | // Get the current post or allow 3rd parties to provide a replacement. |
110 | - $post = current( $posts ); |
|
111 | - $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
110 | + $post = current($posts); |
|
111 | + $post = $post ? $post : apply_filters('wl_content_service__post__not_found', null, $uri); |
|
112 | 112 | |
113 | - if ( is_a( $post, '\WP_Post' ) ) { |
|
114 | - return new Wordpress_Content( current( $posts ) ); |
|
113 | + if (is_a($post, '\WP_Post')) { |
|
114 | + return new Wordpress_Content(current($posts)); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return null; |
118 | 118 | } |
119 | 119 | |
120 | - public function set_entity_id( $content_id, $uri ) { |
|
121 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
122 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
120 | + public function set_entity_id($content_id, $uri) { |
|
121 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.'); |
|
122 | + Assertions::not_empty($uri, "`uri` can't be empty"); |
|
123 | 123 | |
124 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
125 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
124 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
125 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
126 | 126 | } |
127 | 127 | |
128 | - $abs_url = $this->make_absolute( $uri ); |
|
128 | + $abs_url = $this->make_absolute($uri); |
|
129 | 129 | |
130 | - update_post_meta( $content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url ); |
|
130 | + update_post_meta($content_id->get_id(), WL_ENTITY_URL_META_NAME, $abs_url); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | * |
136 | 136 | * @return bool |
137 | 137 | */ |
138 | - public function supports( $content_id ) { |
|
138 | + public function supports($content_id) { |
|
139 | 139 | return $content_id->get_type() === Object_Type_Enum::POST; |
140 | 140 | } |
141 | 141 |
@@ -16,184 +16,184 @@ |
||
16 | 16 | // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledClassName |
17 | 17 | class Wordpress_Post_Content_Table_Service extends Abstract_Wordpress_Content_Service { |
18 | 18 | |
19 | - private static $instance = null; |
|
20 | - |
|
21 | - /** |
|
22 | - * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
23 | - * the constructor. |
|
24 | - * |
|
25 | - * @return Wordpress_Post_Content_Table_Service |
|
26 | - */ |
|
27 | - public static function get_instance() { |
|
28 | - |
|
29 | - if ( ! isset( self::$instance ) ) { |
|
30 | - self::$instance = new self(); |
|
31 | - } |
|
32 | - |
|
33 | - return self::$instance; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * @param string $uri An absolute or relative URI. When absolute it must be within the dataset URI scope. |
|
38 | - * |
|
39 | - * @return Wordpress_Content|null |
|
40 | - * @throws Exception in case of error. when the URI is not within the dataset URI. |
|
41 | - */ |
|
42 | - public function get_by_entity_id( $uri ) { |
|
43 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
44 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
45 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
46 | - |
|
47 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
48 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
49 | - } |
|
50 | - |
|
51 | - $rel_uri = $this->make_relative( $uri ); |
|
52 | - |
|
53 | - global $wpdb; |
|
54 | - $row = $wpdb->get_row( |
|
55 | - $wpdb->prepare( |
|
56 | - " |
|
19 | + private static $instance = null; |
|
20 | + |
|
21 | + /** |
|
22 | + * The singleton instance. We use this only to provide this instance to those classes where we have no access to |
|
23 | + * the constructor. |
|
24 | + * |
|
25 | + * @return Wordpress_Post_Content_Table_Service |
|
26 | + */ |
|
27 | + public static function get_instance() { |
|
28 | + |
|
29 | + if ( ! isset( self::$instance ) ) { |
|
30 | + self::$instance = new self(); |
|
31 | + } |
|
32 | + |
|
33 | + return self::$instance; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * @param string $uri An absolute or relative URI. When absolute it must be within the dataset URI scope. |
|
38 | + * |
|
39 | + * @return Wordpress_Content|null |
|
40 | + * @throws Exception in case of error. when the URI is not within the dataset URI. |
|
41 | + */ |
|
42 | + public function get_by_entity_id( $uri ) { |
|
43 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
44 | + Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
45 | + Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
46 | + |
|
47 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
48 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
49 | + } |
|
50 | + |
|
51 | + $rel_uri = $this->make_relative( $uri ); |
|
52 | + |
|
53 | + global $wpdb; |
|
54 | + $row = $wpdb->get_row( |
|
55 | + $wpdb->prepare( |
|
56 | + " |
|
57 | 57 | SELECT content_type, content_id |
58 | 58 | FROM {$wpdb->prefix}wl_entities |
59 | 59 | WHERE rel_uri = %s |
60 | 60 | ", |
61 | - $rel_uri |
|
62 | - ) |
|
63 | - ); |
|
64 | - |
|
65 | - if ( ! isset( $row ) || Object_Type_Enum::POST !== (int) $row->content_type ) { |
|
66 | - return null; |
|
67 | - } |
|
68 | - |
|
69 | - return new Wordpress_Content( get_post( $row->content_id ) ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @throws Exception in case of error. when `$uri` is not a string. |
|
74 | - */ |
|
75 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
76 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
77 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
78 | - |
|
79 | - // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
80 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
81 | - return $this->get_by_entity_id( $uri ); |
|
82 | - } |
|
83 | - |
|
84 | - // Look in sameAs. |
|
85 | - $query_args = array( |
|
86 | - // See https://github.com/insideout10/wordlift-plugin/issues/654. |
|
87 | - 'ignore_sticky_posts' => 1, |
|
88 | - 'posts_per_page' => 1, |
|
89 | - 'post_status' => 'any', |
|
90 | - 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
91 | - 'meta_query' => array( |
|
92 | - array( |
|
93 | - 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
|
94 | - 'value' => $uri, |
|
95 | - 'compare' => '=', |
|
96 | - ), |
|
97 | - ), |
|
98 | - ); |
|
99 | - |
|
100 | - $posts = get_posts( $query_args ); |
|
101 | - |
|
102 | - // Get the current post or allow 3rd parties to provide a replacement. |
|
103 | - $post = current( $posts ); |
|
104 | - $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
105 | - |
|
106 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
107 | - return new Wordpress_Content( current( $posts ) ); |
|
108 | - } |
|
109 | - |
|
110 | - return null; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param Wordpress_Content_Id $content_id |
|
115 | - * |
|
116 | - * @return string|null The entity ID. |
|
117 | - * @throws Exception in case of error. |
|
118 | - */ |
|
119 | - public function get_entity_id( $content_id ) { |
|
120 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
121 | - |
|
122 | - global $wpdb; |
|
123 | - $rel_uri = $wpdb->get_var( |
|
124 | - $wpdb->prepare( |
|
125 | - " |
|
61 | + $rel_uri |
|
62 | + ) |
|
63 | + ); |
|
64 | + |
|
65 | + if ( ! isset( $row ) || Object_Type_Enum::POST !== (int) $row->content_type ) { |
|
66 | + return null; |
|
67 | + } |
|
68 | + |
|
69 | + return new Wordpress_Content( get_post( $row->content_id ) ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @throws Exception in case of error. when `$uri` is not a string. |
|
74 | + */ |
|
75 | + public function get_by_entity_id_or_same_as( $uri ) { |
|
76 | + Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
77 | + Assertions::not_empty( '`uri` cannot be empty.' ); |
|
78 | + |
|
79 | + // If it's a relative URI, or it's an internal URI, look in entity ID. |
|
80 | + if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
81 | + return $this->get_by_entity_id( $uri ); |
|
82 | + } |
|
83 | + |
|
84 | + // Look in sameAs. |
|
85 | + $query_args = array( |
|
86 | + // See https://github.com/insideout10/wordlift-plugin/issues/654. |
|
87 | + 'ignore_sticky_posts' => 1, |
|
88 | + 'posts_per_page' => 1, |
|
89 | + 'post_status' => 'any', |
|
90 | + 'post_type' => Wordlift_Entity_Service::valid_entity_post_types(), |
|
91 | + 'meta_query' => array( |
|
92 | + array( |
|
93 | + 'key' => Wordlift_Schema_Service::FIELD_SAME_AS, |
|
94 | + 'value' => $uri, |
|
95 | + 'compare' => '=', |
|
96 | + ), |
|
97 | + ), |
|
98 | + ); |
|
99 | + |
|
100 | + $posts = get_posts( $query_args ); |
|
101 | + |
|
102 | + // Get the current post or allow 3rd parties to provide a replacement. |
|
103 | + $post = current( $posts ); |
|
104 | + $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
105 | + |
|
106 | + if ( is_a( $post, 'WP_Post' ) ) { |
|
107 | + return new Wordpress_Content( current( $posts ) ); |
|
108 | + } |
|
109 | + |
|
110 | + return null; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param Wordpress_Content_Id $content_id |
|
115 | + * |
|
116 | + * @return string|null The entity ID. |
|
117 | + * @throws Exception in case of error. |
|
118 | + */ |
|
119 | + public function get_entity_id( $content_id ) { |
|
120 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
121 | + |
|
122 | + global $wpdb; |
|
123 | + $rel_uri = $wpdb->get_var( |
|
124 | + $wpdb->prepare( |
|
125 | + " |
|
126 | 126 | SELECT rel_uri |
127 | 127 | FROM {$wpdb->prefix}wl_entities |
128 | 128 | WHERE content_id = %d AND content_type = %d |
129 | 129 | ", |
130 | - $content_id->get_id(), |
|
131 | - $content_id->get_type() |
|
132 | - ) |
|
133 | - ); |
|
134 | - |
|
135 | - return $rel_uri ? $this->make_absolute( $rel_uri ) : null; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param Wordpress_Content_Id $content_id |
|
140 | - * @param string $uri |
|
141 | - * |
|
142 | - * @return void |
|
143 | - * @throws Exception in case of error. |
|
144 | - */ |
|
145 | - public function set_entity_id( $content_id, $uri ) { |
|
146 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
147 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
148 | - |
|
149 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
150 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
151 | - } |
|
152 | - |
|
153 | - $rel_url = $this->make_relative( $uri ); |
|
154 | - |
|
155 | - global $wpdb; |
|
156 | - $wpdb->query( |
|
157 | - $wpdb->prepare( |
|
158 | - " |
|
130 | + $content_id->get_id(), |
|
131 | + $content_id->get_type() |
|
132 | + ) |
|
133 | + ); |
|
134 | + |
|
135 | + return $rel_uri ? $this->make_absolute( $rel_uri ) : null; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param Wordpress_Content_Id $content_id |
|
140 | + * @param string $uri |
|
141 | + * |
|
142 | + * @return void |
|
143 | + * @throws Exception in case of error. |
|
144 | + */ |
|
145 | + public function set_entity_id( $content_id, $uri ) { |
|
146 | + Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
147 | + Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
148 | + |
|
149 | + if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
150 | + throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
151 | + } |
|
152 | + |
|
153 | + $rel_url = $this->make_relative( $uri ); |
|
154 | + |
|
155 | + global $wpdb; |
|
156 | + $wpdb->query( |
|
157 | + $wpdb->prepare( |
|
158 | + " |
|
159 | 159 | INSERT INTO {$wpdb->prefix}wl_entities( content_id, content_type, rel_uri, rel_uri_hash ) |
160 | 160 | VALUES( %d, %d, %s, SHA1( %s ) ) |
161 | 161 | ON DUPLICATE KEY UPDATE rel_uri = VALUES( rel_uri ), rel_uri_hash = SHA1( VALUES( rel_uri ) ); |
162 | 162 | ", |
163 | - $content_id->get_id(), |
|
164 | - $content_id->get_type(), |
|
165 | - $rel_url, |
|
166 | - $rel_url |
|
167 | - ) |
|
168 | - ); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param Wordpress_Content_Id $content_id |
|
173 | - * |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public function supports( $content_id ) { |
|
177 | - return $content_id->get_type() === Object_Type_Enum::POST; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param Wordpress_Content_Id $content_id |
|
182 | - * |
|
183 | - * @return void |
|
184 | - */ |
|
185 | - public function delete( $content_id ) { |
|
186 | - global $wpdb; |
|
187 | - |
|
188 | - $wpdb->query( |
|
189 | - $wpdb->prepare( |
|
190 | - " |
|
163 | + $content_id->get_id(), |
|
164 | + $content_id->get_type(), |
|
165 | + $rel_url, |
|
166 | + $rel_url |
|
167 | + ) |
|
168 | + ); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param Wordpress_Content_Id $content_id |
|
173 | + * |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public function supports( $content_id ) { |
|
177 | + return $content_id->get_type() === Object_Type_Enum::POST; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param Wordpress_Content_Id $content_id |
|
182 | + * |
|
183 | + * @return void |
|
184 | + */ |
|
185 | + public function delete( $content_id ) { |
|
186 | + global $wpdb; |
|
187 | + |
|
188 | + $wpdb->query( |
|
189 | + $wpdb->prepare( |
|
190 | + " |
|
191 | 191 | DELETE FROM {$wpdb->prefix}wl_entities |
192 | 192 | WHERE content_id = %d AND content_type = %d |
193 | 193 | ", |
194 | - $content_id->get_id(), |
|
195 | - $content_id->get_type() |
|
196 | - ) |
|
197 | - ); |
|
198 | - } |
|
194 | + $content_id->get_id(), |
|
195 | + $content_id->get_type() |
|
196 | + ) |
|
197 | + ); |
|
198 | + } |
|
199 | 199 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | */ |
27 | 27 | public static function get_instance() { |
28 | 28 | |
29 | - if ( ! isset( self::$instance ) ) { |
|
29 | + if ( ! isset(self::$instance)) { |
|
30 | 30 | self::$instance = new self(); |
31 | 31 | } |
32 | 32 | |
@@ -39,16 +39,16 @@ discard block |
||
39 | 39 | * @return Wordpress_Content|null |
40 | 40 | * @throws Exception in case of error. when the URI is not within the dataset URI. |
41 | 41 | */ |
42 | - public function get_by_entity_id( $uri ) { |
|
43 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
44 | - Assertions::not_empty( $uri, '`uri` cannot be empty.' ); |
|
45 | - Assertions::not_empty( $this->get_dataset_uri(), '`dataset_uri` cannot be empty.' ); |
|
42 | + public function get_by_entity_id($uri) { |
|
43 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
44 | + Assertions::not_empty($uri, '`uri` cannot be empty.'); |
|
45 | + Assertions::not_empty($this->get_dataset_uri(), '`dataset_uri` cannot be empty.'); |
|
46 | 46 | |
47 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
48 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
47 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
48 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
49 | 49 | } |
50 | 50 | |
51 | - $rel_uri = $this->make_relative( $uri ); |
|
51 | + $rel_uri = $this->make_relative($uri); |
|
52 | 52 | |
53 | 53 | global $wpdb; |
54 | 54 | $row = $wpdb->get_row( |
@@ -62,23 +62,23 @@ discard block |
||
62 | 62 | ) |
63 | 63 | ); |
64 | 64 | |
65 | - if ( ! isset( $row ) || Object_Type_Enum::POST !== (int) $row->content_type ) { |
|
65 | + if ( ! isset($row) || Object_Type_Enum::POST !== (int) $row->content_type) { |
|
66 | 66 | return null; |
67 | 67 | } |
68 | 68 | |
69 | - return new Wordpress_Content( get_post( $row->content_id ) ); |
|
69 | + return new Wordpress_Content(get_post($row->content_id)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
73 | 73 | * @throws Exception in case of error. when `$uri` is not a string. |
74 | 74 | */ |
75 | - public function get_by_entity_id_or_same_as( $uri ) { |
|
76 | - Assertions::is_string( $uri, '`uri` must be a string.' ); |
|
77 | - Assertions::not_empty( '`uri` cannot be empty.' ); |
|
75 | + public function get_by_entity_id_or_same_as($uri) { |
|
76 | + Assertions::is_string($uri, '`uri` must be a string.'); |
|
77 | + Assertions::not_empty('`uri` cannot be empty.'); |
|
78 | 78 | |
79 | 79 | // If it's a relative URI, or it's an internal URI, look in entity ID. |
80 | - if ( ! $this->is_absolute( $uri ) || $this->is_internal( $uri ) ) { |
|
81 | - return $this->get_by_entity_id( $uri ); |
|
80 | + if ( ! $this->is_absolute($uri) || $this->is_internal($uri)) { |
|
81 | + return $this->get_by_entity_id($uri); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // Look in sameAs. |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | ), |
98 | 98 | ); |
99 | 99 | |
100 | - $posts = get_posts( $query_args ); |
|
100 | + $posts = get_posts($query_args); |
|
101 | 101 | |
102 | 102 | // Get the current post or allow 3rd parties to provide a replacement. |
103 | - $post = current( $posts ); |
|
104 | - $post = $post ? $post : apply_filters( 'wl_content_service__post__not_found', null, $uri ); |
|
103 | + $post = current($posts); |
|
104 | + $post = $post ? $post : apply_filters('wl_content_service__post__not_found', null, $uri); |
|
105 | 105 | |
106 | - if ( is_a( $post, 'WP_Post' ) ) { |
|
107 | - return new Wordpress_Content( current( $posts ) ); |
|
106 | + if (is_a($post, 'WP_Post')) { |
|
107 | + return new Wordpress_Content(current($posts)); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | return null; |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | * @return string|null The entity ID. |
117 | 117 | * @throws Exception in case of error. |
118 | 118 | */ |
119 | - public function get_entity_id( $content_id ) { |
|
120 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
119 | + public function get_entity_id($content_id) { |
|
120 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.'); |
|
121 | 121 | |
122 | 122 | global $wpdb; |
123 | 123 | $rel_uri = $wpdb->get_var( |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | ) |
133 | 133 | ); |
134 | 134 | |
135 | - return $rel_uri ? $this->make_absolute( $rel_uri ) : null; |
|
135 | + return $rel_uri ? $this->make_absolute($rel_uri) : null; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -142,15 +142,15 @@ discard block |
||
142 | 142 | * @return void |
143 | 143 | * @throws Exception in case of error. |
144 | 144 | */ |
145 | - public function set_entity_id( $content_id, $uri ) { |
|
146 | - Assertions::equals( $content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.' ); |
|
147 | - Assertions::not_empty( $uri, "`uri` can't be empty" ); |
|
145 | + public function set_entity_id($content_id, $uri) { |
|
146 | + Assertions::equals($content_id->get_type(), Object_Type_Enum::POST, '`content_id` must be of type post.'); |
|
147 | + Assertions::not_empty($uri, "`uri` can't be empty"); |
|
148 | 148 | |
149 | - if ( $this->is_absolute( $uri ) && ! $this->is_internal( $uri ) ) { |
|
150 | - throw new Exception( '`uri` must be within the dataset URI scope.' ); |
|
149 | + if ($this->is_absolute($uri) && ! $this->is_internal($uri)) { |
|
150 | + throw new Exception('`uri` must be within the dataset URI scope.'); |
|
151 | 151 | } |
152 | 152 | |
153 | - $rel_url = $this->make_relative( $uri ); |
|
153 | + $rel_url = $this->make_relative($uri); |
|
154 | 154 | |
155 | 155 | global $wpdb; |
156 | 156 | $wpdb->query( |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return bool |
175 | 175 | */ |
176 | - public function supports( $content_id ) { |
|
176 | + public function supports($content_id) { |
|
177 | 177 | return $content_id->get_type() === Object_Type_Enum::POST; |
178 | 178 | } |
179 | 179 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return void |
184 | 184 | */ |
185 | - public function delete( $content_id ) { |
|
185 | + public function delete($content_id) { |
|
186 | 186 | global $wpdb; |
187 | 187 | |
188 | 188 | $wpdb->query( |
@@ -4,39 +4,39 @@ |
||
4 | 4 | |
5 | 5 | interface Content { |
6 | 6 | |
7 | - /** |
|
8 | - * Get the actual content. |
|
9 | - * |
|
10 | - * @return mixed Get the actual content. |
|
11 | - */ |
|
12 | - public function get_bag(); |
|
13 | - |
|
14 | - /** |
|
15 | - * Get the content id. |
|
16 | - * |
|
17 | - * @return mixed |
|
18 | - */ |
|
19 | - public function get_id(); |
|
20 | - |
|
21 | - /** |
|
22 | - * Get the content type. |
|
23 | - * |
|
24 | - * @return mixed |
|
25 | - */ |
|
26 | - public function get_object_type_enum(); |
|
27 | - |
|
28 | - /** |
|
29 | - * Get the permalink. |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function get_permalink(); |
|
34 | - |
|
35 | - /** |
|
36 | - * Get the edit link. |
|
37 | - * |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - public function get_edit_link(); |
|
7 | + /** |
|
8 | + * Get the actual content. |
|
9 | + * |
|
10 | + * @return mixed Get the actual content. |
|
11 | + */ |
|
12 | + public function get_bag(); |
|
13 | + |
|
14 | + /** |
|
15 | + * Get the content id. |
|
16 | + * |
|
17 | + * @return mixed |
|
18 | + */ |
|
19 | + public function get_id(); |
|
20 | + |
|
21 | + /** |
|
22 | + * Get the content type. |
|
23 | + * |
|
24 | + * @return mixed |
|
25 | + */ |
|
26 | + public function get_object_type_enum(); |
|
27 | + |
|
28 | + /** |
|
29 | + * Get the permalink. |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function get_permalink(); |
|
34 | + |
|
35 | + /** |
|
36 | + * Get the edit link. |
|
37 | + * |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + public function get_edit_link(); |
|
41 | 41 | |
42 | 42 | } |