Passed
Pull Request — master (#287)
by Kiran
12:52
created
includes/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.
includes/libraries/action-scheduler/classes/migration/Runner.php 2 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -13,124 +13,124 @@
 block discarded – undo
13 13
  * @codeCoverageIgnore
14 14
  */
15 15
 class Runner {
16
-	/** @var ActionScheduler_Store */
17
-	private $source_store;
18
-
19
-	/** @var ActionScheduler_Store */
20
-	private $destination_store;
21
-
22
-	/** @var ActionScheduler_Logger */
23
-	private $source_logger;
24
-
25
-	/** @var ActionScheduler_Logger */
26
-	private $destination_logger;
27
-
28
-	/** @var BatchFetcher */
29
-	private $batch_fetcher;
30
-
31
-	/** @var ActionMigrator */
32
-	private $action_migrator;
33
-
34
-	/** @var LogMigrator */
35
-	private $log_migrator;
36
-
37
-	/** @var ProgressBar */
38
-	private $progress_bar;
39
-
40
-	/**
41
-	 * Runner constructor.
42
-	 *
43
-	 * @param Config $config Migration configuration object.
44
-	 */
45
-	public function __construct( Config $config ) {
46
-		$this->source_store       = $config->get_source_store();
47
-		$this->destination_store  = $config->get_destination_store();
48
-		$this->source_logger      = $config->get_source_logger();
49
-		$this->destination_logger = $config->get_destination_logger();
50
-
51
-		$this->batch_fetcher = new BatchFetcher( $this->source_store );
52
-		if ( $config->get_dry_run() ) {
53
-			$this->log_migrator    = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger );
54
-			$this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
55
-		} else {
56
-			$this->log_migrator    = new LogMigrator( $this->source_logger, $this->destination_logger );
57
-			$this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
58
-		}
59
-
60
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
61
-			$this->progress_bar = $config->get_progress_bar();
62
-		}
63
-	}
64
-
65
-	/**
66
-	 * Run migration batch.
67
-	 *
68
-	 * @param int $batch_size Optional batch size. Default 10.
69
-	 *
70
-	 * @return int Size of batch processed.
71
-	 */
72
-	public function run( $batch_size = 10 ) {
73
-		$batch = $this->batch_fetcher->fetch( $batch_size );
74
-		$batch_size = count( $batch );
75
-
76
-		if ( ! $batch_size ) {
77
-			return 0;
78
-		}
79
-
80
-		if ( $this->progress_bar ) {
81
-			/* translators: %d: amount of actions */
82
-			$this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), number_format_i18n( $batch_size ) ) );
83
-			$this->progress_bar->set_count( $batch_size );
84
-		}
85
-
86
-		$this->migrate_actions( $batch );
87
-
88
-		return $batch_size;
89
-	}
90
-
91
-	/**
92
-	 * Migration a batch of actions.
93
-	 *
94
-	 * @param array $action_ids List of action IDs to migrate.
95
-	 */
96
-	public function migrate_actions( array $action_ids ) {
97
-		do_action( 'action_scheduler/migration_batch_starting', $action_ids );
98
-
99
-		\ActionScheduler::logger()->unhook_stored_action();
100
-		$this->destination_logger->unhook_stored_action();
101
-
102
-		foreach ( $action_ids as $source_action_id ) {
103
-			$destination_action_id = $this->action_migrator->migrate( $source_action_id );
104
-			if ( $destination_action_id ) {
105
-				$this->destination_logger->log( $destination_action_id, sprintf(
106
-					/* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
107
-					__( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ),
108
-					$source_action_id,
109
-					get_class( $this->source_store ),
110
-					$destination_action_id,
111
-					get_class( $this->destination_store )
112
-				) );
113
-			}
114
-
115
-			if ( $this->progress_bar ) {
116
-				$this->progress_bar->tick();
117
-			}
118
-		}
119
-
120
-		if ( $this->progress_bar ) {
121
-			$this->progress_bar->finish();
122
-		}
123
-
124
-		\ActionScheduler::logger()->hook_stored_action();
125
-
126
-		do_action( 'action_scheduler/migration_batch_complete', $action_ids );
127
-	}
128
-
129
-	/**
130
-	 * Initialize destination store and logger.
131
-	 */
132
-	public function init_destination() {
133
-		$this->destination_store->init();
134
-		$this->destination_logger->init();
135
-	}
16
+    /** @var ActionScheduler_Store */
17
+    private $source_store;
18
+
19
+    /** @var ActionScheduler_Store */
20
+    private $destination_store;
21
+
22
+    /** @var ActionScheduler_Logger */
23
+    private $source_logger;
24
+
25
+    /** @var ActionScheduler_Logger */
26
+    private $destination_logger;
27
+
28
+    /** @var BatchFetcher */
29
+    private $batch_fetcher;
30
+
31
+    /** @var ActionMigrator */
32
+    private $action_migrator;
33
+
34
+    /** @var LogMigrator */
35
+    private $log_migrator;
36
+
37
+    /** @var ProgressBar */
38
+    private $progress_bar;
39
+
40
+    /**
41
+     * Runner constructor.
42
+     *
43
+     * @param Config $config Migration configuration object.
44
+     */
45
+    public function __construct( Config $config ) {
46
+        $this->source_store       = $config->get_source_store();
47
+        $this->destination_store  = $config->get_destination_store();
48
+        $this->source_logger      = $config->get_source_logger();
49
+        $this->destination_logger = $config->get_destination_logger();
50
+
51
+        $this->batch_fetcher = new BatchFetcher( $this->source_store );
52
+        if ( $config->get_dry_run() ) {
53
+            $this->log_migrator    = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger );
54
+            $this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
55
+        } else {
56
+            $this->log_migrator    = new LogMigrator( $this->source_logger, $this->destination_logger );
57
+            $this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
58
+        }
59
+
60
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
61
+            $this->progress_bar = $config->get_progress_bar();
62
+        }
63
+    }
64
+
65
+    /**
66
+     * Run migration batch.
67
+     *
68
+     * @param int $batch_size Optional batch size. Default 10.
69
+     *
70
+     * @return int Size of batch processed.
71
+     */
72
+    public function run( $batch_size = 10 ) {
73
+        $batch = $this->batch_fetcher->fetch( $batch_size );
74
+        $batch_size = count( $batch );
75
+
76
+        if ( ! $batch_size ) {
77
+            return 0;
78
+        }
79
+
80
+        if ( $this->progress_bar ) {
81
+            /* translators: %d: amount of actions */
82
+            $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), number_format_i18n( $batch_size ) ) );
83
+            $this->progress_bar->set_count( $batch_size );
84
+        }
85
+
86
+        $this->migrate_actions( $batch );
87
+
88
+        return $batch_size;
89
+    }
90
+
91
+    /**
92
+     * Migration a batch of actions.
93
+     *
94
+     * @param array $action_ids List of action IDs to migrate.
95
+     */
96
+    public function migrate_actions( array $action_ids ) {
97
+        do_action( 'action_scheduler/migration_batch_starting', $action_ids );
98
+
99
+        \ActionScheduler::logger()->unhook_stored_action();
100
+        $this->destination_logger->unhook_stored_action();
101
+
102
+        foreach ( $action_ids as $source_action_id ) {
103
+            $destination_action_id = $this->action_migrator->migrate( $source_action_id );
104
+            if ( $destination_action_id ) {
105
+                $this->destination_logger->log( $destination_action_id, sprintf(
106
+                    /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
107
+                    __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ),
108
+                    $source_action_id,
109
+                    get_class( $this->source_store ),
110
+                    $destination_action_id,
111
+                    get_class( $this->destination_store )
112
+                ) );
113
+            }
114
+
115
+            if ( $this->progress_bar ) {
116
+                $this->progress_bar->tick();
117
+            }
118
+        }
119
+
120
+        if ( $this->progress_bar ) {
121
+            $this->progress_bar->finish();
122
+        }
123
+
124
+        \ActionScheduler::logger()->hook_stored_action();
125
+
126
+        do_action( 'action_scheduler/migration_batch_complete', $action_ids );
127
+    }
128
+
129
+    /**
130
+     * Initialize destination store and logger.
131
+     */
132
+    public function init_destination() {
133
+        $this->destination_store->init();
134
+        $this->destination_logger->init();
135
+    }
136 136
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -42,22 +42,22 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @param Config $config Migration configuration object.
44 44
 	 */
45
-	public function __construct( Config $config ) {
45
+	public function __construct(Config $config) {
46 46
 		$this->source_store       = $config->get_source_store();
47 47
 		$this->destination_store  = $config->get_destination_store();
48 48
 		$this->source_logger      = $config->get_source_logger();
49 49
 		$this->destination_logger = $config->get_destination_logger();
50 50
 
51
-		$this->batch_fetcher = new BatchFetcher( $this->source_store );
52
-		if ( $config->get_dry_run() ) {
53
-			$this->log_migrator    = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger );
54
-			$this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
51
+		$this->batch_fetcher = new BatchFetcher($this->source_store);
52
+		if ($config->get_dry_run()) {
53
+			$this->log_migrator    = new DryRun_LogMigrator($this->source_logger, $this->destination_logger);
54
+			$this->action_migrator = new DryRun_ActionMigrator($this->source_store, $this->destination_store, $this->log_migrator);
55 55
 		} else {
56
-			$this->log_migrator    = new LogMigrator( $this->source_logger, $this->destination_logger );
57
-			$this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
56
+			$this->log_migrator    = new LogMigrator($this->source_logger, $this->destination_logger);
57
+			$this->action_migrator = new ActionMigrator($this->source_store, $this->destination_store, $this->log_migrator);
58 58
 		}
59 59
 
60
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
60
+		if (defined('WP_CLI') && WP_CLI) {
61 61
 			$this->progress_bar = $config->get_progress_bar();
62 62
 		}
63 63
 	}
@@ -69,21 +69,21 @@  discard block
 block discarded – undo
69 69
 	 *
70 70
 	 * @return int Size of batch processed.
71 71
 	 */
72
-	public function run( $batch_size = 10 ) {
73
-		$batch = $this->batch_fetcher->fetch( $batch_size );
74
-		$batch_size = count( $batch );
72
+	public function run($batch_size = 10) {
73
+		$batch = $this->batch_fetcher->fetch($batch_size);
74
+		$batch_size = count($batch);
75 75
 
76
-		if ( ! $batch_size ) {
76
+		if (!$batch_size) {
77 77
 			return 0;
78 78
 		}
79 79
 
80
-		if ( $this->progress_bar ) {
80
+		if ($this->progress_bar) {
81 81
 			/* translators: %d: amount of actions */
82
-			$this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), number_format_i18n( $batch_size ) ) );
83
-			$this->progress_bar->set_count( $batch_size );
82
+			$this->progress_bar->set_message(sprintf(_n('Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler'), number_format_i18n($batch_size)));
83
+			$this->progress_bar->set_count($batch_size);
84 84
 		}
85 85
 
86
-		$this->migrate_actions( $batch );
86
+		$this->migrate_actions($batch);
87 87
 
88 88
 		return $batch_size;
89 89
 	}
@@ -93,37 +93,37 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @param array $action_ids List of action IDs to migrate.
95 95
 	 */
96
-	public function migrate_actions( array $action_ids ) {
97
-		do_action( 'action_scheduler/migration_batch_starting', $action_ids );
96
+	public function migrate_actions(array $action_ids) {
97
+		do_action('action_scheduler/migration_batch_starting', $action_ids);
98 98
 
99 99
 		\ActionScheduler::logger()->unhook_stored_action();
100 100
 		$this->destination_logger->unhook_stored_action();
101 101
 
102
-		foreach ( $action_ids as $source_action_id ) {
103
-			$destination_action_id = $this->action_migrator->migrate( $source_action_id );
104
-			if ( $destination_action_id ) {
105
-				$this->destination_logger->log( $destination_action_id, sprintf(
102
+		foreach ($action_ids as $source_action_id) {
103
+			$destination_action_id = $this->action_migrator->migrate($source_action_id);
104
+			if ($destination_action_id) {
105
+				$this->destination_logger->log($destination_action_id, sprintf(
106 106
 					/* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
107
-					__( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ),
107
+					__('Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler'),
108 108
 					$source_action_id,
109
-					get_class( $this->source_store ),
109
+					get_class($this->source_store),
110 110
 					$destination_action_id,
111
-					get_class( $this->destination_store )
112
-				) );
111
+					get_class($this->destination_store)
112
+				));
113 113
 			}
114 114
 
115
-			if ( $this->progress_bar ) {
115
+			if ($this->progress_bar) {
116 116
 				$this->progress_bar->tick();
117 117
 			}
118 118
 		}
119 119
 
120
-		if ( $this->progress_bar ) {
120
+		if ($this->progress_bar) {
121 121
 			$this->progress_bar->finish();
122 122
 		}
123 123
 
124 124
 		\ActionScheduler::logger()->hook_stored_action();
125 125
 
126
-		do_action( 'action_scheduler/migration_batch_complete', $action_ids );
126
+		do_action('action_scheduler/migration_batch_complete', $action_ids);
127 127
 	}
128 128
 
129 129
 	/**
Please login to merge, or discard this patch.
includes/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.
includes/libraries/action-scheduler/classes/migration/Scheduler.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -13,116 +13,116 @@
 block discarded – undo
13 13
  * @codeCoverageIgnore
14 14
  */
15 15
 class Scheduler {
16
-	/** Migration action hook. */
17
-	const HOOK            = 'action_scheduler/migration_hook';
18
-
19
-	/** Migration action group. */
20
-	const GROUP           = 'action-scheduler-migration';
21
-
22
-	/**
23
-	 * Set up the callback for the scheduled job.
24
-	 */
25
-	public function hook() {
26
-		add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
27
-	}
28
-
29
-	/**
30
-	 * Remove the callback for the scheduled job.
31
-	 */
32
-	public function unhook() {
33
-		remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
34
-	}
35
-
36
-	/**
37
-	 * The migration callback.
38
-	 */
39
-	public function run_migration() {
40
-		$migration_runner = $this->get_migration_runner();
41
-		$count            = $migration_runner->run( $this->get_batch_size() );
42
-
43
-		if ( $count === 0 ) {
44
-			$this->mark_complete();
45
-		} else {
46
-			$this->schedule_migration( time() + $this->get_schedule_interval() );
47
-		}
48
-	}
49
-
50
-	/**
51
-	 * Mark the migration complete.
52
-	 */
53
-	public function mark_complete() {
54
-		$this->unschedule_migration();
55
-
56
-		\ActionScheduler_DataController::mark_migration_complete();
57
-		do_action( 'action_scheduler/migration_complete' );
58
-	}
59
-
60
-	/**
61
-	 * Get a flag indicating whether the migration is scheduled.
62
-	 *
63
-	 * @return bool Whether there is a pending action in the store to handle the migration
64
-	 */
65
-	public function is_migration_scheduled() {
66
-		$next = as_next_scheduled_action( self::HOOK );
67
-
68
-		return ! empty( $next );
69
-	}
70
-
71
-	/**
72
-	 * Schedule the migration.
73
-	 *
74
-	 * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
75
-	 *
76
-	 * @return string The action ID
77
-	 */
78
-	public function schedule_migration( $when = 0 ) {
79
-		$next = as_next_scheduled_action( self::HOOK );
80
-
81
-		if ( ! empty( $next ) ) {
82
-			return $next;
83
-		}
84
-
85
-		if ( empty( $when ) ) {
86
-			$when = time();
87
-		}
88
-
89
-		return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
90
-	}
91
-
92
-	/**
93
-	 * Remove the scheduled migration action.
94
-	 */
95
-	public function unschedule_migration() {
96
-		as_unschedule_action( self::HOOK, null, self::GROUP );
97
-	}
98
-
99
-	/**
100
-	 * Get migration batch schedule interval.
101
-	 *
102
-	 * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
103
-	 */
104
-	private function get_schedule_interval() {
105
-		return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
106
-	}
107
-
108
-	/**
109
-	 * Get migration batch size.
110
-	 *
111
-	 * @return int Number of actions to migrate in each batch. Defaults to 250.
112
-	 */
113
-	private function get_batch_size() {
114
-		return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
115
-	}
116
-
117
-	/**
118
-	 * Get migration runner object.
119
-	 *
120
-	 * @return Runner
121
-	 */
122
-	private function get_migration_runner() {
123
-		$config = Controller::instance()->get_migration_config_object();
124
-
125
-		return new Runner( $config );
126
-	}
16
+    /** Migration action hook. */
17
+    const HOOK            = 'action_scheduler/migration_hook';
18
+
19
+    /** Migration action group. */
20
+    const GROUP           = 'action-scheduler-migration';
21
+
22
+    /**
23
+     * Set up the callback for the scheduled job.
24
+     */
25
+    public function hook() {
26
+        add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
27
+    }
28
+
29
+    /**
30
+     * Remove the callback for the scheduled job.
31
+     */
32
+    public function unhook() {
33
+        remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
34
+    }
35
+
36
+    /**
37
+     * The migration callback.
38
+     */
39
+    public function run_migration() {
40
+        $migration_runner = $this->get_migration_runner();
41
+        $count            = $migration_runner->run( $this->get_batch_size() );
42
+
43
+        if ( $count === 0 ) {
44
+            $this->mark_complete();
45
+        } else {
46
+            $this->schedule_migration( time() + $this->get_schedule_interval() );
47
+        }
48
+    }
49
+
50
+    /**
51
+     * Mark the migration complete.
52
+     */
53
+    public function mark_complete() {
54
+        $this->unschedule_migration();
55
+
56
+        \ActionScheduler_DataController::mark_migration_complete();
57
+        do_action( 'action_scheduler/migration_complete' );
58
+    }
59
+
60
+    /**
61
+     * Get a flag indicating whether the migration is scheduled.
62
+     *
63
+     * @return bool Whether there is a pending action in the store to handle the migration
64
+     */
65
+    public function is_migration_scheduled() {
66
+        $next = as_next_scheduled_action( self::HOOK );
67
+
68
+        return ! empty( $next );
69
+    }
70
+
71
+    /**
72
+     * Schedule the migration.
73
+     *
74
+     * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
75
+     *
76
+     * @return string The action ID
77
+     */
78
+    public function schedule_migration( $when = 0 ) {
79
+        $next = as_next_scheduled_action( self::HOOK );
80
+
81
+        if ( ! empty( $next ) ) {
82
+            return $next;
83
+        }
84
+
85
+        if ( empty( $when ) ) {
86
+            $when = time();
87
+        }
88
+
89
+        return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
90
+    }
91
+
92
+    /**
93
+     * Remove the scheduled migration action.
94
+     */
95
+    public function unschedule_migration() {
96
+        as_unschedule_action( self::HOOK, null, self::GROUP );
97
+    }
98
+
99
+    /**
100
+     * Get migration batch schedule interval.
101
+     *
102
+     * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
103
+     */
104
+    private function get_schedule_interval() {
105
+        return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
106
+    }
107
+
108
+    /**
109
+     * Get migration batch size.
110
+     *
111
+     * @return int Number of actions to migrate in each batch. Defaults to 250.
112
+     */
113
+    private function get_batch_size() {
114
+        return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
115
+    }
116
+
117
+    /**
118
+     * Get migration runner object.
119
+     *
120
+     * @return Runner
121
+     */
122
+    private function get_migration_runner() {
123
+        $config = Controller::instance()->get_migration_config_object();
124
+
125
+        return new Runner( $config );
126
+    }
127 127
 
128 128
 }
Please login to merge, or discard this patch.
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();
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.
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.
libraries/action-scheduler/classes/migration/DryRun_LogMigrator.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
  * @codeCoverageIgnore
12 12
  */
13 13
 class DryRun_LogMigrator extends LogMigrator {
14
-	/**
15
-	 * Simulate migrating an action log.
16
-	 *
17
-	 * @param int $source_action_id Source logger object.
18
-	 * @param int $destination_action_id Destination logger object.
19
-	 */
20
-	public function migrate( $source_action_id, $destination_action_id ) {
21
-		// no-op
22
-	}
14
+    /**
15
+     * Simulate migrating an action log.
16
+     *
17
+     * @param int $source_action_id Source logger object.
18
+     * @param int $destination_action_id Destination logger object.
19
+     */
20
+    public function migrate( $source_action_id, $destination_action_id ) {
21
+        // no-op
22
+    }
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -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 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -9,39 +9,39 @@
 block discarded – undo
9 9
  */
10 10
 class ActionScheduler_DBStoreMigrator extends ActionScheduler_DBStore {
11 11
 
12
-	/**
13
-	 * Save an action with optional last attempt date.
14
-	 *
15
-	 * Normally, saving an action sets its attempted date to 0000-00-00 00:00:00 because when an action is first saved,
16
-	 * it can't have been attempted yet, but migrated completed actions will have an attempted date, so we need to save
17
-	 * that when first saving the action.
18
-	 *
19
-	 * @param ActionScheduler_Action $action
20
-	 * @param \DateTime $scheduled_date Optional date of the first instance to store.
21
-	 * @param \DateTime $last_attempt_date Optional date the action was last attempted.
22
-	 *
23
-	 * @return string The action ID
24
-	 * @throws \RuntimeException When the action is not saved.
25
-	 */
26
-	public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){
27
-		try {
28
-			/** @var \wpdb $wpdb */
29
-			global $wpdb;
12
+    /**
13
+     * Save an action with optional last attempt date.
14
+     *
15
+     * Normally, saving an action sets its attempted date to 0000-00-00 00:00:00 because when an action is first saved,
16
+     * it can't have been attempted yet, but migrated completed actions will have an attempted date, so we need to save
17
+     * that when first saving the action.
18
+     *
19
+     * @param ActionScheduler_Action $action
20
+     * @param \DateTime $scheduled_date Optional date of the first instance to store.
21
+     * @param \DateTime $last_attempt_date Optional date the action was last attempted.
22
+     *
23
+     * @return string The action ID
24
+     * @throws \RuntimeException When the action is not saved.
25
+     */
26
+    public function save_action( ActionScheduler_Action $action, \DateTime $scheduled_date = null, \DateTime $last_attempt_date = null ){
27
+        try {
28
+            /** @var \wpdb $wpdb */
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 ) {
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 ),
37
-				];
33
+            if ( null !== $last_attempt_date ) {
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 ),
37
+                ];
38 38
 
39
-				$wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
40
-			}
39
+                $wpdb->update( $wpdb->actionscheduler_actions, $data, array( 'action_id' => $action_id ), array( '%s', '%s' ), array( '%d' ) );
40
+            }
41 41
 
42
-			return $action_id;
43
-		} catch ( \Exception $e ) {
44
-			throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
45
-		}
46
-	}
42
+            return $action_id;
43
+        } catch ( \Exception $e ) {
44
+            throw new \RuntimeException( sprintf( __( 'Error saving action: %s', 'action-scheduler' ), $e->getMessage() ), 0 );
45
+        }
46
+    }
47 47
 }
Please login to merge, or discard this 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 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -17,190 +17,190 @@
 block discarded – undo
17 17
  * @codeCoverageIgnore
18 18
  */
19 19
 class Controller {
20
-	private static $instance;
21
-
22
-	/** @var Action_Scheduler\Migration\Scheduler */
23
-	private $migration_scheduler;
24
-
25
-	/** @var string */
26
-	private $store_classname;
27
-
28
-	/** @var string */
29
-	private $logger_classname;
30
-
31
-	/** @var bool */
32
-	private $migrate_custom_store;
33
-
34
-	/**
35
-	 * Controller constructor.
36
-	 *
37
-	 * @param Scheduler $migration_scheduler Migration scheduler object.
38
-	 */
39
-	protected function __construct( Scheduler $migration_scheduler ) {
40
-		$this->migration_scheduler = $migration_scheduler;
41
-		$this->store_classname     = '';
42
-	}
43
-
44
-	/**
45
-	 * Set the action store class name.
46
-	 *
47
-	 * @param string $class Classname of the store class.
48
-	 *
49
-	 * @return string
50
-	 */
51
-	public function get_store_class( $class ) {
52
-		if ( \ActionScheduler_DataController::is_migration_complete() ) {
53
-			return \ActionScheduler_DataController::DATASTORE_CLASS;
54
-		} elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
55
-			$this->store_classname = $class;
56
-			return $class;
57
-		} else {
58
-			return 'ActionScheduler_HybridStore';
59
-		}
60
-	}
61
-
62
-	/**
63
-	 * Set the action logger class name.
64
-	 *
65
-	 * @param string $class Classname of the logger class.
66
-	 *
67
-	 * @return string
68
-	 */
69
-	public function get_logger_class( $class ) {
70
-		\ActionScheduler_Store::instance();
71
-
72
-		if ( $this->has_custom_datastore() ) {
73
-			$this->logger_classname = $class;
74
-			return $class;
75
-		} else {
76
-			return \ActionScheduler_DataController::LOGGER_CLASS;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Get flag indicating whether a custom datastore is in use.
82
-	 *
83
-	 * @return bool
84
-	 */
85
-	public function has_custom_datastore() {
86
-		return (bool) $this->store_classname;
87
-	}
88
-
89
-	/**
90
-	 * Set up the background migration process
91
-	 *
92
-	 * @return void
93
-	 */
94
-	public function schedule_migration() {
95
-		if ( \ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled() ) {
96
-			return;
97
-		}
98
-
99
-		$this->migration_scheduler->schedule_migration();
100
-	}
101
-
102
-	/**
103
-	 * Get the default migration config object
104
-	 *
105
-	 * @return ActionScheduler\Migration\Config
106
-	 */
107
-	public function get_migration_config_object() {
108
-		static $config = null;
109
-
110
-		if ( ! $config ) {
111
-			$source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
112
-			$source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
113
-
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() );
119
-
120
-			if ( defined( 'WP_CLI' ) && WP_CLI ) {
121
-				$config->set_progress_bar( new ProgressBar( '', 0 ) );
122
-			}
123
-		}
124
-
125
-		return apply_filters( 'action_scheduler/migration_config', $config );
126
-	}
127
-
128
-	/**
129
-	 * Hook dashboard migration notice.
130
-	 */
131
-	public function hook_admin_notices() {
132
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
133
-			return;
134
-		}
135
-		add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
136
-	}
137
-
138
-	/**
139
-	 * Show a dashboard notice that migration is in progress.
140
-	 */
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' ) );
143
-	}
144
-
145
-	/**
146
-	 * Add store classes. Hook migration.
147
-	 */
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 );
153
-
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 );
157
-	}
158
-
159
-	/**
160
-	 * Possibly hook the migration scheduler action.
161
-	 *
162
-	 * @author Jeremy Pry
163
-	 */
164
-	public function maybe_hook_migration() {
165
-		if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
166
-			return;
167
-		}
168
-
169
-		$this->migration_scheduler->hook();
170
-	}
171
-
172
-	/**
173
-	 * Allow datastores to enable migration to AS tables.
174
-	 */
175
-	public function allow_migration() {
176
-		if ( ! \ActionScheduler_DataController::dependencies_met() ) {
177
-			return false;
178
-		}
179
-
180
-		if ( null === $this->migrate_custom_store ) {
181
-			$this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
182
-		}
183
-
184
-		return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
185
-	}
186
-
187
-	/**
188
-	 * Proceed with the migration if the dependencies have been met.
189
-	 */
190
-	public static function init() {
191
-		if ( \ActionScheduler_DataController::dependencies_met() ) {
192
-			self::instance()->hook();
193
-		}
194
-	}
195
-
196
-	/**
197
-	 * Singleton factory.
198
-	 */
199
-	public static function instance() {
200
-		if ( ! isset( self::$instance ) ) {
201
-			self::$instance = new static( new Scheduler() );
202
-		}
203
-
204
-		return self::$instance;
205
-	}
20
+    private static $instance;
21
+
22
+    /** @var Action_Scheduler\Migration\Scheduler */
23
+    private $migration_scheduler;
24
+
25
+    /** @var string */
26
+    private $store_classname;
27
+
28
+    /** @var string */
29
+    private $logger_classname;
30
+
31
+    /** @var bool */
32
+    private $migrate_custom_store;
33
+
34
+    /**
35
+     * Controller constructor.
36
+     *
37
+     * @param Scheduler $migration_scheduler Migration scheduler object.
38
+     */
39
+    protected function __construct( Scheduler $migration_scheduler ) {
40
+        $this->migration_scheduler = $migration_scheduler;
41
+        $this->store_classname     = '';
42
+    }
43
+
44
+    /**
45
+     * Set the action store class name.
46
+     *
47
+     * @param string $class Classname of the store class.
48
+     *
49
+     * @return string
50
+     */
51
+    public function get_store_class( $class ) {
52
+        if ( \ActionScheduler_DataController::is_migration_complete() ) {
53
+            return \ActionScheduler_DataController::DATASTORE_CLASS;
54
+        } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) {
55
+            $this->store_classname = $class;
56
+            return $class;
57
+        } else {
58
+            return 'ActionScheduler_HybridStore';
59
+        }
60
+    }
61
+
62
+    /**
63
+     * Set the action logger class name.
64
+     *
65
+     * @param string $class Classname of the logger class.
66
+     *
67
+     * @return string
68
+     */
69
+    public function get_logger_class( $class ) {
70
+        \ActionScheduler_Store::instance();
71
+
72
+        if ( $this->has_custom_datastore() ) {
73
+            $this->logger_classname = $class;
74
+            return $class;
75
+        } else {
76
+            return \ActionScheduler_DataController::LOGGER_CLASS;
77
+        }
78
+    }
79
+
80
+    /**
81
+     * Get flag indicating whether a custom datastore is in use.
82
+     *
83
+     * @return bool
84
+     */
85
+    public function has_custom_datastore() {
86
+        return (bool) $this->store_classname;
87
+    }
88
+
89
+    /**
90
+     * Set up the background migration process
91
+     *
92
+     * @return void
93
+     */
94
+    public function schedule_migration() {
95
+        if ( \ActionScheduler_DataController::is_migration_complete() || $this->migration_scheduler->is_migration_scheduled() ) {
96
+            return;
97
+        }
98
+
99
+        $this->migration_scheduler->schedule_migration();
100
+    }
101
+
102
+    /**
103
+     * Get the default migration config object
104
+     *
105
+     * @return ActionScheduler\Migration\Config
106
+     */
107
+    public function get_migration_config_object() {
108
+        static $config = null;
109
+
110
+        if ( ! $config ) {
111
+            $source_store  = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore();
112
+            $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger();
113
+
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() );
119
+
120
+            if ( defined( 'WP_CLI' ) && WP_CLI ) {
121
+                $config->set_progress_bar( new ProgressBar( '', 0 ) );
122
+            }
123
+        }
124
+
125
+        return apply_filters( 'action_scheduler/migration_config', $config );
126
+    }
127
+
128
+    /**
129
+     * Hook dashboard migration notice.
130
+     */
131
+    public function hook_admin_notices() {
132
+        if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
133
+            return;
134
+        }
135
+        add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 );
136
+    }
137
+
138
+    /**
139
+     * Show a dashboard notice that migration is in progress.
140
+     */
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' ) );
143
+    }
144
+
145
+    /**
146
+     * Add store classes. Hook migration.
147
+     */
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 );
153
+
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 );
157
+    }
158
+
159
+    /**
160
+     * Possibly hook the migration scheduler action.
161
+     *
162
+     * @author Jeremy Pry
163
+     */
164
+    public function maybe_hook_migration() {
165
+        if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) {
166
+            return;
167
+        }
168
+
169
+        $this->migration_scheduler->hook();
170
+    }
171
+
172
+    /**
173
+     * Allow datastores to enable migration to AS tables.
174
+     */
175
+    public function allow_migration() {
176
+        if ( ! \ActionScheduler_DataController::dependencies_met() ) {
177
+            return false;
178
+        }
179
+
180
+        if ( null === $this->migrate_custom_store ) {
181
+            $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false );
182
+        }
183
+
184
+        return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store;
185
+    }
186
+
187
+    /**
188
+     * Proceed with the migration if the dependencies have been met.
189
+     */
190
+    public static function init() {
191
+        if ( \ActionScheduler_DataController::dependencies_met() ) {
192
+            self::instance()->hook();
193
+        }
194
+    }
195
+
196
+    /**
197
+     * Singleton factory.
198
+     */
199
+    public static function instance() {
200
+        if ( ! isset( self::$instance ) ) {
201
+            self::$instance = new static( new Scheduler() );
202
+        }
203
+
204
+        return self::$instance;
205
+    }
206 206
 }
Please login to merge, or discard this 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 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -13,97 +13,97 @@
 block discarded – undo
13 13
  * @codeCoverageIgnore
14 14
  */
15 15
 class ActionMigrator {
16
-	/** var ActionScheduler_Store */
17
-	private $source;
18
-
19
-	/** var ActionScheduler_Store */
20
-	private $destination;
21
-
22
-	/** var LogMigrator */
23
-	private $log_migrator;
24
-
25
-	/**
26
-	 * ActionMigrator constructor.
27
-	 *
28
-	 * @param ActionScheduler_Store $source_store Source store object.
29
-	 * @param ActionScheduler_Store $destination_store Destination store object.
30
-	 * @param LogMigrator           $log_migrator Log migrator object.
31
-	 */
32
-	public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
33
-		$this->source       = $source_store;
34
-		$this->destination  = $destination_store;
35
-		$this->log_migrator = $log_migrator;
36
-	}
37
-
38
-	/**
39
-	 * Migrate an action.
40
-	 *
41
-	 * @param int $source_action_id Action ID.
42
-	 *
43
-	 * @return int 0|new action ID
44
-	 */
45
-	public function migrate( $source_action_id ) {
46
-		try {
47
-			$action = $this->source->fetch_action( $source_action_id );
48
-			$status = $this->source->get_status( $source_action_id );
49
-		} catch ( \Exception $e ) {
50
-			$action = null;
51
-			$status = '';
52
-		}
53
-
54
-		if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
55
-			// null action or empty status means the fetch operation failed or the action didn't exist
56
-			// null schedule means it's missing vital data
57
-			// delete it and move on
58
-			try {
59
-				$this->source->delete_action( $source_action_id );
60
-			} catch ( \Exception $e ) {
61
-				// nothing to do, it didn't exist in the first place
62
-			}
63
-			do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
64
-
65
-			return 0;
66
-		}
67
-
68
-		try {
69
-
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;
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 );
76
-
77
-			return 0; // could not save the action in the new store
78
-		}
79
-
80
-		try {
81
-			switch ( $status ) {
82
-				case \ActionScheduler_Store::STATUS_FAILED :
83
-					$this->destination->mark_failure( $destination_action_id );
84
-					break;
85
-				case \ActionScheduler_Store::STATUS_CANCELED :
86
-					$this->destination->cancel_action( $destination_action_id );
87
-					break;
88
-			}
89
-
90
-			$this->log_migrator->migrate( $source_action_id, $destination_action_id );
91
-			$this->source->delete_action( $source_action_id );
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 ) );
96
-			}
97
-			do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
98
-
99
-			return $destination_action_id;
100
-		} catch ( \Exception $e ) {
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 );
105
-
106
-			return $destination_action_id;
107
-		}
108
-	}
16
+    /** var ActionScheduler_Store */
17
+    private $source;
18
+
19
+    /** var ActionScheduler_Store */
20
+    private $destination;
21
+
22
+    /** var LogMigrator */
23
+    private $log_migrator;
24
+
25
+    /**
26
+     * ActionMigrator constructor.
27
+     *
28
+     * @param ActionScheduler_Store $source_store Source store object.
29
+     * @param ActionScheduler_Store $destination_store Destination store object.
30
+     * @param LogMigrator           $log_migrator Log migrator object.
31
+     */
32
+    public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
33
+        $this->source       = $source_store;
34
+        $this->destination  = $destination_store;
35
+        $this->log_migrator = $log_migrator;
36
+    }
37
+
38
+    /**
39
+     * Migrate an action.
40
+     *
41
+     * @param int $source_action_id Action ID.
42
+     *
43
+     * @return int 0|new action ID
44
+     */
45
+    public function migrate( $source_action_id ) {
46
+        try {
47
+            $action = $this->source->fetch_action( $source_action_id );
48
+            $status = $this->source->get_status( $source_action_id );
49
+        } catch ( \Exception $e ) {
50
+            $action = null;
51
+            $status = '';
52
+        }
53
+
54
+        if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
55
+            // null action or empty status means the fetch operation failed or the action didn't exist
56
+            // null schedule means it's missing vital data
57
+            // delete it and move on
58
+            try {
59
+                $this->source->delete_action( $source_action_id );
60
+            } catch ( \Exception $e ) {
61
+                // nothing to do, it didn't exist in the first place
62
+            }
63
+            do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
64
+
65
+            return 0;
66
+        }
67
+
68
+        try {
69
+
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;
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 );
76
+
77
+            return 0; // could not save the action in the new store
78
+        }
79
+
80
+        try {
81
+            switch ( $status ) {
82
+                case \ActionScheduler_Store::STATUS_FAILED :
83
+                    $this->destination->mark_failure( $destination_action_id );
84
+                    break;
85
+                case \ActionScheduler_Store::STATUS_CANCELED :
86
+                    $this->destination->cancel_action( $destination_action_id );
87
+                    break;
88
+            }
89
+
90
+            $this->log_migrator->migrate( $source_action_id, $destination_action_id );
91
+            $this->source->delete_action( $source_action_id );
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 ) );
96
+            }
97
+            do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
98
+
99
+            return $destination_action_id;
100
+        } catch ( \Exception $e ) {
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 );
105
+
106
+            return $destination_action_id;
107
+        }
108
+    }
109 109
 }
Please login to merge, or discard this 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.