MigrateCompletedMigrations.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\MigrationLog\Migrations; |
| 4 | |
| 5 | use Give\Framework\Migrations\Contracts\Migration; |
| 6 | use Give\MigrationLog\MigrationLogFactory; |
| 7 | use Give\MigrationLog\MigrationLogStatus; |
| 8 | |
| 9 | /** |
| 10 | * Class MigrateCompletedMigrations |
| 11 | * @package Give\MigrationLog\Migrations |
| 12 | * |
| 13 | * @since 2.10.0 |
| 14 | */ |
| 15 | class MigrateCompletedMigrations extends Migration |
| 16 | { |
| 17 | /** |
| 18 | * @var MigrationLogFactory |
| 19 | */ |
| 20 | private $migrationLogFactory; |
| 21 | |
| 22 | /** |
| 23 | * MigrateCompletedMigrations constructor. |
| 24 | * |
| 25 | * @param MigrationLogFactory $migrationLogFactory |
| 26 | */ |
| 27 | public function __construct(MigrationLogFactory $migrationLogFactory) |
| 28 | { |
| 29 | $this->migrationLogFactory = $migrationLogFactory; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @return string |
| 34 | */ |
| 35 | public static function id() |
| 36 | { |
| 37 | return 'migrate_completed_migrations'; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @return string |
| 42 | */ |
| 43 | public static function title() |
| 44 | { |
| 45 | return esc_html__('Migrate completed migrations to give_migrations table','give' ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return int |
| 50 | */ |
| 51 | public static function timestamp() |
| 52 | { |
| 53 | return strtotime('1970-01-02 00:00'); |
| 54 | } |
| 55 | |
| 56 | public function run() |
| 57 | { |
| 58 | $migrations = get_option('give_database_migrations', []); |
| 59 | |
| 60 | foreach ($migrations as $migrationId) { |
| 61 | $migrationLog = $this->migrationLogFactory->make($migrationId); |
| 62 | $migrationLog->setStatus(MigrationLogStatus::SUCCESS); |
| 63 | $migrationLog->save(); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 |