Completed
Push — develop ( 1de7c3...6edbae )
by David
58s
created
src/wordlift.php 2 patches
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 // If this file is called directly, abort.
35 35
 if ( ! defined( 'WPINC' ) ) {
36
-	die;
36
+    die;
37 37
 }
38 38
 
39 39
 /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
  *
43 43
  */
44 44
 if ( ! apply_filters( 'wl_is_enabled', true ) ) {
45
-	return;
45
+    return;
46 46
 }
47 47
 
48 48
 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
@@ -72,29 +72,29 @@  discard block
 block discarded – undo
72 72
  */
73 73
 function activate_wordlift() {
74 74
 
75
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
76
-
77
-	$log->info( 'Activating WordLift...' );
78
-
79
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
80
-	Wordlift_Activator::activate();
81
-
82
-	/**
83
-	 * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
84
-	 *
85
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
86
-	 * @since 3.19.2
87
-	 */
88
-	Wordlift_Http_Api::activate();
89
-
90
-	// Ensure the post type is registered before flushing the rewrite rules.
91
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
92
-	flush_rewrite_rules();
93
-	/**
94
-	 * @since 3.27.7
95
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
96
-	 */
97
-	Top_Entities::activate();
75
+    $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
76
+
77
+    $log->info( 'Activating WordLift...' );
78
+
79
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
80
+    Wordlift_Activator::activate();
81
+
82
+    /**
83
+     * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks.
84
+     *
85
+     * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue.
86
+     * @since 3.19.2
87
+     */
88
+    Wordlift_Http_Api::activate();
89
+
90
+    // Ensure the post type is registered before flushing the rewrite rules.
91
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
92
+    flush_rewrite_rules();
93
+    /**
94
+     * @since 3.27.7
95
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
96
+     */
97
+    Top_Entities::activate();
98 98
 }
99 99
 
100 100
 /**
@@ -103,21 +103,21 @@  discard block
 block discarded – undo
103 103
  */
104 104
 function deactivate_wordlift() {
105 105
 
106
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
107
-	Wordlift_Deactivator::deactivate();
108
-	Wordlift_Http_Api::deactivate();
109
-	Ttl_Cache_Cleaner::deactivate();
110
-	/**
111
-	 * @since 3.27.7
112
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1214
113
-	 */
114
-	Top_Entities::deactivate();
115
-	/**
116
-	 * @since 3.27.8
117
-	 * Remove notification flag on deactivation.
118
-	 */
119
-	Key_Validation_Notice::remove_notification_flag();
120
-	flush_rewrite_rules();
106
+    require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
107
+    Wordlift_Deactivator::deactivate();
108
+    Wordlift_Http_Api::deactivate();
109
+    Ttl_Cache_Cleaner::deactivate();
110
+    /**
111
+     * @since 3.27.7
112
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1214
113
+     */
114
+    Top_Entities::deactivate();
115
+    /**
116
+     * @since 3.27.8
117
+     * Remove notification flag on deactivation.
118
+     */
119
+    Key_Validation_Notice::remove_notification_flag();
120
+    flush_rewrite_rules();
121 121
 
122 122
 }
123 123
 
@@ -140,70 +140,70 @@  discard block
 block discarded – undo
140 140
  * @since    1.0.0
141 141
  */
142 142
 function run_wordlift() {
143
-	/**
144
-	 * Filter: wl_feature__enable__widgets.
145
-	 *
146
-	 * @param bool whether the widgets needed to be registered, defaults to true.
147
-	 *
148
-	 * @return bool
149
-	 * @since 3.27.6
150
-	 */
151
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
152
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
153
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
154
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
155
-	}
156
-	add_filter( 'widget_text', 'do_shortcode' );
157
-
158
-
159
-	/**
160
-	 * Filter: wl_feature__enable__analysis
161
-	 *
162
-	 * @param bool Whether to send api request to analysis or not
163
-	 *
164
-	 * @return bool
165
-	 * @since 3.27.6
166
-	 */
167
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
168
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
169
-	} else {
170
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
171
-	}
172
-
173
-	$plugin = new Wordlift();
174
-	$plugin->run();
175
-
176
-	// Initialize the TTL Cache Cleaner.
177
-	new Ttl_Cache_Cleaner();
178
-
179
-	// Load the new Post Adapter.
180
-	new Post_Adapter();
181
-
182
-	// Load the API Data Hooks.
183
-	new Api_Data_Hooks();
184
-
185
-	add_action( 'plugins_loaded', function () {
186
-		// All features from registry should be initialized here.
187
-		$features_registry = Features_Registry::get_instance();
188
-		$features_registry->initialize_all_features();
189
-	}, 5 );
190
-
191
-	add_action( 'plugins_loaded', function () use ( $plugin ) {
192
-
193
-		new Wordlift_Products_Navigator_Shortcode_REST();
194
-
195
-		// Register the Dataset module, requires `$api_service`.
196
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
197
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
198
-
199
-		/*
143
+    /**
144
+     * Filter: wl_feature__enable__widgets.
145
+     *
146
+     * @param bool whether the widgets needed to be registered, defaults to true.
147
+     *
148
+     * @return bool
149
+     * @since 3.27.6
150
+     */
151
+    if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
152
+        add_action( 'widgets_init', 'wl_register_chord_widget' );
153
+        add_action( 'widgets_init', 'wl_register_geo_widget' );
154
+        add_action( 'widgets_init', 'wl_register_timeline_widget' );
155
+    }
156
+    add_filter( 'widget_text', 'do_shortcode' );
157
+
158
+
159
+    /**
160
+     * Filter: wl_feature__enable__analysis
161
+     *
162
+     * @param bool Whether to send api request to analysis or not
163
+     *
164
+     * @return bool
165
+     * @since 3.27.6
166
+     */
167
+    if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
168
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
169
+    } else {
170
+        add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
171
+    }
172
+
173
+    $plugin = new Wordlift();
174
+    $plugin->run();
175
+
176
+    // Initialize the TTL Cache Cleaner.
177
+    new Ttl_Cache_Cleaner();
178
+
179
+    // Load the new Post Adapter.
180
+    new Post_Adapter();
181
+
182
+    // Load the API Data Hooks.
183
+    new Api_Data_Hooks();
184
+
185
+    add_action( 'plugins_loaded', function () {
186
+        // All features from registry should be initialized here.
187
+        $features_registry = Features_Registry::get_instance();
188
+        $features_registry->initialize_all_features();
189
+    }, 5 );
190
+
191
+    add_action( 'plugins_loaded', function () use ( $plugin ) {
192
+
193
+        new Wordlift_Products_Navigator_Shortcode_REST();
194
+
195
+        // Register the Dataset module, requires `$api_service`.
196
+        require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
197
+        require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
198
+
199
+        /*
200 200
 		 * Require the Entity annotation cleanup module.
201 201
 		 *
202 202
 		 * @since 3.34.6
203 203
 		 */
204
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
204
+        require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
205 205
 
206
-	} );
206
+    } );
207 207
 
208 208
 }
209 209
 
@@ -217,50 +217,50 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function wordlift_plugin_autoload_register() {
219 219
 
220
-	spl_autoload_register( function ( $class_name ) {
220
+    spl_autoload_register( function ( $class_name ) {
221 221
 
222
-		// Bail out if these are not our classes.
223
-		if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
224
-			return false;
225
-		}
222
+        // Bail out if these are not our classes.
223
+        if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
224
+            return false;
225
+        }
226 226
 
227
-		$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
227
+        $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
228 228
 
229
-		preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
229
+        preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
230 230
 
231
-		$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
232
-		$file = 'class-' . $matches[2] . '.php';
231
+        $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
232
+        $file = 'class-' . $matches[2] . '.php';
233 233
 
234
-		$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
234
+        $full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
235 235
 
236
-		if ( ! file_exists( $full_path ) ) {
237
-			echo esc_html( "Class $class_name not found at $full_path." );
236
+        if ( ! file_exists( $full_path ) ) {
237
+            echo esc_html( "Class $class_name not found at $full_path." );
238 238
 
239
-			return false;
240
-		}
239
+            return false;
240
+        }
241 241
 
242
-		require_once $full_path;
242
+        require_once $full_path;
243 243
 
244
-		return true;
245
-	} );
244
+        return true;
245
+    } );
246 246
 
247 247
 }
248 248
 
249 249
 function wl_block_categories( $categories, $post ) {
250
-	return array_merge(
251
-		$categories,
252
-		array(
253
-			array(
254
-				'slug'  => 'wordlift',
255
-				'title' => __( 'WordLift', 'wordlift' ),
256
-			),
257
-		)
258
-	);
250
+    return array_merge(
251
+        $categories,
252
+        array(
253
+            array(
254
+                'slug'  => 'wordlift',
255
+                'title' => __( 'WordLift', 'wordlift' ),
256
+            ),
257
+        )
258
+    );
259 259
 }
260 260
 
261 261
 add_filter( 'block_categories', 'wl_block_categories', 10, 2 );
262 262
 
263 263
 // Temporary fix for a typo in WooCommerce Extension.
264 264
 add_filter( 'wl_feature__enable__dataset', function ( $value ) {
265
-	return apply_filters( 'wl_features__enable__dataset', $value );
265
+    return apply_filters( 'wl_features__enable__dataset', $value );
266 266
 } );
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 use Wordlift\Post\Post_Adapter;
33 33
 
34 34
 // If this file is called directly, abort.
35
-if ( ! defined( 'WPINC' ) ) {
35
+if ( ! defined('WPINC')) {
36 36
 	die;
37 37
 }
38 38
 
@@ -41,11 +41,11 @@  discard block
 block discarded – undo
41 41
  * @since 3.33.6
42 42
  *
43 43
  */
44
-if ( ! apply_filters( 'wl_is_enabled', true ) ) {
44
+if ( ! apply_filters('wl_is_enabled', true)) {
45 45
 	return;
46 46
 }
47 47
 
48
-require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
48
+require_once plugin_dir_path(__FILE__).'vendor/autoload.php';
49 49
 
50 50
 /*
51 51
 	 * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http.
@@ -56,15 +56,15 @@  discard block
 block discarded – undo
56 56
 
57 57
 
58 58
 // Include WordLift constants.
59
-require_once( 'wordlift_constants.php' );
59
+require_once('wordlift_constants.php');
60 60
 
61 61
 // Load modules.
62
-require_once( 'modules/core/wordlift_core.php' );
62
+require_once('modules/core/wordlift_core.php');
63 63
 
64
-require_once( 'deprecations.php' );
64
+require_once('deprecations.php');
65 65
 
66 66
 // Load early to enable/disable features.
67
-require_once plugin_dir_path( __FILE__ ) . 'wordlift/features/index.php';
67
+require_once plugin_dir_path(__FILE__).'wordlift/features/index.php';
68 68
 
69 69
 /**
70 70
  * The code that runs during plugin activation.
@@ -72,11 +72,11 @@  discard block
 block discarded – undo
72 72
  */
73 73
 function activate_wordlift() {
74 74
 
75
-	$log = Wordlift_Log_Service::get_logger( 'activate_wordlift' );
75
+	$log = Wordlift_Log_Service::get_logger('activate_wordlift');
76 76
 
77
-	$log->info( 'Activating WordLift...' );
77
+	$log->info('Activating WordLift...');
78 78
 
79
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php';
79
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php';
80 80
 	Wordlift_Activator::activate();
81 81
 
82 82
 	/**
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
  */
104 104
 function deactivate_wordlift() {
105 105
 
106
-	require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php';
106
+	require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php';
107 107
 	Wordlift_Deactivator::deactivate();
108 108
 	Wordlift_Http_Api::deactivate();
109 109
 	Ttl_Cache_Cleaner::deactivate();
@@ -121,14 +121,14 @@  discard block
 block discarded – undo
121 121
 
122 122
 }
123 123
 
124
-register_activation_hook( __FILE__, 'activate_wordlift' );
125
-register_deactivation_hook( __FILE__, 'deactivate_wordlift' );
124
+register_activation_hook(__FILE__, 'activate_wordlift');
125
+register_deactivation_hook(__FILE__, 'deactivate_wordlift');
126 126
 
127 127
 /**
128 128
  * The core plugin class that is used to define internationalization,
129 129
  * admin-specific hooks, and public-facing site hooks.
130 130
  */
131
-require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php';
131
+require plugin_dir_path(__FILE__).'includes/class-wordlift.php';
132 132
 
133 133
 /**
134 134
  * Begins execution of the plugin.
@@ -148,12 +148,12 @@  discard block
 block discarded – undo
148 148
 	 * @return bool
149 149
 	 * @since 3.27.6
150 150
 	 */
151
-	if ( apply_filters( 'wl_feature__enable__widgets', true ) ) {
152
-		add_action( 'widgets_init', 'wl_register_chord_widget' );
153
-		add_action( 'widgets_init', 'wl_register_geo_widget' );
154
-		add_action( 'widgets_init', 'wl_register_timeline_widget' );
151
+	if (apply_filters('wl_feature__enable__widgets', true)) {
152
+		add_action('widgets_init', 'wl_register_chord_widget');
153
+		add_action('widgets_init', 'wl_register_geo_widget');
154
+		add_action('widgets_init', 'wl_register_timeline_widget');
155 155
 	}
156
-	add_filter( 'widget_text', 'do_shortcode' );
156
+	add_filter('widget_text', 'do_shortcode');
157 157
 
158 158
 
159 159
 	/**
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 	 * @return bool
165 165
 	 * @since 3.27.6
166 166
 	 */
167
-	if ( apply_filters( 'wl_feature__enable__analysis', true ) ) {
168
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' );
167
+	if (apply_filters('wl_feature__enable__analysis', true)) {
168
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action');
169 169
 	} else {
170
-		add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' );
170
+		add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action');
171 171
 	}
172 172
 
173 173
 	$plugin = new Wordlift();
@@ -182,26 +182,26 @@  discard block
 block discarded – undo
182 182
 	// Load the API Data Hooks.
183 183
 	new Api_Data_Hooks();
184 184
 
185
-	add_action( 'plugins_loaded', function () {
185
+	add_action('plugins_loaded', function() {
186 186
 		// All features from registry should be initialized here.
187 187
 		$features_registry = Features_Registry::get_instance();
188 188
 		$features_registry->initialize_all_features();
189
-	}, 5 );
189
+	}, 5);
190 190
 
191
-	add_action( 'plugins_loaded', function () use ( $plugin ) {
191
+	add_action('plugins_loaded', function() use ($plugin) {
192 192
 
193 193
 		new Wordlift_Products_Navigator_Shortcode_REST();
194 194
 
195 195
 		// Register the Dataset module, requires `$api_service`.
196
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/dataset/index.php';
197
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/shipping-data/index.php';
196
+		require_once plugin_dir_path(__FILE__).'wordlift/dataset/index.php';
197
+		require_once plugin_dir_path(__FILE__).'wordlift/shipping-data/index.php';
198 198
 
199 199
 		/*
200 200
 		 * Require the Entity annotation cleanup module.
201 201
 		 *
202 202
 		 * @since 3.34.6
203 203
 		 */
204
-		require_once plugin_dir_path( __FILE__ ) . 'wordlift/cleanup/index.php';
204
+		require_once plugin_dir_path(__FILE__).'wordlift/cleanup/index.php';
205 205
 
206 206
 	} );
207 207
 
@@ -217,24 +217,24 @@  discard block
 block discarded – undo
217 217
  */
218 218
 function wordlift_plugin_autoload_register() {
219 219
 
220
-	spl_autoload_register( function ( $class_name ) {
220
+	spl_autoload_register(function($class_name) {
221 221
 
222 222
 		// Bail out if these are not our classes.
223
-		if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) {
223
+		if (0 !== strpos($class_name, 'Wordlift\\')) {
224 224
 			return false;
225 225
 		}
226 226
 
227
-		$class_name_lc = strtolower( str_replace( '_', '-', $class_name ) );
227
+		$class_name_lc = strtolower(str_replace('_', '-', $class_name));
228 228
 
229
-		preg_match( '|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches );
229
+		preg_match('|^(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches);
230 230
 
231
-		$path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] );
232
-		$file = 'class-' . $matches[2] . '.php';
231
+		$path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]);
232
+		$file = 'class-'.$matches[2].'.php';
233 233
 
234
-		$full_path = plugin_dir_path( __FILE__ ) . $path . DIRECTORY_SEPARATOR . $file;
234
+		$full_path = plugin_dir_path(__FILE__).$path.DIRECTORY_SEPARATOR.$file;
235 235
 
236
-		if ( ! file_exists( $full_path ) ) {
237
-			echo esc_html( "Class $class_name not found at $full_path." );
236
+		if ( ! file_exists($full_path)) {
237
+			echo esc_html("Class $class_name not found at $full_path.");
238 238
 
239 239
 			return false;
240 240
 		}
@@ -246,21 +246,21 @@  discard block
 block discarded – undo
246 246
 
247 247
 }
248 248
 
249
-function wl_block_categories( $categories, $post ) {
249
+function wl_block_categories($categories, $post) {
250 250
 	return array_merge(
251 251
 		$categories,
252 252
 		array(
253 253
 			array(
254 254
 				'slug'  => 'wordlift',
255
-				'title' => __( 'WordLift', 'wordlift' ),
255
+				'title' => __('WordLift', 'wordlift'),
256 256
 			),
257 257
 		)
258 258
 	);
259 259
 }
260 260
 
261
-add_filter( 'block_categories', 'wl_block_categories', 10, 2 );
261
+add_filter('block_categories', 'wl_block_categories', 10, 2);
262 262
 
263 263
 // Temporary fix for a typo in WooCommerce Extension.
264
-add_filter( 'wl_feature__enable__dataset', function ( $value ) {
265
-	return apply_filters( 'wl_features__enable__dataset', $value );
264
+add_filter('wl_feature__enable__dataset', function($value) {
265
+	return apply_filters('wl_features__enable__dataset', $value);
266 266
 } );
Please login to merge, or discard this patch.
src/wordlift/task/class-all-posts-task.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -11,46 +11,46 @@
 block discarded – undo
11 11
 
12 12
 class All_Posts_Task implements Task {
13 13
 
14
-	private $callable;
15
-
16
-	public function __construct( $callable ) {
17
-		$this->callable = $callable;
18
-	}
19
-
20
-	public function starting() {
21
-		global $wpdb;
22
-
23
-		// Try to get the count from transient, or load it from database.
24
-		if ( false === ( $count = get_transient( '_wl_task__all_posts_task__count' ) ) ) {
25
-			$count = $wpdb->get_var( "SELECT COUNT( 1 ) FROM $wpdb->posts" );
26
-			set_transient( '_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS );
27
-		}
28
-
29
-		return $count;
30
-	}
31
-
32
-	/**
33
-	 * @param $value mixed The incoming value.
34
-	 * @param $args {
35
-	 *
36
-	 * @type int $offset The index of the current item.
37
-	 * @type int $count The total number of items as provided by the `starting` function.
38
-	 * @type int $batch_size The number of items to process within this call.
39
-	 * }
40
-	 *
41
-	 * @return void
42
-	 */
43
-	public function tick( $value, $args ) {
44
-		global $wpdb;
45
-
46
-		$ids = $wpdb->get_col( $wpdb->prepare( "
14
+    private $callable;
15
+
16
+    public function __construct( $callable ) {
17
+        $this->callable = $callable;
18
+    }
19
+
20
+    public function starting() {
21
+        global $wpdb;
22
+
23
+        // Try to get the count from transient, or load it from database.
24
+        if ( false === ( $count = get_transient( '_wl_task__all_posts_task__count' ) ) ) {
25
+            $count = $wpdb->get_var( "SELECT COUNT( 1 ) FROM $wpdb->posts" );
26
+            set_transient( '_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS );
27
+        }
28
+
29
+        return $count;
30
+    }
31
+
32
+    /**
33
+     * @param $value mixed The incoming value.
34
+     * @param $args {
35
+     *
36
+     * @type int $offset The index of the current item.
37
+     * @type int $count The total number of items as provided by the `starting` function.
38
+     * @type int $batch_size The number of items to process within this call.
39
+     * }
40
+     *
41
+     * @return void
42
+     */
43
+    public function tick( $value, $args ) {
44
+        global $wpdb;
45
+
46
+        $ids = $wpdb->get_col( $wpdb->prepare( "
47 47
 			SELECT ID FROM wp_posts ORDER BY ID LIMIT %d,%d;
48 48
 		", $args['offset'], $args['batch_size'] ) );
49 49
 
50
-		foreach ( $ids as $id ) {
51
-			call_user_func( $this->callable, $id );
52
-		}
50
+        foreach ( $ids as $id ) {
51
+            call_user_func( $this->callable, $id );
52
+        }
53 53
 
54
-	}
54
+    }
55 55
 
56 56
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 	private $callable;
15 15
 
16
-	public function __construct( $callable ) {
16
+	public function __construct($callable) {
17 17
 		$this->callable = $callable;
18 18
 	}
19 19
 
@@ -21,9 +21,9 @@  discard block
 block discarded – undo
21 21
 		global $wpdb;
22 22
 
23 23
 		// Try to get the count from transient, or load it from database.
24
-		if ( false === ( $count = get_transient( '_wl_task__all_posts_task__count' ) ) ) {
25
-			$count = $wpdb->get_var( "SELECT COUNT( 1 ) FROM $wpdb->posts" );
26
-			set_transient( '_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS );
24
+		if (false === ($count = get_transient('_wl_task__all_posts_task__count'))) {
25
+			$count = $wpdb->get_var("SELECT COUNT( 1 ) FROM $wpdb->posts");
26
+			set_transient('_wl_task__all_posts_task__count', $count, HOUR_IN_SECONDS);
27 27
 		}
28 28
 
29 29
 		return $count;
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
 	 *
41 41
 	 * @return void
42 42
 	 */
43
-	public function tick( $value, $args ) {
43
+	public function tick($value, $args) {
44 44
 		global $wpdb;
45 45
 
46
-		$ids = $wpdb->get_col( $wpdb->prepare( "
46
+		$ids = $wpdb->get_col($wpdb->prepare("
47 47
 			SELECT ID FROM wp_posts ORDER BY ID LIMIT %d,%d;
48
-		", $args['offset'], $args['batch_size'] ) );
48
+		", $args['offset'], $args['batch_size']));
49 49
 
50
-		foreach ( $ids as $id ) {
51
-			call_user_func( $this->callable, $id );
50
+		foreach ($ids as $id) {
51
+			call_user_func($this->callable, $id);
52 52
 		}
53 53
 
54 54
 	}
Please login to merge, or discard this patch.
src/wordlift/task/background/class-background-task-route.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -8,71 +8,71 @@
 block discarded – undo
8 8
 
9 9
 class Background_Task_Route {
10 10
 
11
-	const VERSION_STRING = 'wordlift/v1';
12
-
13
-	/**
14
-	 * @var Background_Task
15
-	 */
16
-	private $background_task;
17
-
18
-	/**
19
-	 * @var string
20
-	 */
21
-	private $route_name;
22
-
23
-	public function __construct( $background_task, $route_name ) {
24
-		$this->background_task = $background_task;
25
-		$this->route_name      = $route_name;
26
-	}
27
-
28
-	public static function create( $task, $route_name ) {
29
-		$route = new self( $task, $route_name );
30
-
31
-		add_action( 'rest_api_init', array( $route, 'register' ) );
32
-
33
-		return $route;
34
-	}
35
-
36
-	/**
37
-	 * @throws Exception if the input value is invalid.
38
-	 */
39
-	public function register() {
40
-		Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' );
41
-
42
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
43
-			'methods'             => WP_REST_Server::CREATABLE,
44
-			'callback'            => array( $this->background_task, 'start' ),
45
-			'permission_callback' => array( $this, 'permission_callback' ),
46
-		) );
47
-
48
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
49
-			'methods'             => WP_REST_Server::READABLE,
50
-			'callback'            => array( $this->background_task, 'get_info' ),
51
-			'permission_callback' => array( $this, 'permission_callback' ),
52
-		) );
53
-
54
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
55
-			'methods'             => WP_REST_Server::DELETABLE,
56
-			'callback'            => array( $this->background_task, 'stop' ),
57
-			'permission_callback' => array( $this, 'permission_callback' ),
58
-		) );
59
-
60
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
61
-			'methods'             => 'PUT',
62
-			'callback'            => array( $this->background_task, 'resume' ),
63
-			'permission_callback' => array( $this, 'permission_callback' ),
64
-		) );
65
-
66
-	}
67
-
68
-	public function permission_callback() {
69
-		$user = wp_get_current_user();
70
-
71
-		return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
72
-	}
73
-
74
-	public function get_rest_path() {
75
-		return self::VERSION_STRING . $this->route_name;
76
-	}
11
+    const VERSION_STRING = 'wordlift/v1';
12
+
13
+    /**
14
+     * @var Background_Task
15
+     */
16
+    private $background_task;
17
+
18
+    /**
19
+     * @var string
20
+     */
21
+    private $route_name;
22
+
23
+    public function __construct( $background_task, $route_name ) {
24
+        $this->background_task = $background_task;
25
+        $this->route_name      = $route_name;
26
+    }
27
+
28
+    public static function create( $task, $route_name ) {
29
+        $route = new self( $task, $route_name );
30
+
31
+        add_action( 'rest_api_init', array( $route, 'register' ) );
32
+
33
+        return $route;
34
+    }
35
+
36
+    /**
37
+     * @throws Exception if the input value is invalid.
38
+     */
39
+    public function register() {
40
+        Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' );
41
+
42
+        register_rest_route( self::VERSION_STRING, $this->route_name, array(
43
+            'methods'             => WP_REST_Server::CREATABLE,
44
+            'callback'            => array( $this->background_task, 'start' ),
45
+            'permission_callback' => array( $this, 'permission_callback' ),
46
+        ) );
47
+
48
+        register_rest_route( self::VERSION_STRING, $this->route_name, array(
49
+            'methods'             => WP_REST_Server::READABLE,
50
+            'callback'            => array( $this->background_task, 'get_info' ),
51
+            'permission_callback' => array( $this, 'permission_callback' ),
52
+        ) );
53
+
54
+        register_rest_route( self::VERSION_STRING, $this->route_name, array(
55
+            'methods'             => WP_REST_Server::DELETABLE,
56
+            'callback'            => array( $this->background_task, 'stop' ),
57
+            'permission_callback' => array( $this, 'permission_callback' ),
58
+        ) );
59
+
60
+        register_rest_route( self::VERSION_STRING, $this->route_name, array(
61
+            'methods'             => 'PUT',
62
+            'callback'            => array( $this->background_task, 'resume' ),
63
+            'permission_callback' => array( $this, 'permission_callback' ),
64
+        ) );
65
+
66
+    }
67
+
68
+    public function permission_callback() {
69
+        $user = wp_get_current_user();
70
+
71
+        return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
72
+    }
73
+
74
+    public function get_rest_path() {
75
+        return self::VERSION_STRING . $this->route_name;
76
+    }
77 77
 
78 78
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -20,15 +20,15 @@  discard block
 block discarded – undo
20 20
 	 */
21 21
 	private $route_name;
22 22
 
23
-	public function __construct( $background_task, $route_name ) {
23
+	public function __construct($background_task, $route_name) {
24 24
 		$this->background_task = $background_task;
25 25
 		$this->route_name      = $route_name;
26 26
 	}
27 27
 
28
-	public static function create( $task, $route_name ) {
29
-		$route = new self( $task, $route_name );
28
+	public static function create($task, $route_name) {
29
+		$route = new self($task, $route_name);
30 30
 
31
-		add_action( 'rest_api_init', array( $route, 'register' ) );
31
+		add_action('rest_api_init', array($route, 'register'));
32 32
 
33 33
 		return $route;
34 34
 	}
@@ -37,42 +37,42 @@  discard block
 block discarded – undo
37 37
 	 * @throws Exception if the input value is invalid.
38 38
 	 */
39 39
 	public function register() {
40
-		Assertions::starts_with( $this->route_name, '/', 'The route name must start with a slash.' );
40
+		Assertions::starts_with($this->route_name, '/', 'The route name must start with a slash.');
41 41
 
42
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
42
+		register_rest_route(self::VERSION_STRING, $this->route_name, array(
43 43
 			'methods'             => WP_REST_Server::CREATABLE,
44
-			'callback'            => array( $this->background_task, 'start' ),
45
-			'permission_callback' => array( $this, 'permission_callback' ),
46
-		) );
44
+			'callback'            => array($this->background_task, 'start'),
45
+			'permission_callback' => array($this, 'permission_callback'),
46
+		));
47 47
 
48
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
48
+		register_rest_route(self::VERSION_STRING, $this->route_name, array(
49 49
 			'methods'             => WP_REST_Server::READABLE,
50
-			'callback'            => array( $this->background_task, 'get_info' ),
51
-			'permission_callback' => array( $this, 'permission_callback' ),
52
-		) );
50
+			'callback'            => array($this->background_task, 'get_info'),
51
+			'permission_callback' => array($this, 'permission_callback'),
52
+		));
53 53
 
54
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
54
+		register_rest_route(self::VERSION_STRING, $this->route_name, array(
55 55
 			'methods'             => WP_REST_Server::DELETABLE,
56
-			'callback'            => array( $this->background_task, 'stop' ),
57
-			'permission_callback' => array( $this, 'permission_callback' ),
58
-		) );
56
+			'callback'            => array($this->background_task, 'stop'),
57
+			'permission_callback' => array($this, 'permission_callback'),
58
+		));
59 59
 
60
-		register_rest_route( self::VERSION_STRING, $this->route_name, array(
60
+		register_rest_route(self::VERSION_STRING, $this->route_name, array(
61 61
 			'methods'             => 'PUT',
62
-			'callback'            => array( $this->background_task, 'resume' ),
63
-			'permission_callback' => array( $this, 'permission_callback' ),
64
-		) );
62
+			'callback'            => array($this->background_task, 'resume'),
63
+			'permission_callback' => array($this, 'permission_callback'),
64
+		));
65 65
 
66 66
 	}
67 67
 
68 68
 	public function permission_callback() {
69 69
 		$user = wp_get_current_user();
70 70
 
71
-		return is_super_admin( $user->ID ) || in_array( 'administrator', (array) $user->roles );
71
+		return is_super_admin($user->ID) || in_array('administrator', (array) $user->roles);
72 72
 	}
73 73
 
74 74
 	public function get_rest_path() {
75
-		return self::VERSION_STRING . $this->route_name;
75
+		return self::VERSION_STRING.$this->route_name;
76 76
 	}
77 77
 
78 78
 }
Please login to merge, or discard this patch.
src/wordlift/task/background/class-background-task-page.php 2 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -8,63 +8,63 @@  discard block
 block discarded – undo
8 8
 
9 9
 class Background_Task_Page {
10 10
 
11
-	private $title;
12
-
13
-	private $menu_slug;
14
-
15
-	/**
16
-	 * @var Background_Task_Route $background_task_route
17
-	 */
18
-	private $background_task_route;
19
-
20
-	/**
21
-	 * @throws Exception if one or more parameters are invalid.
22
-	 */
23
-	public function __construct( $title, $menu_slug, $background_task_route ) {
24
-		Assertions::not_empty( $title, '`$title` cannot be empty.' );
25
-		Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' );
26
-		Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' );
27
-
28
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
29
-
30
-		$this->title                 = $title;
31
-		$this->menu_slug             = $menu_slug;
32
-		$this->background_task_route = $background_task_route;
33
-	}
34
-
35
-	/**
36
-	 * @throws Exception if one or more parameters are invalid.
37
-	 */
38
-	public static function create( $title, $menu_slug, $background_route ) {
39
-		return new self( $title, $menu_slug, $background_route );
40
-	}
41
-
42
-	public function admin_menu() {
43
-
44
-		add_submenu_page( 'wl_admin_menu', $this->title, $this->title, 'manage_options', $this->menu_slug, array(
45
-			$this,
46
-			'render'
47
-		) );
48
-
49
-	}
50
-
51
-	public function render() {
52
-
53
-		wp_enqueue_style(
54
-			'wl-task-page',
55
-			plugin_dir_url( __FILE__ ) . 'assets/task-page.css',
56
-			array(),
57
-			Wordlift::get_instance()->get_version(),
58
-			'all' );
59
-
60
-		wp_enqueue_script(
61
-			'wl-task-page',
62
-			plugin_dir_url( __FILE__ ) . 'assets/task-page.js',
63
-			array( 'wp-api' ),
64
-			Wordlift::get_instance()->get_version() );
65
-
66
-		wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) );
67
-		?>
11
+    private $title;
12
+
13
+    private $menu_slug;
14
+
15
+    /**
16
+     * @var Background_Task_Route $background_task_route
17
+     */
18
+    private $background_task_route;
19
+
20
+    /**
21
+     * @throws Exception if one or more parameters are invalid.
22
+     */
23
+    public function __construct( $title, $menu_slug, $background_task_route ) {
24
+        Assertions::not_empty( $title, '`$title` cannot be empty.' );
25
+        Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' );
26
+        Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' );
27
+
28
+        add_action( 'admin_menu', array( $this, 'admin_menu' ) );
29
+
30
+        $this->title                 = $title;
31
+        $this->menu_slug             = $menu_slug;
32
+        $this->background_task_route = $background_task_route;
33
+    }
34
+
35
+    /**
36
+     * @throws Exception if one or more parameters are invalid.
37
+     */
38
+    public static function create( $title, $menu_slug, $background_route ) {
39
+        return new self( $title, $menu_slug, $background_route );
40
+    }
41
+
42
+    public function admin_menu() {
43
+
44
+        add_submenu_page( 'wl_admin_menu', $this->title, $this->title, 'manage_options', $this->menu_slug, array(
45
+            $this,
46
+            'render'
47
+        ) );
48
+
49
+    }
50
+
51
+    public function render() {
52
+
53
+        wp_enqueue_style(
54
+            'wl-task-page',
55
+            plugin_dir_url( __FILE__ ) . 'assets/task-page.css',
56
+            array(),
57
+            Wordlift::get_instance()->get_version(),
58
+            'all' );
59
+
60
+        wp_enqueue_script(
61
+            'wl-task-page',
62
+            plugin_dir_url( __FILE__ ) . 'assets/task-page.js',
63
+            array( 'wp-api' ),
64
+            Wordlift::get_instance()->get_version() );
65
+
66
+        wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) );
67
+        ?>
68 68
         <div class="wrap">
69 69
             <h2><?php echo esc_html( $this->title ); ?></h2>
70 70
 
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
             </div>
75 75
 
76 76
             <button id="wl-start-btn" type="button" class="button button-large button-primary"><?php
77
-				esc_html_e( 'Start', 'wordlift-framework' ); ?></button>
77
+                esc_html_e( 'Start', 'wordlift-framework' ); ?></button>
78 78
             <button id="wl-stop-btn" type="button" class="button button-large button-primary hidden"><?php
79
-				esc_html_e( 'Stop', 'wordlift-framework' ); ?></button>
79
+                esc_html_e( 'Stop', 'wordlift-framework' ); ?></button>
80 80
 
81 81
         </div>
82 82
 		<?php
83
-	}
83
+    }
84 84
 
85 85
 }
86 86
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 	/**
21 21
 	 * @throws Exception if one or more parameters are invalid.
22 22
 	 */
23
-	public function __construct( $title, $menu_slug, $background_task_route ) {
24
-		Assertions::not_empty( $title, '`$title` cannot be empty.' );
25
-		Assertions::not_empty( $menu_slug, '`$menu_slug` cannot be empty.' );
26
-		Assertions::is_a( $background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.' );
23
+	public function __construct($title, $menu_slug, $background_task_route) {
24
+		Assertions::not_empty($title, '`$title` cannot be empty.');
25
+		Assertions::not_empty($menu_slug, '`$menu_slug` cannot be empty.');
26
+		Assertions::is_a($background_task_route, 'Wordlift\Task\Background\Background_Task_Route', '`Background_Task_Route` must be of type `Wordlift\Task\Background\Background_Route`.');
27 27
 
28
-		add_action( 'admin_menu', array( $this, 'admin_menu' ) );
28
+		add_action('admin_menu', array($this, 'admin_menu'));
29 29
 
30 30
 		$this->title                 = $title;
31 31
 		$this->menu_slug             = $menu_slug;
@@ -35,16 +35,16 @@  discard block
 block discarded – undo
35 35
 	/**
36 36
 	 * @throws Exception if one or more parameters are invalid.
37 37
 	 */
38
-	public static function create( $title, $menu_slug, $background_route ) {
39
-		return new self( $title, $menu_slug, $background_route );
38
+	public static function create($title, $menu_slug, $background_route) {
39
+		return new self($title, $menu_slug, $background_route);
40 40
 	}
41 41
 
42 42
 	public function admin_menu() {
43 43
 
44
-		add_submenu_page( 'wl_admin_menu', $this->title, $this->title, 'manage_options', $this->menu_slug, array(
44
+		add_submenu_page('wl_admin_menu', $this->title, $this->title, 'manage_options', $this->menu_slug, array(
45 45
 			$this,
46 46
 			'render'
47
-		) );
47
+		));
48 48
 
49 49
 	}
50 50
 
@@ -52,21 +52,21 @@  discard block
 block discarded – undo
52 52
 
53 53
 		wp_enqueue_style(
54 54
 			'wl-task-page',
55
-			plugin_dir_url( __FILE__ ) . 'assets/task-page.css',
55
+			plugin_dir_url(__FILE__).'assets/task-page.css',
56 56
 			array(),
57 57
 			Wordlift::get_instance()->get_version(),
58 58
 			'all' );
59 59
 
60 60
 		wp_enqueue_script(
61 61
 			'wl-task-page',
62
-			plugin_dir_url( __FILE__ ) . 'assets/task-page.js',
63
-			array( 'wp-api' ),
62
+			plugin_dir_url(__FILE__).'assets/task-page.js',
63
+			array('wp-api'),
64 64
 			Wordlift::get_instance()->get_version() );
65 65
 
66
-		wp_localize_script( 'wl-task-page', '_wlTaskPageSettings', array( 'rest_path' => $this->background_task_route->get_rest_path() ) );
66
+		wp_localize_script('wl-task-page', '_wlTaskPageSettings', array('rest_path' => $this->background_task_route->get_rest_path()));
67 67
 		?>
68 68
         <div class="wrap">
69
-            <h2><?php echo esc_html( $this->title ); ?></h2>
69
+            <h2><?php echo esc_html($this->title); ?></h2>
70 70
 
71 71
             <div class="wl-task__progress" style="border: 1px solid #23282D; height: 20px; margin: 8px 0;">
72 72
                 <div class="wl-task__progress__bar"
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
             </div>
75 75
 
76 76
             <button id="wl-start-btn" type="button" class="button button-large button-primary"><?php
77
-				esc_html_e( 'Start', 'wordlift-framework' ); ?></button>
77
+				esc_html_e('Start', 'wordlift-framework'); ?></button>
78 78
             <button id="wl-stop-btn" type="button" class="button button-large button-primary hidden"><?php
79
-				esc_html_e( 'Stop', 'wordlift-framework' ); ?></button>
79
+				esc_html_e('Stop', 'wordlift-framework'); ?></button>
80 80
 
81 81
         </div>
82 82
 		<?php
Please login to merge, or discard this patch.
src/wordlift/task/background/class-background-task-state.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
4 4
 
5 5
 interface Background_Task_State {
6 6
 
7
-	function enter();
8
-
9
-	function leave();
10
-
11
-	/**
12
-	 * Task
13
-	 *
14
-	 * Override this method to perform any actions required on each
15
-	 * queue item. Return the modified item for further processing
16
-	 * in the next pass through. Or, return false to remove the
17
-	 * item from the queue.
18
-	 *
19
-	 * @param mixed $item Queue item to iterate over.
20
-	 *
21
-	 * @return mixed
22
-	 */
23
-	function task( $item );
24
-
25
-	function get_info();
26
-
27
-	/**
28
-	 * Try to resume an interrupted task.
29
-	 */
30
-	function resume();
7
+    function enter();
8
+
9
+    function leave();
10
+
11
+    /**
12
+     * Task
13
+     *
14
+     * Override this method to perform any actions required on each
15
+     * queue item. Return the modified item for further processing
16
+     * in the next pass through. Or, return false to remove the
17
+     * item from the queue.
18
+     *
19
+     * @param mixed $item Queue item to iterate over.
20
+     *
21
+     * @return mixed
22
+     */
23
+    function task( $item );
24
+
25
+    function get_info();
26
+
27
+    /**
28
+     * Try to resume an interrupted task.
29
+     */
30
+    function resume();
31 31
 
32 32
 }
33 33
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 	 *
21 21
 	 * @return mixed
22 22
 	 */
23
-	function task( $item );
23
+	function task($item);
24 24
 
25 25
 	function get_info();
26 26
 
Please login to merge, or discard this patch.
src/wordlift/task/background/class-background-task-started-state.php 2 patches
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -4,76 +4,76 @@
 block discarded – undo
4 4
 
5 5
 class Background_Task_Started_State extends Abstract_Background_Task_State {
6 6
 
7
-	/**
8
-	 * @var Background_Task
9
-	 */
10
-	private $context;
7
+    /**
8
+     * @var Background_Task
9
+     */
10
+    private $context;
11 11
 
12
-	private $batch_size = 5;
12
+    private $batch_size = 5;
13 13
 
14
-	/**
15
-	 * @var Task
16
-	 */
17
-	private $task;
14
+    /**
15
+     * @var Task
16
+     */
17
+    private $task;
18 18
 
19
-	/**
20
-	 * Back_Started_State constructor.
21
-	 *
22
-	 * @param Background_Task $context
23
-	 */
24
-	function __construct( $context, $task ) {
25
-		parent::__construct( $context, Background_Task::STATE_STARTED );
19
+    /**
20
+     * Back_Started_State constructor.
21
+     *
22
+     * @param Background_Task $context
23
+     */
24
+    function __construct( $context, $task ) {
25
+        parent::__construct( $context, Background_Task::STATE_STARTED );
26 26
 
27
-		$this->context = $context;
28
-		$this->task    = $task;
29
-	}
27
+        $this->context = $context;
28
+        $this->task    = $task;
29
+    }
30 30
 
31
-	function enter() {
31
+    function enter() {
32 32
 
33
-		$count = $this->task->starting();
33
+        $count = $this->task->starting();
34 34
 
35
-		update_option( $this->context->get_option_prefix() . 'count', $count, true );
36
-		update_option( $this->context->get_option_prefix() . 'offset', 0, true );
37
-		update_option( $this->context->get_option_prefix() . 'started', time(), true );
38
-		update_option( $this->context->get_option_prefix() . 'updated', time(), true );
35
+        update_option( $this->context->get_option_prefix() . 'count', $count, true );
36
+        update_option( $this->context->get_option_prefix() . 'offset', 0, true );
37
+        update_option( $this->context->get_option_prefix() . 'started', time(), true );
38
+        update_option( $this->context->get_option_prefix() . 'updated', time(), true );
39 39
 
40
-		$this->context->set_state( Background_Task::STATE_STARTED );
40
+        $this->context->set_state( Background_Task::STATE_STARTED );
41 41
 
42
-		$this->resume();
43
-	}
42
+        $this->resume();
43
+    }
44 44
 
45
-	function resume() {
46
-		$this->context->push_to_queue( true );
47
-		$this->context->save()->dispatch();
48
-	}
45
+    function resume() {
46
+        $this->context->push_to_queue( true );
47
+        $this->context->save()->dispatch();
48
+    }
49 49
 
50
-	function leave() {
51
-		$this->context->set_state( null );
52
-	}
50
+    function leave() {
51
+        $this->context->set_state( null );
52
+    }
53 53
 
54
-	function task( $value ) {
55
-		$offset = get_option( $this->context->get_option_prefix() . 'offset' );
56
-		$count  = get_option( $this->context->get_option_prefix() . 'count' );
54
+    function task( $value ) {
55
+        $offset = get_option( $this->context->get_option_prefix() . 'offset' );
56
+        $count  = get_option( $this->context->get_option_prefix() . 'count' );
57 57
 
58
-		$this->task->tick( $value, array(
59
-			'offset'     => $offset,
60
-			'count'      => $count,
61
-			'batch_size' => $this->batch_size,
62
-		) );
58
+        $this->task->tick( $value, array(
59
+            'offset'     => $offset,
60
+            'count'      => $count,
61
+            'batch_size' => $this->batch_size,
62
+        ) );
63 63
 
64
-		update_option( $this->context->get_option_prefix() . 'updated', time(), true );
64
+        update_option( $this->context->get_option_prefix() . 'updated', time(), true );
65 65
 
66
-		// Increase the offset.
67
-		if ( ( $offset + $this->batch_size ) < $count ) {
68
-			update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true );
66
+        // Increase the offset.
67
+        if ( ( $offset + $this->batch_size ) < $count ) {
68
+            update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true );
69 69
 
70
-			return true;
71
-		}
70
+            return true;
71
+        }
72 72
 
73
-		// Stop processing.
74
-		$this->context->stop();
73
+        // Stop processing.
74
+        $this->context->stop();
75 75
 
76
-		return false;
77
-	}
76
+        return false;
77
+    }
78 78
 
79 79
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param Background_Task $context
23 23
 	 */
24
-	function __construct( $context, $task ) {
25
-		parent::__construct( $context, Background_Task::STATE_STARTED );
24
+	function __construct($context, $task) {
25
+		parent::__construct($context, Background_Task::STATE_STARTED);
26 26
 
27 27
 		$this->context = $context;
28 28
 		$this->task    = $task;
@@ -32,40 +32,40 @@  discard block
 block discarded – undo
32 32
 
33 33
 		$count = $this->task->starting();
34 34
 
35
-		update_option( $this->context->get_option_prefix() . 'count', $count, true );
36
-		update_option( $this->context->get_option_prefix() . 'offset', 0, true );
37
-		update_option( $this->context->get_option_prefix() . 'started', time(), true );
38
-		update_option( $this->context->get_option_prefix() . 'updated', time(), true );
35
+		update_option($this->context->get_option_prefix().'count', $count, true);
36
+		update_option($this->context->get_option_prefix().'offset', 0, true);
37
+		update_option($this->context->get_option_prefix().'started', time(), true);
38
+		update_option($this->context->get_option_prefix().'updated', time(), true);
39 39
 
40
-		$this->context->set_state( Background_Task::STATE_STARTED );
40
+		$this->context->set_state(Background_Task::STATE_STARTED);
41 41
 
42 42
 		$this->resume();
43 43
 	}
44 44
 
45 45
 	function resume() {
46
-		$this->context->push_to_queue( true );
46
+		$this->context->push_to_queue(true);
47 47
 		$this->context->save()->dispatch();
48 48
 	}
49 49
 
50 50
 	function leave() {
51
-		$this->context->set_state( null );
51
+		$this->context->set_state(null);
52 52
 	}
53 53
 
54
-	function task( $value ) {
55
-		$offset = get_option( $this->context->get_option_prefix() . 'offset' );
56
-		$count  = get_option( $this->context->get_option_prefix() . 'count' );
54
+	function task($value) {
55
+		$offset = get_option($this->context->get_option_prefix().'offset');
56
+		$count  = get_option($this->context->get_option_prefix().'count');
57 57
 
58
-		$this->task->tick( $value, array(
58
+		$this->task->tick($value, array(
59 59
 			'offset'     => $offset,
60 60
 			'count'      => $count,
61 61
 			'batch_size' => $this->batch_size,
62
-		) );
62
+		));
63 63
 
64
-		update_option( $this->context->get_option_prefix() . 'updated', time(), true );
64
+		update_option($this->context->get_option_prefix().'updated', time(), true);
65 65
 
66 66
 		// Increase the offset.
67
-		if ( ( $offset + $this->batch_size ) < $count ) {
68
-			update_option( $this->context->get_option_prefix() . 'offset', $offset + $this->batch_size, true );
67
+		if (($offset + $this->batch_size) < $count) {
68
+			update_option($this->context->get_option_prefix().'offset', $offset + $this->batch_size, true);
69 69
 
70 70
 			return true;
71 71
 		}
Please login to merge, or discard this patch.
src/wordlift/task/background/class-background-task-info.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -4,27 +4,27 @@
 block discarded – undo
4 4
 
5 5
 class Background_Task_Info {
6 6
 
7
-	public $started;
8
-	public $index;
9
-	public $count;
10
-	public $last_update;
11
-	public $state;
7
+    public $started;
8
+    public $index;
9
+    public $count;
10
+    public $last_update;
11
+    public $state;
12 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( $state, $started = null, $index = null, $count = null, $last_update = null ) {
23
-		$this->started     = $started;
24
-		$this->index       = $index;
25
-		$this->count       = (int) $count;
26
-		$this->last_update = $last_update;
27
-		$this->state       = $state;
28
-	}
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( $state, $started = null, $index = null, $count = null, $last_update = null ) {
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 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@
 block discarded – undo
19 19
 	 * @param $last_update
20 20
 	 * @param $state
21 21
 	 */
22
-	public function __construct( $state, $started = null, $index = null, $count = null, $last_update = null ) {
22
+	public function __construct($state, $started = null, $index = null, $count = null, $last_update = null) {
23 23
 		$this->started     = $started;
24 24
 		$this->index       = $index;
25 25
 		$this->count       = (int) $count;
Please login to merge, or discard this patch.
src/wordlift/task/background/class-abstract-background-task-state.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,33 +4,33 @@
 block discarded – undo
4 4
 
5 5
 abstract class Abstract_Background_Task_State implements Background_Task_State {
6 6
 
7
-	/**
8
-	 * @var Background_Task_State
9
-	 */
10
-	private $state;
11
-
12
-	/**
13
-	 * @var Background_Task
14
-	 */
15
-	private $context;
16
-
17
-	function __construct( $context, $state ) {
18
-		$this->state   = $state;
19
-		$this->context = $context;
20
-	}
21
-
22
-	function get_info() {
23
-		$started     = get_option( $this->context->get_option_prefix() . 'started' );
24
-		$offset      = get_option( $this->context->get_option_prefix() . 'offset' );
25
-		$count       = get_option( $this->context->get_option_prefix() . 'count', array( 0 ) );
26
-		$last_update = get_option( $this->context->get_option_prefix() . 'updated' );
27
-
28
-
29
-		return new Background_Task_Info( $this->state, $started, $offset, $count, $last_update );
30
-	}
31
-
32
-	function resume() {
33
-		// do nothing.
34
-	}
7
+    /**
8
+     * @var Background_Task_State
9
+     */
10
+    private $state;
11
+
12
+    /**
13
+     * @var Background_Task
14
+     */
15
+    private $context;
16
+
17
+    function __construct( $context, $state ) {
18
+        $this->state   = $state;
19
+        $this->context = $context;
20
+    }
21
+
22
+    function get_info() {
23
+        $started     = get_option( $this->context->get_option_prefix() . 'started' );
24
+        $offset      = get_option( $this->context->get_option_prefix() . 'offset' );
25
+        $count       = get_option( $this->context->get_option_prefix() . 'count', array( 0 ) );
26
+        $last_update = get_option( $this->context->get_option_prefix() . 'updated' );
27
+
28
+
29
+        return new Background_Task_Info( $this->state, $started, $offset, $count, $last_update );
30
+    }
31
+
32
+    function resume() {
33
+        // do nothing.
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,19 +14,19 @@
 block discarded – undo
14 14
 	 */
15 15
 	private $context;
16 16
 
17
-	function __construct( $context, $state ) {
17
+	function __construct($context, $state) {
18 18
 		$this->state   = $state;
19 19
 		$this->context = $context;
20 20
 	}
21 21
 
22 22
 	function get_info() {
23
-		$started     = get_option( $this->context->get_option_prefix() . 'started' );
24
-		$offset      = get_option( $this->context->get_option_prefix() . 'offset' );
25
-		$count       = get_option( $this->context->get_option_prefix() . 'count', array( 0 ) );
26
-		$last_update = get_option( $this->context->get_option_prefix() . 'updated' );
23
+		$started     = get_option($this->context->get_option_prefix().'started');
24
+		$offset      = get_option($this->context->get_option_prefix().'offset');
25
+		$count       = get_option($this->context->get_option_prefix().'count', array(0));
26
+		$last_update = get_option($this->context->get_option_prefix().'updated');
27 27
 
28 28
 
29
-		return new Background_Task_Info( $this->state, $started, $offset, $count, $last_update );
29
+		return new Background_Task_Info($this->state, $started, $offset, $count, $last_update);
30 30
 	}
31 31
 
32 32
 	function resume() {
Please login to merge, or discard this patch.
src/wordlift/task/background/class-background-task.php 2 patches
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -7,119 +7,119 @@
 block discarded – undo
7 7
 
8 8
 class Background_Task extends Wordlift_Plugin_WP_Background_Process {
9 9
 
10
-	const STATE_STARTED = 'started';
11
-	const STATE_STOPPED = 'stopped';
12
-
13
-	/**
14
-	 * The current state of the task, started or stopped.
15
-	 *
16
-	 * @var Background_Task_State $state
17
-	 */
18
-	private $state;
19
-
20
-	/**
21
-	 * The actual task.
22
-	 *
23
-	 * @var Task $task
24
-	 */
25
-	private $task;
26
-
27
-	/**
28
-	 * The prefix to store the state and other information in WP's options table, determined at instantiation.
29
-	 *
30
-	 * @var string $option_prefix
31
-	 */
32
-	private $option_prefix;
33
-
34
-	/**
35
-	 * @param Task $task
36
-	 */
37
-	public function __construct( $task ) {
38
-		$this->action        = sha1( get_class( $task ) );
39
-		$this->option_prefix = "_{$this->action}_";
40
-
41
-		parent::__construct();
42
-
43
-		// Set the current state.
44
-		if ( self::STATE_STARTED === $this->get_state() ) {
45
-			$this->state = new Background_Task_Started_State( $this, $task );
46
-		} else {
47
-			$this->state = new Background_Task_Stopped_State( $this );
48
-		}
49
-
50
-		$this->task = $task;
51
-	}
52
-
53
-	public static function create( $task ) {
54
-		return new self( $task );
55
-	}
56
-
57
-	public function get_option_prefix() {
58
-		return $this->option_prefix;
59
-	}
60
-
61
-	/**
62
-	 * This function is called:
63
-	 *  - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance.
64
-	 *  - To synchronize a post, by passing a numeric ID.
65
-	 *
66
-	 * This function returns the parameter for the next call or NULL if there are no more posts to process.
67
-	 *
68
-	 * @param mixed $item Queue item to iterate over.
69
-	 *
70
-	 * @return int[]|false The next post IDs or false if there are no more.
71
-	 */
72
-	protected function task( $item ) {
73
-
74
-		return $this->state->task( $item );
75
-	}
76
-
77
-	/**
78
-	 * Transition to the started state.
79
-	 */
80
-	public function start() {
81
-		$this->state->leave();
82
-		$this->state = new Background_Task_Started_State( $this, $this->task );
83
-		$this->state->enter();
84
-	}
85
-
86
-	/**
87
-	 * Transition to the stopped state.
88
-	 */
89
-	public function stop() {
90
-		$this->state->leave();
91
-		$this->state = new Background_Task_Stopped_State( $this );
92
-		$this->state->enter();
93
-	}
94
-
95
-	public function resume() {
96
-		$this->state->resume();
97
-	}
98
-
99
-	/**
100
-	 * Get the current state.
101
-	 *
102
-	 * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
103
-	 */
104
-	public function get_state() {
105
-		return get_option( $this->option_prefix . 'state', self::STATE_STOPPED );
106
-	}
107
-
108
-	/**
109
-	 * Persist the current state.
110
-	 *
111
-	 * @param string $value
112
-	 *
113
-	 * @return bool
114
-	 */
115
-	public function set_state( $value ) {
116
-		return null === $value
117
-			? delete_option( $this->option_prefix . 'state' )
118
-			: update_option( $this->option_prefix . 'state', $value, true );
119
-	}
120
-
121
-	public function get_info() {
122
-		return $this->state->get_info();
123
-	}
10
+    const STATE_STARTED = 'started';
11
+    const STATE_STOPPED = 'stopped';
12
+
13
+    /**
14
+     * The current state of the task, started or stopped.
15
+     *
16
+     * @var Background_Task_State $state
17
+     */
18
+    private $state;
19
+
20
+    /**
21
+     * The actual task.
22
+     *
23
+     * @var Task $task
24
+     */
25
+    private $task;
26
+
27
+    /**
28
+     * The prefix to store the state and other information in WP's options table, determined at instantiation.
29
+     *
30
+     * @var string $option_prefix
31
+     */
32
+    private $option_prefix;
33
+
34
+    /**
35
+     * @param Task $task
36
+     */
37
+    public function __construct( $task ) {
38
+        $this->action        = sha1( get_class( $task ) );
39
+        $this->option_prefix = "_{$this->action}_";
40
+
41
+        parent::__construct();
42
+
43
+        // Set the current state.
44
+        if ( self::STATE_STARTED === $this->get_state() ) {
45
+            $this->state = new Background_Task_Started_State( $this, $task );
46
+        } else {
47
+            $this->state = new Background_Task_Stopped_State( $this );
48
+        }
49
+
50
+        $this->task = $task;
51
+    }
52
+
53
+    public static function create( $task ) {
54
+        return new self( $task );
55
+    }
56
+
57
+    public function get_option_prefix() {
58
+        return $this->option_prefix;
59
+    }
60
+
61
+    /**
62
+     * This function is called:
63
+     *  - To start a new Synchronization, by passing a {@link Sync_Start_Message} instance.
64
+     *  - To synchronize a post, by passing a numeric ID.
65
+     *
66
+     * This function returns the parameter for the next call or NULL if there are no more posts to process.
67
+     *
68
+     * @param mixed $item Queue item to iterate over.
69
+     *
70
+     * @return int[]|false The next post IDs or false if there are no more.
71
+     */
72
+    protected function task( $item ) {
73
+
74
+        return $this->state->task( $item );
75
+    }
76
+
77
+    /**
78
+     * Transition to the started state.
79
+     */
80
+    public function start() {
81
+        $this->state->leave();
82
+        $this->state = new Background_Task_Started_State( $this, $this->task );
83
+        $this->state->enter();
84
+    }
85
+
86
+    /**
87
+     * Transition to the stopped state.
88
+     */
89
+    public function stop() {
90
+        $this->state->leave();
91
+        $this->state = new Background_Task_Stopped_State( $this );
92
+        $this->state->enter();
93
+    }
94
+
95
+    public function resume() {
96
+        $this->state->resume();
97
+    }
98
+
99
+    /**
100
+     * Get the current state.
101
+     *
102
+     * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
103
+     */
104
+    public function get_state() {
105
+        return get_option( $this->option_prefix . 'state', self::STATE_STOPPED );
106
+    }
107
+
108
+    /**
109
+     * Persist the current state.
110
+     *
111
+     * @param string $value
112
+     *
113
+     * @return bool
114
+     */
115
+    public function set_state( $value ) {
116
+        return null === $value
117
+            ? delete_option( $this->option_prefix . 'state' )
118
+            : update_option( $this->option_prefix . 'state', $value, true );
119
+    }
120
+
121
+    public function get_info() {
122
+        return $this->state->get_info();
123
+    }
124 124
 
125 125
 }
126 126
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,24 +34,24 @@  discard block
 block discarded – undo
34 34
 	/**
35 35
 	 * @param Task $task
36 36
 	 */
37
-	public function __construct( $task ) {
38
-		$this->action        = sha1( get_class( $task ) );
37
+	public function __construct($task) {
38
+		$this->action        = sha1(get_class($task));
39 39
 		$this->option_prefix = "_{$this->action}_";
40 40
 
41 41
 		parent::__construct();
42 42
 
43 43
 		// Set the current state.
44
-		if ( self::STATE_STARTED === $this->get_state() ) {
45
-			$this->state = new Background_Task_Started_State( $this, $task );
44
+		if (self::STATE_STARTED === $this->get_state()) {
45
+			$this->state = new Background_Task_Started_State($this, $task);
46 46
 		} else {
47
-			$this->state = new Background_Task_Stopped_State( $this );
47
+			$this->state = new Background_Task_Stopped_State($this);
48 48
 		}
49 49
 
50 50
 		$this->task = $task;
51 51
 	}
52 52
 
53
-	public static function create( $task ) {
54
-		return new self( $task );
53
+	public static function create($task) {
54
+		return new self($task);
55 55
 	}
56 56
 
57 57
 	public function get_option_prefix() {
@@ -69,9 +69,9 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return int[]|false The next post IDs or false if there are no more.
71 71
 	 */
72
-	protected function task( $item ) {
72
+	protected function task($item) {
73 73
 
74
-		return $this->state->task( $item );
74
+		return $this->state->task($item);
75 75
 	}
76 76
 
77 77
 	/**
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	 */
80 80
 	public function start() {
81 81
 		$this->state->leave();
82
-		$this->state = new Background_Task_Started_State( $this, $this->task );
82
+		$this->state = new Background_Task_Started_State($this, $this->task);
83 83
 		$this->state->enter();
84 84
 	}
85 85
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	 */
89 89
 	public function stop() {
90 90
 		$this->state->leave();
91
-		$this->state = new Background_Task_Stopped_State( $this );
91
+		$this->state = new Background_Task_Stopped_State($this);
92 92
 		$this->state->enter();
93 93
 	}
94 94
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @return string Either self::STARTED_STATE or self::STOPPED_STATE (default).
103 103
 	 */
104 104
 	public function get_state() {
105
-		return get_option( $this->option_prefix . 'state', self::STATE_STOPPED );
105
+		return get_option($this->option_prefix.'state', self::STATE_STOPPED);
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
 	 *
113 113
 	 * @return bool
114 114
 	 */
115
-	public function set_state( $value ) {
115
+	public function set_state($value) {
116 116
 		return null === $value
117
-			? delete_option( $this->option_prefix . 'state' )
118
-			: update_option( $this->option_prefix . 'state', $value, true );
117
+			? delete_option($this->option_prefix.'state')
118
+			: update_option($this->option_prefix.'state', $value, true);
119 119
 	}
120 120
 
121 121
 	public function get_info() {
Please login to merge, or discard this patch.