@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -9,41 +9,41 @@ |
||
| 9 | 9 | */ |
| 10 | 10 | class ActionScheduler_OptionLock extends ActionScheduler_Lock { |
| 11 | 11 | |
| 12 | - /** |
|
| 13 | - * Set a lock using options for a given amount of time (60 seconds by default). |
|
| 14 | - * |
|
| 15 | - * Using an autoloaded option avoids running database queries or other resource intensive tasks |
|
| 16 | - * on frequently triggered hooks, like 'init' or 'shutdown'. |
|
| 17 | - * |
|
| 18 | - * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid |
|
| 19 | - * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', |
|
| 20 | - * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() |
|
| 21 | - * to find the current number of claims in the database. |
|
| 22 | - * |
|
| 23 | - * @param string $lock_type A string to identify different lock types. |
|
| 24 | - * @bool True if lock value has changed, false if not or if set failed. |
|
| 25 | - */ |
|
| 26 | - public function set( $lock_type ) { |
|
| 27 | - return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
| 28 | - } |
|
| 12 | + /** |
|
| 13 | + * Set a lock using options for a given amount of time (60 seconds by default). |
|
| 14 | + * |
|
| 15 | + * Using an autoloaded option avoids running database queries or other resource intensive tasks |
|
| 16 | + * on frequently triggered hooks, like 'init' or 'shutdown'. |
|
| 17 | + * |
|
| 18 | + * For example, ActionScheduler_QueueRunner->maybe_dispatch_async_request() uses a lock to avoid |
|
| 19 | + * calling ActionScheduler_QueueRunner->has_maximum_concurrent_batches() every time the 'shutdown', |
|
| 20 | + * hook is triggered, because that method calls ActionScheduler_QueueRunner->store->get_claim_count() |
|
| 21 | + * to find the current number of claims in the database. |
|
| 22 | + * |
|
| 23 | + * @param string $lock_type A string to identify different lock types. |
|
| 24 | + * @bool True if lock value has changed, false if not or if set failed. |
|
| 25 | + */ |
|
| 26 | + public function set( $lock_type ) { |
|
| 27 | + return update_option( $this->get_key( $lock_type ), time() + $this->get_duration( $lock_type ) ); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * If a lock is set, return the timestamp it was set to expiry. |
|
| 32 | - * |
|
| 33 | - * @param string $lock_type A string to identify different lock types. |
|
| 34 | - * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
| 35 | - */ |
|
| 36 | - public function get_expiration( $lock_type ) { |
|
| 37 | - return get_option( $this->get_key( $lock_type ) ); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * If a lock is set, return the timestamp it was set to expiry. |
|
| 32 | + * |
|
| 33 | + * @param string $lock_type A string to identify different lock types. |
|
| 34 | + * @return bool|int False if no lock is set, otherwise the timestamp for when the lock is set to expire. |
|
| 35 | + */ |
|
| 36 | + public function get_expiration( $lock_type ) { |
|
| 37 | + return get_option( $this->get_key( $lock_type ) ); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Get the key to use for storing the lock in the transient |
|
| 42 | - * |
|
| 43 | - * @param string $lock_type A string to identify different lock types. |
|
| 44 | - * @return string |
|
| 45 | - */ |
|
| 46 | - protected function get_key( $lock_type ) { |
|
| 47 | - return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * Get the key to use for storing the lock in the transient |
|
| 42 | + * |
|
| 43 | + * @param string $lock_type A string to identify different lock types. |
|
| 44 | + * @return string |
|
| 45 | + */ |
|
| 46 | + protected function get_key( $lock_type ) { |
|
| 47 | + return sprintf( 'action_scheduler_lock_%s', $lock_type ); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -15,62 +15,62 @@ |
||
| 15 | 15 | * @group migration |
| 16 | 16 | */ |
| 17 | 17 | class Controller_Test extends ActionScheduler_UnitTestCase { |
| 18 | - /** |
|
| 19 | - * Test to ensure the Migration Controller will schedule the migration. |
|
| 20 | - */ |
|
| 21 | - public function test_schedules_migration() { |
|
| 22 | - as_unschedule_action( Scheduler::HOOK ); |
|
| 23 | - Controller::instance()->schedule_migration(); |
|
| 18 | + /** |
|
| 19 | + * Test to ensure the Migration Controller will schedule the migration. |
|
| 20 | + */ |
|
| 21 | + public function test_schedules_migration() { |
|
| 22 | + as_unschedule_action( Scheduler::HOOK ); |
|
| 23 | + Controller::instance()->schedule_migration(); |
|
| 24 | 24 | |
| 25 | - $this->assertTrue( |
|
| 26 | - as_next_scheduled_action( Scheduler::HOOK ) > 0, |
|
| 27 | - 'Confirm that the Migration Controller scheduled the migration.' |
|
| 28 | - ); |
|
| 25 | + $this->assertTrue( |
|
| 26 | + as_next_scheduled_action( Scheduler::HOOK ) > 0, |
|
| 27 | + 'Confirm that the Migration Controller scheduled the migration.' |
|
| 28 | + ); |
|
| 29 | 29 | |
| 30 | - as_unschedule_action( Scheduler::HOOK ); |
|
| 31 | - } |
|
| 30 | + as_unschedule_action( Scheduler::HOOK ); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Test to ensure that if an essential table is missing, the Migration |
|
| 35 | - * Controller will not schedule a migration. |
|
| 36 | - * |
|
| 37 | - * @see https://github.com/woocommerce/action-scheduler/issues/653 |
|
| 38 | - */ |
|
| 39 | - public function test_migration_not_scheduled_if_tables_are_missing() { |
|
| 40 | - as_unschedule_action( Scheduler::HOOK ); |
|
| 41 | - $this->rename_claims_table(); |
|
| 42 | - Controller::instance()->schedule_migration(); |
|
| 33 | + /** |
|
| 34 | + * Test to ensure that if an essential table is missing, the Migration |
|
| 35 | + * Controller will not schedule a migration. |
|
| 36 | + * |
|
| 37 | + * @see https://github.com/woocommerce/action-scheduler/issues/653 |
|
| 38 | + */ |
|
| 39 | + public function test_migration_not_scheduled_if_tables_are_missing() { |
|
| 40 | + as_unschedule_action( Scheduler::HOOK ); |
|
| 41 | + $this->rename_claims_table(); |
|
| 42 | + Controller::instance()->schedule_migration(); |
|
| 43 | 43 | |
| 44 | - $this->assertFalse( |
|
| 45 | - as_next_scheduled_action( Scheduler::HOOK ), |
|
| 46 | - 'When required tables are missing, the migration will not be scheduled.' |
|
| 47 | - ); |
|
| 44 | + $this->assertFalse( |
|
| 45 | + as_next_scheduled_action( Scheduler::HOOK ), |
|
| 46 | + 'When required tables are missing, the migration will not be scheduled.' |
|
| 47 | + ); |
|
| 48 | 48 | |
| 49 | - $this->restore_claims_table_name(); |
|
| 50 | - } |
|
| 49 | + $this->restore_claims_table_name(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Rename the claims table, so that it cannot be used by the library. |
|
| 54 | - */ |
|
| 55 | - private function rename_claims_table() { |
|
| 56 | - global $wpdb; |
|
| 57 | - $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
| 58 | - $modified_table_name = $normal_table_name . 'x'; |
|
| 52 | + /** |
|
| 53 | + * Rename the claims table, so that it cannot be used by the library. |
|
| 54 | + */ |
|
| 55 | + private function rename_claims_table() { |
|
| 56 | + global $wpdb; |
|
| 57 | + $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
| 58 | + $modified_table_name = $normal_table_name . 'x'; |
|
| 59 | 59 | |
| 60 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 61 | - $wpdb->query( "RENAME TABLE {$normal_table_name} TO {$modified_table_name}" ); |
|
| 62 | - } |
|
| 60 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 61 | + $wpdb->query( "RENAME TABLE {$normal_table_name} TO {$modified_table_name}" ); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Restore the expected name of the claims table, so that it can be used by the library |
|
| 66 | - * and any further tests. |
|
| 67 | - */ |
|
| 68 | - private function restore_claims_table_name() { |
|
| 69 | - global $wpdb; |
|
| 70 | - $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
| 71 | - $modified_table_name = $normal_table_name . 'x'; |
|
| 64 | + /** |
|
| 65 | + * Restore the expected name of the claims table, so that it can be used by the library |
|
| 66 | + * and any further tests. |
|
| 67 | + */ |
|
| 68 | + private function restore_claims_table_name() { |
|
| 69 | + global $wpdb; |
|
| 70 | + $normal_table_name = $wpdb->prefix . Schema::CLAIMS_TABLE; |
|
| 71 | + $modified_table_name = $normal_table_name . 'x'; |
|
| 72 | 72 | |
| 73 | - // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 74 | - $wpdb->query( "RENAME TABLE {$modified_table_name} TO {$normal_table_name}" ); |
|
| 75 | - } |
|
| 73 | + // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
|
| 74 | + $wpdb->query( "RENAME TABLE {$modified_table_name} TO {$normal_table_name}" ); |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -5,41 +5,41 @@ |
||
| 5 | 5 | * @package test_cases\lock |
| 6 | 6 | */ |
| 7 | 7 | class ActionScheduler_OptionLock_Test extends ActionScheduler_UnitTestCase { |
| 8 | - public function test_instance() { |
|
| 9 | - $lock = ActionScheduler::lock(); |
|
| 10 | - $this->assertInstanceOf( 'ActionScheduler_Lock', $lock ); |
|
| 11 | - $this->assertInstanceOf( 'ActionScheduler_OptionLock', $lock ); |
|
| 12 | - } |
|
| 8 | + public function test_instance() { |
|
| 9 | + $lock = ActionScheduler::lock(); |
|
| 10 | + $this->assertInstanceOf( 'ActionScheduler_Lock', $lock ); |
|
| 11 | + $this->assertInstanceOf( 'ActionScheduler_OptionLock', $lock ); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - public function test_is_locked() { |
|
| 15 | - $lock = ActionScheduler::lock(); |
|
| 16 | - $lock_type = md5( rand() ); |
|
| 14 | + public function test_is_locked() { |
|
| 15 | + $lock = ActionScheduler::lock(); |
|
| 16 | + $lock_type = md5( rand() ); |
|
| 17 | 17 | |
| 18 | - $this->assertFalse( $lock->is_locked( $lock_type ) ); |
|
| 18 | + $this->assertFalse( $lock->is_locked( $lock_type ) ); |
|
| 19 | 19 | |
| 20 | - $lock->set( $lock_type ); |
|
| 21 | - $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
| 22 | - } |
|
| 20 | + $lock->set( $lock_type ); |
|
| 21 | + $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - public function test_set() { |
|
| 25 | - $lock = ActionScheduler::lock(); |
|
| 26 | - $lock_type = md5( rand() ); |
|
| 24 | + public function test_set() { |
|
| 25 | + $lock = ActionScheduler::lock(); |
|
| 26 | + $lock_type = md5( rand() ); |
|
| 27 | 27 | |
| 28 | - $lock->set( $lock_type ); |
|
| 29 | - $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
| 30 | - } |
|
| 28 | + $lock->set( $lock_type ); |
|
| 29 | + $this->assertTrue( $lock->is_locked( $lock_type ) ); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function test_get_expiration() { |
|
| 33 | - $lock = ActionScheduler::lock(); |
|
| 34 | - $lock_type = md5( rand() ); |
|
| 32 | + public function test_get_expiration() { |
|
| 33 | + $lock = ActionScheduler::lock(); |
|
| 34 | + $lock_type = md5( rand() ); |
|
| 35 | 35 | |
| 36 | - $lock->set( $lock_type ); |
|
| 36 | + $lock->set( $lock_type ); |
|
| 37 | 37 | |
| 38 | - $expiration = $lock->get_expiration( $lock_type ); |
|
| 39 | - $current_time = time(); |
|
| 38 | + $expiration = $lock->get_expiration( $lock_type ); |
|
| 39 | + $current_time = time(); |
|
| 40 | 40 | |
| 41 | - $this->assertGreaterThanOrEqual( 0, $expiration ); |
|
| 42 | - $this->assertGreaterThan( $current_time, $expiration ); |
|
| 43 | - $this->assertLessThan( $current_time + MINUTE_IN_SECONDS + 1, $expiration ); |
|
| 44 | - } |
|
| 41 | + $this->assertGreaterThanOrEqual( 0, $expiration ); |
|
| 42 | + $this->assertGreaterThan( $current_time, $expiration ); |
|
| 43 | + $this->assertLessThan( $current_time + MINUTE_IN_SECONDS + 1, $expiration ); |
|
| 44 | + } |
|
| 45 | 45 | } |