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