migration_job.php
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Migration_Job extends WP_Async_Request |
| 6 | { |
| 7 | /** |
| 8 | * @var string |
| 9 | */ |
| 10 | protected $action = 'iawp_database_migration'; |
| 11 | |
| 12 | /** |
| 13 | * Handle |
| 14 | * |
| 15 | * Override this method to perform any actions required |
| 16 | * during the async request. |
| 17 | * |
| 18 | * @return void |
| 19 | */ |
| 20 | protected function handle(): void |
| 21 | { |
| 22 | Migration::create_or_migrate(); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Dispatch a migration job if the database is out of date and no migration is currently running |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public static function maybe_dispatch(): void |
| 31 | { |
| 32 | if (Migration::should_migrate()) { |
| 33 | $migration_job = new self(); |
| 34 | $migration_job->dispatch(); |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 |