rector: arrrrr
This commit is contained in:
@@ -39,6 +39,8 @@ class Execution extends Component
|
||||
$this->backup = $backup;
|
||||
$this->executions = $executions;
|
||||
$this->s3s = currentTeam()->s3s;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
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
|
||||
@@ -24,10 +28,10 @@ class Index extends Component
|
||||
}
|
||||
// No backups
|
||||
if (
|
||||
$database->getMorphClass() === \App\Models\StandaloneRedis::class ||
|
||||
$database->getMorphClass() === \App\Models\StandaloneKeydb::class ||
|
||||
$database->getMorphClass() === \App\Models\StandaloneDragonfly::class ||
|
||||
$database->getMorphClass() === \App\Models\StandaloneClickhouse::class
|
||||
$database->getMorphClass() === StandaloneRedis::class ||
|
||||
$database->getMorphClass() === StandaloneKeydb::class ||
|
||||
$database->getMorphClass() === StandaloneDragonfly::class ||
|
||||
$database->getMorphClass() === StandaloneClickhouse::class
|
||||
) {
|
||||
return redirect()->route('project.database.configuration', [
|
||||
'project_uuid' => $project->uuid,
|
||||
@@ -36,6 +40,8 @@ class Index extends Component
|
||||
]);
|
||||
}
|
||||
$this->database = $database;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function render()
|
||||
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
@@ -11,6 +12,7 @@ use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Spatie\Url\Url;
|
||||
use Throwable;
|
||||
|
||||
class BackupEdit extends Component
|
||||
{
|
||||
@@ -66,6 +68,8 @@ class BackupEdit extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function syncData(bool $toModel = false)
|
||||
@@ -94,12 +98,10 @@ class BackupEdit extends Component
|
||||
|
||||
public function delete($password)
|
||||
{
|
||||
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
||||
if (! Hash::check($password, Auth::user()->password)) {
|
||||
$this->addError('password', 'The provided password is incorrect.');
|
||||
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
|
||||
$this->addError('password', 'The provided password is incorrect.');
|
||||
|
||||
return;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -112,7 +114,7 @@ class BackupEdit extends Component
|
||||
|
||||
$this->backup->delete();
|
||||
|
||||
if ($this->backup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
||||
if ($this->backup->database->getMorphClass() === ServiceDatabase::class) {
|
||||
$previousUrl = url()->previous();
|
||||
$url = Url::fromString($previousUrl);
|
||||
$url = $url->withoutQueryParameter('selectedBackupId');
|
||||
@@ -120,10 +122,10 @@ class BackupEdit extends Component
|
||||
$url = $url->getPath()."#{$url->getFragment()}";
|
||||
|
||||
return redirect($url);
|
||||
} else {
|
||||
return redirect()->route('project.database.backup.index', $this->parameters);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
|
||||
return redirect()->route('project.database.backup.index', $this->parameters);
|
||||
} catch (Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
@@ -133,7 +135,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());
|
||||
}
|
||||
}
|
||||
@@ -145,7 +147,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();
|
||||
}
|
||||
@@ -155,7 +157,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());
|
||||
}
|
||||
}
|
||||
@@ -166,7 +168,7 @@ class BackupEdit extends Component
|
||||
$backupFolder = null;
|
||||
|
||||
foreach ($executions as $execution) {
|
||||
if ($this->backup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
||||
if ($this->backup->database->getMorphClass() === ServiceDatabase::class) {
|
||||
$server = $this->backup->database->service->destination->server;
|
||||
} else {
|
||||
$server = $this->backup->database->destination->server;
|
||||
|
||||
@@ -4,6 +4,10 @@ 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;
|
||||
@@ -33,7 +37,7 @@ class BackupExecutions extends Component
|
||||
|
||||
public function cleanupFailed()
|
||||
{
|
||||
if ($this->backup) {
|
||||
if ($this->backup instanceof ScheduledDatabaseBackup) {
|
||||
$this->backup->executions()->where('status', 'failed')->delete();
|
||||
$this->refreshBackupExecutions();
|
||||
$this->dispatch('success', 'Failed backups cleaned up.');
|
||||
@@ -42,12 +46,10 @@ class BackupExecutions extends Component
|
||||
|
||||
public function deleteBackup($executionId, $password)
|
||||
{
|
||||
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation')) {
|
||||
if (! Hash::check($password, Auth::user()->password)) {
|
||||
$this->addError('password', 'The provided password is incorrect.');
|
||||
if (! data_get(InstanceSettings::get(), 'disable_two_step_confirmation') && ! Hash::check($password, Auth::user()->password)) {
|
||||
$this->addError('password', 'The provided password is incorrect.');
|
||||
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$execution = $this->backup->executions()->where('id', $executionId)->first();
|
||||
@@ -57,7 +59,7 @@ class BackupExecutions extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
||||
if ($execution->scheduledDatabaseBackup->database->getMorphClass() === ServiceDatabase::class) {
|
||||
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->service->destination->server);
|
||||
} else {
|
||||
delete_backup_locally($execution->filename, $execution->scheduledDatabaseBackup->database->destination->server);
|
||||
@@ -83,15 +85,15 @@ class BackupExecutions extends Component
|
||||
|
||||
public function refreshBackupExecutions(): void
|
||||
{
|
||||
if ($this->backup) {
|
||||
if ($this->backup instanceof ScheduledDatabaseBackup) {
|
||||
$this->executions = $this->backup->executions()->get();
|
||||
}
|
||||
}
|
||||
|
||||
public function mount(ScheduledDatabaseBackup $backup)
|
||||
public function mount(ScheduledDatabaseBackup $scheduledDatabaseBackup)
|
||||
{
|
||||
$this->backup = $backup;
|
||||
$this->database = $backup->database;
|
||||
$this->backup = $scheduledDatabaseBackup;
|
||||
$this->database = $scheduledDatabaseBackup->database;
|
||||
$this->refreshBackupExecutions();
|
||||
}
|
||||
|
||||
@@ -100,7 +102,7 @@ class BackupExecutions extends Component
|
||||
if ($this->database) {
|
||||
$server = null;
|
||||
|
||||
if ($this->database instanceof \App\Models\ServiceDatabase) {
|
||||
if ($this->database instanceof ServiceDatabase) {
|
||||
$server = $this->database->service->destination->server;
|
||||
} elseif ($this->database->destination && $this->database->destination->server) {
|
||||
$server = $this->database->destination->server;
|
||||
@@ -126,11 +128,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');
|
||||
|
||||
@@ -10,6 +10,7 @@ use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -67,9 +68,11 @@ 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)
|
||||
@@ -113,7 +116,7 @@ class General extends Component
|
||||
$this->isLogDrainEnabled = false;
|
||||
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$this->syncData(true);
|
||||
|
||||
@@ -122,6 +125,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -131,14 +136,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->isPublic = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -148,12 +153,14 @@ 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()
|
||||
@@ -178,5 +185,7 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
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
|
||||
{
|
||||
@@ -33,9 +35,11 @@ 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()
|
||||
@@ -47,7 +51,7 @@ class CreateScheduledBackup extends Component
|
||||
if (! $isValid) {
|
||||
$this->dispatch('error', 'Invalid Cron / Human expression.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
@@ -68,17 +72,19 @@ class CreateScheduledBackup extends Component
|
||||
$payload['databases_to_backup'] = $this->database->mariadb_database;
|
||||
}
|
||||
|
||||
$databaseBackup = ScheduledDatabaseBackup::create($payload);
|
||||
if ($this->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
||||
$databaseBackup = ScheduledDatabaseBackup::query()->create($payload);
|
||||
if ($this->database->getMorphClass() === 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -64,9 +65,11 @@ 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)
|
||||
@@ -108,7 +111,7 @@ class General extends Component
|
||||
$this->isLogDrainEnabled = false;
|
||||
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$this->syncData(true);
|
||||
|
||||
@@ -117,6 +120,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -126,14 +131,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->isPublic = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -143,12 +148,14 @@ 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()
|
||||
@@ -173,5 +180,7 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,18 @@
|
||||
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
|
||||
{
|
||||
@@ -72,7 +81,7 @@ class Import extends Component
|
||||
public function updatedDumpAll($value)
|
||||
{
|
||||
switch ($this->resource->getMorphClass()) {
|
||||
case \App\Models\StandaloneMariadb::class:
|
||||
case 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
|
||||
@@ -87,7 +96,7 @@ EOD;
|
||||
$this->mariadbRestoreCommand = 'mariadb -u $MARIADB_USER -p$MARIADB_PASSWORD $MARIADB_DATABASE';
|
||||
}
|
||||
break;
|
||||
case \App\Models\StandaloneMysql::class:
|
||||
case 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
|
||||
@@ -102,7 +111,7 @@ EOD;
|
||||
$this->mysqlRestoreCommand = 'mysql -u $MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE';
|
||||
}
|
||||
break;
|
||||
case \App\Models\StandalonePostgresql::class:
|
||||
case 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()" && \
|
||||
@@ -136,10 +145,10 @@ EOD;
|
||||
}
|
||||
|
||||
if (
|
||||
$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->resource->getMorphClass() === StandaloneRedis::class ||
|
||||
$this->resource->getMorphClass() === StandaloneKeydb::class ||
|
||||
$this->resource->getMorphClass() === StandaloneDragonfly::class ||
|
||||
$this->resource->getMorphClass() === StandaloneClickhouse::class
|
||||
) {
|
||||
$this->unsupported = true;
|
||||
}
|
||||
@@ -153,14 +162,16 @@ EOD;
|
||||
if (blank($result)) {
|
||||
$this->dispatch('error', 'The file does not exist or has been deleted.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$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()
|
||||
@@ -168,7 +179,7 @@ EOD;
|
||||
if ($this->filename === '') {
|
||||
$this->dispatch('error', 'Please select a file to import.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$this->importCommands = [];
|
||||
@@ -182,7 +193,7 @@ EOD;
|
||||
if (! Storage::exists($backupFileName)) {
|
||||
$this->dispatch('error', 'The file does not exist or has been deleted.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$tmpPath = '/tmp/'.basename($backupFileName).'_'.$this->resource->uuid;
|
||||
instant_scp($path, $tmpPath, $this->server);
|
||||
@@ -194,7 +205,7 @@ EOD;
|
||||
$scriptPath = "/tmp/restore_{$this->resource->uuid}.sh";
|
||||
|
||||
switch ($this->resource->getMorphClass()) {
|
||||
case \App\Models\StandaloneMariadb::class:
|
||||
case StandaloneMariadb::class:
|
||||
$restoreCommand = $this->mariadbRestoreCommand;
|
||||
if ($this->dumpAll) {
|
||||
$restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mariadb -u root -p\$MARIADB_ROOT_PASSWORD";
|
||||
@@ -202,7 +213,7 @@ EOD;
|
||||
$restoreCommand .= " < {$tmpPath}";
|
||||
}
|
||||
break;
|
||||
case \App\Models\StandaloneMysql::class:
|
||||
case StandaloneMysql::class:
|
||||
$restoreCommand = $this->mysqlRestoreCommand;
|
||||
if ($this->dumpAll) {
|
||||
$restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | mysql -u root -p\$MYSQL_ROOT_PASSWORD";
|
||||
@@ -210,7 +221,7 @@ EOD;
|
||||
$restoreCommand .= " < {$tmpPath}";
|
||||
}
|
||||
break;
|
||||
case \App\Models\StandalonePostgresql::class:
|
||||
case StandalonePostgresql::class:
|
||||
$restoreCommand = $this->postgresqlRestoreCommand;
|
||||
if ($this->dumpAll) {
|
||||
$restoreCommand .= " && (gunzip -cf {$tmpPath} 2>/dev/null || cat {$tmpPath}) | psql -U \$POSTGRES_USER postgres";
|
||||
@@ -218,7 +229,7 @@ EOD;
|
||||
$restoreCommand .= " {$tmpPath}";
|
||||
}
|
||||
break;
|
||||
case \App\Models\StandaloneMongodb::class:
|
||||
case StandaloneMongodb::class:
|
||||
$restoreCommand = $this->mongodbRestoreCommand;
|
||||
if ($this->dumpAll === false) {
|
||||
$restoreCommand .= " {$tmpPath}";
|
||||
@@ -234,7 +245,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 (! empty($this->importCommands)) {
|
||||
if ($this->importCommands !== []) {
|
||||
$activity = remote_process($this->importCommands, $this->server, ignore_errors: true, callEventOnFinish: 'RestoreJobFinished', callEventData: [
|
||||
'scriptPath' => $scriptPath,
|
||||
'tmpPath' => $tmpPath,
|
||||
@@ -243,11 +254,13 @@ EOD;
|
||||
]);
|
||||
$this->dispatch('activityMonitor', $activity->id);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
} catch (Throwable $e) {
|
||||
return handleError($e, $this);
|
||||
} finally {
|
||||
$this->filename = null;
|
||||
$this->importCommands = [];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ class InitScript extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -43,6 +45,8 @@ class InitScript extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
@@ -52,5 +56,7 @@ class InitScript extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ use Exception;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -67,9 +68,11 @@ 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)
|
||||
@@ -113,7 +116,7 @@ class General extends Component
|
||||
$this->isLogDrainEnabled = false;
|
||||
$this->dispatch('error', 'Log drain is not enabled on the server. Please enable it first.');
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
$this->syncData(true);
|
||||
|
||||
@@ -122,6 +125,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -131,14 +136,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->isPublic = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -148,12 +153,14 @@ 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()
|
||||
@@ -178,5 +185,7 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Server;
|
||||
use App\Models\StandaloneMariadb;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -66,7 +67,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;
|
||||
return null;
|
||||
}
|
||||
$this->database->save();
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
@@ -74,6 +75,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -94,6 +97,8 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -103,14 +108,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->database->is_public = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -120,11 +125,13 @@ 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
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Server;
|
||||
use App\Models\StandaloneMongodb;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -64,7 +65,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;
|
||||
return null;
|
||||
}
|
||||
$this->database->save();
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
@@ -72,6 +73,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -95,6 +98,8 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -104,14 +109,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->database->is_public = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -121,11 +126,13 @@ 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
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Server;
|
||||
use App\Models\StandaloneMysql;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -66,7 +67,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;
|
||||
return null;
|
||||
}
|
||||
$this->database->save();
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
@@ -74,6 +75,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -94,6 +97,8 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -103,14 +108,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->database->is_public = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -120,11 +125,13 @@ 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
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Server;
|
||||
use App\Models\StandalonePostgresql;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -81,7 +82,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;
|
||||
return null;
|
||||
}
|
||||
$this->database->save();
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
@@ -89,6 +90,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -98,14 +101,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->database->is_public = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -115,11 +118,13 @@ 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)
|
||||
@@ -143,7 +148,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;
|
||||
@@ -184,7 +189,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;
|
||||
@@ -223,7 +228,7 @@ class General extends Component
|
||||
|
||||
return;
|
||||
}
|
||||
if (! isset($this->database->init_scripts)) {
|
||||
if (! property_exists($this->database, 'init_scripts') || $this->database->init_scripts === null) {
|
||||
$this->database->init_scripts = [];
|
||||
}
|
||||
$this->database->init_scripts = array_merge($this->database->init_scripts, [
|
||||
@@ -257,5 +262,7 @@ class General extends Component
|
||||
$this->dispatch('configurationChanged');
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Models\Server;
|
||||
use App\Models\StandaloneRedis;
|
||||
use Exception;
|
||||
use Livewire\Component;
|
||||
use Throwable;
|
||||
|
||||
class General extends Component
|
||||
{
|
||||
@@ -70,7 +71,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;
|
||||
return null;
|
||||
}
|
||||
$this->database->save();
|
||||
$this->dispatch('success', 'Database updated.');
|
||||
@@ -78,6 +79,8 @@ class General extends Component
|
||||
} catch (Exception $e) {
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -103,6 +106,8 @@ class General extends Component
|
||||
} finally {
|
||||
$this->dispatch('refreshEnvs');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
@@ -112,14 +117,14 @@ class General extends Component
|
||||
$this->dispatch('error', 'Public port is required.');
|
||||
$this->database->is_public = false;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
return null;
|
||||
}
|
||||
StartDatabaseProxy::run($this->database);
|
||||
$this->dispatch('success', 'Database is now publicly accessible.');
|
||||
@@ -129,11 +134,13 @@ 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
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Livewire\Project\Database;
|
||||
|
||||
use App\Models\ScheduledDatabaseBackup;
|
||||
use App\Models\ServiceDatabase;
|
||||
use Livewire\Component;
|
||||
|
||||
class ScheduledBackups extends Component
|
||||
@@ -29,11 +30,7 @@ class ScheduledBackups extends Component
|
||||
$this->setSelectedBackup($this->selectedBackupId, true);
|
||||
}
|
||||
$this->parameters = get_route_parameters();
|
||||
if ($this->database->getMorphClass() === \App\Models\ServiceDatabase::class) {
|
||||
$this->type = 'service-database';
|
||||
} else {
|
||||
$this->type = 'database';
|
||||
}
|
||||
$this->type = $this->database->getMorphClass() === ServiceDatabase::class ? 'service-database' : 'database';
|
||||
$this->s3s = currentTeam()->s3s;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user