mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-05 22:24:24 +00:00
fix(livewire): scope DatabaseProxyStopped to proxy fields, harden status trait
Clickhouse, Dragonfly, and Keydb still called syncData() inside the DatabaseProxyStopped broadcast handler, clobbering in-progress edits to name/description/credentials. Refresh only is_public/public_port/ public_port_timeout instead, matching the pattern used elsewhere. Also null-guard HasDatabaseStatusInfo::getListeners() against an absent Auth::user()/currentTeam(), add explicit return types on getListeners() and render(), and convert inline comments in the SSL refresh test to a PHPDoc block.
This commit is contained in:
@@ -192,9 +192,12 @@ class General extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function databaseProxyStopped()
|
||||
public function databaseProxyStopped(): void
|
||||
{
|
||||
$this->syncData();
|
||||
$this->database->refresh();
|
||||
$this->isPublic = $this->database->is_public;
|
||||
$this->publicPort = $this->database->public_port;
|
||||
$this->publicPortTimeout = $this->database->public_port_timeout;
|
||||
$this->dispatch('databaseUpdated');
|
||||
}
|
||||
|
||||
|
||||
@@ -184,9 +184,12 @@ class General extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function databaseProxyStopped()
|
||||
public function databaseProxyStopped(): void
|
||||
{
|
||||
$this->syncData();
|
||||
$this->database->refresh();
|
||||
$this->isPublic = $this->database->is_public;
|
||||
$this->publicPort = $this->database->public_port;
|
||||
$this->publicPortTimeout = $this->database->public_port_timeout;
|
||||
$this->dispatch('databaseUpdated');
|
||||
}
|
||||
|
||||
|
||||
@@ -189,9 +189,12 @@ class General extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function databaseProxyStopped()
|
||||
public function databaseProxyStopped(): void
|
||||
{
|
||||
$this->syncData();
|
||||
$this->database->refresh();
|
||||
$this->isPublic = $this->database->is_public;
|
||||
$this->publicPort = $this->database->public_port;
|
||||
$this->publicPortTimeout = $this->database->public_port_timeout;
|
||||
$this->dispatch('databaseUpdated');
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Traits;
|
||||
use App\Helpers\SslHelper;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
@@ -51,16 +52,23 @@ trait HasDatabaseStatusInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getListeners()
|
||||
public function getListeners(): array
|
||||
{
|
||||
$userId = Auth::id();
|
||||
$teamId = Auth::user()->currentTeam()->id;
|
||||
$listeners = ['databaseUpdated' => 'refresh'];
|
||||
|
||||
return [
|
||||
"echo-private:user.{$userId},DatabaseStatusChanged" => 'refresh',
|
||||
"echo-private:team.{$teamId},ServiceChecked" => 'refresh',
|
||||
'databaseUpdated' => 'refresh',
|
||||
];
|
||||
$user = Auth::user();
|
||||
if (! $user) {
|
||||
return $listeners;
|
||||
}
|
||||
|
||||
$listeners["echo-private:user.{$user->id},DatabaseStatusChanged"] = 'refresh';
|
||||
|
||||
$team = $user->currentTeam();
|
||||
if ($team) {
|
||||
$listeners["echo-private:team.{$team->id},ServiceChecked"] = 'refresh';
|
||||
}
|
||||
|
||||
return $listeners;
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
@@ -150,7 +158,7 @@ trait HasDatabaseStatusInfo
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.project.database.status-info', [
|
||||
'label' => $this->databaseLabel(),
|
||||
|
||||
@@ -78,11 +78,13 @@ it('does not subscribe the form to status broadcasts when display lives in a sib
|
||||
->not->toHaveKey("echo-private:team.{$this->team->id},ServiceStatusChanged");
|
||||
})->with('database-general-forms-without-broadcasts');
|
||||
|
||||
/**
|
||||
* Resolve a Livewire component's listeners regardless of whether the subclass
|
||||
* exposes getListeners() publicly or only declares a $listeners array — the
|
||||
* HandlesEvents trait keeps getListeners() protected by default.
|
||||
*/
|
||||
function resolveLivewireListeners(object $component): array
|
||||
{
|
||||
// Livewire's HandlesEvents trait declares getListeners() as protected,
|
||||
// so subclasses that override it as public are callable directly, but
|
||||
// subclasses that rely on $listeners are not. Reflection handles both.
|
||||
$method = new ReflectionMethod($component, 'getListeners');
|
||||
$method->setAccessible(true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user