diff --git a/app/Events/BackupCreated.php b/app/Events/BackupCreated.php new file mode 100644 index 000000000..41d0afcbc --- /dev/null +++ b/app/Events/BackupCreated.php @@ -0,0 +1,34 @@ +user()->currentTeam()->id ?? null; + } + if (is_null($teamId)) { + throw new \Exception("Team id is null"); + } + $this->teamId = $teamId; + } + + public function broadcastOn(): array + { + return [ + new PrivateChannel("team.{$this->teamId}"), + ]; + } +} diff --git a/app/Events/DatabaseStatusChanged.php b/app/Events/DatabaseStatusChanged.php index 9c1e54cfd..8f83406f4 100644 --- a/app/Events/DatabaseStatusChanged.php +++ b/app/Events/DatabaseStatusChanged.php @@ -28,7 +28,7 @@ public function __construct($userId = null) public function broadcastOn(): array { return [ - new PrivateChannel("custom.{$this->userId}"), + new PrivateChannel("user.{$this->userId}"), ]; } } diff --git a/app/Events/ServiceStatusChanged.php b/app/Events/ServiceStatusChanged.php index d5de9f3a7..3fe849190 100644 --- a/app/Events/ServiceStatusChanged.php +++ b/app/Events/ServiceStatusChanged.php @@ -28,7 +28,7 @@ public function __construct($userId = null) public function broadcastOn(): array { return [ - new PrivateChannel("custom.{$this->userId}"), + new PrivateChannel("user.{$this->userId}"), ]; } } diff --git a/app/Events/TestEvent.php b/app/Events/TestEvent.php index 2a4c138f6..df677ba7a 100644 --- a/app/Events/TestEvent.php +++ b/app/Events/TestEvent.php @@ -22,7 +22,7 @@ public function __construct() public function broadcastOn(): array { return [ - new PrivateChannel("custom.{$this->teamId}"), + new PrivateChannel("team.{$this->teamId}"), ]; } } diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 7c1d186ff..ee0bc5160 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -79,6 +79,10 @@ public function settings() if (isInstanceAdmin()) { $settings = InstanceSettings::get(); $database = StandalonePostgresql::whereName('coolify-db')->first(); + if ($database->status !== 'running') { + $database->status = 'running'; + $database->save(); + } if ($database) { $s3s = S3Storage::whereTeamId(0)->get(); } diff --git a/app/Jobs/DatabaseBackupJob.php b/app/Jobs/DatabaseBackupJob.php index 02ddb7a5d..1ba855f4e 100644 --- a/app/Jobs/DatabaseBackupJob.php +++ b/app/Jobs/DatabaseBackupJob.php @@ -3,6 +3,7 @@ namespace App\Jobs; use App\Actions\Database\StopDatabase; +use App\Events\BackupCreated; use App\Models\S3Storage; use App\Models\ScheduledDatabaseBackup; use App\Models\ScheduledDatabaseBackupExecution; @@ -74,6 +75,7 @@ public function uniqueId(): int public function handle(): void { try { + BackupCreated::dispatch($this->team->id); // Check if team is exists if (is_null($this->team)) { $this->backup->update(['status' => 'failed']); @@ -307,6 +309,8 @@ public function handle(): void } catch (\Throwable $e) { send_internal_notification('DatabaseBackupJob failed with: ' . $e->getMessage()); throw $e; + } finally { + BackupCreated::dispatch($this->team->id); } } private function backup_standalone_mongodb(string $databaseWithCollections): void diff --git a/app/Livewire/Project/Database/BackupExecutions.php b/app/Livewire/Project/Database/BackupExecutions.php index f92b9790b..a41336bda 100644 --- a/app/Livewire/Project/Database/BackupExecutions.php +++ b/app/Livewire/Project/Database/BackupExecutions.php @@ -10,7 +10,15 @@ class BackupExecutions extends Component public $backup; public $executions; public $setDeletableBackup; - protected $listeners = ['refreshBackupExecutions', 'deleteBackup']; + public function getListeners() + { + $userId = auth()->user()->id; + return [ + "echo-private:team.{$userId},BackupCreated" => 'refreshBackupExecutions', + "refreshBackupExecutions", + "deleteBackup" + ]; + } public function deleteBackup($exeuctionId) { diff --git a/app/Livewire/Project/Database/Heading.php b/app/Livewire/Project/Database/Heading.php index 1c94f9573..59ddf2644 100644 --- a/app/Livewire/Project/Database/Heading.php +++ b/app/Livewire/Project/Database/Heading.php @@ -21,7 +21,7 @@ public function getListeners() { $userId = auth()->user()->id; return [ - "echo-private:custom.{$userId},DatabaseStatusChanged" => 'activityFinished', + "echo-private:user.{$userId},DatabaseStatusChanged" => 'activityFinished', ]; } diff --git a/app/Livewire/Project/Service/Index.php b/app/Livewire/Project/Service/Index.php index c2114bf15..e55dc610c 100644 --- a/app/Livewire/Project/Service/Index.php +++ b/app/Livewire/Project/Service/Index.php @@ -17,7 +17,7 @@ public function getListeners() { $userId = auth()->user()->id; return [ - "echo-private:custom.{$userId},ServiceStatusChanged" => 'checkStatus', + "echo-private:user.{$userId},ServiceStatusChanged" => 'checkStatus', "refreshStacks", "checkStatus", ]; diff --git a/app/Livewire/Sponsorship.php b/app/Livewire/Sponsorship.php index e38f04d27..c4dedffc0 100644 --- a/app/Livewire/Sponsorship.php +++ b/app/Livewire/Sponsorship.php @@ -8,12 +8,12 @@ class Sponsorship extends Component { public function getListeners() { - $userId = auth()->user()->id; + $teamId = auth()->user()->currentTeam()->id; return [ - "echo-private:custom.{$userId},TestEvent" => 'testEvent', + "echo-private:team.{$teamId},TestEvent" => 'testEvent', ]; } - public function testEvent($asd) + public function testEvent() { $this->dispatch('success', 'Realtime events configured!'); } diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index f64999b57..1e7141dec 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -22,9 +22,9 @@ if (window.Echo) { if (window.Echo.connector.pusher.connection.state !== 'connected') { checkNumber++; - if (checkNumber > 5) { + if (checkNumber > 2) { clearInterval(checkPusherInterval); - Livewire.emit('error', errorMessage); + window.Livewire.dispatch('error', errorMessage); } } else { console.log('Coolify is now connected to the new realtime service introduced in beta.154.'); @@ -32,7 +32,7 @@ } } else { clearInterval(checkPusherInterval); - Livewire.emit('error', errorMessage); + window.Livewire.dispatch('error', errorMessage); } }, 2000); } diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php index 4c16bfcd3..52da93d5c 100644 --- a/resources/views/layouts/base.blade.php +++ b/resources/views/layouts/base.blade.php @@ -121,7 +121,7 @@ function upgrade() { } function copyToClipboard(text) { - navigator?.clipboard?.writeText(text) && window.Livewire.emit('success', 'Copied to clipboard.'); + navigator?.clipboard?.writeText(text) && window.Livewire.dispatch('success', 'Copied to clipboard.'); } document.addEventListener('livewire:init', () => { window.Livewire.on('reloadWindow', (timeout) => { diff --git a/resources/views/livewire/project/database/backup-executions.blade.php b/resources/views/livewire/project/database/backup-executions.blade.php index 55bc2919a..a0d5ce649 100644 --- a/resources/views/livewire/project/database/backup-executions.blade.php +++ b/resources/views/livewire/project/database/backup-executions.blade.php @@ -1,10 +1,15 @@