Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/User/StatusCommand.php
<?php | <?php | ||||
namespace App\Console\Commands\User; | namespace App\Console\Commands\User; | ||||
use App\User; | |||||
use Illuminate\Console\Command; | use Illuminate\Console\Command; | ||||
class StatusCommand extends Command | class StatusCommand extends Command | ||||
{ | { | ||||
/** | /** | ||||
* The name and signature of the console command. | * The name and signature of the console command. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $signature = 'user:status {user}'; | protected $signature = 'user:status {user}'; | ||||
/** | /** | ||||
* The console command description. | * The console command description. | ||||
* | * | ||||
* @var string | * @var string | ||||
*/ | */ | ||||
protected $description = "Show a user's status."; | protected $description = "Show a user's status."; | ||||
/** | /** | ||||
* Create a new command instance. | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function __construct() | |||||
{ | |||||
parent::__construct(); | |||||
} | |||||
/** | |||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$user = \App\User::withTrashed()->withEnvTenantContext()->where('email', $this->argument('user'))->first(); | $user = User::withTrashed()->withEnvTenantContext()->where('email', $this->argument('user'))->first(); | ||||
if (!$user) { | if (!$user) { | ||||
$user = \App\User::withTrashed()->withEnvTenantContext()->where('id', $this->argument('user'))->first(); | $user = User::withTrashed()->withEnvTenantContext()->where('id', $this->argument('user'))->first(); | ||||
} | } | ||||
if (!$user) { | if (!$user) { | ||||
$this->error("No such user '" . $this->argument('user') . "' within this tenant context."); | $this->error("No such user '" . $this->argument('user') . "' within this tenant context."); | ||||
$this->info("Try ./artisan scalpel:user:read --attr=email --attr=tenant_id " . $this->argument('user')); | $this->info("Try ./artisan scalpel:user:read --attr=email --attr=tenant_id " . $this->argument('user')); | ||||
return 1; | return 1; | ||||
} | } | ||||
$statuses = [ | $statuses = [ | ||||
'active' => \App\User::STATUS_ACTIVE, | 'active' => User::STATUS_ACTIVE, | ||||
'suspended' => \App\User::STATUS_SUSPENDED, | 'suspended' => User::STATUS_SUSPENDED, | ||||
'deleted' => \App\User::STATUS_DELETED, | 'deleted' => User::STATUS_DELETED, | ||||
'ldapReady' => \App\User::STATUS_LDAP_READY, | 'ldapReady' => User::STATUS_LDAP_READY, | ||||
'imapReady' => \App\User::STATUS_IMAP_READY, | 'imapReady' => User::STATUS_IMAP_READY, | ||||
'degraded' => User::STATUS_DEGRADED, | |||||
]; | ]; | ||||
$user_state = []; | $user_state = []; | ||||
foreach (\array_keys($statuses) as $state) { | foreach (\array_keys($statuses) as $state) { | ||||
$func = 'is' . \ucfirst($state); | $func = 'is' . \ucfirst($state); | ||||
if ($user->$func()) { | if ($user->$func()) { | ||||
$user_state[] = $state; | $user_state[] = $state; | ||||
} | } | ||||
} | } | ||||
$this->info("Status: " . \implode(',', $user_state)); | $this->info("Status: " . \implode(',', $user_state)); | ||||
} | } | ||||
} | } |