An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(domains): allow a new dns check to replace a stored result
pkonejerob154814d272a
diff --git a/app/Livewire/Project/Application/Domains.php b/app/Livewire/Project/Application/Domains.phpindex 929c02e93e..3903a7c6d4 100644--- a/app/Livewire/Project/Application/Domains.php+++ b/app/Livewire/Project/Application/Domains.php@@ -775,8 +775,11 @@ class Domains extends Component/*** Persist current domain row DNS results and drop statuses for removed domains.+ *+ * @param array<int, string> $startingCheckKeys Status keys whose check is being started by this call.+ * They are allowed to replace a stored completed result.*/- protected function persistDomainDnsStatuses(): void+ protected function persistDomainDnsStatuses(array $startingCheckKeys = []): void{$statuses = [];@@ -808,11 +811,15 @@ class Domains extends Component];}- DB::transaction(function () use (&$statuses): void {+ DB::transaction(function () use (&$statuses, $startingCheckKeys): void {$application = Application::query()->lockForUpdate()->findOrFail($this->application->id);$storedStatuses = $application->domain_dns_statuses ?? [];foreach ($statuses as $key => $status) {+ if (in_array($key, $startingCheckKeys, true)) {+ continue;+ }+$localCheckId = $status['check_id'] ?? null;$storedCheckId = $storedStatuses[$key]['check_id'] ?? null;@@ -1054,7 +1061,7 @@ class Domains extends Componentforeach ($dnsChecks as $dnsCheck) {$this->markUrlsAsChecking([$dnsCheck['url']], $serviceForCheck, $dnsCheck['check_id']);}- $this->persistDomainDnsStatuses();+ $this->persistDomainDnsStatuses($dnsChecks->pluck('status_key')->all());$failedDnsChecks = 0;foreach ($dnsChecks as $dnsCheck) {@@ -1207,7 +1214,7 @@ class Domains extends Componentforeach ($this->dnsEntriesForUrls($urls, $service) as $statusKey => $url) {$checkId = new_public_id();$this->markUrlsAsChecking([$url], $service, $checkId);- $this->persistDomainDnsStatuses();+ $this->persistDomainDnsStatuses([$statusKey]);try {CheckDomainDnsJob::dispatch(diff --git a/app/Livewire/Project/Service/Domains.php b/app/Livewire/Project/Service/Domains.phpindex 79c89322a7..8e3402d291 100644--- a/app/Livewire/Project/Service/Domains.php+++ b/app/Livewire/Project/Service/Domains.php@@ -577,7 +577,11 @@ class Domains extends Component$this->persistAllDomainDnsStatuses();}- protected function persistAllDomainDnsStatuses(): void+ /**+ * @param array<int, string> $startingCheckKeys Status keys whose check is being started by this call.+ * They are allowed to replace a stored completed result.+ */+ protected function persistAllDomainDnsStatuses(array $startingCheckKeys = []): void{$byApp = [];@@ -617,11 +621,15 @@ class Domains extends Component->all();$statuses = array_intersect_key($statuses, array_flip($currentUrls));- DB::transaction(function () use ($app, &$statuses): void {+ DB::transaction(function () use ($app, &$statuses, $startingCheckKeys): void {$application = ServiceApplication::query()->lockForUpdate()->findOrFail($app->id);$storedStatuses = $application->domain_dns_statuses ?? [];foreach ($statuses as $key => $status) {+ if (in_array($key, $startingCheckKeys, true)) {+ continue;+ }+$localCheckId = $status['check_id'] ?? null;$storedCheckId = $storedStatuses[$key]['check_id'] ?? null;@@ -1096,7 +1104,7 @@ class Domains extends Componentforeach ($dnsChecks as $dnsCheck) {$this->markUrlsAsChecking([$dnsCheck['url']], $serviceApplicationId, $dnsCheck['check_id']);}- $this->persistAllDomainDnsStatuses();+ $this->persistAllDomainDnsStatuses($dnsChecks->pluck('url')->all());$failedDnsChecks = 0;foreach ($dnsChecks as $dnsCheck) {@@ -1657,7 +1665,7 @@ class Domains extends Componentforeach (array_unique($urls) as $url) {$checkId = new_public_id();$this->markUrlsAsChecking([$url], (int) $application->id, $checkId);- $this->persistAllDomainDnsStatuses();+ $this->persistAllDomainDnsStatuses([$url]);try {CheckDomainDnsJob::dispatch(diff --git a/tests/Feature/ApplicationDomainsTest.php b/tests/Feature/ApplicationDomainsTest.phpindex 74c9db670f..183073366b 100644--- a/tests/Feature/ApplicationDomainsTest.php+++ b/tests/Feature/ApplicationDomainsTest.php@@ -3537,3 +3537,64 @@ it('prevents members from cancelling protected application redirect conflict sta->set('showDomainConflictModal', false)->assertForbidden();});++it('restarts a dns check when the domain already has a completed result', function () {+ Queue::fake();++ $url = 'https://dns-recheck.example.com';+ $this->application->update([+ 'fqdn' => $url,+ 'domain_dns_statuses' => [+ $url => [+ 'status' => 'failed',+ 'message' => 'Required DNS record type A pointing to 203.0.113.10',+ 'expected_ip' => '203.0.113.10',+ 'checked_at' => now()->subDay()->toIso8601String(),+ ],+ ],+ ]);++ Livewire::test(Domains::class, ['application' => $this->application->fresh()])+ ->call('checkDomainDns', 0)+ ->assertSet('domainRows.0.dns_status', 'checking');++ expect($this->application->fresh()->domain_dns_statuses[$url]['status'])->toBe('checking');++ Queue::assertPushed(CheckDomainDnsJob::class);+});++it('does not overwrite a completed dns result with stale checking state', function () {+ $url = 'https://dns-stale.example.com';+ $this->application->update([+ 'fqdn' => $url,+ 'domain_dns_statuses' => [+ $url => [+ 'status' => 'checking',+ 'message' => 'Checking DNS...',+ 'check_id' => 'stale-check',+ ],+ ],+ ]);++ $component = Livewire::test(Domains::class, ['application' => $this->application->fresh()]);++ $this->application->update([+ 'domain_dns_statuses' => [+ $url => [+ 'status' => 'ok',+ 'message' => 'DNS looks correct.',+ 'check_id' => 'completed-check',+ ],+ ],+ ]);++ $method = new ReflectionMethod($component->instance(), 'persistDomainDnsStatuses');+ $method->invoke($component->instance());++ expect($this->application->fresh()->domain_dns_statuses[$url])+ ->toMatchArray([+ 'status' => 'ok',+ 'message' => 'DNS looks correct.',+ 'check_id' => 'completed-check',+ ]);+});diff --git a/tests/Feature/ServiceDomainsTest.php b/tests/Feature/ServiceDomainsTest.phpindex dc07e204de..8e74ded5fe 100644--- a/tests/Feature/ServiceDomainsTest.php+++ b/tests/Feature/ServiceDomainsTest.php@@ -1319,3 +1319,31 @@ it('lays out the domain settings dropdowns in responsive columns', function () {expect($view)->toContain('mt-4 grid grid-cols-1 gap-4 border-t border-neutral-200 pt-4 sm:grid-cols-2')->toContain('flex flex-wrap items-center justify-between gap-2');});++it('restarts a service dns check when the domain already has a completed result', function () {+ Queue::fake();++ $domain = 'https://api.example.com';+ $this->apiApp->update([+ 'domain_dns_statuses' => [+ $domain => [+ 'status' => 'failed',+ 'message' => 'Required DNS record type A pointing to 203.0.113.10',+ 'expected_ip' => '203.0.113.10',+ 'checked_at' => now()->subDay()->toIso8601String(),+ ],+ ],+ ]);++ $component = Livewire::test(Domains::class, ['service' => $this->service->fresh(['applications', 'server'])]);+ $index = collect($component->get('domainRows'))->search(fn (array $row): bool => $row['url'] === $domain);++ expect($index)->not->toBeFalse();++ $component->call('checkDomainDns', $index)+ ->assertSet("domainRows.{$index}.dns_status", 'checking');++ expect($this->apiApp->fresh()->domain_dns_statuses[$domain]['status'])->toBe('checking');++ Queue::assertPushed(CheckDomainDnsJob::class);+});