@@ -6,44 +6,44 @@ |
||
6 | 6 | */ |
7 | 7 | abstract class ActionScheduler_Store_Deprecated { |
8 | 8 | |
9 | - /** |
|
10 | - * Mark an action that failed to fetch correctly as failed. |
|
11 | - * |
|
12 | - * @since 2.2.6 |
|
13 | - * |
|
14 | - * @param int $action_id The ID of the action. |
|
15 | - */ |
|
16 | - public function mark_failed_fetch_action( $action_id ) { |
|
17 | - _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | - self::$store->mark_failure( $action_id ); |
|
19 | - } |
|
9 | + /** |
|
10 | + * Mark an action that failed to fetch correctly as failed. |
|
11 | + * |
|
12 | + * @since 2.2.6 |
|
13 | + * |
|
14 | + * @param int $action_id The ID of the action. |
|
15 | + */ |
|
16 | + public function mark_failed_fetch_action( $action_id ) { |
|
17 | + _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | + self::$store->mark_failure( $action_id ); |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Add base hooks |
|
23 | - * |
|
24 | - * @since 2.2.6 |
|
25 | - */ |
|
26 | - protected static function hook() { |
|
27 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
28 | - } |
|
21 | + /** |
|
22 | + * Add base hooks |
|
23 | + * |
|
24 | + * @since 2.2.6 |
|
25 | + */ |
|
26 | + protected static function hook() { |
|
27 | + _deprecated_function( __METHOD__, '3.0.0' ); |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Remove base hooks |
|
32 | - * |
|
33 | - * @since 2.2.6 |
|
34 | - */ |
|
35 | - protected static function unhook() { |
|
36 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
37 | - } |
|
30 | + /** |
|
31 | + * Remove base hooks |
|
32 | + * |
|
33 | + * @since 2.2.6 |
|
34 | + */ |
|
35 | + protected static function unhook() { |
|
36 | + _deprecated_function( __METHOD__, '3.0.0' ); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Get the site's local time. |
|
41 | - * |
|
42 | - * @deprecated 2.1.0 |
|
43 | - * @return DateTimeZone |
|
44 | - */ |
|
45 | - protected function get_local_timezone() { |
|
46 | - _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
47 | - return ActionScheduler_TimezoneHelper::get_local_timezone(); |
|
48 | - } |
|
39 | + /** |
|
40 | + * Get the site's local time. |
|
41 | + * |
|
42 | + * @deprecated 2.1.0 |
|
43 | + * @return DateTimeZone |
|
44 | + */ |
|
45 | + protected function get_local_timezone() { |
|
46 | + _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
47 | + return ActionScheduler_TimezoneHelper::get_local_timezone(); |
|
48 | + } |
|
49 | 49 | } |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @param int $action_id The ID of the action. |
15 | 15 | */ |
16 | - public function mark_failed_fetch_action( $action_id ) { |
|
17 | - _deprecated_function( __METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()' ); |
|
18 | - self::$store->mark_failure( $action_id ); |
|
16 | + public function mark_failed_fetch_action($action_id) { |
|
17 | + _deprecated_function(__METHOD__, '3.0.0', 'ActionScheduler_Store::mark_failure()'); |
|
18 | + self::$store->mark_failure($action_id); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @since 2.2.6 |
25 | 25 | */ |
26 | 26 | protected static function hook() { |
27 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
27 | + _deprecated_function(__METHOD__, '3.0.0'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @since 2.2.6 |
34 | 34 | */ |
35 | 35 | protected static function unhook() { |
36 | - _deprecated_function( __METHOD__, '3.0.0' ); |
|
36 | + _deprecated_function(__METHOD__, '3.0.0'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @return DateTimeZone |
44 | 44 | */ |
45 | 45 | protected function get_local_timezone() { |
46 | - _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
|
46 | + _deprecated_function(__FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()'); |
|
47 | 47 | return ActionScheduler_TimezoneHelper::get_local_timezone(); |
48 | 48 | } |
49 | 49 | } |
@@ -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 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | * |
11 | 11 | * @param null $date The date & time to run the action. |
12 | 12 | */ |
13 | - public function __construct( DateTime $date = null ) { |
|
13 | + public function __construct(DateTime $date = null) { |
|
14 | 14 | $this->scheduled_date = null; |
15 | 15 | } |
16 | 16 |
@@ -5,25 +5,25 @@ |
||
5 | 5 | */ |
6 | 6 | class ActionScheduler_NullSchedule extends ActionScheduler_SimpleSchedule { |
7 | 7 | |
8 | - /** |
|
9 | - * Make the $date param optional and default to null. |
|
10 | - * |
|
11 | - * @param null $date The date & time to run the action. |
|
12 | - */ |
|
13 | - public function __construct( DateTime $date = null ) { |
|
14 | - $this->scheduled_date = null; |
|
15 | - } |
|
8 | + /** |
|
9 | + * Make the $date param optional and default to null. |
|
10 | + * |
|
11 | + * @param null $date The date & time to run the action. |
|
12 | + */ |
|
13 | + public function __construct( DateTime $date = null ) { |
|
14 | + $this->scheduled_date = null; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * This schedule has no scheduled DateTime, so we need to override the parent __sleep() |
|
19 | - * |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public function __sleep() { |
|
23 | - return array(); |
|
24 | - } |
|
17 | + /** |
|
18 | + * This schedule has no scheduled DateTime, so we need to override the parent __sleep() |
|
19 | + * |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public function __sleep() { |
|
23 | + return array(); |
|
24 | + } |
|
25 | 25 | |
26 | - public function __wakeup() { |
|
27 | - $this->scheduled_date = null; |
|
28 | - } |
|
26 | + public function __wakeup() { |
|
27 | + $this->scheduled_date = null; |
|
28 | + } |
|
29 | 29 | } |
@@ -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; |
@@ -15,35 +15,35 @@ |
||
15 | 15 | * @codeCoverageIgnore |
16 | 16 | */ |
17 | 17 | class LogMigrator { |
18 | - /** @var ActionScheduler_Logger */ |
|
19 | - private $source; |
|
18 | + /** @var ActionScheduler_Logger */ |
|
19 | + private $source; |
|
20 | 20 | |
21 | - /** @var ActionScheduler_Logger */ |
|
22 | - private $destination; |
|
21 | + /** @var ActionScheduler_Logger */ |
|
22 | + private $destination; |
|
23 | 23 | |
24 | - /** |
|
25 | - * ActionMigrator constructor. |
|
26 | - * |
|
27 | - * @param ActionScheduler_Logger $source_logger Source logger object. |
|
28 | - * @param ActionScheduler_Logger $destination_Logger Destination logger object. |
|
29 | - */ |
|
30 | - public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) { |
|
31 | - $this->source = $source_logger; |
|
32 | - $this->destination = $destination_Logger; |
|
33 | - } |
|
24 | + /** |
|
25 | + * ActionMigrator constructor. |
|
26 | + * |
|
27 | + * @param ActionScheduler_Logger $source_logger Source logger object. |
|
28 | + * @param ActionScheduler_Logger $destination_Logger Destination logger object. |
|
29 | + */ |
|
30 | + public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) { |
|
31 | + $this->source = $source_logger; |
|
32 | + $this->destination = $destination_Logger; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Migrate an action log. |
|
37 | - * |
|
38 | - * @param int $source_action_id Source logger object. |
|
39 | - * @param int $destination_action_id Destination logger object. |
|
40 | - */ |
|
41 | - public function migrate( $source_action_id, $destination_action_id ) { |
|
42 | - $logs = $this->source->get_logs( $source_action_id ); |
|
43 | - foreach ( $logs as $log ) { |
|
44 | - if ( $log->get_action_id() == $source_action_id ) { |
|
45 | - $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
35 | + /** |
|
36 | + * Migrate an action log. |
|
37 | + * |
|
38 | + * @param int $source_action_id Source logger object. |
|
39 | + * @param int $destination_action_id Destination logger object. |
|
40 | + */ |
|
41 | + public function migrate( $source_action_id, $destination_action_id ) { |
|
42 | + $logs = $this->source->get_logs( $source_action_id ); |
|
43 | + foreach ( $logs as $log ) { |
|
44 | + if ( $log->get_action_id() == $source_action_id ) { |
|
45 | + $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * @param ActionScheduler_Logger $source_logger Source logger object. |
28 | 28 | * @param ActionScheduler_Logger $destination_Logger Destination logger object. |
29 | 29 | */ |
30 | - public function __construct( ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger ) { |
|
30 | + public function __construct(ActionScheduler_Logger $source_logger, ActionScheduler_Logger $destination_Logger) { |
|
31 | 31 | $this->source = $source_logger; |
32 | 32 | $this->destination = $destination_Logger; |
33 | 33 | } |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * @param int $source_action_id Source logger object. |
39 | 39 | * @param int $destination_action_id Destination logger object. |
40 | 40 | */ |
41 | - public function migrate( $source_action_id, $destination_action_id ) { |
|
42 | - $logs = $this->source->get_logs( $source_action_id ); |
|
43 | - foreach ( $logs as $log ) { |
|
44 | - if ( $log->get_action_id() == $source_action_id ) { |
|
45 | - $this->destination->log( $destination_action_id, $log->get_message(), $log->get_date() ); |
|
41 | + public function migrate($source_action_id, $destination_action_id) { |
|
42 | + $logs = $this->source->get_logs($source_action_id); |
|
43 | + foreach ($logs as $log) { |
|
44 | + if ($log->get_action_id() == $source_action_id) { |
|
45 | + $this->destination->log($destination_action_id, $log->get_message(), $log->get_date()); |
|
46 | 46 | } |
47 | 47 | } |
48 | 48 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |