| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPFunnels\Admin\Migrations; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class AbstractMigrations |
| 7 |
* |
| 8 |
* Abstract class that provides common functionality for migration classes. |
| 9 |
* |
| 10 |
* @package WPFunnels\Admin\Migrations |
| 11 |
* @since 3.5.0 |
| 12 |
*/ |
| 13 |
abstract class AbstractMigrations |
| 14 |
{ |
| 15 |
|
| 16 |
/** |
| 17 |
* Migration key. |
| 18 |
* |
| 19 |
* @var string |
| 20 |
* @since 3.5.0 |
| 21 |
*/ |
| 22 |
public $key; |
| 23 |
|
| 24 |
|
| 25 |
/** |
| 26 |
* Check if the migration should be enqueued. |
| 27 |
* |
| 28 |
* Determines if the migration process should be added to the queue. |
| 29 |
* |
| 30 |
* @return bool |
| 31 |
* |
| 32 |
* @since 3.5.0 |
| 33 |
*/ |
| 34 |
public function should_enqueue_migration_instance() |
| 35 |
{ |
| 36 |
$is_migration_completed = $this->is_migration_completed(); |
| 37 |
if ('completed' === $is_migration_completed) { |
| 38 |
return false; |
| 39 |
} |
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* Check if the migration is completed. |
| 46 |
* |
| 47 |
* @return string The status of the migration. |
| 48 |
* |
| 49 |
* @since 3.5.0 |
| 50 |
*/ |
| 51 |
public function is_migration_completed() |
| 52 |
{ |
| 53 |
return get_option("wpfunnels_" . $this->key . "_status", ''); |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
/** |
| 58 |
* Set the migration status. |
| 59 |
* |
| 60 |
* @param string $status The status to set. |
| 61 |
* |
| 62 |
* @since 3.5.0 |
| 63 |
*/ |
| 64 |
public function set_migration_status($status) |
| 65 |
{ |
| 66 |
update_option("wpfunnels_" . $this->key . "_status", $status); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* Check if the migration is on the queue. |
| 72 |
* |
| 73 |
* @return bool True if the migration is running, false otherwise. |
| 74 |
* |
| 75 |
* @since 3.5.0 |
| 76 |
*/ |
| 77 |
public function is_on_queue() |
| 78 |
{ |
| 79 |
return get_option("wpfunnels_" . $this->key . "_status", '') === 'running'; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
/** |
| 84 |
* Set the batch number. |
| 85 |
* |
| 86 |
* @param int $batch The batch number to set. |
| 87 |
* |
| 88 |
* @since 3.5.0 |
| 89 |
*/ |
| 90 |
public function set_batch($batch) |
| 91 |
{ |
| 92 |
update_option("wpfunnels_" . $this->key . "_batch", $batch); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/** |
| 97 |
* Get the next batch to process. |
| 98 |
* |
| 99 |
* @return mixed The next batch to process. |
| 100 |
* |
| 101 |
* @since 3.5.0 |
| 102 |
*/ |
| 103 |
abstract function get_next_batch_to_process(); |
| 104 |
} |
| 105 |
|