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

Commit

Permalink
Merge pull request #2147 from cgdprojects/analysis-EPDL1x
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
curtisdelicata authored Dec 17, 2022
2 parents 20cf25e + a7c7946 commit 02409ff
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 65 deletions.
22 changes: 9 additions & 13 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private function loggableUser(Request $request)
$c_id = $main_company->id;
}
$tenants = Tenant::find($main_company->id);
if ($main_company == null&& ! $user->isAdmin()) {
if ($main_company == null && ! $user->isAdmin()) {
// if (($main_company == null||$tenants=='') && ! $user->isAdmin()) {
// if ($main_company == null) {
$company_count = Company::count();
Expand Down Expand Up @@ -178,29 +178,25 @@ private function loggableUser(Request $request)
CreateDBs::dispatch($company);
\Log::debug('Migration----------------------'.$company);
Migrations::dispatch($company, $user->name, $user->email, $user->password);

}else{


if($tenants){
} else {
if ($tenants) {
// $c = DB::connection('tenantdb',$tenants->tenancy_db_name)->table('users')->count();
$company=\App\Models\Company::find($main_company->id);
$company = \App\Models\Company::find($main_company->id);
tenancy()->initialize($tenants);
$tenants->run(function () use ($company, $user){

$tenants->run(function () use ($company, $user) {

// $company->save();
$c= User::count();
if($c==0){
$c = User::count();
if ($c == 0) {
\Log::debug('Migration----------------------');
return Migrations::dispatch($company, $user->name, $user->email, $user->password);

return Migrations::dispatch($company, $user->name, $user->email, $user->password);
}
// \Log::debug($company->id.-'users----------------------'.$c);
});

return $user;
}

}
}

Expand Down
19 changes: 9 additions & 10 deletions app/Http/Controllers/Company/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@

use App\Jobs\Tenant\CreateDBs;
use App\Jobs\Tenant\Migrations;
use App\Models\Company as Company1;
use App\Traits\TenantConnectionResolver;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use LaravelEnso\Api\Models\Log;
use LaravelEnso\Companies\Http\Requests\ValidateCompany;
use LaravelEnso\Companies\Models\Company;
use \App\Traits\TenantConnectionResolver;
use App\Models\Company as Company1;

class Store extends Controller
{
use AuthorizesRequests;
use TenantConnectionResolver;

public function __invoke(ValidateCompany $request, Company $company)
{

$company->fill($request->validatedExcept('mandatary'));
$clone = $request->post();
$user = \Auth::user();
Expand All @@ -27,17 +28,15 @@ public function __invoke(ValidateCompany $request, Company $company)
$user_email = $user->email;
$this->authorize('store', $company);
$company->save();
if ($user->role_id!=1){

if ($user->role_id != 1) {
$c = new Company1();

$c->fill($clone);
$c->created_by=1;
$c->updated_by=null;
$c->setAttribute('created_by',1);
$c->setAttribute('updated_by',null);
$c->created_by = 1;
$c->updated_by = null;
$c->setAttribute('created_by', 1);
$c->setAttribute('updated_by', null);
$c->save();

}
CreateDBs::dispatch($company, $user_id);
Migrations::dispatch($company, $user_id, $person_name, $user_email);
Expand Down
43 changes: 20 additions & 23 deletions app/Http/Middleware/Multitenant.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace App\Http\Middleware;

use App\Models\Family;
use App\Models\Tenant as T1;
use App\Models\User;
use App\Service\MixedConnection;
use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use LaravelEnso\Companies\Models\Company;
// use App\Models\enso\companies\Company;
use LaravelEnso\Companies\Models\Company;
use LaravelEnso\Multitenancy\Services\Tenant;
use App\Models\Tenant as T1;

class Multitenant
{
/**
Expand All @@ -26,32 +27,28 @@ public function handle($request, Closure $next)
// $tenatDB=\App\Models\Tenant::where('id',Auth::id())->get();
// Log::debug();



$user = \Auth::user();
Log::debug($user->role_id.'-roleId');
$conn = \Session::get('conn');
//$value = \Session::get('db');
if ($user->isAdmin()){
$key = 'database.connections.mysql.database';
$value =env('DB_DATABASE', 'enso');
}else{
$key = 'database.connections.tenantdb.database';
if (session()->get('db')) {
$value = session()->get('db');
}else{
$company = $user->person->company();
$value = $company->tenancy_db_name;
}

$conn = \Session::get('conn');
//$value = \Session::get('db');
if ($user->isAdmin()) {
$key = 'database.connections.mysql.database';
$value = env('DB_DATABASE', 'enso');
} else {
$key = 'database.connections.tenantdb.database';
if (session()->get('db')) {
$value = session()->get('db');
} else {
$company = $user->person->company();
$value = $company->tenancy_db_name;
}
Log::debug($value);
}
Log::debug($value);
// Log::debug($company);
session()->put('db', $value);
//if ($conn === 'tenant') {

$x = config([$key => $value]);
session()->put('db', $value);
//if ($conn === 'tenant') {

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

//Family::setConnection();
// config(['database.default'=>'tenant']);
Expand Down
6 changes: 3 additions & 3 deletions app/Jobs/Tenant/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function handle()
$em = $this->email;
$na = $this->name;
$person = $tenants->run(function () use ($em, $na) {
return Person::create([
return Person::create([
'email'=>$em,
'name' => $na,

Expand All @@ -82,7 +82,7 @@ public function handle()
\Log::debug($person);
\Log::debug('person created');
$user_group = 1;
$user_group = $tenants->run(function () use ($em, $na) {
$user_group = $tenants->run(function () {
return UserGroup::create([
'name'=>'Administrators',
'description' => 'Administrator users group',
Expand All @@ -91,7 +91,7 @@ public function handle()
});
// get role_id
// $role = 1;
$role = $tenants->run(function () use ($em, $na) {
$role = $tenants->run(function () {
return Role::create([
'name'=>'Admin',
'menu_id '=>null,
Expand Down
3 changes: 1 addition & 2 deletions app/Models/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace App\Models;

use App\Traits\TenantConnectionResolver;
use App\Traits\CreatedBy;
use App\Traits\TenantConnectionResolver;
use Illuminate\Support\Facades\Auth;
use LaravelEnso\Companies\Models\Company as CoreCompany;

class Company extends CoreCompany
{
use TenantConnectionResolver,CreatedBy;

}
4 changes: 2 additions & 2 deletions app/Models/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public static function bootUpdatedBy()

public function setUpdatedBy()
{
if (!is_dir(storage_path('app/public'))) {
if (! is_dir(storage_path('app/public'))) {
// dir doesn't exist, make it
\File::makeDirectory(storage_path().'/'.'app/public',0777,true);
\File::makeDirectory(storage_path().'/'.'app/public', 0777, true);

// mkdir(storage_path('app/public/'), 0700);
}
Expand Down
11 changes: 5 additions & 6 deletions app/Traits/CreatedBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ public function createdBy(): Relation
return $this->belongsTo($userModel, 'created_by');
}

private function setCreatedBy($value=1)
private function setCreatedBy($value = 1)
{
// if($value==''){
// if (Auth::check()) {
// $this->created_by = Auth::id();
// }
// }else{
$this->created_by = $value;
$this->created_by = $value;
// }

}

public static function bootUpdatedBy()
{
self::creating(fn ($model) => $model->setUpdatedBy());
Expand All @@ -44,15 +44,14 @@ public function UpdatedBy(): Relation
return $this->belongsTo($userModel, 'updated_by');
}

private function setUpdatedBy($value=1)
private function setUpdatedBy($value = 1)
{
// if($value==''){
// if (Auth::check()) {
// $this->updated_by = Auth::id();
// }
// }else{
$this->updated_by = $value;
$this->updated_by = $value;
// }

}
}
1 change: 0 additions & 1 deletion app/Traits/TenantConnectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function getConnectionName()
}
}


return $this->connection;
}
}
4 changes: 2 additions & 2 deletions config/cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
'allowed_methods' => ['*'],

'allowed_origins' => [
'http://pusher.com',
'http://pusher.com',
'https://pusher.com',
'http://localhost:8080',
'http://localhost:3000',
'http://localhost:8000',
'https://familytree365.com',
'https://api.familytree365.com',
'https://www.familytree365.com',],
'https://www.familytree365.com', ],

'allowed_origins_patterns' => [],

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class CreateAvatarsTable extends Migration
{
public function up()

{
Schema::create('avatars', function (Blueprint $table) {
$table->increments('id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
$table->integer('type_id')->default(0);
$table->string('original_name')->index();
$table->string('saved_name')->index();
// $table->string('path');
// $table->string('path');

$table->integer('size');
$table->string('mime_type')->nullable();
Expand Down
1 change: 0 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,6 @@
Route::get('trees/options', [TreesManage::class, 'getOptions']);
});


//Route::get('test/{cid}', function($cid){
// session('current_company_id', $cid);
// retrun success;
Expand Down

0 comments on commit 02409ff

Please sign in to comment.