← All changes
|
libraries/action-scheduler/classes/migration/Runner.php
+54
-19
1.0.2
→
3.1.1
View file →
| @@ -12,30 +12,62 @@ | ||
| 12 | 12 | * |
| 13 | 13 | * @codeCoverageIgnore |
| 14 | 14 | */ |
| 15 | 15 | class Runner { |
| 16 | - /** @var ActionScheduler_Store */ | |
| 16 | + /** | |
| 17 | + * Source store instance. | |
| 18 | + * | |
| 19 | + * @var ActionScheduler_Store | |
| 20 | + */ | |
| 17 | 21 | private $source_store; |
| 18 | 22 | |
| 19 | - /** @var ActionScheduler_Store */ | |
| 23 | + /** | |
| 24 | + * Destination store instance. | |
| 25 | + * | |
| 26 | + * @var ActionScheduler_Store | |
| 27 | + */ | |
| 20 | 28 | private $destination_store; |
| 21 | 29 | |
| 22 | - /** @var ActionScheduler_Logger */ | |
| 30 | + /** | |
| 31 | + * Source logger instance. | |
| 32 | + * | |
| 33 | + * @var ActionScheduler_Logger | |
| 34 | + */ | |
| 23 | 35 | private $source_logger; |
| 24 | 36 | |
| 25 | - /** @var ActionScheduler_Logger */ | |
| 37 | + /** | |
| 38 | + * Destination logger instance. | |
| 39 | + * | |
| 40 | + * @var ActionScheduler_Logger | |
| 41 | + */ | |
| 26 | 42 | private $destination_logger; |
| 27 | 43 | |
| 28 | - /** @var BatchFetcher */ | |
| 44 | + /** | |
| 45 | + * Batch fetcher instance. | |
| 46 | + * | |
| 47 | + * @var BatchFetcher | |
| 48 | + */ | |
| 29 | 49 | private $batch_fetcher; |
| 30 | 50 | |
| 31 | - /** @var ActionMigrator */ | |
| 51 | + /** | |
| 52 | + * Action migrator instance. | |
| 53 | + * | |
| 54 | + * @var ActionMigrator | |
| 55 | + */ | |
| 32 | 56 | private $action_migrator; |
| 33 | 57 | |
| 34 | - /** @var LogMigrator */ | |
| 58 | + /** | |
| 59 | + * Log migrator instance. | |
| 60 | + * | |
| 61 | + * @var LogMigrator | |
| 62 | + */ | |
| 35 | 63 | private $log_migrator; |
| 36 | 64 | |
| 37 | - /** @var ProgressBar */ | |
| 65 | + /** | |
| 66 | + * Progress bar instance. | |
| 67 | + * | |
| 68 | + * @var ProgressBar | |
| 69 | + */ | |
| 38 | 70 | private $progress_bar; |
| 39 | 71 | |
| 40 | 72 | /** |
| 41 | 73 | * Runner constructor. |
| @@ -69,9 +101,9 @@ | ||
| 69 | 101 | * |
| 70 | 102 | * @return int Size of batch processed. |
| 71 | 103 | */ |
| 72 | 104 | public function run( $batch_size = 10 ) { |
| 73 | - $batch = $this->batch_fetcher->fetch( $batch_size ); | |
| 105 | + $batch = $this->batch_fetcher->fetch( $batch_size ); | |
| 74 | 106 | $batch_size = count( $batch ); |
| 75 | 107 | |
| 76 | 108 | if ( ! $batch_size ) { |
| 77 | 109 | return 0; |
| @@ -78,9 +110,9 @@ | ||
| 78 | 110 | } |
| 79 | 111 | |
| 80 | 112 | if ( $this->progress_bar ) { |
| 81 | 113 | /* translators: %d: amount of actions */ |
| 82 | - $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), number_format_i18n( $batch_size ) ) ); | |
| 114 | + $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), $batch_size ) ); | |
| 83 | 115 | $this->progress_bar->set_count( $batch_size ); |
| 84 | 116 | } |
| 85 | 117 | |
| 86 | 118 | $this->migrate_actions( $batch ); |
| @@ -93,9 +125,9 @@ | ||
| 93 | 125 | * |
| 94 | 126 | * @param array $action_ids List of action IDs to migrate. |
| 95 | 127 | */ |
| 96 | 128 | public function migrate_actions( array $action_ids ) { |
| 97 | - do_action( 'action_scheduler/migration_batch_starting', $action_ids ); | |
| 129 | + do_action( 'action_scheduler/migration_batch_starting', $action_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores | |
| 98 | 130 | |
| 99 | 131 | \ActionScheduler::logger()->unhook_stored_action(); |
| 100 | 132 | $this->destination_logger->unhook_stored_action(); |
| 101 | 133 | |
| @@ -101,16 +133,19 @@ | ||
| 101 | 133 | |
| 102 | 134 | foreach ( $action_ids as $source_action_id ) { |
| 103 | 135 | $destination_action_id = $this->action_migrator->migrate( $source_action_id ); |
| 104 | 136 | if ( $destination_action_id ) { |
| 105 | - $this->destination_logger->log( $destination_action_id, sprintf( | |
| 106 | - /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */ | |
| 107 | - __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ), | |
| 108 | - $source_action_id, | |
| 109 | - get_class( $this->source_store ), | |
| 137 | + $this->destination_logger->log( | |
| 110 | 138 | $destination_action_id, |
| 111 | - get_class( $this->destination_store ) | |
| 112 | - ) ); | |
| 139 | + sprintf( | |
| 140 | + /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */ | |
| 141 | + __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ), | |
| 142 | + $source_action_id, | |
| 143 | + get_class( $this->source_store ), | |
| 144 | + $destination_action_id, | |
| 145 | + get_class( $this->destination_store ) | |
| 146 | + ) | |
| 147 | + ); | |
| 113 | 148 | } |
| 114 | 149 | |
| 115 | 150 | if ( $this->progress_bar ) { |
| 116 | 151 | $this->progress_bar->tick(); |
| @@ -122,9 +157,9 @@ | ||
| 122 | 157 | } |
| 123 | 158 | |
| 124 | 159 | \ActionScheduler::logger()->hook_stored_action(); |
| 125 | 160 | |
| 126 | - do_action( 'action_scheduler/migration_batch_complete', $action_ids ); | |
| 161 | + do_action( 'action_scheduler/migration_batch_complete', $action_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores | |
| 127 | 162 | } |
| 128 | 163 | |
| 129 | 164 | /** |
| 130 | 165 | * Initialize destination store and logger. |