@@ -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 /**
0 commit comments