diff --git a/src/app/Console/Commands/UserStatus.php b/src/app/Console/Commands/UserStatus.php new file mode 100644 index 00000000..79c90102 --- /dev/null +++ b/src/app/Console/Commands/UserStatus.php @@ -0,0 +1,85 @@ +argument('userid'))->firstOrFail(); + + $this->info("Found user: {$user->id}"); + + $statuses = [ + 'active' => User::STATUS_ACTIVE, + 'suspended' => User::STATUS_SUSPENDED, + 'deleted' => User::STATUS_DELETED, + 'ldapReady' => User::STATUS_LDAP_READY, + 'imapReady' => User::STATUS_IMAP_READY, + ]; + + // I'd prefer "-state" and "+state" syntax, but it's not possible + if ($update = $this->option('del')) { + $delete = true; + } elseif ($update = $this->option('add')) { + $delete = false; + } + + if (!empty($update)) { + $map = \array_change_key_case($statuses); + $update = \strtolower($update); + + if (isset($map[$update])) { + if ($delete && $user->status & $map[$update]) { + $user->status ^= $map[$update]; + $user->save(); + } elseif (!$delete && !($user->status & $map[$update])) { + $user->status |= $map[$update]; + $user->save(); + } + } + } + + $user_state = []; + foreach (\array_keys($statuses) as $state) { + $func = 'is' . \ucfirst($state); + if ($user->$func()) { + $user_state[] = $state; + } + } + + $this->info("Status: " . \implode(',', $user_state)); + } +}