mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-14 12:23:33 +00:00
fix(#168): ensure trmnlp_id is unset during plugin duplication to prevent unique constraint violation
Some checks failed
tests / ci (push) Has been cancelled
Some checks failed
tests / ci (push) Has been cancelled
This commit is contained in:
parent
a095268c30
commit
ffd1cf0d7e
2 changed files with 21 additions and 1 deletions
|
|
@ -594,7 +594,7 @@ class Plugin extends Model
|
||||||
// Get all attributes except id and uuid
|
// Get all attributes except id and uuid
|
||||||
// Use toArray() to get cast values (respects JSON casts)
|
// Use toArray() to get cast values (respects JSON casts)
|
||||||
$attributes = $this->toArray();
|
$attributes = $this->toArray();
|
||||||
unset($attributes['id'], $attributes['uuid']);
|
unset($attributes['id'], $attributes['uuid'], $attributes['trmnlp_id']);
|
||||||
|
|
||||||
// Handle render_markup_view - copy file content to render_markup
|
// Handle render_markup_view - copy file content to render_markup
|
||||||
if ($this->render_markup_view) {
|
if ($this->render_markup_view) {
|
||||||
|
|
|
||||||
|
|
@ -821,6 +821,26 @@ test('plugin duplicate copies all attributes except id and uuid', function (): v
|
||||||
->and($duplicate->render_markup_view)->toBeNull();
|
->and($duplicate->render_markup_view)->toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('plugin duplicate sets trmnlp_id to null to avoid unique constraint violation', function (): void {
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$original = Plugin::factory()->create([
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'name' => 'Plugin with trmnlp_id',
|
||||||
|
'trmnlp_id' => 'test-trmnlp-id-123',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$duplicate = $original->duplicate();
|
||||||
|
|
||||||
|
// Refresh to ensure casts are applied
|
||||||
|
$original->refresh();
|
||||||
|
$duplicate->refresh();
|
||||||
|
|
||||||
|
expect($duplicate->trmnlp_id)->toBeNull()
|
||||||
|
->and($original->trmnlp_id)->toBe('test-trmnlp-id-123')
|
||||||
|
->and($duplicate->name)->toBe('Plugin with trmnlp_id (Copy)');
|
||||||
|
});
|
||||||
|
|
||||||
test('plugin duplicate copies render_markup_view file content to render_markup', function (): void {
|
test('plugin duplicate copies render_markup_view file content to render_markup', function (): void {
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue