From a9e5554dea7d948abcbf60d75f1d5c9d9c06008e Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 27 May 2021 16:14:13 -0400 Subject: [PATCH] Trap migration error for modules if they don't exist --- app/Services/Installer/MigrationService.php | 14 +++++++++----- app/Services/ModuleService.php | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Services/Installer/MigrationService.php b/app/Services/Installer/MigrationService.php index c3dc6908..9ff83a6e 100644 --- a/app/Services/Installer/MigrationService.php +++ b/app/Services/Installer/MigrationService.php @@ -77,7 +77,7 @@ class MigrationService extends Service * Run all of the migrations that are available. Just call artisan since * it looks into all of the module directories, etc */ - public function runAllMigrations() + public function runAllMigrations(): string { // A little ugly, run the main migration first, this makes sure the migration table is there $output = ''; @@ -92,10 +92,14 @@ class MigrationService extends Service $migrator = $this->getMigrator(); $availMigrations = $this->migrationsAvailable(); - Log::info('Running '.count($availMigrations).' available migrations'); - $ret = $migrator->run($availMigrations); - Log::info('Ran '.count($ret).' migrations'); + if (count($availMigrations) > 0) { + Log::info('Running '.count($availMigrations).' available migrations'); + $ret = $migrator->run($availMigrations); + Log::info('Ran '.count($ret).' migrations'); - return $output."\n".implode("\n", $ret); + return $output."\n".implode("\n", $ret); + } + + return $output; } } diff --git a/app/Services/ModuleService.php b/app/Services/ModuleService.php index b9b4c7fd..ca485477 100644 --- a/app/Services/ModuleService.php +++ b/app/Services/ModuleService.php @@ -126,7 +126,11 @@ class ModuleService extends Service 'enabled' => 1, ]); - Artisan::call('module:migrate '.$module_name, ['--force' => true]); + try { + Artisan::call('module:migrate '.$module_name, ['--force' => true]); + } catch (Exception $e) { + Log::error('Error running migration for '.$module_name.'; error='.$e); + } return true; }