MigrationRepository.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Persists applied migration class names in WordPress options and reads registered migrations from container tags. |
| 5 | * Tracks which migrations have run and supports rollback state queries. |
| 6 | * Bridges the migrator with WordPress option storage. |
| 7 | * |
| 8 | * @package Framework |
| 9 | * @subpackage Database\Migrations |
| 10 | * @since 1.0.0 |
| 11 | */ |
| 12 | namespace Kirki\Framework\Database\Migrations; |
| 13 | |
| 14 | \defined('ABSPATH') || exit; |
| 15 | use Kirki\Framework\Constants\OptionKeys; |
| 16 | use Kirki\Framework\Supports\Facades\Option; |
| 17 | use function Kirki\Framework\app; |
| 18 | class MigrationRepository |
| 19 | { |
| 20 | /** |
| 21 | * Get the previous migrations. |
| 22 | * |
| 23 | * @return array |
| 24 | * |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | public function get_previous_migrations() |
| 28 | { |
| 29 | return Option::get(OptionKeys::MIGRATIONS, []); |
| 30 | } |
| 31 | /** |
| 32 | * Update the migrations. |
| 33 | * |
| 34 | * @param array $migrations The migrations. |
| 35 | * |
| 36 | * @return void |
| 37 | * |
| 38 | * @since 1.0.0 |
| 39 | */ |
| 40 | public function update_migrations(array $migrations) |
| 41 | { |
| 42 | Option::set(OptionKeys::MIGRATIONS, $migrations); |
| 43 | } |
| 44 | /** |
| 45 | * Remove the migrations. |
| 46 | * |
| 47 | * @return void |
| 48 | * |
| 49 | * @since 1.0.0 |
| 50 | */ |
| 51 | public function remove_migrations() |
| 52 | { |
| 53 | Option::delete(OptionKeys::MIGRATIONS); |
| 54 | } |
| 55 | /** |
| 56 | * Get the registered migrations. |
| 57 | * |
| 58 | * @return array |
| 59 | * |
| 60 | * @since 1.0.0 |
| 61 | */ |
| 62 | public function get_registered_migrations() |
| 63 | { |
| 64 | return app()->tagged('app.migrations'); |
| 65 | } |
| 66 | /** |
| 67 | * Check if the rollback is enabled. |
| 68 | * |
| 69 | * @return bool |
| 70 | * |
| 71 | * @since 1.0.0 |
| 72 | */ |
| 73 | public function is_rollback_enabled() |
| 74 | { |
| 75 | return \true; |
| 76 | // @todo: will be handled later |
| 77 | } |
| 78 | } |
| 79 |