Issues (364)

app/Jobs/ImportGedcom.php (2 issues)

1
<?php
2
3
namespace App\Jobs;
4
5
use App\Models\ImportJob;
6
use App\Models\User;
7
use App\Tenant\Manager;
8
use FamilyTree365\LaravelGedcom\Utils\GedcomParser;
9
use Illuminate\Bus\Queueable;
10
use Illuminate\Contracts\Queue\ShouldQueue;
11
use Illuminate\Foundation\Bus\Dispatchable;
12
use Illuminate\Queue\InteractsWithQueue;
13
use Illuminate\Queue\SerializesModels;
14
use Illuminate\Support\Facades\File;
15
use Illuminate\Support\Str;
16
17
class ImportGedcom implements ShouldQueue
18
{
19
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Jobs\ImportGedcom: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
20
21
    public int $timeout = 0;
22
    public int $tries = 1;
23
24
    public function __construct(protected User $user, protected string $filePath, protected ?string $slug = null)
25
    {
26
    }
27
28
    public function handle(): int
29
    {
30
        throw_unless(File::isFile($this->filePath), \Exception::class, "{$this->filePath} does not exist.");
31
32
        $tenant = Manager::fromModel($this->user->company(), $this->user);
0 ignored issues
show
It seems like $this->user->company() can also be of type null; however, parameter $model of App\Tenant\Manager::fromModel() does only seem to accept Illuminate\Database\Eloquent\Model, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        $tenant = Manager::fromModel(/** @scrutinizer ignore-type */ $this->user->company(), $this->user);
Loading history...
33
        if (! $tenant->databaseExists()) {
34
            //$tenant->dropDatabase();
35
            $tenant->createDatabase();
36
            $tenant->connect();
37
            $tenant->migrateDatabase();
38
        }
39
        $tenant->connect();
40
        $slug = $this->slug ?? Str::uuid();
41
42
        $job = ImportJob::on($tenant->connectionName())->create([
43
            'user_id' => $this->user->getKey(),
44
            'status' => 'queue',
45
            'slug' => $slug,
46
        ]);
47
        $parser = new GedcomParser();
48
49
        $parser->parse($tenant->connectionName(), $this->filePath, $slug, true);
50
        // with(new GedcomParser())->parse($tenant->connectionName(), $this->filePath, $slug, true);
51
52
        File::delete($this->filePath);
53
54
        $job->update(['status' => 'complete']);
55
56
        $tenant->disconnect();
57
58
        return 0;
59
    }
60
}
61