feat(storage): implement transaction handling in storage settings submission
- Wrapped the storage settings submission process in a database transaction to ensure data integrity. - Added connection testing within the transaction to verify settings before finalizing the save. - Enhanced error handling by refreshing the model state after a rollback, ensuring the UI reflects the latest database values. - Dispatch success event upon successful update and verification of storage settings.
This commit is contained in:
parent
2c64136503
commit
fbbaab55f5
1 changed files with 18 additions and 2 deletions
|
|
@ -5,6 +5,7 @@
|
|||
use App\Models\S3Storage;
|
||||
use App\Support\ValidationPatterns;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Livewire\Component;
|
||||
|
||||
class Form extends Component
|
||||
|
|
@ -91,9 +92,24 @@ public function submit()
|
|||
try {
|
||||
$this->authorize('update', $this->storage);
|
||||
|
||||
$this->validate();
|
||||
$this->testConnection();
|
||||
DB::transaction(function () {
|
||||
$this->validate();
|
||||
$this->storage->save();
|
||||
|
||||
// Test connection with new values - if this fails, transaction will rollback
|
||||
$this->storage->testConnection(shouldSave: false);
|
||||
|
||||
// If we get here, the connection test succeeded
|
||||
$this->storage->is_usable = true;
|
||||
$this->storage->unusable_email_sent = false;
|
||||
$this->storage->save();
|
||||
});
|
||||
|
||||
$this->dispatch('success', 'Storage settings updated and connection verified.');
|
||||
} catch (\Throwable $e) {
|
||||
// Refresh the model to revert UI to database values after rollback
|
||||
$this->storage->refresh();
|
||||
|
||||
return handleError($e, $this);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue