PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.1
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 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / lib / action-scheduler / classes / migration / Runner.php
sureforms / inc / lib / action-scheduler / classes / migration Last commit date
ActionMigrator.php 2 years ago ActionScheduler_DBStoreMigrator.php 2 years ago BatchFetcher.php 2 years ago Config.php 2 years ago Controller.php 2 years ago DryRun_ActionMigrator.php 2 years ago DryRun_LogMigrator.php 2 years ago LogMigrator.php 2 years ago Runner.php 2 years ago Scheduler.php 2 years ago
Runner.php
140 lines
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