Skip to content
This repository was archived by the owner on Feb 4, 2024. It is now read-only.

Commit 02409ff

Browse files
Merge pull request #2147 from cgdprojects/analysis-EPDL1x
Apply fixes from StyleCI
2 parents 20cf25e + a7c7946 commit 02409ff

File tree

12 files changed

+52
-65
lines changed

12 files changed

+52
-65
lines changed

app/Http/Controllers/Auth/LoginController.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ private function loggableUser(Request $request)
147147
$c_id = $main_company->id;
148148
}
149149
$tenants = Tenant::find($main_company->id);
150-
if ($main_company == null&& ! $user->isAdmin()) {
150+
if ($main_company == null && ! $user->isAdmin()) {
151151
// if (($main_company == null||$tenants=='') && ! $user->isAdmin()) {
152152
// if ($main_company == null) {
153153
$company_count = Company::count();
@@ -178,29 +178,25 @@ private function loggableUser(Request $request)
178178
CreateDBs::dispatch($company);
179179
\Log::debug('Migration----------------------'.$company);
180180
Migrations::dispatch($company, $user->name, $user->email, $user->password);
181-
182-
}else{
183-
184-
185-
if($tenants){
181+
} else {
182+
if ($tenants) {
186183
// $c = DB::connection('tenantdb',$tenants->tenancy_db_name)->table('users')->count();
187-
$company=\App\Models\Company::find($main_company->id);
184+
$company = \App\Models\Company::find($main_company->id);
188185
tenancy()->initialize($tenants);
189-
$tenants->run(function () use ($company, $user){
190-
186+
$tenants->run(function () use ($company, $user) {
191187

192188
// $company->save();
193-
$c= User::count();
194-
if($c==0){
189+
$c = User::count();
190+
if ($c == 0) {
195191
\Log::debug('Migration----------------------');
196-
return Migrations::dispatch($company, $user->name, $user->email, $user->password);
197192

193+
return Migrations::dispatch($company, $user->name, $user->email, $user->password);
198194
}
199195
// \Log::debug($company->id.-'users----------------------'.$c);
200196
});
197+
201198
return $user;
202199
}
203-
204200
}
205201
}
206202

app/Http/Controllers/Company/Store.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44

55
use App\Jobs\Tenant\CreateDBs;
66
use App\Jobs\Tenant\Migrations;
7+
use App\Models\Company as Company1;
8+
use App\Traits\TenantConnectionResolver;
79
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
810
use Illuminate\Routing\Controller;
911
use Illuminate\Support\Facades\Auth;
1012
use LaravelEnso\Api\Models\Log;
1113
use LaravelEnso\Companies\Http\Requests\ValidateCompany;
1214
use LaravelEnso\Companies\Models\Company;
13-
use \App\Traits\TenantConnectionResolver;
14-
use App\Models\Company as Company1;
15+
1516
class Store extends Controller
1617
{
1718
use AuthorizesRequests;
1819
use TenantConnectionResolver;
20+
1921
public function __invoke(ValidateCompany $request, Company $company)
2022
{
21-
2223
$company->fill($request->validatedExcept('mandatary'));
2324
$clone = $request->post();
2425
$user = \Auth::user();
@@ -27,17 +28,15 @@ public function __invoke(ValidateCompany $request, Company $company)
2728
$user_email = $user->email;
2829
$this->authorize('store', $company);
2930
$company->save();
30-
if ($user->role_id!=1){
31-
31+
if ($user->role_id != 1) {
3232
$c = new Company1();
3333

3434
$c->fill($clone);
35-
$c->created_by=1;
36-
$c->updated_by=null;
37-
$c->setAttribute('created_by',1);
38-
$c->setAttribute('updated_by',null);
35+
$c->created_by = 1;
36+
$c->updated_by = null;
37+
$c->setAttribute('created_by', 1);
38+
$c->setAttribute('updated_by', null);
3939
$c->save();
40-
4140
}
4241
CreateDBs::dispatch($company, $user_id);
4342
Migrations::dispatch($company, $user_id, $person_name, $user_email);

app/Http/Middleware/Multitenant.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
namespace App\Http\Middleware;
44

55
use App\Models\Family;
6+
use App\Models\Tenant as T1;
67
use App\Models\User;
78
use App\Service\MixedConnection;
89
use Closure;
910
use Illuminate\Support\Facades\Auth;
1011
use Illuminate\Support\Facades\Log;
11-
use LaravelEnso\Companies\Models\Company;
1212
// use App\Models\enso\companies\Company;
13+
use LaravelEnso\Companies\Models\Company;
1314
use LaravelEnso\Multitenancy\Services\Tenant;
14-
use App\Models\Tenant as T1;
15+
1516
class Multitenant
1617
{
1718
/**
@@ -26,32 +27,28 @@ public function handle($request, Closure $next)
2627
// $tenatDB=\App\Models\Tenant::where('id',Auth::id())->get();
2728
// Log::debug();
2829

29-
30-
3130
$user = \Auth::user();
3231
Log::debug($user->role_id.'-roleId');
33-
$conn = \Session::get('conn');
34-
//$value = \Session::get('db');
35-
if ($user->isAdmin()){
36-
$key = 'database.connections.mysql.database';
37-
$value =env('DB_DATABASE', 'enso');
38-
}else{
39-
$key = 'database.connections.tenantdb.database';
40-
if (session()->get('db')) {
41-
$value = session()->get('db');
42-
}else{
43-
$company = $user->person->company();
44-
$value = $company->tenancy_db_name;
45-
}
46-
32+
$conn = \Session::get('conn');
33+
//$value = \Session::get('db');
34+
if ($user->isAdmin()) {
35+
$key = 'database.connections.mysql.database';
36+
$value = env('DB_DATABASE', 'enso');
37+
} else {
38+
$key = 'database.connections.tenantdb.database';
39+
if (session()->get('db')) {
40+
$value = session()->get('db');
41+
} else {
42+
$company = $user->person->company();
43+
$value = $company->tenancy_db_name;
4744
}
48-
Log::debug($value);
45+
}
46+
Log::debug($value);
4947
// Log::debug($company);
50-
session()->put('db', $value);
51-
//if ($conn === 'tenant') {
52-
53-
$x = config([$key => $value]);
48+
session()->put('db', $value);
49+
//if ($conn === 'tenant') {
5450

51+
$x = config([$key => $value]);
5552

5653
//Family::setConnection();
5754
// config(['database.default'=>'tenant']);

app/Jobs/Tenant/Migrations.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function handle()
7373
$em = $this->email;
7474
$na = $this->name;
7575
$person = $tenants->run(function () use ($em, $na) {
76-
return Person::create([
76+
return Person::create([
7777
'email'=>$em,
7878
'name' => $na,
7979

@@ -82,7 +82,7 @@ public function handle()
8282
\Log::debug($person);
8383
\Log::debug('person created');
8484
$user_group = 1;
85-
$user_group = $tenants->run(function () use ($em, $na) {
85+
$user_group = $tenants->run(function () {
8686
return UserGroup::create([
8787
'name'=>'Administrators',
8888
'description' => 'Administrator users group',
@@ -91,7 +91,7 @@ public function handle()
9191
});
9292
// get role_id
9393
// $role = 1;
94-
$role = $tenants->run(function () use ($em, $na) {
94+
$role = $tenants->run(function () {
9595
return Role::create([
9696
'name'=>'Admin',
9797
'menu_id '=>null,

app/Models/Company.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace App\Models;
44

5-
use App\Traits\TenantConnectionResolver;
65
use App\Traits\CreatedBy;
6+
use App\Traits\TenantConnectionResolver;
77
use Illuminate\Support\Facades\Auth;
88
use LaravelEnso\Companies\Models\Company as CoreCompany;
99

1010
class Company extends CoreCompany
1111
{
1212
use TenantConnectionResolver,CreatedBy;
13-
1413
}

app/Models/Person.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ public static function bootUpdatedBy()
147147

148148
public function setUpdatedBy()
149149
{
150-
if (!is_dir(storage_path('app/public'))) {
150+
if (! is_dir(storage_path('app/public'))) {
151151
// dir doesn't exist, make it
152-
\File::makeDirectory(storage_path().'/'.'app/public',0777,true);
152+
\File::makeDirectory(storage_path().'/'.'app/public', 0777, true);
153153

154154
// mkdir(storage_path('app/public/'), 0700);
155155
}

app/Traits/CreatedBy.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ public function createdBy(): Relation
2121
return $this->belongsTo($userModel, 'created_by');
2222
}
2323

24-
private function setCreatedBy($value=1)
24+
private function setCreatedBy($value = 1)
2525
{
2626
// if($value==''){
2727
// if (Auth::check()) {
2828
// $this->created_by = Auth::id();
2929
// }
3030
// }else{
31-
$this->created_by = $value;
31+
$this->created_by = $value;
3232
// }
33-
3433
}
34+
3535
public static function bootUpdatedBy()
3636
{
3737
self::creating(fn ($model) => $model->setUpdatedBy());
@@ -44,15 +44,14 @@ public function UpdatedBy(): Relation
4444
return $this->belongsTo($userModel, 'updated_by');
4545
}
4646

47-
private function setUpdatedBy($value=1)
47+
private function setUpdatedBy($value = 1)
4848
{
4949
// if($value==''){
5050
// if (Auth::check()) {
5151
// $this->updated_by = Auth::id();
5252
// }
5353
// }else{
54-
$this->updated_by = $value;
54+
$this->updated_by = $value;
5555
// }
56-
5756
}
5857
}

app/Traits/TenantConnectionResolver.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function getConnectionName()
2222
}
2323
}
2424

25-
2625
return $this->connection;
2726
}
2827
}

config/cors.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
'allowed_methods' => ['*'],
2525

2626
'allowed_origins' => [
27-
'http://pusher.com',
27+
'http://pusher.com',
2828
'https://pusher.com',
2929
'http://localhost:8080',
3030
'http://localhost:3000',
3131
'http://localhost:8000',
3232
'https://familytree365.com',
3333
'https://api.familytree365.com',
34-
'https://www.familytree365.com',],
34+
'https://www.familytree365.com', ],
3535

3636
'allowed_origins_patterns' => [],
3737

database/migrations/tenant/2017_01_01_113000_create_avatars_table.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
class CreateAvatarsTable extends Migration
88
{
99
public function up()
10-
1110
{
1211
Schema::create('avatars', function (Blueprint $table) {
1312
$table->increments('id');

0 commit comments

Comments
 (0)