PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.11.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.11.0
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 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.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes / migration / ActionMigrator.php
wp-mail-smtp / vendor / woocommerce / 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
ActionMigrator.php
110 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 /** var ActionScheduler_Store */
17 private $source;
18
19 /** var ActionScheduler_Store */
20 private $destination;
21
22 /** var LogMigrator */
23 private $log_migrator;
24
25 /**
26 * ActionMigrator constructor.
27 *
28 * @param ActionScheduler_Store $source_store Source store object.
29 * @param ActionScheduler_Store $destination_store Destination store object.
30 * @param LogMigrator $log_migrator Log migrator object.
31 */
32 public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
33 $this->source = $source_store;
34 $this->destination = $destination_store;
35 $this->log_migrator = $log_migrator;
36 }
37
38 /**
39 * Migrate an action.
40 *
41 * @param int $source_action_id Action ID.
42 *
43 * @return int 0|new action ID
44 */
45 public function migrate( $source_action_id ) {
46 try {
47 $action = $this->source->fetch_action( $source_action_id );
48 $status = $this->source->get_status( $source_action_id );
49 } catch ( \Exception $e ) {
50 $action = null;
51 $status = '';
52 }
53
54 if ( is_null( $action ) || empty( $status ) || ! $action->get_schedule()->get_date() ) {
55 // null action or empty status means the fetch operation failed or the action didn't exist
56 // null schedule means it's missing vital data
57 // delete it and move on
58 try {
59 $this->source->delete_action( $source_action_id );
60 } catch ( \Exception $e ) {
61 // nothing to do, it didn't exist in the first place
62 }
63 do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
64
65 return 0;
66 }
67
68 try {
69
70 // Make sure the last attempt date is set correctly for completed and failed actions
71 $last_attempt_date = ( $status !== \ActionScheduler_Store::STATUS_PENDING ) ? $this->source->get_date( $source_action_id ) : null;
72
73 $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date );
74 } catch ( \Exception $e ) {
75 do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination );
76
77 return 0; // could not save the action in the new store
78 }
79
80 try {
81 switch ( $status ) {
82 case \ActionScheduler_Store::STATUS_FAILED :
83 $this->destination->mark_failure( $destination_action_id );
84 break;
85 case \ActionScheduler_Store::STATUS_CANCELED :
86 $this->destination->cancel_action( $destination_action_id );
87 break;
88 }
89
90 $this->log_migrator->migrate( $source_action_id, $destination_action_id );
91 $this->source->delete_action( $source_action_id );
92
93 $test_action = $this->source->fetch_action( $source_action_id );
94 if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
95 throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) );
96 }
97 do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
98
99 return $destination_action_id;
100 } catch ( \Exception $e ) {
101 // could not delete from the old store
102 $this->source->mark_migrated( $source_action_id );
103 do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination );
104 do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
105
106 return $destination_action_id;
107 }
108 }
109 }
110