Completed
Push — develop ( 36a199...920e68 )
by David
01:14
created
action-scheduler/classes/abstracts/ActionScheduler_Abstract_Schedule.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	/**
23 23
 	 * @param DateTime $date The date & time to run the action.
24 24
 	 */
25
-	public function __construct( DateTime $date ) {
25
+	public function __construct(DateTime $date) {
26 26
 		$this->scheduled_date = $date;
27 27
 	}
28 28
 
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @param DateTime $after
40 40
 	 * @return DateTime
41 41
 	 */
42
-	abstract protected function calculate_next( DateTime $after );
42
+	abstract protected function calculate_next(DateTime $after);
43 43
 
44 44
 	/**
45 45
 	 * Get the next date & time when this schedule should run after a given date & time.
@@ -47,10 +47,10 @@  discard block
 block discarded – undo
47 47
 	 * @param DateTime $after
48 48
 	 * @return DateTime|null
49 49
 	 */
50
-	public function get_next( DateTime $after ) {
50
+	public function get_next(DateTime $after) {
51 51
 		$after = clone $after;
52
-		if ( $after > $this->scheduled_date ) {
53
-			$after = $this->calculate_next( $after );
52
+		if ($after > $this->scheduled_date) {
53
+			$after = $this->calculate_next($after);
54 54
 			return $after;
55 55
 		}
56 56
 		return clone $this->scheduled_date;
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 	}
78 78
 
79 79
 	public function __wakeup() {
80
-		$this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
81
-		unset( $this->scheduled_timestamp );
80
+		$this->scheduled_date = as_get_datetime_object($this->scheduled_timestamp);
81
+		unset($this->scheduled_timestamp);
82 82
 	}
83 83
 }
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -5,80 +5,80 @@
 block discarded – undo
5 5
  */
6 6
 abstract class ActionScheduler_Abstract_Schedule extends ActionScheduler_Schedule_Deprecated {
7 7
 
8
-	/**
9
-	 * The date & time the schedule is set to run.
10
-	 *
11
-	 * @var DateTime
12
-	 */
13
-	private $scheduled_date = null;
8
+    /**
9
+     * The date & time the schedule is set to run.
10
+     *
11
+     * @var DateTime
12
+     */
13
+    private $scheduled_date = null;
14 14
 
15
-	/**
16
-	 * Timestamp equivalent of @see $this->scheduled_date
17
-	 *
18
-	 * @var int
19
-	 */
20
-	protected $scheduled_timestamp = null;
15
+    /**
16
+     * Timestamp equivalent of @see $this->scheduled_date
17
+     *
18
+     * @var int
19
+     */
20
+    protected $scheduled_timestamp = null;
21 21
 
22
-	/**
23
-	 * @param DateTime $date The date & time to run the action.
24
-	 */
25
-	public function __construct( DateTime $date ) {
26
-		$this->scheduled_date = $date;
27
-	}
22
+    /**
23
+     * @param DateTime $date The date & time to run the action.
24
+     */
25
+    public function __construct( DateTime $date ) {
26
+        $this->scheduled_date = $date;
27
+    }
28 28
 
29
-	/**
30
-	 * Check if a schedule should recur.
31
-	 *
32
-	 * @return bool
33
-	 */
34
-	abstract public function is_recurring();
29
+    /**
30
+     * Check if a schedule should recur.
31
+     *
32
+     * @return bool
33
+     */
34
+    abstract public function is_recurring();
35 35
 
36
-	/**
37
-	 * Calculate when the next instance of this schedule would run based on a given date & time.
38
-	 *
39
-	 * @param DateTime $after
40
-	 * @return DateTime
41
-	 */
42
-	abstract protected function calculate_next( DateTime $after );
36
+    /**
37
+     * Calculate when the next instance of this schedule would run based on a given date & time.
38
+     *
39
+     * @param DateTime $after
40
+     * @return DateTime
41
+     */
42
+    abstract protected function calculate_next( DateTime $after );
43 43
 
44
-	/**
45
-	 * Get the next date & time when this schedule should run after a given date & time.
46
-	 *
47
-	 * @param DateTime $after
48
-	 * @return DateTime|null
49
-	 */
50
-	public function get_next( DateTime $after ) {
51
-		$after = clone $after;
52
-		if ( $after > $this->scheduled_date ) {
53
-			$after = $this->calculate_next( $after );
54
-			return $after;
55
-		}
56
-		return clone $this->scheduled_date;
57
-	}
44
+    /**
45
+     * Get the next date & time when this schedule should run after a given date & time.
46
+     *
47
+     * @param DateTime $after
48
+     * @return DateTime|null
49
+     */
50
+    public function get_next( DateTime $after ) {
51
+        $after = clone $after;
52
+        if ( $after > $this->scheduled_date ) {
53
+            $after = $this->calculate_next( $after );
54
+            return $after;
55
+        }
56
+        return clone $this->scheduled_date;
57
+    }
58 58
 
59
-	/**
60
-	 * Get the date & time the schedule is set to run.
61
-	 *
62
-	 * @return DateTime|null
63
-	 */
64
-	public function get_date() {
65
-		return $this->scheduled_date;
66
-	}
59
+    /**
60
+     * Get the date & time the schedule is set to run.
61
+     *
62
+     * @return DateTime|null
63
+     */
64
+    public function get_date() {
65
+        return $this->scheduled_date;
66
+    }
67 67
 
68
-	/**
69
-	 * For PHP 5.2 compat, since DateTime objects can't be serialized
70
-	 *
71
-	 * @return array
72
-	 */
73
-	public function __sleep() {
74
-		$this->scheduled_timestamp = $this->scheduled_date->getTimestamp();
75
-		return array(
76
-			'scheduled_timestamp',
77
-		);
78
-	}
68
+    /**
69
+     * For PHP 5.2 compat, since DateTime objects can't be serialized
70
+     *
71
+     * @return array
72
+     */
73
+    public function __sleep() {
74
+        $this->scheduled_timestamp = $this->scheduled_date->getTimestamp();
75
+        return array(
76
+            'scheduled_timestamp',
77
+        );
78
+    }
79 79
 
80
-	public function __wakeup() {
81
-		$this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
82
-		unset( $this->scheduled_timestamp );
83
-	}
80
+    public function __wakeup() {
81
+        $this->scheduled_date = as_get_datetime_object( $this->scheduled_timestamp );
82
+        unset( $this->scheduled_timestamp );
83
+    }
84 84
 }
Please login to merge, or discard this patch.
action-scheduler/classes/WP_CLI/ActionScheduler_WPCLI_Scheduler_command.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -5,184 +5,184 @@
 block discarded – undo
5 5
  */
6 6
 class ActionScheduler_WPCLI_Scheduler_command extends WP_CLI_Command {
7 7
 
8
-	/**
9
-	 * Force tables schema creation for Action Scheduler
10
-	 *
11
-	 * ## OPTIONS
12
-	 *
13
-	 * @param array $args Positional arguments.
14
-	 * @param array $assoc_args Keyed arguments.
15
-	 *
16
-	 * @subcommand fix-schema
17
-	 */
18
-	public function fix_schema( $args, $assoc_args ) {
19
-		$schema_classes = array( ActionScheduler_LoggerSchema::class, ActionScheduler_StoreSchema::class );
20
-
21
-		foreach ( $schema_classes as $classname ) {
22
-			if ( is_subclass_of( $classname, ActionScheduler_Abstract_Schema::class ) ) {
23
-				$obj = new $classname();
24
-				$obj->init();
25
-				$obj->register_tables( true );
26
-
27
-				WP_CLI::success(
28
-					sprintf(
29
-						/* translators: %s refers to the schema name*/
30
-						__( 'Registered schema for %s', 'action-scheduler' ),
31
-						$classname
32
-					)
33
-				);
34
-			}
35
-		}
36
-	}
37
-
38
-	/**
39
-	 * Run the Action Scheduler
40
-	 *
41
-	 * ## OPTIONS
42
-	 *
43
-	 * [--batch-size=<size>]
44
-	 * : The maximum number of actions to run. Defaults to 100.
45
-	 *
46
-	 * [--batches=<size>]
47
-	 * : Limit execution to a number of batches. Defaults to 0, meaning batches will continue being executed until all actions are complete.
48
-	 *
49
-	 * [--cleanup-batch-size=<size>]
50
-	 * : The maximum number of actions to clean up. Defaults to the value of --batch-size.
51
-	 *
52
-	 * [--hooks=<hooks>]
53
-	 * : Only run actions with the specified hook. Omitting this option runs actions with any hook. Define multiple hooks as a comma separated string (without spaces), e.g. `--hooks=hook_one,hook_two,hook_three`
54
-	 *
55
-	 * [--group=<group>]
56
-	 * : Only run actions from the specified group. Omitting this option runs actions from all groups.
57
-	 *
58
-	 * [--free-memory-on=<count>]
59
-	 * : The number of actions to process between freeing memory. 0 disables freeing memory. Default 50.
60
-	 *
61
-	 * [--pause=<seconds>]
62
-	 * : The number of seconds to pause when freeing memory. Default no pause.
63
-	 *
64
-	 * [--force]
65
-	 * : Whether to force execution despite the maximum number of concurrent processes being exceeded.
66
-	 *
67
-	 * @param array $args Positional arguments.
68
-	 * @param array $assoc_args Keyed arguments.
69
-	 * @throws \WP_CLI\ExitException When an error occurs.
70
-	 *
71
-	 * @subcommand run
72
-	 */
73
-	public function run( $args, $assoc_args ) {
74
-		// Handle passed arguments.
75
-		$batch   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) );
76
-		$batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) );
77
-		$clean   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) );
78
-		$hooks   = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) );
79
-		$hooks   = array_filter( array_map( 'trim', $hooks ) );
80
-		$group   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' );
81
-		$free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 );
82
-		$sleep   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 );
83
-		$force   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
84
-
85
-		ActionScheduler_DataController::set_free_ticks( $free_on );
86
-		ActionScheduler_DataController::set_sleep_time( $sleep );
87
-
88
-		$batches_completed = 0;
89
-		$actions_completed = 0;
90
-		$unlimited         = $batches === 0;
91
-
92
-		try {
93
-			// Custom queue cleaner instance.
94
-			$cleaner = new ActionScheduler_QueueCleaner( null, $clean );
95
-
96
-			// Get the queue runner instance
97
-			$runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner );
98
-
99
-			// Determine how many tasks will be run in the first batch.
100
-			$total = $runner->setup( $batch, $hooks, $group, $force );
101
-
102
-			// Run actions for as long as possible.
103
-			while ( $total > 0 ) {
104
-				$this->print_total_actions( $total );
105
-				$actions_completed += $runner->run();
106
-				$batches_completed++;
107
-
108
-				// Maybe set up tasks for the next batch.
109
-				$total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0;
110
-			}
111
-		} catch ( Exception $e ) {
112
-			$this->print_error( $e );
113
-		}
114
-
115
-		$this->print_total_batches( $batches_completed );
116
-		$this->print_success( $actions_completed );
117
-	}
118
-
119
-	/**
120
-	 * Print WP CLI message about how many actions are about to be processed.
121
-	 *
122
-	 * @author Jeremy Pry
123
-	 *
124
-	 * @param int $total
125
-	 */
126
-	protected function print_total_actions( $total ) {
127
-		WP_CLI::log(
128
-			sprintf(
129
-				/* translators: %d refers to how many scheduled taks were found to run */
130
-				_n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler' ),
131
-				number_format_i18n( $total )
132
-			)
133
-		);
134
-	}
135
-
136
-	/**
137
-	 * Print WP CLI message about how many batches of actions were processed.
138
-	 *
139
-	 * @author Jeremy Pry
140
-	 *
141
-	 * @param int $batches_completed
142
-	 */
143
-	protected function print_total_batches( $batches_completed ) {
144
-		WP_CLI::log(
145
-			sprintf(
146
-				/* translators: %d refers to the total number of batches executed */
147
-				_n( '%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler' ),
148
-				number_format_i18n( $batches_completed )
149
-			)
150
-		);
151
-	}
152
-
153
-	/**
154
-	 * Convert an exception into a WP CLI error.
155
-	 *
156
-	 * @author Jeremy Pry
157
-	 *
158
-	 * @param Exception $e The error object.
159
-	 *
160
-	 * @throws \WP_CLI\ExitException
161
-	 */
162
-	protected function print_error( Exception $e ) {
163
-		WP_CLI::error(
164
-			sprintf(
165
-				/* translators: %s refers to the exception error message */
166
-				__( 'There was an error running the action scheduler: %s', 'action-scheduler' ),
167
-				$e->getMessage()
168
-			)
169
-		);
170
-	}
171
-
172
-	/**
173
-	 * Print a success message with the number of completed actions.
174
-	 *
175
-	 * @author Jeremy Pry
176
-	 *
177
-	 * @param int $actions_completed
178
-	 */
179
-	protected function print_success( $actions_completed ) {
180
-		WP_CLI::success(
181
-			sprintf(
182
-				/* translators: %d refers to the total number of taskes completed */
183
-				_n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler' ),
184
-				number_format_i18n( $actions_completed )
185
-			)
186
-		);
187
-	}
8
+    /**
9
+     * Force tables schema creation for Action Scheduler
10
+     *
11
+     * ## OPTIONS
12
+     *
13
+     * @param array $args Positional arguments.
14
+     * @param array $assoc_args Keyed arguments.
15
+     *
16
+     * @subcommand fix-schema
17
+     */
18
+    public function fix_schema( $args, $assoc_args ) {
19
+        $schema_classes = array( ActionScheduler_LoggerSchema::class, ActionScheduler_StoreSchema::class );
20
+
21
+        foreach ( $schema_classes as $classname ) {
22
+            if ( is_subclass_of( $classname, ActionScheduler_Abstract_Schema::class ) ) {
23
+                $obj = new $classname();
24
+                $obj->init();
25
+                $obj->register_tables( true );
26
+
27
+                WP_CLI::success(
28
+                    sprintf(
29
+                        /* translators: %s refers to the schema name*/
30
+                        __( 'Registered schema for %s', 'action-scheduler' ),
31
+                        $classname
32
+                    )
33
+                );
34
+            }
35
+        }
36
+    }
37
+
38
+    /**
39
+     * Run the Action Scheduler
40
+     *
41
+     * ## OPTIONS
42
+     *
43
+     * [--batch-size=<size>]
44
+     * : The maximum number of actions to run. Defaults to 100.
45
+     *
46
+     * [--batches=<size>]
47
+     * : Limit execution to a number of batches. Defaults to 0, meaning batches will continue being executed until all actions are complete.
48
+     *
49
+     * [--cleanup-batch-size=<size>]
50
+     * : The maximum number of actions to clean up. Defaults to the value of --batch-size.
51
+     *
52
+     * [--hooks=<hooks>]
53
+     * : Only run actions with the specified hook. Omitting this option runs actions with any hook. Define multiple hooks as a comma separated string (without spaces), e.g. `--hooks=hook_one,hook_two,hook_three`
54
+     *
55
+     * [--group=<group>]
56
+     * : Only run actions from the specified group. Omitting this option runs actions from all groups.
57
+     *
58
+     * [--free-memory-on=<count>]
59
+     * : The number of actions to process between freeing memory. 0 disables freeing memory. Default 50.
60
+     *
61
+     * [--pause=<seconds>]
62
+     * : The number of seconds to pause when freeing memory. Default no pause.
63
+     *
64
+     * [--force]
65
+     * : Whether to force execution despite the maximum number of concurrent processes being exceeded.
66
+     *
67
+     * @param array $args Positional arguments.
68
+     * @param array $assoc_args Keyed arguments.
69
+     * @throws \WP_CLI\ExitException When an error occurs.
70
+     *
71
+     * @subcommand run
72
+     */
73
+    public function run( $args, $assoc_args ) {
74
+        // Handle passed arguments.
75
+        $batch   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) );
76
+        $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) );
77
+        $clean   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) );
78
+        $hooks   = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) );
79
+        $hooks   = array_filter( array_map( 'trim', $hooks ) );
80
+        $group   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' );
81
+        $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 );
82
+        $sleep   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 );
83
+        $force   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
84
+
85
+        ActionScheduler_DataController::set_free_ticks( $free_on );
86
+        ActionScheduler_DataController::set_sleep_time( $sleep );
87
+
88
+        $batches_completed = 0;
89
+        $actions_completed = 0;
90
+        $unlimited         = $batches === 0;
91
+
92
+        try {
93
+            // Custom queue cleaner instance.
94
+            $cleaner = new ActionScheduler_QueueCleaner( null, $clean );
95
+
96
+            // Get the queue runner instance
97
+            $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner );
98
+
99
+            // Determine how many tasks will be run in the first batch.
100
+            $total = $runner->setup( $batch, $hooks, $group, $force );
101
+
102
+            // Run actions for as long as possible.
103
+            while ( $total > 0 ) {
104
+                $this->print_total_actions( $total );
105
+                $actions_completed += $runner->run();
106
+                $batches_completed++;
107
+
108
+                // Maybe set up tasks for the next batch.
109
+                $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0;
110
+            }
111
+        } catch ( Exception $e ) {
112
+            $this->print_error( $e );
113
+        }
114
+
115
+        $this->print_total_batches( $batches_completed );
116
+        $this->print_success( $actions_completed );
117
+    }
118
+
119
+    /**
120
+     * Print WP CLI message about how many actions are about to be processed.
121
+     *
122
+     * @author Jeremy Pry
123
+     *
124
+     * @param int $total
125
+     */
126
+    protected function print_total_actions( $total ) {
127
+        WP_CLI::log(
128
+            sprintf(
129
+                /* translators: %d refers to how many scheduled taks were found to run */
130
+                _n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler' ),
131
+                number_format_i18n( $total )
132
+            )
133
+        );
134
+    }
135
+
136
+    /**
137
+     * Print WP CLI message about how many batches of actions were processed.
138
+     *
139
+     * @author Jeremy Pry
140
+     *
141
+     * @param int $batches_completed
142
+     */
143
+    protected function print_total_batches( $batches_completed ) {
144
+        WP_CLI::log(
145
+            sprintf(
146
+                /* translators: %d refers to the total number of batches executed */
147
+                _n( '%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler' ),
148
+                number_format_i18n( $batches_completed )
149
+            )
150
+        );
151
+    }
152
+
153
+    /**
154
+     * Convert an exception into a WP CLI error.
155
+     *
156
+     * @author Jeremy Pry
157
+     *
158
+     * @param Exception $e The error object.
159
+     *
160
+     * @throws \WP_CLI\ExitException
161
+     */
162
+    protected function print_error( Exception $e ) {
163
+        WP_CLI::error(
164
+            sprintf(
165
+                /* translators: %s refers to the exception error message */
166
+                __( 'There was an error running the action scheduler: %s', 'action-scheduler' ),
167
+                $e->getMessage()
168
+            )
169
+        );
170
+    }
171
+
172
+    /**
173
+     * Print a success message with the number of completed actions.
174
+     *
175
+     * @author Jeremy Pry
176
+     *
177
+     * @param int $actions_completed
178
+     */
179
+    protected function print_success( $actions_completed ) {
180
+        WP_CLI::success(
181
+            sprintf(
182
+                /* translators: %d refers to the total number of taskes completed */
183
+                _n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler' ),
184
+                number_format_i18n( $actions_completed )
185
+            )
186
+        );
187
+    }
188 188
 }
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -15,19 +15,19 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
 	 * @subcommand fix-schema
17 17
 	 */
18
-	public function fix_schema( $args, $assoc_args ) {
19
-		$schema_classes = array( ActionScheduler_LoggerSchema::class, ActionScheduler_StoreSchema::class );
18
+	public function fix_schema($args, $assoc_args) {
19
+		$schema_classes = array(ActionScheduler_LoggerSchema::class, ActionScheduler_StoreSchema::class);
20 20
 
21
-		foreach ( $schema_classes as $classname ) {
22
-			if ( is_subclass_of( $classname, ActionScheduler_Abstract_Schema::class ) ) {
21
+		foreach ($schema_classes as $classname) {
22
+			if (is_subclass_of($classname, ActionScheduler_Abstract_Schema::class)) {
23 23
 				$obj = new $classname();
24 24
 				$obj->init();
25
-				$obj->register_tables( true );
25
+				$obj->register_tables(true);
26 26
 
27 27
 				WP_CLI::success(
28 28
 					sprintf(
29 29
 						/* translators: %s refers to the schema name*/
30
-						__( 'Registered schema for %s', 'action-scheduler' ),
30
+						__('Registered schema for %s', 'action-scheduler'),
31 31
 						$classname
32 32
 					)
33 33
 				);
@@ -70,20 +70,20 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @subcommand run
72 72
 	 */
73
-	public function run( $args, $assoc_args ) {
73
+	public function run($args, $assoc_args) {
74 74
 		// Handle passed arguments.
75
-		$batch   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) );
76
-		$batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) );
77
-		$clean   = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) );
78
-		$hooks   = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) );
79
-		$hooks   = array_filter( array_map( 'trim', $hooks ) );
80
-		$group   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' );
81
-		$free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 );
82
-		$sleep   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 );
83
-		$force   = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false );
84
-
85
-		ActionScheduler_DataController::set_free_ticks( $free_on );
86
-		ActionScheduler_DataController::set_sleep_time( $sleep );
75
+		$batch   = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'batch-size', 100));
76
+		$batches = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'batches', 0));
77
+		$clean   = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'cleanup-batch-size', $batch));
78
+		$hooks   = explode(',', WP_CLI\Utils\get_flag_value($assoc_args, 'hooks', ''));
79
+		$hooks   = array_filter(array_map('trim', $hooks));
80
+		$group   = \WP_CLI\Utils\get_flag_value($assoc_args, 'group', '');
81
+		$free_on = \WP_CLI\Utils\get_flag_value($assoc_args, 'free-memory-on', 50);
82
+		$sleep   = \WP_CLI\Utils\get_flag_value($assoc_args, 'pause', 0);
83
+		$force   = \WP_CLI\Utils\get_flag_value($assoc_args, 'force', false);
84
+
85
+		ActionScheduler_DataController::set_free_ticks($free_on);
86
+		ActionScheduler_DataController::set_sleep_time($sleep);
87 87
 
88 88
 		$batches_completed = 0;
89 89
 		$actions_completed = 0;
@@ -91,29 +91,29 @@  discard block
 block discarded – undo
91 91
 
92 92
 		try {
93 93
 			// Custom queue cleaner instance.
94
-			$cleaner = new ActionScheduler_QueueCleaner( null, $clean );
94
+			$cleaner = new ActionScheduler_QueueCleaner(null, $clean);
95 95
 
96 96
 			// Get the queue runner instance
97
-			$runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner );
97
+			$runner = new ActionScheduler_WPCLI_QueueRunner(null, null, $cleaner);
98 98
 
99 99
 			// Determine how many tasks will be run in the first batch.
100
-			$total = $runner->setup( $batch, $hooks, $group, $force );
100
+			$total = $runner->setup($batch, $hooks, $group, $force);
101 101
 
102 102
 			// Run actions for as long as possible.
103
-			while ( $total > 0 ) {
104
-				$this->print_total_actions( $total );
103
+			while ($total > 0) {
104
+				$this->print_total_actions($total);
105 105
 				$actions_completed += $runner->run();
106 106
 				$batches_completed++;
107 107
 
108 108
 				// Maybe set up tasks for the next batch.
109
-				$total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0;
109
+				$total = ($unlimited || $batches_completed < $batches) ? $runner->setup($batch, $hooks, $group, $force) : 0;
110 110
 			}
111
-		} catch ( Exception $e ) {
112
-			$this->print_error( $e );
111
+		} catch (Exception $e) {
112
+			$this->print_error($e);
113 113
 		}
114 114
 
115
-		$this->print_total_batches( $batches_completed );
116
-		$this->print_success( $actions_completed );
115
+		$this->print_total_batches($batches_completed);
116
+		$this->print_success($actions_completed);
117 117
 	}
118 118
 
119 119
 	/**
@@ -123,12 +123,12 @@  discard block
 block discarded – undo
123 123
 	 *
124 124
 	 * @param int $total
125 125
 	 */
126
-	protected function print_total_actions( $total ) {
126
+	protected function print_total_actions($total) {
127 127
 		WP_CLI::log(
128 128
 			sprintf(
129 129
 				/* translators: %d refers to how many scheduled taks were found to run */
130
-				_n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler' ),
131
-				number_format_i18n( $total )
130
+				_n('Found %d scheduled task', 'Found %d scheduled tasks', $total, 'action-scheduler'),
131
+				number_format_i18n($total)
132 132
 			)
133 133
 		);
134 134
 	}
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @param int $batches_completed
142 142
 	 */
143
-	protected function print_total_batches( $batches_completed ) {
143
+	protected function print_total_batches($batches_completed) {
144 144
 		WP_CLI::log(
145 145
 			sprintf(
146 146
 				/* translators: %d refers to the total number of batches executed */
147
-				_n( '%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler' ),
148
-				number_format_i18n( $batches_completed )
147
+				_n('%d batch executed.', '%d batches executed.', $batches_completed, 'action-scheduler'),
148
+				number_format_i18n($batches_completed)
149 149
 			)
150 150
 		);
151 151
 	}
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @throws \WP_CLI\ExitException
161 161
 	 */
162
-	protected function print_error( Exception $e ) {
162
+	protected function print_error(Exception $e) {
163 163
 		WP_CLI::error(
164 164
 			sprintf(
165 165
 				/* translators: %s refers to the exception error message */
166
-				__( 'There was an error running the action scheduler: %s', 'action-scheduler' ),
166
+				__('There was an error running the action scheduler: %s', 'action-scheduler'),
167 167
 				$e->getMessage()
168 168
 			)
169 169
 		);
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @param int $actions_completed
178 178
 	 */
179
-	protected function print_success( $actions_completed ) {
179
+	protected function print_success($actions_completed) {
180 180
 		WP_CLI::success(
181 181
 			sprintf(
182 182
 				/* translators: %d refers to the total number of taskes completed */
183
-				_n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler' ),
184
-				number_format_i18n( $actions_completed )
183
+				_n('%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'action-scheduler'),
184
+				number_format_i18n($actions_completed)
185 185
 			)
186 186
 		);
187 187
 	}
Please login to merge, or discard this patch.
src/libraries/action-scheduler/classes/migration/LogMigrator.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -15,35 +15,35 @@
 block discarded – undo
15 15
  * @codeCoverageIgnore
16 16
  */
17 17
 class LogMigrator {
18
-	/** @var ActionScheduler_Logger */
19
-	private $source;
18
+    /** @var ActionScheduler_Logger */
19
+    private $source;
20 20
 
21
-	/** @var ActionScheduler_Logger */
22
-	private $destination;
21
+    /** @var ActionScheduler_Logger */
22
+    private $destination;
23 23
 
24
-	/**
25
-	 * ActionMigrator constructor.
26
-	 *
27
-	 * @param ActionScheduler_Logger $source_logger Source logger object.
28
-	 * @param ActionScheduler_Logger $destination_Logger Destination logger object.
29
-	 */
30
-	public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) {
31
-		$this->source      = $source_logger;
32
-		$this->destination = $destination_Logger;
33
-	}
24
+    /**
25
+     * ActionMigrator constructor.
26
+     *
27
+     * @param ActionScheduler_Logger $source_logger Source logger object.
28
+     * @param ActionScheduler_Logger $destination_Logger Destination logger object.
29
+     */
30
+    public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) {
31
+        $this->source      = $source_logger;
32
+        $this->destination = $destination_Logger;
33
+    }
34 34
 
35
-	/**
36
-	 * Migrate an action log.
37
-	 *
38
-	 * @param int $source_action_id Source logger object.
39
-	 * @param int $destination_action_id Destination logger object.
40
-	 */
41
-	public function migrate( $source_action_id, $destination_action_id ) {
42
-		$logs = $this->source->get_logs( $source_action_id );
43
-		foreach ( $logs as $log ) {
44
-			if ( $log->get_action_id() == $source_action_id ) {
45
-				$this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() );
46
-			}
47
-		}
48
-	}
35
+    /**
36
+     * Migrate an action log.
37
+     *
38
+     * @param int $source_action_id Source logger object.
39
+     * @param int $destination_action_id Destination logger object.
40
+     */
41
+    public function migrate( $source_action_id, $destination_action_id ) {
42
+        $logs = $this->source->get_logs( $source_action_id );
43
+        foreach ( $logs as $log ) {
44
+            if ( $log->get_action_id() == $source_action_id ) {
45
+                $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() );
46
+            }
47
+        }
48
+    }
49 49
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 * @param ActionScheduler_Logger $source_logger Source logger object.
28 28
 	 * @param ActionScheduler_Logger $destination_Logger Destination logger object.
29 29
 	 */
30
-	public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) {
30
+	public function __construct(ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger) {
31 31
 		$this->source      = $source_logger;
32 32
 		$this->destination = $destination_Logger;
33 33
 	}
@@ -38,11 +38,11 @@  discard block
 block discarded – undo
38 38
 	 * @param int $source_action_id Source logger object.
39 39
 	 * @param int $destination_action_id Destination logger object.
40 40
 	 */
41
-	public function migrate( $source_action_id, $destination_action_id ) {
42
-		$logs = $this->source->get_logs( $source_action_id );
43
-		foreach ( $logs as $log ) {
44
-			if ( $log->get_action_id() == $source_action_id ) {
45
-				$this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() );
41
+	public function migrate($source_action_id, $destination_action_id) {
42
+		$logs = $this->source->get_logs($source_action_id);
43
+		foreach ($logs as $log) {
44
+			if ($log->get_action_id() == $source_action_id) {
45
+				$this->destination->log($destination_action_id, $log->get_message(), $log->get_date());
46 46
 			}
47 47
 		}
48 48
 	}
Please login to merge, or discard this patch.
src/libraries/action-scheduler/classes/migration/Config.php 2 patches
Indentation   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -17,152 +17,152 @@
 block discarded – undo
17 17
  * A config builder for the ActionScheduler\Migration\Runner class
18 18
  */
19 19
 class Config {
20
-	/** @var ActionScheduler_Store */
21
-	private $source_store;
22
-
23
-	/** @var ActionScheduler_Logger */
24
-	private $source_logger;
25
-
26
-	/** @var ActionScheduler_Store */
27
-	private $destination_store;
28
-
29
-	/** @var ActionScheduler_Logger */
30
-	private $destination_logger;
31
-
32
-	/** @var Progress bar */
33
-	private $progress_bar;
34
-
35
-	/** @var bool */
36
-	private $dry_run = false;
37
-
38
-	/**
39
-	 * Config constructor.
40
-	 */
41
-	public function __construct() {
42
-
43
-	}
44
-
45
-	/**
46
-	 * Get the configured source store.
47
-	 *
48
-	 * @return ActionScheduler_Store
49
-	 */
50
-	public function get_source_store() {
51
-		if ( empty( $this->source_store ) ) {
52
-			throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
53
-		}
54
-
55
-		return $this->source_store;
56
-	}
57
-
58
-	/**
59
-	 * Set the configured source store.
60
-	 *
61
-	 * @param ActionScheduler_Store $store Source store object.
62
-	 */
63
-	public function set_source_store( Store $store ) {
64
-		$this->source_store = $store;
65
-	}
66
-
67
-	/**
68
-	 * Get the configured source loger.
69
-	 *
70
-	 * @return ActionScheduler_Logger
71
-	 */
72
-	public function get_source_logger() {
73
-		if ( empty( $this->source_logger ) ) {
74
-			throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
75
-		}
76
-
77
-		return $this->source_logger;
78
-	}
79
-
80
-	/**
81
-	 * Set the configured source logger.
82
-	 *
83
-	 * @param ActionScheduler_Logger $logger
84
-	 */
85
-	public function set_source_logger( Logger $logger ) {
86
-		$this->source_logger = $logger;
87
-	}
88
-
89
-	/**
90
-	 * Get the configured destination store.
91
-	 *
92
-	 * @return ActionScheduler_Store
93
-	 */
94
-	public function get_destination_store() {
95
-		if ( empty( $this->destination_store ) ) {
96
-			throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
97
-		}
98
-
99
-		return $this->destination_store;
100
-	}
101
-
102
-	/**
103
-	 * Set the configured destination store.
104
-	 *
105
-	 * @param ActionScheduler_Store $store
106
-	 */
107
-	public function set_destination_store( Store $store ) {
108
-		$this->destination_store = $store;
109
-	}
110
-
111
-	/**
112
-	 * Get the configured destination logger.
113
-	 *
114
-	 * @return ActionScheduler_Logger
115
-	 */
116
-	public function get_destination_logger() {
117
-		if ( empty( $this->destination_logger ) ) {
118
-			throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
119
-		}
120
-
121
-		return $this->destination_logger;
122
-	}
123
-
124
-	/**
125
-	 * Set the configured destination logger.
126
-	 *
127
-	 * @param ActionScheduler_Logger $logger
128
-	 */
129
-	public function set_destination_logger( Logger $logger ) {
130
-		$this->destination_logger = $logger;
131
-	}
132
-
133
-	/**
134
-	 * Get flag indicating whether it's a dry run.
135
-	 *
136
-	 * @return bool
137
-	 */
138
-	public function get_dry_run() {
139
-		return $this->dry_run;
140
-	}
141
-
142
-	/**
143
-	 * Set flag indicating whether it's a dry run.
144
-	 *
145
-	 * @param bool $dry_run
146
-	 */
147
-	public function set_dry_run( $dry_run ) {
148
-		$this->dry_run = (bool) $dry_run;
149
-	}
150
-
151
-	/**
152
-	 * Get progress bar object.
153
-	 *
154
-	 * @return ActionScheduler\WPCLI\ProgressBar
155
-	 */
156
-	public function get_progress_bar() {
157
-		return $this->progress_bar;
158
-	}
159
-
160
-	/**
161
-	 * Set progress bar object.
162
-	 *
163
-	 * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
164
-	 */
165
-	public function set_progress_bar( ProgressBar $progress_bar ) {
166
-		$this->progress_bar = $progress_bar;
167
-	}
20
+    /** @var ActionScheduler_Store */
21
+    private $source_store;
22
+
23
+    /** @var ActionScheduler_Logger */
24
+    private $source_logger;
25
+
26
+    /** @var ActionScheduler_Store */
27
+    private $destination_store;
28
+
29
+    /** @var ActionScheduler_Logger */
30
+    private $destination_logger;
31
+
32
+    /** @var Progress bar */
33
+    private $progress_bar;
34
+
35
+    /** @var bool */
36
+    private $dry_run = false;
37
+
38
+    /**
39
+     * Config constructor.
40
+     */
41
+    public function __construct() {
42
+
43
+    }
44
+
45
+    /**
46
+     * Get the configured source store.
47
+     *
48
+     * @return ActionScheduler_Store
49
+     */
50
+    public function get_source_store() {
51
+        if ( empty( $this->source_store ) ) {
52
+            throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
53
+        }
54
+
55
+        return $this->source_store;
56
+    }
57
+
58
+    /**
59
+     * Set the configured source store.
60
+     *
61
+     * @param ActionScheduler_Store $store Source store object.
62
+     */
63
+    public function set_source_store( Store $store ) {
64
+        $this->source_store = $store;
65
+    }
66
+
67
+    /**
68
+     * Get the configured source loger.
69
+     *
70
+     * @return ActionScheduler_Logger
71
+     */
72
+    public function get_source_logger() {
73
+        if ( empty( $this->source_logger ) ) {
74
+            throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
75
+        }
76
+
77
+        return $this->source_logger;
78
+    }
79
+
80
+    /**
81
+     * Set the configured source logger.
82
+     *
83
+     * @param ActionScheduler_Logger $logger
84
+     */
85
+    public function set_source_logger( Logger $logger ) {
86
+        $this->source_logger = $logger;
87
+    }
88
+
89
+    /**
90
+     * Get the configured destination store.
91
+     *
92
+     * @return ActionScheduler_Store
93
+     */
94
+    public function get_destination_store() {
95
+        if ( empty( $this->destination_store ) ) {
96
+            throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
97
+        }
98
+
99
+        return $this->destination_store;
100
+    }
101
+
102
+    /**
103
+     * Set the configured destination store.
104
+     *
105
+     * @param ActionScheduler_Store $store
106
+     */
107
+    public function set_destination_store( Store $store ) {
108
+        $this->destination_store = $store;
109
+    }
110
+
111
+    /**
112
+     * Get the configured destination logger.
113
+     *
114
+     * @return ActionScheduler_Logger
115
+     */
116
+    public function get_destination_logger() {
117
+        if ( empty( $this->destination_logger ) ) {
118
+            throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
119
+        }
120
+
121
+        return $this->destination_logger;
122
+    }
123
+
124
+    /**
125
+     * Set the configured destination logger.
126
+     *
127
+     * @param ActionScheduler_Logger $logger
128
+     */
129
+    public function set_destination_logger( Logger $logger ) {
130
+        $this->destination_logger = $logger;
131
+    }
132
+
133
+    /**
134
+     * Get flag indicating whether it's a dry run.
135
+     *
136
+     * @return bool
137
+     */
138
+    public function get_dry_run() {
139
+        return $this->dry_run;
140
+    }
141
+
142
+    /**
143
+     * Set flag indicating whether it's a dry run.
144
+     *
145
+     * @param bool $dry_run
146
+     */
147
+    public function set_dry_run( $dry_run ) {
148
+        $this->dry_run = (bool) $dry_run;
149
+    }
150
+
151
+    /**
152
+     * Get progress bar object.
153
+     *
154
+     * @return ActionScheduler\WPCLI\ProgressBar
155
+     */
156
+    public function get_progress_bar() {
157
+        return $this->progress_bar;
158
+    }
159
+
160
+    /**
161
+     * Set progress bar object.
162
+     *
163
+     * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
164
+     */
165
+    public function set_progress_bar( ProgressBar $progress_bar ) {
166
+        $this->progress_bar = $progress_bar;
167
+    }
168 168
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
 	 * @return ActionScheduler_Store
49 49
 	 */
50 50
 	public function get_source_store() {
51
-		if ( empty( $this->source_store ) ) {
52
-			throw new \RuntimeException( __( 'Source store must be configured before running a migration', 'action-scheduler' ) );
51
+		if (empty($this->source_store)) {
52
+			throw new \RuntimeException(__('Source store must be configured before running a migration', 'action-scheduler'));
53 53
 		}
54 54
 
55 55
 		return $this->source_store;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @param ActionScheduler_Store $store Source store object.
62 62
 	 */
63
-	public function set_source_store( Store $store ) {
63
+	public function set_source_store(Store $store) {
64 64
 		$this->source_store = $store;
65 65
 	}
66 66
 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 	 * @return ActionScheduler_Logger
71 71
 	 */
72 72
 	public function get_source_logger() {
73
-		if ( empty( $this->source_logger ) ) {
74
-			throw new \RuntimeException( __( 'Source logger must be configured before running a migration', 'action-scheduler' ) );
73
+		if (empty($this->source_logger)) {
74
+			throw new \RuntimeException(__('Source logger must be configured before running a migration', 'action-scheduler'));
75 75
 		}
76 76
 
77 77
 		return $this->source_logger;
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @param ActionScheduler_Logger $logger
84 84
 	 */
85
-	public function set_source_logger( Logger $logger ) {
85
+	public function set_source_logger(Logger $logger) {
86 86
 		$this->source_logger = $logger;
87 87
 	}
88 88
 
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
 	 * @return ActionScheduler_Store
93 93
 	 */
94 94
 	public function get_destination_store() {
95
-		if ( empty( $this->destination_store ) ) {
96
-			throw new \RuntimeException( __( 'Destination store must be configured before running a migration', 'action-scheduler' ) );
95
+		if (empty($this->destination_store)) {
96
+			throw new \RuntimeException(__('Destination store must be configured before running a migration', 'action-scheduler'));
97 97
 		}
98 98
 
99 99
 		return $this->destination_store;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @param ActionScheduler_Store $store
106 106
 	 */
107
-	public function set_destination_store( Store $store ) {
107
+	public function set_destination_store(Store $store) {
108 108
 		$this->destination_store = $store;
109 109
 	}
110 110
 
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @return ActionScheduler_Logger
115 115
 	 */
116 116
 	public function get_destination_logger() {
117
-		if ( empty( $this->destination_logger ) ) {
118
-			throw new \RuntimeException( __( 'Destination logger must be configured before running a migration', 'action-scheduler' ) );
117
+		if (empty($this->destination_logger)) {
118
+			throw new \RuntimeException(__('Destination logger must be configured before running a migration', 'action-scheduler'));
119 119
 		}
120 120
 
121 121
 		return $this->destination_logger;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 *
127 127
 	 * @param ActionScheduler_Logger $logger
128 128
 	 */
129
-	public function set_destination_logger( Logger $logger ) {
129
+	public function set_destination_logger(Logger $logger) {
130 130
 		$this->destination_logger = $logger;
131 131
 	}
132 132
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 *
145 145
 	 * @param bool $dry_run
146 146
 	 */
147
-	public function set_dry_run( $dry_run ) {
147
+	public function set_dry_run($dry_run) {
148 148
 		$this->dry_run = (bool) $dry_run;
149 149
 	}
150 150
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 *
163 163
 	 * @param ActionScheduler\WPCLI\ProgressBar $progress_bar
164 164
 	 */
165
-	public function set_progress_bar( ProgressBar $progress_bar ) {
165
+	public function set_progress_bar(ProgressBar $progress_bar) {
166 166
 		$this->progress_bar = $progress_bar;
167 167
 	}
168 168
 }
Please login to merge, or discard this patch.
src/libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,16 +13,16 @@
 block discarded – undo
13 13
  * @codeCoverageIgnore
14 14
  */
15 15
 class DryRun_ActionMigrator extends ActionMigrator {
16
-	/**
17
-	 * Simulate migrating an action.
18
-	 *
19
-	 * @param int $source_action_id Action ID.
20
-	 *
21
-	 * @return int
22
-	 */
23
-	public function migrate( $source_action_id ) {
24
-		do_action( 'action_scheduler/migrate_action_dry_run', $source_action_id );
16
+    /**
17
+     * Simulate migrating an action.
18
+     *
19
+     * @param int $source_action_id Action ID.
20
+     *
21
+     * @return int
22
+     */
23
+    public function migrate( $source_action_id ) {
24
+        do_action( 'action_scheduler/migrate_action_dry_run', $source_action_id );
25 25
 
26
-		return 0;
27
-	}
26
+        return 0;
27
+    }
28 28
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 block discarded – undo
20 20
 	 *
21 21
 	 * @return int
22 22
 	 */
23
-	public function migrate( $source_action_id ) {
24
-		do_action( 'action_scheduler/migrate_action_dry_run', $source_action_id );
23
+	public function migrate($source_action_id) {
24
+		do_action('action_scheduler/migrate_action_dry_run', $source_action_id);
25 25
 
26 26
 		return 0;
27 27
 	}
Please login to merge, or discard this patch.
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.