PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.8
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.8
2.12.8 2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 All 98 releases
sureforms / inc / lib / action-scheduler / classes / migration / Runner.php

Runner.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 2.12.8, at inc/lib/action-scheduler/classes/migration/Runner.php

140 lines 3.7 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 /** @var ActionScheduler_Store */
17 private $source_store;
18
19 /** @var ActionScheduler_Store */
20 private $destination_store;
21
22 /** @var ActionScheduler_Logger */
23 private $source_logger;
24
25 /** @var ActionScheduler_Logger */
26 private $destination_logger;
27
28 /** @var BatchFetcher */
29 private $batch_fetcher;
30
31 /** @var ActionMigrator */
32 private $action_migrator;
33
34 /** @var LogMigrator */
35 private $log_migrator;
36
37 /** @var ProgressBar */
38 private $progress_bar;
39
40 /**
41 * Runner constructor.
42 *
43 * @param Config $config Migration configuration object.
44 */
45 public function __construct( Config $config ) {
46 $this->source_store = $config->get_source_store();
47 $this->destination_store = $config->get_destination_store();
48 $this->source_logger = $config->get_source_logger();
49 $this->destination_logger = $config->get_destination_logger();
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 );
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 );
58 }
59
60 if ( defined( 'WP_CLI' ) && WP_CLI ) {
61 $this->progress_bar = $config->get_progress_bar();
62 }
63 }
64
65 /**
66 * Run migration batch.
67 *
68 * @param int $batch_size Optional batch size. Default 10.
69 *
70 * @return int Size of batch processed.
71 */
72 public function run( $batch_size = 10 ) {
73 $batch = $this->batch_fetcher->fetch( $batch_size );
74 $batch_size = count( $batch );
75
76 if ( ! $batch_size ) {
77 return 0;
78 }
79
80 if ( $this->progress_bar ) {
81 /* translators: %d: amount of actions */
82 $this->progress_bar->set_message( sprintf( _n( 'Migrating %d action', 'Migrating %d actions', $batch_size, 'action-scheduler' ), $batch_size ) );
83 $this->progress_bar->set_count( $batch_size );
84 }
85
86 $this->migrate_actions( $batch );
87
88 return $batch_size;
89 }
90
91 /**
92 * Migration a batch of actions.
93 *
94 * @param array $action_ids List of action IDs to migrate.
95 */
96 public function migrate_actions( array $action_ids ) {
97 do_action( 'action_scheduler/migration_batch_starting', $action_ids );
98
99 \ActionScheduler::logger()->unhook_stored_action();
100 $this->destination_logger->unhook_stored_action();
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(
106 $destination_action_id,
107 sprintf(
108 /* translators: 1: source action ID 2: source store class 3: destination action ID 4: destination store class */
109 __( 'Migrated action with ID %1$d in %2$s to ID %3$d in %4$s', 'action-scheduler' ),
110 $source_action_id,
111 get_class( $this->source_store ),
112 $destination_action_id,
113 get_class( $this->destination_store )
114 )
115 );
116 }
117
118 if ( $this->progress_bar ) {
119 $this->progress_bar->tick();
120 }
121 }
122
123 if ( $this->progress_bar ) {
124 $this->progress_bar->finish();
125 }
126
127 \ActionScheduler::logger()->hook_stored_action();
128
129 do_action( 'action_scheduler/migration_batch_complete', $action_ids );
130 }
131
132 /**
133 * Initialize destination store and logger.
134 */
135 public function init_destination() {
136 $this->destination_store->init();
137 $this->destination_logger->init();
138 }
139 }
140