@@ -15,19 +15,19 @@ discard block |
||
| 15 | 15 | * |
| 16 | 16 | * @subcommand fix-schema |
| 17 | 17 | */ |
| 18 | - public function fix_schema( $args, $assoc_args ) { |
|
| 19 | - $schema_classes = array( ActionScheduler_LoggerSchema::class, ActionScheduler_StoreSchema::class ); |
|
| 18 | + public function fix_schema($args, $assoc_args) { |
|
| 19 | + $schema_classes = array(ActionScheduler_LoggerSchema::class, ActionScheduler_StoreSchema::class); |
|
| 20 | 20 | |
| 21 | - foreach ( $schema_classes as $classname ) { |
|
| 22 | - if ( is_subclass_of( $classname, ActionScheduler_Abstract_Schema::class ) ) { |
|
| 21 | + foreach ($schema_classes as $classname) { |
|
| 22 | + if (is_subclass_of($classname, ActionScheduler_Abstract_Schema::class)) { |
|
| 23 | 23 | $obj = new $classname(); |
| 24 | 24 | $obj->init(); |
| 25 | - $obj->register_tables( true ); |
|
| 25 | + $obj->register_tables(true); |
|
| 26 | 26 | |
| 27 | 27 | WP_CLI::success( |
| 28 | 28 | sprintf( |
| 29 | 29 | /* translators: %s refers to the schema name*/ |
| 30 | - __( 'Registered schema for %s', 'woocommerce' ), |
|
| 30 | + __('Registered schema for %s', 'woocommerce'), |
|
| 31 | 31 | $classname |
| 32 | 32 | ) |
| 33 | 33 | ); |
@@ -70,20 +70,20 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @subcommand run |
| 72 | 72 | */ |
| 73 | - public function run( $args, $assoc_args ) { |
|
| 73 | + public function run($args, $assoc_args) { |
|
| 74 | 74 | // Handle passed arguments. |
| 75 | - $batch = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batch-size', 100 ) ); |
|
| 76 | - $batches = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'batches', 0 ) ); |
|
| 77 | - $clean = absint( \WP_CLI\Utils\get_flag_value( $assoc_args, 'cleanup-batch-size', $batch ) ); |
|
| 78 | - $hooks = explode( ',', WP_CLI\Utils\get_flag_value( $assoc_args, 'hooks', '' ) ); |
|
| 79 | - $hooks = array_filter( array_map( 'trim', $hooks ) ); |
|
| 80 | - $group = \WP_CLI\Utils\get_flag_value( $assoc_args, 'group', '' ); |
|
| 81 | - $free_on = \WP_CLI\Utils\get_flag_value( $assoc_args, 'free-memory-on', 50 ); |
|
| 82 | - $sleep = \WP_CLI\Utils\get_flag_value( $assoc_args, 'pause', 0 ); |
|
| 83 | - $force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force', false ); |
|
| 84 | - |
|
| 85 | - ActionScheduler_DataController::set_free_ticks( $free_on ); |
|
| 86 | - ActionScheduler_DataController::set_sleep_time( $sleep ); |
|
| 75 | + $batch = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'batch-size', 100)); |
|
| 76 | + $batches = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'batches', 0)); |
|
| 77 | + $clean = absint(\WP_CLI\Utils\get_flag_value($assoc_args, 'cleanup-batch-size', $batch)); |
|
| 78 | + $hooks = explode(',', WP_CLI\Utils\get_flag_value($assoc_args, 'hooks', '')); |
|
| 79 | + $hooks = array_filter(array_map('trim', $hooks)); |
|
| 80 | + $group = \WP_CLI\Utils\get_flag_value($assoc_args, 'group', ''); |
|
| 81 | + $free_on = \WP_CLI\Utils\get_flag_value($assoc_args, 'free-memory-on', 50); |
|
| 82 | + $sleep = \WP_CLI\Utils\get_flag_value($assoc_args, 'pause', 0); |
|
| 83 | + $force = \WP_CLI\Utils\get_flag_value($assoc_args, 'force', false); |
|
| 84 | + |
|
| 85 | + ActionScheduler_DataController::set_free_ticks($free_on); |
|
| 86 | + ActionScheduler_DataController::set_sleep_time($sleep); |
|
| 87 | 87 | |
| 88 | 88 | $batches_completed = 0; |
| 89 | 89 | $actions_completed = 0; |
@@ -91,29 +91,29 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | try { |
| 93 | 93 | // Custom queue cleaner instance. |
| 94 | - $cleaner = new ActionScheduler_QueueCleaner( null, $clean ); |
|
| 94 | + $cleaner = new ActionScheduler_QueueCleaner(null, $clean); |
|
| 95 | 95 | |
| 96 | 96 | // Get the queue runner instance |
| 97 | - $runner = new ActionScheduler_WPCLI_QueueRunner( null, null, $cleaner ); |
|
| 97 | + $runner = new ActionScheduler_WPCLI_QueueRunner(null, null, $cleaner); |
|
| 98 | 98 | |
| 99 | 99 | // Determine how many tasks will be run in the first batch. |
| 100 | - $total = $runner->setup( $batch, $hooks, $group, $force ); |
|
| 100 | + $total = $runner->setup($batch, $hooks, $group, $force); |
|
| 101 | 101 | |
| 102 | 102 | // Run actions for as long as possible. |
| 103 | - while ( $total > 0 ) { |
|
| 104 | - $this->print_total_actions( $total ); |
|
| 103 | + while ($total > 0) { |
|
| 104 | + $this->print_total_actions($total); |
|
| 105 | 105 | $actions_completed += $runner->run(); |
| 106 | 106 | $batches_completed++; |
| 107 | 107 | |
| 108 | 108 | // Maybe set up tasks for the next batch. |
| 109 | - $total = ( $unlimited || $batches_completed < $batches ) ? $runner->setup( $batch, $hooks, $group, $force ) : 0; |
|
| 109 | + $total = ($unlimited || $batches_completed < $batches) ? $runner->setup($batch, $hooks, $group, $force) : 0; |
|
| 110 | 110 | } |
| 111 | - } catch ( Exception $e ) { |
|
| 112 | - $this->print_error( $e ); |
|
| 111 | + } catch (Exception $e) { |
|
| 112 | + $this->print_error($e); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $this->print_total_batches( $batches_completed ); |
|
| 116 | - $this->print_success( $actions_completed ); |
|
| 115 | + $this->print_total_batches($batches_completed); |
|
| 116 | + $this->print_success($actions_completed); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -123,12 +123,12 @@ discard block |
||
| 123 | 123 | * |
| 124 | 124 | * @param int $total |
| 125 | 125 | */ |
| 126 | - protected function print_total_actions( $total ) { |
|
| 126 | + protected function print_total_actions($total) { |
|
| 127 | 127 | WP_CLI::log( |
| 128 | 128 | sprintf( |
| 129 | 129 | /* translators: %d refers to how many scheduled taks were found to run */ |
| 130 | - _n( 'Found %d scheduled task', 'Found %d scheduled tasks', $total, 'woocommerce' ), |
|
| 131 | - number_format_i18n( $total ) |
|
| 130 | + _n('Found %d scheduled task', 'Found %d scheduled tasks', $total, 'woocommerce'), |
|
| 131 | + number_format_i18n($total) |
|
| 132 | 132 | ) |
| 133 | 133 | ); |
| 134 | 134 | } |
@@ -140,12 +140,12 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @param int $batches_completed |
| 142 | 142 | */ |
| 143 | - protected function print_total_batches( $batches_completed ) { |
|
| 143 | + protected function print_total_batches($batches_completed) { |
|
| 144 | 144 | WP_CLI::log( |
| 145 | 145 | sprintf( |
| 146 | 146 | /* translators: %d refers to the total number of batches executed */ |
| 147 | - _n( '%d batch executed.', '%d batches executed.', $batches_completed, 'woocommerce' ), |
|
| 148 | - number_format_i18n( $batches_completed ) |
|
| 147 | + _n('%d batch executed.', '%d batches executed.', $batches_completed, 'woocommerce'), |
|
| 148 | + number_format_i18n($batches_completed) |
|
| 149 | 149 | ) |
| 150 | 150 | ); |
| 151 | 151 | } |
@@ -159,11 +159,11 @@ discard block |
||
| 159 | 159 | * |
| 160 | 160 | * @throws \WP_CLI\ExitException |
| 161 | 161 | */ |
| 162 | - protected function print_error( Exception $e ) { |
|
| 162 | + protected function print_error(Exception $e) { |
|
| 163 | 163 | WP_CLI::error( |
| 164 | 164 | sprintf( |
| 165 | 165 | /* translators: %s refers to the exception error message */ |
| 166 | - __( 'There was an error running the action scheduler: %s', 'woocommerce' ), |
|
| 166 | + __('There was an error running the action scheduler: %s', 'woocommerce'), |
|
| 167 | 167 | $e->getMessage() |
| 168 | 168 | ) |
| 169 | 169 | ); |
@@ -176,12 +176,12 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @param int $actions_completed |
| 178 | 178 | */ |
| 179 | - protected function print_success( $actions_completed ) { |
|
| 179 | + protected function print_success($actions_completed) { |
|
| 180 | 180 | WP_CLI::success( |
| 181 | 181 | sprintf( |
| 182 | 182 | /* translators: %d refers to the total number of taskes completed */ |
| 183 | - _n( '%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'woocommerce' ), |
|
| 184 | - number_format_i18n( $actions_completed ) |
|
| 183 | + _n('%d scheduled task completed.', '%d scheduled tasks completed.', $actions_completed, 'woocommerce'), |
|
| 184 | + number_format_i18n($actions_completed) |
|
| 185 | 185 | ) |
| 186 | 186 | ); |
| 187 | 187 | } |
@@ -41,10 +41,10 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @throws Exception When this is not run within WP CLI |
| 43 | 43 | */ |
| 44 | - public function __construct( $message, $count, $interval = 100 ) { |
|
| 45 | - if ( ! ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
| 44 | + public function __construct($message, $count, $interval = 100) { |
|
| 45 | + if (!(defined('WP_CLI') && WP_CLI)) { |
|
| 46 | 46 | /* translators: %s php class name */ |
| 47 | - throw new \Exception( sprintf( __( 'The %s class can only be run within WP CLI.', 'woocommerce' ), __CLASS__ ) ); |
|
| 47 | + throw new \Exception(sprintf(__('The %s class can only be run within WP CLI.', 'woocommerce'), __CLASS__)); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $this->total_ticks = 0; |
@@ -57,14 +57,14 @@ discard block |
||
| 57 | 57 | * Increment the progress bar ticks. |
| 58 | 58 | */ |
| 59 | 59 | public function tick() { |
| 60 | - if ( null === $this->progress_bar ) { |
|
| 60 | + if (null === $this->progress_bar) { |
|
| 61 | 61 | $this->setup_progress_bar(); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $this->progress_bar->tick(); |
| 65 | 65 | $this->total_ticks++; |
| 66 | 66 | |
| 67 | - do_action( 'action_scheduler/progress_tick', $this->total_ticks ); |
|
| 67 | + do_action('action_scheduler/progress_tick', $this->total_ticks); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * Finish the current progress bar. |
| 81 | 81 | */ |
| 82 | 82 | public function finish() { |
| 83 | - if ( null !== $this->progress_bar ) { |
|
| 83 | + if (null !== $this->progress_bar) { |
|
| 84 | 84 | $this->progress_bar->finish(); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * |
| 93 | 93 | * @param string $message The message to be used when the next progress bar is created. |
| 94 | 94 | */ |
| 95 | - public function set_message( $message ) { |
|
| 95 | + public function set_message($message) { |
|
| 96 | 96 | $this->message = $message; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | * @param integer $count The total number of ticks expected to complete. |
| 103 | 103 | */ |
| 104 | - public function set_count( $count ) { |
|
| 104 | + public function set_count($count) { |
|
| 105 | 105 | $this->count = $count; |
| 106 | 106 | $this->finish(); |
| 107 | 107 | } |
@@ -28,11 +28,11 @@ discard block |
||
| 28 | 28 | * Register the command with WP-CLI |
| 29 | 29 | */ |
| 30 | 30 | public function register() { |
| 31 | - if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) { |
|
| 31 | + if (!defined('WP_CLI') || !WP_CLI) { |
|
| 32 | 32 | return; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - WP_CLI::add_command( 'action-scheduler migrate', [ $this, 'migrate' ], [ |
|
| 35 | + WP_CLI::add_command('action-scheduler migrate', [$this, 'migrate'], [ |
|
| 36 | 36 | 'shortdesc' => 'Migrates actions to the DB tables store', |
| 37 | 37 | 'synopsis' => [ |
| 38 | 38 | [ |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | 'description' => 'Reports on the actions that would have been migrated, but does not change any data', |
| 64 | 64 | ], |
| 65 | 65 | ], |
| 66 | - ] ); |
|
| 66 | + ]); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -74,31 +74,31 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return void |
| 76 | 76 | */ |
| 77 | - public function migrate( $positional_args, $assoc_args ) { |
|
| 77 | + public function migrate($positional_args, $assoc_args) { |
|
| 78 | 78 | $this->init_logging(); |
| 79 | 79 | |
| 80 | - $config = $this->get_migration_config( $assoc_args ); |
|
| 81 | - $runner = new Runner( $config ); |
|
| 80 | + $config = $this->get_migration_config($assoc_args); |
|
| 81 | + $runner = new Runner($config); |
|
| 82 | 82 | $runner->init_destination(); |
| 83 | 83 | |
| 84 | - $batch_size = isset( $assoc_args[ 'batch-size' ] ) ? (int) $assoc_args[ 'batch-size' ] : 100; |
|
| 85 | - $free_on = isset( $assoc_args[ 'free-memory-on' ] ) ? (int) $assoc_args[ 'free-memory-on' ] : 50; |
|
| 86 | - $sleep = isset( $assoc_args[ 'pause' ] ) ? (int) $assoc_args[ 'pause' ] : 0; |
|
| 87 | - \ActionScheduler_DataController::set_free_ticks( $free_on ); |
|
| 88 | - \ActionScheduler_DataController::set_sleep_time( $sleep ); |
|
| 84 | + $batch_size = isset($assoc_args['batch-size']) ? (int) $assoc_args['batch-size'] : 100; |
|
| 85 | + $free_on = isset($assoc_args['free-memory-on']) ? (int) $assoc_args['free-memory-on'] : 50; |
|
| 86 | + $sleep = isset($assoc_args['pause']) ? (int) $assoc_args['pause'] : 0; |
|
| 87 | + \ActionScheduler_DataController::set_free_ticks($free_on); |
|
| 88 | + \ActionScheduler_DataController::set_sleep_time($sleep); |
|
| 89 | 89 | |
| 90 | 90 | do { |
| 91 | - $actions_processed = $runner->run( $batch_size ); |
|
| 91 | + $actions_processed = $runner->run($batch_size); |
|
| 92 | 92 | $this->total_processed += $actions_processed; |
| 93 | - } while ( $actions_processed > 0 ); |
|
| 93 | + } while ($actions_processed > 0); |
|
| 94 | 94 | |
| 95 | - if ( ! $config->get_dry_run() ) { |
|
| 95 | + if (!$config->get_dry_run()) { |
|
| 96 | 96 | // let the scheduler know that there's nothing left to do |
| 97 | 97 | $scheduler = new Scheduler(); |
| 98 | 98 | $scheduler->mark_complete(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - WP_CLI::success( sprintf( '%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed ) ); |
|
| 101 | + WP_CLI::success(sprintf('%s complete. %d actions processed.', $config->get_dry_run() ? 'Dry run' : 'Migration', $this->total_processed)); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | * |
| 109 | 109 | * @return ActionScheduler\Migration\Config |
| 110 | 110 | */ |
| 111 | - private function get_migration_config( $args ) { |
|
| 112 | - $args = wp_parse_args( $args, [ |
|
| 111 | + private function get_migration_config($args) { |
|
| 112 | + $args = wp_parse_args($args, [ |
|
| 113 | 113 | 'dry-run' => false, |
| 114 | - ] ); |
|
| 114 | + ]); |
|
| 115 | 115 | |
| 116 | 116 | $config = Controller::instance()->get_migration_config_object(); |
| 117 | - $config->set_dry_run( ! empty( $args[ 'dry-run' ] ) ); |
|
| 117 | + $config->set_dry_run(!empty($args['dry-run'])); |
|
| 118 | 118 | |
| 119 | 119 | return $config; |
| 120 | 120 | } |
@@ -123,26 +123,26 @@ discard block |
||
| 123 | 123 | * Hook command line logging into migration actions. |
| 124 | 124 | */ |
| 125 | 125 | private function init_logging() { |
| 126 | - add_action( 'action_scheduler/migrate_action_dry_run', function ( $action_id ) { |
|
| 127 | - WP_CLI::debug( sprintf( 'Dry-run: migrated action %d', $action_id ) ); |
|
| 128 | - }, 10, 1 ); |
|
| 129 | - add_action( 'action_scheduler/no_action_to_migrate', function ( $action_id ) { |
|
| 130 | - WP_CLI::debug( sprintf( 'No action found to migrate for ID %d', $action_id ) ); |
|
| 131 | - }, 10, 1 ); |
|
| 132 | - add_action( 'action_scheduler/migrate_action_failed', function ( $action_id ) { |
|
| 133 | - WP_CLI::warning( sprintf( 'Failed migrating action with ID %d', $action_id ) ); |
|
| 134 | - }, 10, 1 ); |
|
| 135 | - add_action( 'action_scheduler/migrate_action_incomplete', function ( $source_id, $destination_id ) { |
|
| 136 | - WP_CLI::warning( sprintf( 'Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id ) ); |
|
| 137 | - }, 10, 2 ); |
|
| 138 | - add_action( 'action_scheduler/migrated_action', function ( $source_id, $destination_id ) { |
|
| 139 | - WP_CLI::debug( sprintf( 'Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id ) ); |
|
| 140 | - }, 10, 2 ); |
|
| 141 | - add_action( 'action_scheduler/migration_batch_starting', function ( $batch ) { |
|
| 142 | - WP_CLI::debug( 'Beginning migration of batch: ' . print_r( $batch, true ) ); |
|
| 143 | - }, 10, 1 ); |
|
| 144 | - add_action( 'action_scheduler/migration_batch_complete', function ( $batch ) { |
|
| 145 | - WP_CLI::log( sprintf( 'Completed migration of %d actions', count( $batch ) ) ); |
|
| 146 | - }, 10, 1 ); |
|
| 126 | + add_action('action_scheduler/migrate_action_dry_run', function($action_id) { |
|
| 127 | + WP_CLI::debug(sprintf('Dry-run: migrated action %d', $action_id)); |
|
| 128 | + }, 10, 1); |
|
| 129 | + add_action('action_scheduler/no_action_to_migrate', function($action_id) { |
|
| 130 | + WP_CLI::debug(sprintf('No action found to migrate for ID %d', $action_id)); |
|
| 131 | + }, 10, 1); |
|
| 132 | + add_action('action_scheduler/migrate_action_failed', function($action_id) { |
|
| 133 | + WP_CLI::warning(sprintf('Failed migrating action with ID %d', $action_id)); |
|
| 134 | + }, 10, 1); |
|
| 135 | + add_action('action_scheduler/migrate_action_incomplete', function($source_id, $destination_id) { |
|
| 136 | + WP_CLI::warning(sprintf('Unable to remove source action with ID %d after migrating to new ID %d', $source_id, $destination_id)); |
|
| 137 | + }, 10, 2); |
|
| 138 | + add_action('action_scheduler/migrated_action', function($source_id, $destination_id) { |
|
| 139 | + WP_CLI::debug(sprintf('Migrated source action with ID %d to new store with ID %d', $source_id, $destination_id)); |
|
| 140 | + }, 10, 2); |
|
| 141 | + add_action('action_scheduler/migration_batch_starting', function($batch) { |
|
| 142 | + WP_CLI::debug('Beginning migration of batch: ' . print_r($batch, true)); |
|
| 143 | + }, 10, 1); |
|
| 144 | + add_action('action_scheduler/migration_batch_complete', function($batch) { |
|
| 145 | + WP_CLI::log(sprintf('Completed migration of %d actions', count($batch))); |
|
| 146 | + }, 10, 1); |
|
| 147 | 147 | } |
| 148 | 148 | } |
@@ -14,16 +14,16 @@ discard block |
||
| 14 | 14 | * |
| 15 | 15 | * @return ActionScheduler_Action An instance of the stored action |
| 16 | 16 | */ |
| 17 | - public function get_stored_action( $status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '' ) { |
|
| 17 | + public function get_stored_action($status, $hook, array $args = array(), ActionScheduler_Schedule $schedule = null, $group = '') { |
|
| 18 | 18 | |
| 19 | - switch ( $status ) { |
|
| 19 | + switch ($status) { |
|
| 20 | 20 | case ActionScheduler_Store::STATUS_PENDING : |
| 21 | 21 | $action_class = 'ActionScheduler_Action'; |
| 22 | 22 | break; |
| 23 | 23 | case ActionScheduler_Store::STATUS_CANCELED : |
| 24 | 24 | $action_class = 'ActionScheduler_CanceledAction'; |
| 25 | - if ( ! is_null( $schedule ) && ! is_a( $schedule, 'ActionScheduler_CanceledSchedule' ) && ! is_a( $schedule, 'ActionScheduler_NullSchedule' ) ) { |
|
| 26 | - $schedule = new ActionScheduler_CanceledSchedule( $schedule->get_date() ); |
|
| 25 | + if (!is_null($schedule) && !is_a($schedule, 'ActionScheduler_CanceledSchedule') && !is_a($schedule, 'ActionScheduler_NullSchedule')) { |
|
| 26 | + $schedule = new ActionScheduler_CanceledSchedule($schedule->get_date()); |
|
| 27 | 27 | } |
| 28 | 28 | break; |
| 29 | 29 | default : |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | break; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - $action_class = apply_filters( 'action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group ); |
|
| 34 | + $action_class = apply_filters('action_scheduler_stored_action_class', $action_class, $status, $hook, $args, $schedule, $group); |
|
| 35 | 35 | |
| 36 | - $action = new $action_class( $hook, $args, $schedule, $group ); |
|
| 36 | + $action = new $action_class($hook, $args, $schedule, $group); |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Allow 3rd party code to change the instantiated action for a given hook, args, schedule and group. |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * @param ActionScheduler_Schedule $schedule The instantiated action's schedule. |
| 45 | 45 | * @param string $group The instantiated action's group. |
| 46 | 46 | */ |
| 47 | - return apply_filters( 'action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group ); |
|
| 47 | + return apply_filters('action_scheduler_stored_action_instance', $action, $hook, $args, $schedule, $group); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | /** |
@@ -63,10 +63,10 @@ discard block |
||
| 63 | 63 | * |
| 64 | 64 | * @return int The ID of the stored action |
| 65 | 65 | */ |
| 66 | - public function async( $hook, $args = array(), $group = '' ) { |
|
| 66 | + public function async($hook, $args = array(), $group = '') { |
|
| 67 | 67 | $schedule = new ActionScheduler_NullSchedule(); |
| 68 | - $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); |
|
| 69 | - return $this->store( $action ); |
|
| 68 | + $action = new ActionScheduler_Action($hook, $args, $schedule, $group); |
|
| 69 | + return $this->store($action); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -77,11 +77,11 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | * @return int The ID of the stored action |
| 79 | 79 | */ |
| 80 | - public function single( $hook, $args = array(), $when = null, $group = '' ) { |
|
| 81 | - $date = as_get_datetime_object( $when ); |
|
| 82 | - $schedule = new ActionScheduler_SimpleSchedule( $date ); |
|
| 83 | - $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); |
|
| 84 | - return $this->store( $action ); |
|
| 80 | + public function single($hook, $args = array(), $when = null, $group = '') { |
|
| 81 | + $date = as_get_datetime_object($when); |
|
| 82 | + $schedule = new ActionScheduler_SimpleSchedule($date); |
|
| 83 | + $action = new ActionScheduler_Action($hook, $args, $schedule, $group); |
|
| 84 | + return $this->store($action); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -95,14 +95,14 @@ discard block |
||
| 95 | 95 | * |
| 96 | 96 | * @return int The ID of the stored action |
| 97 | 97 | */ |
| 98 | - public function recurring( $hook, $args = array(), $first = null, $interval = null, $group = '' ) { |
|
| 99 | - if ( empty($interval) ) { |
|
| 100 | - return $this->single( $hook, $args, $first, $group ); |
|
| 98 | + public function recurring($hook, $args = array(), $first = null, $interval = null, $group = '') { |
|
| 99 | + if (empty($interval)) { |
|
| 100 | + return $this->single($hook, $args, $first, $group); |
|
| 101 | 101 | } |
| 102 | - $date = as_get_datetime_object( $first ); |
|
| 103 | - $schedule = new ActionScheduler_IntervalSchedule( $date, $interval ); |
|
| 104 | - $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); |
|
| 105 | - return $this->store( $action ); |
|
| 102 | + $date = as_get_datetime_object($first); |
|
| 103 | + $schedule = new ActionScheduler_IntervalSchedule($date, $interval); |
|
| 104 | + $action = new ActionScheduler_Action($hook, $args, $schedule, $group); |
|
| 105 | + return $this->store($action); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | * |
| 119 | 119 | * @return int The ID of the stored action |
| 120 | 120 | */ |
| 121 | - public function cron( $hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '' ) { |
|
| 122 | - if ( empty($schedule) ) { |
|
| 123 | - return $this->single( $hook, $args, $base_timestamp, $group ); |
|
| 121 | + public function cron($hook, $args = array(), $base_timestamp = null, $schedule = null, $group = '') { |
|
| 122 | + if (empty($schedule)) { |
|
| 123 | + return $this->single($hook, $args, $base_timestamp, $group); |
|
| 124 | 124 | } |
| 125 | - $date = as_get_datetime_object( $base_timestamp ); |
|
| 126 | - $cron = CronExpression::factory( $schedule ); |
|
| 127 | - $schedule = new ActionScheduler_CronSchedule( $date, $cron ); |
|
| 128 | - $action = new ActionScheduler_Action( $hook, $args, $schedule, $group ); |
|
| 129 | - return $this->store( $action ); |
|
| 125 | + $date = as_get_datetime_object($base_timestamp); |
|
| 126 | + $cron = CronExpression::factory($schedule); |
|
| 127 | + $schedule = new ActionScheduler_CronSchedule($date, $cron); |
|
| 128 | + $action = new ActionScheduler_Action($hook, $args, $schedule, $group); |
|
| 129 | + return $this->store($action); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -153,18 +153,18 @@ discard block |
||
| 153 | 153 | * @return string The ID of the stored action |
| 154 | 154 | * @throws InvalidArgumentException If $action is not a recurring action. |
| 155 | 155 | */ |
| 156 | - public function repeat( $action ) { |
|
| 156 | + public function repeat($action) { |
|
| 157 | 157 | $schedule = $action->get_schedule(); |
| 158 | - $next = $schedule->get_next( as_get_datetime_object() ); |
|
| 158 | + $next = $schedule->get_next(as_get_datetime_object()); |
|
| 159 | 159 | |
| 160 | - if ( is_null( $next ) || ! $schedule->is_recurring() ) { |
|
| 161 | - throw new InvalidArgumentException( __( 'Invalid action - must be a recurring action.', 'woocommerce' ) ); |
|
| 160 | + if (is_null($next) || !$schedule->is_recurring()) { |
|
| 161 | + throw new InvalidArgumentException(__('Invalid action - must be a recurring action.', 'woocommerce')); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $schedule_class = get_class( $schedule ); |
|
| 165 | - $new_schedule = new $schedule( $next, $schedule->get_recurrence(), $schedule->get_first_date() ); |
|
| 166 | - $new_action = new ActionScheduler_Action( $action->get_hook(), $action->get_args(), $new_schedule, $action->get_group() ); |
|
| 167 | - return $this->store( $new_action ); |
|
| 164 | + $schedule_class = get_class($schedule); |
|
| 165 | + $new_schedule = new $schedule($next, $schedule->get_recurrence(), $schedule->get_first_date()); |
|
| 166 | + $new_action = new ActionScheduler_Action($action->get_hook(), $action->get_args(), $new_schedule, $action->get_group()); |
|
| 167 | + return $this->store($new_action); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -172,8 +172,8 @@ discard block |
||
| 172 | 172 | * |
| 173 | 173 | * @return int The ID of the stored action |
| 174 | 174 | */ |
| 175 | - protected function store( ActionScheduler_Action $action ) { |
|
| 175 | + protected function store(ActionScheduler_Action $action) { |
|
| 176 | 176 | $store = ActionScheduler_Store::instance(); |
| 177 | - return $store->save_action( $action ); |
|
| 177 | + return $store->save_action($action); |
|
| 178 | 178 | } |
| 179 | 179 | } |
@@ -4,7 +4,7 @@ |
||
| 4 | 4 | * Class ActionScheduler_NullLogEntry |
| 5 | 5 | */ |
| 6 | 6 | class ActionScheduler_NullLogEntry extends ActionScheduler_LogEntry { |
| 7 | - public function __construct( $action_id = '', $message = '' ) { |
|
| 7 | + public function __construct($action_id = '', $message = '') { |
|
| 8 | 8 | // nothing to see here |
| 9 | 9 | } |
| 10 | 10 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * |
| 20 | 20 | * @return void |
| 21 | 21 | */ |
| 22 | - public function __construct( $store ) { |
|
| 22 | + public function __construct($store) { |
|
| 23 | 23 | $this->store = $store; |
| 24 | 24 | } |
| 25 | 25 | |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | public function render() { |
| 32 | 32 | $action_counts = $this->store->action_counts(); |
| 33 | 33 | $status_labels = $this->store->get_status_labels(); |
| 34 | - $oldest_and_newest = $this->get_oldest_and_newest( array_keys( $status_labels ) ); |
|
| 34 | + $oldest_and_newest = $this->get_oldest_and_newest(array_keys($status_labels)); |
|
| 35 | 35 | |
| 36 | - $this->get_template( $status_labels, $action_counts, $oldest_and_newest ); |
|
| 36 | + $this->get_template($status_labels, $action_counts, $oldest_and_newest); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * @param array $status_keys Set of statuses to find oldest & newest action for. |
| 43 | 43 | * @return array |
| 44 | 44 | */ |
| 45 | - protected function get_oldest_and_newest( $status_keys ) { |
|
| 45 | + protected function get_oldest_and_newest($status_keys) { |
|
| 46 | 46 | |
| 47 | 47 | $oldest_and_newest = array(); |
| 48 | 48 | |
| 49 | - foreach ( $status_keys as $status ) { |
|
| 50 | - $oldest_and_newest[ $status ] = array( |
|
| 49 | + foreach ($status_keys as $status) { |
|
| 50 | + $oldest_and_newest[$status] = array( |
|
| 51 | 51 | 'oldest' => '–', |
| 52 | 52 | 'newest' => '–', |
| 53 | 53 | ); |
| 54 | 54 | |
| 55 | - if ( 'in-progress' === $status ) { |
|
| 55 | + if ('in-progress' === $status) { |
|
| 56 | 56 | continue; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - $oldest_and_newest[ $status ]['oldest'] = $this->get_action_status_date( $status, 'oldest' ); |
|
| 60 | - $oldest_and_newest[ $status ]['newest'] = $this->get_action_status_date( $status, 'newest' ); |
|
| 59 | + $oldest_and_newest[$status]['oldest'] = $this->get_action_status_date($status, 'oldest'); |
|
| 60 | + $oldest_and_newest[$status]['newest'] = $this->get_action_status_date($status, 'newest'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | return $oldest_and_newest; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param string $date_type Oldest or Newest. |
| 71 | 71 | * @return DateTime |
| 72 | 72 | */ |
| 73 | - protected function get_action_status_date( $status, $date_type = 'oldest' ) { |
|
| 73 | + protected function get_action_status_date($status, $date_type = 'oldest') { |
|
| 74 | 74 | |
| 75 | 75 | $order = 'oldest' === $date_type ? 'ASC' : 'DESC'; |
| 76 | 76 | |
@@ -83,9 +83,9 @@ discard block |
||
| 83 | 83 | ) |
| 84 | 84 | ); |
| 85 | 85 | |
| 86 | - if ( ! empty( $action ) ) { |
|
| 87 | - $date_object = $this->store->get_date( $action[0] ); |
|
| 88 | - $action_date = $date_object->format( 'Y-m-d H:i:s O' ); |
|
| 86 | + if (!empty($action)) { |
|
| 87 | + $date_object = $this->store->get_date($action[0]); |
|
| 88 | + $action_date = $date_object->format('Y-m-d H:i:s O'); |
|
| 89 | 89 | } else { |
| 90 | 90 | $action_date = '–'; |
| 91 | 91 | } |
@@ -100,42 +100,42 @@ discard block |
||
| 100 | 100 | * @param array $action_counts Number of actions grouped by status. |
| 101 | 101 | * @param array $oldest_and_newest Date of the oldest and newest action with each status. |
| 102 | 102 | */ |
| 103 | - protected function get_template( $status_labels, $action_counts, $oldest_and_newest ) { |
|
| 103 | + protected function get_template($status_labels, $action_counts, $oldest_and_newest) { |
|
| 104 | 104 | $as_version = ActionScheduler_Versions::instance()->latest_version(); |
| 105 | - $as_datastore = get_class( ActionScheduler_Store::instance() ); |
|
| 105 | + $as_datastore = get_class(ActionScheduler_Store::instance()); |
|
| 106 | 106 | ?> |
| 107 | 107 | |
| 108 | 108 | <table class="wc_status_table widefat" cellspacing="0"> |
| 109 | 109 | <thead> |
| 110 | 110 | <tr> |
| 111 | - <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e( 'Action Scheduler', 'woocommerce' ); ?><?php echo wc_help_tip( esc_html__( 'This section shows details of Action Scheduler.', 'woocommerce' ) ); ?></h2></th> |
|
| 111 | + <th colspan="5" data-export-label="Action Scheduler"><h2><?php esc_html_e('Action Scheduler', 'woocommerce'); ?><?php echo wc_help_tip(esc_html__('This section shows details of Action Scheduler.', 'woocommerce')); ?></h2></th> |
|
| 112 | 112 | </tr> |
| 113 | 113 | <tr> |
| 114 | - <td colspan="2" data-export-label="Version"><?php esc_html_e( 'Version:', 'woocommerce' ); ?></td> |
|
| 115 | - <td colspan="3"><?php echo esc_html( $as_version ); ?></td> |
|
| 114 | + <td colspan="2" data-export-label="Version"><?php esc_html_e('Version:', 'woocommerce'); ?></td> |
|
| 115 | + <td colspan="3"><?php echo esc_html($as_version); ?></td> |
|
| 116 | 116 | </tr> |
| 117 | 117 | <tr> |
| 118 | - <td colspan="2" data-export-label="Data store"><?php esc_html_e( 'Data store:', 'woocommerce' ); ?></td> |
|
| 119 | - <td colspan="3"><?php echo esc_html( $as_datastore ); ?></td> |
|
| 118 | + <td colspan="2" data-export-label="Data store"><?php esc_html_e('Data store:', 'woocommerce'); ?></td> |
|
| 119 | + <td colspan="3"><?php echo esc_html($as_datastore); ?></td> |
|
| 120 | 120 | </tr> |
| 121 | 121 | <tr> |
| 122 | - <td><strong><?php esc_html_e( 'Action Status', 'woocommerce' ); ?></strong></td> |
|
| 122 | + <td><strong><?php esc_html_e('Action Status', 'woocommerce'); ?></strong></td> |
|
| 123 | 123 | <td class="help"> </td> |
| 124 | - <td><strong><?php esc_html_e( 'Count', 'woocommerce' ); ?></strong></td> |
|
| 125 | - <td><strong><?php esc_html_e( 'Oldest Scheduled Date', 'woocommerce' ); ?></strong></td> |
|
| 126 | - <td><strong><?php esc_html_e( 'Newest Scheduled Date', 'woocommerce' ); ?></strong></td> |
|
| 124 | + <td><strong><?php esc_html_e('Count', 'woocommerce'); ?></strong></td> |
|
| 125 | + <td><strong><?php esc_html_e('Oldest Scheduled Date', 'woocommerce'); ?></strong></td> |
|
| 126 | + <td><strong><?php esc_html_e('Newest Scheduled Date', 'woocommerce'); ?></strong></td> |
|
| 127 | 127 | </tr> |
| 128 | 128 | </thead> |
| 129 | 129 | <tbody> |
| 130 | 130 | <?php |
| 131 | - foreach ( $action_counts as $status => $count ) { |
|
| 131 | + foreach ($action_counts as $status => $count) { |
|
| 132 | 132 | // WC uses the 3rd column for export, so we need to display more data in that (hidden when viewed as part of the table) and add an empty 2nd column. |
| 133 | 133 | printf( |
| 134 | 134 | '<tr><td>%1$s</td><td> </td><td>%2$s<span style="display: none;">, Oldest: %3$s, Newest: %4$s</span></td><td>%3$s</td><td>%4$s</td></tr>', |
| 135 | - esc_html( $status_labels[ $status ] ), |
|
| 136 | - esc_html( number_format_i18n( $count ) ), |
|
| 137 | - esc_html( $oldest_and_newest[ $status ]['oldest'] ), |
|
| 138 | - esc_html( $oldest_and_newest[ $status ]['newest'] ) |
|
| 135 | + esc_html($status_labels[$status]), |
|
| 136 | + esc_html(number_format_i18n($count)), |
|
| 137 | + esc_html($oldest_and_newest[$status]['oldest']), |
|
| 138 | + esc_html($oldest_and_newest[$status]['newest']) |
|
| 139 | 139 | ); |
| 140 | 140 | } |
| 141 | 141 | ?> |
@@ -154,11 +154,11 @@ discard block |
||
| 154 | 154 | * @return mixed |
| 155 | 155 | * @link https://php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods |
| 156 | 156 | */ |
| 157 | - public function __call( $name, $arguments ) { |
|
| 158 | - switch ( $name ) { |
|
| 157 | + public function __call($name, $arguments) { |
|
| 158 | + switch ($name) { |
|
| 159 | 159 | case 'print': |
| 160 | - _deprecated_function( __CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()' ); |
|
| 161 | - return call_user_func_array( array( $this, 'render' ), $arguments ); |
|
| 160 | + _deprecated_function(__CLASS__ . '::print()', '2.2.4', __CLASS__ . '::render()'); |
|
| 161 | + return call_user_func_array(array($this, 'render'), $arguments); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | return null; |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @param Config $config Migration configuration object. |
| 44 | 44 | */ |
| 45 | - public function __construct( Config $config ) { |
|
| 45 | + public function __construct(Config $config) { |
|
| 46 | 46 | $this->source_store = $config->get_source_store(); |
| 47 | 47 | $this->destination_store = $config->get_destination_store(); |
| 48 | 48 | $this->source_logger = $config->get_source_logger(); |
| 49 | 49 | $this->destination_logger = $config->get_destination_logger(); |
| 50 | 50 | |
| 51 | - $this->batch_fetcher = new BatchFetcher( $this->source_store ); |
|
| 52 | - if ( $config->get_dry_run() ) { |
|
| 53 | - $this->log_migrator = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger ); |
|
| 54 | - $this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator ); |
|
| 51 | + $this->batch_fetcher = new BatchFetcher($this->source_store); |
|
| 52 | + if ($config->get_dry_run()) { |
|
| 53 | + $this->log_migrator = new DryRun_LogMigrator($this->source_logger, $this->destination_logger); |
|
| 54 | + $this->action_migrator = new DryRun_ActionMigrator($this->source_store, $this->destination_store, $this->log_migrator); |
|
| 55 | 55 | } else { |
| 56 | - $this->log_migrator = new LogMigrator( $this->source_logger, $this->destination_logger ); |
|
| 57 | - $this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator ); |
|
| 56 | + $this->log_migrator = new LogMigrator($this->source_logger, $this->destination_logger); |
|
| 57 | + $this->action_migrator = new ActionMigrator($this->source_store, $this->destination_store, $this->log_migrator); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 60 | + if (defined('WP_CLI') && WP_CLI) { |
|
| 61 | 61 | $this->progress_bar = $config->get_progress_bar(); |
| 62 | 62 | } |
| 63 | 63 | } |
@@ -69,21 +69,21 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return int Size of batch processed. |
| 71 | 71 | */ |
| 72 | - public function run( $batch_size = 10 ) { |
|
| 73 | - $batch = $this->batch_fetcher->fetch( $batch_size ); |
|
| 74 | - $batch_size = count( $batch ); |
|
| 72 | + public function run($batch_size = 10) { |
|
| 73 | + $batch = $this->batch_fetcher->fetch($batch_size); |
|
| 74 | + $batch_size = count($batch); |
|
| 75 | 75 | |
| 76 | - if ( ! $batch_size ) { |
|
| 76 | + if (!$batch_size) { |
|
| 77 | 77 | return 0; |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if ( $this->progress_bar ) { |
|
| 80 | + if ($this->progress_bar) { |
|
| 81 | 81 | /* translators: %d: amount of actions */ |
| 82 | - $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'woocommerce' ), number_format_i18n( $batch_size ) ) ); |
|
| 83 | - $this->progress_bar->set_count( $batch_size ); |
|
| 82 | + $this->progress_bar->set_message(sprintf(_n('Migrating %d action', 'Migrating %d actions', $batch_size, 'woocommerce'), number_format_i18n($batch_size))); |
|
| 83 | + $this->progress_bar->set_count($batch_size); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - $this->migrate_actions( $batch ); |
|
| 86 | + $this->migrate_actions($batch); |
|
| 87 | 87 | |
| 88 | 88 | return $batch_size; |
| 89 | 89 | } |
@@ -93,37 +93,37 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @param array $action_ids List of action IDs to migrate. |
| 95 | 95 | */ |
| 96 | - public function migrate_actions( array $action_ids ) { |
|
| 97 | - do_action( 'action_scheduler/migration_batch_starting', $action_ids ); |
|
| 96 | + public function migrate_actions(array $action_ids) { |
|
| 97 | + do_action('action_scheduler/migration_batch_starting', $action_ids); |
|
| 98 | 98 | |
| 99 | 99 | \ActionScheduler::logger()->unhook_stored_action(); |
| 100 | 100 | $this->destination_logger->unhook_stored_action(); |
| 101 | 101 | |
| 102 | - foreach ( $action_ids as $source_action_id ) { |
|
| 103 | - $destination_action_id = $this->action_migrator->migrate( $source_action_id ); |
|
| 104 | - if ( $destination_action_id ) { |
|
| 105 | - $this->destination_logger->log( $destination_action_id, sprintf( |
|
| 102 | + foreach ($action_ids as $source_action_id) { |
|
| 103 | + $destination_action_id = $this->action_migrator->migrate($source_action_id); |
|
| 104 | + if ($destination_action_id) { |
|
| 105 | + $this->destination_logger->log($destination_action_id, sprintf( |
|
| 106 | 106 | /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */ |
| 107 | - __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'woocommerce' ), |
|
| 107 | + __('Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'woocommerce'), |
|
| 108 | 108 | $source_action_id, |
| 109 | - get_class( $this->source_store ), |
|
| 109 | + get_class($this->source_store), |
|
| 110 | 110 | $destination_action_id, |
| 111 | - get_class( $this->destination_store ) |
|
| 112 | - ) ); |
|
| 111 | + get_class($this->destination_store) |
|
| 112 | + )); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - if ( $this->progress_bar ) { |
|
| 115 | + if ($this->progress_bar) { |
|
| 116 | 116 | $this->progress_bar->tick(); |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if ( $this->progress_bar ) { |
|
| 120 | + if ($this->progress_bar) { |
|
| 121 | 121 | $this->progress_bar->finish(); |
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | \ActionScheduler::logger()->hook_stored_action(); |
| 125 | 125 | |
| 126 | - do_action( 'action_scheduler/migration_batch_complete', $action_ids ); |
|
| 126 | + do_action('action_scheduler/migration_batch_complete', $action_ids); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -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 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param ActionScheduler_Store $destination_store Destination store object. |
| 30 | 30 | * @param LogMigrator $log_migrator Log migrator object. |
| 31 | 31 | */ |
| 32 | - public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) { |
|
| 32 | + public function __construct(\ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator) { |
|
| 33 | 33 | $this->source = $source_store; |
| 34 | 34 | $this->destination = $destination_store; |
| 35 | 35 | $this->log_migrator = $log_migrator; |
@@ -42,25 +42,25 @@ discard block |
||
| 42 | 42 | * |
| 43 | 43 | * @return int 0|new action ID |
| 44 | 44 | */ |
| 45 | - public function migrate( $source_action_id ) { |
|
| 45 | + public function migrate($source_action_id) { |
|
| 46 | 46 | try { |
| 47 | - $action = $this->source->fetch_action( $source_action_id ); |
|
| 48 | - $status = $this->source->get_status( $source_action_id ); |
|
| 49 | - } catch ( \Exception $e ) { |
|
| 47 | + $action = $this->source->fetch_action($source_action_id); |
|
| 48 | + $status = $this->source->get_status($source_action_id); |
|
| 49 | + } catch (\Exception $e) { |
|
| 50 | 50 | $action = null; |
| 51 | 51 | $status = ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) { |
|
| 54 | + if (is_null($action) || empty($status) || !$action->get_schedule()->get_date()) { |
|
| 55 | 55 | // null action or empty status means the fetch operation failed or the action didn't exist |
| 56 | 56 | // null schedule means it's missing vital data |
| 57 | 57 | // delete it and move on |
| 58 | 58 | try { |
| 59 | - $this->source->delete_action( $source_action_id ); |
|
| 60 | - } catch ( \Exception $e ) { |
|
| 59 | + $this->source->delete_action($source_action_id); |
|
| 60 | + } catch (\Exception $e) { |
|
| 61 | 61 | // nothing to do, it didn't exist in the first place |
| 62 | 62 | } |
| 63 | - do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); |
|
| 63 | + do_action('action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination); |
|
| 64 | 64 | |
| 65 | 65 | return 0; |
| 66 | 66 | } |
@@ -68,40 +68,40 @@ discard block |
||
| 68 | 68 | try { |
| 69 | 69 | |
| 70 | 70 | // Make sure the last attempt date is set correctly for completed and failed actions |
| 71 | - $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null; |
|
| 71 | + $last_attempt_date = ($status !== \ActionScheduler_Store::STATUS_PENDING) ? $this->source->get_date($source_action_id) : null; |
|
| 72 | 72 | |
| 73 | - $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date ); |
|
| 74 | - } catch ( \Exception $e ) { |
|
| 75 | - do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); |
|
| 73 | + $destination_action_id = $this->destination->save_action($action, null, $last_attempt_date); |
|
| 74 | + } catch (\Exception $e) { |
|
| 75 | + do_action('action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination); |
|
| 76 | 76 | |
| 77 | 77 | return 0; // could not save the action in the new store |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | try { |
| 81 | - switch ( $status ) { |
|
| 81 | + switch ($status) { |
|
| 82 | 82 | case \ActionScheduler_Store::STATUS_FAILED : |
| 83 | - $this->destination->mark_failure( $destination_action_id ); |
|
| 83 | + $this->destination->mark_failure($destination_action_id); |
|
| 84 | 84 | break; |
| 85 | 85 | case \ActionScheduler_Store::STATUS_CANCELED : |
| 86 | - $this->destination->cancel_action( $destination_action_id ); |
|
| 86 | + $this->destination->cancel_action($destination_action_id); |
|
| 87 | 87 | break; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $this->log_migrator->migrate( $source_action_id, $destination_action_id ); |
|
| 91 | - $this->source->delete_action( $source_action_id ); |
|
| 90 | + $this->log_migrator->migrate($source_action_id, $destination_action_id); |
|
| 91 | + $this->source->delete_action($source_action_id); |
|
| 92 | 92 | |
| 93 | - $test_action = $this->source->fetch_action( $source_action_id ); |
|
| 94 | - if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) { |
|
| 95 | - throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'woocommerce' ), $source_action_id ) ); |
|
| 93 | + $test_action = $this->source->fetch_action($source_action_id); |
|
| 94 | + if (!is_a($test_action, 'ActionScheduler_NullAction')) { |
|
| 95 | + throw new \RuntimeException(sprintf(__('Unable to remove source migrated action %s', 'woocommerce'), $source_action_id)); |
|
| 96 | 96 | } |
| 97 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 97 | + do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
| 98 | 98 | |
| 99 | 99 | return $destination_action_id; |
| 100 | - } catch ( \Exception $e ) { |
|
| 100 | + } catch (\Exception $e) { |
|
| 101 | 101 | // could not delete from the old store |
| 102 | - $this->source->mark_migrated( $source_action_id ); |
|
| 103 | - do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 104 | - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); |
|
| 102 | + $this->source->mark_migrated($source_action_id); |
|
| 103 | + do_action('action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
| 104 | + do_action('action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination); |
|
| 105 | 105 | |
| 106 | 106 | return $destination_action_id; |
| 107 | 107 | } |