1 | <?php |
||
2 | |||
3 | namespace App\Jobs; |
||
4 | |||
5 | use App\ImportJob; |
||
6 | use Illuminate\Bus\Queueable; |
||
7 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
8 | use Illuminate\Foundation\Bus\Dispatchable; |
||
9 | use Illuminate\Http\Request; |
||
10 | use Illuminate\Queue\InteractsWithQueue; |
||
11 | use Illuminate\Queue\SerializesModels; |
||
12 | use Illuminate\Support\Facades\Artisan; |
||
13 | use Illuminate\Support\Facades\File; |
||
14 | use ModularSoftware\LaravelGedcom\Utils\GedcomParser; |
||
15 | |||
16 | class ImportGedcom implements ShouldQueue |
||
17 | { |
||
18 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
19 | protected $filename; |
||
20 | protected $slug; |
||
21 | protected $user_id; |
||
22 | protected $conn; |
||
23 | protected $db; |
||
24 | public $tries = 1; |
||
25 | public $timeout = 0; |
||
26 | |||
27 | /** |
||
28 | * Create a new job instance. |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function __construct($filename, $slug, $user_id, $conn, $db) |
||
33 | { |
||
34 | // |
||
35 | $this->filename = $filename; |
||
36 | $this->slug = $slug; |
||
37 | $this->user_id = $user_id; |
||
38 | $this->conn = $conn; |
||
39 | $this->db = $db; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Execute the job. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | public function handle() |
||
48 | { |
||
49 | // add import job |
||
50 | $slug = $this->slug; |
||
51 | $user_id = $this->user_id; |
||
52 | $status = 'queue'; |
||
53 | if ($this->conn == 'tenant') { |
||
54 | $key = 'database.connections.tenant.database'; |
||
55 | $value = $this->db; |
||
56 | config([$key => $value]); |
||
57 | } |
||
58 | ImportJob::on($this->conn)->create(compact('user_id', 'slug', 'status')); |
||
59 | |||
60 | $parser = new GedcomParser(); |
||
61 | $parser->parse($this->conn, storage_path($this->filename), $slug, true); |
||
62 | File::delete(storage_path($this->filename)); |
||
63 | |||
64 | // update import job |
||
65 | $status = 'complete'; |
||
66 | ImportJob::on($this->conn)->where('slug', $slug)->where('user_id', $user_id)->update(compact('status')); |
||
67 | |||
68 | return 0; |
||
0 ignored issues
–
show
|
|||
69 | } |
||
70 | } |
||
71 |