From 3ef49104491dd108a03dc273aef563c25d31e07c Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Sun, 17 Mar 2024 16:42:36 -0400 Subject: [PATCH 1/9] Sluggify the database name --- app/Services/Forge/Pipeline/CreateDatabase.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Services/Forge/Pipeline/CreateDatabase.php b/app/Services/Forge/Pipeline/CreateDatabase.php index 85598b2..e7bcef3 100644 --- a/app/Services/Forge/Pipeline/CreateDatabase.php +++ b/app/Services/Forge/Pipeline/CreateDatabase.php @@ -13,6 +13,7 @@ namespace App\Services\Forge\Pipeline; +use App\Actions\FormattedBranchName; use App\Services\Forge\ForgeService; use App\Traits\Outputifier; use Closure; @@ -28,8 +29,13 @@ public function __invoke(ForgeService $service, Closure $next) return $next($service); } + if ( $service->setting->dbName ) { + $dbName = FormattedBranchName::run($service->setting->dbName); + } else { + $dbName = $service->getStandardizedBranchName(); + } + $dbPassword = Str::random(16); - $dbName = $service->setting->dbName ?? $service->getStandardizedBranchName(); if (! $this->databaseExists($service, $dbName)) { $this->information('Creating database.'); From 0fbe2c382975c8f51b4e6a4a477f7a417221b9e8 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Sun, 17 Mar 2024 21:16:04 -0400 Subject: [PATCH 2/9] Use existing GenerateStandardizedBranchName action --- app/Services/Forge/Pipeline/CreateDatabase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/Forge/Pipeline/CreateDatabase.php b/app/Services/Forge/Pipeline/CreateDatabase.php index e7bcef3..b7dcdce 100644 --- a/app/Services/Forge/Pipeline/CreateDatabase.php +++ b/app/Services/Forge/Pipeline/CreateDatabase.php @@ -13,7 +13,7 @@ namespace App\Services\Forge\Pipeline; -use App\Actions\FormattedBranchName; +use App\Actions\GenerateStandardizedBranchName; use App\Services\Forge\ForgeService; use App\Traits\Outputifier; use Closure; @@ -30,7 +30,7 @@ public function __invoke(ForgeService $service, Closure $next) } if ( $service->setting->dbName ) { - $dbName = FormattedBranchName::run($service->setting->dbName); + $dbName = GenerateStandardizedBranchName::run($service->setting->dbName); } else { $dbName = $service->getStandardizedBranchName(); } From 80366ec6369c626c83359dfc58f48821633bf001 Mon Sep 17 00:00:00 2001 From: Shawn Hooper Date: Sun, 17 Mar 2024 21:21:09 -0400 Subject: [PATCH 3/9] Refactor Pipeline & Service --- app/Services/Forge/ForgeService.php | 7 +++++++ app/Services/Forge/Pipeline/CreateDatabase.php | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Services/Forge/ForgeService.php b/app/Services/Forge/ForgeService.php index 93c7918..4df5952 100644 --- a/app/Services/Forge/ForgeService.php +++ b/app/Services/Forge/ForgeService.php @@ -87,6 +87,13 @@ public function getStandardizedBranchName(): string ); } + public function getFormattedDatabaseName(): string + { + return GenerateStandardizedBranchName::run( + $this->setting->dbName ?? $this->getFormattedBranchName() + ); + } + public function siteNginxTemplate(): string { return $this->forge->siteNginxFile($this->setting->server, $this->site->id); diff --git a/app/Services/Forge/Pipeline/CreateDatabase.php b/app/Services/Forge/Pipeline/CreateDatabase.php index b7dcdce..800e388 100644 --- a/app/Services/Forge/Pipeline/CreateDatabase.php +++ b/app/Services/Forge/Pipeline/CreateDatabase.php @@ -29,12 +29,7 @@ public function __invoke(ForgeService $service, Closure $next) return $next($service); } - if ( $service->setting->dbName ) { - $dbName = GenerateStandardizedBranchName::run($service->setting->dbName); - } else { - $dbName = $service->getStandardizedBranchName(); - } - + $dbName = $service->getFormattedDatabaseName(); $dbPassword = Str::random(16); if (! $this->databaseExists($service, $dbName)) { From 909abce6a446a672068667302fcb5698476f5a14 Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 16:28:37 +0330 Subject: [PATCH 4/9] Used formatted db name when removing database --- app/Services/Forge/Pipeline/RemoveDatabaseUser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Forge/Pipeline/RemoveDatabaseUser.php b/app/Services/Forge/Pipeline/RemoveDatabaseUser.php index fafb124..561d30b 100644 --- a/app/Services/Forge/Pipeline/RemoveDatabaseUser.php +++ b/app/Services/Forge/Pipeline/RemoveDatabaseUser.php @@ -24,7 +24,7 @@ class RemoveDatabaseUser public function __invoke(ForgeService $service, Closure $next) { foreach ($service->forge->databaseUsers($service->setting->server) as $databaseUser) { - if ($databaseUser->name === $service->getStandardizedBranchName()) { + if ($databaseUser->name === $service->getFormattedDatabaseName()) { $this->information('Removing database with user.'); foreach ($databaseUser->databases as $database) { From 0c33c41278ec7cfbcd112afd930a8613edd7ae83 Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 17:06:58 +0330 Subject: [PATCH 5/9] Updated the translations directory --- app/Providers/AppServiceProvider.php | 4 +--- config/app.php | 12 ++++++++++++ {lang => resources/lang}/en/valiadtion.php | 8 +++++--- 3 files changed, 18 insertions(+), 6 deletions(-) rename {lang => resources/lang}/en/valiadtion.php (98%) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 8a7af64..c3b24fd 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -11,9 +11,7 @@ class AppServiceProvider extends ServiceProvider { public function boot(): void { - $this->app->setLocale('en'); - - $this->loadTranslationsFrom(base_path('lang'), 'harbor'); + // } public function register(): void diff --git a/config/app.php b/config/app.php index dac24b1..08ad7c7 100644 --- a/config/app.php +++ b/config/app.php @@ -55,6 +55,18 @@ 'timezone' => 'UTC', + /* + |-------------------------------------------------------------------------- + | Application Locale Configuration + |-------------------------------------------------------------------------- + | + | The application locale determines the default locale that will be used + | by the translation service provider. You are free to set this value + | to any of the locales which will be supported by the application. + | + */ + 'locale' => 'en', + /* |-------------------------------------------------------------------------- | Autoloaded Service Providers diff --git a/lang/en/valiadtion.php b/resources/lang/en/valiadtion.php similarity index 98% rename from lang/en/valiadtion.php rename to resources/lang/en/valiadtion.php index 70407c9..629bb80 100644 --- a/lang/en/valiadtion.php +++ b/resources/lang/en/valiadtion.php @@ -163,8 +163,8 @@ */ 'custom' => [ - 'attribute-name' => [ - 'rule-name' => 'custom-message', + 'db_name' => [ + 'regex' => 'The :attribute must only contain letters, numbers, and underscores.', ], ], @@ -179,6 +179,8 @@ | */ - 'attributes' => [], + 'attributes' => [ + 'db_name' => 'Database name' + ], ]; From d5cc0ebdf6ae348e0136020fd57e040cefcbe9e4 Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 17:11:02 +0330 Subject: [PATCH 6/9] Added regex validation rule for db_name --- app/Services/Forge/ForgeService.php | 4 ++-- app/Services/Forge/ForgeSetting.php | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Services/Forge/ForgeService.php b/app/Services/Forge/ForgeService.php index 4df5952..4a1bff9 100644 --- a/app/Services/Forge/ForgeService.php +++ b/app/Services/Forge/ForgeService.php @@ -89,8 +89,8 @@ public function getStandardizedBranchName(): string public function getFormattedDatabaseName(): string { - return GenerateStandardizedBranchName::run( - $this->setting->dbName ?? $this->getFormattedBranchName() + return $this->setting->dbName ?? GenerateStandardizedBranchName::run( + $this->getFormattedBranchName() ); } diff --git a/app/Services/Forge/ForgeSetting.php b/app/Services/Forge/ForgeSetting.php index 12b22f4..81d0d84 100644 --- a/app/Services/Forge/ForgeSetting.php +++ b/app/Services/Forge/ForgeSetting.php @@ -201,7 +201,7 @@ class ForgeSetting 'site_isolation_required' => ['boolean'], 'job_scheduler_required' => ['boolean'], 'db_creation_required' => ['boolean'], - 'db_name' => ['nullable', 'string'], + 'db_name' => ['nullable', 'string', 'regex:/^[a-zA-Z0-9_]+$/'], 'auto_source_required' => ['boolean'], 'ssl_required' => ['boolean'], 'wait_on_ssl' => ['boolean'], @@ -224,7 +224,14 @@ public function __construct() private function init(array $configurations): void { - $validator = Validator::make($configurations, $this->validationRules); + $validator = Validator::make( + $configurations, + $this->validationRules, + [ + 'db_name.regex' => 'The :attribute must only contain letters, numbers, and underscores.' + ], + ['db_name' => 'Database name'] + ); throw_if($validator->fails(), ValidationException::class, $validator->errors()->all()); From ed9441405d7bed69935f14ae806bb3466c0b6a01 Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 17:11:59 +0330 Subject: [PATCH 7/9] Renamed the site isolation username function --- app/Services/Forge/ForgeService.php | 2 +- app/Services/Forge/Pipeline/OrCreateNewSite.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Services/Forge/ForgeService.php b/app/Services/Forge/ForgeService.php index 4a1bff9..fe081cc 100644 --- a/app/Services/Forge/ForgeService.php +++ b/app/Services/Forge/ForgeService.php @@ -80,7 +80,7 @@ public function getFormattedDomainName(): string ); } - public function getStandardizedBranchName(): string + public function getSiteIsolationUsername(): string { return GenerateStandardizedBranchName::run( $this->getFormattedBranchName() diff --git a/app/Services/Forge/Pipeline/OrCreateNewSite.php b/app/Services/Forge/Pipeline/OrCreateNewSite.php index a4130dc..b90729c 100644 --- a/app/Services/Forge/Pipeline/OrCreateNewSite.php +++ b/app/Services/Forge/Pipeline/OrCreateNewSite.php @@ -54,7 +54,7 @@ private function gatherSiteData(ForgeService $service): array $this->information('---> Enabling site isolation.'); $data['isolated'] = true; - $data['username'] = $service->getStandardizedBranchName(); + $data['username'] = $service->getSiteIsolationUsername(); } return $data; From 274e0ad9109887211c842a1ae02b6f3823709a03 Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 19:47:20 +0330 Subject: [PATCH 8/9] Updated db_name validation attribute name --- app/Services/Forge/ForgeSetting.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/Forge/ForgeSetting.php b/app/Services/Forge/ForgeSetting.php index 81d0d84..0e9b01b 100644 --- a/app/Services/Forge/ForgeSetting.php +++ b/app/Services/Forge/ForgeSetting.php @@ -230,7 +230,7 @@ private function init(array $configurations): void [ 'db_name.regex' => 'The :attribute must only contain letters, numbers, and underscores.' ], - ['db_name' => 'Database name'] + ['db_name' => 'FORGE_DB_NAME'] ); throw_if($validator->fails(), ValidationException::class, $validator->errors()->all()); From fb51fdcb4600dbead43748fd73f51b50fee94ac3 Mon Sep 17 00:00:00 2001 From: Mehran Date: Mon, 18 Mar 2024 19:48:11 +0330 Subject: [PATCH 9/9] Updated db_name validation attribute name for validation.php --- resources/lang/en/valiadtion.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/valiadtion.php b/resources/lang/en/valiadtion.php index 629bb80..c7ebe56 100644 --- a/resources/lang/en/valiadtion.php +++ b/resources/lang/en/valiadtion.php @@ -180,7 +180,7 @@ */ 'attributes' => [ - 'db_name' => 'Database name' + 'db_name' => 'FORGE_DB_NAME' ], ];