user()->id; return [ "echo-private:user.{$userId},DatabaseStatusChanged" => '$refresh', ]; } public function mount() { $this->parameters = get_route_parameters(); $this->getContainers(); } public function getContainers() { $this->containers = collect(); if (!data_get($this->parameters, 'database_uuid')) { abort(404); } $resource = getResourceByUuid($this->parameters['database_uuid'], data_get(auth()->user()->currentTeam(), 'id')); if (is_null($resource)) { abort(404); } $this->resource = $resource; $this->server = $this->resource->destination->server; $this->container = $this->resource->uuid; if (str(data_get($this, 'resource.status'))->startsWith('running')) { $this->containers->push($this->container); } if ( $this->resource->getMorphClass() == 'App\Models\StandaloneRedis' || $this->resource->getMorphClass() == 'App\Models\StandaloneKeydb' || $this->resource->getMorphClass() == 'App\Models\StandaloneDragonfly' || $this->resource->getMorphClass() == 'App\Models\StandaloneClickhouse' ) { $this->unsupported = true; } } public function runImport() { if ($this->filename == '') { $this->dispatch('error', 'Please select a file to import.'); return; } try { $uploadedFilename = "upload/{$this->resource->uuid}/restore"; $path = Storage::path($uploadedFilename); if (!Storage::exists($uploadedFilename)) { $this->dispatch('error', 'The file does not exist or has been deleted.'); return; } $tmpPath = '/tmp/' . basename($uploadedFilename); instant_scp($path, $tmpPath, $this->server); Storage::delete($uploadedFilename); $this->importCommands[] = "docker cp {$tmpPath} {$this->container}:{$tmpPath}"; switch ($this->resource->getMorphClass()) { case 'App\Models\StandaloneMariadb': $this->importCommands[] = "docker exec {$this->container} sh -c '{$this->mariadbRestoreCommand} < {$tmpPath}'"; $this->importCommands[] = "rm {$tmpPath}"; break; case 'App\Models\StandaloneMysql': $this->importCommands[] = "docker exec {$this->container} sh -c '{$this->mysqlRestoreCommand} < {$tmpPath}'"; $this->importCommands[] = "rm {$tmpPath}"; break; case 'App\Models\StandalonePostgresql': $this->importCommands[] = "docker exec {$this->container} sh -c '{$this->postgresqlRestoreCommand} {$tmpPath}'"; $this->importCommands[] = "rm {$tmpPath}"; break; case 'App\Models\StandaloneMongodb': $this->importCommands[] = "docker exec {$this->container} sh -c '{$this->mongodbRestoreCommand} {$tmpPath}'"; $this->importCommands[] = "rm {$tmpPath}"; break; } $this->importCommands[] = "docker exec {$this->container} sh -c 'rm {$tmpPath}'"; $this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'"; if (!empty($this->importCommands)) { $activity = remote_process($this->importCommands, $this->server, ignore_errors: true); $this->dispatch('activityMonitor', $activity->id); } } catch (\Throwable $e) { return handleError($e, $this); } } }