@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | // If this file is called directly, abort. |
34 | 34 | if ( ! defined( 'WPINC' ) ) { |
35 | - die; |
|
35 | + die; |
|
36 | 36 | } |
37 | 37 | define( |
38 | - 'WORDLIFT_PLUGIN_FILE', |
|
39 | - __FILE__ |
|
38 | + 'WORDLIFT_PLUGIN_FILE', |
|
39 | + __FILE__ |
|
40 | 40 | ); |
41 | 41 | define( 'WORDLIFT_VERSION', '3.41.0-dev' ); |
42 | 42 | |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @since 3.33.6 |
51 | 51 | */ |
52 | 52 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
53 | - return; |
|
53 | + return; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -79,33 +79,33 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function activate_wordlift() { |
81 | 81 | |
82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
82 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
83 | 83 | |
84 | - $log->info( 'Activating WordLift...' ); |
|
84 | + $log->info( 'Activating WordLift...' ); |
|
85 | 85 | |
86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
87 | - Wordlift_Activator::activate(); |
|
86 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
87 | + Wordlift_Activator::activate(); |
|
88 | 88 | |
89 | - /** |
|
90 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
91 | - * |
|
92 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
93 | - * @since 3.19.2 |
|
94 | - */ |
|
95 | - Wordlift_Http_Api::activate(); |
|
96 | - |
|
97 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
98 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
99 | - flush_rewrite_rules(); |
|
100 | - /** |
|
101 | - * @since 3.27.7 |
|
102 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
103 | - */ |
|
104 | - Top_Entities::activate(); |
|
89 | + /** |
|
90 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
91 | + * |
|
92 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
93 | + * @since 3.19.2 |
|
94 | + */ |
|
95 | + Wordlift_Http_Api::activate(); |
|
96 | + |
|
97 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
98 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
99 | + flush_rewrite_rules(); |
|
100 | + /** |
|
101 | + * @since 3.27.7 |
|
102 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
103 | + */ |
|
104 | + Top_Entities::activate(); |
|
105 | 105 | |
106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
108 | - } |
|
106 | + if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | + wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | |
@@ -115,23 +115,23 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function deactivate_wordlift() { |
117 | 117 | |
118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
119 | - Wordlift_Deactivator::deactivate(); |
|
120 | - Wordlift_Http_Api::deactivate(); |
|
121 | - Ttl_Cache_Cleaner::deactivate(); |
|
122 | - /** |
|
123 | - * @since 3.27.7 |
|
124 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
125 | - */ |
|
126 | - Top_Entities::deactivate(); |
|
127 | - /** |
|
128 | - * @since 3.27.8 |
|
129 | - * Remove notification flag on deactivation. |
|
130 | - */ |
|
131 | - Key_Validation_Notice::remove_notification_flag(); |
|
132 | - flush_rewrite_rules(); |
|
133 | - |
|
134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
118 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
119 | + Wordlift_Deactivator::deactivate(); |
|
120 | + Wordlift_Http_Api::deactivate(); |
|
121 | + Ttl_Cache_Cleaner::deactivate(); |
|
122 | + /** |
|
123 | + * @since 3.27.7 |
|
124 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
125 | + */ |
|
126 | + Top_Entities::deactivate(); |
|
127 | + /** |
|
128 | + * @since 3.27.8 |
|
129 | + * Remove notification flag on deactivation. |
|
130 | + */ |
|
131 | + Key_Validation_Notice::remove_notification_flag(); |
|
132 | + flush_rewrite_rules(); |
|
133 | + |
|
134 | + wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | |
@@ -154,84 +154,84 @@ discard block |
||
154 | 154 | * @since 1.0.0 |
155 | 155 | */ |
156 | 156 | function run_wordlift() { |
157 | - /** |
|
158 | - * Filter: wl_feature__enable__widgets. |
|
159 | - * |
|
160 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - * @since 3.27.6 |
|
164 | - */ |
|
165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
169 | - } |
|
170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
171 | - |
|
172 | - /** |
|
173 | - * Filter: wl_feature__enable__analysis |
|
174 | - * |
|
175 | - * @param bool Whether to send api request to analysis or not |
|
176 | - * |
|
177 | - * @return bool |
|
178 | - * @since 3.27.6 |
|
179 | - */ |
|
180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
182 | - } else { |
|
183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
184 | - } |
|
185 | - |
|
186 | - $plugin = new Wordlift(); |
|
187 | - $plugin->run(); |
|
188 | - |
|
189 | - // Initialize the TTL Cache Cleaner. |
|
190 | - new Ttl_Cache_Cleaner(); |
|
191 | - |
|
192 | - // Load the new Post Adapter. |
|
193 | - new Post_Adapter(); |
|
194 | - |
|
195 | - // Load the API Data Hooks. |
|
196 | - new Api_Data_Hooks(); |
|
197 | - |
|
198 | - add_action( |
|
199 | - 'plugins_loaded', |
|
200 | - function () { |
|
201 | - // All features from registry should be initialized here. |
|
202 | - $features_registry = Features_Registry::get_instance(); |
|
203 | - $features_registry->initialize_all_features(); |
|
204 | - }, |
|
205 | - 5 |
|
206 | - ); |
|
207 | - |
|
208 | - add_action( |
|
209 | - 'plugins_loaded', |
|
210 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | - function () use ( $plugin ) { |
|
212 | - |
|
213 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
214 | - |
|
215 | - // Register the Dataset module, requires `$api_service`. |
|
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
218 | - |
|
219 | - /* |
|
157 | + /** |
|
158 | + * Filter: wl_feature__enable__widgets. |
|
159 | + * |
|
160 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + * @since 3.27.6 |
|
164 | + */ |
|
165 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
169 | + } |
|
170 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
171 | + |
|
172 | + /** |
|
173 | + * Filter: wl_feature__enable__analysis |
|
174 | + * |
|
175 | + * @param bool Whether to send api request to analysis or not |
|
176 | + * |
|
177 | + * @return bool |
|
178 | + * @since 3.27.6 |
|
179 | + */ |
|
180 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
182 | + } else { |
|
183 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
184 | + } |
|
185 | + |
|
186 | + $plugin = new Wordlift(); |
|
187 | + $plugin->run(); |
|
188 | + |
|
189 | + // Initialize the TTL Cache Cleaner. |
|
190 | + new Ttl_Cache_Cleaner(); |
|
191 | + |
|
192 | + // Load the new Post Adapter. |
|
193 | + new Post_Adapter(); |
|
194 | + |
|
195 | + // Load the API Data Hooks. |
|
196 | + new Api_Data_Hooks(); |
|
197 | + |
|
198 | + add_action( |
|
199 | + 'plugins_loaded', |
|
200 | + function () { |
|
201 | + // All features from registry should be initialized here. |
|
202 | + $features_registry = Features_Registry::get_instance(); |
|
203 | + $features_registry->initialize_all_features(); |
|
204 | + }, |
|
205 | + 5 |
|
206 | + ); |
|
207 | + |
|
208 | + add_action( |
|
209 | + 'plugins_loaded', |
|
210 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
211 | + function () use ( $plugin ) { |
|
212 | + |
|
213 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
214 | + |
|
215 | + // Register the Dataset module, requires `$api_service`. |
|
216 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
218 | + |
|
219 | + /* |
|
220 | 220 | * Require the Entity annotation cleanup module. |
221 | 221 | * |
222 | 222 | * @since 3.34.6 |
223 | 223 | */ |
224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
224 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
225 | 225 | |
226 | - /* |
|
226 | + /* |
|
227 | 227 | * Import LOD entities. |
228 | 228 | * |
229 | 229 | * @since 3.35.0 |
230 | 230 | */ |
231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
231 | + require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
232 | 232 | |
233 | - } |
|
234 | - ); |
|
233 | + } |
|
234 | + ); |
|
235 | 235 | |
236 | 236 | } |
237 | 237 | |
@@ -245,45 +245,45 @@ discard block |
||
245 | 245 | */ |
246 | 246 | function wordlift_plugin_autoload_register() { |
247 | 247 | |
248 | - spl_autoload_register( |
|
249 | - function ( $class_name ) { |
|
248 | + spl_autoload_register( |
|
249 | + function ( $class_name ) { |
|
250 | 250 | |
251 | - // Bail out if these are not our classes. |
|
252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
253 | - return false; |
|
254 | - } |
|
251 | + // Bail out if these are not our classes. |
|
252 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
253 | + return false; |
|
254 | + } |
|
255 | 255 | |
256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
256 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
257 | 257 | |
258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
258 | + preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
259 | 259 | |
260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | - $file = 'class-' . $matches[2] . '.php'; |
|
260 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | + $file = 'class-' . $matches[2] . '.php'; |
|
262 | 262 | |
263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
263 | + $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
264 | 264 | |
265 | - if ( ! file_exists( $full_path ) ) { |
|
266 | - return false; |
|
267 | - } |
|
265 | + if ( ! file_exists( $full_path ) ) { |
|
266 | + return false; |
|
267 | + } |
|
268 | 268 | |
269 | - require_once $full_path; |
|
269 | + require_once $full_path; |
|
270 | 270 | |
271 | - return true; |
|
272 | - } |
|
273 | - ); |
|
271 | + return true; |
|
272 | + } |
|
273 | + ); |
|
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | 277 | function wl_block_categories( $categories ) { |
278 | - return array_merge( |
|
279 | - $categories, |
|
280 | - array( |
|
281 | - array( |
|
282 | - 'slug' => 'wordlift', |
|
283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
284 | - ), |
|
285 | - ) |
|
286 | - ); |
|
278 | + return array_merge( |
|
279 | + $categories, |
|
280 | + array( |
|
281 | + array( |
|
282 | + 'slug' => 'wordlift', |
|
283 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
284 | + ), |
|
285 | + ) |
|
286 | + ); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -291,19 +291,19 @@ discard block |
||
291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
292 | 292 | */ |
293 | 293 | function wl_enqueue_leaflet( $in_footer = false ) { |
294 | - // Leaflet. |
|
295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
294 | + // Leaflet. |
|
295 | + wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | + wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | add_filter( 'block_categories', 'wl_block_categories', 10 ); |
300 | 300 | |
301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
302 | 302 | add_filter( |
303 | - 'wl_feature__enable__dataset', |
|
304 | - function ( $value ) { |
|
305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | - } |
|
303 | + 'wl_feature__enable__dataset', |
|
304 | + function ( $value ) { |
|
305 | + return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | + } |
|
307 | 307 | ); |
308 | 308 | |
309 | 309 | require_once __DIR__ . '/modules/food-kg/load.php'; |
@@ -312,26 +312,26 @@ discard block |
||
312 | 312 | require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
313 | 313 | |
314 | 314 | add_action( |
315 | - 'update_plugins_adthrive.wordlift.io', |
|
316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
317 | - // Bail out if it's not our plugin. |
|
318 | - $update_uri = $plugin_data['UpdateURI']; |
|
319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
320 | - return $update; |
|
321 | - } |
|
322 | - |
|
323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
324 | - |
|
325 | - if ( is_wp_error( $response ) ) { |
|
326 | - return $update; |
|
327 | - } |
|
328 | - |
|
329 | - try { |
|
330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | - } catch ( Exception $e ) { |
|
332 | - return $update; |
|
333 | - } |
|
334 | - }, |
|
335 | - 10, |
|
336 | - 3 |
|
315 | + 'update_plugins_adthrive.wordlift.io', |
|
316 | + function ( $update, $plugin_data, $plugin_file ) { |
|
317 | + // Bail out if it's not our plugin. |
|
318 | + $update_uri = $plugin_data['UpdateURI']; |
|
319 | + if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
320 | + return $update; |
|
321 | + } |
|
322 | + |
|
323 | + $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
324 | + |
|
325 | + if ( is_wp_error( $response ) ) { |
|
326 | + return $update; |
|
327 | + } |
|
328 | + |
|
329 | + try { |
|
330 | + return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | + } catch ( Exception $e ) { |
|
332 | + return $update; |
|
333 | + } |
|
334 | + }, |
|
335 | + 10, |
|
336 | + 3 |
|
337 | 337 | ); |
@@ -31,29 +31,29 @@ discard block |
||
31 | 31 | use Wordlift\Features\Features_Registry; |
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | // If this file is called directly, abort. |
34 | -if ( ! defined( 'WPINC' ) ) { |
|
34 | +if ( ! defined('WPINC')) { |
|
35 | 35 | die; |
36 | 36 | } |
37 | 37 | define( |
38 | 38 | 'WORDLIFT_PLUGIN_FILE', |
39 | 39 | __FILE__ |
40 | 40 | ); |
41 | -define( 'WORDLIFT_VERSION', '3.41.0-dev' ); |
|
41 | +define('WORDLIFT_VERSION', '3.41.0-dev'); |
|
42 | 42 | |
43 | -require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php'; |
|
44 | -require_once __DIR__ . '/modules/common/load.php'; |
|
45 | -require_once __DIR__ . '/modules/include-exclude/load.php'; |
|
43 | +require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php'; |
|
44 | +require_once __DIR__.'/modules/common/load.php'; |
|
45 | +require_once __DIR__.'/modules/include-exclude/load.php'; |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Filter to disable WLP on any request, defaults to true. |
49 | 49 | * |
50 | 50 | * @since 3.33.6 |
51 | 51 | */ |
52 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
52 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
56 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
56 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
57 | 57 | |
58 | 58 | /* |
59 | 59 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
@@ -63,15 +63,15 @@ discard block |
||
63 | 63 | wordlift_plugin_autoload_register(); |
64 | 64 | |
65 | 65 | // Include WordLift constants. |
66 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php'; |
|
66 | +require_once plugin_dir_path(__FILE__).'wordlift-constants.php'; |
|
67 | 67 | |
68 | 68 | // Load modules. |
69 | -require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php'; |
|
69 | +require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php'; |
|
70 | 70 | |
71 | -require_once plugin_dir_path( __FILE__ ) . 'deprecations.php'; |
|
71 | +require_once plugin_dir_path(__FILE__).'deprecations.php'; |
|
72 | 72 | |
73 | 73 | // Load early to enable/disable features. |
74 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php'; |
|
74 | +require_once plugin_dir_path(__FILE__).'wordlift/features/index.php'; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * The code that runs during plugin activation. |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | */ |
80 | 80 | function activate_wordlift() { |
81 | 81 | |
82 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
82 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
83 | 83 | |
84 | - $log->info( 'Activating WordLift...' ); |
|
84 | + $log->info('Activating WordLift...'); |
|
85 | 85 | |
86 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
86 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
87 | 87 | Wordlift_Activator::activate(); |
88 | 88 | |
89 | 89 | /** |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | */ |
104 | 104 | Top_Entities::activate(); |
105 | 105 | |
106 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
107 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
106 | + if ( ! wp_next_scheduled('wl_daily_cron')) { |
|
107 | + wp_schedule_event(time(), 'daily', 'wl_daily_cron'); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | function deactivate_wordlift() { |
117 | 117 | |
118 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
118 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
119 | 119 | Wordlift_Deactivator::deactivate(); |
120 | 120 | Wordlift_Http_Api::deactivate(); |
121 | 121 | Ttl_Cache_Cleaner::deactivate(); |
@@ -131,18 +131,18 @@ discard block |
||
131 | 131 | Key_Validation_Notice::remove_notification_flag(); |
132 | 132 | flush_rewrite_rules(); |
133 | 133 | |
134 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
134 | + wp_clear_scheduled_hook('wl_daily_cron'); |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | |
138 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
139 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
138 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
139 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
140 | 140 | |
141 | 141 | /** |
142 | 142 | * The core plugin class that is used to define internationalization, |
143 | 143 | * admin-specific hooks, and public-facing site hooks. |
144 | 144 | */ |
145 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
145 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
146 | 146 | |
147 | 147 | /** |
148 | 148 | * Begins execution of the plugin. |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | * @return bool |
163 | 163 | * @since 3.27.6 |
164 | 164 | */ |
165 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
166 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
167 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
168 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
165 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
166 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
167 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
168 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
169 | 169 | } |
170 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
170 | + add_filter('widget_text', 'do_shortcode'); |
|
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Filter: wl_feature__enable__analysis |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | * @return bool |
178 | 178 | * @since 3.27.6 |
179 | 179 | */ |
180 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
181 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
180 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
181 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
182 | 182 | } else { |
183 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
183 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | $plugin = new Wordlift(); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | |
198 | 198 | add_action( |
199 | 199 | 'plugins_loaded', |
200 | - function () { |
|
200 | + function() { |
|
201 | 201 | // All features from registry should be initialized here. |
202 | 202 | $features_registry = Features_Registry::get_instance(); |
203 | 203 | $features_registry->initialize_all_features(); |
@@ -208,27 +208,27 @@ discard block |
||
208 | 208 | add_action( |
209 | 209 | 'plugins_loaded', |
210 | 210 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
211 | - function () use ( $plugin ) { |
|
211 | + function() use ($plugin) { |
|
212 | 212 | |
213 | 213 | new Wordlift_Products_Navigator_Shortcode_REST(); |
214 | 214 | |
215 | 215 | // Register the Dataset module, requires `$api_service`. |
216 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php'; |
|
217 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php'; |
|
216 | + require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php'; |
|
217 | + require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php'; |
|
218 | 218 | |
219 | 219 | /* |
220 | 220 | * Require the Entity annotation cleanup module. |
221 | 221 | * |
222 | 222 | * @since 3.34.6 |
223 | 223 | */ |
224 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php'; |
|
224 | + require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php'; |
|
225 | 225 | |
226 | 226 | /* |
227 | 227 | * Import LOD entities. |
228 | 228 | * |
229 | 229 | * @since 3.35.0 |
230 | 230 | */ |
231 | - require_once plugin_dir_path( __FILE__ ) . 'wordlift/lod-import/index.php'; |
|
231 | + require_once plugin_dir_path(__FILE__).'wordlift/lod-import/index.php'; |
|
232 | 232 | |
233 | 233 | } |
234 | 234 | ); |
@@ -246,23 +246,23 @@ discard block |
||
246 | 246 | function wordlift_plugin_autoload_register() { |
247 | 247 | |
248 | 248 | spl_autoload_register( |
249 | - function ( $class_name ) { |
|
249 | + function($class_name) { |
|
250 | 250 | |
251 | 251 | // Bail out if these are not our classes. |
252 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
252 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
253 | 253 | return false; |
254 | 254 | } |
255 | 255 | |
256 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
256 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
257 | 257 | |
258 | - preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
258 | + preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
259 | 259 | |
260 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
261 | - $file = 'class-' . $matches[2] . '.php'; |
|
260 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
261 | + $file = 'class-'.$matches[2].'.php'; |
|
262 | 262 | |
263 | - $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file; |
|
263 | + $full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file; |
|
264 | 264 | |
265 | - if ( ! file_exists( $full_path ) ) { |
|
265 | + if ( ! file_exists($full_path)) { |
|
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | |
275 | 275 | } |
276 | 276 | |
277 | -function wl_block_categories( $categories ) { |
|
277 | +function wl_block_categories($categories) { |
|
278 | 278 | return array_merge( |
279 | 279 | $categories, |
280 | 280 | array( |
281 | 281 | array( |
282 | 282 | 'slug' => 'wordlift', |
283 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
283 | + 'title' => __('WordLift', 'wordlift'), |
|
284 | 284 | ), |
285 | 285 | ) |
286 | 286 | ); |
@@ -290,45 +290,45 @@ discard block |
||
290 | 290 | * This function is created temporarily to handle the legacy library, |
291 | 291 | * this has to be removed when removing the legacy fields from the ui. |
292 | 292 | */ |
293 | -function wl_enqueue_leaflet( $in_footer = false ) { |
|
293 | +function wl_enqueue_leaflet($in_footer = false) { |
|
294 | 294 | // Leaflet. |
295 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
296 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
295 | + wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0'); |
|
296 | + wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer); |
|
297 | 297 | } |
298 | 298 | |
299 | -add_filter( 'block_categories', 'wl_block_categories', 10 ); |
|
299 | +add_filter('block_categories', 'wl_block_categories', 10); |
|
300 | 300 | |
301 | 301 | // Temporary fix for a typo in WooCommerce Extension. |
302 | 302 | add_filter( |
303 | 303 | 'wl_feature__enable__dataset', |
304 | - function ( $value ) { |
|
305 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
304 | + function($value) { |
|
305 | + return apply_filters('wl_features__enable__dataset', $value); |
|
306 | 306 | } |
307 | 307 | ); |
308 | 308 | |
309 | -require_once __DIR__ . '/modules/food-kg/load.php'; |
|
310 | -require_once __DIR__ . '/modules/acf4so/load.php'; |
|
311 | -require_once __DIR__ . '/modules/pods/load.php'; |
|
312 | -require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
|
309 | +require_once __DIR__.'/modules/food-kg/load.php'; |
|
310 | +require_once __DIR__.'/modules/acf4so/load.php'; |
|
311 | +require_once __DIR__.'/modules/pods/load.php'; |
|
312 | +require_once __DIR__.'/modules/include-exclude-push-config/load.php'; |
|
313 | 313 | |
314 | 314 | add_action( |
315 | 315 | 'update_plugins_adthrive.wordlift.io', |
316 | - function ( $update, $plugin_data, $plugin_file ) { |
|
316 | + function($update, $plugin_data, $plugin_file) { |
|
317 | 317 | // Bail out if it's not our plugin. |
318 | 318 | $update_uri = $plugin_data['UpdateURI']; |
319 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
319 | + if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) { |
|
320 | 320 | return $update; |
321 | 321 | } |
322 | 322 | |
323 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
323 | + $response = wp_remote_get("$update_uri?nocache=".time()); |
|
324 | 324 | |
325 | - if ( is_wp_error( $response ) ) { |
|
325 | + if (is_wp_error($response)) { |
|
326 | 326 | return $update; |
327 | 327 | } |
328 | 328 | |
329 | 329 | try { |
330 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
331 | - } catch ( Exception $e ) { |
|
330 | + return json_decode(wp_remote_retrieve_body($response)); |
|
331 | + } catch (Exception $e) { |
|
332 | 332 | return $update; |
333 | 333 | } |
334 | 334 | }, |
@@ -6,82 +6,82 @@ |
||
6 | 6 | |
7 | 7 | class Sync_Background_Process_Wpjson_Endpoint { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Sync_Background_Process |
|
11 | - */ |
|
12 | - private $sync_background_process; |
|
13 | - |
|
14 | - /** |
|
15 | - * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
16 | - * |
|
17 | - * @param Action_Scheduler_Sync_Background_Process $sync_background_process |
|
18 | - */ |
|
19 | - public function __construct( $sync_background_process ) { |
|
20 | - |
|
21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
22 | - |
|
23 | - $this->sync_background_process = $sync_background_process; |
|
24 | - |
|
25 | - } |
|
26 | - |
|
27 | - public function rest_api_init() { |
|
28 | - |
|
29 | - register_rest_route( |
|
30 | - 'wordlift/v1', |
|
31 | - '/dataset/background/sync', |
|
32 | - array( |
|
33 | - 'methods' => WP_REST_Server::CREATABLE, |
|
34 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | - 'permission_callback' => function () { |
|
36 | - $user = wp_get_current_user(); |
|
37 | - |
|
38 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
39 | - }, |
|
40 | - ) |
|
41 | - ); |
|
42 | - |
|
43 | - register_rest_route( |
|
44 | - 'wordlift/v1', |
|
45 | - '/dataset/background/sync', |
|
46 | - array( |
|
47 | - 'methods' => WP_REST_Server::READABLE, |
|
48 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | - 'permission_callback' => function () { |
|
50 | - $user = wp_get_current_user(); |
|
51 | - |
|
52 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
53 | - }, |
|
54 | - ) |
|
55 | - ); |
|
56 | - |
|
57 | - register_rest_route( |
|
58 | - 'wordlift/v1', |
|
59 | - '/dataset/background/sync', |
|
60 | - array( |
|
61 | - 'methods' => WP_REST_Server::DELETABLE, |
|
62 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | - 'permission_callback' => function () { |
|
64 | - $user = wp_get_current_user(); |
|
65 | - |
|
66 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
67 | - }, |
|
68 | - ) |
|
69 | - ); |
|
70 | - |
|
71 | - register_rest_route( |
|
72 | - 'wordlift/v1', |
|
73 | - '/dataset/background/sync', |
|
74 | - array( |
|
75 | - 'methods' => 'PUT', |
|
76 | - 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | - 'permission_callback' => function () { |
|
78 | - $user = wp_get_current_user(); |
|
79 | - |
|
80 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
81 | - }, |
|
82 | - ) |
|
83 | - ); |
|
84 | - |
|
85 | - } |
|
9 | + /** |
|
10 | + * @var Sync_Background_Process |
|
11 | + */ |
|
12 | + private $sync_background_process; |
|
13 | + |
|
14 | + /** |
|
15 | + * Sync_Background_Process_Wpjson_Endpoint constructor. |
|
16 | + * |
|
17 | + * @param Action_Scheduler_Sync_Background_Process $sync_background_process |
|
18 | + */ |
|
19 | + public function __construct( $sync_background_process ) { |
|
20 | + |
|
21 | + add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
22 | + |
|
23 | + $this->sync_background_process = $sync_background_process; |
|
24 | + |
|
25 | + } |
|
26 | + |
|
27 | + public function rest_api_init() { |
|
28 | + |
|
29 | + register_rest_route( |
|
30 | + 'wordlift/v1', |
|
31 | + '/dataset/background/sync', |
|
32 | + array( |
|
33 | + 'methods' => WP_REST_Server::CREATABLE, |
|
34 | + 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | + 'permission_callback' => function () { |
|
36 | + $user = wp_get_current_user(); |
|
37 | + |
|
38 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
39 | + }, |
|
40 | + ) |
|
41 | + ); |
|
42 | + |
|
43 | + register_rest_route( |
|
44 | + 'wordlift/v1', |
|
45 | + '/dataset/background/sync', |
|
46 | + array( |
|
47 | + 'methods' => WP_REST_Server::READABLE, |
|
48 | + 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | + 'permission_callback' => function () { |
|
50 | + $user = wp_get_current_user(); |
|
51 | + |
|
52 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
53 | + }, |
|
54 | + ) |
|
55 | + ); |
|
56 | + |
|
57 | + register_rest_route( |
|
58 | + 'wordlift/v1', |
|
59 | + '/dataset/background/sync', |
|
60 | + array( |
|
61 | + 'methods' => WP_REST_Server::DELETABLE, |
|
62 | + 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | + 'permission_callback' => function () { |
|
64 | + $user = wp_get_current_user(); |
|
65 | + |
|
66 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
67 | + }, |
|
68 | + ) |
|
69 | + ); |
|
70 | + |
|
71 | + register_rest_route( |
|
72 | + 'wordlift/v1', |
|
73 | + '/dataset/background/sync', |
|
74 | + array( |
|
75 | + 'methods' => 'PUT', |
|
76 | + 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | + 'permission_callback' => function () { |
|
78 | + $user = wp_get_current_user(); |
|
79 | + |
|
80 | + return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
81 | + }, |
|
82 | + ) |
|
83 | + ); |
|
84 | + |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | * |
17 | 17 | * @param Action_Scheduler_Sync_Background_Process $sync_background_process |
18 | 18 | */ |
19 | - public function __construct( $sync_background_process ) { |
|
19 | + public function __construct($sync_background_process) { |
|
20 | 20 | |
21 | - add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); |
|
21 | + add_action('rest_api_init', array($this, 'rest_api_init')); |
|
22 | 22 | |
23 | 23 | $this->sync_background_process = $sync_background_process; |
24 | 24 | |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | '/dataset/background/sync', |
32 | 32 | array( |
33 | 33 | 'methods' => WP_REST_Server::CREATABLE, |
34 | - 'callback' => array( $this->sync_background_process, 'start' ), |
|
35 | - 'permission_callback' => function () { |
|
34 | + 'callback' => array($this->sync_background_process, 'start'), |
|
35 | + 'permission_callback' => function() { |
|
36 | 36 | $user = wp_get_current_user(); |
37 | 37 | |
38 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
38 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
39 | 39 | }, |
40 | 40 | ) |
41 | 41 | ); |
@@ -45,11 +45,11 @@ discard block |
||
45 | 45 | '/dataset/background/sync', |
46 | 46 | array( |
47 | 47 | 'methods' => WP_REST_Server::READABLE, |
48 | - 'callback' => array( $this->sync_background_process, 'get_info' ), |
|
49 | - 'permission_callback' => function () { |
|
48 | + 'callback' => array($this->sync_background_process, 'get_info'), |
|
49 | + 'permission_callback' => function() { |
|
50 | 50 | $user = wp_get_current_user(); |
51 | 51 | |
52 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
52 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
53 | 53 | }, |
54 | 54 | ) |
55 | 55 | ); |
@@ -59,11 +59,11 @@ discard block |
||
59 | 59 | '/dataset/background/sync', |
60 | 60 | array( |
61 | 61 | 'methods' => WP_REST_Server::DELETABLE, |
62 | - 'callback' => array( $this->sync_background_process, 'stop' ), |
|
63 | - 'permission_callback' => function () { |
|
62 | + 'callback' => array($this->sync_background_process, 'stop'), |
|
63 | + 'permission_callback' => function() { |
|
64 | 64 | $user = wp_get_current_user(); |
65 | 65 | |
66 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
66 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
67 | 67 | }, |
68 | 68 | ) |
69 | 69 | ); |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | '/dataset/background/sync', |
74 | 74 | array( |
75 | 75 | 'methods' => 'PUT', |
76 | - 'callback' => array( $this->sync_background_process, 'resume' ), |
|
77 | - 'permission_callback' => function () { |
|
76 | + 'callback' => array($this->sync_background_process, 'resume'), |
|
77 | + 'permission_callback' => function() { |
|
78 | 78 | $user = wp_get_current_user(); |
79 | 79 | |
80 | - return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles, true ); |
|
80 | + return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles, true); |
|
81 | 81 | }, |
82 | 82 | ) |
83 | 83 | ); |
@@ -8,96 +8,96 @@ |
||
8 | 8 | |
9 | 9 | class Action_Scheduler_Sync_Background_Process extends Action_Scheduler_Background_Process { |
10 | 10 | |
11 | - const STATE_STARTED = 'started'; |
|
12 | - const STATE_STOPPED = 'stopped'; |
|
13 | - |
|
14 | - const HOOK_NAME = 'wl_dataset__sync'; |
|
15 | - |
|
16 | - /** |
|
17 | - * @var Sync_Service |
|
18 | - */ |
|
19 | - private $sync_service; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var Sync_Object_Adapter_Factory |
|
23 | - */ |
|
24 | - private $sync_object_adapter_factory; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var Sync_Background_Process_State |
|
28 | - */ |
|
29 | - private $state; |
|
30 | - |
|
31 | - /** |
|
32 | - * Sync_Background_Process constructor. |
|
33 | - * |
|
34 | - * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
35 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
36 | - */ |
|
37 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
38 | - parent::__construct( self::HOOK_NAME, 'wordlift' ); |
|
39 | - $this->sync_service = $sync_service; |
|
40 | - $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
41 | - |
|
42 | - // Set the current state. |
|
43 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
44 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
45 | - } else { |
|
46 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - public function start() { |
|
51 | - $this->state->leave(); |
|
52 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
53 | - $this->state->enter(); |
|
54 | - $this->schedule(); |
|
55 | - } |
|
56 | - |
|
57 | - public function stop() { |
|
58 | - $this->state->leave(); |
|
59 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
60 | - $this->state->enter(); |
|
61 | - } |
|
62 | - |
|
63 | - public function resume() { |
|
64 | - $this->schedule(); |
|
65 | - $this->state->resume(); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - public function do_task( $args ) { |
|
70 | - $result = $this->state->task( $args ); |
|
71 | - if ( ! $result->has_next() ) { |
|
72 | - $this->stop(); |
|
73 | - } |
|
74 | - return $result; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Get the current state. |
|
79 | - * |
|
80 | - * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
81 | - */ |
|
82 | - public function get_state() { |
|
83 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Persist the current state. |
|
88 | - * |
|
89 | - * @param string $value |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function set_state( $value ) { |
|
94 | - return null === $value |
|
95 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
96 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
97 | - } |
|
98 | - |
|
99 | - public function get_info() { |
|
100 | - return $this->state->get_info(); |
|
101 | - } |
|
11 | + const STATE_STARTED = 'started'; |
|
12 | + const STATE_STOPPED = 'stopped'; |
|
13 | + |
|
14 | + const HOOK_NAME = 'wl_dataset__sync'; |
|
15 | + |
|
16 | + /** |
|
17 | + * @var Sync_Service |
|
18 | + */ |
|
19 | + private $sync_service; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var Sync_Object_Adapter_Factory |
|
23 | + */ |
|
24 | + private $sync_object_adapter_factory; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var Sync_Background_Process_State |
|
28 | + */ |
|
29 | + private $state; |
|
30 | + |
|
31 | + /** |
|
32 | + * Sync_Background_Process constructor. |
|
33 | + * |
|
34 | + * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
|
35 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
36 | + */ |
|
37 | + public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
38 | + parent::__construct( self::HOOK_NAME, 'wordlift' ); |
|
39 | + $this->sync_service = $sync_service; |
|
40 | + $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
|
41 | + |
|
42 | + // Set the current state. |
|
43 | + if ( self::STATE_STARTED === $this->get_state() ) { |
|
44 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
45 | + } else { |
|
46 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + public function start() { |
|
51 | + $this->state->leave(); |
|
52 | + $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
53 | + $this->state->enter(); |
|
54 | + $this->schedule(); |
|
55 | + } |
|
56 | + |
|
57 | + public function stop() { |
|
58 | + $this->state->leave(); |
|
59 | + $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
60 | + $this->state->enter(); |
|
61 | + } |
|
62 | + |
|
63 | + public function resume() { |
|
64 | + $this->schedule(); |
|
65 | + $this->state->resume(); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + public function do_task( $args ) { |
|
70 | + $result = $this->state->task( $args ); |
|
71 | + if ( ! $result->has_next() ) { |
|
72 | + $this->stop(); |
|
73 | + } |
|
74 | + return $result; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Get the current state. |
|
79 | + * |
|
80 | + * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
|
81 | + */ |
|
82 | + public function get_state() { |
|
83 | + return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Persist the current state. |
|
88 | + * |
|
89 | + * @param string $value |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function set_state( $value ) { |
|
94 | + return null === $value |
|
95 | + ? delete_option( '_wl_sync_background_process_state' ) |
|
96 | + : update_option( '_wl_sync_background_process_state', $value, true ); |
|
97 | + } |
|
98 | + |
|
99 | + public function get_info() { |
|
100 | + return $this->state->get_info(); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | } |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | * @param Sync_Service $sync_service A {@link Sync_Service} instance providing the supporting functions to this background process. |
35 | 35 | * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
36 | 36 | */ |
37 | - public function __construct( $sync_service, $sync_object_adapter_factory ) { |
|
38 | - parent::__construct( self::HOOK_NAME, 'wordlift' ); |
|
37 | + public function __construct($sync_service, $sync_object_adapter_factory) { |
|
38 | + parent::__construct(self::HOOK_NAME, 'wordlift'); |
|
39 | 39 | $this->sync_service = $sync_service; |
40 | 40 | $this->sync_object_adapter_factory = $sync_object_adapter_factory; |
41 | 41 | |
42 | 42 | // Set the current state. |
43 | - if ( self::STATE_STARTED === $this->get_state() ) { |
|
44 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
43 | + if (self::STATE_STARTED === $this->get_state()) { |
|
44 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
45 | 45 | } else { |
46 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
46 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
50 | 50 | public function start() { |
51 | 51 | $this->state->leave(); |
52 | - $this->state = new Sync_Background_Process_Started_State( $this, $this->sync_service, $this->sync_object_adapter_factory ); |
|
52 | + $this->state = new Sync_Background_Process_Started_State($this, $this->sync_service, $this->sync_object_adapter_factory); |
|
53 | 53 | $this->state->enter(); |
54 | 54 | $this->schedule(); |
55 | 55 | } |
56 | 56 | |
57 | 57 | public function stop() { |
58 | 58 | $this->state->leave(); |
59 | - $this->state = new Sync_Background_Process_Stopped_State( $this ); |
|
59 | + $this->state = new Sync_Background_Process_Stopped_State($this); |
|
60 | 60 | $this->state->enter(); |
61 | 61 | } |
62 | 62 | |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | - public function do_task( $args ) { |
|
70 | - $result = $this->state->task( $args ); |
|
71 | - if ( ! $result->has_next() ) { |
|
69 | + public function do_task($args) { |
|
70 | + $result = $this->state->task($args); |
|
71 | + if ( ! $result->has_next()) { |
|
72 | 72 | $this->stop(); |
73 | 73 | } |
74 | 74 | return $result; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default). |
81 | 81 | */ |
82 | 82 | public function get_state() { |
83 | - return get_option( '_wl_sync_background_process_state', self::STATE_STOPPED ); |
|
83 | + return get_option('_wl_sync_background_process_state', self::STATE_STOPPED); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @return bool |
92 | 92 | */ |
93 | - public function set_state( $value ) { |
|
93 | + public function set_state($value) { |
|
94 | 94 | return null === $value |
95 | - ? delete_option( '_wl_sync_background_process_state' ) |
|
96 | - : update_option( '_wl_sync_background_process_state', $value, true ); |
|
95 | + ? delete_option('_wl_sync_background_process_state') |
|
96 | + : update_option('_wl_sync_background_process_state', $value, true); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | public function get_info() { |
@@ -6,31 +6,31 @@ |
||
6 | 6 | |
7 | 7 | class Sync_Background_Process_Stopped_State extends Abstract_Sync_Background_Process_State { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Action_Scheduler_Sync_Background_Process |
|
11 | - */ |
|
12 | - private $context; |
|
9 | + /** |
|
10 | + * @var Action_Scheduler_Sync_Background_Process |
|
11 | + */ |
|
12 | + private $context; |
|
13 | 13 | |
14 | - public function __construct( $context ) { |
|
15 | - parent::__construct( Action_Scheduler_Sync_Background_Process::STATE_STOPPED ); |
|
14 | + public function __construct( $context ) { |
|
15 | + parent::__construct( Action_Scheduler_Sync_Background_Process::STATE_STOPPED ); |
|
16 | 16 | |
17 | - $this->context = $context; |
|
18 | - } |
|
17 | + $this->context = $context; |
|
18 | + } |
|
19 | 19 | |
20 | - public function enter() { |
|
21 | - $this->context->set_state( Action_Scheduler_Sync_Background_Process::STATE_STOPPED ); |
|
22 | - } |
|
20 | + public function enter() { |
|
21 | + $this->context->set_state( Action_Scheduler_Sync_Background_Process::STATE_STOPPED ); |
|
22 | + } |
|
23 | 23 | |
24 | - public function leave() { |
|
25 | - $this->context->set_state( null ); |
|
26 | - } |
|
24 | + public function leave() { |
|
25 | + $this->context->set_state( null ); |
|
26 | + } |
|
27 | 27 | |
28 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
29 | - public function task( $item ) { |
|
28 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
29 | + public function task( $item ) { |
|
30 | 30 | |
31 | - $this->context->unschedule(); |
|
31 | + $this->context->unschedule(); |
|
32 | 32 | |
33 | - return State::complete(); |
|
34 | - } |
|
33 | + return State::complete(); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -11,22 +11,22 @@ |
||
11 | 11 | */ |
12 | 12 | private $context; |
13 | 13 | |
14 | - public function __construct( $context ) { |
|
15 | - parent::__construct( Action_Scheduler_Sync_Background_Process::STATE_STOPPED ); |
|
14 | + public function __construct($context) { |
|
15 | + parent::__construct(Action_Scheduler_Sync_Background_Process::STATE_STOPPED); |
|
16 | 16 | |
17 | 17 | $this->context = $context; |
18 | 18 | } |
19 | 19 | |
20 | 20 | public function enter() { |
21 | - $this->context->set_state( Action_Scheduler_Sync_Background_Process::STATE_STOPPED ); |
|
21 | + $this->context->set_state(Action_Scheduler_Sync_Background_Process::STATE_STOPPED); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | public function leave() { |
25 | - $this->context->set_state( null ); |
|
25 | + $this->context->set_state(null); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
29 | - public function task( $item ) { |
|
29 | + public function task($item) { |
|
30 | 30 | |
31 | 31 | $this->context->unschedule(); |
32 | 32 |
@@ -12,141 +12,141 @@ |
||
12 | 12 | |
13 | 13 | class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State { |
14 | 14 | |
15 | - /** |
|
16 | - * @var Action_Scheduler_Sync_Background_Process |
|
17 | - */ |
|
18 | - private $context; |
|
19 | - |
|
20 | - /** |
|
21 | - * @var Sync_Service |
|
22 | - */ |
|
23 | - private $sync_service; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var Sync_Background_Process_Stage[] |
|
27 | - */ |
|
28 | - private $stages; |
|
29 | - |
|
30 | - private $batch_size = 5; |
|
31 | - /** |
|
32 | - * @var bool |
|
33 | - */ |
|
34 | - private $reset; |
|
35 | - |
|
36 | - /** |
|
37 | - * Sync_Background_Process_Started_State constructor. |
|
38 | - * |
|
39 | - * @param Action_Scheduler_Sync_Background_Process $context |
|
40 | - * @param Sync_Service $sync_service |
|
41 | - * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
42 | - * @param bool $reset Whether to reset the counters |
|
43 | - */ |
|
44 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
45 | - public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
46 | - parent::__construct( Action_Scheduler_Sync_Background_Process::STATE_STARTED ); |
|
47 | - |
|
48 | - $this->context = $context; |
|
49 | - $this->sync_service = $sync_service; |
|
50 | - |
|
51 | - $this->stages = array( |
|
52 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
53 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
54 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
55 | - ); |
|
56 | - } |
|
57 | - |
|
58 | - public function enter() { |
|
59 | - // Delete the KG contents. |
|
60 | - $this->sync_service->delete_all(); |
|
61 | - |
|
62 | - // Clear caches. |
|
63 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
64 | - |
|
65 | - $counts = array_map( |
|
66 | - function ( $item ) { |
|
67 | - return $item->count(); |
|
68 | - }, |
|
69 | - $this->stages |
|
70 | - ); |
|
71 | - |
|
72 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
73 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
74 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
75 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
76 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
77 | - |
|
78 | - $this->context->set_state( Action_Scheduler_Sync_Background_Process::STATE_STARTED ); |
|
79 | - |
|
80 | - $this->resume(); |
|
81 | - } |
|
82 | - |
|
83 | - public function resume() { |
|
84 | - $this->context->schedule(); |
|
85 | - } |
|
86 | - |
|
87 | - public function leave() { |
|
88 | - $this->context->set_state( null ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @param $args |
|
93 | - * |
|
94 | - * @return State |
|
95 | - */ |
|
96 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
97 | - public function task( $args ) { |
|
98 | - error_log("started state task() called"); |
|
99 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
100 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
101 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
102 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
103 | - |
|
104 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
105 | - try { |
|
106 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
107 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
108 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
109 | - } catch ( \Exception $e ) { |
|
110 | - // ignored. |
|
111 | - } |
|
112 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
113 | - |
|
114 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
115 | - |
|
116 | - // Increase the offset. |
|
117 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
118 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
119 | - |
|
120 | - return State::items_in_queue(); |
|
121 | - } |
|
122 | - |
|
123 | - // Increase the stage. |
|
124 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
125 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
126 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
127 | - |
|
128 | - return State::items_in_queue(); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - return State::complete(); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Hook to provide a request to update the status on the server. |
|
138 | - * |
|
139 | - * @param array $args |
|
140 | - * |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function api_service__request( $args ) { |
|
144 | - |
|
145 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
146 | - |
|
147 | - $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
148 | - |
|
149 | - return $args; |
|
150 | - } |
|
15 | + /** |
|
16 | + * @var Action_Scheduler_Sync_Background_Process |
|
17 | + */ |
|
18 | + private $context; |
|
19 | + |
|
20 | + /** |
|
21 | + * @var Sync_Service |
|
22 | + */ |
|
23 | + private $sync_service; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var Sync_Background_Process_Stage[] |
|
27 | + */ |
|
28 | + private $stages; |
|
29 | + |
|
30 | + private $batch_size = 5; |
|
31 | + /** |
|
32 | + * @var bool |
|
33 | + */ |
|
34 | + private $reset; |
|
35 | + |
|
36 | + /** |
|
37 | + * Sync_Background_Process_Started_State constructor. |
|
38 | + * |
|
39 | + * @param Action_Scheduler_Sync_Background_Process $context |
|
40 | + * @param Sync_Service $sync_service |
|
41 | + * @param Sync_Object_Adapter_Factory $sync_object_adapter_factory |
|
42 | + * @param bool $reset Whether to reset the counters |
|
43 | + */ |
|
44 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
45 | + public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
46 | + parent::__construct( Action_Scheduler_Sync_Background_Process::STATE_STARTED ); |
|
47 | + |
|
48 | + $this->context = $context; |
|
49 | + $this->sync_service = $sync_service; |
|
50 | + |
|
51 | + $this->stages = array( |
|
52 | + new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
53 | + new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
54 | + new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
55 | + ); |
|
56 | + } |
|
57 | + |
|
58 | + public function enter() { |
|
59 | + // Delete the KG contents. |
|
60 | + $this->sync_service->delete_all(); |
|
61 | + |
|
62 | + // Clear caches. |
|
63 | + do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
64 | + |
|
65 | + $counts = array_map( |
|
66 | + function ( $item ) { |
|
67 | + return $item->count(); |
|
68 | + }, |
|
69 | + $this->stages |
|
70 | + ); |
|
71 | + |
|
72 | + update_option( '_wl_sync_background_process_count', $counts, true ); |
|
73 | + update_option( '_wl_sync_background_process_stage', 0, true ); |
|
74 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
75 | + update_option( '_wl_sync_background_process_started', time(), true ); |
|
76 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
77 | + |
|
78 | + $this->context->set_state( Action_Scheduler_Sync_Background_Process::STATE_STARTED ); |
|
79 | + |
|
80 | + $this->resume(); |
|
81 | + } |
|
82 | + |
|
83 | + public function resume() { |
|
84 | + $this->context->schedule(); |
|
85 | + } |
|
86 | + |
|
87 | + public function leave() { |
|
88 | + $this->context->set_state( null ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @param $args |
|
93 | + * |
|
94 | + * @return State |
|
95 | + */ |
|
96 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
97 | + public function task( $args ) { |
|
98 | + error_log("started state task() called"); |
|
99 | + $offset = get_option( '_wl_sync_background_process_offset' ); |
|
100 | + $stage = get_option( '_wl_sync_background_process_stage' ); |
|
101 | + $counts = get_option( '_wl_sync_background_process_count' ); |
|
102 | + $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
103 | + |
|
104 | + add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
105 | + try { |
|
106 | + $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
107 | + $this->sync_service->sync_many( $object_adapters, true ); |
|
108 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
|
109 | + } catch ( \Exception $e ) { |
|
110 | + // ignored. |
|
111 | + } |
|
112 | + remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
113 | + |
|
114 | + update_option( '_wl_sync_background_process_updated', time(), true ); |
|
115 | + |
|
116 | + // Increase the offset. |
|
117 | + if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
118 | + update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
119 | + |
|
120 | + return State::items_in_queue(); |
|
121 | + } |
|
122 | + |
|
123 | + // Increase the stage. |
|
124 | + if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
125 | + update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
126 | + update_option( '_wl_sync_background_process_offset', 0, true ); |
|
127 | + |
|
128 | + return State::items_in_queue(); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + return State::complete(); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Hook to provide a request to update the status on the server. |
|
138 | + * |
|
139 | + * @param array $args |
|
140 | + * |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function api_service__request( $args ) { |
|
144 | + |
|
145 | + $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
146 | + |
|
147 | + $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
|
148 | + |
|
149 | + return $args; |
|
150 | + } |
|
151 | 151 | |
152 | 152 | } |
@@ -42,16 +42,16 @@ discard block |
||
42 | 42 | * @param bool $reset Whether to reset the counters |
43 | 43 | */ |
44 | 44 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
45 | - public function __construct( $context, $sync_service, $sync_object_adapter_factory, $reset = true ) { |
|
46 | - parent::__construct( Action_Scheduler_Sync_Background_Process::STATE_STARTED ); |
|
45 | + public function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) { |
|
46 | + parent::__construct(Action_Scheduler_Sync_Background_Process::STATE_STARTED); |
|
47 | 47 | |
48 | 48 | $this->context = $context; |
49 | 49 | $this->sync_service = $sync_service; |
50 | 50 | |
51 | 51 | $this->stages = array( |
52 | - new Sync_Background_Process_Posts_Stage( $sync_object_adapter_factory ), |
|
53 | - new Sync_Background_Process_Terms_Stage( $sync_object_adapter_factory ), |
|
54 | - new Sync_Background_Process_Users_Stage( $sync_object_adapter_factory ), |
|
52 | + new Sync_Background_Process_Posts_Stage($sync_object_adapter_factory), |
|
53 | + new Sync_Background_Process_Terms_Stage($sync_object_adapter_factory), |
|
54 | + new Sync_Background_Process_Users_Stage($sync_object_adapter_factory), |
|
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
@@ -60,22 +60,22 @@ discard block |
||
60 | 60 | $this->sync_service->delete_all(); |
61 | 61 | |
62 | 62 | // Clear caches. |
63 | - do_action( 'wl_ttl_cache_cleaner__flush' ); |
|
63 | + do_action('wl_ttl_cache_cleaner__flush'); |
|
64 | 64 | |
65 | 65 | $counts = array_map( |
66 | - function ( $item ) { |
|
66 | + function($item) { |
|
67 | 67 | return $item->count(); |
68 | 68 | }, |
69 | 69 | $this->stages |
70 | 70 | ); |
71 | 71 | |
72 | - update_option( '_wl_sync_background_process_count', $counts, true ); |
|
73 | - update_option( '_wl_sync_background_process_stage', 0, true ); |
|
74 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
75 | - update_option( '_wl_sync_background_process_started', time(), true ); |
|
76 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
72 | + update_option('_wl_sync_background_process_count', $counts, true); |
|
73 | + update_option('_wl_sync_background_process_stage', 0, true); |
|
74 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
75 | + update_option('_wl_sync_background_process_started', time(), true); |
|
76 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
77 | 77 | |
78 | - $this->context->set_state( Action_Scheduler_Sync_Background_Process::STATE_STARTED ); |
|
78 | + $this->context->set_state(Action_Scheduler_Sync_Background_Process::STATE_STARTED); |
|
79 | 79 | |
80 | 80 | $this->resume(); |
81 | 81 | } |
@@ -85,7 +85,7 @@ discard block |
||
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 | /** |
@@ -94,36 +94,36 @@ discard block |
||
94 | 94 | * @return State |
95 | 95 | */ |
96 | 96 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
97 | - public function task( $args ) { |
|
97 | + public function task($args) { |
|
98 | 98 | error_log("started state task() called"); |
99 | - $offset = get_option( '_wl_sync_background_process_offset' ); |
|
100 | - $stage = get_option( '_wl_sync_background_process_stage' ); |
|
101 | - $counts = get_option( '_wl_sync_background_process_count' ); |
|
102 | - $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size ); |
|
99 | + $offset = get_option('_wl_sync_background_process_offset'); |
|
100 | + $stage = get_option('_wl_sync_background_process_stage'); |
|
101 | + $counts = get_option('_wl_sync_background_process_count'); |
|
102 | + $batch_size = min($counts[$stage] - $offset, $this->batch_size); |
|
103 | 103 | |
104 | - add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
104 | + add_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
105 | 105 | try { |
106 | - $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size ); |
|
107 | - $this->sync_service->sync_many( $object_adapters, true ); |
|
106 | + $object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size); |
|
107 | + $this->sync_service->sync_many($object_adapters, true); |
|
108 | 108 | // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch |
109 | - } catch ( \Exception $e ) { |
|
109 | + } catch (\Exception $e) { |
|
110 | 110 | // ignored. |
111 | 111 | } |
112 | - remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) ); |
|
112 | + remove_filter('wl_api_service__request', array($this, 'api_service__request')); |
|
113 | 113 | |
114 | - update_option( '_wl_sync_background_process_updated', time(), true ); |
|
114 | + update_option('_wl_sync_background_process_updated', time(), true); |
|
115 | 115 | |
116 | 116 | // Increase the offset. |
117 | - if ( ( $offset + $batch_size ) < $counts[ $stage ] ) { |
|
118 | - update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true ); |
|
117 | + if (($offset + $batch_size) < $counts[$stage]) { |
|
118 | + update_option('_wl_sync_background_process_offset', $offset + $batch_size, true); |
|
119 | 119 | |
120 | 120 | return State::items_in_queue(); |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Increase the stage. |
124 | - if ( ( $stage + 1 ) < count( $this->stages ) ) { |
|
125 | - update_option( '_wl_sync_background_process_stage', $stage + 1, true ); |
|
126 | - update_option( '_wl_sync_background_process_offset', 0, true ); |
|
124 | + if (($stage + 1) < count($this->stages)) { |
|
125 | + update_option('_wl_sync_background_process_stage', $stage + 1, true); |
|
126 | + update_option('_wl_sync_background_process_offset', 0, true); |
|
127 | 127 | |
128 | 128 | return State::items_in_queue(); |
129 | 129 | } |
@@ -140,9 +140,9 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @return mixed |
142 | 142 | */ |
143 | - public function api_service__request( $args ) { |
|
143 | + public function api_service__request($args) { |
|
144 | 144 | |
145 | - $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) ); |
|
145 | + $state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info())); |
|
146 | 146 | |
147 | 147 | $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value; |
148 | 148 |
@@ -16,38 +16,38 @@ |
||
16 | 16 | use Wordlift\Jsonld\Jsonld_Service; |
17 | 17 | |
18 | 18 | if ( ! defined( 'ABSPATH' ) ) { |
19 | - exit; |
|
19 | + exit; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | // Register the Dataset JSON Endpoint. |
23 | 23 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
24 | 24 | if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) { |
25 | 25 | |
26 | - $sync_object_adapter_factory = new Sync_Object_Adapter_Factory(); |
|
27 | - $sync_service = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
28 | - new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory ); |
|
29 | - new Sync_User_Hooks( $sync_service ); |
|
26 | + $sync_object_adapter_factory = new Sync_Object_Adapter_Factory(); |
|
27 | + $sync_service = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
28 | + new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory ); |
|
29 | + new Sync_User_Hooks( $sync_service ); |
|
30 | 30 | |
31 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
32 | - if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) { |
|
33 | - new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory ); |
|
34 | - } |
|
35 | - /** |
|
36 | - * @since 3.28.0 |
|
37 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1186 |
|
38 | - */ |
|
39 | - new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() ); |
|
31 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
32 | + if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) { |
|
33 | + new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory ); |
|
34 | + } |
|
35 | + /** |
|
36 | + * @since 3.28.0 |
|
37 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1186 |
|
38 | + */ |
|
39 | + new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() ); |
|
40 | 40 | |
41 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
42 | - if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) { |
|
43 | - new Sync_Hooks_Wordpress_Ontology(); |
|
44 | - } |
|
41 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
42 | + if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) { |
|
43 | + new Sync_Hooks_Wordpress_Ontology(); |
|
44 | + } |
|
45 | 45 | |
46 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
47 | - if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) { |
|
48 | - // Set up the sync background process. |
|
49 | - $sync_background_process = new Action_Scheduler_Sync_Background_Process( $sync_service, $sync_object_adapter_factory ); |
|
50 | - new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process ); |
|
51 | - new Sync_Page(); |
|
52 | - } |
|
46 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
47 | + if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) { |
|
48 | + // Set up the sync background process. |
|
49 | + $sync_background_process = new Action_Scheduler_Sync_Background_Process( $sync_service, $sync_object_adapter_factory ); |
|
50 | + new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process ); |
|
51 | + new Sync_Page(); |
|
52 | + } |
|
53 | 53 | } |
@@ -15,39 +15,39 @@ |
||
15 | 15 | use Wordlift\Dataset\Sync_User_Hooks; |
16 | 16 | use Wordlift\Jsonld\Jsonld_Service; |
17 | 17 | |
18 | -if ( ! defined( 'ABSPATH' ) ) { |
|
18 | +if ( ! defined('ABSPATH')) { |
|
19 | 19 | exit; |
20 | 20 | } |
21 | 21 | |
22 | 22 | // Register the Dataset JSON Endpoint. |
23 | 23 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
24 | -if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) { |
|
24 | +if (apply_filters('wl_feature__enable__dataset-ng', false)) { |
|
25 | 25 | |
26 | 26 | $sync_object_adapter_factory = new Sync_Object_Adapter_Factory(); |
27 | - $sync_service = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() ); |
|
28 | - new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory ); |
|
29 | - new Sync_User_Hooks( $sync_service ); |
|
27 | + $sync_service = new Sync_Service(Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance()); |
|
28 | + new Sync_Post_Hooks($sync_service, $sync_object_adapter_factory); |
|
29 | + new Sync_User_Hooks($sync_service); |
|
30 | 30 | |
31 | 31 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
32 | - if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) { |
|
33 | - new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory ); |
|
32 | + if (apply_filters('wl_feature__enable__no-vocabulary-terms', false)) { |
|
33 | + new Sync_Term_Hooks($sync_service, $sync_object_adapter_factory); |
|
34 | 34 | } |
35 | 35 | /** |
36 | 36 | * @since 3.28.0 |
37 | 37 | * @see https://github.com/insideout10/wordlift-plugin/issues/1186 |
38 | 38 | */ |
39 | - new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() ); |
|
39 | + new Sync_Hooks_Entity_Relation(Wordlift_Entity_Service::get_instance()); |
|
40 | 40 | |
41 | 41 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
42 | - if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) { |
|
42 | + if (apply_filters('wl_feature__enable__wordpress-ontology', false)) { |
|
43 | 43 | new Sync_Hooks_Wordpress_Ontology(); |
44 | 44 | } |
45 | 45 | |
46 | 46 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
47 | - if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) { |
|
47 | + if (apply_filters('wl_feature__enable__sync-background', false)) { |
|
48 | 48 | // Set up the sync background process. |
49 | - $sync_background_process = new Action_Scheduler_Sync_Background_Process( $sync_service, $sync_object_adapter_factory ); |
|
50 | - new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process ); |
|
49 | + $sync_background_process = new Action_Scheduler_Sync_Background_Process($sync_service, $sync_object_adapter_factory); |
|
50 | + new Sync_Background_Process_Wpjson_Endpoint($sync_background_process); |
|
51 | 51 | new Sync_Page(); |
52 | 52 | } |
53 | 53 | } |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | class State { |
6 | 6 | |
7 | - private $args; |
|
8 | - private $has_next; |
|
7 | + private $args; |
|
8 | + private $has_next; |
|
9 | 9 | |
10 | - public function __construct( $has_next, $args ) { |
|
11 | - $this->has_next = $has_next; |
|
12 | - $this->args = $args; |
|
13 | - } |
|
10 | + public function __construct( $has_next, $args ) { |
|
11 | + $this->has_next = $has_next; |
|
12 | + $this->args = $args; |
|
13 | + } |
|
14 | 14 | |
15 | - public function has_next() { |
|
16 | - return $this->has_next; |
|
17 | - } |
|
15 | + public function has_next() { |
|
16 | + return $this->has_next; |
|
17 | + } |
|
18 | 18 | |
19 | - public function get_args() { |
|
20 | - return $this->args; |
|
21 | - } |
|
19 | + public function get_args() { |
|
20 | + return $this->args; |
|
21 | + } |
|
22 | 22 | |
23 | - public static function complete() { |
|
24 | - return new self( false, array() ); |
|
25 | - } |
|
23 | + public static function complete() { |
|
24 | + return new self( false, array() ); |
|
25 | + } |
|
26 | 26 | |
27 | - public static function items_in_queue( $args = array() ) { |
|
28 | - return new self( true, $args ); |
|
29 | - } |
|
27 | + public static function items_in_queue( $args = array() ) { |
|
28 | + return new self( true, $args ); |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | private $args; |
8 | 8 | private $has_next; |
9 | 9 | |
10 | - public function __construct( $has_next, $args ) { |
|
10 | + public function __construct($has_next, $args) { |
|
11 | 11 | $this->has_next = $has_next; |
12 | 12 | $this->args = $args; |
13 | 13 | } |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | public static function complete() { |
24 | - return new self( false, array() ); |
|
24 | + return new self(false, array()); |
|
25 | 25 | } |
26 | 26 | |
27 | - public static function items_in_queue( $args = array() ) { |
|
28 | - return new self( true, $args ); |
|
27 | + public static function items_in_queue($args = array()) { |
|
28 | + return new self(true, $args); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 |
@@ -5,49 +5,49 @@ |
||
5 | 5 | abstract class Action_Scheduler_Background_Process { |
6 | 6 | |
7 | 7 | |
8 | - /** |
|
9 | - * @var string Hook name used for invoking the task method. |
|
10 | - */ |
|
11 | - private $hook; |
|
12 | - /** |
|
13 | - * @var string Group which would be used when |
|
14 | - */ |
|
15 | - private $group; |
|
16 | - |
|
17 | - |
|
18 | - public function __construct( $hook, $group ) { |
|
19 | - $this->hook = $hook; |
|
20 | - $this->group = $group; |
|
21 | - add_action( $this->hook, array( $this, 'task' ) ); |
|
22 | - } |
|
23 | - |
|
24 | - public function schedule( $args = array() ) { |
|
25 | - |
|
26 | - as_enqueue_async_action( $this->hook, $args, $this->group ); |
|
27 | - error_log( "scheduled action for hook " . $this->hook ); |
|
28 | - |
|
29 | - } |
|
30 | - |
|
31 | - public function unschedule() { |
|
32 | - as_unschedule_all_actions( $this->hook ); |
|
33 | - } |
|
34 | - |
|
35 | - public function task( $args = array() ) { |
|
36 | - $state = $this->do_task( $args ); |
|
37 | - error_log( 'do_task returned state ' . var_export( $state, true ) ); |
|
38 | - if ( $state->has_next() ) { |
|
39 | - $this->schedule( $state->get_args() ); |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * @param $args |
|
46 | - * |
|
47 | - * @return State The state object provides necessary information about |
|
48 | - * whether to schedule next event or stop processing. |
|
49 | - */ |
|
50 | - abstract public function do_task( $args ); |
|
8 | + /** |
|
9 | + * @var string Hook name used for invoking the task method. |
|
10 | + */ |
|
11 | + private $hook; |
|
12 | + /** |
|
13 | + * @var string Group which would be used when |
|
14 | + */ |
|
15 | + private $group; |
|
16 | + |
|
17 | + |
|
18 | + public function __construct( $hook, $group ) { |
|
19 | + $this->hook = $hook; |
|
20 | + $this->group = $group; |
|
21 | + add_action( $this->hook, array( $this, 'task' ) ); |
|
22 | + } |
|
23 | + |
|
24 | + public function schedule( $args = array() ) { |
|
25 | + |
|
26 | + as_enqueue_async_action( $this->hook, $args, $this->group ); |
|
27 | + error_log( "scheduled action for hook " . $this->hook ); |
|
28 | + |
|
29 | + } |
|
30 | + |
|
31 | + public function unschedule() { |
|
32 | + as_unschedule_all_actions( $this->hook ); |
|
33 | + } |
|
34 | + |
|
35 | + public function task( $args = array() ) { |
|
36 | + $state = $this->do_task( $args ); |
|
37 | + error_log( 'do_task returned state ' . var_export( $state, true ) ); |
|
38 | + if ( $state->has_next() ) { |
|
39 | + $this->schedule( $state->get_args() ); |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * @param $args |
|
46 | + * |
|
47 | + * @return State The state object provides necessary information about |
|
48 | + * whether to schedule next event or stop processing. |
|
49 | + */ |
|
50 | + abstract public function do_task( $args ); |
|
51 | 51 | |
52 | 52 | |
53 | 53 | } |
@@ -15,28 +15,28 @@ discard block |
||
15 | 15 | private $group; |
16 | 16 | |
17 | 17 | |
18 | - public function __construct( $hook, $group ) { |
|
18 | + public function __construct($hook, $group) { |
|
19 | 19 | $this->hook = $hook; |
20 | 20 | $this->group = $group; |
21 | - add_action( $this->hook, array( $this, 'task' ) ); |
|
21 | + add_action($this->hook, array($this, 'task')); |
|
22 | 22 | } |
23 | 23 | |
24 | - public function schedule( $args = array() ) { |
|
24 | + public function schedule($args = array()) { |
|
25 | 25 | |
26 | - as_enqueue_async_action( $this->hook, $args, $this->group ); |
|
27 | - error_log( "scheduled action for hook " . $this->hook ); |
|
26 | + as_enqueue_async_action($this->hook, $args, $this->group); |
|
27 | + error_log("scheduled action for hook ".$this->hook); |
|
28 | 28 | |
29 | 29 | } |
30 | 30 | |
31 | 31 | public function unschedule() { |
32 | - as_unschedule_all_actions( $this->hook ); |
|
32 | + as_unschedule_all_actions($this->hook); |
|
33 | 33 | } |
34 | 34 | |
35 | - public function task( $args = array() ) { |
|
36 | - $state = $this->do_task( $args ); |
|
37 | - error_log( 'do_task returned state ' . var_export( $state, true ) ); |
|
38 | - if ( $state->has_next() ) { |
|
39 | - $this->schedule( $state->get_args() ); |
|
35 | + public function task($args = array()) { |
|
36 | + $state = $this->do_task($args); |
|
37 | + error_log('do_task returned state '.var_export($state, true)); |
|
38 | + if ($state->has_next()) { |
|
39 | + $this->schedule($state->get_args()); |
|
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return State The state object provides necessary information about |
48 | 48 | * whether to schedule next event or stop processing. |
49 | 49 | */ |
50 | - abstract public function do_task( $args ); |
|
50 | + abstract public function do_task($args); |
|
51 | 51 | |
52 | 52 | |
53 | 53 | } |