PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / trunk
Image Optimizer – Compress Images and Convert to WebP or AVIF vtrunk
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | vendor/woocommerce/action-scheduler/classes/migration/ActionMigrator.php +37 -20 1.2.1 → trunk View file →
@@ -12,23 +12,35 @@
12 12 *
13 13 * @codeCoverageIgnore
14 14 */
15 15 class ActionMigrator {
16 - /** var ActionScheduler_Store */
16 + /**
17 + * Source store instance.
18 + *
19 + * @var ActionScheduler_Store
20 + */
17 21 private $source;
18 22
19 - /** var ActionScheduler_Store */
23 + /**
24 + * Destination store instance.
25 + *
26 + * @var ActionScheduler_Store
27 + */
20 28 private $destination;
21 29
22 - /** var LogMigrator */
30 + /**
31 + * LogMigrator instance.
32 + *
33 + * @var LogMigrator
34 + */
23 35 private $log_migrator;
24 36
25 37 /**
26 38 * ActionMigrator constructor.
27 39 *
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.
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.
31 43 */
32 44 public function __construct( \ActionScheduler_Store $source_store, \ActionScheduler_Store $destination_store, LogMigrator $log_migrator ) {
33 45 $this->source = $source_store;
34 46 $this->destination = $destination_store;
@@ -40,8 +52,9 @@
40 52 *
41 53 * @param int $source_action_id Action ID.
42 54 *
43 55 * @return int 0|new action ID
56 + * @throws \RuntimeException When unable to delete action from the source store.
44 57 */
45 58 public function migrate( $source_action_id ) {
46 59 try {
47 60 $action = $this->source->fetch_action( $source_action_id );
@@ -51,17 +64,17 @@
51 64 $status = '';
52 65 }
53 66
54 67 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
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.
58 71 try {
59 72 $this->source->delete_action( $source_action_id );
60 - } catch ( \Exception $e ) {
61 - // nothing to do, it didn't exist in the first place
73 + } catch ( \Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
74 + // nothing to do, it didn't exist in the first place.
62 75 }
63 - do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination );
76 + do_action( 'action_scheduler/no_action_to_migrate', $source_action_id, $this->source, $this->destination ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
64 77
65 78 return 0;
66 79 }
67 80
@@ -66,24 +79,24 @@
66 79 }
67 80
68 81 try {
69 82
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;
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;
72 85
73 86 $destination_action_id = $this->destination->save_action( $action, null, $last_attempt_date );
74 87 } catch ( \Exception $e ) {
75 - do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination );
88 + do_action( 'action_scheduler/migrate_action_failed', $source_action_id, $this->source, $this->destination ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
76 89
77 - return 0; // could not save the action in the new store
90 + return 0; // could not save the action in the new store.
78 91 }
79 92
80 93 try {
81 94 switch ( $status ) {
82 - case \ActionScheduler_Store::STATUS_FAILED :
95 + case \ActionScheduler_Store::STATUS_FAILED:
83 96 $this->destination->mark_failure( $destination_action_id );
84 97 break;
85 - case \ActionScheduler_Store::STATUS_CANCELED :
98 + case \ActionScheduler_Store::STATUS_CANCELED:
86 99 $this->destination->cancel_action( $destination_action_id );
87 100 break;
88 101 }
89 102
@@ -91,18 +104,22 @@
91 104 $this->source->delete_action( $source_action_id );
92 105
93 106 $test_action = $this->source->fetch_action( $source_action_id );
94 107 if ( ! is_a( $test_action, 'ActionScheduler_NullAction' ) ) {
108 + // translators: %s is an action ID.
95 109 throw new \RuntimeException( sprintf( __( 'Unable to remove source migrated action %s', 'action-scheduler' ), $source_action_id ) );
96 110 }
97 - do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
111 + do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
98 112
99 113 return $destination_action_id;
100 114 } catch ( \Exception $e ) {
101 - // could not delete from the old store
115 + // could not delete from the old store.
102 116 $this->source->mark_migrated( $source_action_id );
117 +
118 + // phpcs:disable WordPress.NamingConventions.ValidHookName.UseUnderscores
103 119 do_action( 'action_scheduler/migrate_action_incomplete', $source_action_id, $destination_action_id, $this->source, $this->destination );
104 120 do_action( 'action_scheduler/migrated_action', $source_action_id, $destination_action_id, $this->source, $this->destination );
121 + // phpcs:enable
105 122
106 123 return $destination_action_id;
107 124 }
108 125 }