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 / Scheduler.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
Scheduler.php
129 lines
1 <?php
2
3
4 namespace Action_Scheduler\Migration;
5
6 /**
7 * Class Scheduler
8 *
9 * @package Action_Scheduler\WP_CLI
10 *
11 * @since 3.0.0
12 *
13 * @codeCoverageIgnore
14 */
15 class Scheduler {
16 /** Migration action hook. */
17 const HOOK = 'action_scheduler/migration_hook';
18
19 /** Migration action group. */
20 const GROUP = 'action-scheduler-migration';
21
22 /**
23 * Set up the callback for the scheduled job.
24 */
25 public function hook() {
26 add_action( self::HOOK, array( $this, 'run_migration' ), 10, 0 );
27 }
28
29 /**
30 * Remove the callback for the scheduled job.
31 */
32 public function unhook() {
33 remove_action( self::HOOK, array( $this, 'run_migration' ), 10 );
34 }
35
36 /**
37 * The migration callback.
38 */
39 public function run_migration() {
40 $migration_runner = $this->get_migration_runner();
41 $count = $migration_runner->run( $this->get_batch_size() );
42
43 if ( $count === 0 ) {
44 $this->mark_complete();
45 } else {
46 $this->schedule_migration( time() + $this->get_schedule_interval() );
47 }
48 }
49
50 /**
51 * Mark the migration complete.
52 */
53 public function mark_complete() {
54 $this->unschedule_migration();
55
56 \ActionScheduler_DataController::mark_migration_complete();
57 do_action( 'action_scheduler/migration_complete' );
58 }
59
60 /**
61 * Get a flag indicating whether the migration is scheduled.
62 *
63 * @return bool Whether there is a pending action in the store to handle the migration
64 */
65 public function is_migration_scheduled() {
66 $next = as_next_scheduled_action( self::HOOK );
67
68 return ! empty( $next );
69 }
70
71 /**
72 * Schedule the migration.
73 *
74 * @param int $when Optional timestamp to run the next migration batch. Defaults to now.
75 *
76 * @return string The action ID
77 */
78 public function schedule_migration( $when = 0 ) {
79 $next = as_next_scheduled_action( self::HOOK );
80
81 if ( ! empty( $next ) ) {
82 return $next;
83 }
84
85 if ( empty( $when ) ) {
86 $when = time() + MINUTE_IN_SECONDS;
87 }
88
89 return as_schedule_single_action( $when, self::HOOK, array(), self::GROUP );
90 }
91
92 /**
93 * Remove the scheduled migration action.
94 */
95 public function unschedule_migration() {
96 as_unschedule_action( self::HOOK, null, self::GROUP );
97 }
98
99 /**
100 * Get migration batch schedule interval.
101 *
102 * @return int Seconds between migration runs. Defaults to 0 seconds to allow chaining migration via Async Runners.
103 */
104 private function get_schedule_interval() {
105 return (int) apply_filters( 'action_scheduler/migration_interval', 0 );
106 }
107
108 /**
109 * Get migration batch size.
110 *
111 * @return int Number of actions to migrate in each batch. Defaults to 250.
112 */
113 private function get_batch_size() {
114 return (int) apply_filters( 'action_scheduler/migration_batch_size', 250 );
115 }
116
117 /**
118 * Get migration runner object.
119 *
120 * @return Runner
121 */
122 private function get_migration_runner() {
123 $config = Controller::instance()->get_migration_config_object();
124
125 return new Runner( $config );
126 }
127
128 }
129