Passed
Pull Request — master (#284)
by Brian
06:11
created
libraries/action-scheduler/classes/migration/DryRun_ActionMigrator.php 1 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.
libraries/action-scheduler/classes/migration/DryRun_LogMigrator.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 	 * @param int $source_action_id Source logger object.
18 18
 	 * @param int $destination_action_id Destination logger object.
19 19
 	 */
20
-	public function migrate( $source_action_id, $destination_action_id ) {
20
+	public function migrate($source_action_id, $destination_action_id) {
21 21
 		// no-op
22 22
 	}
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
action-scheduler/classes/migration/ActionScheduler_DBStoreMigrator.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -23,25 +23,25 @@
 block discarded – undo
23 23
 	 * @return string The action ID
24 24
 	 * @throws \RuntimeException When the action is not saved.
25 25
 	 */
26
-	public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){
26
+	public function save_action(ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null) {
27 27
 		try {
28 28
 			/** @var \wpdb $wpdb */
29 29
 			global $wpdb;
30 30
 
31
-			$action_id = parent::save_action( $action, $scheduled_date );
31
+			$action_id = parent::save_action($action, $scheduled_date);
32 32
 
33
-			if ( null !== $last_attempt_date ) {
33
+			if (null !== $last_attempt_date) {
34 34
 				$data = [
35
-					'last_attempt_gmt'   => $this->get_scheduled_date_string( $action, $last_attempt_date ),
36
-					'last_attempt_local' => $this->get_scheduled_date_string_local( $action, $last_attempt_date ),
35
+					'last_attempt_gmt'   => $this->get_scheduled_date_string($action, $last_attempt_date),
36
+					'last_attempt_local' => $this->get_scheduled_date_string_local($action, $last_attempt_date),
37 37
 				];
38 38
 
39
-				$wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
39
+				$wpdb->update($wpdb->actionscheduler_actions, $data, array('action_id' => $action_id), array('%s', '%s'), array('%d'));
40 40
 			}
41 41
 
42 42
 			return $action_id;
43
-		} catch ( \Exception $e ) {
44
-			throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
43
+		} catch (\Exception $e) {
44
+			throw new \RuntimeException(sprintf(__('Error saving action: %s', 'action-scheduler'), $e->getMessage()), 0);
45 45
 		}
46 46
 	}
47 47
 }
Please login to merge, or discard this patch.
includes/libraries/action-scheduler/classes/migration/Controller.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param Scheduler $migration_scheduler Migration scheduler object.
38 38
 	 */
39
-	protected function __construct( Scheduler $migration_scheduler ) {
39
+	protected function __construct(Scheduler $migration_scheduler) {
40 40
 		$this->migration_scheduler = $migration_scheduler;
41 41
 		$this->store_classname     = '';
42 42
 	}
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
 	 *
49 49
 	 * @return string
50 50
 	 */
51
-	public function get_store_class( $class ) {
52
-		if ( \ActionScheduler_DataController::is_migration_complete() ) {
51
+	public function get_store_class($class) {
52
+		if (\ActionScheduler_DataController::is_migration_complete()) {
53 53
 			return \ActionScheduler_DataController::DATASTORE_CLASS;
54
-		} elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
54
+		} elseif (\ActionScheduler_Store::DEFAULT_CLASS !== $class) {
55 55
 			$this->store_classname = $class;
56 56
 			return $class;
57 57
 		} else {
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 *
67 67
 	 * @return string
68 68
 	 */
69
-	public function get_logger_class( $class ) {
69
+	public function get_logger_class($class) {
70 70
 		\ActionScheduler_Store::instance();
71 71
 
72
-		if ( $this->has_custom_datastore() ) {
72
+		if ($this->has_custom_datastore()) {
73 73
 			$this->logger_classname = $class;
74 74
 			return $class;
75 75
 		} else {
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @return void
93 93
 	 */
94 94
 	public function schedule_migration() {
95
-		if ( \ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled() ) {
95
+		if (\ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled()) {
96 96
 			return;
97 97
 		}
98 98
 
@@ -107,53 +107,53 @@  discard block
 block discarded – undo
107 107
 	public function get_migration_config_object() {
108 108
 		static $config = null;
109 109
 
110
-		if ( ! $config ) {
110
+		if (!$config) {
111 111
 			$source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
112 112
 			$source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
113 113
 
114 114
 			$config = new Config();
115
-			$config->set_source_store( $source_store );
116
-			$config->set_source_logger( $source_logger );
117
-			$config->set_destination_store( new \ActionScheduler_DBStoreMigrator() );
118
-			$config->set_destination_logger( new \ActionScheduler_DBLogger() );
115
+			$config->set_source_store($source_store);
116
+			$config->set_source_logger($source_logger);
117
+			$config->set_destination_store(new \ActionScheduler_DBStoreMigrator());
118
+			$config->set_destination_logger(new \ActionScheduler_DBLogger());
119 119
 
120
-			if ( defined( 'WP_CLI' ) && WP_CLI ) {
121
-				$config->set_progress_bar( new ProgressBar( '', 0 ) );
120
+			if (defined('WP_CLI') && WP_CLI) {
121
+				$config->set_progress_bar(new ProgressBar('', 0));
122 122
 			}
123 123
 		}
124 124
 
125
-		return apply_filters( 'action_scheduler/migration_config', $config );
125
+		return apply_filters('action_scheduler/migration_config', $config);
126 126
 	}
127 127
 
128 128
 	/**
129 129
 	 * Hook dashboard migration notice.
130 130
 	 */
131 131
 	public function hook_admin_notices() {
132
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
132
+		if (!$this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) {
133 133
 			return;
134 134
 		}
135
-		add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
135
+		add_action('admin_notices', array($this, 'display_migration_notice'), 10, 0);
136 136
 	}
137 137
 
138 138
 	/**
139 139
 	 * Show a dashboard notice that migration is in progress.
140 140
 	 */
141 141
 	public function display_migration_notice() {
142
-		printf( '<div class="notice notice-warning"><p>%s</p></div>', __( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) );
142
+		printf('<div class="notice notice-warning"><p>%s</p></div>', __('Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler'));
143 143
 	}
144 144
 
145 145
 	/**
146 146
 	 * Add store classes. Hook migration.
147 147
 	 */
148 148
 	private function hook() {
149
-		add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 );
150
-		add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 );
151
-		add_action( 'init', array( $this, 'maybe_hook_migration' ) );
152
-		add_action( 'shutdown', array( $this, 'schedule_migration' ), 0, 0 );
149
+		add_filter('action_scheduler_store_class', array($this, 'get_store_class'), 100, 1);
150
+		add_filter('action_scheduler_logger_class', array($this, 'get_logger_class'), 100, 1);
151
+		add_action('init', array($this, 'maybe_hook_migration'));
152
+		add_action('shutdown', array($this, 'schedule_migration'), 0, 0);
153 153
 
154 154
 		// Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen
155
-		add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 );
156
-		add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 );
155
+		add_action('load-tools_page_action-scheduler', array($this, 'hook_admin_notices'), 10, 0);
156
+		add_action('load-woocommerce_page_wc-status', array($this, 'hook_admin_notices'), 10, 0);
157 157
 	}
158 158
 
159 159
 	/**
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 	 * @author Jeremy Pry
163 163
 	 */
164 164
 	public function maybe_hook_migration() {
165
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
165
+		if (!$this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) {
166 166
 			return;
167 167
 		}
168 168
 
@@ -173,22 +173,22 @@  discard block
 block discarded – undo
173 173
 	 * Allow datastores to enable migration to AS tables.
174 174
 	 */
175 175
 	public function allow_migration() {
176
-		if ( ! \ActionScheduler_DataController::dependencies_met() ) {
176
+		if (!\ActionScheduler_DataController::dependencies_met()) {
177 177
 			return false;
178 178
 		}
179 179
 
180
-		if ( null === $this->migrate_custom_store ) {
181
-			$this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
180
+		if (null === $this->migrate_custom_store) {
181
+			$this->migrate_custom_store = apply_filters('action_scheduler_migrate_data_store', false);
182 182
 		}
183 183
 
184
-		return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
184
+		return (!$this->has_custom_datastore()) || $this->migrate_custom_store;
185 185
 	}
186 186
 
187 187
 	/**
188 188
 	 * Proceed with the migration if the dependencies have been met.
189 189
 	 */
190 190
 	public static function init() {
191
-		if ( \ActionScheduler_DataController::dependencies_met() ) {
191
+		if (\ActionScheduler_DataController::dependencies_met()) {
192 192
 			self::instance()->hook();
193 193
 		}
194 194
 	}
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 	 * Singleton factory.
198 198
 	 */
199 199
 	public static function instance() {
200
-		if ( ! isset( self::$instance ) ) {
201
-			self::$instance = new static( new Scheduler() );
200
+		if (!isset(self::$instance)) {
201
+			self::$instance = new static(new Scheduler());
202 202
 		}
203 203
 
204 204
 		return self::$instance;
Please login to merge, or discard this patch.
includes/libraries/action-scheduler/classes/migration/ActionMigrator.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 	 * @param ActionScheduler_Store $destination_store Destination store object.
30 30
 	 * @param LogMigrator           $log_migrator Log migrator object.
31 31
 	 */
32
-	public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
32
+	public function __construct(\ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator) {
33 33
 		$this->source       = $source_store;
34 34
 		$this->destination  = $destination_store;
35 35
 		$this->log_migrator = $log_migrator;
@@ -42,25 +42,25 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return int 0|new action ID
44 44
 	 */
45
-	public function migrate( $source_action_id ) {
45
+	public function migrate($source_action_id) {
46 46
 		try {
47
-			$action = $this->source->fetch_action( $source_action_id );
48
-			$status = $this->source->get_status( $source_action_id );
49
-		} catch ( \Exception $e ) {
47
+			$action = $this->source->fetch_action($source_action_id);
48
+			$status = $this->source->get_status($source_action_id);
49
+		} catch (\Exception $e) {
50 50
 			$action = null;
51 51
 			$status = '';
52 52
 		}
53 53
 
54
-		if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
54
+		if (is_null($action) || empty($status) || !$action->get_schedule()->get_date()) {
55 55
 			// null action or empty status means the fetch operation failed or the action didn't exist
56 56
 			// null schedule means it's missing vital data
57 57
 			// delete it and move on
58 58
 			try {
59
-				$this->source->delete_action( $source_action_id );
60
-			} catch ( \Exception $e ) {
59
+				$this->source->delete_action($source_action_id);
60
+			} catch (\Exception $e) {
61 61
 				// nothing to do, it didn't exist in the first place
62 62
 			}
63
-			do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
63
+			do_action('action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination);
64 64
 
65 65
 			return 0;
66 66
 		}
@@ -68,40 +68,40 @@  discard block
 block discarded – undo
68 68
 		try {
69 69
 
70 70
 			// Make sure the last attempt date is set correctly for completed and failed actions
71
-			$last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null;
71
+			$last_attempt_date = ($status !== \ActionScheduler_Store::STATUS_PENDING) ? $this->source->get_date($source_action_id) : null;
72 72
 
73
-			$destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date );
74
-		} catch ( \Exception $e ) {
75
-			do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination );
73
+			$destination_action_id = $this->destination->save_action($action, null, $last_attempt_date);
74
+		} catch (\Exception $e) {
75
+			do_action('action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination);
76 76
 
77 77
 			return 0; // could not save the action in the new store
78 78
 		}
79 79
 
80 80
 		try {
81
-			switch ( $status ) {
81
+			switch ($status) {
82 82
 				case \ActionScheduler_Store::STATUS_FAILED :
83
-					$this->destination->mark_failure( $destination_action_id );
83
+					$this->destination->mark_failure($destination_action_id);
84 84
 					break;
85 85
 				case \ActionScheduler_Store::STATUS_CANCELED :
86
-					$this->destination->cancel_action( $destination_action_id );
86
+					$this->destination->cancel_action($destination_action_id);
87 87
 					break;
88 88
 			}
89 89
 
90
-			$this->log_migrator->migrate( $source_action_id, $destination_action_id );
91
-			$this->source->delete_action( $source_action_id );
90
+			$this->log_migrator->migrate($source_action_id, $destination_action_id);
91
+			$this->source->delete_action($source_action_id);
92 92
 
93
-			$test_action = $this->source->fetch_action( $source_action_id );
94
-			if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
95
-				throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) );
93
+			$test_action = $this->source->fetch_action($source_action_id);
94
+			if (!is_a($test_action, 'ActionScheduler_NullAction')) {
95
+				throw new \RuntimeException(sprintf(__('Unable to remove source migrated action %s', 'action-scheduler'), $source_action_id));
96 96
 			}
97
-			do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
97
+			do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination);
98 98
 
99 99
 			return $destination_action_id;
100
-		} catch ( \Exception $e ) {
100
+		} catch (\Exception $e) {
101 101
 			// could not delete from the old store
102
-			$this->source->mark_migrated( $source_action_id );
103
-			do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination );
104
-			do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
102
+			$this->source->mark_migrated($source_action_id);
103
+			do_action('action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination);
104
+			do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination);
105 105
 
106 106
 			return $destination_action_id;
107 107
 		}
Please login to merge, or discard this patch.
action-scheduler/classes/schedules/ActionScheduler_IntervalSchedule.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 	 * @param DateTime $after
23 23
 	 * @return DateTime
24 24
 	 */
25
-	protected function calculate_next( DateTime $after ) {
26
-		$after->modify( '+' . (int) $this->get_recurrence() . ' seconds' );
25
+	protected function calculate_next(DateTime $after) {
26
+		$after->modify('+' . (int) $this->get_recurrence() . ' seconds');
27 27
 		return $after;
28 28
 	}
29 29
 
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @return int
32 32
 	 */
33 33
 	public function interval_in_seconds() {
34
-		_deprecated_function( __METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()' );
34
+		_deprecated_function(__METHOD__, '3.0.0', '(int)ActionScheduler_Abstract_RecurringSchedule::get_recurrence()');
35 35
 		return (int) $this->get_recurrence();
36 36
 	}
37 37
 
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
 		$this->start_timestamp     = $this->scheduled_timestamp;
56 56
 		$this->interval_in_seconds = $this->recurrence;
57 57
 
58
-		return array_merge( $sleep_params, array(
58
+		return array_merge($sleep_params, array(
59 59
 			'start_timestamp',
60 60
 			'interval_in_seconds'
61
-		) );
61
+		));
62 62
 	}
63 63
 
64 64
 	/**
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
 	 * For more background, @see ActionScheduler_Abstract_RecurringSchedule::__wakeup().
68 68
 	 */
69 69
 	public function __wakeup() {
70
-		if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->start_timestamp ) ) {
70
+		if (is_null($this->scheduled_timestamp) && !is_null($this->start_timestamp)) {
71 71
 			$this->scheduled_timestamp = $this->start_timestamp;
72
-			unset( $this->start_timestamp );
72
+			unset($this->start_timestamp);
73 73
 		}
74 74
 
75
-		if ( is_null( $this->recurrence ) && ! is_null( $this->interval_in_seconds ) ) {
75
+		if (is_null($this->recurrence) && !is_null($this->interval_in_seconds)) {
76 76
 			$this->recurrence = $this->interval_in_seconds;
77
-			unset( $this->interval_in_seconds );
77
+			unset($this->interval_in_seconds);
78 78
 		}
79 79
 		parent::__wakeup();
80 80
 	}
Please login to merge, or discard this patch.
action-scheduler/classes/schedules/ActionScheduler_SimpleSchedule.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
 	 * @return DateTime|null
17 17
 	 */
18
-	public function calculate_next( DateTime $after ) {
18
+	public function calculate_next(DateTime $after) {
19 19
 		return null;
20 20
 	}
21 21
 
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
 		$this->timestamp = $this->scheduled_timestamp;
47 47
 
48
-		return array_merge( $sleep_params, array(
48
+		return array_merge($sleep_params, array(
49 49
 			'timestamp',
50
-		) );
50
+		));
51 51
 	}
52 52
 
53 53
 	/**
@@ -62,9 +62,9 @@  discard block
 block discarded – undo
62 62
 	 */
63 63
 	public function __wakeup() {
64 64
 
65
-		if ( is_null( $this->scheduled_timestamp ) && ! is_null( $this->timestamp ) ) {
65
+		if (is_null($this->scheduled_timestamp) && !is_null($this->timestamp)) {
66 66
 			$this->scheduled_timestamp = $this->timestamp;
67
-			unset( $this->timestamp );
67
+			unset($this->timestamp);
68 68
 		}
69 69
 		parent::__wakeup();
70 70
 	}
Please login to merge, or discard this patch.
libraries/action-scheduler/classes/schedules/ActionScheduler_Schedule.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
 	 * @param DateTime $after
9 9
 	 * @return DateTime|null
10 10
 	 */
11
-	public function next( DateTime $after = NULL );
11
+	public function next(DateTime $after = NULL);
12 12
 
13 13
 	/**
14 14
 	 * @return bool
Please login to merge, or discard this patch.
action-scheduler/classes/schedules/ActionScheduler_NullSchedule.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
 	 *
11 11
 	 * @param null $date The date & time to run the action.
12 12
 	 */
13
-	public function __construct( DateTime $date = null ) {
13
+	public function __construct(DateTime $date = null) {
14 14
 		$this->scheduled_date = null;
15 15
 	}
16 16
 
Please login to merge, or discard this patch.