PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / packages / action-scheduler / classes / migration / Runner.php

Runner.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at packages/action-scheduler/classes/migration/Runner.php

153 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace Action_Scheduler\Migration;
5
6 /**
7 * Class Runner
8 *
9 * @package Action_Scheduler\Migration
10 *
11 * @since 3.0.0
12 *
13 * @codeCoverageIgnore
14 */
15 class Runner {
16 /**
17 * @var ActionScheduler_Store
18 */
19 private $source_store;
20
21 /**
22 * @var ActionScheduler_Store
23 */
24 private $destination_store;
25
26 /**
27 * @var ActionScheduler_Logger
28 */
29 private $source_logger;
30
31 /**
32 * @var ActionScheduler_Logger
33 */
34 private $destination_logger;
35
36 /**
37 * @var BatchFetcher
38 */
39 private $batch_fetcher;
40
41 /**
42 * @var ActionMigrator
43 */
44 private $action_migrator;
45
46 /**
47 * @var LogMigrator
48 */
49 private $log_migrator;
50
51 /**
52 * @var ProgressBar
53 */
54 private $progress_bar;
55
56 /**
57 * Runner constructor.
58 *
59 * @param Config $config Migration configuration object.
60 */
61 public function __construct( Config $config ) {
62 $this->source_store = $config->get_source_store();
63 $this->destination_store = $config->get_destination_store();
64 $this->source_logger = $config->get_source_logger();
65 $this->destination_logger = $config->get_destination_logger();
66
67 $this->batch_fetcher = new BatchFetcher( $this->source_store );
68 if ( $config->get_dry_run() ) {
69 $this->log_migrator = new DryRun_LogMigrator( $this->source_logger, $this->destination_logger );
70 $this->action_migrator = new DryRun_ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
71 } else {
72 $this->log_migrator = new LogMigrator( $this->source_logger, $this->destination_logger );
73 $this->action_migrator = new ActionMigrator( $this->source_store, $this->destination_store, $this->log_migrator );
74 }
75
76 if ( defined( 'WP_CLI' ) && WP_CLI ) {
77 $this->progress_bar = $config->get_progress_bar();
78 }
79 }
80
81 /**
82 * Run migration batch.
83 *
84 * @param int $batch_size Optional batch size. Default 10.
85 *
86 * @return int Size of batch processed.
87 */
88 public function run( $batch_size = 10 ) {
89 $batch = $this->batch_fetcher->fetch( $batch_size );
90 $batch_size = count( $batch );
91
92 if ( ! $batch_size ) {
93 return 0;
94 }
95
96 if ( $this->progress_bar ) {
97 /* translators: %d: amount of actions */
98 $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'woocommerce' ), number_format_i18n( $batch_size ) ) );
99 $this->progress_bar->set_count( $batch_size );
100 }
101
102 $this->migrate_actions( $batch );
103
104 return $batch_size;
105 }
106
107 /**
108 * Migration a batch of actions.
109 *
110 * @param array $action_ids List of action IDs to migrate.
111 */
112 public function migrate_actions( array $action_ids ) {
113 do_action( 'action_scheduler/migration_batch_starting', $action_ids );
114
115 \ActionScheduler::logger()->unhook_stored_action();
116 $this->destination_logger->unhook_stored_action();
117
118 foreach ( $action_ids as $source_action_id ) {
119 $destination_action_id = $this->action_migrator->migrate( $source_action_id );
120 if ( $destination_action_id ) {
121 $this->destination_logger->log( $destination_action_id, sprintf(
122 /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
123 __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'woocommerce' ),
124 $source_action_id,
125 get_class( $this->source_store ),
126 $destination_action_id,
127 get_class( $this->destination_store )
128 ) );
129 }
130
131 if ( $this->progress_bar ) {
132 $this->progress_bar->tick();
133 }
134 }
135
136 if ( $this->progress_bar ) {
137 $this->progress_bar->finish();
138 }
139
140 \ActionScheduler::logger()->hook_stored_action();
141
142 do_action( 'action_scheduler/migration_batch_complete', $action_ids );
143 }
144
145 /**
146 * Initialize destination store and logger.
147 */
148 public function init_destination() {
149 $this->destination_store->init();
150 $this->destination_logger->init();
151 }
152 }
153