PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.0
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.0
1.7.2 1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / vendor / woocommerce / action-scheduler / classes / migration / Scheduler.php
hostinger-reach / vendor / woocommerce / action-scheduler / classes / migration Last commit date
ActionMigrator.php 10 months ago ActionScheduler_DBStoreMigrator.php 10 months ago BatchFetcher.php 10 months ago Config.php 10 months ago Controller.php 10 months ago DryRun_ActionMigrator.php 10 months ago DryRun_LogMigrator.php 10 months ago LogMigrator.php 10 months ago Runner.php 10 months ago Scheduler.php 10 months 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 ( 0 === $count ) {
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' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
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 ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
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 ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
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