@@ -17,152 +17,152 @@ |
||
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 | } |
@@ -48,8 +48,8 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -13,16 +13,16 @@ |
||
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 | } |
@@ -20,8 +20,8 @@ |
||
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 | } |
@@ -19,85 +19,85 @@ discard block |
||
19 | 19 | * @codeCoverageIgnore |
20 | 20 | */ |
21 | 21 | class Controller { |
22 | - private static $instance; |
|
23 | - |
|
24 | - /** @var Action_Scheduler\Migration\Scheduler */ |
|
25 | - private $migration_scheduler; |
|
26 | - |
|
27 | - /** @var string */ |
|
28 | - private $store_classname; |
|
29 | - |
|
30 | - /** @var string */ |
|
31 | - private $logger_classname; |
|
32 | - |
|
33 | - /** @var bool */ |
|
34 | - private $migrate_custom_store; |
|
35 | - |
|
36 | - /** |
|
37 | - * Controller constructor. |
|
38 | - * |
|
39 | - * @param Scheduler $migration_scheduler Migration scheduler object. |
|
40 | - */ |
|
41 | - protected function __construct( Scheduler $migration_scheduler ) { |
|
42 | - $this->migration_scheduler = $migration_scheduler; |
|
43 | - $this->store_classname = ''; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Set the action store class name. |
|
48 | - * |
|
49 | - * @param string $class Classname of the store class. |
|
50 | - * |
|
51 | - * @return string |
|
52 | - */ |
|
53 | - public function get_store_class( $class ) { |
|
54 | - if ( \ActionScheduler_DataController::is_migration_complete() ) { |
|
55 | - return \ActionScheduler_DataController::DATASTORE_CLASS; |
|
56 | - } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { |
|
57 | - $this->store_classname = $class; |
|
58 | - return $class; |
|
59 | - } else { |
|
60 | - return 'ActionScheduler_HybridStore'; |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Set the action logger class name. |
|
66 | - * |
|
67 | - * @param string $class Classname of the logger class. |
|
68 | - * |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function get_logger_class( $class ) { |
|
72 | - \ActionScheduler_Store::instance(); |
|
73 | - |
|
74 | - if ( $this->has_custom_datastore() ) { |
|
75 | - $this->logger_classname = $class; |
|
76 | - return $class; |
|
77 | - } else { |
|
78 | - return \ActionScheduler_DataController::LOGGER_CLASS; |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Get flag indicating whether a custom datastore is in use. |
|
84 | - * |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function has_custom_datastore() { |
|
88 | - return (bool) $this->store_classname; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Set up the background migration process. |
|
93 | - * |
|
94 | - * @return void |
|
95 | - */ |
|
96 | - public function schedule_migration() { |
|
97 | - $logging_tables = new ActionScheduler_LoggerSchema(); |
|
98 | - $store_tables = new ActionScheduler_StoreSchema(); |
|
99 | - |
|
100 | - /* |
|
22 | + private static $instance; |
|
23 | + |
|
24 | + /** @var Action_Scheduler\Migration\Scheduler */ |
|
25 | + private $migration_scheduler; |
|
26 | + |
|
27 | + /** @var string */ |
|
28 | + private $store_classname; |
|
29 | + |
|
30 | + /** @var string */ |
|
31 | + private $logger_classname; |
|
32 | + |
|
33 | + /** @var bool */ |
|
34 | + private $migrate_custom_store; |
|
35 | + |
|
36 | + /** |
|
37 | + * Controller constructor. |
|
38 | + * |
|
39 | + * @param Scheduler $migration_scheduler Migration scheduler object. |
|
40 | + */ |
|
41 | + protected function __construct( Scheduler $migration_scheduler ) { |
|
42 | + $this->migration_scheduler = $migration_scheduler; |
|
43 | + $this->store_classname = ''; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Set the action store class name. |
|
48 | + * |
|
49 | + * @param string $class Classname of the store class. |
|
50 | + * |
|
51 | + * @return string |
|
52 | + */ |
|
53 | + public function get_store_class( $class ) { |
|
54 | + if ( \ActionScheduler_DataController::is_migration_complete() ) { |
|
55 | + return \ActionScheduler_DataController::DATASTORE_CLASS; |
|
56 | + } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { |
|
57 | + $this->store_classname = $class; |
|
58 | + return $class; |
|
59 | + } else { |
|
60 | + return 'ActionScheduler_HybridStore'; |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Set the action logger class name. |
|
66 | + * |
|
67 | + * @param string $class Classname of the logger class. |
|
68 | + * |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function get_logger_class( $class ) { |
|
72 | + \ActionScheduler_Store::instance(); |
|
73 | + |
|
74 | + if ( $this->has_custom_datastore() ) { |
|
75 | + $this->logger_classname = $class; |
|
76 | + return $class; |
|
77 | + } else { |
|
78 | + return \ActionScheduler_DataController::LOGGER_CLASS; |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Get flag indicating whether a custom datastore is in use. |
|
84 | + * |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function has_custom_datastore() { |
|
88 | + return (bool) $this->store_classname; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Set up the background migration process. |
|
93 | + * |
|
94 | + * @return void |
|
95 | + */ |
|
96 | + public function schedule_migration() { |
|
97 | + $logging_tables = new ActionScheduler_LoggerSchema(); |
|
98 | + $store_tables = new ActionScheduler_StoreSchema(); |
|
99 | + |
|
100 | + /* |
|
101 | 101 | * In some unusual cases, the expected tables may not have been created. In such cases |
102 | 102 | * we do not schedule a migration as doing so will lead to fatal error conditions. |
103 | 103 | * |
@@ -107,120 +107,120 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @see https://github.com/woocommerce/action-scheduler/issues/653 |
109 | 109 | */ |
110 | - if ( |
|
111 | - ActionScheduler_DataController::is_migration_complete() |
|
112 | - || $this->migration_scheduler->is_migration_scheduled() |
|
113 | - || ! $store_tables->tables_exist() |
|
114 | - || ! $logging_tables->tables_exist() |
|
115 | - ) { |
|
116 | - return; |
|
117 | - } |
|
118 | - |
|
119 | - $this->migration_scheduler->schedule_migration(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get the default migration config object |
|
124 | - * |
|
125 | - * @return ActionScheduler\Migration\Config |
|
126 | - */ |
|
127 | - public function get_migration_config_object() { |
|
128 | - static $config = null; |
|
129 | - |
|
130 | - if ( ! $config ) { |
|
131 | - $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); |
|
132 | - $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); |
|
133 | - |
|
134 | - $config = new Config(); |
|
135 | - $config->set_source_store( $source_store ); |
|
136 | - $config->set_source_logger( $source_logger ); |
|
137 | - $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); |
|
138 | - $config->set_destination_logger( new \ActionScheduler_DBLogger() ); |
|
139 | - |
|
140 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
141 | - $config->set_progress_bar( new ProgressBar( '', 0 ) ); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - return apply_filters( 'action_scheduler/migration_config', $config ); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Hook dashboard migration notice. |
|
150 | - */ |
|
151 | - public function hook_admin_notices() { |
|
152 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
153 | - return; |
|
154 | - } |
|
155 | - add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Show a dashboard notice that migration is in progress. |
|
160 | - */ |
|
161 | - public function display_migration_notice() { |
|
162 | - printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Add store classes. Hook migration. |
|
167 | - */ |
|
168 | - private function hook() { |
|
169 | - add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); |
|
170 | - add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); |
|
171 | - add_action( 'init', array( $this, 'maybe_hook_migration' ) ); |
|
172 | - add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); |
|
173 | - |
|
174 | - // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
|
175 | - add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
176 | - add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Possibly hook the migration scheduler action. |
|
181 | - * |
|
182 | - * @author Jeremy Pry |
|
183 | - */ |
|
184 | - public function maybe_hook_migration() { |
|
185 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
186 | - return; |
|
187 | - } |
|
188 | - |
|
189 | - $this->migration_scheduler->hook(); |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Allow datastores to enable migration to AS tables. |
|
194 | - */ |
|
195 | - public function allow_migration() { |
|
196 | - if ( ! \ActionScheduler_DataController::dependencies_met() ) { |
|
197 | - return false; |
|
198 | - } |
|
199 | - |
|
200 | - if ( null === $this->migrate_custom_store ) { |
|
201 | - $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); |
|
202 | - } |
|
203 | - |
|
204 | - return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Proceed with the migration if the dependencies have been met. |
|
209 | - */ |
|
210 | - public static function init() { |
|
211 | - if ( \ActionScheduler_DataController::dependencies_met() ) { |
|
212 | - self::instance()->hook(); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Singleton factory. |
|
218 | - */ |
|
219 | - public static function instance() { |
|
220 | - if ( ! isset( self::$instance ) ) { |
|
221 | - self::$instance = new static( new Scheduler() ); |
|
222 | - } |
|
223 | - |
|
224 | - return self::$instance; |
|
225 | - } |
|
110 | + if ( |
|
111 | + ActionScheduler_DataController::is_migration_complete() |
|
112 | + || $this->migration_scheduler->is_migration_scheduled() |
|
113 | + || ! $store_tables->tables_exist() |
|
114 | + || ! $logging_tables->tables_exist() |
|
115 | + ) { |
|
116 | + return; |
|
117 | + } |
|
118 | + |
|
119 | + $this->migration_scheduler->schedule_migration(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get the default migration config object |
|
124 | + * |
|
125 | + * @return ActionScheduler\Migration\Config |
|
126 | + */ |
|
127 | + public function get_migration_config_object() { |
|
128 | + static $config = null; |
|
129 | + |
|
130 | + if ( ! $config ) { |
|
131 | + $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); |
|
132 | + $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); |
|
133 | + |
|
134 | + $config = new Config(); |
|
135 | + $config->set_source_store( $source_store ); |
|
136 | + $config->set_source_logger( $source_logger ); |
|
137 | + $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); |
|
138 | + $config->set_destination_logger( new \ActionScheduler_DBLogger() ); |
|
139 | + |
|
140 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
141 | + $config->set_progress_bar( new ProgressBar( '', 0 ) ); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + return apply_filters( 'action_scheduler/migration_config', $config ); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Hook dashboard migration notice. |
|
150 | + */ |
|
151 | + public function hook_admin_notices() { |
|
152 | + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
153 | + return; |
|
154 | + } |
|
155 | + add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Show a dashboard notice that migration is in progress. |
|
160 | + */ |
|
161 | + public function display_migration_notice() { |
|
162 | + printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Add store classes. Hook migration. |
|
167 | + */ |
|
168 | + private function hook() { |
|
169 | + add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); |
|
170 | + add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); |
|
171 | + add_action( 'init', array( $this, 'maybe_hook_migration' ) ); |
|
172 | + add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); |
|
173 | + |
|
174 | + // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
|
175 | + add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
176 | + add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Possibly hook the migration scheduler action. |
|
181 | + * |
|
182 | + * @author Jeremy Pry |
|
183 | + */ |
|
184 | + public function maybe_hook_migration() { |
|
185 | + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
186 | + return; |
|
187 | + } |
|
188 | + |
|
189 | + $this->migration_scheduler->hook(); |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Allow datastores to enable migration to AS tables. |
|
194 | + */ |
|
195 | + public function allow_migration() { |
|
196 | + if ( ! \ActionScheduler_DataController::dependencies_met() ) { |
|
197 | + return false; |
|
198 | + } |
|
199 | + |
|
200 | + if ( null === $this->migrate_custom_store ) { |
|
201 | + $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); |
|
202 | + } |
|
203 | + |
|
204 | + return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Proceed with the migration if the dependencies have been met. |
|
209 | + */ |
|
210 | + public static function init() { |
|
211 | + if ( \ActionScheduler_DataController::dependencies_met() ) { |
|
212 | + self::instance()->hook(); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Singleton factory. |
|
218 | + */ |
|
219 | + public static function instance() { |
|
220 | + if ( ! isset( self::$instance ) ) { |
|
221 | + self::$instance = new static( new Scheduler() ); |
|
222 | + } |
|
223 | + |
|
224 | + return self::$instance; |
|
225 | + } |
|
226 | 226 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @param Scheduler $migration_scheduler Migration scheduler object. |
40 | 40 | */ |
41 | - protected function __construct( Scheduler $migration_scheduler ) { |
|
41 | + protected function __construct(Scheduler $migration_scheduler) { |
|
42 | 42 | $this->migration_scheduler = $migration_scheduler; |
43 | 43 | $this->store_classname = ''; |
44 | 44 | } |
@@ -50,10 +50,10 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - public function get_store_class( $class ) { |
|
54 | - if ( \ActionScheduler_DataController::is_migration_complete() ) { |
|
53 | + public function get_store_class($class) { |
|
54 | + if (\ActionScheduler_DataController::is_migration_complete()) { |
|
55 | 55 | return \ActionScheduler_DataController::DATASTORE_CLASS; |
56 | - } elseif ( \ActionScheduler_Store::DEFAULT_CLASS !== $class ) { |
|
56 | + } elseif (\ActionScheduler_Store::DEFAULT_CLASS !== $class) { |
|
57 | 57 | $this->store_classname = $class; |
58 | 58 | return $class; |
59 | 59 | } else { |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return string |
70 | 70 | */ |
71 | - public function get_logger_class( $class ) { |
|
71 | + public function get_logger_class($class) { |
|
72 | 72 | \ActionScheduler_Store::instance(); |
73 | 73 | |
74 | - if ( $this->has_custom_datastore() ) { |
|
74 | + if ($this->has_custom_datastore()) { |
|
75 | 75 | $this->logger_classname = $class; |
76 | 76 | return $class; |
77 | 77 | } else { |
@@ -127,53 +127,53 @@ discard block |
||
127 | 127 | public function get_migration_config_object() { |
128 | 128 | static $config = null; |
129 | 129 | |
130 | - if ( ! $config ) { |
|
130 | + if ( ! $config) { |
|
131 | 131 | $source_store = $this->store_classname ? new $this->store_classname() : new \ActionScheduler_wpPostStore(); |
132 | 132 | $source_logger = $this->logger_classname ? new $this->logger_classname() : new \ActionScheduler_wpCommentLogger(); |
133 | 133 | |
134 | 134 | $config = new Config(); |
135 | - $config->set_source_store( $source_store ); |
|
136 | - $config->set_source_logger( $source_logger ); |
|
137 | - $config->set_destination_store( new \ActionScheduler_DBStoreMigrator() ); |
|
138 | - $config->set_destination_logger( new \ActionScheduler_DBLogger() ); |
|
135 | + $config->set_source_store($source_store); |
|
136 | + $config->set_source_logger($source_logger); |
|
137 | + $config->set_destination_store(new \ActionScheduler_DBStoreMigrator()); |
|
138 | + $config->set_destination_logger(new \ActionScheduler_DBLogger()); |
|
139 | 139 | |
140 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
141 | - $config->set_progress_bar( new ProgressBar( '', 0 ) ); |
|
140 | + if (defined('WP_CLI') && WP_CLI) { |
|
141 | + $config->set_progress_bar(new ProgressBar('', 0)); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - return apply_filters( 'action_scheduler/migration_config', $config ); |
|
145 | + return apply_filters('action_scheduler/migration_config', $config); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
149 | 149 | * Hook dashboard migration notice. |
150 | 150 | */ |
151 | 151 | public function hook_admin_notices() { |
152 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
152 | + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) { |
|
153 | 153 | return; |
154 | 154 | } |
155 | - add_action( 'admin_notices', array( $this, 'display_migration_notice' ), 10, 0 ); |
|
155 | + add_action('admin_notices', array($this, 'display_migration_notice'), 10, 0); |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | /** |
159 | 159 | * Show a dashboard notice that migration is in progress. |
160 | 160 | */ |
161 | 161 | public function display_migration_notice() { |
162 | - printf( '<div class="notice notice-warning"><p>%s</p></div>', esc_html__( 'Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler' ) ); |
|
162 | + printf('<div class="notice notice-warning"><p>%s</p></div>', esc_html__('Action Scheduler migration in progress. The list of scheduled actions may be incomplete.', 'action-scheduler')); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
166 | 166 | * Add store classes. Hook migration. |
167 | 167 | */ |
168 | 168 | private function hook() { |
169 | - add_filter( 'action_scheduler_store_class', array( $this, 'get_store_class' ), 100, 1 ); |
|
170 | - add_filter( 'action_scheduler_logger_class', array( $this, 'get_logger_class' ), 100, 1 ); |
|
171 | - add_action( 'init', array( $this, 'maybe_hook_migration' ) ); |
|
172 | - add_action( 'wp_loaded', array( $this, 'schedule_migration' ) ); |
|
169 | + add_filter('action_scheduler_store_class', array($this, 'get_store_class'), 100, 1); |
|
170 | + add_filter('action_scheduler_logger_class', array($this, 'get_logger_class'), 100, 1); |
|
171 | + add_action('init', array($this, 'maybe_hook_migration')); |
|
172 | + add_action('wp_loaded', array($this, 'schedule_migration')); |
|
173 | 173 | |
174 | 174 | // Action Scheduler may be displayed as a Tools screen or WooCommerce > Status administration screen |
175 | - add_action( 'load-tools_page_action-scheduler', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
176 | - add_action( 'load-woocommerce_page_wc-status', array( $this, 'hook_admin_notices' ), 10, 0 ); |
|
175 | + add_action('load-tools_page_action-scheduler', array($this, 'hook_admin_notices'), 10, 0); |
|
176 | + add_action('load-woocommerce_page_wc-status', array($this, 'hook_admin_notices'), 10, 0); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @author Jeremy Pry |
183 | 183 | */ |
184 | 184 | public function maybe_hook_migration() { |
185 | - if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete() ) { |
|
185 | + if ( ! $this->allow_migration() || \ActionScheduler_DataController::is_migration_complete()) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | |
@@ -193,22 +193,22 @@ discard block |
||
193 | 193 | * Allow datastores to enable migration to AS tables. |
194 | 194 | */ |
195 | 195 | public function allow_migration() { |
196 | - if ( ! \ActionScheduler_DataController::dependencies_met() ) { |
|
196 | + if ( ! \ActionScheduler_DataController::dependencies_met()) { |
|
197 | 197 | return false; |
198 | 198 | } |
199 | 199 | |
200 | - if ( null === $this->migrate_custom_store ) { |
|
201 | - $this->migrate_custom_store = apply_filters( 'action_scheduler_migrate_data_store', false ); |
|
200 | + if (null === $this->migrate_custom_store) { |
|
201 | + $this->migrate_custom_store = apply_filters('action_scheduler_migrate_data_store', false); |
|
202 | 202 | } |
203 | 203 | |
204 | - return ( ! $this->has_custom_datastore() ) || $this->migrate_custom_store; |
|
204 | + return ( ! $this->has_custom_datastore()) || $this->migrate_custom_store; |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | 208 | * Proceed with the migration if the dependencies have been met. |
209 | 209 | */ |
210 | 210 | public static function init() { |
211 | - if ( \ActionScheduler_DataController::dependencies_met() ) { |
|
211 | + if (\ActionScheduler_DataController::dependencies_met()) { |
|
212 | 212 | self::instance()->hook(); |
213 | 213 | } |
214 | 214 | } |
@@ -217,8 +217,8 @@ discard block |
||
217 | 217 | * Singleton factory. |
218 | 218 | */ |
219 | 219 | public static function instance() { |
220 | - if ( ! isset( self::$instance ) ) { |
|
221 | - self::$instance = new static( new Scheduler() ); |
|
220 | + if ( ! isset(self::$instance)) { |
|
221 | + self::$instance = new static(new Scheduler()); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return self::$instance; |
@@ -23,14 +23,14 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
75 | 75 | * |
76 | 76 | * @return string The action ID |
77 | 77 | */ |
78 | - public function schedule_migration( $when = 0 ) { |
|
79 | - $next = as_next_scheduled_action( self::HOOK ); |
|
78 | + public function schedule_migration($when = 0) { |
|
79 | + $next = as_next_scheduled_action(self::HOOK); |
|
80 | 80 | |
81 | - if ( ! empty( $next ) ) { |
|
81 | + if ( ! empty($next)) { |
|
82 | 82 | return $next; |
83 | 83 | } |
84 | 84 | |
85 | - if ( empty( $when ) ) { |
|
85 | + if (empty($when)) { |
|
86 | 86 | $when = time() + MINUTE_IN_SECONDS; |
87 | 87 | } |
88 | 88 | |
89 | - return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); |
|
89 | + return as_schedule_single_action($when, self::HOOK, array(), self::GROUP); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
93 | 93 | * Remove the scheduled migration action. |
94 | 94 | */ |
95 | 95 | public function unschedule_migration() { |
96 | - as_unschedule_action( self::HOOK, null, self::GROUP ); |
|
96 | + as_unschedule_action(self::HOOK, null, self::GROUP); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -102,7 +102,7 @@ discard block |
||
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 |
||
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 |
||
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 | } |
@@ -12,116 +12,116 @@ |
||
12 | 12 | * @codeCoverageIgnore |
13 | 13 | */ |
14 | 14 | class Scheduler { |
15 | - /** Migration action hook. */ |
|
16 | - const HOOK = 'action_scheduler/migration_hook'; |
|
17 | - |
|
18 | - /** Migration action group. */ |
|
19 | - const GROUP = 'action-scheduler-migration'; |
|
20 | - |
|
21 | - /** |
|
22 | - * Set up the callback for the scheduled job. |
|
23 | - */ |
|
24 | - public function hook() { |
|
25 | - add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 ); |
|
26 | - } |
|
27 | - |
|
28 | - /** |
|
29 | - * Remove the callback for the scheduled job. |
|
30 | - */ |
|
31 | - public function unhook() { |
|
32 | - remove_action( self::HOOK, array( $this, 'run_migration' ), 10 ); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * The migration callback. |
|
37 | - */ |
|
38 | - public function run_migration() { |
|
39 | - $migration_runner = $this->get_migration_runner(); |
|
40 | - $count = $migration_runner->run( $this->get_batch_size() ); |
|
41 | - |
|
42 | - if ( $count === 0 ) { |
|
43 | - $this->mark_complete(); |
|
44 | - } else { |
|
45 | - $this->schedule_migration( time() + $this->get_schedule_interval() ); |
|
46 | - } |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Mark the migration complete. |
|
51 | - */ |
|
52 | - public function mark_complete() { |
|
53 | - $this->unschedule_migration(); |
|
54 | - |
|
55 | - \ActionScheduler_DataController::mark_migration_complete(); |
|
56 | - do_action( 'action_scheduler/migration_complete' ); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Get a flag indicating whether the migration is scheduled. |
|
61 | - * |
|
62 | - * @return bool Whether there is a pending action in the store to handle the migration |
|
63 | - */ |
|
64 | - public function is_migration_scheduled() { |
|
65 | - $next = as_next_scheduled_action( self::HOOK ); |
|
66 | - |
|
67 | - return ! empty( $next ); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Schedule the migration. |
|
72 | - * |
|
73 | - * @param int $when Optional timestamp to run the next migration batch. Defaults to now. |
|
74 | - * |
|
75 | - * @return string The action ID |
|
76 | - */ |
|
77 | - public function schedule_migration( $when = 0 ) { |
|
78 | - $next = as_next_scheduled_action( self::HOOK ); |
|
79 | - |
|
80 | - if ( ! empty( $next ) ) { |
|
81 | - return $next; |
|
82 | - } |
|
83 | - |
|
84 | - if ( empty( $when ) ) { |
|
85 | - $when = time() + MINUTE_IN_SECONDS; |
|
86 | - } |
|
87 | - |
|
88 | - return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Remove the scheduled migration action. |
|
93 | - */ |
|
94 | - public function unschedule_migration() { |
|
95 | - as_unschedule_action( self::HOOK, null, self::GROUP ); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Get migration batch schedule interval. |
|
100 | - * |
|
101 | - * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners. |
|
102 | - */ |
|
103 | - private function get_schedule_interval() { |
|
104 | - return (int) apply_filters( 'action_scheduler/migration_interval', 0 ); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get migration batch size. |
|
109 | - * |
|
110 | - * @return int Number of actions to migrate in each batch. Defaults to 250. |
|
111 | - */ |
|
112 | - private function get_batch_size() { |
|
113 | - return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 ); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Get migration runner object. |
|
118 | - * |
|
119 | - * @return Runner |
|
120 | - */ |
|
121 | - private function get_migration_runner() { |
|
122 | - $config = Controller::instance()->get_migration_config_object(); |
|
123 | - |
|
124 | - return new Runner( $config ); |
|
125 | - } |
|
15 | + /** Migration action hook. */ |
|
16 | + const HOOK = 'action_scheduler/migration_hook'; |
|
17 | + |
|
18 | + /** Migration action group. */ |
|
19 | + const GROUP = 'action-scheduler-migration'; |
|
20 | + |
|
21 | + /** |
|
22 | + * Set up the callback for the scheduled job. |
|
23 | + */ |
|
24 | + public function hook() { |
|
25 | + add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 ); |
|
26 | + } |
|
27 | + |
|
28 | + /** |
|
29 | + * Remove the callback for the scheduled job. |
|
30 | + */ |
|
31 | + public function unhook() { |
|
32 | + remove_action( self::HOOK, array( $this, 'run_migration' ), 10 ); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * The migration callback. |
|
37 | + */ |
|
38 | + public function run_migration() { |
|
39 | + $migration_runner = $this->get_migration_runner(); |
|
40 | + $count = $migration_runner->run( $this->get_batch_size() ); |
|
41 | + |
|
42 | + if ( $count === 0 ) { |
|
43 | + $this->mark_complete(); |
|
44 | + } else { |
|
45 | + $this->schedule_migration( time() + $this->get_schedule_interval() ); |
|
46 | + } |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Mark the migration complete. |
|
51 | + */ |
|
52 | + public function mark_complete() { |
|
53 | + $this->unschedule_migration(); |
|
54 | + |
|
55 | + \ActionScheduler_DataController::mark_migration_complete(); |
|
56 | + do_action( 'action_scheduler/migration_complete' ); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Get a flag indicating whether the migration is scheduled. |
|
61 | + * |
|
62 | + * @return bool Whether there is a pending action in the store to handle the migration |
|
63 | + */ |
|
64 | + public function is_migration_scheduled() { |
|
65 | + $next = as_next_scheduled_action( self::HOOK ); |
|
66 | + |
|
67 | + return ! empty( $next ); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Schedule the migration. |
|
72 | + * |
|
73 | + * @param int $when Optional timestamp to run the next migration batch. Defaults to now. |
|
74 | + * |
|
75 | + * @return string The action ID |
|
76 | + */ |
|
77 | + public function schedule_migration( $when = 0 ) { |
|
78 | + $next = as_next_scheduled_action( self::HOOK ); |
|
79 | + |
|
80 | + if ( ! empty( $next ) ) { |
|
81 | + return $next; |
|
82 | + } |
|
83 | + |
|
84 | + if ( empty( $when ) ) { |
|
85 | + $when = time() + MINUTE_IN_SECONDS; |
|
86 | + } |
|
87 | + |
|
88 | + return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP ); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Remove the scheduled migration action. |
|
93 | + */ |
|
94 | + public function unschedule_migration() { |
|
95 | + as_unschedule_action( self::HOOK, null, self::GROUP ); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Get migration batch schedule interval. |
|
100 | + * |
|
101 | + * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners. |
|
102 | + */ |
|
103 | + private function get_schedule_interval() { |
|
104 | + return (int) apply_filters( 'action_scheduler/migration_interval', 0 ); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get migration batch size. |
|
109 | + * |
|
110 | + * @return int Number of actions to migrate in each batch. Defaults to 250. |
|
111 | + */ |
|
112 | + private function get_batch_size() { |
|
113 | + return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 ); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Get migration runner object. |
|
118 | + * |
|
119 | + * @return Runner |
|
120 | + */ |
|
121 | + private function get_migration_runner() { |
|
122 | + $config = Controller::instance()->get_migration_config_object(); |
|
123 | + |
|
124 | + return new Runner( $config ); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -5,54 +5,54 @@ |
||
5 | 5 | * @codeCoverageIgnore |
6 | 6 | */ |
7 | 7 | class ActionScheduler_wpPostStore_PostStatusRegistrar { |
8 | - public function register() { |
|
9 | - register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) ); |
|
10 | - register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); |
|
11 | - } |
|
8 | + public function register() { |
|
9 | + register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) ); |
|
10 | + register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); |
|
11 | + } |
|
12 | 12 | |
13 | - /** |
|
14 | - * Build the args array for the post type definition |
|
15 | - * |
|
16 | - * @return array |
|
17 | - */ |
|
18 | - protected function post_status_args() { |
|
19 | - $args = array( |
|
20 | - 'public' => false, |
|
21 | - 'exclude_from_search' => false, |
|
22 | - 'show_in_admin_all_list' => true, |
|
23 | - 'show_in_admin_status_list' => true, |
|
24 | - ); |
|
13 | + /** |
|
14 | + * Build the args array for the post type definition |
|
15 | + * |
|
16 | + * @return array |
|
17 | + */ |
|
18 | + protected function post_status_args() { |
|
19 | + $args = array( |
|
20 | + 'public' => false, |
|
21 | + 'exclude_from_search' => false, |
|
22 | + 'show_in_admin_all_list' => true, |
|
23 | + 'show_in_admin_status_list' => true, |
|
24 | + ); |
|
25 | 25 | |
26 | - return apply_filters( 'action_scheduler_post_status_args', $args ); |
|
27 | - } |
|
26 | + return apply_filters( 'action_scheduler_post_status_args', $args ); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Build the args array for the post type definition |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - protected function post_status_failed_labels() { |
|
35 | - $labels = array( |
|
36 | - 'label' => _x( 'Failed', 'post', 'action-scheduler' ), |
|
37 | - /* translators: %s: count */ |
|
38 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ), |
|
39 | - ); |
|
29 | + /** |
|
30 | + * Build the args array for the post type definition |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + protected function post_status_failed_labels() { |
|
35 | + $labels = array( |
|
36 | + 'label' => _x( 'Failed', 'post', 'action-scheduler' ), |
|
37 | + /* translators: %s: count */ |
|
38 | + 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ), |
|
39 | + ); |
|
40 | 40 | |
41 | - return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); |
|
42 | - } |
|
41 | + return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Build the args array for the post type definition |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - protected function post_status_running_labels() { |
|
50 | - $labels = array( |
|
51 | - 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ), |
|
52 | - /* translators: %s: count */ |
|
53 | - 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ), |
|
54 | - ); |
|
44 | + /** |
|
45 | + * Build the args array for the post type definition |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + protected function post_status_running_labels() { |
|
50 | + $labels = array( |
|
51 | + 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ), |
|
52 | + /* translators: %s: count */ |
|
53 | + 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ), |
|
54 | + ); |
|
55 | 55 | |
56 | - return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); |
|
57 | - } |
|
56 | + return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); |
|
57 | + } |
|
58 | 58 | } |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | */ |
7 | 7 | class ActionScheduler_wpPostStore_PostStatusRegistrar { |
8 | 8 | public function register() { |
9 | - register_post_status( ActionScheduler_Store::STATUS_RUNNING, array_merge( $this->post_status_args(), $this->post_status_running_labels() ) ); |
|
10 | - register_post_status( ActionScheduler_Store::STATUS_FAILED, array_merge( $this->post_status_args(), $this->post_status_failed_labels() ) ); |
|
9 | + register_post_status(ActionScheduler_Store::STATUS_RUNNING, array_merge($this->post_status_args(), $this->post_status_running_labels())); |
|
10 | + register_post_status(ActionScheduler_Store::STATUS_FAILED, array_merge($this->post_status_args(), $this->post_status_failed_labels())); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | 'show_in_admin_status_list' => true, |
24 | 24 | ); |
25 | 25 | |
26 | - return apply_filters( 'action_scheduler_post_status_args', $args ); |
|
26 | + return apply_filters('action_scheduler_post_status_args', $args); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -33,12 +33,12 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function post_status_failed_labels() { |
35 | 35 | $labels = array( |
36 | - 'label' => _x( 'Failed', 'post', 'action-scheduler' ), |
|
36 | + 'label' => _x('Failed', 'post', 'action-scheduler'), |
|
37 | 37 | /* translators: %s: count */ |
38 | - 'label_count' => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler' ), |
|
38 | + 'label_count' => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'action-scheduler'), |
|
39 | 39 | ); |
40 | 40 | |
41 | - return apply_filters( 'action_scheduler_post_status_failed_labels', $labels ); |
|
41 | + return apply_filters('action_scheduler_post_status_failed_labels', $labels); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | */ |
49 | 49 | protected function post_status_running_labels() { |
50 | 50 | $labels = array( |
51 | - 'label' => _x( 'In-Progress', 'post', 'action-scheduler' ), |
|
51 | + 'label' => _x('In-Progress', 'post', 'action-scheduler'), |
|
52 | 52 | /* translators: %s: count */ |
53 | - 'label_count' => _n_noop( 'In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler' ), |
|
53 | + 'label_count' => _n_noop('In-Progress <span class="count">(%s)</span>', 'In-Progress <span class="count">(%s)</span>', 'action-scheduler'), |
|
54 | 54 | ); |
55 | 55 | |
56 | - return apply_filters( 'action_scheduler_post_status_running_labels', $labels ); |
|
56 | + return apply_filters('action_scheduler_post_status_running_labels', $labels); |
|
57 | 57 | } |
58 | 58 | } |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * @return bool |
45 | 45 | */ |
46 | 46 | public static function dependencies_met() { |
47 | - $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' ); |
|
48 | - return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true ); |
|
47 | + $php_support = version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '>='); |
|
48 | + return $php_support && apply_filters('action_scheduler_migration_dependencies_met', true); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -54,14 +54,14 @@ discard block |
||
54 | 54 | * @return bool Whether the flag has been set marking the migration as complete |
55 | 55 | */ |
56 | 56 | public static function is_migration_complete() { |
57 | - return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE; |
|
57 | + return get_option(self::STATUS_FLAG) === self::STATUS_COMPLETE; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | 61 | * Mark the migration as complete. |
62 | 62 | */ |
63 | 63 | public static function mark_migration_complete() { |
64 | - update_option( self::STATUS_FLAG, self::STATUS_COMPLETE ); |
|
64 | + update_option(self::STATUS_FLAG, self::STATUS_COMPLETE); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * deactivated and the site was running on AS 2.x again. |
71 | 71 | */ |
72 | 72 | public static function mark_migration_incomplete() { |
73 | - delete_option( self::STATUS_FLAG ); |
|
73 | + delete_option(self::STATUS_FLAG); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return string |
82 | 82 | */ |
83 | - public static function set_store_class( $class ) { |
|
83 | + public static function set_store_class($class) { |
|
84 | 84 | return self::DATASTORE_CLASS; |
85 | 85 | } |
86 | 86 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @return string |
93 | 93 | */ |
94 | - public static function set_logger_class( $class ) { |
|
94 | + public static function set_logger_class($class) { |
|
95 | 95 | return self::LOGGER_CLASS; |
96 | 96 | } |
97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @param integer $sleep_time The number of seconds to pause before resuming operation. |
102 | 102 | */ |
103 | - public static function set_sleep_time( $sleep_time ) { |
|
103 | + public static function set_sleep_time($sleep_time) { |
|
104 | 104 | self::$sleep_time = (int) $sleep_time; |
105 | 105 | } |
106 | 106 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * |
110 | 110 | * @param integer $free_ticks The number of ticks to free memory on. |
111 | 111 | */ |
112 | - public static function set_free_ticks( $free_ticks ) { |
|
112 | + public static function set_free_ticks($free_ticks) { |
|
113 | 113 | self::$free_ticks = (int) $free_ticks; |
114 | 114 | } |
115 | 115 | |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @param int $ticks Current tick count. |
120 | 120 | */ |
121 | - public static function maybe_free_memory( $ticks ) { |
|
122 | - if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) { |
|
121 | + public static function maybe_free_memory($ticks) { |
|
122 | + if (self::$free_ticks && 0 === $ticks % self::$free_ticks) { |
|
123 | 123 | self::free_memory(); |
124 | 124 | } |
125 | 125 | } |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | * Reduce memory footprint by clearing the database query and object caches. |
129 | 129 | */ |
130 | 130 | public static function free_memory() { |
131 | - if ( 0 < self::$sleep_time ) { |
|
131 | + if (0 < self::$sleep_time) { |
|
132 | 132 | /* translators: %d: amount of time */ |
133 | - \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) ); |
|
134 | - sleep( self::$sleep_time ); |
|
133 | + \WP_CLI::warning(sprintf(_n('Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler'), self::$sleep_time)); |
|
134 | + sleep(self::$sleep_time); |
|
135 | 135 | } |
136 | 136 | |
137 | - \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) ); |
|
137 | + \WP_CLI::warning(__('Attempting to reduce used memory...', 'action-scheduler')); |
|
138 | 138 | |
139 | 139 | /** |
140 | 140 | * @var $wpdb \wpdb |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | $wpdb->queries = array(); |
146 | 146 | |
147 | - if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) { |
|
147 | + if ( ! is_a($wp_object_cache, 'WP_Object_Cache')) { |
|
148 | 148 | return; |
149 | 149 | } |
150 | 150 | |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | $wp_object_cache->memcache_debug = array(); |
154 | 154 | $wp_object_cache->cache = array(); |
155 | 155 | |
156 | - if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) { |
|
157 | - call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important |
|
156 | + if (is_callable(array($wp_object_cache, '__remoteset'))) { |
|
157 | + call_user_func(array($wp_object_cache, '__remoteset')); // important |
|
158 | 158 | } |
159 | 159 | } |
160 | 160 | |
@@ -163,22 +163,22 @@ discard block |
||
163 | 163 | * Otherwise, proceed with the migration if the dependencies have been met. |
164 | 164 | */ |
165 | 165 | public static function init() { |
166 | - if ( self::is_migration_complete() ) { |
|
167 | - add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 ); |
|
168 | - add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 ); |
|
169 | - add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) ); |
|
170 | - } elseif ( self::dependencies_met() ) { |
|
166 | + if (self::is_migration_complete()) { |
|
167 | + add_filter('action_scheduler_store_class', array('ActionScheduler_DataController', 'set_store_class'), 100); |
|
168 | + add_filter('action_scheduler_logger_class', array('ActionScheduler_DataController', 'set_logger_class'), 100); |
|
169 | + add_action('deactivate_plugin', array('ActionScheduler_DataController', 'mark_migration_incomplete')); |
|
170 | + } elseif (self::dependencies_met()) { |
|
171 | 171 | Controller::init(); |
172 | 172 | } |
173 | 173 | |
174 | - add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) ); |
|
174 | + add_action('action_scheduler/progress_tick', array('ActionScheduler_DataController', 'maybe_free_memory')); |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | /** |
178 | 178 | * Singleton factory. |
179 | 179 | */ |
180 | 180 | public static function instance() { |
181 | - if ( ! isset( self::$instance ) ) { |
|
181 | + if ( ! isset(self::$instance)) { |
|
182 | 182 | self::$instance = new static(); |
183 | 183 | } |
184 | 184 |
@@ -14,174 +14,174 @@ |
||
14 | 14 | * @since 3.0.0 |
15 | 15 | */ |
16 | 16 | class ActionScheduler_DataController { |
17 | - /** Action data store class name. */ |
|
18 | - const DATASTORE_CLASS = 'ActionScheduler_DBStore'; |
|
19 | - |
|
20 | - /** Logger data store class name. */ |
|
21 | - const LOGGER_CLASS = 'ActionScheduler_DBLogger'; |
|
22 | - |
|
23 | - /** Migration status option name. */ |
|
24 | - const STATUS_FLAG = 'action_scheduler_migration_status'; |
|
25 | - |
|
26 | - /** Migration status option value. */ |
|
27 | - const STATUS_COMPLETE = 'complete'; |
|
28 | - |
|
29 | - /** Migration minimum required PHP version. */ |
|
30 | - const MIN_PHP_VERSION = '5.5'; |
|
31 | - |
|
32 | - /** @var ActionScheduler_DataController */ |
|
33 | - private static $instance; |
|
34 | - |
|
35 | - /** @var int */ |
|
36 | - private static $sleep_time = 0; |
|
37 | - |
|
38 | - /** @var int */ |
|
39 | - private static $free_ticks = 50; |
|
40 | - |
|
41 | - /** |
|
42 | - * Get a flag indicating whether the migration environment dependencies are met. |
|
43 | - * |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - public static function dependencies_met() { |
|
47 | - $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' ); |
|
48 | - return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Get a flag indicating whether the migration is complete. |
|
53 | - * |
|
54 | - * @return bool Whether the flag has been set marking the migration as complete |
|
55 | - */ |
|
56 | - public static function is_migration_complete() { |
|
57 | - return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Mark the migration as complete. |
|
62 | - */ |
|
63 | - public static function mark_migration_complete() { |
|
64 | - update_option( self::STATUS_FLAG, self::STATUS_COMPLETE ); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Unmark migration when a plugin is de-activated. Will not work in case of silent activation, for example in an update. |
|
69 | - * We do this to mitigate the bug of lost actions which happens if there was an AS 2.x to AS 3.x migration in the past, but that plugin is now |
|
70 | - * deactivated and the site was running on AS 2.x again. |
|
71 | - */ |
|
72 | - public static function mark_migration_incomplete() { |
|
73 | - delete_option( self::STATUS_FLAG ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Set the action store class name. |
|
78 | - * |
|
79 | - * @param string $class Classname of the store class. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public static function set_store_class( $class ) { |
|
84 | - return self::DATASTORE_CLASS; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Set the action logger class name. |
|
89 | - * |
|
90 | - * @param string $class Classname of the logger class. |
|
91 | - * |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public static function set_logger_class( $class ) { |
|
95 | - return self::LOGGER_CLASS; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Set the sleep time in seconds. |
|
100 | - * |
|
101 | - * @param integer $sleep_time The number of seconds to pause before resuming operation. |
|
102 | - */ |
|
103 | - public static function set_sleep_time( $sleep_time ) { |
|
104 | - self::$sleep_time = (int) $sleep_time; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Set the tick count required for freeing memory. |
|
109 | - * |
|
110 | - * @param integer $free_ticks The number of ticks to free memory on. |
|
111 | - */ |
|
112 | - public static function set_free_ticks( $free_ticks ) { |
|
113 | - self::$free_ticks = (int) $free_ticks; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Free memory if conditions are met. |
|
118 | - * |
|
119 | - * @param int $ticks Current tick count. |
|
120 | - */ |
|
121 | - public static function maybe_free_memory( $ticks ) { |
|
122 | - if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) { |
|
123 | - self::free_memory(); |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Reduce memory footprint by clearing the database query and object caches. |
|
129 | - */ |
|
130 | - public static function free_memory() { |
|
131 | - if ( 0 < self::$sleep_time ) { |
|
132 | - /* translators: %d: amount of time */ |
|
133 | - \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) ); |
|
134 | - sleep( self::$sleep_time ); |
|
135 | - } |
|
136 | - |
|
137 | - \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) ); |
|
138 | - |
|
139 | - /** |
|
140 | - * @var $wpdb \wpdb |
|
141 | - * @var $wp_object_cache \WP_Object_Cache |
|
142 | - */ |
|
143 | - global $wpdb, $wp_object_cache; |
|
144 | - |
|
145 | - $wpdb->queries = array(); |
|
146 | - |
|
147 | - if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) { |
|
148 | - return; |
|
149 | - } |
|
150 | - |
|
151 | - $wp_object_cache->group_ops = array(); |
|
152 | - $wp_object_cache->stats = array(); |
|
153 | - $wp_object_cache->memcache_debug = array(); |
|
154 | - $wp_object_cache->cache = array(); |
|
155 | - |
|
156 | - if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) { |
|
157 | - call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * Connect to table datastores if migration is complete. |
|
163 | - * Otherwise, proceed with the migration if the dependencies have been met. |
|
164 | - */ |
|
165 | - public static function init() { |
|
166 | - if ( self::is_migration_complete() ) { |
|
167 | - add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 ); |
|
168 | - add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 ); |
|
169 | - add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) ); |
|
170 | - } elseif ( self::dependencies_met() ) { |
|
171 | - Controller::init(); |
|
172 | - } |
|
173 | - |
|
174 | - add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) ); |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * Singleton factory. |
|
179 | - */ |
|
180 | - public static function instance() { |
|
181 | - if ( ! isset( self::$instance ) ) { |
|
182 | - self::$instance = new static(); |
|
183 | - } |
|
184 | - |
|
185 | - return self::$instance; |
|
186 | - } |
|
17 | + /** Action data store class name. */ |
|
18 | + const DATASTORE_CLASS = 'ActionScheduler_DBStore'; |
|
19 | + |
|
20 | + /** Logger data store class name. */ |
|
21 | + const LOGGER_CLASS = 'ActionScheduler_DBLogger'; |
|
22 | + |
|
23 | + /** Migration status option name. */ |
|
24 | + const STATUS_FLAG = 'action_scheduler_migration_status'; |
|
25 | + |
|
26 | + /** Migration status option value. */ |
|
27 | + const STATUS_COMPLETE = 'complete'; |
|
28 | + |
|
29 | + /** Migration minimum required PHP version. */ |
|
30 | + const MIN_PHP_VERSION = '5.5'; |
|
31 | + |
|
32 | + /** @var ActionScheduler_DataController */ |
|
33 | + private static $instance; |
|
34 | + |
|
35 | + /** @var int */ |
|
36 | + private static $sleep_time = 0; |
|
37 | + |
|
38 | + /** @var int */ |
|
39 | + private static $free_ticks = 50; |
|
40 | + |
|
41 | + /** |
|
42 | + * Get a flag indicating whether the migration environment dependencies are met. |
|
43 | + * |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + public static function dependencies_met() { |
|
47 | + $php_support = version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' ); |
|
48 | + return $php_support && apply_filters( 'action_scheduler_migration_dependencies_met', true ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Get a flag indicating whether the migration is complete. |
|
53 | + * |
|
54 | + * @return bool Whether the flag has been set marking the migration as complete |
|
55 | + */ |
|
56 | + public static function is_migration_complete() { |
|
57 | + return get_option( self::STATUS_FLAG ) === self::STATUS_COMPLETE; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Mark the migration as complete. |
|
62 | + */ |
|
63 | + public static function mark_migration_complete() { |
|
64 | + update_option( self::STATUS_FLAG, self::STATUS_COMPLETE ); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Unmark migration when a plugin is de-activated. Will not work in case of silent activation, for example in an update. |
|
69 | + * We do this to mitigate the bug of lost actions which happens if there was an AS 2.x to AS 3.x migration in the past, but that plugin is now |
|
70 | + * deactivated and the site was running on AS 2.x again. |
|
71 | + */ |
|
72 | + public static function mark_migration_incomplete() { |
|
73 | + delete_option( self::STATUS_FLAG ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Set the action store class name. |
|
78 | + * |
|
79 | + * @param string $class Classname of the store class. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public static function set_store_class( $class ) { |
|
84 | + return self::DATASTORE_CLASS; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Set the action logger class name. |
|
89 | + * |
|
90 | + * @param string $class Classname of the logger class. |
|
91 | + * |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public static function set_logger_class( $class ) { |
|
95 | + return self::LOGGER_CLASS; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Set the sleep time in seconds. |
|
100 | + * |
|
101 | + * @param integer $sleep_time The number of seconds to pause before resuming operation. |
|
102 | + */ |
|
103 | + public static function set_sleep_time( $sleep_time ) { |
|
104 | + self::$sleep_time = (int) $sleep_time; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Set the tick count required for freeing memory. |
|
109 | + * |
|
110 | + * @param integer $free_ticks The number of ticks to free memory on. |
|
111 | + */ |
|
112 | + public static function set_free_ticks( $free_ticks ) { |
|
113 | + self::$free_ticks = (int) $free_ticks; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Free memory if conditions are met. |
|
118 | + * |
|
119 | + * @param int $ticks Current tick count. |
|
120 | + */ |
|
121 | + public static function maybe_free_memory( $ticks ) { |
|
122 | + if ( self::$free_ticks && 0 === $ticks % self::$free_ticks ) { |
|
123 | + self::free_memory(); |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Reduce memory footprint by clearing the database query and object caches. |
|
129 | + */ |
|
130 | + public static function free_memory() { |
|
131 | + if ( 0 < self::$sleep_time ) { |
|
132 | + /* translators: %d: amount of time */ |
|
133 | + \WP_CLI::warning( sprintf( _n( 'Stopped the insanity for %d second', 'Stopped the insanity for %d seconds', self::$sleep_time, 'action-scheduler' ), self::$sleep_time ) ); |
|
134 | + sleep( self::$sleep_time ); |
|
135 | + } |
|
136 | + |
|
137 | + \WP_CLI::warning( __( 'Attempting to reduce used memory...', 'action-scheduler' ) ); |
|
138 | + |
|
139 | + /** |
|
140 | + * @var $wpdb \wpdb |
|
141 | + * @var $wp_object_cache \WP_Object_Cache |
|
142 | + */ |
|
143 | + global $wpdb, $wp_object_cache; |
|
144 | + |
|
145 | + $wpdb->queries = array(); |
|
146 | + |
|
147 | + if ( ! is_a( $wp_object_cache, 'WP_Object_Cache' ) ) { |
|
148 | + return; |
|
149 | + } |
|
150 | + |
|
151 | + $wp_object_cache->group_ops = array(); |
|
152 | + $wp_object_cache->stats = array(); |
|
153 | + $wp_object_cache->memcache_debug = array(); |
|
154 | + $wp_object_cache->cache = array(); |
|
155 | + |
|
156 | + if ( is_callable( array( $wp_object_cache, '__remoteset' ) ) ) { |
|
157 | + call_user_func( array( $wp_object_cache, '__remoteset' ) ); // important |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * Connect to table datastores if migration is complete. |
|
163 | + * Otherwise, proceed with the migration if the dependencies have been met. |
|
164 | + */ |
|
165 | + public static function init() { |
|
166 | + if ( self::is_migration_complete() ) { |
|
167 | + add_filter( 'action_scheduler_store_class', array( 'ActionScheduler_DataController', 'set_store_class' ), 100 ); |
|
168 | + add_filter( 'action_scheduler_logger_class', array( 'ActionScheduler_DataController', 'set_logger_class' ), 100 ); |
|
169 | + add_action( 'deactivate_plugin', array( 'ActionScheduler_DataController', 'mark_migration_incomplete' ) ); |
|
170 | + } elseif ( self::dependencies_met() ) { |
|
171 | + Controller::init(); |
|
172 | + } |
|
173 | + |
|
174 | + add_action( 'action_scheduler/progress_tick', array( 'ActionScheduler_DataController', 'maybe_free_memory' ) ); |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * Singleton factory. |
|
179 | + */ |
|
180 | + public static function instance() { |
|
181 | + if ( ! isset( self::$instance ) ) { |
|
182 | + self::$instance = new static(); |
|
183 | + } |
|
184 | + |
|
185 | + return self::$instance; |
|
186 | + } |
|
187 | 187 | } |
@@ -14,178 +14,178 @@ |
||
14 | 14 | |
15 | 15 | if ( ! class_exists( 'WP_Async_Request' ) ) { |
16 | 16 | |
17 | - /** |
|
18 | - * Abstract WP_Async_Request class. |
|
19 | - * |
|
20 | - * @abstract |
|
21 | - */ |
|
22 | - abstract class WP_Async_Request { |
|
23 | - |
|
24 | - /** |
|
25 | - * Prefix |
|
26 | - * |
|
27 | - * (default value: 'wp') |
|
28 | - * |
|
29 | - * @var string |
|
30 | - * @access protected |
|
31 | - */ |
|
32 | - protected $prefix = 'wp'; |
|
33 | - |
|
34 | - /** |
|
35 | - * Action |
|
36 | - * |
|
37 | - * (default value: 'async_request') |
|
38 | - * |
|
39 | - * @var string |
|
40 | - * @access protected |
|
41 | - */ |
|
42 | - protected $action = 'async_request'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Identifier |
|
46 | - * |
|
47 | - * @var mixed |
|
48 | - * @access protected |
|
49 | - */ |
|
50 | - protected $identifier; |
|
51 | - |
|
52 | - /** |
|
53 | - * Data |
|
54 | - * |
|
55 | - * (default value: array()) |
|
56 | - * |
|
57 | - * @var array |
|
58 | - * @access protected |
|
59 | - */ |
|
60 | - protected $data = array(); |
|
61 | - |
|
62 | - /** |
|
63 | - * Initiate new async request |
|
64 | - */ |
|
65 | - public function __construct() { |
|
66 | - $this->identifier = $this->prefix . '_' . $this->action; |
|
67 | - |
|
68 | - add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
69 | - add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Set data used during the request |
|
74 | - * |
|
75 | - * @param array $data Data. |
|
76 | - * |
|
77 | - * @return $this |
|
78 | - */ |
|
79 | - public function data( $data ) { |
|
80 | - $this->data = $data; |
|
81 | - |
|
82 | - return $this; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Dispatch the async request |
|
87 | - * |
|
88 | - * @return array|WP_Error |
|
89 | - */ |
|
90 | - public function dispatch() { |
|
91 | - $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
|
92 | - $args = $this->get_post_args(); |
|
93 | - |
|
94 | - return wp_remote_post( esc_url_raw( $url ), $args ); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get query args |
|
99 | - * |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - protected function get_query_args() { |
|
103 | - if ( property_exists( $this, 'query_args' ) ) { |
|
104 | - return $this->query_args; |
|
105 | - } |
|
106 | - |
|
107 | - $args = array( |
|
108 | - 'action' => $this->identifier, |
|
109 | - 'nonce' => wp_create_nonce( $this->identifier ), |
|
110 | - ); |
|
111 | - |
|
112 | - /** |
|
113 | - * Filters the post arguments used during an async request. |
|
114 | - * |
|
115 | - * @param array $url |
|
116 | - */ |
|
117 | - return apply_filters( $this->identifier . '_query_args', $args ); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Get query URL |
|
122 | - * |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - protected function get_query_url() { |
|
126 | - if ( property_exists( $this, 'query_url' ) ) { |
|
127 | - return $this->query_url; |
|
128 | - } |
|
129 | - |
|
130 | - $url = admin_url( 'admin-ajax.php' ); |
|
131 | - |
|
132 | - /** |
|
133 | - * Filters the post arguments used during an async request. |
|
134 | - * |
|
135 | - * @param string $url |
|
136 | - */ |
|
137 | - return apply_filters( $this->identifier . '_query_url', $url ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Get post args |
|
142 | - * |
|
143 | - * @return array |
|
144 | - */ |
|
145 | - protected function get_post_args() { |
|
146 | - if ( property_exists( $this, 'post_args' ) ) { |
|
147 | - return $this->post_args; |
|
148 | - } |
|
149 | - |
|
150 | - $args = array( |
|
151 | - 'timeout' => 0.01, |
|
152 | - 'blocking' => false, |
|
153 | - 'body' => $this->data, |
|
154 | - 'cookies' => $_COOKIE, |
|
155 | - 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
|
156 | - ); |
|
157 | - |
|
158 | - /** |
|
159 | - * Filters the post arguments used during an async request. |
|
160 | - * |
|
161 | - * @param array $args |
|
162 | - */ |
|
163 | - return apply_filters( $this->identifier . '_post_args', $args ); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Maybe handle |
|
168 | - * |
|
169 | - * Check for correct nonce and pass to handler. |
|
170 | - */ |
|
171 | - public function maybe_handle() { |
|
172 | - // Don't lock up other requests while processing |
|
173 | - session_write_close(); |
|
174 | - |
|
175 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
176 | - |
|
177 | - $this->handle(); |
|
178 | - |
|
179 | - wp_die(); |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Handle |
|
184 | - * |
|
185 | - * Override this method to perform any actions required |
|
186 | - * during the async request. |
|
187 | - */ |
|
188 | - abstract protected function handle(); |
|
189 | - |
|
190 | - } |
|
17 | + /** |
|
18 | + * Abstract WP_Async_Request class. |
|
19 | + * |
|
20 | + * @abstract |
|
21 | + */ |
|
22 | + abstract class WP_Async_Request { |
|
23 | + |
|
24 | + /** |
|
25 | + * Prefix |
|
26 | + * |
|
27 | + * (default value: 'wp') |
|
28 | + * |
|
29 | + * @var string |
|
30 | + * @access protected |
|
31 | + */ |
|
32 | + protected $prefix = 'wp'; |
|
33 | + |
|
34 | + /** |
|
35 | + * Action |
|
36 | + * |
|
37 | + * (default value: 'async_request') |
|
38 | + * |
|
39 | + * @var string |
|
40 | + * @access protected |
|
41 | + */ |
|
42 | + protected $action = 'async_request'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Identifier |
|
46 | + * |
|
47 | + * @var mixed |
|
48 | + * @access protected |
|
49 | + */ |
|
50 | + protected $identifier; |
|
51 | + |
|
52 | + /** |
|
53 | + * Data |
|
54 | + * |
|
55 | + * (default value: array()) |
|
56 | + * |
|
57 | + * @var array |
|
58 | + * @access protected |
|
59 | + */ |
|
60 | + protected $data = array(); |
|
61 | + |
|
62 | + /** |
|
63 | + * Initiate new async request |
|
64 | + */ |
|
65 | + public function __construct() { |
|
66 | + $this->identifier = $this->prefix . '_' . $this->action; |
|
67 | + |
|
68 | + add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
69 | + add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Set data used during the request |
|
74 | + * |
|
75 | + * @param array $data Data. |
|
76 | + * |
|
77 | + * @return $this |
|
78 | + */ |
|
79 | + public function data( $data ) { |
|
80 | + $this->data = $data; |
|
81 | + |
|
82 | + return $this; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Dispatch the async request |
|
87 | + * |
|
88 | + * @return array|WP_Error |
|
89 | + */ |
|
90 | + public function dispatch() { |
|
91 | + $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
|
92 | + $args = $this->get_post_args(); |
|
93 | + |
|
94 | + return wp_remote_post( esc_url_raw( $url ), $args ); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get query args |
|
99 | + * |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + protected function get_query_args() { |
|
103 | + if ( property_exists( $this, 'query_args' ) ) { |
|
104 | + return $this->query_args; |
|
105 | + } |
|
106 | + |
|
107 | + $args = array( |
|
108 | + 'action' => $this->identifier, |
|
109 | + 'nonce' => wp_create_nonce( $this->identifier ), |
|
110 | + ); |
|
111 | + |
|
112 | + /** |
|
113 | + * Filters the post arguments used during an async request. |
|
114 | + * |
|
115 | + * @param array $url |
|
116 | + */ |
|
117 | + return apply_filters( $this->identifier . '_query_args', $args ); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Get query URL |
|
122 | + * |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + protected function get_query_url() { |
|
126 | + if ( property_exists( $this, 'query_url' ) ) { |
|
127 | + return $this->query_url; |
|
128 | + } |
|
129 | + |
|
130 | + $url = admin_url( 'admin-ajax.php' ); |
|
131 | + |
|
132 | + /** |
|
133 | + * Filters the post arguments used during an async request. |
|
134 | + * |
|
135 | + * @param string $url |
|
136 | + */ |
|
137 | + return apply_filters( $this->identifier . '_query_url', $url ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Get post args |
|
142 | + * |
|
143 | + * @return array |
|
144 | + */ |
|
145 | + protected function get_post_args() { |
|
146 | + if ( property_exists( $this, 'post_args' ) ) { |
|
147 | + return $this->post_args; |
|
148 | + } |
|
149 | + |
|
150 | + $args = array( |
|
151 | + 'timeout' => 0.01, |
|
152 | + 'blocking' => false, |
|
153 | + 'body' => $this->data, |
|
154 | + 'cookies' => $_COOKIE, |
|
155 | + 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
|
156 | + ); |
|
157 | + |
|
158 | + /** |
|
159 | + * Filters the post arguments used during an async request. |
|
160 | + * |
|
161 | + * @param array $args |
|
162 | + */ |
|
163 | + return apply_filters( $this->identifier . '_post_args', $args ); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Maybe handle |
|
168 | + * |
|
169 | + * Check for correct nonce and pass to handler. |
|
170 | + */ |
|
171 | + public function maybe_handle() { |
|
172 | + // Don't lock up other requests while processing |
|
173 | + session_write_close(); |
|
174 | + |
|
175 | + check_ajax_referer( $this->identifier, 'nonce' ); |
|
176 | + |
|
177 | + $this->handle(); |
|
178 | + |
|
179 | + wp_die(); |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Handle |
|
184 | + * |
|
185 | + * Override this method to perform any actions required |
|
186 | + * during the async request. |
|
187 | + */ |
|
188 | + abstract protected function handle(); |
|
189 | + |
|
190 | + } |
|
191 | 191 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | License URI: https://github.com/deliciousbrains/wp-background-processing/commit/126d7945dd3d39f39cb6488ca08fe1fb66cb351a |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! class_exists( 'WP_Async_Request' ) ) { |
|
15 | +if ( ! class_exists('WP_Async_Request')) { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Abstract WP_Async_Request class. |
@@ -63,10 +63,10 @@ discard block |
||
63 | 63 | * Initiate new async request |
64 | 64 | */ |
65 | 65 | public function __construct() { |
66 | - $this->identifier = $this->prefix . '_' . $this->action; |
|
66 | + $this->identifier = $this->prefix.'_'.$this->action; |
|
67 | 67 | |
68 | - add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
69 | - add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) ); |
|
68 | + add_action('wp_ajax_'.$this->identifier, array($this, 'maybe_handle')); |
|
69 | + add_action('wp_ajax_nopriv_'.$this->identifier, array($this, 'maybe_handle')); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return $this |
78 | 78 | */ |
79 | - public function data( $data ) { |
|
79 | + public function data($data) { |
|
80 | 80 | $this->data = $data; |
81 | 81 | |
82 | 82 | return $this; |
@@ -88,10 +88,10 @@ discard block |
||
88 | 88 | * @return array|WP_Error |
89 | 89 | */ |
90 | 90 | public function dispatch() { |
91 | - $url = add_query_arg( $this->get_query_args(), $this->get_query_url() ); |
|
91 | + $url = add_query_arg($this->get_query_args(), $this->get_query_url()); |
|
92 | 92 | $args = $this->get_post_args(); |
93 | 93 | |
94 | - return wp_remote_post( esc_url_raw( $url ), $args ); |
|
94 | + return wp_remote_post(esc_url_raw($url), $args); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | * @return array |
101 | 101 | */ |
102 | 102 | protected function get_query_args() { |
103 | - if ( property_exists( $this, 'query_args' ) ) { |
|
103 | + if (property_exists($this, 'query_args')) { |
|
104 | 104 | return $this->query_args; |
105 | 105 | } |
106 | 106 | |
107 | 107 | $args = array( |
108 | 108 | 'action' => $this->identifier, |
109 | - 'nonce' => wp_create_nonce( $this->identifier ), |
|
109 | + 'nonce' => wp_create_nonce($this->identifier), |
|
110 | 110 | ); |
111 | 111 | |
112 | 112 | /** |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @param array $url |
116 | 116 | */ |
117 | - return apply_filters( $this->identifier . '_query_args', $args ); |
|
117 | + return apply_filters($this->identifier.'_query_args', $args); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | /** |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @return string |
124 | 124 | */ |
125 | 125 | protected function get_query_url() { |
126 | - if ( property_exists( $this, 'query_url' ) ) { |
|
126 | + if (property_exists($this, 'query_url')) { |
|
127 | 127 | return $this->query_url; |
128 | 128 | } |
129 | 129 | |
130 | - $url = admin_url( 'admin-ajax.php' ); |
|
130 | + $url = admin_url('admin-ajax.php'); |
|
131 | 131 | |
132 | 132 | /** |
133 | 133 | * Filters the post arguments used during an async request. |
134 | 134 | * |
135 | 135 | * @param string $url |
136 | 136 | */ |
137 | - return apply_filters( $this->identifier . '_query_url', $url ); |
|
137 | + return apply_filters($this->identifier.'_query_url', $url); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @return array |
144 | 144 | */ |
145 | 145 | protected function get_post_args() { |
146 | - if ( property_exists( $this, 'post_args' ) ) { |
|
146 | + if (property_exists($this, 'post_args')) { |
|
147 | 147 | return $this->post_args; |
148 | 148 | } |
149 | 149 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | 'blocking' => false, |
153 | 153 | 'body' => $this->data, |
154 | 154 | 'cookies' => $_COOKIE, |
155 | - 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), |
|
155 | + 'sslverify' => apply_filters('https_local_ssl_verify', false), |
|
156 | 156 | ); |
157 | 157 | |
158 | 158 | /** |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param array $args |
162 | 162 | */ |
163 | - return apply_filters( $this->identifier . '_post_args', $args ); |
|
163 | + return apply_filters($this->identifier.'_post_args', $args); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | // Don't lock up other requests while processing |
173 | 173 | session_write_close(); |
174 | 174 | |
175 | - check_ajax_referer( $this->identifier, 'nonce' ); |
|
175 | + check_ajax_referer($this->identifier, 'nonce'); |
|
176 | 176 | |
177 | 177 | $this->handle(); |
178 | 178 |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | * @return string The job ID |
20 | 20 | */ |
21 | 21 | function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) { |
22 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
23 | - return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
22 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
23 | + return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | * @return string The job ID |
38 | 38 | */ |
39 | 39 | function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
40 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
41 | - return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
40 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
41 | + return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return string The job ID |
66 | 66 | */ |
67 | 67 | function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) { |
68 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
69 | - return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
68 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
69 | + return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | * @deprecated 2.1.0 |
80 | 80 | */ |
81 | 81 | function wc_unschedule_action( $hook, $args = array(), $group = '' ) { |
82 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
83 | - as_unschedule_action( $hook, $args, $group ); |
|
82 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
83 | + as_unschedule_action( $hook, $args, $group ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * @return int|bool The timestamp for the next occurrence, or false if nothing was found |
94 | 94 | */ |
95 | 95 | function wc_next_scheduled_action( $hook, $args = null, $group = '' ) { |
96 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
97 | - return as_next_scheduled_action( $hook, $args, $group ); |
|
96 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
97 | + return as_next_scheduled_action( $hook, $args, $group ); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -121,6 +121,6 @@ discard block |
||
121 | 121 | * @return array |
122 | 122 | */ |
123 | 123 | function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
124 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
125 | - return as_get_scheduled_actions( $args, $return_format ); |
|
124 | + _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
125 | + return as_get_scheduled_actions( $args, $return_format ); |
|
126 | 126 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string The job ID |
20 | 20 | */ |
21 | -function wc_schedule_single_action( $timestamp, $hook, $args = array(), $group = '' ) { |
|
22 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_single_action()' ); |
|
23 | - return as_schedule_single_action( $timestamp, $hook, $args, $group ); |
|
21 | +function wc_schedule_single_action($timestamp, $hook, $args = array(), $group = '') { |
|
22 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_single_action()'); |
|
23 | + return as_schedule_single_action($timestamp, $hook, $args, $group); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return string The job ID |
38 | 38 | */ |
39 | -function wc_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args = array(), $group = '' ) { |
|
40 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_recurring_action()' ); |
|
41 | - return as_schedule_recurring_action( $timestamp, $interval_in_seconds, $hook, $args, $group ); |
|
39 | +function wc_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args = array(), $group = '') { |
|
40 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_recurring_action()'); |
|
41 | + return as_schedule_recurring_action($timestamp, $interval_in_seconds, $hook, $args, $group); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string The job ID |
66 | 66 | */ |
67 | -function wc_schedule_cron_action( $timestamp, $schedule, $hook, $args = array(), $group = '' ) { |
|
68 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_schedule_cron_action()' ); |
|
69 | - return as_schedule_cron_action( $timestamp, $schedule, $hook, $args, $group ); |
|
67 | +function wc_schedule_cron_action($timestamp, $schedule, $hook, $args = array(), $group = '') { |
|
68 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_schedule_cron_action()'); |
|
69 | + return as_schedule_cron_action($timestamp, $schedule, $hook, $args, $group); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -78,9 +78,9 @@ discard block |
||
78 | 78 | * |
79 | 79 | * @deprecated 2.1.0 |
80 | 80 | */ |
81 | -function wc_unschedule_action( $hook, $args = array(), $group = '' ) { |
|
82 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_unschedule_action()' ); |
|
83 | - as_unschedule_action( $hook, $args, $group ); |
|
81 | +function wc_unschedule_action($hook, $args = array(), $group = '') { |
|
82 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_unschedule_action()'); |
|
83 | + as_unschedule_action($hook, $args, $group); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return int|bool The timestamp for the next occurrence, or false if nothing was found |
94 | 94 | */ |
95 | -function wc_next_scheduled_action( $hook, $args = null, $group = '' ) { |
|
96 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_next_scheduled_action()' ); |
|
97 | - return as_next_scheduled_action( $hook, $args, $group ); |
|
95 | +function wc_next_scheduled_action($hook, $args = null, $group = '') { |
|
96 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_next_scheduled_action()'); |
|
97 | + return as_next_scheduled_action($hook, $args, $group); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | * |
121 | 121 | * @return array |
122 | 122 | */ |
123 | -function wc_get_scheduled_actions( $args = array(), $return_format = OBJECT ) { |
|
124 | - _deprecated_function( __FUNCTION__, '2.1.0', 'as_get_scheduled_actions()' ); |
|
125 | - return as_get_scheduled_actions( $args, $return_format ); |
|
123 | +function wc_get_scheduled_actions($args = array(), $return_format = OBJECT) { |
|
124 | + _deprecated_function(__FUNCTION__, '2.1.0', 'as_get_scheduled_actions()'); |
|
125 | + return as_get_scheduled_actions($args, $return_format); |
|
126 | 126 | } |
@@ -10,138 +10,138 @@ |
||
10 | 10 | */ |
11 | 11 | class ActionScheduler_AdminView_Deprecated { |
12 | 12 | |
13 | - public function action_scheduler_post_type_args( $args ) { |
|
14 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
15 | - return $args; |
|
16 | - } |
|
13 | + public function action_scheduler_post_type_args( $args ) { |
|
14 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
15 | + return $args; |
|
16 | + } |
|
17 | 17 | |
18 | - /** |
|
19 | - * Customise the post status related views displayed on the Scheduled Actions administration screen. |
|
20 | - * |
|
21 | - * @param array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
|
22 | - * @return array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
|
23 | - */ |
|
24 | - public function list_table_views( $views ) { |
|
25 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
26 | - return $views; |
|
27 | - } |
|
18 | + /** |
|
19 | + * Customise the post status related views displayed on the Scheduled Actions administration screen. |
|
20 | + * |
|
21 | + * @param array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
|
22 | + * @return array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
|
23 | + */ |
|
24 | + public function list_table_views( $views ) { |
|
25 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
26 | + return $views; |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * Do not include the "Edit" action for the Scheduled Actions administration screen. |
|
31 | - * |
|
32 | - * Hooked to the 'bulk_actions-edit-action-scheduler' filter. |
|
33 | - * |
|
34 | - * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
35 | - * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
36 | - */ |
|
37 | - public function bulk_actions( $actions ) { |
|
38 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
39 | - return $actions; |
|
40 | - } |
|
29 | + /** |
|
30 | + * Do not include the "Edit" action for the Scheduled Actions administration screen. |
|
31 | + * |
|
32 | + * Hooked to the 'bulk_actions-edit-action-scheduler' filter. |
|
33 | + * |
|
34 | + * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
35 | + * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
36 | + */ |
|
37 | + public function bulk_actions( $actions ) { |
|
38 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
39 | + return $actions; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Completely customer the columns displayed on the Scheduled Actions administration screen. |
|
44 | - * |
|
45 | - * Because we can't filter the content of the default title and date columns, we need to recreate our own |
|
46 | - * custom columns for displaying those post fields. For the column content, @see self::list_table_column_content(). |
|
47 | - * |
|
48 | - * @param array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
|
49 | - * @return array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
|
50 | - */ |
|
51 | - public function list_table_columns( $columns ) { |
|
52 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
53 | - return $columns; |
|
54 | - } |
|
42 | + /** |
|
43 | + * Completely customer the columns displayed on the Scheduled Actions administration screen. |
|
44 | + * |
|
45 | + * Because we can't filter the content of the default title and date columns, we need to recreate our own |
|
46 | + * custom columns for displaying those post fields. For the column content, @see self::list_table_column_content(). |
|
47 | + * |
|
48 | + * @param array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
|
49 | + * @return array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
|
50 | + */ |
|
51 | + public function list_table_columns( $columns ) { |
|
52 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
53 | + return $columns; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Make our custom title & date columns use defaulting title & date sorting. |
|
58 | - * |
|
59 | - * @param array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
|
60 | - * @return array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
|
61 | - */ |
|
62 | - public static function list_table_sortable_columns( $columns ) { |
|
63 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
64 | - return $columns; |
|
65 | - } |
|
56 | + /** |
|
57 | + * Make our custom title & date columns use defaulting title & date sorting. |
|
58 | + * |
|
59 | + * @param array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
|
60 | + * @return array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
|
61 | + */ |
|
62 | + public static function list_table_sortable_columns( $columns ) { |
|
63 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
64 | + return $columns; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Print the content for our custom columns. |
|
69 | - * |
|
70 | - * @param string $column_name The key for the column for which we should output our content. |
|
71 | - * @param int $post_id The ID of the 'scheduled-action' post for which this row relates. |
|
72 | - */ |
|
73 | - public static function list_table_column_content( $column_name, $post_id ) { |
|
74 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
75 | - } |
|
67 | + /** |
|
68 | + * Print the content for our custom columns. |
|
69 | + * |
|
70 | + * @param string $column_name The key for the column for which we should output our content. |
|
71 | + * @param int $post_id The ID of the 'scheduled-action' post for which this row relates. |
|
72 | + */ |
|
73 | + public static function list_table_column_content( $column_name, $post_id ) { |
|
74 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Hide the inline "Edit" action for all 'scheduled-action' posts. |
|
79 | - * |
|
80 | - * Hooked to the 'post_row_actions' filter. |
|
81 | - * |
|
82 | - * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
83 | - * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
84 | - */ |
|
85 | - public static function row_actions( $actions, $post ) { |
|
86 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
87 | - return $actions; |
|
88 | - } |
|
77 | + /** |
|
78 | + * Hide the inline "Edit" action for all 'scheduled-action' posts. |
|
79 | + * |
|
80 | + * Hooked to the 'post_row_actions' filter. |
|
81 | + * |
|
82 | + * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
83 | + * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
|
84 | + */ |
|
85 | + public static function row_actions( $actions, $post ) { |
|
86 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
87 | + return $actions; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Run an action when triggered from the Action Scheduler administration screen. |
|
92 | - * |
|
93 | - * @codeCoverageIgnore |
|
94 | - */ |
|
95 | - public static function maybe_execute_action() { |
|
96 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
97 | - } |
|
90 | + /** |
|
91 | + * Run an action when triggered from the Action Scheduler administration screen. |
|
92 | + * |
|
93 | + * @codeCoverageIgnore |
|
94 | + */ |
|
95 | + public static function maybe_execute_action() { |
|
96 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Convert an interval of seconds into a two part human friendly string. |
|
101 | - * |
|
102 | - * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning |
|
103 | - * even if an action is 1 day and 11 hours away, it will display "1 day". This funciton goes one step |
|
104 | - * further to display two degrees of accuracy. |
|
105 | - * |
|
106 | - * Based on Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ |
|
107 | - * |
|
108 | - * @param int $interval A interval in seconds. |
|
109 | - * @return string A human friendly string representation of the interval. |
|
110 | - */ |
|
111 | - public static function admin_notices() { |
|
112 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
113 | - } |
|
99 | + /** |
|
100 | + * Convert an interval of seconds into a two part human friendly string. |
|
101 | + * |
|
102 | + * The WordPress human_time_diff() function only calculates the time difference to one degree, meaning |
|
103 | + * even if an action is 1 day and 11 hours away, it will display "1 day". This funciton goes one step |
|
104 | + * further to display two degrees of accuracy. |
|
105 | + * |
|
106 | + * Based on Crontrol::interval() function by Edward Dale: https://wordpress.org/plugins/wp-crontrol/ |
|
107 | + * |
|
108 | + * @param int $interval A interval in seconds. |
|
109 | + * @return string A human friendly string representation of the interval. |
|
110 | + */ |
|
111 | + public static function admin_notices() { |
|
112 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Filter search queries to allow searching by Claim ID (i.e. post_password). |
|
117 | - * |
|
118 | - * @param string $orderby MySQL orderby string. |
|
119 | - * @param WP_Query $query Instance of a WP_Query object |
|
120 | - * @return string MySQL orderby string. |
|
121 | - */ |
|
122 | - public function custom_orderby( $orderby, $query ) { |
|
123 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
124 | - } |
|
115 | + /** |
|
116 | + * Filter search queries to allow searching by Claim ID (i.e. post_password). |
|
117 | + * |
|
118 | + * @param string $orderby MySQL orderby string. |
|
119 | + * @param WP_Query $query Instance of a WP_Query object |
|
120 | + * @return string MySQL orderby string. |
|
121 | + */ |
|
122 | + public function custom_orderby( $orderby, $query ) { |
|
123 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Filter search queries to allow searching by Claim ID (i.e. post_password). |
|
128 | - * |
|
129 | - * @param string $search MySQL search string. |
|
130 | - * @param WP_Query $query Instance of a WP_Query object |
|
131 | - * @return string MySQL search string. |
|
132 | - */ |
|
133 | - public function search_post_password( $search, $query ) { |
|
134 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
135 | - } |
|
126 | + /** |
|
127 | + * Filter search queries to allow searching by Claim ID (i.e. post_password). |
|
128 | + * |
|
129 | + * @param string $search MySQL search string. |
|
130 | + * @param WP_Query $query Instance of a WP_Query object |
|
131 | + * @return string MySQL search string. |
|
132 | + */ |
|
133 | + public function search_post_password( $search, $query ) { |
|
134 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Change messages when a scheduled action is updated. |
|
139 | - * |
|
140 | - * @param array $messages |
|
141 | - * @return array |
|
142 | - */ |
|
143 | - public function post_updated_messages( $messages ) { |
|
144 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
145 | - return $messages; |
|
146 | - } |
|
137 | + /** |
|
138 | + * Change messages when a scheduled action is updated. |
|
139 | + * |
|
140 | + * @param array $messages |
|
141 | + * @return array |
|
142 | + */ |
|
143 | + public function post_updated_messages( $messages ) { |
|
144 | + _deprecated_function( __METHOD__, '2.0.0' ); |
|
145 | + return $messages; |
|
146 | + } |
|
147 | 147 | } |
@@ -10,8 +10,8 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ActionScheduler_AdminView_Deprecated { |
12 | 12 | |
13 | - public function action_scheduler_post_type_args( $args ) { |
|
14 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
13 | + public function action_scheduler_post_type_args($args) { |
|
14 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
15 | 15 | return $args; |
16 | 16 | } |
17 | 17 | |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * @param array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
22 | 22 | * @return array $views An associative array of views and view labels which can be used to filter the 'scheduled-action' posts displayed on the Scheduled Actions administration screen. |
23 | 23 | */ |
24 | - public function list_table_views( $views ) { |
|
25 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
24 | + public function list_table_views($views) { |
|
25 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
26 | 26 | return $views; |
27 | 27 | } |
28 | 28 | |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
35 | 35 | * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
36 | 36 | */ |
37 | - public function bulk_actions( $actions ) { |
|
38 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
37 | + public function bulk_actions($actions) { |
|
38 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
39 | 39 | return $actions; |
40 | 40 | } |
41 | 41 | |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | * @param array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
49 | 49 | * @return array $columns An associative array of columns that are use for the table on the Scheduled Actions administration screen. |
50 | 50 | */ |
51 | - public function list_table_columns( $columns ) { |
|
52 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
51 | + public function list_table_columns($columns) { |
|
52 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
53 | 53 | return $columns; |
54 | 54 | } |
55 | 55 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * @param array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
60 | 60 | * @return array $columns An associative array of columns that can be used to sort the table on the Scheduled Actions administration screen. |
61 | 61 | */ |
62 | - public static function list_table_sortable_columns( $columns ) { |
|
63 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
62 | + public static function list_table_sortable_columns($columns) { |
|
63 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
64 | 64 | return $columns; |
65 | 65 | } |
66 | 66 | |
@@ -70,8 +70,8 @@ discard block |
||
70 | 70 | * @param string $column_name The key for the column for which we should output our content. |
71 | 71 | * @param int $post_id The ID of the 'scheduled-action' post for which this row relates. |
72 | 72 | */ |
73 | - public static function list_table_column_content( $column_name, $post_id ) { |
|
74 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
73 | + public static function list_table_column_content($column_name, $post_id) { |
|
74 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @param array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
83 | 83 | * @return array $actions An associative array of actions which can be performed on the 'scheduled-action' post type. |
84 | 84 | */ |
85 | - public static function row_actions( $actions, $post ) { |
|
86 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
85 | + public static function row_actions($actions, $post) { |
|
86 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
87 | 87 | return $actions; |
88 | 88 | } |
89 | 89 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * @codeCoverageIgnore |
94 | 94 | */ |
95 | 95 | public static function maybe_execute_action() { |
96 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
96 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return string A human friendly string representation of the interval. |
110 | 110 | */ |
111 | 111 | public static function admin_notices() { |
112 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
112 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param WP_Query $query Instance of a WP_Query object |
120 | 120 | * @return string MySQL orderby string. |
121 | 121 | */ |
122 | - public function custom_orderby( $orderby, $query ) { |
|
123 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
122 | + public function custom_orderby($orderby, $query) { |
|
123 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @param WP_Query $query Instance of a WP_Query object |
131 | 131 | * @return string MySQL search string. |
132 | 132 | */ |
133 | - public function search_post_password( $search, $query ) { |
|
134 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
133 | + public function search_post_password($search, $query) { |
|
134 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | * @param array $messages |
141 | 141 | * @return array |
142 | 142 | */ |
143 | - public function post_updated_messages( $messages ) { |
|
144 | - _deprecated_function( __METHOD__, '2.0.0' ); |
|
143 | + public function post_updated_messages($messages) { |
|
144 | + _deprecated_function(__METHOD__, '2.0.0'); |
|
145 | 145 | return $messages; |
146 | 146 | } |
147 | 147 | } |