forked from liberu-genealogy/genealogy-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportGedCom.php
More file actions
53 lines (41 loc) · 1.46 KB
/
ExportGedCom.php
File metadata and controls
53 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace App\Jobs;
use Throwable;
use App\Models\Family;
use App\Models\Person;
use App\Models\User;
use App\Services\GedcomService;
use App\Tenant\Manager;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
final class ExportGedCom implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function __construct(
private readonly string $file,
private readonly User $user,
) {}
public function handle(): void
{
try {
$tenant = Manager::fromModel($this->user->company(), $this->user);
$tenant->connect();
$people = Person::all();
$families = Family::all();
Log::info("Exporting {$people->count()} people and {$families->count()} families.");
$gedcomService = new GedcomService();
$content = $gedcomService->generateGedcomContent($people, $families);
$tenant->storage()->put($this->file, $content);
chmod($tenant->storage()->path($this->file), 0600);
Log::info('GEDCOM file generated and stored successfully.');
} catch (Throwable $e) {
Log::error('Error during GEDCOM export: ' . $e->getMessage());
throw $e;
}
}
}