@@ -4,195 +4,195 @@ |
||
4 | 4 | |
5 | 5 | class Analysis_Background_Process extends \Wordlift_Plugin_WP_Background_Process { |
6 | 6 | |
7 | - const WL_CMKG_ANALYSIS_BACKGROUND_PROCESS = '_wl_cmkg_analysis_background_process'; |
|
8 | - |
|
9 | - protected $action = 'wl_cmkg_analysis_background__analysis'; |
|
10 | - |
|
11 | - /** |
|
12 | - * @var Analysis_Background_Service |
|
13 | - */ |
|
14 | - private $analysis_background_service; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var \Wordlift_Log_Service |
|
18 | - */ |
|
19 | - private $log; |
|
20 | - |
|
21 | - /** |
|
22 | - * Analysis_Background_Process constructor. |
|
23 | - * |
|
24 | - * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process. |
|
25 | - */ |
|
26 | - public function __construct( $analysis_background_service ) { |
|
27 | - parent::__construct(); |
|
28 | - |
|
29 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
30 | - |
|
31 | - $this->analysis_background_service = $analysis_background_service; |
|
32 | - |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * This function is called: |
|
37 | - * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
38 | - * - To synchronize a post, by passing a numeric ID. |
|
39 | - * |
|
40 | - * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
41 | - * |
|
42 | - * @param int[] $term_ids An array of term IDs. |
|
43 | - * |
|
44 | - * @return int[]|false The next term IDs or false if there are no more. |
|
45 | - */ |
|
46 | - protected function task( $term_ids ) { |
|
47 | - |
|
48 | - // Check if we must cancel. |
|
49 | - if ( $this->must_cancel() ) { |
|
50 | - $this->cancel(); |
|
51 | - |
|
52 | - return false; |
|
53 | - } |
|
54 | - |
|
55 | - if ( ! $term_ids || ! is_array( $term_ids ) ) { |
|
56 | - $this->cancel(); |
|
57 | - return false; |
|
58 | - } |
|
59 | - |
|
60 | - $this->log->debug( sprintf( 'Synchronizing terms %s...', implode( ', ', $term_ids ) ) ); |
|
61 | - // Sync the item. |
|
62 | - return $this->sync_items( $term_ids ); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * Start the background processing. |
|
67 | - * |
|
68 | - * @return bool True if the process has been started, otherwise false. |
|
69 | - */ |
|
70 | - public function start() { |
|
71 | - $this->log->debug( 'Trying to start analysis bg service...' ); |
|
72 | - // Create a new Sync_Model state of `started`. |
|
73 | - if ( ! $this->is_started( self::get_state() ) ) { |
|
74 | - $this->log->debug( 'Starting...' ); |
|
75 | - |
|
76 | - $sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' ); |
|
77 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false ); |
|
78 | - |
|
79 | - $next = $this->analysis_background_service->next(); |
|
80 | - |
|
81 | - $this->push_to_queue( $next ); |
|
82 | - $this->save()->dispatch(); |
|
83 | - |
|
84 | - if ( $next && is_array( $next ) ) { |
|
85 | - $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
86 | - } |
|
87 | - |
|
88 | - return true; |
|
89 | - } |
|
90 | - |
|
91 | - return false; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Set the transient to cancel the process. The next time the process runs, it'll check whether this transient is |
|
96 | - * set and will stop processing. |
|
97 | - */ |
|
98 | - public function request_cancel() { |
|
99 | - |
|
100 | - set_transient( "{$this->action}__cancel", true ); |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Get the sync state. |
|
106 | - * |
|
107 | - * @return Sync_State The {@link Sync_State}. |
|
108 | - */ |
|
109 | - public static function get_state() { |
|
110 | - |
|
111 | - try { |
|
112 | - return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
113 | - } catch ( \Exception $e ) { |
|
114 | - return Sync_State::unknown(); |
|
115 | - } |
|
116 | - |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Check whether the provided state is `started` or not. |
|
121 | - * |
|
122 | - * @param Sync_State $state The {@link Sync_State}. |
|
123 | - * |
|
124 | - * @return bool True if the state is started. |
|
125 | - */ |
|
126 | - private function is_started( $state ) { |
|
127 | - return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Check whether the process must cancel or not. |
|
132 | - * |
|
133 | - * @return bool Whether to cancel or not the process. |
|
134 | - */ |
|
135 | - private function must_cancel() { |
|
136 | - |
|
137 | - return get_transient( "{$this->action}__cancel" ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Cancels the current process. |
|
142 | - */ |
|
143 | - public function cancel() { |
|
144 | - |
|
145 | - $this->log->debug( 'Cancelling synchronization...' ); |
|
146 | - |
|
147 | - // Cleanup the process data. |
|
148 | - $this->cancel_process(); |
|
149 | - |
|
150 | - // Set the state to cancelled. |
|
151 | - $state = self::get_state(); |
|
152 | - $state->set_state( 'cancelled' ); |
|
153 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false ); |
|
154 | - |
|
155 | - // Finally delete the transient. |
|
156 | - delete_transient( "{$this->action}__cancel" ); |
|
157 | - |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Push the post with the provided ID to the remote platform. |
|
162 | - * |
|
163 | - * @param int[] $term_ids The term IDs. |
|
164 | - * |
|
165 | - * @return int[]|false The next term ID to process or false if processing is complete. |
|
166 | - */ |
|
167 | - private function sync_items( $term_ids ) { |
|
168 | - |
|
169 | - // Sync this item. |
|
170 | - if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) { |
|
171 | - |
|
172 | - $next = $this->analysis_background_service->next(); |
|
173 | - $next_state = isset( $next ) ? 'started' : 'ended'; |
|
174 | - |
|
175 | - /** |
|
176 | - * Update the synchronization meta data, by increasing the current index. |
|
177 | - * |
|
178 | - * @var Sync_State $sync The {@link Sync_State}. |
|
179 | - */ |
|
180 | - $state = self::get_state() |
|
181 | - ->increment_index( $this->analysis_background_service->get_batch_size() ) |
|
182 | - ->set_state( $next_state ); |
|
183 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false ); |
|
184 | - |
|
185 | - // Return the next IDs or false if there aren't. |
|
186 | - return isset( $next ) ? $next : false; |
|
187 | - } else { |
|
188 | - // Retry. |
|
189 | - // @@todo: put a limit to the number of retries. |
|
190 | - |
|
191 | - $this->log->error( sprintf( 'Sync failed for terms %s.', implode( ', ', $term_ids ) ) ); |
|
192 | - |
|
193 | - return $term_ids; |
|
194 | - } |
|
195 | - |
|
196 | - } |
|
7 | + const WL_CMKG_ANALYSIS_BACKGROUND_PROCESS = '_wl_cmkg_analysis_background_process'; |
|
8 | + |
|
9 | + protected $action = 'wl_cmkg_analysis_background__analysis'; |
|
10 | + |
|
11 | + /** |
|
12 | + * @var Analysis_Background_Service |
|
13 | + */ |
|
14 | + private $analysis_background_service; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var \Wordlift_Log_Service |
|
18 | + */ |
|
19 | + private $log; |
|
20 | + |
|
21 | + /** |
|
22 | + * Analysis_Background_Process constructor. |
|
23 | + * |
|
24 | + * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process. |
|
25 | + */ |
|
26 | + public function __construct( $analysis_background_service ) { |
|
27 | + parent::__construct(); |
|
28 | + |
|
29 | + $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
30 | + |
|
31 | + $this->analysis_background_service = $analysis_background_service; |
|
32 | + |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * This function is called: |
|
37 | + * - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance. |
|
38 | + * - To synchronize a post, by passing a numeric ID. |
|
39 | + * |
|
40 | + * This function returns the parameter for the next call or NULL if there are no more posts to process. |
|
41 | + * |
|
42 | + * @param int[] $term_ids An array of term IDs. |
|
43 | + * |
|
44 | + * @return int[]|false The next term IDs or false if there are no more. |
|
45 | + */ |
|
46 | + protected function task( $term_ids ) { |
|
47 | + |
|
48 | + // Check if we must cancel. |
|
49 | + if ( $this->must_cancel() ) { |
|
50 | + $this->cancel(); |
|
51 | + |
|
52 | + return false; |
|
53 | + } |
|
54 | + |
|
55 | + if ( ! $term_ids || ! is_array( $term_ids ) ) { |
|
56 | + $this->cancel(); |
|
57 | + return false; |
|
58 | + } |
|
59 | + |
|
60 | + $this->log->debug( sprintf( 'Synchronizing terms %s...', implode( ', ', $term_ids ) ) ); |
|
61 | + // Sync the item. |
|
62 | + return $this->sync_items( $term_ids ); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * Start the background processing. |
|
67 | + * |
|
68 | + * @return bool True if the process has been started, otherwise false. |
|
69 | + */ |
|
70 | + public function start() { |
|
71 | + $this->log->debug( 'Trying to start analysis bg service...' ); |
|
72 | + // Create a new Sync_Model state of `started`. |
|
73 | + if ( ! $this->is_started( self::get_state() ) ) { |
|
74 | + $this->log->debug( 'Starting...' ); |
|
75 | + |
|
76 | + $sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' ); |
|
77 | + update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false ); |
|
78 | + |
|
79 | + $next = $this->analysis_background_service->next(); |
|
80 | + |
|
81 | + $this->push_to_queue( $next ); |
|
82 | + $this->save()->dispatch(); |
|
83 | + |
|
84 | + if ( $next && is_array( $next ) ) { |
|
85 | + $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
86 | + } |
|
87 | + |
|
88 | + return true; |
|
89 | + } |
|
90 | + |
|
91 | + return false; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Set the transient to cancel the process. The next time the process runs, it'll check whether this transient is |
|
96 | + * set and will stop processing. |
|
97 | + */ |
|
98 | + public function request_cancel() { |
|
99 | + |
|
100 | + set_transient( "{$this->action}__cancel", true ); |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Get the sync state. |
|
106 | + * |
|
107 | + * @return Sync_State The {@link Sync_State}. |
|
108 | + */ |
|
109 | + public static function get_state() { |
|
110 | + |
|
111 | + try { |
|
112 | + return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
113 | + } catch ( \Exception $e ) { |
|
114 | + return Sync_State::unknown(); |
|
115 | + } |
|
116 | + |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Check whether the provided state is `started` or not. |
|
121 | + * |
|
122 | + * @param Sync_State $state The {@link Sync_State}. |
|
123 | + * |
|
124 | + * @return bool True if the state is started. |
|
125 | + */ |
|
126 | + private function is_started( $state ) { |
|
127 | + return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Check whether the process must cancel or not. |
|
132 | + * |
|
133 | + * @return bool Whether to cancel or not the process. |
|
134 | + */ |
|
135 | + private function must_cancel() { |
|
136 | + |
|
137 | + return get_transient( "{$this->action}__cancel" ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Cancels the current process. |
|
142 | + */ |
|
143 | + public function cancel() { |
|
144 | + |
|
145 | + $this->log->debug( 'Cancelling synchronization...' ); |
|
146 | + |
|
147 | + // Cleanup the process data. |
|
148 | + $this->cancel_process(); |
|
149 | + |
|
150 | + // Set the state to cancelled. |
|
151 | + $state = self::get_state(); |
|
152 | + $state->set_state( 'cancelled' ); |
|
153 | + update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false ); |
|
154 | + |
|
155 | + // Finally delete the transient. |
|
156 | + delete_transient( "{$this->action}__cancel" ); |
|
157 | + |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Push the post with the provided ID to the remote platform. |
|
162 | + * |
|
163 | + * @param int[] $term_ids The term IDs. |
|
164 | + * |
|
165 | + * @return int[]|false The next term ID to process or false if processing is complete. |
|
166 | + */ |
|
167 | + private function sync_items( $term_ids ) { |
|
168 | + |
|
169 | + // Sync this item. |
|
170 | + if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) { |
|
171 | + |
|
172 | + $next = $this->analysis_background_service->next(); |
|
173 | + $next_state = isset( $next ) ? 'started' : 'ended'; |
|
174 | + |
|
175 | + /** |
|
176 | + * Update the synchronization meta data, by increasing the current index. |
|
177 | + * |
|
178 | + * @var Sync_State $sync The {@link Sync_State}. |
|
179 | + */ |
|
180 | + $state = self::get_state() |
|
181 | + ->increment_index( $this->analysis_background_service->get_batch_size() ) |
|
182 | + ->set_state( $next_state ); |
|
183 | + update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false ); |
|
184 | + |
|
185 | + // Return the next IDs or false if there aren't. |
|
186 | + return isset( $next ) ? $next : false; |
|
187 | + } else { |
|
188 | + // Retry. |
|
189 | + // @@todo: put a limit to the number of retries. |
|
190 | + |
|
191 | + $this->log->error( sprintf( 'Sync failed for terms %s.', implode( ', ', $term_ids ) ) ); |
|
192 | + |
|
193 | + return $term_ids; |
|
194 | + } |
|
195 | + |
|
196 | + } |
|
197 | 197 | |
198 | 198 | } |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param $analysis_background_service Analysis_Background_Service A {@link Analysis_Background_Service} instance providing the supporting functions to this background process. |
25 | 25 | */ |
26 | - public function __construct( $analysis_background_service ) { |
|
26 | + public function __construct($analysis_background_service) { |
|
27 | 27 | parent::__construct(); |
28 | 28 | |
29 | - $this->log = \Wordlift_Log_Service::get_logger( get_class() ); |
|
29 | + $this->log = \Wordlift_Log_Service::get_logger(get_class()); |
|
30 | 30 | |
31 | 31 | $this->analysis_background_service = $analysis_background_service; |
32 | 32 | |
@@ -43,23 +43,23 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return int[]|false The next term IDs or false if there are no more. |
45 | 45 | */ |
46 | - protected function task( $term_ids ) { |
|
46 | + protected function task($term_ids) { |
|
47 | 47 | |
48 | 48 | // Check if we must cancel. |
49 | - if ( $this->must_cancel() ) { |
|
49 | + if ($this->must_cancel()) { |
|
50 | 50 | $this->cancel(); |
51 | 51 | |
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
55 | - if ( ! $term_ids || ! is_array( $term_ids ) ) { |
|
55 | + if ( ! $term_ids || ! is_array($term_ids)) { |
|
56 | 56 | $this->cancel(); |
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | - $this->log->debug( sprintf( 'Synchronizing terms %s...', implode( ', ', $term_ids ) ) ); |
|
60 | + $this->log->debug(sprintf('Synchronizing terms %s...', implode(', ', $term_ids))); |
|
61 | 61 | // Sync the item. |
62 | - return $this->sync_items( $term_ids ); |
|
62 | + return $this->sync_items($term_ids); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -68,21 +68,21 @@ discard block |
||
68 | 68 | * @return bool True if the process has been started, otherwise false. |
69 | 69 | */ |
70 | 70 | public function start() { |
71 | - $this->log->debug( 'Trying to start analysis bg service...' ); |
|
71 | + $this->log->debug('Trying to start analysis bg service...'); |
|
72 | 72 | // Create a new Sync_Model state of `started`. |
73 | - if ( ! $this->is_started( self::get_state() ) ) { |
|
74 | - $this->log->debug( 'Starting...' ); |
|
73 | + if ( ! $this->is_started(self::get_state())) { |
|
74 | + $this->log->debug('Starting...'); |
|
75 | 75 | |
76 | - $sync_state = new Sync_State( time(), 0, $this->analysis_background_service->count(), time(), 'started' ); |
|
77 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false ); |
|
76 | + $sync_state = new Sync_State(time(), 0, $this->analysis_background_service->count(), time(), 'started'); |
|
77 | + update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $sync_state, false); |
|
78 | 78 | |
79 | 79 | $next = $this->analysis_background_service->next(); |
80 | 80 | |
81 | - $this->push_to_queue( $next ); |
|
81 | + $this->push_to_queue($next); |
|
82 | 82 | $this->save()->dispatch(); |
83 | 83 | |
84 | - if ( $next && is_array( $next ) ) { |
|
85 | - $this->log->debug( sprintf( 'Started with term IDs %s.', implode( ', ', $next ) ) ); |
|
84 | + if ($next && is_array($next)) { |
|
85 | + $this->log->debug(sprintf('Started with term IDs %s.', implode(', ', $next))); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | return true; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function request_cancel() { |
99 | 99 | |
100 | - set_transient( "{$this->action}__cancel", true ); |
|
100 | + set_transient("{$this->action}__cancel", true); |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | public static function get_state() { |
110 | 110 | |
111 | 111 | try { |
112 | - return get_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown() ); |
|
113 | - } catch ( \Exception $e ) { |
|
112 | + return get_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, Sync_State::unknown()); |
|
113 | + } catch (\Exception $e) { |
|
114 | 114 | return Sync_State::unknown(); |
115 | 115 | } |
116 | 116 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * |
124 | 124 | * @return bool True if the state is started. |
125 | 125 | */ |
126 | - private function is_started( $state ) { |
|
127 | - return $state instanceof Sync_State && 'started' === $state->state && 30 > ( time() - $state->last_update ); |
|
126 | + private function is_started($state) { |
|
127 | + return $state instanceof Sync_State && 'started' === $state->state && 30 > (time() - $state->last_update); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | */ |
135 | 135 | private function must_cancel() { |
136 | 136 | |
137 | - return get_transient( "{$this->action}__cancel" ); |
|
137 | + return get_transient("{$this->action}__cancel"); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -142,18 +142,18 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function cancel() { |
144 | 144 | |
145 | - $this->log->debug( 'Cancelling synchronization...' ); |
|
145 | + $this->log->debug('Cancelling synchronization...'); |
|
146 | 146 | |
147 | 147 | // Cleanup the process data. |
148 | 148 | $this->cancel_process(); |
149 | 149 | |
150 | 150 | // Set the state to cancelled. |
151 | 151 | $state = self::get_state(); |
152 | - $state->set_state( 'cancelled' ); |
|
153 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false ); |
|
152 | + $state->set_state('cancelled'); |
|
153 | + update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS, $state, false); |
|
154 | 154 | |
155 | 155 | // Finally delete the transient. |
156 | - delete_transient( "{$this->action}__cancel" ); |
|
156 | + delete_transient("{$this->action}__cancel"); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 | |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | * |
165 | 165 | * @return int[]|false The next term ID to process or false if processing is complete. |
166 | 166 | */ |
167 | - private function sync_items( $term_ids ) { |
|
167 | + private function sync_items($term_ids) { |
|
168 | 168 | |
169 | 169 | // Sync this item. |
170 | - if ( $this->analysis_background_service->perform_analysis_for_terms( $term_ids ) ) { |
|
170 | + if ($this->analysis_background_service->perform_analysis_for_terms($term_ids)) { |
|
171 | 171 | |
172 | 172 | $next = $this->analysis_background_service->next(); |
173 | - $next_state = isset( $next ) ? 'started' : 'ended'; |
|
173 | + $next_state = isset($next) ? 'started' : 'ended'; |
|
174 | 174 | |
175 | 175 | /** |
176 | 176 | * Update the synchronization meta data, by increasing the current index. |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | * @var Sync_State $sync The {@link Sync_State}. |
179 | 179 | */ |
180 | 180 | $state = self::get_state() |
181 | - ->increment_index( $this->analysis_background_service->get_batch_size() ) |
|
182 | - ->set_state( $next_state ); |
|
183 | - update_option( self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS . '', $state, false ); |
|
181 | + ->increment_index($this->analysis_background_service->get_batch_size()) |
|
182 | + ->set_state($next_state); |
|
183 | + update_option(self::WL_CMKG_ANALYSIS_BACKGROUND_PROCESS.'', $state, false); |
|
184 | 184 | |
185 | 185 | // Return the next IDs or false if there aren't. |
186 | - return isset( $next ) ? $next : false; |
|
186 | + return isset($next) ? $next : false; |
|
187 | 187 | } else { |
188 | 188 | // Retry. |
189 | 189 | // @@todo: put a limit to the number of retries. |
190 | 190 | |
191 | - $this->log->error( sprintf( 'Sync failed for terms %s.', implode( ', ', $term_ids ) ) ); |
|
191 | + $this->log->error(sprintf('Sync failed for terms %s.', implode(', ', $term_ids))); |
|
192 | 192 | |
193 | 193 | return $term_ids; |
194 | 194 | } |
@@ -4,56 +4,56 @@ |
||
4 | 4 | |
5 | 5 | class Sync_State { |
6 | 6 | |
7 | - public $started; |
|
8 | - public $index; |
|
9 | - public $count; |
|
10 | - public $last_update; |
|
11 | - public $state; |
|
12 | - |
|
13 | - /** |
|
14 | - * Sync_Model constructor. |
|
15 | - * |
|
16 | - * @param $started |
|
17 | - * @param $index |
|
18 | - * @param $count |
|
19 | - * @param $last_update |
|
20 | - * @param $state |
|
21 | - */ |
|
22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
23 | - $this->started = $started; |
|
24 | - $this->index = $index; |
|
25 | - $this->count = (int) $count; |
|
26 | - $this->last_update = $last_update; |
|
27 | - $this->state = $state; |
|
28 | - } |
|
29 | - |
|
30 | - public function increment_index( $count ) { |
|
31 | - $this->index += $count; |
|
32 | - $this->last_update = time(); |
|
33 | - |
|
34 | - return $this; |
|
35 | - } |
|
36 | - |
|
37 | - public function set_state( $value ) { |
|
38 | - $this->state = $value; |
|
39 | - $this->last_update = time(); |
|
40 | - |
|
41 | - return $this; |
|
42 | - } |
|
43 | - |
|
44 | - public function get_array() { |
|
45 | - return array( |
|
46 | - 'started' => $this->started, |
|
47 | - 'index' => $this->index, |
|
48 | - 'count' => $this->count, |
|
49 | - 'last_update' => $this->last_update, |
|
50 | - 'state' => $this->state, |
|
51 | - ); |
|
52 | - } |
|
53 | - |
|
54 | - public static function unknown() { |
|
55 | - |
|
56 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
57 | - } |
|
7 | + public $started; |
|
8 | + public $index; |
|
9 | + public $count; |
|
10 | + public $last_update; |
|
11 | + public $state; |
|
12 | + |
|
13 | + /** |
|
14 | + * Sync_Model constructor. |
|
15 | + * |
|
16 | + * @param $started |
|
17 | + * @param $index |
|
18 | + * @param $count |
|
19 | + * @param $last_update |
|
20 | + * @param $state |
|
21 | + */ |
|
22 | + public function __construct( $started, $index, $count, $last_update, $state ) { |
|
23 | + $this->started = $started; |
|
24 | + $this->index = $index; |
|
25 | + $this->count = (int) $count; |
|
26 | + $this->last_update = $last_update; |
|
27 | + $this->state = $state; |
|
28 | + } |
|
29 | + |
|
30 | + public function increment_index( $count ) { |
|
31 | + $this->index += $count; |
|
32 | + $this->last_update = time(); |
|
33 | + |
|
34 | + return $this; |
|
35 | + } |
|
36 | + |
|
37 | + public function set_state( $value ) { |
|
38 | + $this->state = $value; |
|
39 | + $this->last_update = time(); |
|
40 | + |
|
41 | + return $this; |
|
42 | + } |
|
43 | + |
|
44 | + public function get_array() { |
|
45 | + return array( |
|
46 | + 'started' => $this->started, |
|
47 | + 'index' => $this->index, |
|
48 | + 'count' => $this->count, |
|
49 | + 'last_update' => $this->last_update, |
|
50 | + 'state' => $this->state, |
|
51 | + ); |
|
52 | + } |
|
53 | + |
|
54 | + public static function unknown() { |
|
55 | + |
|
56 | + return new self( time(), 0, 0, time(), 'unknown' ); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * @param $last_update |
20 | 20 | * @param $state |
21 | 21 | */ |
22 | - public function __construct( $started, $index, $count, $last_update, $state ) { |
|
22 | + public function __construct($started, $index, $count, $last_update, $state) { |
|
23 | 23 | $this->started = $started; |
24 | 24 | $this->index = $index; |
25 | 25 | $this->count = (int) $count; |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | $this->state = $state; |
28 | 28 | } |
29 | 29 | |
30 | - public function increment_index( $count ) { |
|
30 | + public function increment_index($count) { |
|
31 | 31 | $this->index += $count; |
32 | 32 | $this->last_update = time(); |
33 | 33 | |
34 | 34 | return $this; |
35 | 35 | } |
36 | 36 | |
37 | - public function set_state( $value ) { |
|
37 | + public function set_state($value) { |
|
38 | 38 | $this->state = $value; |
39 | 39 | $this->last_update = time(); |
40 | 40 | |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public static function unknown() { |
55 | 55 | |
56 | - return new self( time(), 0, 0, time(), 'unknown' ); |
|
56 | + return new self(time(), 0, 0, time(), 'unknown'); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class Cache_Service_Factory { |
6 | 6 | |
7 | - public static function get_cache_service() { |
|
8 | - return new Options_Cache( 'wordlift-cmkg' ); |
|
9 | - } |
|
7 | + public static function get_cache_service() { |
|
8 | + return new Options_Cache( 'wordlift-cmkg' ); |
|
9 | + } |
|
10 | 10 | |
11 | 11 | } |
@@ -5,7 +5,7 @@ |
||
5 | 5 | class Cache_Service_Factory { |
6 | 6 | |
7 | 7 | public static function get_cache_service() { |
8 | - return new Options_Cache( 'wordlift-cmkg' ); |
|
8 | + return new Options_Cache('wordlift-cmkg'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | } |
@@ -4,35 +4,35 @@ |
||
4 | 4 | |
5 | 5 | class Options_Cache implements Cache { |
6 | 6 | |
7 | - private $namespace; |
|
7 | + private $namespace; |
|
8 | 8 | |
9 | - /** |
|
10 | - * Options_Cache constructor. |
|
11 | - * |
|
12 | - * @param $namespace |
|
13 | - */ |
|
14 | - public function __construct( $namespace ) { |
|
15 | - $this->namespace = $namespace; |
|
16 | - } |
|
9 | + /** |
|
10 | + * Options_Cache constructor. |
|
11 | + * |
|
12 | + * @param $namespace |
|
13 | + */ |
|
14 | + public function __construct( $namespace ) { |
|
15 | + $this->namespace = $namespace; |
|
16 | + } |
|
17 | 17 | |
18 | - public function get( $cache_key ) { |
|
18 | + public function get( $cache_key ) { |
|
19 | 19 | |
20 | - return get_option( $this->namespace . '__' . $cache_key, false ); |
|
20 | + return get_option( $this->namespace . '__' . $cache_key, false ); |
|
21 | 21 | |
22 | - } |
|
22 | + } |
|
23 | 23 | |
24 | - public function put( $cache_key, $value ) { |
|
24 | + public function put( $cache_key, $value ) { |
|
25 | 25 | |
26 | - return update_option( $this->namespace . '__' . $cache_key, $value ); |
|
26 | + return update_option( $this->namespace . '__' . $cache_key, $value ); |
|
27 | 27 | |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - public function flush_all() { |
|
31 | - if ( '' !== $this->namespace ) { |
|
32 | - global $wpdb; |
|
33 | - $namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%'; |
|
34 | - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) ); |
|
35 | - } |
|
36 | - } |
|
30 | + public function flush_all() { |
|
31 | + if ( '' !== $this->namespace ) { |
|
32 | + global $wpdb; |
|
33 | + $namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%'; |
|
34 | + $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) ); |
|
35 | + } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | } |
@@ -11,27 +11,27 @@ |
||
11 | 11 | * |
12 | 12 | * @param $namespace |
13 | 13 | */ |
14 | - public function __construct( $namespace ) { |
|
14 | + public function __construct($namespace) { |
|
15 | 15 | $this->namespace = $namespace; |
16 | 16 | } |
17 | 17 | |
18 | - public function get( $cache_key ) { |
|
18 | + public function get($cache_key) { |
|
19 | 19 | |
20 | - return get_option( $this->namespace . '__' . $cache_key, false ); |
|
20 | + return get_option($this->namespace.'__'.$cache_key, false); |
|
21 | 21 | |
22 | 22 | } |
23 | 23 | |
24 | - public function put( $cache_key, $value ) { |
|
24 | + public function put($cache_key, $value) { |
|
25 | 25 | |
26 | - return update_option( $this->namespace . '__' . $cache_key, $value ); |
|
26 | + return update_option($this->namespace.'__'.$cache_key, $value); |
|
27 | 27 | |
28 | 28 | } |
29 | 29 | |
30 | 30 | public function flush_all() { |
31 | - if ( '' !== $this->namespace ) { |
|
31 | + if ('' !== $this->namespace) { |
|
32 | 32 | global $wpdb; |
33 | - $namespace_esc = $wpdb->esc_like( $this->namespace ) . '__%'; |
|
34 | - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc ) ); |
|
33 | + $namespace_esc = $wpdb->esc_like($this->namespace).'__%'; |
|
34 | + $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->options WHERE option_name LIKE %s", $namespace_esc)); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 |
@@ -16,47 +16,47 @@ |
||
16 | 16 | |
17 | 17 | class Term_Link extends Default_Link { |
18 | 18 | |
19 | - /** |
|
20 | - * @var Synonyms_Service |
|
21 | - */ |
|
22 | - private $synonyms_service; |
|
23 | - |
|
24 | - public function __construct() { |
|
25 | - parent::__construct(); |
|
26 | - $this->synonyms_service = Synonyms_Service::get_instance(); |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @throws Exception when the {@link Wordpress_Term_Content_Legacy_Service} throws one, i.e. when passing a non term content id. |
|
31 | - */ |
|
32 | - public function get_same_as_uris( $id ) { |
|
33 | - return array_merge( |
|
34 | - (array) Wordpress_Term_Content_Legacy_Service::get_instance() |
|
35 | - ->get_entity_id( Wordpress_Content_Id::create_term( $id ) ), |
|
36 | - get_term_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
37 | - ); |
|
38 | - } |
|
39 | - |
|
40 | - public function get_id( $uri ) { |
|
41 | - $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
|
42 | - ->get_by_entity_id_or_same_as( $uri ); |
|
43 | - |
|
44 | - if ( ! isset( $content ) ) { |
|
45 | - return false; |
|
46 | - } |
|
47 | - |
|
48 | - return $content->get_bag()->term_id; |
|
49 | - } |
|
50 | - |
|
51 | - public function get_synonyms( $id ) { |
|
52 | - return $this->synonyms_service->get_synonyms( $id ); |
|
53 | - } |
|
54 | - |
|
55 | - public function get_permalink( $id ) { |
|
56 | - return get_term_link( $id ); |
|
57 | - } |
|
58 | - |
|
59 | - public function get_edit_page_link( $id ) { |
|
60 | - return get_edit_term_link( $id ); |
|
61 | - } |
|
19 | + /** |
|
20 | + * @var Synonyms_Service |
|
21 | + */ |
|
22 | + private $synonyms_service; |
|
23 | + |
|
24 | + public function __construct() { |
|
25 | + parent::__construct(); |
|
26 | + $this->synonyms_service = Synonyms_Service::get_instance(); |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @throws Exception when the {@link Wordpress_Term_Content_Legacy_Service} throws one, i.e. when passing a non term content id. |
|
31 | + */ |
|
32 | + public function get_same_as_uris( $id ) { |
|
33 | + return array_merge( |
|
34 | + (array) Wordpress_Term_Content_Legacy_Service::get_instance() |
|
35 | + ->get_entity_id( Wordpress_Content_Id::create_term( $id ) ), |
|
36 | + get_term_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
37 | + ); |
|
38 | + } |
|
39 | + |
|
40 | + public function get_id( $uri ) { |
|
41 | + $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
|
42 | + ->get_by_entity_id_or_same_as( $uri ); |
|
43 | + |
|
44 | + if ( ! isset( $content ) ) { |
|
45 | + return false; |
|
46 | + } |
|
47 | + |
|
48 | + return $content->get_bag()->term_id; |
|
49 | + } |
|
50 | + |
|
51 | + public function get_synonyms( $id ) { |
|
52 | + return $this->synonyms_service->get_synonyms( $id ); |
|
53 | + } |
|
54 | + |
|
55 | + public function get_permalink( $id ) { |
|
56 | + return get_term_link( $id ); |
|
57 | + } |
|
58 | + |
|
59 | + public function get_edit_page_link( $id ) { |
|
60 | + return get_edit_term_link( $id ); |
|
61 | + } |
|
62 | 62 | } |
@@ -29,34 +29,34 @@ |
||
29 | 29 | /** |
30 | 30 | * @throws Exception when the {@link Wordpress_Term_Content_Legacy_Service} throws one, i.e. when passing a non term content id. |
31 | 31 | */ |
32 | - public function get_same_as_uris( $id ) { |
|
32 | + public function get_same_as_uris($id) { |
|
33 | 33 | return array_merge( |
34 | 34 | (array) Wordpress_Term_Content_Legacy_Service::get_instance() |
35 | - ->get_entity_id( Wordpress_Content_Id::create_term( $id ) ), |
|
36 | - get_term_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
35 | + ->get_entity_id(Wordpress_Content_Id::create_term($id)), |
|
36 | + get_term_meta($id, Wordlift_Schema_Service::FIELD_SAME_AS) |
|
37 | 37 | ); |
38 | 38 | } |
39 | 39 | |
40 | - public function get_id( $uri ) { |
|
40 | + public function get_id($uri) { |
|
41 | 41 | $content = Wordpress_Term_Content_Legacy_Service::get_instance() |
42 | - ->get_by_entity_id_or_same_as( $uri ); |
|
42 | + ->get_by_entity_id_or_same_as($uri); |
|
43 | 43 | |
44 | - if ( ! isset( $content ) ) { |
|
44 | + if ( ! isset($content)) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | return $content->get_bag()->term_id; |
49 | 49 | } |
50 | 50 | |
51 | - public function get_synonyms( $id ) { |
|
52 | - return $this->synonyms_service->get_synonyms( $id ); |
|
51 | + public function get_synonyms($id) { |
|
52 | + return $this->synonyms_service->get_synonyms($id); |
|
53 | 53 | } |
54 | 54 | |
55 | - public function get_permalink( $id ) { |
|
56 | - return get_term_link( $id ); |
|
55 | + public function get_permalink($id) { |
|
56 | + return get_term_link($id); |
|
57 | 57 | } |
58 | 58 | |
59 | - public function get_edit_page_link( $id ) { |
|
60 | - return get_edit_term_link( $id ); |
|
59 | + public function get_edit_page_link($id) { |
|
60 | + return get_edit_term_link($id); |
|
61 | 61 | } |
62 | 62 | } |
@@ -9,93 +9,93 @@ |
||
9 | 9 | |
10 | 10 | class Link_Builder { |
11 | 11 | |
12 | - private $id; |
|
13 | - private $type; |
|
14 | - private $label; |
|
15 | - private $href; |
|
16 | - private $entity_url; |
|
17 | - /** |
|
18 | - * @var Object_Link_Provider |
|
19 | - */ |
|
20 | - private $object_link_provider; |
|
21 | - |
|
22 | - public function __construct( $entity_url, $id ) { |
|
23 | - $this->entity_url = $entity_url; |
|
24 | - $this->id = $id; |
|
25 | - $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
26 | - $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
27 | - } |
|
28 | - |
|
29 | - public static function create( $entity_url, $id ) { |
|
30 | - return new Link_Builder( $entity_url, $id ); |
|
31 | - } |
|
32 | - |
|
33 | - public function label( $label ) { |
|
34 | - $this->label = $label; |
|
35 | - |
|
36 | - return $this; |
|
37 | - } |
|
38 | - |
|
39 | - public function href( $href ) { |
|
40 | - $this->href = $href; |
|
41 | - |
|
42 | - return $this; |
|
43 | - } |
|
44 | - |
|
45 | - private function get_attributes_for_link() { |
|
46 | - /** |
|
47 | - * Allow 3rd parties to add additional attributes to the anchor link. |
|
48 | - * |
|
49 | - * @since 3.26.0 |
|
50 | - */ |
|
51 | - $default_attributes = array( |
|
52 | - 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ), |
|
53 | - ); |
|
54 | - |
|
55 | - /** |
|
56 | - * @since 3.32.0 |
|
57 | - * Additional parameter {@link $this->type} is added to the filter denoting the type of |
|
58 | - * the entity url by the enum values {@link Object_Type_Enum} |
|
59 | - */ |
|
60 | - $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
61 | - $attributes_html = ''; |
|
62 | - foreach ( $attributes as $key => $value ) { |
|
63 | - $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
64 | - } |
|
65 | - |
|
66 | - return $attributes_html; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get a `title` attribute with an alternative label for the link. |
|
71 | - * |
|
72 | - * If an alternative title isn't available an empty string is returned. |
|
73 | - * |
|
74 | - * @return string A `title` attribute with an alternative label or an empty |
|
75 | - * string if none available. |
|
76 | - * @since 3.32.0 |
|
77 | - */ |
|
78 | - private function get_title_attribute() { |
|
79 | - |
|
80 | - // Get an alternative title. |
|
81 | - $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
82 | - if ( ! empty( $title ) ) { |
|
83 | - return 'title="' . esc_attr( $title ) . '"'; |
|
84 | - } |
|
85 | - |
|
86 | - return ''; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function generate_link() { |
|
93 | - // Get an alternative title attribute. |
|
94 | - $title_attribute = $this->get_title_attribute(); |
|
95 | - $attributes_html = $this->get_attributes_for_link(); |
|
96 | - |
|
97 | - // Return the link. |
|
98 | - return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>"; |
|
99 | - } |
|
12 | + private $id; |
|
13 | + private $type; |
|
14 | + private $label; |
|
15 | + private $href; |
|
16 | + private $entity_url; |
|
17 | + /** |
|
18 | + * @var Object_Link_Provider |
|
19 | + */ |
|
20 | + private $object_link_provider; |
|
21 | + |
|
22 | + public function __construct( $entity_url, $id ) { |
|
23 | + $this->entity_url = $entity_url; |
|
24 | + $this->id = $id; |
|
25 | + $this->object_link_provider = Object_Link_Provider::get_instance(); |
|
26 | + $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
27 | + } |
|
28 | + |
|
29 | + public static function create( $entity_url, $id ) { |
|
30 | + return new Link_Builder( $entity_url, $id ); |
|
31 | + } |
|
32 | + |
|
33 | + public function label( $label ) { |
|
34 | + $this->label = $label; |
|
35 | + |
|
36 | + return $this; |
|
37 | + } |
|
38 | + |
|
39 | + public function href( $href ) { |
|
40 | + $this->href = $href; |
|
41 | + |
|
42 | + return $this; |
|
43 | + } |
|
44 | + |
|
45 | + private function get_attributes_for_link() { |
|
46 | + /** |
|
47 | + * Allow 3rd parties to add additional attributes to the anchor link. |
|
48 | + * |
|
49 | + * @since 3.26.0 |
|
50 | + */ |
|
51 | + $default_attributes = array( |
|
52 | + 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ), |
|
53 | + ); |
|
54 | + |
|
55 | + /** |
|
56 | + * @since 3.32.0 |
|
57 | + * Additional parameter {@link $this->type} is added to the filter denoting the type of |
|
58 | + * the entity url by the enum values {@link Object_Type_Enum} |
|
59 | + */ |
|
60 | + $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
61 | + $attributes_html = ''; |
|
62 | + foreach ( $attributes as $key => $value ) { |
|
63 | + $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
64 | + } |
|
65 | + |
|
66 | + return $attributes_html; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get a `title` attribute with an alternative label for the link. |
|
71 | + * |
|
72 | + * If an alternative title isn't available an empty string is returned. |
|
73 | + * |
|
74 | + * @return string A `title` attribute with an alternative label or an empty |
|
75 | + * string if none available. |
|
76 | + * @since 3.32.0 |
|
77 | + */ |
|
78 | + private function get_title_attribute() { |
|
79 | + |
|
80 | + // Get an alternative title. |
|
81 | + $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
82 | + if ( ! empty( $title ) ) { |
|
83 | + return 'title="' . esc_attr( $title ) . '"'; |
|
84 | + } |
|
85 | + |
|
86 | + return ''; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function generate_link() { |
|
93 | + // Get an alternative title attribute. |
|
94 | + $title_attribute = $this->get_title_attribute(); |
|
95 | + $attributes_html = $this->get_attributes_for_link(); |
|
96 | + |
|
97 | + // Return the link. |
|
98 | + return "<a class=\"wl-entity-page-link\" $title_attribute href=\"{$this->href}\"$attributes_html>{$this->label}</a>"; |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -19,24 +19,24 @@ discard block |
||
19 | 19 | */ |
20 | 20 | private $object_link_provider; |
21 | 21 | |
22 | - public function __construct( $entity_url, $id ) { |
|
22 | + public function __construct($entity_url, $id) { |
|
23 | 23 | $this->entity_url = $entity_url; |
24 | 24 | $this->id = $id; |
25 | 25 | $this->object_link_provider = Object_Link_Provider::get_instance(); |
26 | - $this->type = $this->object_link_provider->get_object_type( $entity_url ); |
|
26 | + $this->type = $this->object_link_provider->get_object_type($entity_url); |
|
27 | 27 | } |
28 | 28 | |
29 | - public static function create( $entity_url, $id ) { |
|
30 | - return new Link_Builder( $entity_url, $id ); |
|
29 | + public static function create($entity_url, $id) { |
|
30 | + return new Link_Builder($entity_url, $id); |
|
31 | 31 | } |
32 | 32 | |
33 | - public function label( $label ) { |
|
33 | + public function label($label) { |
|
34 | 34 | $this->label = $label; |
35 | 35 | |
36 | 36 | return $this; |
37 | 37 | } |
38 | 38 | |
39 | - public function href( $href ) { |
|
39 | + public function href($href) { |
|
40 | 40 | $this->href = $href; |
41 | 41 | |
42 | 42 | return $this; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @since 3.26.0 |
50 | 50 | */ |
51 | 51 | $default_attributes = array( |
52 | - 'id' => implode( ';', $this->object_link_provider->get_same_as_uris( $this->id, $this->type ) ), |
|
52 | + 'id' => implode(';', $this->object_link_provider->get_same_as_uris($this->id, $this->type)), |
|
53 | 53 | ); |
54 | 54 | |
55 | 55 | /** |
@@ -57,10 +57,10 @@ discard block |
||
57 | 57 | * Additional parameter {@link $this->type} is added to the filter denoting the type of |
58 | 58 | * the entity url by the enum values {@link Object_Type_Enum} |
59 | 59 | */ |
60 | - $attributes = apply_filters( 'wl_anchor_data_attributes', $default_attributes, $this->id, $this->type ); |
|
60 | + $attributes = apply_filters('wl_anchor_data_attributes', $default_attributes, $this->id, $this->type); |
|
61 | 61 | $attributes_html = ''; |
62 | - foreach ( $attributes as $key => $value ) { |
|
63 | - $attributes_html .= ' data-' . esc_html( $key ) . '="' . esc_attr( $value ) . '" '; |
|
62 | + foreach ($attributes as $key => $value) { |
|
63 | + $attributes_html .= ' data-'.esc_html($key).'="'.esc_attr($value).'" '; |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | return $attributes_html; |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | private function get_title_attribute() { |
79 | 79 | |
80 | 80 | // Get an alternative title. |
81 | - $title = $this->object_link_provider->get_link_title( $this->id, $this->label, $this->type ); |
|
82 | - if ( ! empty( $title ) ) { |
|
83 | - return 'title="' . esc_attr( $title ) . '"'; |
|
81 | + $title = $this->object_link_provider->get_link_title($this->id, $this->label, $this->type); |
|
82 | + if ( ! empty($title)) { |
|
83 | + return 'title="'.esc_attr($title).'"'; |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return ''; |
@@ -9,22 +9,22 @@ |
||
9 | 9 | |
10 | 10 | interface Link { |
11 | 11 | |
12 | - public function get_link_title( $id, $label_to_be_ignored ); |
|
12 | + public function get_link_title( $id, $label_to_be_ignored ); |
|
13 | 13 | |
14 | - public function get_same_as_uris( $id ); |
|
14 | + public function get_same_as_uris( $id ); |
|
15 | 15 | |
16 | - public function get_id( $uri ); |
|
16 | + public function get_id( $uri ); |
|
17 | 17 | |
18 | - public function get_synonyms( $id ); |
|
18 | + public function get_synonyms( $id ); |
|
19 | 19 | |
20 | - public function get_permalink( $id ); |
|
20 | + public function get_permalink( $id ); |
|
21 | 21 | |
22 | - /** |
|
23 | - * Return the edit page link. |
|
24 | - * |
|
25 | - * @param $id |
|
26 | - * |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function get_edit_page_link( $id ); |
|
22 | + /** |
|
23 | + * Return the edit page link. |
|
24 | + * |
|
25 | + * @param $id |
|
26 | + * |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function get_edit_page_link( $id ); |
|
30 | 30 | } |
@@ -9,15 +9,15 @@ discard block |
||
9 | 9 | |
10 | 10 | interface Link { |
11 | 11 | |
12 | - public function get_link_title( $id, $label_to_be_ignored ); |
|
12 | + public function get_link_title($id, $label_to_be_ignored); |
|
13 | 13 | |
14 | - public function get_same_as_uris( $id ); |
|
14 | + public function get_same_as_uris($id); |
|
15 | 15 | |
16 | - public function get_id( $uri ); |
|
16 | + public function get_id($uri); |
|
17 | 17 | |
18 | - public function get_synonyms( $id ); |
|
18 | + public function get_synonyms($id); |
|
19 | 19 | |
20 | - public function get_permalink( $id ); |
|
20 | + public function get_permalink($id); |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * Return the edit page link. |
@@ -26,5 +26,5 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @return string |
28 | 28 | */ |
29 | - public function get_edit_page_link( $id ); |
|
29 | + public function get_edit_page_link($id); |
|
30 | 30 | } |
@@ -11,19 +11,19 @@ |
||
11 | 11 | |
12 | 12 | abstract class Default_Link extends Singleton implements Link { |
13 | 13 | |
14 | - public function get_link_title( $id, $label_to_be_ignored ) { |
|
14 | + public function get_link_title( $id, $label_to_be_ignored ) { |
|
15 | 15 | |
16 | - $entity_labels = $this->get_synonyms( $id ); |
|
16 | + $entity_labels = $this->get_synonyms( $id ); |
|
17 | 17 | |
18 | - foreach ( $entity_labels as $entity_label ) { |
|
19 | - // Return first synonym if it doesnt match the label. |
|
20 | - if ( 0 !== strcasecmp( $entity_label, $label_to_be_ignored ) ) { |
|
21 | - return $entity_label; |
|
22 | - } |
|
23 | - } |
|
18 | + foreach ( $entity_labels as $entity_label ) { |
|
19 | + // Return first synonym if it doesnt match the label. |
|
20 | + if ( 0 !== strcasecmp( $entity_label, $label_to_be_ignored ) ) { |
|
21 | + return $entity_label; |
|
22 | + } |
|
23 | + } |
|
24 | 24 | |
25 | - // If the label matches the synonym then dont add title attr. |
|
26 | - return ''; |
|
27 | - } |
|
25 | + // If the label matches the synonym then dont add title attr. |
|
26 | + return ''; |
|
27 | + } |
|
28 | 28 | |
29 | 29 | } |
@@ -11,13 +11,13 @@ |
||
11 | 11 | |
12 | 12 | abstract class Default_Link extends Singleton implements Link { |
13 | 13 | |
14 | - public function get_link_title( $id, $label_to_be_ignored ) { |
|
14 | + public function get_link_title($id, $label_to_be_ignored) { |
|
15 | 15 | |
16 | - $entity_labels = $this->get_synonyms( $id ); |
|
16 | + $entity_labels = $this->get_synonyms($id); |
|
17 | 17 | |
18 | - foreach ( $entity_labels as $entity_label ) { |
|
18 | + foreach ($entity_labels as $entity_label) { |
|
19 | 19 | // Return first synonym if it doesnt match the label. |
20 | - if ( 0 !== strcasecmp( $entity_label, $label_to_be_ignored ) ) { |
|
20 | + if (0 !== strcasecmp($entity_label, $label_to_be_ignored)) { |
|
21 | 21 | return $entity_label; |
22 | 22 | } |
23 | 23 | } |
@@ -13,57 +13,57 @@ |
||
13 | 13 | |
14 | 14 | class Post_Link extends Default_Link { |
15 | 15 | |
16 | - /** |
|
17 | - * @var \Wordlift_Entity_Service |
|
18 | - */ |
|
19 | - private $entity_service; |
|
16 | + /** |
|
17 | + * @var \Wordlift_Entity_Service |
|
18 | + */ |
|
19 | + private $entity_service; |
|
20 | 20 | |
21 | - public function __construct() { |
|
22 | - parent::__construct(); |
|
23 | - $this->entity_service = Wordlift_Entity_Service::get_instance(); |
|
24 | - } |
|
21 | + public function __construct() { |
|
22 | + parent::__construct(); |
|
23 | + $this->entity_service = Wordlift_Entity_Service::get_instance(); |
|
24 | + } |
|
25 | 25 | |
26 | - public function get_same_as_uris( $id ) { |
|
26 | + public function get_same_as_uris( $id ) { |
|
27 | 27 | |
28 | - return array_merge( |
|
29 | - array( $this->entity_service->get_uri( $id ) ), |
|
30 | - get_post_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
31 | - ); |
|
28 | + return array_merge( |
|
29 | + array( $this->entity_service->get_uri( $id ) ), |
|
30 | + get_post_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
31 | + ); |
|
32 | 32 | |
33 | - } |
|
33 | + } |
|
34 | 34 | |
35 | - public function get_id( $uri ) { |
|
36 | - $content = Wordpress_Content_Service::get_instance() |
|
37 | - ->get_by_entity_id_or_same_as( $uri ); |
|
35 | + public function get_id( $uri ) { |
|
36 | + $content = Wordpress_Content_Service::get_instance() |
|
37 | + ->get_by_entity_id_or_same_as( $uri ); |
|
38 | 38 | |
39 | - if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
40 | - return false; |
|
41 | - } |
|
39 | + if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
40 | + return false; |
|
41 | + } |
|
42 | 42 | |
43 | - return $content->get_bag()->ID; |
|
44 | - } |
|
43 | + return $content->get_bag()->ID; |
|
44 | + } |
|
45 | 45 | |
46 | - public function get_synonyms( $id ) { |
|
47 | - // Get possible alternative entity_labels we can select from. |
|
48 | - $entity_labels = $this->entity_service->get_alternative_labels( $id ); |
|
46 | + public function get_synonyms( $id ) { |
|
47 | + // Get possible alternative entity_labels we can select from. |
|
48 | + $entity_labels = $this->entity_service->get_alternative_labels( $id ); |
|
49 | 49 | |
50 | - /* |
|
50 | + /* |
|
51 | 51 | * Since the original text might use an alternative entity_label than the |
52 | 52 | * Entity title, add the title itself which is not returned by the api. |
53 | 53 | */ |
54 | - $entity_labels[] = get_the_title( $id ); |
|
54 | + $entity_labels[] = get_the_title( $id ); |
|
55 | 55 | |
56 | - // Add some randomness to the entity_label selection. |
|
57 | - shuffle( $entity_labels ); |
|
56 | + // Add some randomness to the entity_label selection. |
|
57 | + shuffle( $entity_labels ); |
|
58 | 58 | |
59 | - return $entity_labels; |
|
60 | - } |
|
59 | + return $entity_labels; |
|
60 | + } |
|
61 | 61 | |
62 | - public function get_permalink( $id ) { |
|
63 | - return get_permalink( $id ); |
|
64 | - } |
|
62 | + public function get_permalink( $id ) { |
|
63 | + return get_permalink( $id ); |
|
64 | + } |
|
65 | 65 | |
66 | - public function get_edit_page_link( $id ) { |
|
67 | - return get_edit_post_link( $id, 'none' ); |
|
68 | - } |
|
66 | + public function get_edit_page_link( $id ) { |
|
67 | + return get_edit_post_link( $id, 'none' ); |
|
68 | + } |
|
69 | 69 | } |
@@ -23,47 +23,47 @@ |
||
23 | 23 | $this->entity_service = Wordlift_Entity_Service::get_instance(); |
24 | 24 | } |
25 | 25 | |
26 | - public function get_same_as_uris( $id ) { |
|
26 | + public function get_same_as_uris($id) { |
|
27 | 27 | |
28 | 28 | return array_merge( |
29 | - array( $this->entity_service->get_uri( $id ) ), |
|
30 | - get_post_meta( $id, Wordlift_Schema_Service::FIELD_SAME_AS ) |
|
29 | + array($this->entity_service->get_uri($id)), |
|
30 | + get_post_meta($id, Wordlift_Schema_Service::FIELD_SAME_AS) |
|
31 | 31 | ); |
32 | 32 | |
33 | 33 | } |
34 | 34 | |
35 | - public function get_id( $uri ) { |
|
35 | + public function get_id($uri) { |
|
36 | 36 | $content = Wordpress_Content_Service::get_instance() |
37 | - ->get_by_entity_id_or_same_as( $uri ); |
|
37 | + ->get_by_entity_id_or_same_as($uri); |
|
38 | 38 | |
39 | - if ( ! isset( $content ) || ! is_a( $content->get_bag(), '\WP_Post' ) ) { |
|
39 | + if ( ! isset($content) || ! is_a($content->get_bag(), '\WP_Post')) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | return $content->get_bag()->ID; |
44 | 44 | } |
45 | 45 | |
46 | - public function get_synonyms( $id ) { |
|
46 | + public function get_synonyms($id) { |
|
47 | 47 | // Get possible alternative entity_labels we can select from. |
48 | - $entity_labels = $this->entity_service->get_alternative_labels( $id ); |
|
48 | + $entity_labels = $this->entity_service->get_alternative_labels($id); |
|
49 | 49 | |
50 | 50 | /* |
51 | 51 | * Since the original text might use an alternative entity_label than the |
52 | 52 | * Entity title, add the title itself which is not returned by the api. |
53 | 53 | */ |
54 | - $entity_labels[] = get_the_title( $id ); |
|
54 | + $entity_labels[] = get_the_title($id); |
|
55 | 55 | |
56 | 56 | // Add some randomness to the entity_label selection. |
57 | - shuffle( $entity_labels ); |
|
57 | + shuffle($entity_labels); |
|
58 | 58 | |
59 | 59 | return $entity_labels; |
60 | 60 | } |
61 | 61 | |
62 | - public function get_permalink( $id ) { |
|
63 | - return get_permalink( $id ); |
|
62 | + public function get_permalink($id) { |
|
63 | + return get_permalink($id); |
|
64 | 64 | } |
65 | 65 | |
66 | - public function get_edit_page_link( $id ) { |
|
67 | - return get_edit_post_link( $id, 'none' ); |
|
66 | + public function get_edit_page_link($id) { |
|
67 | + return get_edit_post_link($id, 'none'); |
|
68 | 68 | } |
69 | 69 | } |