@@ -4,31 +4,31 @@ |
||
4 | 4 | |
5 | 5 | class Sync_Background_Process_Stopped_State extends Abstract_Sync_Background_Process_State { |
6 | 6 | |
7 | - /** |
|
8 | - * @var Sync_Background_Process |
|
9 | - */ |
|
10 | - private $context; |
|
7 | + /** |
|
8 | + * @var Sync_Background_Process |
|
9 | + */ |
|
10 | + private $context; |
|
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( Sync_Background_Process::STATE_STOPPED ); |
|
12 | + public function __construct( $context ) { |
|
13 | + parent::__construct( Sync_Background_Process::STATE_STOPPED ); |
|
14 | 14 | |
15 | - $this->context = $context; |
|
16 | - } |
|
15 | + $this->context = $context; |
|
16 | + } |
|
17 | 17 | |
18 | - public function enter() { |
|
19 | - $this->context->set_state( Sync_Background_Process::STATE_STOPPED ); |
|
20 | - } |
|
18 | + public function enter() { |
|
19 | + $this->context->set_state( Sync_Background_Process::STATE_STOPPED ); |
|
20 | + } |
|
21 | 21 | |
22 | - public function leave() { |
|
23 | - $this->context->set_state( null ); |
|
24 | - } |
|
22 | + public function leave() { |
|
23 | + $this->context->set_state( null ); |
|
24 | + } |
|
25 | 25 | |
26 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
27 | - public function task( $item ) { |
|
26 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
27 | + public function task( $item ) { |
|
28 | 28 | |
29 | - $this->context->cancel_process(); |
|
29 | + $this->context->cancel_process(); |
|
30 | 30 | |
31 | - return false; |
|
32 | - } |
|
31 | + return false; |
|
32 | + } |
|
33 | 33 | |
34 | 34 | } |
@@ -9,22 +9,22 @@ |
||
9 | 9 | */ |
10 | 10 | private $context; |
11 | 11 | |
12 | - public function __construct( $context ) { |
|
13 | - parent::__construct( Sync_Background_Process::STATE_STOPPED ); |
|
12 | + public function __construct($context) { |
|
13 | + parent::__construct(Sync_Background_Process::STATE_STOPPED); |
|
14 | 14 | |
15 | 15 | $this->context = $context; |
16 | 16 | } |
17 | 17 | |
18 | 18 | public function enter() { |
19 | - $this->context->set_state( Sync_Background_Process::STATE_STOPPED ); |
|
19 | + $this->context->set_state(Sync_Background_Process::STATE_STOPPED); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | public function leave() { |
23 | - $this->context->set_state( null ); |
|
23 | + $this->context->set_state(null); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
27 | - public function task( $item ) { |
|
27 | + public function task($item) { |
|
28 | 28 | |
29 | 29 | $this->context->cancel_process(); |
30 | 30 |
@@ -11,138 +11,138 @@ |
||
11 | 11 | |
12 | 12 | class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State { |
13 | 13 | |
14 | - /** |
|
15 | - * @var Sync_Background_Process |
|
16 | - */ |
|
17 | - private $context; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var Sync_Service |
|
21 | - */ |
|
22 | - private $sync_service; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var Sync_Background_Process_Stage[] |
|
26 | - */ |
|
27 | - private $stages; |
|
28 | - |
|
29 | - private $batch_size = 5; |
|
30 | - /** |
|
31 | - * @var bool |
|
32 | - */ |
|
33 | - private $reset; |
|
34 | - |
|
35 | - /** |
|
36 | - * Sync_Background_Process_Started_State constructor. |
|
37 | - * |
|
38 | - * @param Sync_Background_Process $context |
|
39 | - * @param Sync_Service $sync_service |
|
40 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
41 | - * @param bool $reset Whether to reset the counters |
|
42 | - */ |
|
43 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
44 | - public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
45 | - parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
46 | - |
|
47 | - $this->context = $context; |
|
48 | - $this->sync_service = $sync_service; |
|
49 | - |
|
50 | - $this->stages = array( |
|
51 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
52 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
53 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
54 | - ); |
|
55 | - } |
|
56 | - |
|
57 | - public function enter() { |
|
58 | - // Delete the KG contents. |
|
59 | - $this->sync_service->delete_all(); |
|
60 | - |
|
61 | - // Clear caches. |
|
62 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
63 | - |
|
64 | - $counts = array_map( |
|
65 | - function ( $item ) { |
|
66 | - return $item->count(); |
|
67 | - }, |
|
68 | - $this->stages |
|
69 | - ); |
|
70 | - |
|
71 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
72 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
73 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
74 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
75 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
76 | - |
|
77 | - $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
78 | - |
|
79 | - $this->resume(); |
|
80 | - } |
|
81 | - |
|
82 | - public function resume() { |
|
83 | - $this->context->push_to_queue( true ); |
|
84 | - $this->context->save()->dispatch(); |
|
85 | - } |
|
86 | - |
|
87 | - public function leave() { |
|
88 | - $this->context->set_state( null ); |
|
89 | - } |
|
90 | - |
|
91 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
92 | - public function task( $args ) { |
|
93 | - |
|
94 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
95 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
96 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
97 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
98 | - |
|
99 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
100 | - try { |
|
101 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
102 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
103 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
104 | - } catch ( \Exception $e ) { |
|
105 | - // ignored. |
|
106 | - } |
|
107 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
108 | - |
|
109 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
110 | - |
|
111 | - // Increase the offset. |
|
112 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
113 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
114 | - |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - // Increase the stage. |
|
119 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
120 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
121 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
122 | - |
|
123 | - return true; |
|
124 | - } |
|
125 | - |
|
126 | - // Stop processing. |
|
127 | - $this->context->stop(); |
|
128 | - |
|
129 | - return false; |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Hook to provide a request to update the status on the server. |
|
134 | - * |
|
135 | - * @param array $args |
|
136 | - * |
|
137 | - * @return mixed |
|
138 | - */ |
|
139 | - public function api_service__request( $args ) { |
|
140 | - |
|
141 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
142 | - |
|
143 | - $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
144 | - |
|
145 | - return $args; |
|
146 | - } |
|
14 | + /** |
|
15 | + * @var Sync_Background_Process |
|
16 | + */ |
|
17 | + private $context; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var Sync_Service |
|
21 | + */ |
|
22 | + private $sync_service; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var Sync_Background_Process_Stage[] |
|
26 | + */ |
|
27 | + private $stages; |
|
28 | + |
|
29 | + private $batch_size = 5; |
|
30 | + /** |
|
31 | + * @var bool |
|
32 | + */ |
|
33 | + private $reset; |
|
34 | + |
|
35 | + /** |
|
36 | + * Sync_Background_Process_Started_State constructor. |
|
37 | + * |
|
38 | + * @param Sync_Background_Process $context |
|
39 | + * @param Sync_Service $sync_service |
|
40 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
41 | + * @param bool $reset Whether to reset the counters |
|
42 | + */ |
|
43 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
44 | + public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
45 | + parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
46 | + |
|
47 | + $this->context = $context; |
|
48 | + $this->sync_service = $sync_service; |
|
49 | + |
|
50 | + $this->stages = array( |
|
51 | + new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
52 | + new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
53 | + new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
54 | + ); |
|
55 | + } |
|
56 | + |
|
57 | + public function enter() { |
|
58 | + // Delete the KG contents. |
|
59 | + $this->sync_service->delete_all(); |
|
60 | + |
|
61 | + // Clear caches. |
|
62 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
63 | + |
|
64 | + $counts = array_map( |
|
65 | + function ( $item ) { |
|
66 | + return $item->count(); |
|
67 | + }, |
|
68 | + $this->stages |
|
69 | + ); |
|
70 | + |
|
71 | + update_option( '_wl_sync_background_process_count', $counts, true ); |
|
72 | + update_option( '_wl_sync_background_process_stage', 0, true ); |
|
73 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
74 | + update_option( '_wl_sync_background_process_started', time(), true ); |
|
75 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
76 | + |
|
77 | + $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
78 | + |
|
79 | + $this->resume(); |
|
80 | + } |
|
81 | + |
|
82 | + public function resume() { |
|
83 | + $this->context->push_to_queue( true ); |
|
84 | + $this->context->save()->dispatch(); |
|
85 | + } |
|
86 | + |
|
87 | + public function leave() { |
|
88 | + $this->context->set_state( null ); |
|
89 | + } |
|
90 | + |
|
91 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
92 | + public function task( $args ) { |
|
93 | + |
|
94 | + $offset = get_option( '_wl_sync_background_process_offset' ); |
|
95 | + $stage = get_option( '_wl_sync_background_process_stage' ); |
|
96 | + $counts = get_option( '_wl_sync_background_process_count' ); |
|
97 | + $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
98 | + |
|
99 | + add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
100 | + try { |
|
101 | + $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
102 | + $this->sync_service->sync_many( $object_adapters, true ); |
|
103 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
104 | + } catch ( \Exception $e ) { |
|
105 | + // ignored. |
|
106 | + } |
|
107 | + remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
108 | + |
|
109 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
110 | + |
|
111 | + // Increase the offset. |
|
112 | + if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
113 | + update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
114 | + |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + // Increase the stage. |
|
119 | + if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
120 | + update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
121 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
122 | + |
|
123 | + return true; |
|
124 | + } |
|
125 | + |
|
126 | + // Stop processing. |
|
127 | + $this->context->stop(); |
|
128 | + |
|
129 | + return false; |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Hook to provide a request to update the status on the server. |
|
134 | + * |
|
135 | + * @param array $args |
|
136 | + * |
|
137 | + * @return mixed |
|
138 | + */ |
|
139 | + public function api_service__request( $args ) { |
|
140 | + |
|
141 | + $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
142 | + |
|
143 | + $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
144 | + |
|
145 | + return $args; |
|
146 | + } |
|
147 | 147 | |
148 | 148 | } |
@@ -41,16 +41,16 @@ discard block |
||
41 | 41 | * @param bool $reset Whether to reset the counters |
42 | 42 | */ |
43 | 43 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
44 | - public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
45 | - parent::__construct( Sync_Background_Process::STATE_STARTED ); |
|
44 | + public function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) { |
|
45 | + parent::__construct(Sync_Background_Process::STATE_STARTED); |
|
46 | 46 | |
47 | 47 | $this->context = $context; |
48 | 48 | $this->sync_service = $sync_service; |
49 | 49 | |
50 | 50 | $this->stages = array( |
51 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
52 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
53 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
51 | + new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory), |
|
52 | + new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory), |
|
53 | + new Sync_Background_Process_Users_Stage($sync_object_adapter_factory), |
|
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
@@ -59,66 +59,66 @@ discard block |
||
59 | 59 | $this->sync_service->delete_all(); |
60 | 60 | |
61 | 61 | // Clear caches. |
62 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
62 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
63 | 63 | |
64 | 64 | $counts = array_map( |
65 | - function ( $item ) { |
|
65 | + function($item) { |
|
66 | 66 | return $item->count(); |
67 | 67 | }, |
68 | 68 | $this->stages |
69 | 69 | ); |
70 | 70 | |
71 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
72 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
73 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
74 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
75 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
71 | + update_option('_wl_sync_background_process_count', $counts, true); |
|
72 | + update_option('_wl_sync_background_process_stage', 0, true); |
|
73 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
74 | + update_option('_wl_sync_background_process_started', time(), true); |
|
75 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
76 | 76 | |
77 | - $this->context->set_state( Sync_Background_Process::STATE_STARTED ); |
|
77 | + $this->context->set_state(Sync_Background_Process::STATE_STARTED); |
|
78 | 78 | |
79 | 79 | $this->resume(); |
80 | 80 | } |
81 | 81 | |
82 | 82 | public function resume() { |
83 | - $this->context->push_to_queue( true ); |
|
83 | + $this->context->push_to_queue(true); |
|
84 | 84 | $this->context->save()->dispatch(); |
85 | 85 | } |
86 | 86 | |
87 | 87 | public function leave() { |
88 | - $this->context->set_state( null ); |
|
88 | + $this->context->set_state(null); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
92 | - public function task( $args ) { |
|
92 | + public function task($args) { |
|
93 | 93 | |
94 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
95 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
96 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
97 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
94 | + $offset = get_option('_wl_sync_background_process_offset'); |
|
95 | + $stage = get_option('_wl_sync_background_process_stage'); |
|
96 | + $counts = get_option('_wl_sync_background_process_count'); |
|
97 | + $batch_size = min($counts[$stage] - $offset, $this->batch_size); |
|
98 | 98 | |
99 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
99 | + add_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
100 | 100 | try { |
101 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
102 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
101 | + $object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size); |
|
102 | + $this->sync_service->sync_many($object_adapters, true); |
|
103 | 103 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
104 | - } catch ( \Exception $e ) { |
|
104 | + } catch (\Exception $e) { |
|
105 | 105 | // ignored. |
106 | 106 | } |
107 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
107 | + remove_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
108 | 108 | |
109 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
109 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
110 | 110 | |
111 | 111 | // Increase the offset. |
112 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
113 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
112 | + if (($offset + $batch_size) < $counts[$stage]) { |
|
113 | + update_option('_wl_sync_background_process_offset', $offset + $batch_size, true); |
|
114 | 114 | |
115 | 115 | return true; |
116 | 116 | } |
117 | 117 | |
118 | 118 | // Increase the stage. |
119 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
120 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
121 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
119 | + if (($stage + 1) < count($this->stages)) { |
|
120 | + update_option('_wl_sync_background_process_stage', $stage + 1, true); |
|
121 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
122 | 122 | |
123 | 123 | return true; |
124 | 124 | } |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @return mixed |
138 | 138 | */ |
139 | - public function api_service__request( $args ) { |
|
139 | + public function api_service__request($args) { |
|
140 | 140 | |
141 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
141 | + $state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info())); |
|
142 | 142 | |
143 | 143 | $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
144 | 144 |
@@ -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 |
@@ -7,128 +7,128 @@ |
||
7 | 7 | use Wordlift\Object_Type_Enum; |
8 | 8 | |
9 | 9 | class Sync_Term_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_Term_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( 'create_term', array( $this, 'do_sync' ) ); |
|
47 | - add_action( 'edit_term', array( $this, 'do_sync' ) ); |
|
48 | - add_action( 'added_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
49 | - add_action( 'updated_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
50 | - add_action( 'deleted_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
51 | - add_action( 'pre_delete_term', array( $this, 'delete_term' ) ); |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - public function saved_term( $term_id ) { |
|
56 | - |
|
57 | - // Sync all the terms without filtering. |
|
58 | - $this->sync( $term_id ); |
|
59 | - } |
|
60 | - |
|
61 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
62 | - public function changed_term_meta( $meta_id, $term_id, $meta_key, $_meta_value ) { |
|
63 | - |
|
64 | - if ( in_array( |
|
65 | - $meta_key, |
|
66 | - apply_filters( |
|
67 | - 'wl_dataset__sync_post_hooks__ignored_meta_keys', |
|
68 | - apply_filters( |
|
69 | - 'wl_dataset__sync_hooks__ignored_meta_keys', |
|
70 | - array( |
|
71 | - '_pingme', |
|
72 | - '_encloseme', |
|
73 | - 'entity_url', |
|
74 | - ) |
|
75 | - ) |
|
76 | - ), |
|
77 | - true |
|
78 | - ) |
|
79 | - ) { |
|
80 | - return; |
|
81 | - } |
|
82 | - |
|
83 | - $this->sync( $term_id ); |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - private function sync( $term_id ) { |
|
88 | - |
|
89 | - $this->enqueue( array( 'do_sync', $term_id ) ); |
|
90 | - } |
|
91 | - |
|
92 | - public function do_sync( $term_id ) { |
|
93 | - |
|
94 | - try { |
|
95 | - $term = get_term( $term_id ); |
|
96 | - if ( ! isset( $term ) ) { |
|
97 | - return; |
|
98 | - } |
|
99 | - $this->sync_service->sync_many( |
|
100 | - array( |
|
101 | - $this->sync_object_factory->create( Object_Type_Enum::TERM, $term_id ), |
|
102 | - ) |
|
103 | - ); |
|
104 | - } catch ( \Exception $e ) { |
|
105 | - $this->log->error( "An error occurred while trying to sync post $term_id: " . $e->getMessage(), $e ); |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @param $term \WP_Term |
|
111 | - * |
|
112 | - * @throws \Exception when an error occurs. |
|
113 | - */ |
|
114 | - public function delete_term( $term_id ) { |
|
115 | - $args = array( |
|
116 | - $term_id, |
|
117 | - Wordpress_Term_Content_Legacy_Service::get_instance() |
|
118 | - ->get_entity_id( Wordpress_Content_Id::create_term( $term_id ) ), |
|
119 | - ); |
|
120 | - // We can't postpone the execution for a `delete` because we would miss the actual data. |
|
121 | - $this->do_delete( $args ); |
|
122 | - } |
|
123 | - |
|
124 | - public function do_delete( $args ) { |
|
125 | - $term_id = $args[0]; |
|
126 | - $term_entity_uri = $args[1]; |
|
127 | - |
|
128 | - try { |
|
129 | - $this->sync_service->delete_one( Object_Type_Enum::TERM, $term_id, $term_entity_uri ); |
|
130 | - } catch ( \Exception $e ) { |
|
131 | - $this->log->error( "An error occurred while trying to delete term $term_id: " . $e->getMessage(), $e ); |
|
132 | - } |
|
133 | - } |
|
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_Term_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( 'create_term', array( $this, 'do_sync' ) ); |
|
47 | + add_action( 'edit_term', array( $this, 'do_sync' ) ); |
|
48 | + add_action( 'added_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
49 | + add_action( 'updated_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
50 | + add_action( 'deleted_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
51 | + add_action( 'pre_delete_term', array( $this, 'delete_term' ) ); |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + public function saved_term( $term_id ) { |
|
56 | + |
|
57 | + // Sync all the terms without filtering. |
|
58 | + $this->sync( $term_id ); |
|
59 | + } |
|
60 | + |
|
61 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
62 | + public function changed_term_meta( $meta_id, $term_id, $meta_key, $_meta_value ) { |
|
63 | + |
|
64 | + if ( in_array( |
|
65 | + $meta_key, |
|
66 | + apply_filters( |
|
67 | + 'wl_dataset__sync_post_hooks__ignored_meta_keys', |
|
68 | + apply_filters( |
|
69 | + 'wl_dataset__sync_hooks__ignored_meta_keys', |
|
70 | + array( |
|
71 | + '_pingme', |
|
72 | + '_encloseme', |
|
73 | + 'entity_url', |
|
74 | + ) |
|
75 | + ) |
|
76 | + ), |
|
77 | + true |
|
78 | + ) |
|
79 | + ) { |
|
80 | + return; |
|
81 | + } |
|
82 | + |
|
83 | + $this->sync( $term_id ); |
|
84 | + |
|
85 | + } |
|
86 | + |
|
87 | + private function sync( $term_id ) { |
|
88 | + |
|
89 | + $this->enqueue( array( 'do_sync', $term_id ) ); |
|
90 | + } |
|
91 | + |
|
92 | + public function do_sync( $term_id ) { |
|
93 | + |
|
94 | + try { |
|
95 | + $term = get_term( $term_id ); |
|
96 | + if ( ! isset( $term ) ) { |
|
97 | + return; |
|
98 | + } |
|
99 | + $this->sync_service->sync_many( |
|
100 | + array( |
|
101 | + $this->sync_object_factory->create( Object_Type_Enum::TERM, $term_id ), |
|
102 | + ) |
|
103 | + ); |
|
104 | + } catch ( \Exception $e ) { |
|
105 | + $this->log->error( "An error occurred while trying to sync post $term_id: " . $e->getMessage(), $e ); |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @param $term \WP_Term |
|
111 | + * |
|
112 | + * @throws \Exception when an error occurs. |
|
113 | + */ |
|
114 | + public function delete_term( $term_id ) { |
|
115 | + $args = array( |
|
116 | + $term_id, |
|
117 | + Wordpress_Term_Content_Legacy_Service::get_instance() |
|
118 | + ->get_entity_id( Wordpress_Content_Id::create_term( $term_id ) ), |
|
119 | + ); |
|
120 | + // We can't postpone the execution for a `delete` because we would miss the actual data. |
|
121 | + $this->do_delete( $args ); |
|
122 | + } |
|
123 | + |
|
124 | + public function do_delete( $args ) { |
|
125 | + $term_id = $args[0]; |
|
126 | + $term_entity_uri = $args[1]; |
|
127 | + |
|
128 | + try { |
|
129 | + $this->sync_service->delete_one( Object_Type_Enum::TERM, $term_id, $term_entity_uri ); |
|
130 | + } catch ( \Exception $e ) { |
|
131 | + $this->log->error( "An error occurred while trying to delete term $term_id: " . $e->getMessage(), $e ); |
|
132 | + } |
|
133 | + } |
|
134 | 134 | } |
@@ -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,25 +43,25 @@ discard block |
||
43 | 43 | /** |
44 | 44 | * Register hooks for post and meta. |
45 | 45 | */ |
46 | - add_action( 'create_term', array( $this, 'do_sync' ) ); |
|
47 | - add_action( 'edit_term', array( $this, 'do_sync' ) ); |
|
48 | - add_action( 'added_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
49 | - add_action( 'updated_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
50 | - add_action( 'deleted_term_meta', array( $this, 'changed_term_meta' ), 10, 4 ); |
|
51 | - add_action( 'pre_delete_term', array( $this, 'delete_term' ) ); |
|
46 | + add_action('create_term', array($this, 'do_sync')); |
|
47 | + add_action('edit_term', array($this, 'do_sync')); |
|
48 | + add_action('added_term_meta', array($this, 'changed_term_meta'), 10, 4); |
|
49 | + add_action('updated_term_meta', array($this, 'changed_term_meta'), 10, 4); |
|
50 | + add_action('deleted_term_meta', array($this, 'changed_term_meta'), 10, 4); |
|
51 | + add_action('pre_delete_term', array($this, 'delete_term')); |
|
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | - public function saved_term( $term_id ) { |
|
55 | + public function saved_term($term_id) { |
|
56 | 56 | |
57 | 57 | // Sync all the terms without filtering. |
58 | - $this->sync( $term_id ); |
|
58 | + $this->sync($term_id); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
62 | - public function changed_term_meta( $meta_id, $term_id, $meta_key, $_meta_value ) { |
|
62 | + public function changed_term_meta($meta_id, $term_id, $meta_key, $_meta_value) { |
|
63 | 63 | |
64 | - if ( in_array( |
|
64 | + if (in_array( |
|
65 | 65 | $meta_key, |
66 | 66 | apply_filters( |
67 | 67 | 'wl_dataset__sync_post_hooks__ignored_meta_keys', |
@@ -80,29 +80,29 @@ discard block |
||
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | - $this->sync( $term_id ); |
|
83 | + $this->sync($term_id); |
|
84 | 84 | |
85 | 85 | } |
86 | 86 | |
87 | - private function sync( $term_id ) { |
|
87 | + private function sync($term_id) { |
|
88 | 88 | |
89 | - $this->enqueue( array( 'do_sync', $term_id ) ); |
|
89 | + $this->enqueue(array('do_sync', $term_id)); |
|
90 | 90 | } |
91 | 91 | |
92 | - public function do_sync( $term_id ) { |
|
92 | + public function do_sync($term_id) { |
|
93 | 93 | |
94 | 94 | try { |
95 | - $term = get_term( $term_id ); |
|
96 | - if ( ! isset( $term ) ) { |
|
95 | + $term = get_term($term_id); |
|
96 | + if ( ! isset($term)) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | $this->sync_service->sync_many( |
100 | 100 | array( |
101 | - $this->sync_object_factory->create( Object_Type_Enum::TERM, $term_id ), |
|
101 | + $this->sync_object_factory->create(Object_Type_Enum::TERM, $term_id), |
|
102 | 102 | ) |
103 | 103 | ); |
104 | - } catch ( \Exception $e ) { |
|
105 | - $this->log->error( "An error occurred while trying to sync post $term_id: " . $e->getMessage(), $e ); |
|
104 | + } catch (\Exception $e) { |
|
105 | + $this->log->error("An error occurred while trying to sync post $term_id: ".$e->getMessage(), $e); |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @throws \Exception when an error occurs. |
113 | 113 | */ |
114 | - public function delete_term( $term_id ) { |
|
114 | + public function delete_term($term_id) { |
|
115 | 115 | $args = array( |
116 | 116 | $term_id, |
117 | 117 | Wordpress_Term_Content_Legacy_Service::get_instance() |
118 | - ->get_entity_id( Wordpress_Content_Id::create_term( $term_id ) ), |
|
118 | + ->get_entity_id(Wordpress_Content_Id::create_term($term_id)), |
|
119 | 119 | ); |
120 | 120 | // We can't postpone the execution for a `delete` because we would miss the actual data. |
121 | - $this->do_delete( $args ); |
|
121 | + $this->do_delete($args); |
|
122 | 122 | } |
123 | 123 | |
124 | - public function do_delete( $args ) { |
|
124 | + public function do_delete($args) { |
|
125 | 125 | $term_id = $args[0]; |
126 | 126 | $term_entity_uri = $args[1]; |
127 | 127 | |
128 | 128 | try { |
129 | - $this->sync_service->delete_one( Object_Type_Enum::TERM, $term_id, $term_entity_uri ); |
|
130 | - } catch ( \Exception $e ) { |
|
131 | - $this->log->error( "An error occurred while trying to delete term $term_id: " . $e->getMessage(), $e ); |
|
129 | + $this->sync_service->delete_one(Object_Type_Enum::TERM, $term_id, $term_entity_uri); |
|
130 | + } catch (\Exception $e) { |
|
131 | + $this->log->error("An error occurred while trying to delete term $term_id: ".$e->getMessage(), $e); |
|
132 | 132 | } |
133 | 133 | } |
134 | 134 | } |
@@ -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 | } |
@@ -7,45 +7,45 @@ |
||
7 | 7 | |
8 | 8 | abstract class Abstract_Sync_Object_Adapter implements Sync_Object_Adapter { |
9 | 9 | |
10 | - private $object_id; |
|
11 | - |
|
12 | - private $type; |
|
13 | - |
|
14 | - private static $meta_name = array( |
|
15 | - Object_Type_Enum::POST => 'post', |
|
16 | - Object_Type_Enum::TERM => 'term', |
|
17 | - Object_Type_Enum::USER => 'user', |
|
18 | - ); |
|
19 | - |
|
20 | - /** |
|
21 | - * Sync_Object_Adapter constructor. |
|
22 | - * |
|
23 | - * @param int $type One of Object_Type_Enum. |
|
24 | - * @param int $object_id A post or term id. |
|
25 | - * @param Jsonld_Service |
|
26 | - * |
|
27 | - * @throws \Exception when an error occurs. |
|
28 | - */ |
|
29 | - public function __construct( $type, $object_id ) { |
|
30 | - |
|
31 | - $this->type = filter_var( $type, FILTER_VALIDATE_INT ); |
|
32 | - $this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT ); |
|
33 | - |
|
34 | - if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) { |
|
35 | - throw new \Exception( 'Invalid $type.' ); |
|
36 | - } |
|
37 | - if ( null === $this->object_id ) { |
|
38 | - throw new \Exception( 'Invalid $object.' ); |
|
39 | - } |
|
40 | - |
|
41 | - } |
|
42 | - |
|
43 | - public function get_type() { |
|
44 | - return $this->type; |
|
45 | - } |
|
46 | - |
|
47 | - public function get_object_id() { |
|
48 | - return $this->object_id; |
|
49 | - } |
|
10 | + private $object_id; |
|
11 | + |
|
12 | + private $type; |
|
13 | + |
|
14 | + private static $meta_name = array( |
|
15 | + Object_Type_Enum::POST => 'post', |
|
16 | + Object_Type_Enum::TERM => 'term', |
|
17 | + Object_Type_Enum::USER => 'user', |
|
18 | + ); |
|
19 | + |
|
20 | + /** |
|
21 | + * Sync_Object_Adapter constructor. |
|
22 | + * |
|
23 | + * @param int $type One of Object_Type_Enum. |
|
24 | + * @param int $object_id A post or term id. |
|
25 | + * @param Jsonld_Service |
|
26 | + * |
|
27 | + * @throws \Exception when an error occurs. |
|
28 | + */ |
|
29 | + public function __construct( $type, $object_id ) { |
|
30 | + |
|
31 | + $this->type = filter_var( $type, FILTER_VALIDATE_INT ); |
|
32 | + $this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT ); |
|
33 | + |
|
34 | + if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) { |
|
35 | + throw new \Exception( 'Invalid $type.' ); |
|
36 | + } |
|
37 | + if ( null === $this->object_id ) { |
|
38 | + throw new \Exception( 'Invalid $object.' ); |
|
39 | + } |
|
40 | + |
|
41 | + } |
|
42 | + |
|
43 | + public function get_type() { |
|
44 | + return $this->type; |
|
45 | + } |
|
46 | + |
|
47 | + public function get_object_id() { |
|
48 | + return $this->object_id; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -26,16 +26,16 @@ |
||
26 | 26 | * |
27 | 27 | * @throws \Exception when an error occurs. |
28 | 28 | */ |
29 | - public function __construct( $type, $object_id ) { |
|
29 | + public function __construct($type, $object_id) { |
|
30 | 30 | |
31 | - $this->type = filter_var( $type, FILTER_VALIDATE_INT ); |
|
32 | - $this->object_id = filter_var( $object_id, FILTER_VALIDATE_INT ); |
|
31 | + $this->type = filter_var($type, FILTER_VALIDATE_INT); |
|
32 | + $this->object_id = filter_var($object_id, FILTER_VALIDATE_INT); |
|
33 | 33 | |
34 | - if ( null === $this->type || ! isset( self::$meta_name[ $this->type ] ) ) { |
|
35 | - throw new \Exception( 'Invalid $type.' ); |
|
34 | + if (null === $this->type || ! isset(self::$meta_name[$this->type])) { |
|
35 | + throw new \Exception('Invalid $type.'); |
|
36 | 36 | } |
37 | - if ( null === $this->object_id ) { |
|
38 | - throw new \Exception( 'Invalid $object.' ); |
|
37 | + if (null === $this->object_id) { |
|
38 | + throw new \Exception('Invalid $object.'); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | } |
@@ -7,110 +7,110 @@ |
||
7 | 7 | use Wordlift\Object_Type_Enum; |
8 | 8 | |
9 | 9 | class Sync_User_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 | - * Sync_User_Hooks constructor. |
|
22 | - * |
|
23 | - * @param Sync_Service $sync_service |
|
24 | - */ |
|
25 | - public function __construct( Sync_Service $sync_service ) { |
|
26 | - parent::__construct(); |
|
27 | - |
|
28 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
29 | - |
|
30 | - $this->sync_service = $sync_service; |
|
31 | - |
|
32 | - $this->register_hooks(); |
|
33 | - |
|
34 | - } |
|
35 | - |
|
36 | - private function register_hooks() { |
|
37 | - /** |
|
38 | - * Register hooks for user and meta. |
|
39 | - */ |
|
40 | - add_action( 'user_register', array( $this, 'changed_user' ) ); |
|
41 | - add_action( 'profile_update', array( $this, 'changed_user' ) ); |
|
42 | - add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
43 | - add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
44 | - add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
45 | - add_action( 'delete_user', array( $this, 'delete_user' ) ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - public function changed_user( $user_id ) { |
|
50 | - |
|
51 | - $this->sync( $user_id ); |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - public function changed_user_meta( $meta_id, $user_id, $meta_key ) { |
|
56 | - |
|
57 | - if ( in_array( |
|
58 | - $meta_key, |
|
59 | - apply_filters( |
|
60 | - 'wl_dataset__sync_user_hooks__ignored_meta_keys', |
|
61 | - apply_filters( |
|
62 | - 'wl_dataset__sync_hooks__ignored_meta_keys', |
|
63 | - array( |
|
64 | - 'rich_editing', |
|
65 | - 'comment_shortcuts', |
|
66 | - 'admin_color', |
|
67 | - 'use_ssl', |
|
68 | - 'show_admin_bar_front', |
|
69 | - 'wptests_capabilities', |
|
70 | - 'wptests_user_level', |
|
71 | - 'dismissed_wp_pointers', |
|
72 | - 'entity_url', |
|
73 | - ) |
|
74 | - ) |
|
75 | - ), |
|
76 | - true |
|
77 | - ) ) { |
|
78 | - return; |
|
79 | - } |
|
80 | - |
|
81 | - $this->sync( $user_id ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - private function sync( $user_id ) { |
|
86 | - $this->enqueue( array( 'do_sync', $user_id ) ); |
|
87 | - } |
|
88 | - |
|
89 | - public function do_sync( $user_id ) { |
|
90 | - |
|
91 | - try { |
|
92 | - $this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id ); |
|
93 | - } catch ( \Exception $e ) { |
|
94 | - $this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e ); |
|
95 | - } |
|
96 | - |
|
97 | - } |
|
98 | - |
|
99 | - public function delete_user( $user_id ) { |
|
100 | - $this->enqueue( array( 'do_delete', $user_id ) ); |
|
101 | - } |
|
102 | - |
|
103 | - public function do_delete( $user_id ) { |
|
104 | - try { |
|
105 | - $this->sync_service->delete_one( |
|
106 | - Object_Type_Enum::USER, |
|
107 | - $user_id, |
|
108 | - Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_user( $user_id ) ) |
|
109 | - ); |
|
110 | - } catch ( \Exception $e ) { |
|
111 | - $this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e ); |
|
112 | - } |
|
113 | - |
|
114 | - } |
|
10 | + /** |
|
11 | + * @var \Wordlift_Log_Service |
|
12 | + */ |
|
13 | + private $log; |
|
14 | + |
|
15 | + /** |
|
16 | + * @var Sync_Service |
|
17 | + */ |
|
18 | + private $sync_service; |
|
19 | + |
|
20 | + /** |
|
21 | + * Sync_User_Hooks constructor. |
|
22 | + * |
|
23 | + * @param Sync_Service $sync_service |
|
24 | + */ |
|
25 | + public function __construct( Sync_Service $sync_service ) { |
|
26 | + parent::__construct(); |
|
27 | + |
|
28 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
29 | + |
|
30 | + $this->sync_service = $sync_service; |
|
31 | + |
|
32 | + $this->register_hooks(); |
|
33 | + |
|
34 | + } |
|
35 | + |
|
36 | + private function register_hooks() { |
|
37 | + /** |
|
38 | + * Register hooks for user and meta. |
|
39 | + */ |
|
40 | + add_action( 'user_register', array( $this, 'changed_user' ) ); |
|
41 | + add_action( 'profile_update', array( $this, 'changed_user' ) ); |
|
42 | + add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
43 | + add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
44 | + add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
45 | + add_action( 'delete_user', array( $this, 'delete_user' ) ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + public function changed_user( $user_id ) { |
|
50 | + |
|
51 | + $this->sync( $user_id ); |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + public function changed_user_meta( $meta_id, $user_id, $meta_key ) { |
|
56 | + |
|
57 | + if ( in_array( |
|
58 | + $meta_key, |
|
59 | + apply_filters( |
|
60 | + 'wl_dataset__sync_user_hooks__ignored_meta_keys', |
|
61 | + apply_filters( |
|
62 | + 'wl_dataset__sync_hooks__ignored_meta_keys', |
|
63 | + array( |
|
64 | + 'rich_editing', |
|
65 | + 'comment_shortcuts', |
|
66 | + 'admin_color', |
|
67 | + 'use_ssl', |
|
68 | + 'show_admin_bar_front', |
|
69 | + 'wptests_capabilities', |
|
70 | + 'wptests_user_level', |
|
71 | + 'dismissed_wp_pointers', |
|
72 | + 'entity_url', |
|
73 | + ) |
|
74 | + ) |
|
75 | + ), |
|
76 | + true |
|
77 | + ) ) { |
|
78 | + return; |
|
79 | + } |
|
80 | + |
|
81 | + $this->sync( $user_id ); |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + private function sync( $user_id ) { |
|
86 | + $this->enqueue( array( 'do_sync', $user_id ) ); |
|
87 | + } |
|
88 | + |
|
89 | + public function do_sync( $user_id ) { |
|
90 | + |
|
91 | + try { |
|
92 | + $this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id ); |
|
93 | + } catch ( \Exception $e ) { |
|
94 | + $this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e ); |
|
95 | + } |
|
96 | + |
|
97 | + } |
|
98 | + |
|
99 | + public function delete_user( $user_id ) { |
|
100 | + $this->enqueue( array( 'do_delete', $user_id ) ); |
|
101 | + } |
|
102 | + |
|
103 | + public function do_delete( $user_id ) { |
|
104 | + try { |
|
105 | + $this->sync_service->delete_one( |
|
106 | + Object_Type_Enum::USER, |
|
107 | + $user_id, |
|
108 | + Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_user( $user_id ) ) |
|
109 | + ); |
|
110 | + } catch ( \Exception $e ) { |
|
111 | + $this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e ); |
|
112 | + } |
|
113 | + |
|
114 | + } |
|
115 | 115 | |
116 | 116 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param Sync_Service $sync_service |
24 | 24 | */ |
25 | - public function __construct( Sync_Service $sync_service ) { |
|
25 | + public function __construct(Sync_Service $sync_service) { |
|
26 | 26 | parent::__construct(); |
27 | 27 | |
28 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
28 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
29 | 29 | |
30 | 30 | $this->sync_service = $sync_service; |
31 | 31 | |
@@ -37,24 +37,24 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * Register hooks for user and meta. |
39 | 39 | */ |
40 | - add_action( 'user_register', array( $this, 'changed_user' ) ); |
|
41 | - add_action( 'profile_update', array( $this, 'changed_user' ) ); |
|
42 | - add_action( 'added_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
43 | - add_action( 'updated_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
44 | - add_action( 'deleted_user_meta', array( $this, 'changed_user_meta' ), 10, 3 ); |
|
45 | - add_action( 'delete_user', array( $this, 'delete_user' ) ); |
|
40 | + add_action('user_register', array($this, 'changed_user')); |
|
41 | + add_action('profile_update', array($this, 'changed_user')); |
|
42 | + add_action('added_user_meta', array($this, 'changed_user_meta'), 10, 3); |
|
43 | + add_action('updated_user_meta', array($this, 'changed_user_meta'), 10, 3); |
|
44 | + add_action('deleted_user_meta', array($this, 'changed_user_meta'), 10, 3); |
|
45 | + add_action('delete_user', array($this, 'delete_user')); |
|
46 | 46 | |
47 | 47 | } |
48 | 48 | |
49 | - public function changed_user( $user_id ) { |
|
49 | + public function changed_user($user_id) { |
|
50 | 50 | |
51 | - $this->sync( $user_id ); |
|
51 | + $this->sync($user_id); |
|
52 | 52 | |
53 | 53 | } |
54 | 54 | |
55 | - public function changed_user_meta( $meta_id, $user_id, $meta_key ) { |
|
55 | + public function changed_user_meta($meta_id, $user_id, $meta_key) { |
|
56 | 56 | |
57 | - if ( in_array( |
|
57 | + if (in_array( |
|
58 | 58 | $meta_key, |
59 | 59 | apply_filters( |
60 | 60 | 'wl_dataset__sync_user_hooks__ignored_meta_keys', |
@@ -74,41 +74,41 @@ discard block |
||
74 | 74 | ) |
75 | 75 | ), |
76 | 76 | true |
77 | - ) ) { |
|
77 | + )) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - $this->sync( $user_id ); |
|
81 | + $this->sync($user_id); |
|
82 | 82 | |
83 | 83 | } |
84 | 84 | |
85 | - private function sync( $user_id ) { |
|
86 | - $this->enqueue( array( 'do_sync', $user_id ) ); |
|
85 | + private function sync($user_id) { |
|
86 | + $this->enqueue(array('do_sync', $user_id)); |
|
87 | 87 | } |
88 | 88 | |
89 | - public function do_sync( $user_id ) { |
|
89 | + public function do_sync($user_id) { |
|
90 | 90 | |
91 | 91 | try { |
92 | - $this->sync_service->sync_one( Object_Type_Enum::USER, (int) $user_id ); |
|
93 | - } catch ( \Exception $e ) { |
|
94 | - $this->log->error( "An error occurred while trying to sync user $user_id: " . $e->getMessage(), $e ); |
|
92 | + $this->sync_service->sync_one(Object_Type_Enum::USER, (int) $user_id); |
|
93 | + } catch (\Exception $e) { |
|
94 | + $this->log->error("An error occurred while trying to sync user $user_id: ".$e->getMessage(), $e); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | } |
98 | 98 | |
99 | - public function delete_user( $user_id ) { |
|
100 | - $this->enqueue( array( 'do_delete', $user_id ) ); |
|
99 | + public function delete_user($user_id) { |
|
100 | + $this->enqueue(array('do_delete', $user_id)); |
|
101 | 101 | } |
102 | 102 | |
103 | - public function do_delete( $user_id ) { |
|
103 | + public function do_delete($user_id) { |
|
104 | 104 | try { |
105 | 105 | $this->sync_service->delete_one( |
106 | 106 | Object_Type_Enum::USER, |
107 | 107 | $user_id, |
108 | - Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id( Wordpress_Content_Id::create_user( $user_id ) ) |
|
108 | + Wordpress_User_Content_Legacy_Service::get_instance()->get_entity_id(Wordpress_Content_Id::create_user($user_id)) |
|
109 | 109 | ); |
110 | - } catch ( \Exception $e ) { |
|
111 | - $this->log->error( "An error occurred while trying to delete user $user_id: " . $e->getMessage(), $e ); |
|
110 | + } catch (\Exception $e) { |
|
111 | + $this->log->error("An error occurred while trying to delete user $user_id: ".$e->getMessage(), $e); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | } |
@@ -6,33 +6,33 @@ |
||
6 | 6 | |
7 | 7 | class Sync_User_Adapter extends Abstract_Sync_Object_Adapter { |
8 | 8 | |
9 | - /** |
|
10 | - * Sync_User_Adapter constructor. |
|
11 | - * |
|
12 | - * @param int $user_id |
|
13 | - * |
|
14 | - * @throws \Exception when an error occurs. |
|
15 | - */ |
|
16 | - public function __construct( $user_id ) { |
|
17 | - parent::__construct( Object_Type_Enum::USER, $user_id ); |
|
18 | - } |
|
19 | - |
|
20 | - public function is_published() { |
|
21 | - return true; |
|
22 | - } |
|
23 | - |
|
24 | - public function is_public() { |
|
25 | - return true; |
|
26 | - } |
|
27 | - |
|
28 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
29 | - public function set_values( $arr ) { |
|
30 | - // @@todo |
|
31 | - } |
|
32 | - |
|
33 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
34 | - public function get_value( $key ) { |
|
35 | - // @@todo |
|
36 | - } |
|
9 | + /** |
|
10 | + * Sync_User_Adapter constructor. |
|
11 | + * |
|
12 | + * @param int $user_id |
|
13 | + * |
|
14 | + * @throws \Exception when an error occurs. |
|
15 | + */ |
|
16 | + public function __construct( $user_id ) { |
|
17 | + parent::__construct( Object_Type_Enum::USER, $user_id ); |
|
18 | + } |
|
19 | + |
|
20 | + public function is_published() { |
|
21 | + return true; |
|
22 | + } |
|
23 | + |
|
24 | + public function is_public() { |
|
25 | + return true; |
|
26 | + } |
|
27 | + |
|
28 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
29 | + public function set_values( $arr ) { |
|
30 | + // @@todo |
|
31 | + } |
|
32 | + |
|
33 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
34 | + public function get_value( $key ) { |
|
35 | + // @@todo |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -13,8 +13,8 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @throws \Exception when an error occurs. |
15 | 15 | */ |
16 | - public function __construct( $user_id ) { |
|
17 | - parent::__construct( Object_Type_Enum::USER, $user_id ); |
|
16 | + public function __construct($user_id) { |
|
17 | + parent::__construct(Object_Type_Enum::USER, $user_id); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | public function is_published() { |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | } |
27 | 27 | |
28 | 28 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
29 | - public function set_values( $arr ) { |
|
29 | + public function set_values($arr) { |
|
30 | 30 | // @@todo |
31 | 31 | } |
32 | 32 | |
33 | 33 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
34 | - public function get_value( $key ) { |
|
34 | + public function get_value($key) { |
|
35 | 35 | // @@todo |
36 | 36 | } |
37 | 37 |