From cd959b7e55ce93aeed222ceb7cc23361ca008999 Mon Sep 17 00:00:00 2001 From: flashwave Date: Sun, 1 Jan 2023 03:50:41 +0000 Subject: [PATCH] Forgot to CTRL+S this file, oops! --- src/Console/Commands/MigrateCommand.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Console/Commands/MigrateCommand.php b/src/Console/Commands/MigrateCommand.php index a5a82d4..768abbd 100644 --- a/src/Console/Commands/MigrateCommand.php +++ b/src/Console/Commands/MigrateCommand.php @@ -15,18 +15,21 @@ class MigrateCommand implements CommandInterface { } public function dispatch(CommandArgs $args): void { + if($args->getArg(0) === 'rollback') { + echo 'Migration rollback is gone.' . PHP_EOL; + return; + } + touch(MSZ_ROOT . '/.migrating'); chmod(MSZ_ROOT . '/.migrating', 0777); - echo "Creating migration manager.." . PHP_EOL; - $migrationManager = new DatabaseMigrationManager(DB::getPDO(), MSZ_ROOT . '/database'); - $migrationManager->setLogger(function ($log) { - echo $log . PHP_EOL; - }); + try { + echo "Creating migration manager.." . PHP_EOL; + $migrationManager = new DatabaseMigrationManager(DB::getPDO(), MSZ_ROOT . '/database'); + $migrationManager->setLogger(function ($log) { + echo $log . PHP_EOL; + }); - if($args->getArg(0) === 'rollback') { - echo 'Migration rollback is gone.' . PHP_EOL; - } else { $migrationManager->migrate(); $errors = $migrationManager->getErrors(); @@ -39,8 +42,8 @@ class MigrateCommand implements CommandInterface { foreach($errors as $error) echo $error . PHP_EOL; } + } finally { + unlink(MSZ_ROOT . '/.migrating'); } - - unlink(MSZ_ROOT . '/.migrating'); } }