Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Command.php
Show First 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | protected function getObjectModel($objectClass, $withDeleted = false) | ||||
} else { | } else { | ||||
$model = new $objectClass(); | $model = new $objectClass(); | ||||
} | } | ||||
if ($this->commandPrefix == 'scalpel') { | if ($this->commandPrefix == 'scalpel') { | ||||
return $model; | return $model; | ||||
} | } | ||||
$modelsWithTenant = [ | |||||
\App\Discount::class, | |||||
\App\Domain::class, | |||||
\App\Group::class, | |||||
\App\Package::class, | |||||
\App\Plan::class, | |||||
\App\Resource::class, | |||||
\App\Sku::class, | |||||
\App\User::class, | |||||
]; | |||||
$modelsWithOwner = [ | $modelsWithOwner = [ | ||||
\App\Wallet::class, | \App\Wallet::class, | ||||
]; | ]; | ||||
$tenantId = \config('app.tenant_id'); | $tenantId = \config('app.tenant_id'); | ||||
// Add tenant filter | // Add tenant filter | ||||
if (in_array($objectClass, $modelsWithTenant)) { | if (in_array(\App\Traits\BelongsToTenantTrait::class, class_uses($objectClass))) { | ||||
$model = $model->withEnvTenantContext(); | $model = $model->withEnvTenantContext(); | ||||
} elseif (in_array($objectClass, $modelsWithOwner)) { | } elseif (in_array($objectClass, $modelsWithOwner)) { | ||||
$model = $model->whereExists(function ($query) use ($tenantId) { | $model = $model->whereExists(function ($query) use ($tenantId) { | ||||
$query->select(DB::raw(1)) | $query->select(DB::raw(1)) | ||||
->from('users') | ->from('users') | ||||
->whereRaw('wallets.user_id = users.id') | ->whereRaw('wallets.user_id = users.id') | ||||
->whereRaw('users.tenant_id ' . ($tenantId ? "= $tenantId" : 'is null')); | ->whereRaw('users.tenant_id ' . ($tenantId ? "= $tenantId" : 'is null')); | ||||
}); | }); | ||||
Show All 11 Lines | abstract class Command extends \Illuminate\Console\Command | ||||
* @return \App\Resource|null | * @return \App\Resource|null | ||||
*/ | */ | ||||
public function getResource($resource, $withDeleted = false) | public function getResource($resource, $withDeleted = false) | ||||
{ | { | ||||
return $this->getObject(\App\Resource::class, $resource, 'email', $withDeleted); | return $this->getObject(\App\Resource::class, $resource, 'email', $withDeleted); | ||||
} | } | ||||
/** | /** | ||||
* Find a shared folder. | |||||
* | |||||
* @param string $folder Folder ID or email | |||||
* @param bool $withDeleted Include deleted | |||||
* | |||||
* @return \App\SharedFolder|null | |||||
*/ | |||||
public function getSharedFolder($folder, $withDeleted = false) | |||||
{ | |||||
return $this->getObject(\App\SharedFolder::class, $folder, 'email', $withDeleted); | |||||
} | |||||
/** | |||||
* Find the user. | * Find the user. | ||||
* | * | ||||
* @param string $user User ID or email | * @param string $user User ID or email | ||||
* @param bool $withDeleted Include deleted | * @param bool $withDeleted Include deleted | ||||
* | * | ||||
* @return \App\User|null | * @return \App\User|null | ||||
*/ | */ | ||||
public function getUser($user, $withDeleted = false) | public function getUser($user, $withDeleted = false) | ||||
▲ Show 20 Lines • Show All 78 Lines • Show Last 20 Lines |