From ae136d9c511689fdb367c1cf97c788ea55fa9c2a Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 21:00:30 +0330 Subject: [PATCH] Formatting the given db_name internally --- app/Actions/FormattedBranchName.php | 2 +- app/Services/Forge/ForgeService.php | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Actions/FormattedBranchName.php b/app/Actions/FormattedBranchName.php index 24d09db..c239244 100644 --- a/app/Actions/FormattedBranchName.php +++ b/app/Actions/FormattedBranchName.php @@ -24,7 +24,7 @@ class FormattedBranchName protected const SLUGIFY_DICTIONARY = ['+' => '-', '_' => '-', '@' => '-']; - public function handle(string $branch, ?string $pattern): string + public function handle(string $branch, ?string $pattern = null): string { if (isset($pattern)) { preg_match($pattern, $branch, $matches); diff --git a/app/Services/Forge/ForgeService.php b/app/Services/Forge/ForgeService.php index da2fc7e..c866b17 100644 --- a/app/Services/Forge/ForgeService.php +++ b/app/Services/Forge/ForgeService.php @@ -16,6 +16,7 @@ use App\Actions\FormattedBranchName; use App\Actions\GenerateDomainName; use App\Actions\GenerateStandardizedBranchName; +use Illuminate\Support\Str; use Laravel\Forge\Forge; use Laravel\Forge\Resources\Server; use Laravel\Forge\Resources\Site; @@ -89,9 +90,13 @@ public function getSiteIsolationUsername(): string public function getFormattedDatabaseName(): string { - return $this->setting->dbName ?? GenerateStandardizedBranchName::run( - $this->getFormattedBranchName() - ); + if ($this->setting->dbName) { + $dbName = FormattedBranchName::run($this->setting->dbName); + } else { + $dbName = $this->getFormattedBranchName(); + } + + return Str::replace('-', '_', $dbName); } public function siteNginxTemplate(): string