Issues (364)

app/Jobs/ExportGedCom.php (2 issues)

1
<?php
2
3
namespace App\Jobs;
4
5
use App\Models\Family;
6
use App\Models\Person;
7
use App\Models\User;
8
use App\Tenant\Manager;
9
use FamilyTree365\LaravelGedcom\Utils\GedcomGenerator;
10
use Illuminate\Bus\Queueable;
11
use Illuminate\Contracts\Queue\ShouldQueue;
12
use Illuminate\Foundation\Bus\Dispatchable;
13
use Illuminate\Queue\InteractsWithQueue;
14
use Illuminate\Queue\SerializesModels;
15
use Illuminate\Support\Facades\File;
16
use Illuminate\Support\Facades\Log;
17
18
class ExportGedCom implements ShouldQueue
19
{
20
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Jobs\ExportGedCom: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
21
22
    /**
23
     * Create a new job instance.
24
     *
25
     * @return void
26
     */
27
    public function __construct(protected $file, protected User $user)
28
    {
29
    }
30
31
    /**
32
     * Execute the job.
33
     *
34
     * @return void
35
     */
36
    public function handle()
37
    {
38
        $p_id = $this->user->person_id; // person_id
39
        $f_id = 0;                      // family_id
40
41
        $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

41
        $tenant = Manager::fromModel(/** @scrutinizer ignore-type */ $this->user->company(), $this->user);
Loading history...
42
        $tenant->connect();
43
44
        $family = Family::where('husband_id', $this->user->id)
45
                ->orWhere('wife_id', $this->user->id)
46
                ->first();
47
        $manager = Manager::fromModel($this->user->company(), $this->user);
48
        if ($family == null) {
49
            $person = Person::where('child_in_family_id', $this->user->id)->first();
50
51
            $f_id = $person != null ? $person->child_in_family_id : 0;
52
        } else {
53
            $f_id = $family->id;
54
        }
55
56
        Log::info("Family Id => $f_id \n Person Id => $p_id");
57
58
        $up_nest = 3;
59
        $down_nest = 3;
60
61
        $writer = new GedcomGenerator($p_id, $f_id, $up_nest, $down_nest);
62
        $content = $writer->getGedcomPerson();
63
64
//        Log::info("content from getGedcomPerson function => \n $content");
65
        // var_dump(\Storage::disk('public')->path($this->file), "job");
66
        $manager->storage()->put($this->file, $content);
67
 //       $filePath = 'public/' . $this->file;
68
//        $filePath = $manager->storage()->path($filePath);
69
        //	chmod_r('/home/genealogia/domains/api.genealogia.co.uk/genealogy/storage/tenants/');
70
        exec('chmod -R 0777 '.storage_path('/tenants/'));
71
        //exec ("find /home/genealogia/ap -type d -exec chmod 0750 {} +");
72
        //exec ("find /path/to/folder -type f -exec chmod 0644 {} +");
73
        // var_dump($path,'path');
74
    }
75
}
76