11<?php
22
3+ declare (strict_types=1 );
4+
35namespace App \Jobs ;
46
57use App \Models \Family ;
1214use Illuminate \Foundation \Bus \Dispatchable ;
1315use Illuminate \Queue \InteractsWithQueue ;
1416use Illuminate \Queue \SerializesModels ;
15- use Illuminate \Support \Facades \File ;
1617use Illuminate \Support \Facades \Log ;
1718
18- class ExportGedCom implements ShouldQueue
19+ final readonly class ExportGedCom implements ShouldQueue
1920{
20- use Dispatchable;
21- use InteractsWithQueue;
22- use Queueable;
23- use SerializesModels;
21+ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
2422
25- /**
26- * Create a new job instance.
27- *
28- * @return void
29- */
30- public function __construct (protected string $ file , protected User $ user )
31- {
32- }
23+ public function __construct (
24+ private readonly string $ file ,
25+ private readonly User $ user ,
26+ ) {}
3327
34- /**
35- * Execute the job.
36- *
37- * @return void
38- */
39- public function handle ()
28+ public function handle (): void
4029 {
41- // Establishing tenant connection
42- $ tenant = Manager::fromModel ($ this ->user ->company (), $ this ->user );
43- $ tenant ->connect ();
44-
45- // Fetching all people and families related to the user
46- $ people = Person::all ();
47- $ families = Family::all ();
48-
49- // Logging the count of people and families to be exported
50- Log::info ('Exporting ' .$ people ->count ().' people and ' .$ families ->count ().' families. ' );
30+ try {
31+ $ tenant = Manager::fromModel ($ this ->user ->company (), $ this ->user );
32+ $ tenant ->connect ();
5133
52- // Generating GEDCOM content
53- $ gedcomService = new GedcomService ();
54- $ content = $ gedcomService ->generateGedcomContent ($ people , $ families );
34+ $ people = Person::all ();
35+ $ families = Family::all ();
5536
56- // Storing the GEDCOM file
57- $ manager ->storage ()->put ($ this ->file , $ content );
58- Log::info ('GEDCOM file generated and stored: ' .$ this ->file );
37+ Log::info ("Exporting {$ people ->count ()} people and {$ families ->count ()} families. " );
5938
60- $ up_nest = 3 ;
61- $ down_nest = 3 ;
39+ $ gedcomService = new GedcomService () ;
40+ $ content = $ gedcomService -> generateGedcomContent ( $ people , $ families ) ;
6241
63- $ writer = new GedcomGenerator ($ p_id , $ f_id , $ up_nest , $ down_nest );
64- $ content = $ writer ->getGedcomPerson ();
42+ $ tenant ->storage ()->put ($ this ->file , $ content );
6543
66- // Log::info("content from getGedcomPerson function => \n $content");
67- // var_dump(\Storage::disk('public')->path($this->file), "job");
68- $ manager ->storage ()->put ($ this ->file , $ content );
69- // $filePath = 'public/' . $this->file;
70- // $filePath = $manager->storage()->path($filePath);
71- // chmod_r('/home/genealogia/domains/api.genealogia.co.uk/genealogy/storage/tenants/');
72- // Setting permissions for the GEDCOM file
73- exec ('chmod 0644 ' .$ manager ->storage ()->path ($ this ->file ));
74- Log::info ('Permissions set for GEDCOM file. ' );
44+ chmod ($ tenant ->storage ()->path ($ this ->file ), 0644 );
7545
76- // Handling errors and exceptions
77- try {
78- // Export logic here
79- } catch (\Exception $ e ) {
80- Log::error ('Error during GEDCOM export: ' .$ e ->getMessage ());
46+ Log::info ('GEDCOM file generated and stored successfully. ' );
47+ } catch (\Throwable $ e ) {
48+ Log::error ('Error during GEDCOM export: ' . $ e ->getMessage ());
49+ throw $ e ;
8150 }
82- //exec ("find /home/genealogia/ap -type d -exec chmod 0750 {} +");
83- //exec ("find /path/to/folder -type f -exec chmod 0644 {} +");
84- // var_dump($path,'path');
8551 }
86- }
52+ }
0 commit comments