Skip to content

Commit 3913e38

Browse files
Merge pull request #1484 from liberu-genealogy/copilot/fix-after-create-method-bug
Fix missing afterCreate() in CreateGedcom and make ImportJobResource index-only
2 parents c7537bb + 5853d5f commit 3913e38

File tree

2 files changed

+22
-32
lines changed

2 files changed

+22
-32
lines changed

app/Filament/App/Resources/GedcomResource/Pages/CreateGedcom.php

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,25 @@ protected function handleRecordCreation(array $data): Model
3131
$path = $filtered !== [] ? $filtered[0] : null;
3232
}
3333

34+
$data['filename'] = (string) ($path ?? '');
35+
36+
return Gedcom::create($data);
37+
}
38+
39+
protected function afterCreate(): void
40+
{
41+
$path = $this->record->filename;
42+
43+
// FileUpload may store as array even when multiple(false) is set
44+
if (is_array($path)) {
45+
$filtered = array_values(array_filter($path));
46+
$path = $filtered !== [] ? $filtered[0] : null;
47+
}
48+
3449
$path = (string) ($path ?? '');
3550

3651
if (! $path) {
37-
Notification::make()
38-
->title('No file selected')
39-
->body('Please upload a GEDCOM or GrampsXML file.')
40-
->danger()
41-
->send();
42-
43-
$this->halt();
52+
return;
4453
}
4554

4655
$disk = Storage::disk('private');
@@ -51,34 +60,22 @@ protected function handleRecordCreation(array $data): Model
5160
if (str_starts_with($path, 'livewire-tmp/') && $disk->exists($path)) {
5261
$newPath = 'gedcom-form-imports/' . basename($path);
5362
$disk->move($path, $newPath);
54-
$path = $newPath;
55-
$data['filename'] = $newPath;
63+
$path = $newPath;
64+
$this->record->update(['filename' => $newPath]);
5665

5766
Log::info('CreateGedcom: moved upload from livewire-tmp to gedcom-form-imports', [
5867
'new_path' => $newPath,
5968
]);
6069
}
6170

62-
// Ensure the (possibly moved) filename is written into the record
63-
$data['filename'] = $path;
64-
$gedcom = Gedcom::create($data);
65-
6671
// Verify the file actually exists before dispatching the job
6772
if (! $disk->exists($path)) {
6873
Log::error('CreateGedcom: file does not exist on private disk, aborting dispatch', [
69-
'gedcom_id' => $gedcom->getKey(),
74+
'gedcom_id' => $this->record->getKey(),
7075
'path' => $path,
7176
]);
7277

73-
$gedcom->delete();
74-
75-
Notification::make()
76-
->title('Import failed')
77-
->body('The uploaded file could not be found. Please try uploading again.')
78-
->danger()
79-
->send();
80-
81-
$this->halt();
78+
return;
8279
}
8380

8481
$fullPath = $disk->path($path);
@@ -109,7 +106,7 @@ protected function handleRecordCreation(array $data): Model
109106
->send();
110107
} catch (Throwable $e) {
111108
Log::error('Failed to dispatch GEDCOM import job', [
112-
'gedcom_id' => $gedcom->getKey(),
109+
'gedcom_id' => $this->record->getKey(),
113110
'path' => $path,
114111
'full_path' => $fullPath,
115112
'error' => $e->getMessage(),
@@ -122,8 +119,6 @@ protected function handleRecordCreation(array $data): Model
122119
->danger()
123120
->send();
124121
}
125-
126-
return $gedcom;
127122
}
128123

129124
/**

app/Filament/App/Resources/ImportJobResource.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
namespace App\Filament\App\Resources;
44

55
use App\Filament\App\Resources\ImportJobResource\Pages\ListImportJobs;
6-
use App\Filament\App\Resources\ImportJobResource\Pages\ViewImportJob;
76
use App\Models\ImportJob;
8-
use Filament\Actions\ViewAction;
97
use Filament\Tables\Columns\TextColumn;
108
use Filament\Tables\Table;
119
use Illuminate\Database\Eloquent\Builder;
@@ -92,17 +90,14 @@ public static function table(Table $table): Table
9290
])
9391
->defaultSort('created_at', 'desc')
9492
->filters([])
95-
->recordActions([
96-
ViewAction::make(),
97-
])
93+
->recordActions([])
9894
->toolbarActions([]);
9995
}
10096

10197
public static function getPages(): array
10298
{
10399
return [
104100
'index' => ListImportJobs::route('/'),
105-
'view' => ViewImportJob::route('/{record}'),
106101
];
107102
}
108103
}

0 commit comments

Comments
 (0)