Completed
Push — develop ( f91b81...cb057c )
by Naveen
03:13 queued 01:47
created
src/libraries/action-scheduler/classes/migration/Controller.php 2 patches
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -19,85 +19,85 @@  discard block
 block discarded – undo
19 19
  * @codeCoverageIgnore
20 20
  */
21 21
 class Controller {
22
-	private static $instance;
23
-
24
-	/** @var Action_Scheduler\Migration\Scheduler */
25
-	private $migration_scheduler;
26
-
27
-	/** @var string */
28
-	private $store_classname;
29
-
30
-	/** @var string */
31
-	private $logger_classname;
32
-
33
-	/** @var bool */
34
-	private $migrate_custom_store;
35
-
36
-	/**
37
-	 * Controller constructor.
38
-	 *
39
-	 * @param Scheduler $migration_scheduler Migration scheduler object.
40
-	 */
41
-	protected function __construct( Scheduler $migration_scheduler ) {
42
-		$this->migration_scheduler = $migration_scheduler;
43
-		$this->store_classname     = '';
44
-	}
45
-
46
-	/**
47
-	 * Set the action store class name.
48
-	 *
49
-	 * @param string $class Classname of the store class.
50
-	 *
51
-	 * @return string
52
-	 */
53
-	public function get_store_class( $class ) {
54
-		if ( \ActionScheduler_DataController::is_migration_complete() ) {
55
-			return \ActionScheduler_DataController::DATASTORE_CLASS;
56
-		} elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
57
-			$this->store_classname = $class;
58
-			return $class;
59
-		} else {
60
-			return 'ActionScheduler_HybridStore';
61
-		}
62
-	}
63
-
64
-	/**
65
-	 * Set the action logger class name.
66
-	 *
67
-	 * @param string $class Classname of the logger class.
68
-	 *
69
-	 * @return string
70
-	 */
71
-	public function get_logger_class( $class ) {
72
-		\ActionScheduler_Store::instance();
73
-
74
-		if ( $this->has_custom_datastore() ) {
75
-			$this->logger_classname = $class;
76
-			return $class;
77
-		} else {
78
-			return \ActionScheduler_DataController::LOGGER_CLASS;
79
-		}
80
-	}
81
-
82
-	/**
83
-	 * Get flag indicating whether a custom datastore is in use.
84
-	 *
85
-	 * @return bool
86
-	 */
87
-	public function has_custom_datastore() {
88
-		return (bool) $this->store_classname;
89
-	}
90
-
91
-	/**
92
-	 * Set up the background migration process.
93
-	 *
94
-	 * @return void
95
-	 */
96
-	public function schedule_migration() {
97
-		$logging_tables = new ActionScheduler_LoggerSchema();
98
-		$store_tables   = new ActionScheduler_StoreSchema();
99
-
100
-		/*
22
+    private static $instance;
23
+
24
+    /** @var Action_Scheduler\Migration\Scheduler */
25
+    private $migration_scheduler;
26
+
27
+    /** @var string */
28
+    private $store_classname;
29
+
30
+    /** @var string */
31
+    private $logger_classname;
32
+
33
+    /** @var bool */
34
+    private $migrate_custom_store;
35
+
36
+    /**
37
+     * Controller constructor.
38
+     *
39
+     * @param Scheduler $migration_scheduler Migration scheduler object.
40
+     */
41
+    protected function __construct( Scheduler $migration_scheduler ) {
42
+        $this->migration_scheduler = $migration_scheduler;
43
+        $this->store_classname     = '';
44
+    }
45
+
46
+    /**
47
+     * Set the action store class name.
48
+     *
49
+     * @param string $class Classname of the store class.
50
+     *
51
+     * @return string
52
+     */
53
+    public function get_store_class( $class ) {
54
+        if ( \ActionScheduler_DataController::is_migration_complete() ) {
55
+            return \ActionScheduler_DataController::DATASTORE_CLASS;
56
+        } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
57
+            $this->store_classname = $class;
58
+            return $class;
59
+        } else {
60
+            return 'ActionScheduler_HybridStore';
61
+        }
62
+    }
63
+
64
+    /**
65
+     * Set the action logger class name.
66
+     *
67
+     * @param string $class Classname of the logger class.
68
+     *
69
+     * @return string
70
+     */
71
+    public function get_logger_class( $class ) {
72
+        \ActionScheduler_Store::instance();
73
+
74
+        if ( $this->has_custom_datastore() ) {
75
+            $this->logger_classname = $class;
76
+            return $class;
77
+        } else {
78
+            return \ActionScheduler_DataController::LOGGER_CLASS;
79
+        }
80
+    }
81
+
82
+    /**
83
+     * Get flag indicating whether a custom datastore is in use.
84
+     *
85
+     * @return bool
86
+     */
87
+    public function has_custom_datastore() {
88
+        return (bool) $this->store_classname;
89
+    }
90
+
91
+    /**
92
+     * Set up the background migration process.
93
+     *
94
+     * @return void
95
+     */
96
+    public function schedule_migration() {
97
+        $logging_tables = new ActionScheduler_LoggerSchema();
98
+        $store_tables   = new ActionScheduler_StoreSchema();
99
+
100
+        /*
101 101
 		 * In some unusual cases, the expected tables may not have been created. In such cases
102 102
 		 * we do not schedule a migration as doing so will lead to fatal error conditions.
103 103
 		 *
@@ -107,120 +107,120 @@  discard block
 block discarded – undo
107 107
 		 *
108 108
 		 * @see https://github.com/woocommerce/action-scheduler/issues/653
109 109
 		 */
110
-		if (
111
-			ActionScheduler_DataController::is_migration_complete()
112
-			|| $this->migration_scheduler->is_migration_scheduled()
113
-			|| ! $store_tables->tables_exist()
114
-			|| ! $logging_tables->tables_exist()
115
-		) {
116
-			return;
117
-		}
118
-
119
-		$this->migration_scheduler->schedule_migration();
120
-	}
121
-
122
-	/**
123
-	 * Get the default migration config object
124
-	 *
125
-	 * @return ActionScheduler\Migration\Config
126
-	 */
127
-	public function get_migration_config_object() {
128
-		static $config = null;
129
-
130
-		if ( ! $config ) {
131
-			$source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
132
-			$source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
133
-
134
-			$config = new Config();
135
-			$config->set_source_store( $source_store );
136
-			$config->set_source_logger( $source_logger );
137
-			$config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
138
-			$config->set_destination_logger( new \ActionScheduler_DBLogger() );
139
-
140
-			if ( defined( 'WP_CLI' ) && WP_CLI ) {
141
-				$config->set_progress_bar( new ProgressBar( '', 0 ) );
142
-			}
143
-		}
144
-
145
-		return apply_filters( 'action_scheduler/migration_config', $config );
146
-	}
147
-
148
-	/**
149
-	 * Hook dashboard migration notice.
150
-	 */
151
-	public function hook_admin_notices() {
152
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
153
-			return;
154
-		}
155
-		add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
156
-	}
157
-
158
-	/**
159
-	 * Show a dashboard notice that migration is in progress.
160
-	 */
161
-	public function display_migration_notice() {
162
-		printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
163
-	}
164
-
165
-	/**
166
-	 * Add store classes. Hook migration.
167
-	 */
168
-	private function hook() {
169
-		add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
170
-		add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
171
-		add_action( 'init', array( $this, 'maybe_hook_migration' ) );
172
-		add_action( 'wp_loaded', array( $this, 'schedule_migration' ) );
173
-
174
-		// Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
175
-		add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
176
-		add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
177
-	}
178
-
179
-	/**
180
-	 * Possibly hook the migration scheduler action.
181
-	 *
182
-	 * @author Jeremy Pry
183
-	 */
184
-	public function maybe_hook_migration() {
185
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
186
-			return;
187
-		}
188
-
189
-		$this->migration_scheduler->hook();
190
-	}
191
-
192
-	/**
193
-	 * Allow datastores to enable migration to AS tables.
194
-	 */
195
-	public function allow_migration() {
196
-		if ( ! \ActionScheduler_DataController::dependencies_met() ) {
197
-			return false;
198
-		}
199
-
200
-		if ( null === $this->migrate_custom_store ) {
201
-			$this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
202
-		}
203
-
204
-		return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
205
-	}
206
-
207
-	/**
208
-	 * Proceed with the migration if the dependencies have been met.
209
-	 */
210
-	public static function init() {
211
-		if ( \ActionScheduler_DataController::dependencies_met() ) {
212
-			self::instance()->hook();
213
-		}
214
-	}
215
-
216
-	/**
217
-	 * Singleton factory.
218
-	 */
219
-	public static function instance() {
220
-		if ( ! isset( self::$instance ) ) {
221
-			self::$instance = new static( new Scheduler() );
222
-		}
223
-
224
-		return self::$instance;
225
-	}
110
+        if (
111
+            ActionScheduler_DataController::is_migration_complete()
112
+            || $this->migration_scheduler->is_migration_scheduled()
113
+            || ! $store_tables->tables_exist()
114
+            || ! $logging_tables->tables_exist()
115
+        ) {
116
+            return;
117
+        }
118
+
119
+        $this->migration_scheduler->schedule_migration();
120
+    }
121
+
122
+    /**
123
+     * Get the default migration config object
124
+     *
125
+     * @return ActionScheduler\Migration\Config
126
+     */
127
+    public function get_migration_config_object() {
128
+        static $config = null;
129
+
130
+        if ( ! $config ) {
131
+            $source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
132
+            $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
133
+
134
+            $config = new Config();
135
+            $config->set_source_store( $source_store );
136
+            $config->set_source_logger( $source_logger );
137
+            $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
138
+            $config->set_destination_logger( new \ActionScheduler_DBLogger() );
139
+
140
+            if ( defined( 'WP_CLI' ) && WP_CLI ) {
141
+                $config->set_progress_bar( new ProgressBar( '', 0 ) );
142
+            }
143
+        }
144
+
145
+        return apply_filters( 'action_scheduler/migration_config', $config );
146
+    }
147
+
148
+    /**
149
+     * Hook dashboard migration notice.
150
+     */
151
+    public function hook_admin_notices() {
152
+        if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
153
+            return;
154
+        }
155
+        add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
156
+    }
157
+
158
+    /**
159
+     * Show a dashboard notice that migration is in progress.
160
+     */
161
+    public function display_migration_notice() {
162
+        printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
163
+    }
164
+
165
+    /**
166
+     * Add store classes. Hook migration.
167
+     */
168
+    private function hook() {
169
+        add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
170
+        add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
171
+        add_action( 'init', array( $this, 'maybe_hook_migration' ) );
172
+        add_action( 'wp_loaded', array( $this, 'schedule_migration' ) );
173
+
174
+        // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
175
+        add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
176
+        add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
177
+    }
178
+
179
+    /**
180
+     * Possibly hook the migration scheduler action.
181
+     *
182
+     * @author Jeremy Pry
183
+     */
184
+    public function maybe_hook_migration() {
185
+        if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
186
+            return;
187
+        }
188
+
189
+        $this->migration_scheduler->hook();
190
+    }
191
+
192
+    /**
193
+     * Allow datastores to enable migration to AS tables.
194
+     */
195
+    public function allow_migration() {
196
+        if ( ! \ActionScheduler_DataController::dependencies_met() ) {
197
+            return false;
198
+        }
199
+
200
+        if ( null === $this->migrate_custom_store ) {
201
+            $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
202
+        }
203
+
204
+        return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
205
+    }
206
+
207
+    /**
208
+     * Proceed with the migration if the dependencies have been met.
209
+     */
210
+    public static function init() {
211
+        if ( \ActionScheduler_DataController::dependencies_met() ) {
212
+            self::instance()->hook();
213
+        }
214
+    }
215
+
216
+    /**
217
+     * Singleton factory.
218
+     */
219
+    public static function instance() {
220
+        if ( ! isset( self::$instance ) ) {
221
+            self::$instance = new static( new Scheduler() );
222
+        }
223
+
224
+        return self::$instance;
225
+    }
226 226
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param Scheduler $migration_scheduler Migration scheduler object.
40 40
 	 */
41
-	protected function __construct( Scheduler $migration_scheduler ) {
41
+	protected function __construct(Scheduler $migration_scheduler) {
42 42
 		$this->migration_scheduler = $migration_scheduler;
43 43
 		$this->store_classname     = '';
44 44
 	}
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @return string
52 52
 	 */
53
-	public function get_store_class( $class ) {
54
-		if ( \ActionScheduler_DataController::is_migration_complete() ) {
53
+	public function get_store_class($class) {
54
+		if (\ActionScheduler_DataController::is_migration_complete()) {
55 55
 			return \ActionScheduler_DataController::DATASTORE_CLASS;
56
-		} elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
56
+		} elseif (\ActionScheduler_Store::DEFAULT_CLASS !== $class) {
57 57
 			$this->store_classname = $class;
58 58
 			return $class;
59 59
 		} else {
@@ -68,10 +68,10 @@  discard block
 block discarded – undo
68 68
 	 *
69 69
 	 * @return string
70 70
 	 */
71
-	public function get_logger_class( $class ) {
71
+	public function get_logger_class($class) {
72 72
 		\ActionScheduler_Store::instance();
73 73
 
74
-		if ( $this->has_custom_datastore() ) {
74
+		if ($this->has_custom_datastore()) {
75 75
 			$this->logger_classname = $class;
76 76
 			return $class;
77 77
 		} else {
@@ -127,53 +127,53 @@  discard block
 block discarded – undo
127 127
 	public function get_migration_config_object() {
128 128
 		static $config = null;
129 129
 
130
-		if ( ! $config ) {
130
+		if ( ! $config) {
131 131
 			$source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
132 132
 			$source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
133 133
 
134 134
 			$config = new Config();
135
-			$config->set_source_store( $source_store );
136
-			$config->set_source_logger( $source_logger );
137
-			$config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
138
-			$config->set_destination_logger( new \ActionScheduler_DBLogger() );
135
+			$config->set_source_store($source_store);
136
+			$config->set_source_logger($source_logger);
137
+			$config->set_destination_store(new \ActionScheduler_DBStoreMigrator());
138
+			$config->set_destination_logger(new \ActionScheduler_DBLogger());
139 139
 
140
-			if ( defined( 'WP_CLI' ) && WP_CLI ) {
141
-				$config->set_progress_bar( new ProgressBar( '', 0 ) );
140
+			if (defined('WP_CLI') && WP_CLI) {
141
+				$config->set_progress_bar(new ProgressBar('', 0));
142 142
 			}
143 143
 		}
144 144
 
145
-		return apply_filters( 'action_scheduler/migration_config', $config );
145
+		return apply_filters('action_scheduler/migration_config', $config);
146 146
 	}
147 147
 
148 148
 	/**
149 149
 	 * Hook dashboard migration notice.
150 150
 	 */
151 151
 	public function hook_admin_notices() {
152
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
152
+		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) {
153 153
 			return;
154 154
 		}
155
-		add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
155
+		add_action('admin_notices', array($this, 'display_migration_notice'), 10, 0);
156 156
 	}
157 157
 
158 158
 	/**
159 159
 	 * Show a dashboard notice that migration is in progress.
160 160
 	 */
161 161
 	public function display_migration_notice() {
162
-		printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
162
+		printf('<div class="notice notice-warning"><p>%s</p></div>', esc_html__('Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler'));
163 163
 	}
164 164
 
165 165
 	/**
166 166
 	 * Add store classes. Hook migration.
167 167
 	 */
168 168
 	private function hook() {
169
-		add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
170
-		add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
171
-		add_action( 'init', array( $this, 'maybe_hook_migration' ) );
172
-		add_action( 'wp_loaded', array( $this, 'schedule_migration' ) );
169
+		add_filter('action_scheduler_store_class', array($this, 'get_store_class'), 100, 1);
170
+		add_filter('action_scheduler_logger_class', array($this, 'get_logger_class'), 100, 1);
171
+		add_action('init', array($this, 'maybe_hook_migration'));
172
+		add_action('wp_loaded', array($this, 'schedule_migration'));
173 173
 
174 174
 		// Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
175
-		add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
176
-		add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
175
+		add_action('load-tools_page_action-scheduler', array($this, 'hook_admin_notices'), 10, 0);
176
+		add_action('load-woocommerce_page_wc-status', array($this, 'hook_admin_notices'), 10, 0);
177 177
 	}
178 178
 
179 179
 	/**
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @author Jeremy Pry
183 183
 	 */
184 184
 	public function maybe_hook_migration() {
185
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
185
+		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) {
186 186
 			return;
187 187
 		}
188 188
 
@@ -193,22 +193,22 @@  discard block
 block discarded – undo
193 193
 	 * Allow datastores to enable migration to AS tables.
194 194
 	 */
195 195
 	public function allow_migration() {
196
-		if ( ! \ActionScheduler_DataController::dependencies_met() ) {
196
+		if ( ! \ActionScheduler_DataController::dependencies_met()) {
197 197
 			return false;
198 198
 		}
199 199
 
200
-		if ( null === $this->migrate_custom_store ) {
201
-			$this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
200
+		if (null === $this->migrate_custom_store) {
201
+			$this->migrate_custom_store = apply_filters('action_scheduler_migrate_data_store', false);
202 202
 		}
203 203
 
204
-		return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
204
+		return ( ! $this->has_custom_datastore()) || $this->migrate_custom_store;
205 205
 	}
206 206
 
207 207
 	/**
208 208
 	 * Proceed with the migration if the dependencies have been met.
209 209
 	 */
210 210
 	public static function init() {
211
-		if ( \ActionScheduler_DataController::dependencies_met() ) {
211
+		if (\ActionScheduler_DataController::dependencies_met()) {
212 212
 			self::instance()->hook();
213 213
 		}
214 214
 	}
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 	 * Singleton factory.
218 218
 	 */
219 219
 	public static function instance() {
220
-		if ( ! isset( self::$instance ) ) {
221
-			self::$instance = new static( new Scheduler() );
220
+		if ( ! isset(self::$instance)) {
221
+			self::$instance = new static(new Scheduler());
222 222
 		}
223 223
 
224 224
 		return self::$instance;
Please login to merge, or discard this patch.
src/libraries/action-scheduler/classes/migration/Scheduler.php 2 patches
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -23,14 +23,14 @@  discard block
 block discarded – undo
23 23
 	 * Set up the callback for the scheduled job.
24 24
 	 */
25 25
 	public function hook() {
26
-		add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
26
+		add_action(self::HOOK, array($this, 'run_migration'), 10, 0);
27 27
 	}
28 28
 
29 29
 	/**
30 30
 	 * Remove the callback for the scheduled job.
31 31
 	 */
32 32
 	public function unhook() {
33
-		remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
33
+		remove_action(self::HOOK, array($this, 'run_migration'), 10);
34 34
 	}
35 35
 
36 36
 	/**
@@ -38,12 +38,12 @@  discard block
 block discarded – undo
38 38
 	 */
39 39
 	public function run_migration() {
40 40
 		$migration_runner = $this->get_migration_runner();
41
-		$count            = $migration_runner->run( $this->get_batch_size() );
41
+		$count            = $migration_runner->run($this->get_batch_size());
42 42
 
43
-		if ( $count === 0 ) {
43
+		if ($count === 0) {
44 44
 			$this->mark_complete();
45 45
 		} else {
46
-			$this->schedule_migration( time() + $this->get_schedule_interval() );
46
+			$this->schedule_migration(time() + $this->get_schedule_interval());
47 47
 		}
48 48
 	}
49 49
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 		$this->unschedule_migration();
55 55
 
56 56
 		\ActionScheduler_DataController::mark_migration_complete();
57
-		do_action( 'action_scheduler/migration_complete' );
57
+		do_action('action_scheduler/migration_complete');
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
 	 * @return bool Whether there is a pending action in the store to handle the migration
64 64
 	 */
65 65
 	public function is_migration_scheduled() {
66
-		$next = as_next_scheduled_action( self::HOOK );
66
+		$next = as_next_scheduled_action(self::HOOK);
67 67
 
68
-		return ! empty( $next );
68
+		return ! empty($next);
69 69
 	}
70 70
 
71 71
 	/**
@@ -75,25 +75,25 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return string The action ID
77 77
 	 */
78
-	public function schedule_migration( $when = 0 ) {
79
-		$next = as_next_scheduled_action( self::HOOK );
78
+	public function schedule_migration($when = 0) {
79
+		$next = as_next_scheduled_action(self::HOOK);
80 80
 
81
-		if ( ! empty( $next ) ) {
81
+		if ( ! empty($next)) {
82 82
 			return $next;
83 83
 		}
84 84
 
85
-		if ( empty( $when ) ) {
85
+		if (empty($when)) {
86 86
 			$when = time() + MINUTE_IN_SECONDS;
87 87
 		}
88 88
 
89
-		return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
89
+		return as_schedule_single_action($when, self::HOOK, array(), self::GROUP);
90 90
 	}
91 91
 
92 92
 	/**
93 93
 	 * Remove the scheduled migration action.
94 94
 	 */
95 95
 	public function unschedule_migration() {
96
-		as_unschedule_action( self::HOOK, null, self::GROUP );
96
+		as_unschedule_action(self::HOOK, null, self::GROUP);
97 97
 	}
98 98
 
99 99
 	/**
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 	 * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
103 103
 	 */
104 104
 	private function get_schedule_interval() {
105
-		return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
105
+		return (int) apply_filters('action_scheduler/migration_interval', 0);
106 106
 	}
107 107
 
108 108
 	/**
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	 * @return int Number of actions to migrate in each batch. Defaults to 250.
112 112
 	 */
113 113
 	private function get_batch_size() {
114
-		return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
114
+		return (int) apply_filters('action_scheduler/migration_batch_size', 250);
115 115
 	}
116 116
 
117 117
 	/**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	private function get_migration_runner() {
123 123
 		$config = Controller::instance()->get_migration_config_object();
124 124
 
125
-		return new Runner( $config );
125
+		return new Runner($config);
126 126
 	}
127 127
 
128 128
 }
Please login to merge, or discard this patch.
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -12,116 +12,116 @@
 block discarded – undo
12 12
  * @codeCoverageIgnore
13 13
  */
14 14
 class Scheduler {
15
-	/** Migration action hook. */
16
-	const HOOK = 'action_scheduler/migration_hook';
17
-
18
-	/** Migration action group. */
19
-	const GROUP = 'action-scheduler-migration';
20
-
21
-	/**
22
-	 * Set up the callback for the scheduled job.
23
-	 */
24
-	public function hook() {
25
-		add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
26
-	}
27
-
28
-	/**
29
-	 * Remove the callback for the scheduled job.
30
-	 */
31
-	public function unhook() {
32
-		remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
33
-	}
34
-
35
-	/**
36
-	 * The migration callback.
37
-	 */
38
-	public function run_migration() {
39
-		$migration_runner = $this->get_migration_runner();
40
-		$count            = $migration_runner->run( $this->get_batch_size() );
41
-
42
-		if ( $count === 0 ) {
43
-			$this->mark_complete();
44
-		} else {
45
-			$this->schedule_migration( time() + $this->get_schedule_interval() );
46
-		}
47
-	}
48
-
49
-	/**
50
-	 * Mark the migration complete.
51
-	 */
52
-	public function mark_complete() {
53
-		$this->unschedule_migration();
54
-
55
-		\ActionScheduler_DataController::mark_migration_complete();
56
-		do_action( 'action_scheduler/migration_complete' );
57
-	}
58
-
59
-	/**
60
-	 * Get a flag indicating whether the migration is scheduled.
61
-	 *
62
-	 * @return bool Whether there is a pending action in the store to handle the migration
63
-	 */
64
-	public function is_migration_scheduled() {
65
-		$next = as_next_scheduled_action( self::HOOK );
66
-
67
-		return ! empty( $next );
68
-	}
69
-
70
-	/**
71
-	 * Schedule the migration.
72
-	 *
73
-	 * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
74
-	 *
75
-	 * @return string The action ID
76
-	 */
77
-	public function schedule_migration( $when = 0 ) {
78
-		$next = as_next_scheduled_action( self::HOOK );
79
-
80
-		if ( ! empty( $next ) ) {
81
-			return $next;
82
-		}
83
-
84
-		if ( empty( $when ) ) {
85
-			$when = time() + MINUTE_IN_SECONDS;
86
-		}
87
-
88
-		return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
89
-	}
90
-
91
-	/**
92
-	 * Remove the scheduled migration action.
93
-	 */
94
-	public function unschedule_migration() {
95
-		as_unschedule_action( self::HOOK, null, self::GROUP );
96
-	}
97
-
98
-	/**
99
-	 * Get migration batch schedule interval.
100
-	 *
101
-	 * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
102
-	 */
103
-	private function get_schedule_interval() {
104
-		return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
105
-	}
106
-
107
-	/**
108
-	 * Get migration batch size.
109
-	 *
110
-	 * @return int Number of actions to migrate in each batch. Defaults to 250.
111
-	 */
112
-	private function get_batch_size() {
113
-		return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
114
-	}
115
-
116
-	/**
117
-	 * Get migration runner object.
118
-	 *
119
-	 * @return Runner
120
-	 */
121
-	private function get_migration_runner() {
122
-		$config = Controller::instance()->get_migration_config_object();
123
-
124
-		return new Runner( $config );
125
-	}
15
+    /** Migration action hook. */
16
+    const HOOK = 'action_scheduler/migration_hook';
17
+
18
+    /** Migration action group. */
19
+    const GROUP = 'action-scheduler-migration';
20
+
21
+    /**
22
+     * Set up the callback for the scheduled job.
23
+     */
24
+    public function hook() {
25
+        add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
26
+    }
27
+
28
+    /**
29
+     * Remove the callback for the scheduled job.
30
+     */
31
+    public function unhook() {
32
+        remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
33
+    }
34
+
35
+    /**
36
+     * The migration callback.
37
+     */
38
+    public function run_migration() {
39
+        $migration_runner = $this->get_migration_runner();
40
+        $count            = $migration_runner->run( $this->get_batch_size() );
41
+
42
+        if ( $count === 0 ) {
43
+            $this->mark_complete();
44
+        } else {
45
+            $this->schedule_migration( time() + $this->get_schedule_interval() );
46
+        }
47
+    }
48
+
49
+    /**
50
+     * Mark the migration complete.
51
+     */
52
+    public function mark_complete() {
53
+        $this->unschedule_migration();
54
+
55
+        \ActionScheduler_DataController::mark_migration_complete();
56
+        do_action( 'action_scheduler/migration_complete' );
57
+    }
58
+
59
+    /**
60
+     * Get a flag indicating whether the migration is scheduled.
61
+     *
62
+     * @return bool Whether there is a pending action in the store to handle the migration
63
+     */
64
+    public function is_migration_scheduled() {
65
+        $next = as_next_scheduled_action( self::HOOK );
66
+
67
+        return ! empty( $next );
68
+    }
69
+
70
+    /**
71
+     * Schedule the migration.
72
+     *
73
+     * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
74
+     *
75
+     * @return string The action ID
76
+     */
77
+    public function schedule_migration( $when = 0 ) {
78
+        $next = as_next_scheduled_action( self::HOOK );
79
+
80
+        if ( ! empty( $next ) ) {
81
+            return $next;
82
+        }
83
+
84
+        if ( empty( $when ) ) {
85
+            $when = time() + MINUTE_IN_SECONDS;
86
+        }
87
+
88
+        return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
89
+    }
90
+
91
+    /**
92
+     * Remove the scheduled migration action.
93
+     */
94
+    public function unschedule_migration() {
95
+        as_unschedule_action( self::HOOK, null, self::GROUP );
96
+    }
97
+
98
+    /**
99
+     * Get migration batch schedule interval.
100
+     *
101
+     * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
102
+     */
103
+    private function get_schedule_interval() {
104
+        return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
105
+    }
106
+
107
+    /**
108
+     * Get migration batch size.
109
+     *
110
+     * @return int Number of actions to migrate in each batch. Defaults to 250.
111
+     */
112
+    private function get_batch_size() {
113
+        return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
114
+    }
115
+
116
+    /**
117
+     * Get migration runner object.
118
+     *
119
+     * @return Runner
120
+     */
121
+    private function get_migration_runner() {
122
+        $config = Controller::instance()->get_migration_config_object();
123
+
124
+        return new Runner( $config );
125
+    }
126 126
 
127 127
 }
Please login to merge, or discard this patch.
classes/data-stores/ActionScheduler_wpPostStore_PostStatusRegistrar.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -5,54 +5,54 @@
 block discarded – undo
5 5
  * @codeCoverageIgnore
6 6
  */
7 7
 class ActionScheduler_wpPostStore_PostStatusRegistrar {
8
-	public function register() {
9
-		register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) );
10
-		register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) );
11
-	}
8
+    public function register() {
9
+        register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) );
10
+        register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) );
11
+    }
12 12
 
13
-	/**
14
-	 * Build the args array for the post type definition
15
-	 *
16
-	 * @return array
17
-	 */
18
-	protected function post_status_args() {
19
-		$args = array(
20
-			'public'                    => false,
21
-			'exclude_from_search'       => false,
22
-			'show_in_admin_all_list'    => true,
23
-			'show_in_admin_status_list' => true,
24
-		);
13
+    /**
14
+     * Build the args array for the post type definition
15
+     *
16
+     * @return array
17
+     */
18
+    protected function post_status_args() {
19
+        $args = array(
20
+            'public'                    => false,
21
+            'exclude_from_search'       => false,
22
+            'show_in_admin_all_list'    => true,
23
+            'show_in_admin_status_list' => true,
24
+        );
25 25
 
26
-		return apply_filters( 'action_scheduler_post_status_args', $args );
27
-	}
26
+        return apply_filters( 'action_scheduler_post_status_args', $args );
27
+    }
28 28
 
29
-	/**
30
-	 * Build the args array for the post type definition
31
-	 *
32
-	 * @return array
33
-	 */
34
-	protected function post_status_failed_labels() {
35
-		$labels = array(
36
-			'label'       => _x( 'Failed', 'post', 'action-scheduler' ),
37
-			/* translators: %s: count */
38
-			'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ),
39
-		);
29
+    /**
30
+     * Build the args array for the post type definition
31
+     *
32
+     * @return array
33
+     */
34
+    protected function post_status_failed_labels() {
35
+        $labels = array(
36
+            'label'       => _x( 'Failed', 'post', 'action-scheduler' ),
37
+            /* translators: %s: count */
38
+            'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ),
39
+        );
40 40
 
41
-		return apply_filters( 'action_scheduler_post_status_failed_labels', $labels );
42
-	}
41
+        return apply_filters( 'action_scheduler_post_status_failed_labels', $labels );
42
+    }
43 43
 
44
-	/**
45
-	 * Build the args array for the post type definition
46
-	 *
47
-	 * @return array
48
-	 */
49
-	protected function post_status_running_labels() {
50
-		$labels = array(
51
-			'label'       => _x( 'In-Progress', 'post', 'action-scheduler' ),
52
-			/* translators: %s: count */
53
-			'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ),
54
-		);
44
+    /**
45
+     * Build the args array for the post type definition
46
+     *
47
+     * @return array
48
+     */
49
+    protected function post_status_running_labels() {
50
+        $labels = array(
51
+            'label'       => _x( 'In-Progress', 'post', 'action-scheduler' ),
52
+            /* translators: %s: count */
53
+            'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ),
54
+        );
55 55
 
56
-		return apply_filters( 'action_scheduler_post_status_running_labels', $labels );
57
-	}
56
+        return apply_filters( 'action_scheduler_post_status_running_labels', $labels );
57
+    }
58 58
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -6,8 +6,8 @@  discard block
 block discarded – undo
6 6
  */
7 7
 class ActionScheduler_wpPostStore_PostStatusRegistrar {
8 8
 	public function register() {
9
-		register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) );
10
-		register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) );
9
+		register_post_status(ActionScheduler_Store::STATUS_RUNNING, array_merge($this->post_status_args(), $this->post_status_running_labels()));
10
+		register_post_status(ActionScheduler_Store::STATUS_FAILED, array_merge($this->post_status_args(), $this->post_status_failed_labels()));
11 11
 	}
12 12
 
13 13
 	/**
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 			'show_in_admin_status_list' => true,
24 24
 		);
25 25
 
26
-		return apply_filters( 'action_scheduler_post_status_args', $args );
26
+		return apply_filters('action_scheduler_post_status_args', $args);
27 27
 	}
28 28
 
29 29
 	/**
@@ -33,12 +33,12 @@  discard block
 block discarded – undo
33 33
 	 */
34 34
 	protected function post_status_failed_labels() {
35 35
 		$labels = array(
36
-			'label'       => _x( 'Failed', 'post', 'action-scheduler' ),
36
+			'label'       => _x('Failed', 'post', 'action-scheduler'),
37 37
 			/* translators: %s: count */
38
-			'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ),
38
+			'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler'),
39 39
 		);
40 40
 
41
-		return apply_filters( 'action_scheduler_post_status_failed_labels', $labels );
41
+		return apply_filters('action_scheduler_post_status_failed_labels', $labels);
42 42
 	}
43 43
 
44 44
 	/**
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
48 48
 	 */
49 49
 	protected function post_status_running_labels() {
50 50
 		$labels = array(
51
-			'label'       => _x( 'In-Progress', 'post', 'action-scheduler' ),
51
+			'label'       => _x('In-Progress', 'post', 'action-scheduler'),
52 52
 			/* translators: %s: count */
53
-			'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ),
53
+			'label_count' => _n_noop('In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler'),
54 54
 		);
55 55
 
56
-		return apply_filters( 'action_scheduler_post_status_running_labels', $labels );
56
+		return apply_filters('action_scheduler_post_status_running_labels', $labels);
57 57
 	}
58 58
 }
Please login to merge, or discard this patch.
src/libraries/action-scheduler/classes/ActionScheduler_DataController.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
44 44
 	 * @return bool
45 45
 	 */
46 46
 	public static function dependencies_met() {
47
-		$php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
48
-		return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
47
+		$php_support = version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '>=');
48
+		return $php_support && apply_filters('action_scheduler_migration_dependencies_met', true);
49 49
 	}
50 50
 
51 51
 	/**
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
 	 * @return bool Whether the flag has been set marking the migration as complete
55 55
 	 */
56 56
 	public static function is_migration_complete() {
57
-		return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE;
57
+		return get_option(self::STATUS_FLAG) === self::STATUS_COMPLETE;
58 58
 	}
59 59
 
60 60
 	/**
61 61
 	 * Mark the migration as complete.
62 62
 	 */
63 63
 	public static function mark_migration_complete() {
64
-		update_option( self::STATUS_FLAG, self::STATUS_COMPLETE );
64
+		update_option(self::STATUS_FLAG, self::STATUS_COMPLETE);
65 65
 	}
66 66
 
67 67
 	/**
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 * deactivated and the site was running on AS 2.x again.
71 71
 	 */
72 72
 	public static function mark_migration_incomplete() {
73
-		delete_option( self::STATUS_FLAG );
73
+		delete_option(self::STATUS_FLAG);
74 74
 	}
75 75
 
76 76
 	/**
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @return string
82 82
 	 */
83
-	public static function set_store_class( $class ) {
83
+	public static function set_store_class($class) {
84 84
 		return self::DATASTORE_CLASS;
85 85
 	}
86 86
 
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @return string
93 93
 	 */
94
-	public static function set_logger_class( $class ) {
94
+	public static function set_logger_class($class) {
95 95
 		return self::LOGGER_CLASS;
96 96
 	}
97 97
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @param integer $sleep_time The number of seconds to pause before resuming operation.
102 102
 	 */
103
-	public static function set_sleep_time( $sleep_time ) {
103
+	public static function set_sleep_time($sleep_time) {
104 104
 		self::$sleep_time = (int) $sleep_time;
105 105
 	}
106 106
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @param integer $free_ticks The number of ticks to free memory on.
111 111
 	 */
112
-	public static function set_free_ticks( $free_ticks ) {
112
+	public static function set_free_ticks($free_ticks) {
113 113
 		self::$free_ticks = (int) $free_ticks;
114 114
 	}
115 115
 
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 *
119 119
 	 * @param int $ticks Current tick count.
120 120
 	 */
121
-	public static function maybe_free_memory( $ticks ) {
122
-		if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) {
121
+	public static function maybe_free_memory($ticks) {
122
+		if (self::$free_ticks && 0 === $ticks % self::$free_ticks) {
123 123
 			self::free_memory();
124 124
 		}
125 125
 	}
@@ -128,13 +128,13 @@  discard block
 block discarded – undo
128 128
 	 * Reduce memory footprint by clearing the database query and object caches.
129 129
 	 */
130 130
 	public static function free_memory() {
131
-		if ( 0 < self::$sleep_time ) {
131
+		if (0 < self::$sleep_time) {
132 132
 			/* translators: %d: amount of time */
133
-			\WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) );
134
-			sleep( self::$sleep_time );
133
+			\WP_CLI::warning(sprintf(_n('Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler'), self::$sleep_time));
134
+			sleep(self::$sleep_time);
135 135
 		}
136 136
 
137
-		\WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) );
137
+		\WP_CLI::warning(__('Attempting to reduce used memory...', 'action-scheduler'));
138 138
 
139 139
 		/**
140 140
 		 * @var $wpdb            \wpdb
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 
145 145
 		$wpdb->queries = array();
146 146
 
147
-		if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) {
147
+		if ( ! is_a($wp_object_cache, 'WP_Object_Cache')) {
148 148
 			return;
149 149
 		}
150 150
 
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 		$wp_object_cache->memcache_debug = array();
154 154
 		$wp_object_cache->cache          = array();
155 155
 
156
-		if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
157
-			call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important
156
+		if (is_callable(array($wp_object_cache, '__remoteset'))) {
157
+			call_user_func(array($wp_object_cache, '__remoteset')); // important
158 158
 		}
159 159
 	}
160 160
 
@@ -163,22 +163,22 @@  discard block
 block discarded – undo
163 163
 	 * Otherwise, proceed with the migration if the dependencies have been met.
164 164
 	 */
165 165
 	public static function init() {
166
-		if ( self::is_migration_complete() ) {
167
-			add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 );
168
-			add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 );
169
-			add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) );
170
-		} elseif ( self::dependencies_met() ) {
166
+		if (self::is_migration_complete()) {
167
+			add_filter('action_scheduler_store_class', array('ActionScheduler_DataController', 'set_store_class'), 100);
168
+			add_filter('action_scheduler_logger_class', array('ActionScheduler_DataController', 'set_logger_class'), 100);
169
+			add_action('deactivate_plugin', array('ActionScheduler_DataController', 'mark_migration_incomplete'));
170
+		} elseif (self::dependencies_met()) {
171 171
 			Controller::init();
172 172
 		}
173 173
 
174
-		add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) );
174
+		add_action('action_scheduler/progress_tick', array('ActionScheduler_DataController', 'maybe_free_memory'));
175 175
 	}
176 176
 
177 177
 	/**
178 178
 	 * Singleton factory.
179 179
 	 */
180 180
 	public static function instance() {
181
-		if ( ! isset( self::$instance ) ) {
181
+		if ( ! isset(self::$instance)) {
182 182
 			self::$instance = new static();
183 183
 		}
184 184
 
Please login to merge, or discard this patch.
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -14,174 +14,174 @@
 block discarded – undo
14 14
  * @since 3.0.0
15 15
  */
16 16
 class ActionScheduler_DataController {
17
-	/** Action data store class name. */
18
-	const DATASTORE_CLASS = 'ActionScheduler_DBStore';
19
-
20
-	/** Logger data store class name. */
21
-	const LOGGER_CLASS = 'ActionScheduler_DBLogger';
22
-
23
-	/** Migration status option name. */
24
-	const STATUS_FLAG = 'action_scheduler_migration_status';
25
-
26
-	/** Migration status option value. */
27
-	const STATUS_COMPLETE = 'complete';
28
-
29
-	/** Migration minimum required PHP version. */
30
-	const MIN_PHP_VERSION = '5.5';
31
-
32
-	/** @var ActionScheduler_DataController */
33
-	private static $instance;
34
-
35
-	/** @var int */
36
-	private static $sleep_time = 0;
37
-
38
-	/** @var int */
39
-	private static $free_ticks = 50;
40
-
41
-	/**
42
-	 * Get a flag indicating whether the migration environment dependencies are met.
43
-	 *
44
-	 * @return bool
45
-	 */
46
-	public static function dependencies_met() {
47
-		$php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
48
-		return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
49
-	}
50
-
51
-	/**
52
-	 * Get a flag indicating whether the migration is complete.
53
-	 *
54
-	 * @return bool Whether the flag has been set marking the migration as complete
55
-	 */
56
-	public static function is_migration_complete() {
57
-		return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE;
58
-	}
59
-
60
-	/**
61
-	 * Mark the migration as complete.
62
-	 */
63
-	public static function mark_migration_complete() {
64
-		update_option( self::STATUS_FLAG, self::STATUS_COMPLETE );
65
-	}
66
-
67
-	/**
68
-	 * Unmark migration when a plugin is de-activated. Will not work in case of silent activation, for example in an update.
69
-	 * We do this to mitigate the bug of lost actions which happens if there was an AS 2.x to AS 3.x migration in the past, but that plugin is now
70
-	 * deactivated and the site was running on AS 2.x again.
71
-	 */
72
-	public static function mark_migration_incomplete() {
73
-		delete_option( self::STATUS_FLAG );
74
-	}
75
-
76
-	/**
77
-	 * Set the action store class name.
78
-	 *
79
-	 * @param string $class Classname of the store class.
80
-	 *
81
-	 * @return string
82
-	 */
83
-	public static function set_store_class( $class ) {
84
-		return self::DATASTORE_CLASS;
85
-	}
86
-
87
-	/**
88
-	 * Set the action logger class name.
89
-	 *
90
-	 * @param string $class Classname of the logger class.
91
-	 *
92
-	 * @return string
93
-	 */
94
-	public static function set_logger_class( $class ) {
95
-		return self::LOGGER_CLASS;
96
-	}
97
-
98
-	/**
99
-	 * Set the sleep time in seconds.
100
-	 *
101
-	 * @param integer $sleep_time The number of seconds to pause before resuming operation.
102
-	 */
103
-	public static function set_sleep_time( $sleep_time ) {
104
-		self::$sleep_time = (int) $sleep_time;
105
-	}
106
-
107
-	/**
108
-	 * Set the tick count required for freeing memory.
109
-	 *
110
-	 * @param integer $free_ticks The number of ticks to free memory on.
111
-	 */
112
-	public static function set_free_ticks( $free_ticks ) {
113
-		self::$free_ticks = (int) $free_ticks;
114
-	}
115
-
116
-	/**
117
-	 * Free memory if conditions are met.
118
-	 *
119
-	 * @param int $ticks Current tick count.
120
-	 */
121
-	public static function maybe_free_memory( $ticks ) {
122
-		if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) {
123
-			self::free_memory();
124
-		}
125
-	}
126
-
127
-	/**
128
-	 * Reduce memory footprint by clearing the database query and object caches.
129
-	 */
130
-	public static function free_memory() {
131
-		if ( 0 < self::$sleep_time ) {
132
-			/* translators: %d: amount of time */
133
-			\WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) );
134
-			sleep( self::$sleep_time );
135
-		}
136
-
137
-		\WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) );
138
-
139
-		/**
140
-		 * @var $wpdb            \wpdb
141
-		 * @var $wp_object_cache \WP_Object_Cache
142
-		 */
143
-		global $wpdb, $wp_object_cache;
144
-
145
-		$wpdb->queries = array();
146
-
147
-		if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) {
148
-			return;
149
-		}
150
-
151
-		$wp_object_cache->group_ops      = array();
152
-		$wp_object_cache->stats          = array();
153
-		$wp_object_cache->memcache_debug = array();
154
-		$wp_object_cache->cache          = array();
155
-
156
-		if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
157
-			call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important
158
-		}
159
-	}
160
-
161
-	/**
162
-	 * Connect to table datastores if migration is complete.
163
-	 * Otherwise, proceed with the migration if the dependencies have been met.
164
-	 */
165
-	public static function init() {
166
-		if ( self::is_migration_complete() ) {
167
-			add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 );
168
-			add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 );
169
-			add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) );
170
-		} elseif ( self::dependencies_met() ) {
171
-			Controller::init();
172
-		}
173
-
174
-		add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) );
175
-	}
176
-
177
-	/**
178
-	 * Singleton factory.
179
-	 */
180
-	public static function instance() {
181
-		if ( ! isset( self::$instance ) ) {
182
-			self::$instance = new static();
183
-		}
184
-
185
-		return self::$instance;
186
-	}
17
+    /** Action data store class name. */
18
+    const DATASTORE_CLASS = 'ActionScheduler_DBStore';
19
+
20
+    /** Logger data store class name. */
21
+    const LOGGER_CLASS = 'ActionScheduler_DBLogger';
22
+
23
+    /** Migration status option name. */
24
+    const STATUS_FLAG = 'action_scheduler_migration_status';
25
+
26
+    /** Migration status option value. */
27
+    const STATUS_COMPLETE = 'complete';
28
+
29
+    /** Migration minimum required PHP version. */
30
+    const MIN_PHP_VERSION = '5.5';
31
+
32
+    /** @var ActionScheduler_DataController */
33
+    private static $instance;
34
+
35
+    /** @var int */
36
+    private static $sleep_time = 0;
37
+
38
+    /** @var int */
39
+    private static $free_ticks = 50;
40
+
41
+    /**
42
+     * Get a flag indicating whether the migration environment dependencies are met.
43
+     *
44
+     * @return bool
45
+     */
46
+    public static function dependencies_met() {
47
+        $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
48
+        return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true );
49
+    }
50
+
51
+    /**
52
+     * Get a flag indicating whether the migration is complete.
53
+     *
54
+     * @return bool Whether the flag has been set marking the migration as complete
55
+     */
56
+    public static function is_migration_complete() {
57
+        return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE;
58
+    }
59
+
60
+    /**
61
+     * Mark the migration as complete.
62
+     */
63
+    public static function mark_migration_complete() {
64
+        update_option( self::STATUS_FLAG, self::STATUS_COMPLETE );
65
+    }
66
+
67
+    /**
68
+     * Unmark migration when a plugin is de-activated. Will not work in case of silent activation, for example in an update.
69
+     * We do this to mitigate the bug of lost actions which happens if there was an AS 2.x to AS 3.x migration in the past, but that plugin is now
70
+     * deactivated and the site was running on AS 2.x again.
71
+     */
72
+    public static function mark_migration_incomplete() {
73
+        delete_option( self::STATUS_FLAG );
74
+    }
75
+
76
+    /**
77
+     * Set the action store class name.
78
+     *
79
+     * @param string $class Classname of the store class.
80
+     *
81
+     * @return string
82
+     */
83
+    public static function set_store_class( $class ) {
84
+        return self::DATASTORE_CLASS;
85
+    }
86
+
87
+    /**
88
+     * Set the action logger class name.
89
+     *
90
+     * @param string $class Classname of the logger class.
91
+     *
92
+     * @return string
93
+     */
94
+    public static function set_logger_class( $class ) {
95
+        return self::LOGGER_CLASS;
96
+    }
97
+
98
+    /**
99
+     * Set the sleep time in seconds.
100
+     *
101
+     * @param integer $sleep_time The number of seconds to pause before resuming operation.
102
+     */
103
+    public static function set_sleep_time( $sleep_time ) {
104
+        self::$sleep_time = (int) $sleep_time;
105
+    }
106
+
107
+    /**
108
+     * Set the tick count required for freeing memory.
109
+     *
110
+     * @param integer $free_ticks The number of ticks to free memory on.
111
+     */
112
+    public static function set_free_ticks( $free_ticks ) {
113
+        self::$free_ticks = (int) $free_ticks;
114
+    }
115
+
116
+    /**
117
+     * Free memory if conditions are met.
118
+     *
119
+     * @param int $ticks Current tick count.
120
+     */
121
+    public static function maybe_free_memory( $ticks ) {
122
+        if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) {
123
+            self::free_memory();
124
+        }
125
+    }
126
+
127
+    /**
128
+     * Reduce memory footprint by clearing the database query and object caches.
129
+     */
130
+    public static function free_memory() {
131
+        if ( 0 < self::$sleep_time ) {
132
+            /* translators: %d: amount of time */
133
+            \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) );
134
+            sleep( self::$sleep_time );
135
+        }
136
+
137
+        \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) );
138
+
139
+        /**
140
+         * @var $wpdb            \wpdb
141
+         * @var $wp_object_cache \WP_Object_Cache
142
+         */
143
+        global $wpdb, $wp_object_cache;
144
+
145
+        $wpdb->queries = array();
146
+
147
+        if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) {
148
+            return;
149
+        }
150
+
151
+        $wp_object_cache->group_ops      = array();
152
+        $wp_object_cache->stats          = array();
153
+        $wp_object_cache->memcache_debug = array();
154
+        $wp_object_cache->cache          = array();
155
+
156
+        if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) {
157
+            call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important
158
+        }
159
+    }
160
+
161
+    /**
162
+     * Connect to table datastores if migration is complete.
163
+     * Otherwise, proceed with the migration if the dependencies have been met.
164
+     */
165
+    public static function init() {
166
+        if ( self::is_migration_complete() ) {
167
+            add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 );
168
+            add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 );
169
+            add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) );
170
+        } elseif ( self::dependencies_met() ) {
171
+            Controller::init();
172
+        }
173
+
174
+        add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) );
175
+    }
176
+
177
+    /**
178
+     * Singleton factory.
179
+     */
180
+    public static function instance() {
181
+        if ( ! isset( self::$instance ) ) {
182
+            self::$instance = new static();
183
+        }
184
+
185
+        return self::$instance;
186
+    }
187 187
 }
Please login to merge, or discard this patch.
src/wordlift/common/background-process/action-scheduler/class-state.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-stopped-state.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -6,31 +6,31 @@
 block discarded – undo
6 6
 
7 7
 class Sync_Background_Process_Stopped_State extends Abstract_Sync_Background_Process_State {
8 8
 
9
-	/**
10
-	 * @var Sync_Background_Process
11
-	 */
12
-	private $context;
9
+    /**
10
+     * @var Sync_Background_Process
11
+     */
12
+    private $context;
13 13
 
14
-	public function __construct( $context ) {
15
-		parent::__construct( Sync_Background_Process::STATE_STOPPED );
14
+    public function __construct( $context ) {
15
+        parent::__construct( 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->unschedule();
22
-		$this->context->set_state( Sync_Background_Process::STATE_STOPPED );
23
-	}
20
+    public function enter() {
21
+        $this->context->unschedule();
22
+        $this->context->set_state( Sync_Background_Process::STATE_STOPPED );
23
+    }
24 24
 
25
-	public function leave() {
26
-		$this->context->set_state( null );
27
-	}
25
+    public function leave() {
26
+        $this->context->set_state( null );
27
+    }
28 28
 
29
-	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
30
-	public function task( $item ) {
29
+    // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
30
+    public function task( $item ) {
31 31
 
32 32
 
33
-		return State::complete();
34
-	}
33
+        return State::complete();
34
+    }
35 35
 
36 36
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,23 +11,23 @@
 block discarded – undo
11 11
 	 */
12 12
 	private $context;
13 13
 
14
-	public function __construct( $context ) {
15
-		parent::__construct( Sync_Background_Process::STATE_STOPPED );
14
+	public function __construct($context) {
15
+		parent::__construct(Sync_Background_Process::STATE_STOPPED);
16 16
 
17 17
 		$this->context = $context;
18 18
 	}
19 19
 
20 20
 	public function enter() {
21 21
 		$this->context->unschedule();
22
-		$this->context->set_state( Sync_Background_Process::STATE_STOPPED );
22
+		$this->context->set_state(Sync_Background_Process::STATE_STOPPED);
23 23
 	}
24 24
 
25 25
 	public function leave() {
26
-		$this->context->set_state( null );
26
+		$this->context->set_state(null);
27 27
 	}
28 28
 
29 29
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
30
-	public function task( $item ) {
30
+	public function task($item) {
31 31
 
32 32
 		return State::complete();
33 33
 	}
Please login to merge, or discard this patch.
wordlift/dataset/background/class-sync-background-process-started-state.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -42,16 +42,16 @@  discard block
 block discarded – undo
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( Sync_Background_Process::STATE_STARTED );
45
+	public function __construct($context, $sync_service, $sync_object_adapter_factory, $reset = true) {
46
+		parent::__construct(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
 block discarded – undo
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( Sync_Background_Process::STATE_STARTED );
78
+		$this->context->set_state(Sync_Background_Process::STATE_STARTED);
79 79
 
80 80
 		$this->resume();
81 81
 	}
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
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,35 +94,35 @@  discard block
 block discarded – undo
94 94
 	 * @return State
95 95
 	 */
96 96
 	// phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
97
-	public function task( $args ) {
98
-		$offset     = get_option( '_wl_sync_background_process_offset' );
99
-		$stage      = get_option( '_wl_sync_background_process_stage' );
100
-		$counts     = get_option( '_wl_sync_background_process_count' );
101
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
97
+	public function task($args) {
98
+		$offset     = get_option('_wl_sync_background_process_offset');
99
+		$stage      = get_option('_wl_sync_background_process_stage');
100
+		$counts     = get_option('_wl_sync_background_process_count');
101
+		$batch_size = min($counts[$stage] - $offset, $this->batch_size);
102 102
 
103
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
103
+		add_filter('wl_api_service__request', array($this, 'api_service__request'));
104 104
 		try {
105
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
106
-			$this->sync_service->sync_many( $object_adapters, true );
105
+			$object_adapters = $this->stages[$stage]->get_sync_object_adapters($offset, $batch_size);
106
+			$this->sync_service->sync_many($object_adapters, true);
107 107
 		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
108
-		} catch ( \Exception $e ) {
108
+		} catch (\Exception $e) {
109 109
 			// ignored.
110 110
 		}
111
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
111
+		remove_filter('wl_api_service__request', array($this, 'api_service__request'));
112 112
 
113
-		update_option( '_wl_sync_background_process_updated', time(), true );
113
+		update_option('_wl_sync_background_process_updated', time(), true);
114 114
 
115 115
 		// Increase the offset.
116
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
117
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
116
+		if (($offset + $batch_size) < $counts[$stage]) {
117
+			update_option('_wl_sync_background_process_offset', $offset + $batch_size, true);
118 118
 
119 119
 			return State::items_in_queue();
120 120
 		}
121 121
 
122 122
 		// Increase the stage.
123
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
124
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
125
-			update_option( '_wl_sync_background_process_offset', 0, true );
123
+		if (($stage + 1) < count($this->stages)) {
124
+			update_option('_wl_sync_background_process_stage', $stage + 1, true);
125
+			update_option('_wl_sync_background_process_offset', 0, true);
126 126
 
127 127
 			return State::items_in_queue();
128 128
 		}
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
 	 *
140 140
 	 * @return mixed
141 141
 	 */
142
-	public function api_service__request( $args ) {
142
+	public function api_service__request($args) {
143 143
 
144
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
144
+		$state_header_value = str_replace("\n", '', wp_json_encode($this->context->get_info()));
145 145
 
146 146
 		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
147 147
 
Please login to merge, or discard this patch.
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -12,138 +12,138 @@
 block discarded – undo
12 12
 
13 13
 class Sync_Background_Process_Started_State extends Abstract_Sync_Background_Process_State {
14 14
 
15
-	/**
16
-	 * @var 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 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( 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( 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
-		$offset     = get_option( '_wl_sync_background_process_offset' );
99
-		$stage      = get_option( '_wl_sync_background_process_stage' );
100
-		$counts     = get_option( '_wl_sync_background_process_count' );
101
-		$batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
102
-
103
-		add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
104
-		try {
105
-			$object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
106
-			$this->sync_service->sync_many( $object_adapters, true );
107
-		// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
108
-		} catch ( \Exception $e ) {
109
-			// ignored.
110
-		}
111
-		remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
112
-
113
-		update_option( '_wl_sync_background_process_updated', time(), true );
114
-
115
-		// Increase the offset.
116
-		if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
117
-			update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
118
-
119
-			return State::items_in_queue();
120
-		}
121
-
122
-		// Increase the stage.
123
-		if ( ( $stage + 1 ) < count( $this->stages ) ) {
124
-			update_option( '_wl_sync_background_process_stage', $stage + 1, true );
125
-			update_option( '_wl_sync_background_process_offset', 0, true );
126
-
127
-			return State::items_in_queue();
128
-		}
129
-
130
-		return State::complete();
131
-	}
132
-
133
-	/**
134
-	 * Hook to provide a request to update the status on the server.
135
-	 *
136
-	 * @param array $args
137
-	 *
138
-	 * @return mixed
139
-	 */
140
-	public function api_service__request( $args ) {
141
-
142
-		$state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
143
-
144
-		$args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
145
-
146
-		return $args;
147
-	}
15
+    /**
16
+     * @var 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 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( 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( 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
+        $offset     = get_option( '_wl_sync_background_process_offset' );
99
+        $stage      = get_option( '_wl_sync_background_process_stage' );
100
+        $counts     = get_option( '_wl_sync_background_process_count' );
101
+        $batch_size = min( $counts[ $stage ] - $offset, $this->batch_size );
102
+
103
+        add_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
104
+        try {
105
+            $object_adapters = $this->stages[ $stage ]->get_sync_object_adapters( $offset, $batch_size );
106
+            $this->sync_service->sync_many( $object_adapters, true );
107
+        // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
108
+        } catch ( \Exception $e ) {
109
+            // ignored.
110
+        }
111
+        remove_filter( 'wl_api_service__request', array( $this, 'api_service__request' ) );
112
+
113
+        update_option( '_wl_sync_background_process_updated', time(), true );
114
+
115
+        // Increase the offset.
116
+        if ( ( $offset + $batch_size ) < $counts[ $stage ] ) {
117
+            update_option( '_wl_sync_background_process_offset', $offset + $batch_size, true );
118
+
119
+            return State::items_in_queue();
120
+        }
121
+
122
+        // Increase the stage.
123
+        if ( ( $stage + 1 ) < count( $this->stages ) ) {
124
+            update_option( '_wl_sync_background_process_stage', $stage + 1, true );
125
+            update_option( '_wl_sync_background_process_offset', 0, true );
126
+
127
+            return State::items_in_queue();
128
+        }
129
+
130
+        return State::complete();
131
+    }
132
+
133
+    /**
134
+     * Hook to provide a request to update the status on the server.
135
+     *
136
+     * @param array $args
137
+     *
138
+     * @return mixed
139
+     */
140
+    public function api_service__request( $args ) {
141
+
142
+        $state_header_value = str_replace( "\n", '', wp_json_encode( $this->context->get_info() ) );
143
+
144
+        $args['headers']['X-Wordlift-Dataset-Sync-State-V1'] = $state_header_value;
145
+
146
+        return $args;
147
+    }
148 148
 
149 149
 }
Please login to merge, or discard this patch.
src/wordlift/dataset/index.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,38 +15,38 @@
 block discarded – undo
15 15
 use Wordlift\Jsonld\Jsonld_Service;
16 16
 
17 17
 if ( ! defined( 'ABSPATH' ) ) {
18
-	exit;
18
+    exit;
19 19
 }
20 20
 
21 21
 // Register the Dataset JSON Endpoint.
22 22
 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
23 23
 if ( apply_filters( 'wl_feature__enable__dataset-ng', false ) ) {
24 24
 
25
-	$sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
26
-	$sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
27
-	new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
28
-	new Sync_User_Hooks( $sync_service );
29
-
30
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
31
-	if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
32
-		new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
33
-	}
34
-	/**
35
-	 * @since 3.28.0
36
-	 * @see https://github.com/insideout10/wordlift-plugin/issues/1186
37
-	 */
38
-	new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
39
-
40
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
41
-	if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
42
-		new Sync_Hooks_Wordpress_Ontology();
43
-	}
44
-
45
-	// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
46
-	if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
47
-		// Set up the sync background process.
48
-		$sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
49
-		new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
50
-		new Sync_Page();
51
-	}
25
+    $sync_object_adapter_factory = new Sync_Object_Adapter_Factory();
26
+    $sync_service                = new Sync_Service( Default_Api_Service::get_instance(), $sync_object_adapter_factory, Jsonld_Service::get_instance(), Wordlift_Entity_Service::get_instance() );
27
+    new Sync_Post_Hooks( $sync_service, $sync_object_adapter_factory );
28
+    new Sync_User_Hooks( $sync_service );
29
+
30
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
31
+    if ( apply_filters( 'wl_feature__enable__no-vocabulary-terms', false ) ) {
32
+        new Sync_Term_Hooks( $sync_service, $sync_object_adapter_factory );
33
+    }
34
+    /**
35
+     * @since 3.28.0
36
+     * @see https://github.com/insideout10/wordlift-plugin/issues/1186
37
+     */
38
+    new Sync_Hooks_Entity_Relation( Wordlift_Entity_Service::get_instance() );
39
+
40
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
41
+    if ( apply_filters( 'wl_feature__enable__wordpress-ontology', false ) ) {
42
+        new Sync_Hooks_Wordpress_Ontology();
43
+    }
44
+
45
+    // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
46
+    if ( apply_filters( 'wl_feature__enable__sync-background', false ) ) {
47
+        // Set up the sync background process.
48
+        $sync_background_process = new Sync_Background_Process( $sync_service, $sync_object_adapter_factory );
49
+        new Sync_Background_Process_Wpjson_Endpoint( $sync_background_process );
50
+        new Sync_Page();
51
+    }
52 52
 }
Please login to merge, or discard this patch.
tests/phpunit/schedules/ActionScheduler_CronSchedule_Test.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -6,72 +6,72 @@
 block discarded – undo
6 6
  * @group schedules
7 7
  */
8 8
 class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase {
9
-	public function test_creation() {
10
-		$time  = as_get_datetime_object( 'tomorrow' );
11
-		$cron  = CronExpression::factory( '@daily' );
12
-		$start = clone $time;
13
-		$start->modify( '-1 hour' );
14
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron );
15
-		$this->assertEquals( $time, $schedule->get_date() );
16
-		$this->assertEquals( $start, $schedule->get_first_date() );
9
+    public function test_creation() {
10
+        $time  = as_get_datetime_object( 'tomorrow' );
11
+        $cron  = CronExpression::factory( '@daily' );
12
+        $start = clone $time;
13
+        $start->modify( '-1 hour' );
14
+        $schedule = new ActionScheduler_CronSchedule( $start, $cron );
15
+        $this->assertEquals( $time, $schedule->get_date() );
16
+        $this->assertEquals( $start, $schedule->get_first_date() );
17 17
 
18
-		// Test delaying for a future start date
19
-		$start->modify( '+1 week' );
20
-		$time->modify( '+1 week' );
18
+        // Test delaying for a future start date
19
+        $start->modify( '+1 week' );
20
+        $time->modify( '+1 week' );
21 21
 
22
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron );
23
-		$this->assertEquals( $time, $schedule->get_date() );
24
-		$this->assertEquals( $start, $schedule->get_first_date() );
25
-	}
22
+        $schedule = new ActionScheduler_CronSchedule( $start, $cron );
23
+        $this->assertEquals( $time, $schedule->get_date() );
24
+        $this->assertEquals( $start, $schedule->get_first_date() );
25
+    }
26 26
 
27
-	public function test_creation_with_first_date() {
28
-		$time  = as_get_datetime_object( 'tomorrow' );
29
-		$cron  = CronExpression::factory( '@daily' );
30
-		$start = clone $time;
31
-		$start->modify( '-1 hour' );
32
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron );
33
-		$this->assertEquals( $time, $schedule->get_date() );
34
-		$this->assertEquals( $start, $schedule->get_first_date() );
27
+    public function test_creation_with_first_date() {
28
+        $time  = as_get_datetime_object( 'tomorrow' );
29
+        $cron  = CronExpression::factory( '@daily' );
30
+        $start = clone $time;
31
+        $start->modify( '-1 hour' );
32
+        $schedule = new ActionScheduler_CronSchedule( $start, $cron );
33
+        $this->assertEquals( $time, $schedule->get_date() );
34
+        $this->assertEquals( $start, $schedule->get_first_date() );
35 35
 
36
-		// Test delaying for a future start date
37
-		$first = clone $time;
38
-		$first->modify( '-1 day' );
39
-		$start->modify( '+1 week' );
40
-		$time->modify( '+1 week' );
36
+        // Test delaying for a future start date
37
+        $first = clone $time;
38
+        $first->modify( '-1 day' );
39
+        $start->modify( '+1 week' );
40
+        $time->modify( '+1 week' );
41 41
 
42
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron, $first );
43
-		$this->assertEquals( $time, $schedule->get_date() );
44
-		$this->assertEquals( $first, $schedule->get_first_date() );
45
-	}
42
+        $schedule = new ActionScheduler_CronSchedule( $start, $cron, $first );
43
+        $this->assertEquals( $time, $schedule->get_date() );
44
+        $this->assertEquals( $first, $schedule->get_first_date() );
45
+    }
46 46
 
47
-	public function test_next() {
48
-		$time     = as_get_datetime_object( '2013-06-14' );
49
-		$cron     = CronExpression::factory( '@daily' );
50
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
51
-		$this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) );
52
-	}
47
+    public function test_next() {
48
+        $time     = as_get_datetime_object( '2013-06-14' );
49
+        $cron     = CronExpression::factory( '@daily' );
50
+        $schedule = new ActionScheduler_CronSchedule( $time, $cron );
51
+        $this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) );
52
+    }
53 53
 
54
-	public function test_is_recurring() {
55
-		$schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) );
56
-		$this->assertTrue( $schedule->is_recurring() );
57
-	}
54
+    public function test_is_recurring() {
55
+        $schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) );
56
+        $this->assertTrue( $schedule->is_recurring() );
57
+    }
58 58
 
59
-	public function test_cron_format() {
60
-		$time     = as_get_datetime_object( '2014-01-01' );
61
-		$cron     = CronExpression::factory( '0 0 10 10 *' );
62
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
63
-		$this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() );
59
+    public function test_cron_format() {
60
+        $time     = as_get_datetime_object( '2014-01-01' );
61
+        $cron     = CronExpression::factory( '0 0 10 10 *' );
62
+        $schedule = new ActionScheduler_CronSchedule( $time, $cron );
63
+        $this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() );
64 64
 
65
-		$cron     = CronExpression::factory( '0 0 L 1/2 *' );
66
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
67
-		$this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() );
68
-		$this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) );
69
-		$this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) );
65
+        $cron     = CronExpression::factory( '0 0 L 1/2 *' );
66
+        $schedule = new ActionScheduler_CronSchedule( $time, $cron );
67
+        $this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() );
68
+        $this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) );
69
+        $this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) );
70 70
 
71
-		$cron     = CronExpression::factory( '30 14 * * MON#3 *' );
72
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
73
-		$this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() );
74
-		$this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) );
75
-	}
71
+        $cron     = CronExpression::factory( '30 14 * * MON#3 *' );
72
+        $schedule = new ActionScheduler_CronSchedule( $time, $cron );
73
+        $this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() );
74
+        $this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) );
75
+    }
76 76
 }
77 77
 
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -7,71 +7,71 @@
 block discarded – undo
7 7
  */
8 8
 class ActionScheduler_CronSchedule_Test extends ActionScheduler_UnitTestCase {
9 9
 	public function test_creation() {
10
-		$time  = as_get_datetime_object( 'tomorrow' );
11
-		$cron  = CronExpression::factory( '@daily' );
10
+		$time  = as_get_datetime_object('tomorrow');
11
+		$cron  = CronExpression::factory('@daily');
12 12
 		$start = clone $time;
13
-		$start->modify( '-1 hour' );
14
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron );
15
-		$this->assertEquals( $time, $schedule->get_date() );
16
-		$this->assertEquals( $start, $schedule->get_first_date() );
13
+		$start->modify('-1 hour');
14
+		$schedule = new ActionScheduler_CronSchedule($start, $cron);
15
+		$this->assertEquals($time, $schedule->get_date());
16
+		$this->assertEquals($start, $schedule->get_first_date());
17 17
 
18 18
 		// Test delaying for a future start date
19
-		$start->modify( '+1 week' );
20
-		$time->modify( '+1 week' );
19
+		$start->modify('+1 week');
20
+		$time->modify('+1 week');
21 21
 
22
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron );
23
-		$this->assertEquals( $time, $schedule->get_date() );
24
-		$this->assertEquals( $start, $schedule->get_first_date() );
22
+		$schedule = new ActionScheduler_CronSchedule($start, $cron);
23
+		$this->assertEquals($time, $schedule->get_date());
24
+		$this->assertEquals($start, $schedule->get_first_date());
25 25
 	}
26 26
 
27 27
 	public function test_creation_with_first_date() {
28
-		$time  = as_get_datetime_object( 'tomorrow' );
29
-		$cron  = CronExpression::factory( '@daily' );
28
+		$time  = as_get_datetime_object('tomorrow');
29
+		$cron  = CronExpression::factory('@daily');
30 30
 		$start = clone $time;
31
-		$start->modify( '-1 hour' );
32
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron );
33
-		$this->assertEquals( $time, $schedule->get_date() );
34
-		$this->assertEquals( $start, $schedule->get_first_date() );
31
+		$start->modify('-1 hour');
32
+		$schedule = new ActionScheduler_CronSchedule($start, $cron);
33
+		$this->assertEquals($time, $schedule->get_date());
34
+		$this->assertEquals($start, $schedule->get_first_date());
35 35
 
36 36
 		// Test delaying for a future start date
37 37
 		$first = clone $time;
38
-		$first->modify( '-1 day' );
39
-		$start->modify( '+1 week' );
40
-		$time->modify( '+1 week' );
38
+		$first->modify('-1 day');
39
+		$start->modify('+1 week');
40
+		$time->modify('+1 week');
41 41
 
42
-		$schedule = new ActionScheduler_CronSchedule( $start, $cron, $first );
43
-		$this->assertEquals( $time, $schedule->get_date() );
44
-		$this->assertEquals( $first, $schedule->get_first_date() );
42
+		$schedule = new ActionScheduler_CronSchedule($start, $cron, $first);
43
+		$this->assertEquals($time, $schedule->get_date());
44
+		$this->assertEquals($first, $schedule->get_first_date());
45 45
 	}
46 46
 
47 47
 	public function test_next() {
48
-		$time     = as_get_datetime_object( '2013-06-14' );
49
-		$cron     = CronExpression::factory( '@daily' );
50
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
51
-		$this->assertEquals( as_get_datetime_object( 'tomorrow' ), $schedule->get_next( as_get_datetime_object() ) );
48
+		$time     = as_get_datetime_object('2013-06-14');
49
+		$cron     = CronExpression::factory('@daily');
50
+		$schedule = new ActionScheduler_CronSchedule($time, $cron);
51
+		$this->assertEquals(as_get_datetime_object('tomorrow'), $schedule->get_next(as_get_datetime_object()));
52 52
 	}
53 53
 
54 54
 	public function test_is_recurring() {
55
-		$schedule = new ActionScheduler_CronSchedule( as_get_datetime_object( '2013-06-14' ), CronExpression::factory( '@daily' ) );
56
-		$this->assertTrue( $schedule->is_recurring() );
55
+		$schedule = new ActionScheduler_CronSchedule(as_get_datetime_object('2013-06-14'), CronExpression::factory('@daily'));
56
+		$this->assertTrue($schedule->is_recurring());
57 57
 	}
58 58
 
59 59
 	public function test_cron_format() {
60
-		$time     = as_get_datetime_object( '2014-01-01' );
61
-		$cron     = CronExpression::factory( '0 0 10 10 *' );
62
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
63
-		$this->assertEquals( as_get_datetime_object( '2014-10-10' ), $schedule->get_date() );
60
+		$time     = as_get_datetime_object('2014-01-01');
61
+		$cron     = CronExpression::factory('0 0 10 10 *');
62
+		$schedule = new ActionScheduler_CronSchedule($time, $cron);
63
+		$this->assertEquals(as_get_datetime_object('2014-10-10'), $schedule->get_date());
64 64
 
65
-		$cron     = CronExpression::factory( '0 0 L 1/2 *' );
66
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
67
-		$this->assertEquals( as_get_datetime_object( '2014-01-31' ), $schedule->get_date() );
68
-		$this->assertEquals( as_get_datetime_object( '2014-07-31' ), $schedule->get_next( as_get_datetime_object( '2014-06-01' ) ) );
69
-		$this->assertEquals( as_get_datetime_object( '2028-11-30' ), $schedule->get_next( as_get_datetime_object( '2028-11-01' ) ) );
65
+		$cron     = CronExpression::factory('0 0 L 1/2 *');
66
+		$schedule = new ActionScheduler_CronSchedule($time, $cron);
67
+		$this->assertEquals(as_get_datetime_object('2014-01-31'), $schedule->get_date());
68
+		$this->assertEquals(as_get_datetime_object('2014-07-31'), $schedule->get_next(as_get_datetime_object('2014-06-01')));
69
+		$this->assertEquals(as_get_datetime_object('2028-11-30'), $schedule->get_next(as_get_datetime_object('2028-11-01')));
70 70
 
71
-		$cron     = CronExpression::factory( '30 14 * * MON#3 *' );
72
-		$schedule = new ActionScheduler_CronSchedule( $time, $cron );
73
-		$this->assertEquals( as_get_datetime_object( '2014-01-20 14:30:00' ), $schedule->get_date() );
74
-		$this->assertEquals( as_get_datetime_object( '2014-05-19 14:30:00' ), $schedule->get_next( as_get_datetime_object( '2014-05-01' ) ) );
71
+		$cron     = CronExpression::factory('30 14 * * MON#3 *');
72
+		$schedule = new ActionScheduler_CronSchedule($time, $cron);
73
+		$this->assertEquals(as_get_datetime_object('2014-01-20 14:30:00'), $schedule->get_date());
74
+		$this->assertEquals(as_get_datetime_object('2014-05-19 14:30:00'), $schedule->get_next(as_get_datetime_object('2014-05-01')));
75 75
 	}
76 76
 }
77 77
 
Please login to merge, or discard this patch.