1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Jobs\Tenant; |
4
|
|
|
|
5
|
|
|
use App\Models\enso\companies\Company; |
|
|
|
|
6
|
|
|
use App\Models\enso\core\UserGroup; |
|
|
|
|
7
|
|
|
use App\Models\enso\Roles\Role; |
|
|
|
|
8
|
|
|
use App\Models\User; |
9
|
|
|
use App\Person; |
10
|
|
|
use App\Service\Tenant; |
11
|
|
|
use DB; |
12
|
|
|
use Illuminate\Bus\Queueable; |
13
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue; |
14
|
|
|
use Illuminate\Foundation\Bus\Dispatchable; |
15
|
|
|
use Illuminate\Queue\InteractsWithQueue; |
16
|
|
|
use Illuminate\Queue\SerializesModels; |
17
|
|
|
use Illuminate\Support\Facades\Artisan; |
18
|
|
|
use Illuminate\Support\Facades\Hash; |
19
|
|
|
use LaravelEnso\Multitenancy\Enums\Connections; |
20
|
|
|
use Str; |
21
|
|
|
|
22
|
|
|
class Migration implements ShouldQueue |
23
|
|
|
{ |
24
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
|
|
|
|
25
|
|
|
private $tenant; |
26
|
|
|
private $name; |
27
|
|
|
private $email; |
28
|
|
|
private $password; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Create a new job instance. |
32
|
|
|
* |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function __construct(Company $tenant, $name = '', $email = '', $password = '') |
36
|
|
|
{ |
37
|
|
|
// |
38
|
|
|
$this->tenant = $tenant; |
39
|
|
|
$this->name = $name; |
40
|
|
|
$this->email = $email; |
41
|
|
|
$this->password = $password; |
42
|
|
|
// $this->queue = 'sync'; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Execute the job. |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
public function handle() |
51
|
|
|
{ |
52
|
|
|
// |
53
|
|
|
|
54
|
|
|
Tenant::set($this->tenant); |
55
|
|
|
$company = Tenant::get(); |
56
|
|
|
$db = Connections::Tenant.$company->id; |
|
|
|
|
57
|
|
|
Artisan::call('migrate', [ |
58
|
|
|
'--database' => Connections::Tenant, |
59
|
|
|
'--path' => '/database/migrations/tenant', |
60
|
|
|
'--force' => true, |
61
|
|
|
]); |
62
|
|
|
Artisan::call('db:seed', [ |
63
|
|
|
'--database' => Connections::Tenant, |
64
|
|
|
'--force' => true, |
65
|
|
|
]); |
66
|
|
|
|
67
|
|
|
$person = DB::connection(Connections::Tenant)->table('people')->insertGetId([ |
68
|
|
|
'email'=>$this->email, |
69
|
|
|
'name' => $this->name, |
70
|
|
|
]); |
71
|
|
|
// get user_group_id |
72
|
|
|
$user_group = 1; |
73
|
|
|
|
74
|
|
|
// get role_id |
75
|
|
|
$role = 1; |
76
|
|
|
|
77
|
|
|
$person = DB::connection(Connections::Tenant)->table('users')->insert([ |
|
|
|
|
78
|
|
|
'email' => $this->email, |
79
|
|
|
'password' => Hash::make($this->password), |
80
|
|
|
'person_id' => $person, |
81
|
|
|
'group_id' => $user_group, |
82
|
|
|
'role_id' => $role, |
83
|
|
|
'is_active' => 1, |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths