@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | interface Sync_Background_Process_State { |
6 | 6 | |
7 | - public function enter(); |
|
8 | - |
|
9 | - public function leave(); |
|
10 | - |
|
11 | - /** |
|
12 | - * Task |
|
13 | - * |
|
14 | - * Override this method to perform any actions required on each |
|
15 | - * queue item. Return the modified item for further processing |
|
16 | - * in the next pass through. Or, return false to remove the |
|
17 | - * item from the queue. |
|
18 | - * |
|
19 | - * @param mixed $item Queue item to iterate over. |
|
20 | - * |
|
21 | - * @return mixed |
|
22 | - */ |
|
23 | - public function task( $item ); |
|
24 | - |
|
25 | - public function get_info(); |
|
26 | - |
|
27 | - /** |
|
28 | - * Try to resume an interrupted task. |
|
29 | - */ |
|
30 | - public function resume(); |
|
7 | + public function enter(); |
|
8 | + |
|
9 | + public function leave(); |
|
10 | + |
|
11 | + /** |
|
12 | + * Task |
|
13 | + * |
|
14 | + * Override this method to perform any actions required on each |
|
15 | + * queue item. Return the modified item for further processing |
|
16 | + * in the next pass through. Or, return false to remove the |
|
17 | + * item from the queue. |
|
18 | + * |
|
19 | + * @param mixed $item Queue item to iterate over. |
|
20 | + * |
|
21 | + * @return mixed |
|
22 | + */ |
|
23 | + public function task( $item ); |
|
24 | + |
|
25 | + public function get_info(); |
|
26 | + |
|
27 | + /** |
|
28 | + * Try to resume an interrupted task. |
|
29 | + */ |
|
30 | + public function resume(); |
|
31 | 31 | |
32 | 32 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * |
21 | 21 | * @return mixed |
22 | 22 | */ |
23 | - public function task( $item ); |
|
23 | + public function task($item); |
|
24 | 24 | |
25 | 25 | public function get_info(); |
26 | 26 |
@@ -6,82 +6,82 @@ |
||
6 | 6 | |
7 | 7 | class Sync_Background_Process_Wpjson_Endpoint { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Sync_Background_Process |
|
11 | - */ |
|
12 | - private $sync_background_process; |
|
13 | - |
|
14 | - /** |
|
15 | - * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
16 | - * |
|
17 | - * @param Sync_Background_Process $sync_background_process |
|
18 | - */ |
|
19 | - public function __construct( $sync_background_process ) { |
|
20 | - |
|
21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
22 | - |
|
23 | - $this->sync_background_process = $sync_background_process; |
|
24 | - |
|
25 | - } |
|
26 | - |
|
27 | - public function rest_api_init() { |
|
28 | - |
|
29 | - register_rest_route( |
|
30 | - 'wordlift/v1', |
|
31 | - '/dataset/background/sync', |
|
32 | - array( |
|
33 | - 'methods' => WP_REST_Server::CREATABLE, |
|
34 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | - 'permission_callback' => function () { |
|
36 | - $user = wp_get_current_user(); |
|
37 | - |
|
38 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
39 | - }, |
|
40 | - ) |
|
41 | - ); |
|
42 | - |
|
43 | - register_rest_route( |
|
44 | - 'wordlift/v1', |
|
45 | - '/dataset/background/sync', |
|
46 | - array( |
|
47 | - 'methods' => WP_REST_Server::READABLE, |
|
48 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | - 'permission_callback' => function () { |
|
50 | - $user = wp_get_current_user(); |
|
51 | - |
|
52 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
53 | - }, |
|
54 | - ) |
|
55 | - ); |
|
56 | - |
|
57 | - register_rest_route( |
|
58 | - 'wordlift/v1', |
|
59 | - '/dataset/background/sync', |
|
60 | - array( |
|
61 | - 'methods' => WP_REST_Server::DELETABLE, |
|
62 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | - 'permission_callback' => function () { |
|
64 | - $user = wp_get_current_user(); |
|
65 | - |
|
66 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
67 | - }, |
|
68 | - ) |
|
69 | - ); |
|
70 | - |
|
71 | - register_rest_route( |
|
72 | - 'wordlift/v1', |
|
73 | - '/dataset/background/sync', |
|
74 | - array( |
|
75 | - 'methods' => 'PUT', |
|
76 | - 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | - 'permission_callback' => function () { |
|
78 | - $user = wp_get_current_user(); |
|
79 | - |
|
80 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
81 | - }, |
|
82 | - ) |
|
83 | - ); |
|
84 | - |
|
85 | - } |
|
9 | + /** |
|
10 | + * @var Sync_Background_Process |
|
11 | + */ |
|
12 | + private $sync_background_process; |
|
13 | + |
|
14 | + /** |
|
15 | + * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
16 | + * |
|
17 | + * @param Sync_Background_Process $sync_background_process |
|
18 | + */ |
|
19 | + public function __construct( $sync_background_process ) { |
|
20 | + |
|
21 | + add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
22 | + |
|
23 | + $this->sync_background_process = $sync_background_process; |
|
24 | + |
|
25 | + } |
|
26 | + |
|
27 | + public function rest_api_init() { |
|
28 | + |
|
29 | + register_rest_route( |
|
30 | + 'wordlift/v1', |
|
31 | + '/dataset/background/sync', |
|
32 | + array( |
|
33 | + 'methods' => WP_REST_Server::CREATABLE, |
|
34 | + 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | + 'permission_callback' => function () { |
|
36 | + $user = wp_get_current_user(); |
|
37 | + |
|
38 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
39 | + }, |
|
40 | + ) |
|
41 | + ); |
|
42 | + |
|
43 | + register_rest_route( |
|
44 | + 'wordlift/v1', |
|
45 | + '/dataset/background/sync', |
|
46 | + array( |
|
47 | + 'methods' => WP_REST_Server::READABLE, |
|
48 | + 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | + 'permission_callback' => function () { |
|
50 | + $user = wp_get_current_user(); |
|
51 | + |
|
52 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
53 | + }, |
|
54 | + ) |
|
55 | + ); |
|
56 | + |
|
57 | + register_rest_route( |
|
58 | + 'wordlift/v1', |
|
59 | + '/dataset/background/sync', |
|
60 | + array( |
|
61 | + 'methods' => WP_REST_Server::DELETABLE, |
|
62 | + 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | + 'permission_callback' => function () { |
|
64 | + $user = wp_get_current_user(); |
|
65 | + |
|
66 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
67 | + }, |
|
68 | + ) |
|
69 | + ); |
|
70 | + |
|
71 | + register_rest_route( |
|
72 | + 'wordlift/v1', |
|
73 | + '/dataset/background/sync', |
|
74 | + array( |
|
75 | + 'methods' => 'PUT', |
|
76 | + 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | + 'permission_callback' => function () { |
|
78 | + $user = wp_get_current_user(); |
|
79 | + |
|
80 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
81 | + }, |
|
82 | + ) |
|
83 | + ); |
|
84 | + |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @param Sync_Background_Process $sync_background_process |
18 | 18 | */ |
19 | - public function __construct( $sync_background_process ) { |
|
19 | + public function __construct($sync_background_process) { |
|
20 | 20 | |
21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
21 | + add_action('rest_api_init', array($this, 'rest_api_init')); |
|
22 | 22 | |
23 | 23 | $this->sync_background_process = $sync_background_process; |
24 | 24 | |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | '/dataset/background/sync', |
32 | 32 | array( |
33 | 33 | 'methods' => WP_REST_Server::CREATABLE, |
34 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | - 'permission_callback' => function () { |
|
34 | + 'callback' => array($this->sync_background_process, 'start'), |
|
35 | + 'permission_callback' => function() { |
|
36 | 36 | $user = wp_get_current_user(); |
37 | 37 | |
38 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
38 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
39 | 39 | }, |
40 | 40 | ) |
41 | 41 | ); |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | '/dataset/background/sync', |
46 | 46 | array( |
47 | 47 | 'methods' => WP_REST_Server::READABLE, |
48 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | - 'permission_callback' => function () { |
|
48 | + 'callback' => array($this->sync_background_process, 'get_info'), |
|
49 | + 'permission_callback' => function() { |
|
50 | 50 | $user = wp_get_current_user(); |
51 | 51 | |
52 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
52 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
53 | 53 | }, |
54 | 54 | ) |
55 | 55 | ); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | '/dataset/background/sync', |
60 | 60 | array( |
61 | 61 | 'methods' => WP_REST_Server::DELETABLE, |
62 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | - 'permission_callback' => function () { |
|
62 | + 'callback' => array($this->sync_background_process, 'stop'), |
|
63 | + 'permission_callback' => function() { |
|
64 | 64 | $user = wp_get_current_user(); |
65 | 65 | |
66 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
66 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
67 | 67 | }, |
68 | 68 | ) |
69 | 69 | ); |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | '/dataset/background/sync', |
74 | 74 | array( |
75 | 75 | 'methods' => 'PUT', |
76 | - 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | - 'permission_callback' => function () { |
|
76 | + 'callback' => array($this->sync_background_process, 'resume'), |
|
77 | + 'permission_callback' => function() { |
|
78 | 78 | $user = wp_get_current_user(); |
79 | 79 | |
80 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
80 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
81 | 81 | }, |
82 | 82 | ) |
83 | 83 | ); |
@@ -7,42 +7,42 @@ discard block |
||
7 | 7 | |
8 | 8 | class Sync_Background_Process_Terms_Stage { |
9 | 9 | |
10 | - /** |
|
11 | - * @var Sync_Object_Adapter_Factory |
|
12 | - */ |
|
13 | - private $sync_object_adapter_factory; |
|
14 | - |
|
15 | - /** |
|
16 | - * Sync_Background_Process_Posts_Stage constructor. |
|
17 | - * |
|
18 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
19 | - */ |
|
20 | - public function __construct( $sync_object_adapter_factory ) { |
|
21 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | - } |
|
23 | - |
|
24 | - public function count() { |
|
25 | - |
|
26 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
27 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
28 | - |
|
29 | - global $wpdb; |
|
30 | - $sql = " |
|
10 | + /** |
|
11 | + * @var Sync_Object_Adapter_Factory |
|
12 | + */ |
|
13 | + private $sync_object_adapter_factory; |
|
14 | + |
|
15 | + /** |
|
16 | + * Sync_Background_Process_Posts_Stage constructor. |
|
17 | + * |
|
18 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
19 | + */ |
|
20 | + public function __construct( $sync_object_adapter_factory ) { |
|
21 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | + } |
|
23 | + |
|
24 | + public function count() { |
|
25 | + |
|
26 | + $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
27 | + $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
28 | + |
|
29 | + global $wpdb; |
|
30 | + $sql = " |
|
31 | 31 | SELECT COUNT( 1 ) |
32 | 32 | FROM $wpdb->term_taxonomy |
33 | 33 | WHERE taxonomy IN ('$in_taxonomies') |
34 | 34 | "; |
35 | 35 | |
36 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
37 | - } |
|
36 | + return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
37 | + } |
|
38 | 38 | |
39 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
39 | + public function get_sync_object_adapters( $offset, $limit ) { |
|
40 | 40 | |
41 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
42 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
41 | + $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
42 | + $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
43 | 43 | |
44 | - global $wpdb; |
|
45 | - $sql = " |
|
44 | + global $wpdb; |
|
45 | + $sql = " |
|
46 | 46 | SELECT term_id |
47 | 47 | FROM $wpdb->term_taxonomy |
48 | 48 | WHERE taxonomy IN ('$in_taxonomies') |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | LIMIT %d, %d |
51 | 51 | "; |
52 | 52 | |
53 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
53 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
54 | 54 | |
55 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids ); |
|
56 | - } |
|
55 | + return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids ); |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
19 | 19 | */ |
20 | - public function __construct( $sync_object_adapter_factory ) { |
|
20 | + public function __construct($sync_object_adapter_factory) { |
|
21 | 21 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
22 | 22 | } |
23 | 23 | |
24 | 24 | public function count() { |
25 | 25 | |
26 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
27 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
26 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
27 | + $in_taxonomies = implode("','", array_map('esc_sql', $taxonomies)); |
|
28 | 28 | |
29 | 29 | global $wpdb; |
30 | 30 | $sql = " |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | WHERE taxonomy IN ('$in_taxonomies') |
34 | 34 | "; |
35 | 35 | |
36 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | + return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
37 | 37 | } |
38 | 38 | |
39 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
39 | + public function get_sync_object_adapters($offset, $limit) { |
|
40 | 40 | |
41 | - $taxonomies = get_taxonomies( array( 'public' => true ) ); |
|
42 | - $in_taxonomies = implode( "','", array_map( 'esc_sql', $taxonomies ) ); |
|
41 | + $taxonomies = get_taxonomies(array('public' => true)); |
|
42 | + $in_taxonomies = implode("','", array_map('esc_sql', $taxonomies)); |
|
43 | 43 | |
44 | 44 | global $wpdb; |
45 | 45 | $sql = " |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | LIMIT %d, %d |
51 | 51 | "; |
52 | 52 | |
53 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
53 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
54 | 54 | |
55 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::TERM, $ids ); |
|
55 | + return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::TERM, $ids); |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | } |
@@ -8,49 +8,49 @@ discard block |
||
8 | 8 | |
9 | 9 | class Sync_Background_Process_Posts_Stage { |
10 | 10 | |
11 | - /** |
|
12 | - * @var Sync_Object_Adapter_Factory |
|
13 | - */ |
|
14 | - private $sync_object_adapter_factory; |
|
11 | + /** |
|
12 | + * @var Sync_Object_Adapter_Factory |
|
13 | + */ |
|
14 | + private $sync_object_adapter_factory; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Sync_Background_Process_Posts_Stage constructor. |
|
18 | - * |
|
19 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
20 | - */ |
|
21 | - public function __construct( $sync_object_adapter_factory ) { |
|
22 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
23 | - } |
|
16 | + /** |
|
17 | + * Sync_Background_Process_Posts_Stage constructor. |
|
18 | + * |
|
19 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
20 | + */ |
|
21 | + public function __construct( $sync_object_adapter_factory ) { |
|
22 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
23 | + } |
|
24 | 24 | |
25 | - public function count() { |
|
25 | + public function count() { |
|
26 | 26 | |
27 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
27 | + $post_types = get_post_types( array( 'public' => true ) ); |
|
28 | 28 | |
29 | - global $wpdb; |
|
30 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
31 | - $sql = " |
|
29 | + global $wpdb; |
|
30 | + $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
31 | + $sql = " |
|
32 | 32 | SELECT COUNT( 1 ) |
33 | 33 | FROM $wpdb->posts |
34 | 34 | WHERE post_type IN ('$in_post_type') |
35 | 35 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
36 | 36 | "; |
37 | 37 | |
38 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
39 | - } |
|
38 | + return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param int $offset |
|
43 | - * @param int $limit |
|
44 | - * |
|
45 | - * @return Sync_Object_Adapter[] |
|
46 | - */ |
|
47 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
41 | + /** |
|
42 | + * @param int $offset |
|
43 | + * @param int $limit |
|
44 | + * |
|
45 | + * @return Sync_Object_Adapter[] |
|
46 | + */ |
|
47 | + public function get_sync_object_adapters( $offset, $limit ) { |
|
48 | 48 | |
49 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
49 | + $post_types = get_post_types( array( 'public' => true ) ); |
|
50 | 50 | |
51 | - global $wpdb; |
|
52 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
53 | - $sql = " |
|
51 | + global $wpdb; |
|
52 | + $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
53 | + $sql = " |
|
54 | 54 | SELECT ID |
55 | 55 | FROM $wpdb->posts |
56 | 56 | WHERE post_type IN ('$in_post_type') |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | LIMIT %d, %d |
60 | 60 | "; |
61 | 61 | |
62 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
62 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
63 | 63 | |
64 | - return $this->sync_object_adapter_factory |
|
65 | - ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) ); |
|
66 | - } |
|
64 | + return $this->sync_object_adapter_factory |
|
65 | + ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) ); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
@@ -18,16 +18,16 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
20 | 20 | */ |
21 | - public function __construct( $sync_object_adapter_factory ) { |
|
21 | + public function __construct($sync_object_adapter_factory) { |
|
22 | 22 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
23 | 23 | } |
24 | 24 | |
25 | 25 | public function count() { |
26 | 26 | |
27 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
27 | + $post_types = get_post_types(array('public' => true)); |
|
28 | 28 | |
29 | 29 | global $wpdb; |
30 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
30 | + $in_post_type = implode("','", array_map('esc_sql', $post_types)); |
|
31 | 31 | $sql = " |
32 | 32 | SELECT COUNT( 1 ) |
33 | 33 | FROM $wpdb->posts |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
36 | 36 | "; |
37 | 37 | |
38 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
38 | + return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return Sync_Object_Adapter[] |
46 | 46 | */ |
47 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
47 | + public function get_sync_object_adapters($offset, $limit) { |
|
48 | 48 | |
49 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
49 | + $post_types = get_post_types(array('public' => true)); |
|
50 | 50 | |
51 | 51 | global $wpdb; |
52 | - $in_post_type = implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
52 | + $in_post_type = implode("','", array_map('esc_sql', $post_types)); |
|
53 | 53 | $sql = " |
54 | 54 | SELECT ID |
55 | 55 | FROM $wpdb->posts |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | LIMIT %d, %d |
60 | 60 | "; |
61 | 61 | |
62 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
62 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
63 | 63 | |
64 | 64 | return $this->sync_object_adapter_factory |
65 | - ->create_many( Object_Type_Enum::POST, array_map( 'intval', $ids ) ); |
|
65 | + ->create_many(Object_Type_Enum::POST, array_map('intval', $ids)); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | } |
@@ -7,39 +7,39 @@ discard block |
||
7 | 7 | |
8 | 8 | class Sync_Background_Process_Users_Stage { |
9 | 9 | |
10 | - /** |
|
11 | - * @var Sync_Object_Adapter_Factory |
|
12 | - */ |
|
13 | - private $sync_object_adapter_factory; |
|
10 | + /** |
|
11 | + * @var Sync_Object_Adapter_Factory |
|
12 | + */ |
|
13 | + private $sync_object_adapter_factory; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Sync_Background_Process_Posts_Stage constructor. |
|
17 | - * |
|
18 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
19 | - */ |
|
20 | - public function __construct( $sync_object_adapter_factory ) { |
|
21 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | - } |
|
15 | + /** |
|
16 | + * Sync_Background_Process_Posts_Stage constructor. |
|
17 | + * |
|
18 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
19 | + */ |
|
20 | + public function __construct( $sync_object_adapter_factory ) { |
|
21 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
22 | + } |
|
23 | 23 | |
24 | - public function count() { |
|
24 | + public function count() { |
|
25 | 25 | |
26 | - global $wpdb; |
|
27 | - $in_post_type = $this->get_post_types_string(); |
|
28 | - $sql = " |
|
26 | + global $wpdb; |
|
27 | + $in_post_type = $this->get_post_types_string(); |
|
28 | + $sql = " |
|
29 | 29 | SELECT COUNT( DISTINCT post_author ) |
30 | 30 | FROM $wpdb->posts |
31 | 31 | WHERE post_type IN ('$in_post_type') |
32 | 32 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
33 | 33 | "; |
34 | 34 | |
35 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | - } |
|
35 | + return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | + } |
|
37 | 37 | |
38 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
38 | + public function get_sync_object_adapters( $offset, $limit ) { |
|
39 | 39 | |
40 | - global $wpdb; |
|
41 | - $in_post_type = $this->get_post_types_string(); |
|
42 | - $sql = " |
|
40 | + global $wpdb; |
|
41 | + $in_post_type = $this->get_post_types_string(); |
|
42 | + $sql = " |
|
43 | 43 | SELECT DISTINCT post_author |
44 | 44 | FROM $wpdb->posts |
45 | 45 | WHERE post_type IN ('$in_post_type') |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | LIMIT %d, %d |
48 | 48 | "; |
49 | 49 | |
50 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
50 | + $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
51 | 51 | |
52 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
53 | - } |
|
52 | + return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - protected function get_post_types_string() { |
|
59 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + protected function get_post_types_string() { |
|
59 | + $post_types = get_post_types( array( 'public' => true ) ); |
|
60 | 60 | |
61 | - return implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
62 | - } |
|
61 | + return implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
19 | 19 | */ |
20 | - public function __construct( $sync_object_adapter_factory ) { |
|
20 | + public function __construct($sync_object_adapter_factory) { |
|
21 | 21 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
22 | 22 | } |
23 | 23 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | AND post_status IN ( 'publish', 'future', 'draft', 'pending', 'private' ) |
33 | 33 | "; |
34 | 34 | |
35 | - return $wpdb->get_var( $sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
35 | + return $wpdb->get_var($sql); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
36 | 36 | } |
37 | 37 | |
38 | - public function get_sync_object_adapters( $offset, $limit ) { |
|
38 | + public function get_sync_object_adapters($offset, $limit) { |
|
39 | 39 | |
40 | 40 | global $wpdb; |
41 | 41 | $in_post_type = $this->get_post_types_string(); |
@@ -47,18 +47,18 @@ discard block |
||
47 | 47 | LIMIT %d, %d |
48 | 48 | "; |
49 | 49 | |
50 | - $ids = $wpdb->get_col( $wpdb->prepare( $sql, $offset, $limit ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
50 | + $ids = $wpdb->get_col($wpdb->prepare($sql, $offset, $limit)); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared |
|
51 | 51 | |
52 | - return $this->sync_object_adapter_factory->create_many( Object_Type_Enum::USER, $ids ); |
|
52 | + return $this->sync_object_adapter_factory->create_many(Object_Type_Enum::USER, $ids); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @return string |
57 | 57 | */ |
58 | 58 | protected function get_post_types_string() { |
59 | - $post_types = get_post_types( array( 'public' => true ) ); |
|
59 | + $post_types = get_post_types(array('public' => true)); |
|
60 | 60 | |
61 | - return implode( "','", array_map( 'esc_sql', $post_types ) ); |
|
61 | + return implode("','", array_map('esc_sql', $post_types)); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | interface Sync_Background_Process_Stage { |
6 | 6 | |
7 | - public function count(); |
|
7 | + public function count(); |
|
8 | 8 | |
9 | - public function get_sync_object_adapters( $offset, $batch_size ); |
|
9 | + public function get_sync_object_adapters( $offset, $batch_size ); |
|
10 | 10 | |
11 | 11 | } |
@@ -6,6 +6,6 @@ |
||
6 | 6 | |
7 | 7 | public function count(); |
8 | 8 | |
9 | - public function get_sync_object_adapters( $offset, $batch_size ); |
|
9 | + public function get_sync_object_adapters($offset, $batch_size); |
|
10 | 10 | |
11 | 11 | } |
@@ -5,42 +5,42 @@ |
||
5 | 5 | use Wordlift\Object_Type_Enum; |
6 | 6 | |
7 | 7 | class Sync_Term_Adapter extends Abstract_Sync_Object_Adapter { |
8 | - /** |
|
9 | - * @var int |
|
10 | - */ |
|
11 | - private $term_id; |
|
12 | - |
|
13 | - /** |
|
14 | - * Sync_Term_Adapter constructor. |
|
15 | - * |
|
16 | - * @param int $term_id |
|
17 | - * |
|
18 | - * @throws \Exception when an error occurs. |
|
19 | - */ |
|
20 | - public function __construct( $term_id ) { |
|
21 | - parent::__construct( Object_Type_Enum::TERM, $term_id ); |
|
22 | - |
|
23 | - $this->term_id = $term_id; |
|
24 | - } |
|
25 | - |
|
26 | - public function is_published() { |
|
27 | - return $this->is_public(); |
|
28 | - } |
|
29 | - |
|
30 | - public function is_public() { |
|
31 | - $term = get_term( $this->term_id ); |
|
32 | - |
|
33 | - return get_taxonomy( $term->taxonomy )->public; |
|
34 | - } |
|
35 | - |
|
36 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
37 | - public function set_values( $arr ) { |
|
38 | - // @@todo |
|
39 | - } |
|
40 | - |
|
41 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
42 | - public function get_value( $key ) { |
|
43 | - // @@todo |
|
44 | - } |
|
8 | + /** |
|
9 | + * @var int |
|
10 | + */ |
|
11 | + private $term_id; |
|
12 | + |
|
13 | + /** |
|
14 | + * Sync_Term_Adapter constructor. |
|
15 | + * |
|
16 | + * @param int $term_id |
|
17 | + * |
|
18 | + * @throws \Exception when an error occurs. |
|
19 | + */ |
|
20 | + public function __construct( $term_id ) { |
|
21 | + parent::__construct( Object_Type_Enum::TERM, $term_id ); |
|
22 | + |
|
23 | + $this->term_id = $term_id; |
|
24 | + } |
|
25 | + |
|
26 | + public function is_published() { |
|
27 | + return $this->is_public(); |
|
28 | + } |
|
29 | + |
|
30 | + public function is_public() { |
|
31 | + $term = get_term( $this->term_id ); |
|
32 | + |
|
33 | + return get_taxonomy( $term->taxonomy )->public; |
|
34 | + } |
|
35 | + |
|
36 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
37 | + public function set_values( $arr ) { |
|
38 | + // @@todo |
|
39 | + } |
|
40 | + |
|
41 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
42 | + public function get_value( $key ) { |
|
43 | + // @@todo |
|
44 | + } |
|
45 | 45 | |
46 | 46 | } |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @throws \Exception when an error occurs. |
19 | 19 | */ |
20 | - public function __construct( $term_id ) { |
|
21 | - parent::__construct( Object_Type_Enum::TERM, $term_id ); |
|
20 | + public function __construct($term_id) { |
|
21 | + parent::__construct(Object_Type_Enum::TERM, $term_id); |
|
22 | 22 | |
23 | 23 | $this->term_id = $term_id; |
24 | 24 | } |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | } |
29 | 29 | |
30 | 30 | public function is_public() { |
31 | - $term = get_term( $this->term_id ); |
|
31 | + $term = get_term($this->term_id); |
|
32 | 32 | |
33 | - return get_taxonomy( $term->taxonomy )->public; |
|
33 | + return get_taxonomy($term->taxonomy)->public; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
37 | - public function set_values( $arr ) { |
|
37 | + public function set_values($arr) { |
|
38 | 38 | // @@todo |
39 | 39 | } |
40 | 40 | |
41 | 41 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
42 | - public function get_value( $key ) { |
|
42 | + public function get_value($key) { |
|
43 | 43 | // @@todo |
44 | 44 | } |
45 | 45 |
@@ -7,143 +7,143 @@ |
||
7 | 7 | use Wordlift\Object_Type_Enum; |
8 | 8 | |
9 | 9 | class Sync_Post_Hooks extends Abstract_Sync_Hooks { |
10 | - /** |
|
11 | - * @var \Wordlift_Log_Service |
|
12 | - */ |
|
13 | - private $log; |
|
14 | - |
|
15 | - /** |
|
16 | - * @var Sync_Service |
|
17 | - */ |
|
18 | - private $sync_service; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var Sync_Object_Adapter_Factory |
|
22 | - */ |
|
23 | - private $sync_object_factory; |
|
24 | - |
|
25 | - /** |
|
26 | - * Sync_Post_Hooks constructor. |
|
27 | - * |
|
28 | - * @param Sync_Service $sync_service |
|
29 | - * @param Sync_Object_Adapter_Factory $sync_object_factory |
|
30 | - */ |
|
31 | - public function __construct( $sync_service, $sync_object_factory ) { |
|
32 | - parent::__construct(); |
|
33 | - |
|
34 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
35 | - |
|
36 | - $this->sync_service = $sync_service; |
|
37 | - $this->sync_object_factory = $sync_object_factory; |
|
38 | - |
|
39 | - $this->register_hooks(); |
|
40 | - } |
|
41 | - |
|
42 | - private function register_hooks() { |
|
43 | - /** |
|
44 | - * Register hooks for post and meta. |
|
45 | - */ |
|
46 | - add_action( 'save_post', array( $this, 'save_post' ) ); |
|
47 | - add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
48 | - add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
49 | - add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
50 | - |
|
51 | - // running this on delete_post wouldnt work because at that time |
|
52 | - // entity_url would be deleted, so we cant delete this item from KG. |
|
53 | - add_action( 'before_delete_post', array( $this, 'delete_post' ) ); |
|
54 | - |
|
55 | - // Remove post when its trashed. |
|
56 | - add_action( 'trashed_post', array( $this, 'delete_post' ) ); |
|
57 | - // Save the post when its untrashed. |
|
58 | - add_action( 'untrashed_post', array( $this, 'save_post' ) ); |
|
59 | - // Get sticky posts changes. |
|
60 | - add_action( 'update_option_sticky_posts', array( $this, 'sticky_posts' ), 10, 2 ); |
|
61 | - |
|
62 | - } |
|
63 | - |
|
64 | - public function save_post( $post_id ) { |
|
65 | - |
|
66 | - if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) ) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - $this->sync( $post_id ); |
|
71 | - |
|
72 | - } |
|
73 | - |
|
74 | - public function sticky_posts( $old_value, $value ) { |
|
75 | - foreach ( $old_value as $post_id ) { |
|
76 | - $this->sync( $post_id ); |
|
77 | - } |
|
78 | - |
|
79 | - foreach ( $value as $post_id ) { |
|
80 | - $this->sync( $post_id ); |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
85 | - public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) { |
|
86 | - |
|
87 | - if ( in_array( |
|
88 | - $meta_key, |
|
89 | - apply_filters( |
|
90 | - 'wl_dataset__sync_post_hooks__ignored_meta_keys', |
|
91 | - apply_filters( |
|
92 | - 'wl_dataset__sync_hooks__ignored_meta_keys', |
|
93 | - array( |
|
94 | - '_pingme', |
|
95 | - '_encloseme', |
|
96 | - 'entity_url', |
|
97 | - ) |
|
98 | - ) |
|
99 | - ), |
|
100 | - true |
|
101 | - ) |
|
102 | - || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) |
|
103 | - ) { |
|
104 | - return; |
|
105 | - } |
|
106 | - |
|
107 | - $this->sync( $post_id ); |
|
108 | - |
|
109 | - } |
|
110 | - |
|
111 | - private function sync( $post_id ) { |
|
112 | - $this->enqueue( array( 'do_sync', $post_id ) ); |
|
113 | - } |
|
114 | - |
|
115 | - public function do_sync( $post_id ) { |
|
116 | - try { |
|
117 | - $post = get_post( $post_id ); |
|
118 | - if ( ! isset( $post ) ) { |
|
119 | - return; |
|
120 | - } |
|
121 | - $this->sync_service->sync_many( |
|
122 | - array( |
|
123 | - $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ), |
|
124 | - $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ), |
|
125 | - ) |
|
126 | - ); |
|
127 | - } catch ( \Exception $e ) { |
|
128 | - $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e ); |
|
129 | - } |
|
130 | - |
|
131 | - } |
|
132 | - |
|
133 | - public function delete_post( $post_id ) { |
|
134 | - $this->enqueue( array( 'do_delete', $post_id ) ); |
|
135 | - } |
|
136 | - |
|
137 | - public function do_delete( $post_id ) { |
|
138 | - try { |
|
139 | - $this->sync_service->delete_one( |
|
140 | - Object_Type_Enum::POST, |
|
141 | - $post_id, |
|
142 | - Wordpress_Content_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_post( $post_id ) ) |
|
143 | - ); |
|
144 | - } catch ( \Exception $e ) { |
|
145 | - $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e ); |
|
146 | - } |
|
147 | - } |
|
10 | + /** |
|
11 | + * @var \Wordlift_Log_Service |
|
12 | + */ |
|
13 | + private $log; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var Sync_Service |
|
17 | + */ |
|
18 | + private $sync_service; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var Sync_Object_Adapter_Factory |
|
22 | + */ |
|
23 | + private $sync_object_factory; |
|
24 | + |
|
25 | + /** |
|
26 | + * Sync_Post_Hooks constructor. |
|
27 | + * |
|
28 | + * @param Sync_Service $sync_service |
|
29 | + * @param Sync_Object_Adapter_Factory $sync_object_factory |
|
30 | + */ |
|
31 | + public function __construct( $sync_service, $sync_object_factory ) { |
|
32 | + parent::__construct(); |
|
33 | + |
|
34 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
35 | + |
|
36 | + $this->sync_service = $sync_service; |
|
37 | + $this->sync_object_factory = $sync_object_factory; |
|
38 | + |
|
39 | + $this->register_hooks(); |
|
40 | + } |
|
41 | + |
|
42 | + private function register_hooks() { |
|
43 | + /** |
|
44 | + * Register hooks for post and meta. |
|
45 | + */ |
|
46 | + add_action( 'save_post', array( $this, 'save_post' ) ); |
|
47 | + add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
48 | + add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
49 | + add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
50 | + |
|
51 | + // running this on delete_post wouldnt work because at that time |
|
52 | + // entity_url would be deleted, so we cant delete this item from KG. |
|
53 | + add_action( 'before_delete_post', array( $this, 'delete_post' ) ); |
|
54 | + |
|
55 | + // Remove post when its trashed. |
|
56 | + add_action( 'trashed_post', array( $this, 'delete_post' ) ); |
|
57 | + // Save the post when its untrashed. |
|
58 | + add_action( 'untrashed_post', array( $this, 'save_post' ) ); |
|
59 | + // Get sticky posts changes. |
|
60 | + add_action( 'update_option_sticky_posts', array( $this, 'sticky_posts' ), 10, 2 ); |
|
61 | + |
|
62 | + } |
|
63 | + |
|
64 | + public function save_post( $post_id ) { |
|
65 | + |
|
66 | + if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) ) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + $this->sync( $post_id ); |
|
71 | + |
|
72 | + } |
|
73 | + |
|
74 | + public function sticky_posts( $old_value, $value ) { |
|
75 | + foreach ( $old_value as $post_id ) { |
|
76 | + $this->sync( $post_id ); |
|
77 | + } |
|
78 | + |
|
79 | + foreach ( $value as $post_id ) { |
|
80 | + $this->sync( $post_id ); |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
85 | + public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) { |
|
86 | + |
|
87 | + if ( in_array( |
|
88 | + $meta_key, |
|
89 | + apply_filters( |
|
90 | + 'wl_dataset__sync_post_hooks__ignored_meta_keys', |
|
91 | + apply_filters( |
|
92 | + 'wl_dataset__sync_hooks__ignored_meta_keys', |
|
93 | + array( |
|
94 | + '_pingme', |
|
95 | + '_encloseme', |
|
96 | + 'entity_url', |
|
97 | + ) |
|
98 | + ) |
|
99 | + ), |
|
100 | + true |
|
101 | + ) |
|
102 | + || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) |
|
103 | + ) { |
|
104 | + return; |
|
105 | + } |
|
106 | + |
|
107 | + $this->sync( $post_id ); |
|
108 | + |
|
109 | + } |
|
110 | + |
|
111 | + private function sync( $post_id ) { |
|
112 | + $this->enqueue( array( 'do_sync', $post_id ) ); |
|
113 | + } |
|
114 | + |
|
115 | + public function do_sync( $post_id ) { |
|
116 | + try { |
|
117 | + $post = get_post( $post_id ); |
|
118 | + if ( ! isset( $post ) ) { |
|
119 | + return; |
|
120 | + } |
|
121 | + $this->sync_service->sync_many( |
|
122 | + array( |
|
123 | + $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ), |
|
124 | + $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ), |
|
125 | + ) |
|
126 | + ); |
|
127 | + } catch ( \Exception $e ) { |
|
128 | + $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e ); |
|
129 | + } |
|
130 | + |
|
131 | + } |
|
132 | + |
|
133 | + public function delete_post( $post_id ) { |
|
134 | + $this->enqueue( array( 'do_delete', $post_id ) ); |
|
135 | + } |
|
136 | + |
|
137 | + public function do_delete( $post_id ) { |
|
138 | + try { |
|
139 | + $this->sync_service->delete_one( |
|
140 | + Object_Type_Enum::POST, |
|
141 | + $post_id, |
|
142 | + Wordpress_Content_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_post( $post_id ) ) |
|
143 | + ); |
|
144 | + } catch ( \Exception $e ) { |
|
145 | + $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e ); |
|
146 | + } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | } |
@@ -28,10 +28,10 @@ discard block |
||
28 | 28 | * @param Sync_Service $sync_service |
29 | 29 | * @param Sync_Object_Adapter_Factory $sync_object_factory |
30 | 30 | */ |
31 | - public function __construct( $sync_service, $sync_object_factory ) { |
|
31 | + public function __construct($sync_service, $sync_object_factory) { |
|
32 | 32 | parent::__construct(); |
33 | 33 | |
34 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
34 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
35 | 35 | |
36 | 36 | $this->sync_service = $sync_service; |
37 | 37 | $this->sync_object_factory = $sync_object_factory; |
@@ -43,48 +43,48 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * Register hooks for post and meta. |
45 | 45 | */ |
46 | - add_action( 'save_post', array( $this, 'save_post' ) ); |
|
47 | - add_action( 'added_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
48 | - add_action( 'updated_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
49 | - add_action( 'deleted_post_meta', array( $this, 'changed_post_meta' ), 10, 4 ); |
|
46 | + add_action('save_post', array($this, 'save_post')); |
|
47 | + add_action('added_post_meta', array($this, 'changed_post_meta'), 10, 4); |
|
48 | + add_action('updated_post_meta', array($this, 'changed_post_meta'), 10, 4); |
|
49 | + add_action('deleted_post_meta', array($this, 'changed_post_meta'), 10, 4); |
|
50 | 50 | |
51 | 51 | // running this on delete_post wouldnt work because at that time |
52 | 52 | // entity_url would be deleted, so we cant delete this item from KG. |
53 | - add_action( 'before_delete_post', array( $this, 'delete_post' ) ); |
|
53 | + add_action('before_delete_post', array($this, 'delete_post')); |
|
54 | 54 | |
55 | 55 | // Remove post when its trashed. |
56 | - add_action( 'trashed_post', array( $this, 'delete_post' ) ); |
|
56 | + add_action('trashed_post', array($this, 'delete_post')); |
|
57 | 57 | // Save the post when its untrashed. |
58 | - add_action( 'untrashed_post', array( $this, 'save_post' ) ); |
|
58 | + add_action('untrashed_post', array($this, 'save_post')); |
|
59 | 59 | // Get sticky posts changes. |
60 | - add_action( 'update_option_sticky_posts', array( $this, 'sticky_posts' ), 10, 2 ); |
|
60 | + add_action('update_option_sticky_posts', array($this, 'sticky_posts'), 10, 2); |
|
61 | 61 | |
62 | 62 | } |
63 | 63 | |
64 | - public function save_post( $post_id ) { |
|
64 | + public function save_post($post_id) { |
|
65 | 65 | |
66 | - if ( ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) ) { |
|
66 | + if ( ! in_array(get_post_type($post_id), \Wordlift_Entity_Service::valid_entity_post_types(), true)) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $this->sync( $post_id ); |
|
70 | + $this->sync($post_id); |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | |
74 | - public function sticky_posts( $old_value, $value ) { |
|
75 | - foreach ( $old_value as $post_id ) { |
|
76 | - $this->sync( $post_id ); |
|
74 | + public function sticky_posts($old_value, $value) { |
|
75 | + foreach ($old_value as $post_id) { |
|
76 | + $this->sync($post_id); |
|
77 | 77 | } |
78 | 78 | |
79 | - foreach ( $value as $post_id ) { |
|
80 | - $this->sync( $post_id ); |
|
79 | + foreach ($value as $post_id) { |
|
80 | + $this->sync($post_id); |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | 84 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
85 | - public function changed_post_meta( $meta_id, $post_id, $meta_key, $_meta_value ) { |
|
85 | + public function changed_post_meta($meta_id, $post_id, $meta_key, $_meta_value) { |
|
86 | 86 | |
87 | - if ( in_array( |
|
87 | + if (in_array( |
|
88 | 88 | $meta_key, |
89 | 89 | apply_filters( |
90 | 90 | 'wl_dataset__sync_post_hooks__ignored_meta_keys', |
@@ -99,50 +99,50 @@ discard block |
||
99 | 99 | ), |
100 | 100 | true |
101 | 101 | ) |
102 | - || ! in_array( get_post_type( $post_id ), \Wordlift_Entity_Service::valid_entity_post_types(), true ) |
|
102 | + || ! in_array(get_post_type($post_id), \Wordlift_Entity_Service::valid_entity_post_types(), true) |
|
103 | 103 | ) { |
104 | 104 | return; |
105 | 105 | } |
106 | 106 | |
107 | - $this->sync( $post_id ); |
|
107 | + $this->sync($post_id); |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | |
111 | - private function sync( $post_id ) { |
|
112 | - $this->enqueue( array( 'do_sync', $post_id ) ); |
|
111 | + private function sync($post_id) { |
|
112 | + $this->enqueue(array('do_sync', $post_id)); |
|
113 | 113 | } |
114 | 114 | |
115 | - public function do_sync( $post_id ) { |
|
115 | + public function do_sync($post_id) { |
|
116 | 116 | try { |
117 | - $post = get_post( $post_id ); |
|
118 | - if ( ! isset( $post ) ) { |
|
117 | + $post = get_post($post_id); |
|
118 | + if ( ! isset($post)) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | $this->sync_service->sync_many( |
122 | 122 | array( |
123 | - $this->sync_object_factory->create( Object_Type_Enum::POST, $post_id ), |
|
124 | - $this->sync_object_factory->create( Object_Type_Enum::USER, $post->post_author ), |
|
123 | + $this->sync_object_factory->create(Object_Type_Enum::POST, $post_id), |
|
124 | + $this->sync_object_factory->create(Object_Type_Enum::USER, $post->post_author), |
|
125 | 125 | ) |
126 | 126 | ); |
127 | - } catch ( \Exception $e ) { |
|
128 | - $this->log->error( "An error occurred while trying to sync post $post_id: " . $e->getMessage(), $e ); |
|
127 | + } catch (\Exception $e) { |
|
128 | + $this->log->error("An error occurred while trying to sync post $post_id: ".$e->getMessage(), $e); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | } |
132 | 132 | |
133 | - public function delete_post( $post_id ) { |
|
134 | - $this->enqueue( array( 'do_delete', $post_id ) ); |
|
133 | + public function delete_post($post_id) { |
|
134 | + $this->enqueue(array('do_delete', $post_id)); |
|
135 | 135 | } |
136 | 136 | |
137 | - public function do_delete( $post_id ) { |
|
137 | + public function do_delete($post_id) { |
|
138 | 138 | try { |
139 | 139 | $this->sync_service->delete_one( |
140 | 140 | Object_Type_Enum::POST, |
141 | 141 | $post_id, |
142 | - Wordpress_Content_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_post( $post_id ) ) |
|
142 | + Wordpress_Content_Service::get_instance()->get_entity_id(Wordpress_Content_Id::create_post($post_id)) |
|
143 | 143 | ); |
144 | - } catch ( \Exception $e ) { |
|
145 | - $this->log->error( "An error occurred while trying to delete post $post_id: " . $e->getMessage(), $e ); |
|
144 | + } catch (\Exception $e) { |
|
145 | + $this->log->error("An error occurred while trying to delete post $post_id: ".$e->getMessage(), $e); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 |
@@ -4,19 +4,19 @@ |
||
4 | 4 | |
5 | 5 | interface Sync_Object_Adapter { |
6 | 6 | |
7 | - /** |
|
8 | - * @return int see {@link Object_Type_Enum} |
|
9 | - */ |
|
10 | - public function get_type(); |
|
7 | + /** |
|
8 | + * @return int see {@link Object_Type_Enum} |
|
9 | + */ |
|
10 | + public function get_type(); |
|
11 | 11 | |
12 | - public function get_object_id(); |
|
12 | + public function get_object_id(); |
|
13 | 13 | |
14 | - public function is_published(); |
|
14 | + public function is_published(); |
|
15 | 15 | |
16 | - public function is_public(); |
|
16 | + public function is_public(); |
|
17 | 17 | |
18 | - public function set_values( $arr ); |
|
18 | + public function set_values( $arr ); |
|
19 | 19 | |
20 | - public function get_value( $key ); |
|
20 | + public function get_value( $key ); |
|
21 | 21 | |
22 | 22 | } |
@@ -15,8 +15,8 @@ |
||
15 | 15 | |
16 | 16 | public function is_public(); |
17 | 17 | |
18 | - public function set_values( $arr ); |
|
18 | + public function set_values($arr); |
|
19 | 19 | |
20 | - public function get_value( $key ); |
|
20 | + public function get_value($key); |
|
21 | 21 | |
22 | 22 | } |