Revert "rector: arrrrr"

This reverts commit 16c0cd10d8.
This commit is contained in:
Andras Bacsai
2025-01-07 15:31:43 +01:00
parent da07b4fdcf
commit 1fe4dd722b
349 changed files with 3689 additions and 4184 deletions

View File

@@ -39,8 +39,6 @@ class Execution extends Component
$this->backup = $backup;
$this->executions = $executions;
$this->s3s = currentTeam()->s3s;
return null;
}
public function render()

View File

@@ -2,10 +2,6 @@
namespace App\Livewire\Project\Database\Backup;
use App\Models\StandaloneClickhouse;
use App\Models\StandaloneDragonfly;
use App\Models\StandaloneKeydb;
use App\Models\StandaloneRedis;
use Livewire\Component;
class Index extends Component
@@ -28,10 +24,10 @@ class Index extends Component
}
// No backups
if (
$database->getMorphClass() === StandaloneRedis::class ||
$database->getMorphClass() === StandaloneKeydb::class ||
$database->getMorphClass() === StandaloneDragonfly::class ||
$database->getMorphClass() === StandaloneClickhouse::class
$database->getMorphClass() === \App\Models\StandaloneRedis::class ||
$database->getMorphClass() === \App\Models\StandaloneKeydb::class ||
$database->getMorphClass() === \App\Models\StandaloneDragonfly::class ||
$database->getMorphClass() === \App\Models\StandaloneClickhouse::class
) {
return redirect()->route('project.database.configuration', [
'project_uuid' => $project->uuid,
@@ -40,8 +36,6 @@ class Index extends Component
]);
}
$this->database = $database;
return null;
}
public function render()

View File

@@ -4,7 +4,6 @@ namespace App\Livewire\Project\Database;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ServiceDatabase;
use Exception;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
@@ -12,7 +11,6 @@ use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Spatie\Url\Url;
use Throwable;
class BackupEdit extends Component
{
@@ -68,8 +66,6 @@ class BackupEdit extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -98,10 +94,12 @@ class BackupEdit extends Component
public function delete($password)
{
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return null;
return;
}
}
try {
@@ -114,7 +112,7 @@ class BackupEdit extends Component
$this->backup->delete();
if ($this->backup->database->getMorphClass() === ServiceDatabase::class) {
if ($this->backup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
$previousUrl = url()->previous();
$url = Url::fromString($previousUrl);
$url = $url->withoutQueryParameter('selectedBackupId');
@@ -122,10 +120,10 @@ class BackupEdit extends Component
$url = $url->getPath()."#{$url->getFragment()}";
return redirect($url);
} else {
return redirect()->route('project.database.backup.index', $this->parameters);
}
return redirect()->route('project.database.backup.index', $this->parameters);
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
@@ -135,7 +133,7 @@ class BackupEdit extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Backup updated successfully.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->dispatch('error', $e->getMessage());
}
}
@@ -147,7 +145,7 @@ class BackupEdit extends Component
}
$isValid = validate_cron_expression($this->backup->frequency);
if (! $isValid) {
throw new Exception('Invalid Cron / Human expression');
throw new \Exception('Invalid Cron / Human expression');
}
$this->validate();
}
@@ -157,7 +155,7 @@ class BackupEdit extends Component
try {
$this->syncData(true);
$this->dispatch('success', 'Backup updated successfully.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->dispatch('error', $e->getMessage());
}
}
@@ -168,7 +166,7 @@ class BackupEdit extends Component
$backupFolder = null;
foreach ($executions as $execution) {
if ($this->backup->database->getMorphClass() === ServiceDatabase::class) {
if ($this->backup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
$server = $this->backup->database->service->destination->server;
} else {
$server = $this->backup->database->destination->server;

View File

@@ -4,10 +4,6 @@ namespace App\Livewire\Project\Database;
use App\Models\InstanceSettings;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ServiceDatabase;
use DateTime;
use DateTimeZone;
use Exception;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Livewire\Component;
@@ -37,7 +33,7 @@ class BackupExecutions extends Component
public function cleanupFailed()
{
if ($this->backup instanceof ScheduledDatabaseBackup) {
if ($this->backup) {
$this->backup->executions()->where('status', 'failed')->delete();
$this->refreshBackupExecutions();
$this->dispatch('success', 'Failed backups cleaned up.');
@@ -46,10 +42,12 @@ class BackupExecutions extends Component
public function deleteBackup($executionId, $password)
{
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
if (! Hash::check($password, Auth::user()->password)) {
$this->addError('password', 'The provided password is incorrect.');
return;
return;
}
}
$execution = $this->backup->executions()->where('id', $executionId)->first();
@@ -59,7 +57,7 @@ class BackupExecutions extends Component
return;
}
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === ServiceDatabase::class) {
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->service->destination->server);
} else {
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->destination->server);
@@ -85,15 +83,15 @@ class BackupExecutions extends Component
public function refreshBackupExecutions(): void
{
if ($this->backup instanceof ScheduledDatabaseBackup) {
if ($this->backup) {
$this->executions = $this->backup->executions()->get();
}
}
public function mount(ScheduledDatabaseBackup $scheduledDatabaseBackup)
public function mount(ScheduledDatabaseBackup $backup)
{
$this->backup = $scheduledDatabaseBackup;
$this->database = $scheduledDatabaseBackup->database;
$this->backup = $backup;
$this->database = $backup->database;
$this->refreshBackupExecutions();
}
@@ -102,7 +100,7 @@ class BackupExecutions extends Component
if ($this->database) {
$server = null;
if ($this->database instanceof ServiceDatabase) {
if ($this->database instanceof \App\Models\ServiceDatabase) {
$server = $this->database->service->destination->server;
} elseif ($this->database->destination && $this->database->destination->server) {
$server = $this->database->destination->server;
@@ -128,11 +126,11 @@ class BackupExecutions extends Component
public function formatDateInServerTimezone($date)
{
$serverTimezone = $this->getServerTimezone();
$dateObj = new DateTime($date);
$dateObj = new \DateTime($date);
try {
$dateObj->setTimezone(new DateTimeZone($serverTimezone));
} catch (Exception) {
$dateObj->setTimezone(new DateTimeZone('UTC'));
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
} catch (\Exception) {
$dateObj->setTimezone(new \DateTimeZone('UTC'));
}
return $dateObj->format('Y-m-d H:i:s T');

View File

@@ -10,7 +10,6 @@ use Exception;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -68,11 +67,9 @@ class General extends Component
try {
$this->syncData();
$this->server = data_get($this->database, 'destination.server');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -116,7 +113,7 @@ class General extends Component
$this->isLogDrainEnabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->syncData(true);
@@ -125,8 +122,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -136,14 +131,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->isPublic = false;
return null;
return;
}
if ($this->isPublic) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->isPublic = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -153,14 +148,12 @@ class General extends Component
}
$this->dbUrlPublic = $this->database->external_db_url;
$this->syncData(true);
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
return handleError($e, $this);
}
return null;
}
public function databaseProxyStopped()
@@ -185,7 +178,5 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
}

View File

@@ -3,12 +3,10 @@
namespace App\Livewire\Project\Database;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ServiceDatabase;
use Illuminate\Support\Collection;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class CreateScheduledBackup extends Component
{
@@ -35,11 +33,9 @@ class CreateScheduledBackup extends Component
if ($this->definedS3s->count() > 0) {
$this->s3StorageId = $this->definedS3s->first()->id;
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -51,7 +47,7 @@ class CreateScheduledBackup extends Component
if (! $isValid) {
$this->dispatch('error', 'Invalid Cron / Human expression.');
return null;
return;
}
$payload = [
@@ -72,19 +68,17 @@ class CreateScheduledBackup extends Component
$payload['databases_to_backup'] = $this->database->mariadb_database;
}
$databaseBackup = ScheduledDatabaseBackup::query()->create($payload);
if ($this->database->getMorphClass() === ServiceDatabase::class) {
$databaseBackup = ScheduledDatabaseBackup::create($payload);
if ($this->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
$this->dispatch('refreshScheduledBackups', $databaseBackup->id);
} else {
$this->dispatch('refreshScheduledBackups');
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
$this->frequency = '';
}
return null;
}
}

View File

@@ -10,7 +10,6 @@ use Exception;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -65,11 +64,9 @@ class General extends Component
try {
$this->syncData();
$this->server = data_get($this->database, 'destination.server');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -111,7 +108,7 @@ class General extends Component
$this->isLogDrainEnabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->syncData(true);
@@ -120,8 +117,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -131,14 +126,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->isPublic = false;
return null;
return;
}
if ($this->isPublic) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->isPublic = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -148,14 +143,12 @@ class General extends Component
}
$this->dbUrlPublic = $this->database->external_db_url;
$this->syncData(true);
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
return handleError($e, $this);
}
return null;
}
public function databaseProxyStopped()
@@ -180,7 +173,5 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
}

View File

@@ -3,18 +3,9 @@
namespace App\Livewire\Project\Database;
use App\Models\Server;
use App\Models\StandaloneClickhouse;
use App\Models\StandaloneDragonfly;
use App\Models\StandaloneKeydb;
use App\Models\StandaloneMariadb;
use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Livewire\Component;
use Throwable;
class Import extends Component
{
@@ -81,7 +72,7 @@ class Import extends Component
public function updatedDumpAll($value)
{
switch ($this->resource->getMorphClass()) {
case StandaloneMariadb::class:
case \App\Models\StandaloneMariadb::class:
if ($value === true) {
$this->mariadbRestoreCommand = <<<'EOD'
for pid in $(mariadb -u root -p$MARIADB_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do
@@ -96,7 +87,7 @@ EOD;
$this->mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';
}
break;
case StandaloneMysql::class:
case \App\Models\StandaloneMysql::class:
if ($value === true) {
$this->mysqlRestoreCommand = <<<'EOD'
for pid in $(mysql -u root -p$MYSQL_ROOT_PASSWORD -N -e "SELECT id FROM information_schema.processlist WHERE user != 'root';"); do
@@ -111,7 +102,7 @@ EOD;
$this->mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';
}
break;
case StandalonePostgresql::class:
case \App\Models\StandalonePostgresql::class:
if ($value === true) {
$this->postgresqlRestoreCommand = <<<'EOD'
psql -U $POSTGRES_USER -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname IS NOT NULL AND pid <> pg_backend_pid()" && \
@@ -145,10 +136,10 @@ EOD;
}
if (
$this->resource->getMorphClass() === StandaloneRedis::class ||
$this->resource->getMorphClass() === StandaloneKeydb::class ||
$this->resource->getMorphClass() === StandaloneDragonfly::class ||
$this->resource->getMorphClass() === StandaloneClickhouse::class
$this->resource->getMorphClass() === \App\Models\StandaloneRedis::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneKeydb::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneDragonfly::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneClickhouse::class
) {
$this->unsupported = true;
}
@@ -162,16 +153,14 @@ EOD;
if (blank($result)) {
$this->dispatch('error', 'The file does not exist or has been deleted.');
return null;
return;
}
$this->filename = $this->customLocation;
$this->dispatch('success', 'The file exists.');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
return null;
}
public function runImport()
@@ -179,7 +168,7 @@ EOD;
if ($this->filename === '') {
$this->dispatch('error', 'Please select a file to import.');
return null;
return;
}
try {
$this->importCommands = [];
@@ -193,7 +182,7 @@ EOD;
if (! Storage::exists($backupFileName)) {
$this->dispatch('error', 'The file does not exist or has been deleted.');
return null;
return;
}
$tmpPath = '/tmp/'.basename($backupFileName).'_'.$this->resource->uuid;
instant_scp($path, $tmpPath, $this->server);
@@ -205,7 +194,7 @@ EOD;
$scriptPath = "/tmp/restore_{$this->resource->uuid}.sh";
switch ($this->resource->getMorphClass()) {
case StandaloneMariadb::class:
case \App\Models\StandaloneMariadb::class:
$restoreCommand = $this->mariadbRestoreCommand;
if ($this->dumpAll) {
$restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mariadb -u root -p\$MARIADB_ROOT_PASSWORD";
@@ -213,7 +202,7 @@ EOD;
$restoreCommand .= " < {$tmpPath}";
}
break;
case StandaloneMysql::class:
case \App\Models\StandaloneMysql::class:
$restoreCommand = $this->mysqlRestoreCommand;
if ($this->dumpAll) {
$restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mysql -u root -p\$MYSQL_ROOT_PASSWORD";
@@ -221,7 +210,7 @@ EOD;
$restoreCommand .= " < {$tmpPath}";
}
break;
case StandalonePostgresql::class:
case \App\Models\StandalonePostgresql::class:
$restoreCommand = $this->postgresqlRestoreCommand;
if ($this->dumpAll) {
$restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | psql -U \$POSTGRES_USER postgres";
@@ -229,7 +218,7 @@ EOD;
$restoreCommand .= " {$tmpPath}";
}
break;
case StandaloneMongodb::class:
case \App\Models\StandaloneMongodb::class:
$restoreCommand = $this->mongodbRestoreCommand;
if ($this->dumpAll === false) {
$restoreCommand .= " {$tmpPath}";
@@ -245,7 +234,7 @@ EOD;
$this->importCommands[] = "docker exec {$this->container} sh -c '{$scriptPath}'";
$this->importCommands[] = "docker exec {$this->container} sh -c 'echo \"Import finished with exit code $?\"'";
if ($this->importCommands !== []) {
if (! empty($this->importCommands)) {
$activity = remote_process($this->importCommands, $this->server, ignore_errors: true, callEventOnFinish: 'RestoreJobFinished', callEventData: [
'scriptPath' => $scriptPath,
'tmpPath' => $tmpPath,
@@ -254,13 +243,11 @@ EOD;
]);
$this->dispatch('activityMonitor', $activity->id);
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
} finally {
$this->filename = null;
$this->importCommands = [];
}
return null;
}
}

View File

@@ -30,8 +30,6 @@ class InitScript extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -45,8 +43,6 @@ class InitScript extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function delete()
@@ -56,7 +52,5 @@ class InitScript extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
}

View File

@@ -10,7 +10,6 @@ use Exception;
use Illuminate\Support\Facades\Auth;
use Livewire\Attributes\Validate;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -68,11 +67,9 @@ class General extends Component
try {
$this->syncData();
$this->server = data_get($this->database, 'destination.server');
} catch (Throwable $e) {
} catch (\Throwable $e) {
return handleError($e, $this);
}
return null;
}
public function syncData(bool $toModel = false)
@@ -116,7 +113,7 @@ class General extends Component
$this->isLogDrainEnabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->syncData(true);
@@ -125,8 +122,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -136,14 +131,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->isPublic = false;
return null;
return;
}
if ($this->isPublic) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->isPublic = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -153,14 +148,12 @@ class General extends Component
}
$this->dbUrlPublic = $this->database->external_db_url;
$this->syncData(true);
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->isPublic = ! $this->isPublic;
$this->syncData(true);
return handleError($e, $this);
}
return null;
}
public function databaseProxyStopped()
@@ -185,7 +178,5 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
}

View File

@@ -8,7 +8,6 @@ use App\Models\Server;
use App\Models\StandaloneMariadb;
use Exception;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -67,7 +66,7 @@ class General extends Component
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->database->save();
$this->dispatch('success', 'Database updated.');
@@ -75,8 +74,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -97,8 +94,6 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
public function instantSave()
@@ -108,14 +103,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return null;
return;
}
if ($this->database->is_public) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -125,13 +120,11 @@ class General extends Component
}
$this->db_url_public = $this->database->external_db_url;
$this->database->save();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
return null;
}
public function refresh(): void

View File

@@ -8,7 +8,6 @@ use App\Models\Server;
use App\Models\StandaloneMongodb;
use Exception;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -65,7 +64,7 @@ class General extends Component
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->database->save();
$this->dispatch('success', 'Database updated.');
@@ -73,8 +72,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -98,8 +95,6 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
public function instantSave()
@@ -109,14 +104,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return null;
return;
}
if ($this->database->is_public) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -126,13 +121,11 @@ class General extends Component
}
$this->db_url_public = $this->database->external_db_url;
$this->database->save();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
return null;
}
public function refresh(): void

View File

@@ -8,7 +8,6 @@ use App\Models\Server;
use App\Models\StandaloneMysql;
use Exception;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -67,7 +66,7 @@ class General extends Component
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->database->save();
$this->dispatch('success', 'Database updated.');
@@ -75,8 +74,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -97,8 +94,6 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
public function instantSave()
@@ -108,14 +103,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return null;
return;
}
if ($this->database->is_public) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -125,13 +120,11 @@ class General extends Component
}
$this->db_url_public = $this->database->external_db_url;
$this->database->save();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
return null;
}
public function refresh(): void

View File

@@ -8,7 +8,6 @@ use App\Models\Server;
use App\Models\StandalonePostgresql;
use Exception;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -82,7 +81,7 @@ class General extends Component
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->database->save();
$this->dispatch('success', 'Database updated.');
@@ -90,8 +89,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function instantSave()
@@ -101,14 +98,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return null;
return;
}
if ($this->database->is_public) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -118,13 +115,11 @@ class General extends Component
}
$this->db_url_public = $this->database->external_db_url;
$this->database->save();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
return null;
}
public function save_init_script($script)
@@ -148,7 +143,7 @@ class General extends Component
$delete_command = "rm -f $old_file_path";
try {
instant_remote_process([$delete_command], $this->server);
} catch (Exception $e) {
} catch (\Exception $e) {
$this->dispatch('error', 'Failed to remove old init script from server: '.$e->getMessage());
return;
@@ -189,7 +184,7 @@ class General extends Component
$command = "rm -f $file_path";
try {
instant_remote_process([$command], $this->server);
} catch (Exception $e) {
} catch (\Exception $e) {
$this->dispatch('error', 'Failed to remove init script from server: '.$e->getMessage());
return;
@@ -228,7 +223,7 @@ class General extends Component
return;
}
if (! property_exists($this->database, 'init_scripts') || $this->database->init_scripts === null) {
if (! isset($this->database->init_scripts)) {
$this->database->init_scripts = [];
}
$this->database->init_scripts = array_merge($this->database->init_scripts, [
@@ -262,7 +257,5 @@ class General extends Component
$this->dispatch('configurationChanged');
}
}
return null;
}
}

View File

@@ -8,7 +8,6 @@ use App\Models\Server;
use App\Models\StandaloneRedis;
use Exception;
use Livewire\Component;
use Throwable;
class General extends Component
{
@@ -71,7 +70,7 @@ class General extends Component
$this->database->is_log_drain_enabled = false;
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
return null;
return;
}
$this->database->save();
$this->dispatch('success', 'Database updated.');
@@ -79,8 +78,6 @@ class General extends Component
} catch (Exception $e) {
return handleError($e, $this);
}
return null;
}
public function submit()
@@ -106,8 +103,6 @@ class General extends Component
} finally {
$this->dispatch('refreshEnvs');
}
return null;
}
public function instantSave()
@@ -117,14 +112,14 @@ class General extends Component
$this->dispatch('error', 'Public port is required.');
$this->database->is_public = false;
return null;
return;
}
if ($this->database->is_public) {
if (! str($this->database->status)->startsWith('running')) {
$this->dispatch('error', 'Database must be started to be publicly accessible.');
$this->database->is_public = false;
return null;
return;
}
StartDatabaseProxy::run($this->database);
$this->dispatch('success', 'Database is now publicly accessible.');
@@ -134,13 +129,11 @@ class General extends Component
}
$this->db_url_public = $this->database->external_db_url;
$this->database->save();
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->database->is_public = ! $this->database->is_public;
return handleError($e, $this);
}
return null;
}
public function refresh(): void

View File

@@ -3,7 +3,6 @@
namespace App\Livewire\Project\Database;
use App\Models\ScheduledDatabaseBackup;
use App\Models\ServiceDatabase;
use Livewire\Component;
class ScheduledBackups extends Component
@@ -30,7 +29,11 @@ class ScheduledBackups extends Component
$this->setSelectedBackup($this->selectedBackupId, true);
}
$this->parameters = get_route_parameters();
$this->type = $this->database->getMorphClass() === ServiceDatabase::class ? 'service-database' : 'database';
if ($this->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
$this->type = 'service-database';
} else {
$this->type = 'database';
}
$this->s3s = currentTeam()->s3s;
}