mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-30 02:20:50 +00:00
Complete Livewire legacy model binding migration (25+ components)
This completes the migration from Livewire's legacy `id="model.property"` pattern to explicit properties with manual synchronization. This allows disabling the `legacy_model_binding` feature flag. **Components Migrated (Final Session - 9 components):** - Server/Proxy.php (1 field) - Service/EditDomain.php (1 field) - Fixed Collection/string bug & parent sync - Application/Previews.php (2 fields - array handling) - Service/EditCompose.php (4 fields) - Service/FileStorage.php (6 fields) - Service/Database.php (7 fields) - Service/ServiceApplicationView.php (10 fields) - Application/General.php (53 fields) - LARGEST migration - Application/PreviewsCompose.php (1 field) **Total Migration Summary:** - 25+ components migrated across all phases - 150+ explicit properties added - 0 legacy bindings remaining (verified via grep) - All wire:model, id, @entangle bindings updated - All updater hooks renamed (updatedApplicationX → updatedX) **Technical Changes:** - Added explicit public properties (camelCase) - Implemented syncData(bool $toModel) bidirectional sync - Updated validation rules (removed model. prefix) - Updated all action methods (mount, submit, instantSave) - Fixed updater hooks: updatedBuildPack, updatedBaseDirectory, updatedIsStatic - Updated Blade views (id & wire:model bindings) - Applied Collection/string confusion fixes - Added model refresh + re-sync pattern **Critical Fixes:** - EditDomain.php Collection/string confusion (use intermediate variables) - EditDomain.php parent component sync (refresh + re-sync after save) - General.php domain field empty (syncData at end of mount) - General.php wire:model bindings (application.* → property) - General.php updater hooks (wrong naming convention) **Files Modified:** 34 files - 17 PHP Livewire components - 17 Blade view templates - 1 MIGRATION_REPORT.md (documentation) **Ready to disable legacy_model_binding flag in config/livewire.php** 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -14,17 +14,34 @@ class Form extends Component
|
||||
|
||||
public S3Storage $storage;
|
||||
|
||||
// Explicit properties
|
||||
public ?string $name = null;
|
||||
|
||||
public ?string $description = null;
|
||||
|
||||
public string $endpoint;
|
||||
|
||||
public string $bucket;
|
||||
|
||||
public string $region;
|
||||
|
||||
public string $key;
|
||||
|
||||
public string $secret;
|
||||
|
||||
public ?bool $isUsable = null;
|
||||
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'storage.is_usable' => 'nullable|boolean',
|
||||
'storage.name' => ValidationPatterns::nameRules(required: false),
|
||||
'storage.description' => ValidationPatterns::descriptionRules(),
|
||||
'storage.region' => 'required|max:255',
|
||||
'storage.key' => 'required|max:255',
|
||||
'storage.secret' => 'required|max:255',
|
||||
'storage.bucket' => 'required|max:255',
|
||||
'storage.endpoint' => 'required|url|max:255',
|
||||
'isUsable' => 'nullable|boolean',
|
||||
'name' => ValidationPatterns::nameRules(required: false),
|
||||
'description' => ValidationPatterns::descriptionRules(),
|
||||
'region' => 'required|max:255',
|
||||
'key' => 'required|max:255',
|
||||
'secret' => 'required|max:255',
|
||||
'bucket' => 'required|max:255',
|
||||
'endpoint' => 'required|url|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -33,34 +50,69 @@ class Form extends Component
|
||||
return array_merge(
|
||||
ValidationPatterns::combinedMessages(),
|
||||
[
|
||||
'storage.name.regex' => 'The Name may only contain letters, numbers, spaces, dashes (-), underscores (_), dots (.), slashes (/), colons (:), and parentheses ().',
|
||||
'storage.description.regex' => 'The Description contains invalid characters. Only letters, numbers, spaces, and common punctuation (- _ . : / () \' " , ! ? @ # % & + = [] {} | ~ ` *) are allowed.',
|
||||
'storage.region.required' => 'The Region field is required.',
|
||||
'storage.region.max' => 'The Region may not be greater than 255 characters.',
|
||||
'storage.key.required' => 'The Access Key field is required.',
|
||||
'storage.key.max' => 'The Access Key may not be greater than 255 characters.',
|
||||
'storage.secret.required' => 'The Secret Key field is required.',
|
||||
'storage.secret.max' => 'The Secret Key may not be greater than 255 characters.',
|
||||
'storage.bucket.required' => 'The Bucket field is required.',
|
||||
'storage.bucket.max' => 'The Bucket may not be greater than 255 characters.',
|
||||
'storage.endpoint.required' => 'The Endpoint field is required.',
|
||||
'storage.endpoint.url' => 'The Endpoint must be a valid URL.',
|
||||
'storage.endpoint.max' => 'The Endpoint may not be greater than 255 characters.',
|
||||
'name.regex' => 'The Name may only contain letters, numbers, spaces, dashes (-), underscores (_), dots (.), slashes (/), colons (:), and parentheses ().',
|
||||
'description.regex' => 'The Description contains invalid characters. Only letters, numbers, spaces, and common punctuation (- _ . : / () \' " , ! ? @ # % & + = [] {} | ~ ` *) are allowed.',
|
||||
'region.required' => 'The Region field is required.',
|
||||
'region.max' => 'The Region may not be greater than 255 characters.',
|
||||
'key.required' => 'The Access Key field is required.',
|
||||
'key.max' => 'The Access Key may not be greater than 255 characters.',
|
||||
'secret.required' => 'The Secret Key field is required.',
|
||||
'secret.max' => 'The Secret Key may not be greater than 255 characters.',
|
||||
'bucket.required' => 'The Bucket field is required.',
|
||||
'bucket.max' => 'The Bucket may not be greater than 255 characters.',
|
||||
'endpoint.required' => 'The Endpoint field is required.',
|
||||
'endpoint.url' => 'The Endpoint must be a valid URL.',
|
||||
'endpoint.max' => 'The Endpoint may not be greater than 255 characters.',
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected $validationAttributes = [
|
||||
'storage.is_usable' => 'Is Usable',
|
||||
'storage.name' => 'Name',
|
||||
'storage.description' => 'Description',
|
||||
'storage.region' => 'Region',
|
||||
'storage.key' => 'Key',
|
||||
'storage.secret' => 'Secret',
|
||||
'storage.bucket' => 'Bucket',
|
||||
'storage.endpoint' => 'Endpoint',
|
||||
'isUsable' => 'Is Usable',
|
||||
'name' => 'Name',
|
||||
'description' => 'Description',
|
||||
'region' => 'Region',
|
||||
'key' => 'Key',
|
||||
'secret' => 'Secret',
|
||||
'bucket' => 'Bucket',
|
||||
'endpoint' => 'Endpoint',
|
||||
];
|
||||
|
||||
/**
|
||||
* Sync data between component properties and model
|
||||
*
|
||||
* @param bool $toModel If true, sync FROM properties TO model. If false, sync FROM model TO properties.
|
||||
*/
|
||||
private function syncData(bool $toModel = false): void
|
||||
{
|
||||
if ($toModel) {
|
||||
// Sync TO model (before save)
|
||||
$this->storage->name = $this->name;
|
||||
$this->storage->description = $this->description;
|
||||
$this->storage->endpoint = $this->endpoint;
|
||||
$this->storage->bucket = $this->bucket;
|
||||
$this->storage->region = $this->region;
|
||||
$this->storage->key = $this->key;
|
||||
$this->storage->secret = $this->secret;
|
||||
$this->storage->is_usable = $this->isUsable;
|
||||
} else {
|
||||
// Sync FROM model (on load/refresh)
|
||||
$this->name = $this->storage->name;
|
||||
$this->description = $this->storage->description;
|
||||
$this->endpoint = $this->storage->endpoint;
|
||||
$this->bucket = $this->storage->bucket;
|
||||
$this->region = $this->storage->region;
|
||||
$this->key = $this->storage->key;
|
||||
$this->secret = $this->storage->secret;
|
||||
$this->isUsable = $this->storage->is_usable;
|
||||
}
|
||||
}
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->syncData(false);
|
||||
}
|
||||
|
||||
public function testConnection()
|
||||
{
|
||||
try {
|
||||
@@ -94,6 +146,9 @@ class Form extends Component
|
||||
|
||||
DB::transaction(function () {
|
||||
$this->validate();
|
||||
|
||||
// Sync properties to model before saving
|
||||
$this->syncData(true);
|
||||
$this->storage->save();
|
||||
|
||||
// Test connection with new values - if this fails, transaction will rollback
|
||||
@@ -103,12 +158,16 @@ class Form extends Component
|
||||
$this->storage->is_usable = true;
|
||||
$this->storage->unusable_email_sent = false;
|
||||
$this->storage->save();
|
||||
|
||||
// Update local property to reflect success
|
||||
$this->isUsable = true;
|
||||
});
|
||||
|
||||
$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();
|
||||
$this->syncData(false);
|
||||
|
||||
return handleError($e, $this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user