PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.1
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / vendor / woocommerce / action-scheduler / classes / migration / ActionMigrator.php
jetformbuilder / vendor / woocommerce / action-scheduler / classes / migration Last commit date
ActionMigrator.php 1 year ago ActionScheduler_DBStoreMigrator.php 1 year ago BatchFetcher.php 1 year ago Config.php 1 year ago Controller.php 1 year ago DryRun_ActionMigrator.php 1 year ago DryRun_LogMigrator.php 1 year ago LogMigrator.php 1 year ago Runner.php 1 year ago Scheduler.php 1 year ago
ActionMigrator.php
127 lines
1 <?php
2
3
4 namespace Action_Scheduler\Migration;
5
6 /**
7 * Class ActionMigrator
8 *
9 * @package Action_Scheduler\Migration
10 *
11 * @since 3.0.0
12 *
13 * @codeCoverageIgnore
14 */
15 class ActionMigrator {
16 /**
17 * Source store instance.
18 *
19 * @var ActionScheduler_Store
20 */
21 private $source;
22
23 /**
24 * Destination store instance.
25 *
26 * @var ActionScheduler_Store
27 */
28 private $destination;
29
30 /**
31 * LogMigrator instance.
32 *
33 * @var LogMigrator
34 */
35 private $log_migrator;
36
37 /**
38 * ActionMigrator constructor.
39 *
40 * @param \ActionScheduler_Store $source_store Source store object.
41 * @param \ActionScheduler_Store $destination_store Destination store object.
42 * @param LogMigrator $log_migrator Log migrator object.
43 */
44 public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
45 $this->source = $source_store;
46 $this->destination = $destination_store;
47 $this->log_migrator = $log_migrator;
48 }
49
50 /**
51 * Migrate an action.
52 *
53 * @param int $source_action_id Action ID.
54 *
55 * @return int 0|new action ID
56 * @throws \RuntimeException When unable to delete action from the source store.
57 */
58 public function migrate( $source_action_id ) {
59 try {
60 $action = $this->source->fetch_action( $source_action_id );
61 $status = $this->source->get_status( $source_action_id );
62 } catch ( \Exception $e ) {
63 $action = null;
64 $status = '';
65 }
66
67 if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
68 // null action or empty status means the fetch operation failed or the action didn't exist.
69 // null schedule means it's missing vital data.
70 // delete it and move on.
71 try {
72 $this->source->delete_action( $source_action_id );
73 } catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
74 // nothing to do, it didn't exist in the first place.
75 }
76 do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
77
78 return 0;
79 }
80
81 try {
82
83 // Make sure the last attempt date is set correctly for completed and failed actions.
84 $last_attempt_date = ( \ActionScheduler_Store::STATUS_PENDING !== $status ) ? $this->source->get_date( $source_action_id ) : null;
85
86 $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date );
87 } catch ( \Exception $e ) {
88 do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
89
90 return 0; // could not save the action in the new store.
91 }
92
93 try {
94 switch ( $status ) {
95 case \ActionScheduler_Store::STATUS_FAILED:
96 $this->destination->mark_failure( $destination_action_id );
97 break;
98 case \ActionScheduler_Store::STATUS_CANCELED:
99 $this->destination->cancel_action( $destination_action_id );
100 break;
101 }
102
103 $this->log_migrator->migrate( $source_action_id, $destination_action_id );
104 $this->source->delete_action( $source_action_id );
105
106 $test_action = $this->source->fetch_action( $source_action_id );
107 if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
108 // translators: %s is an action ID.
109 throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) );
110 }
111 do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
112
113 return $destination_action_id;
114 } catch ( \Exception $e ) {
115 // could not delete from the old store.
116 $this->source->mark_migrated( $source_action_id );
117
118 // phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
119 do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination );
120 do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
121 // phpcs:enable
122
123 return $destination_action_id;
124 }
125 }
126 }
127