N98\Magento\Command\Admin\User\ChangeStatusCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer | void
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
return integer | void
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->detectMagento($output);
        if ($this->initMagento()) {
            // Username
            $id = $this->getOrAskForArgument('id', $input, $output, 'Username or Email');
            $user = $this->getUserModel()->loadByUsername($id);
            if (!$user->getId()) {
                $user = $this->getUserModel()->load($id, 'email');
            }
            if (!$user->getId()) {
                $output->writeln('<error>User was not found</error>');
                return;
            }
            try {
                $result = $user->validate();
                if (is_array($result)) {
                    throw new RuntimeException(implode(PHP_EOL, $result));
                }
                if ($input->getOption('activate')) {
                    $user->setIsActive(1);
                }
                if ($input->getOption('deactivate')) {
                    $user->setIsActive(0);
                }
                // toggle is_active
                if (!$input->getOption('activate') && !$input->getOption('deactivate')) {
                    $user->setIsActive(!$user->getIsActive());
                    // toggle
                }
                $user->save();
                if ($user->getIsActive() == 1) {
                    $output->writeln('<info>User <comment>' . $user->getUsername() . '</comment>' . ' is now <comment>active</comment></info>');
                } else {
                    $output->writeln('<info>User <comment>' . $user->getUsername() . '</comment>' . ' is now <comment>inactive</comment></info>');
                }
            } catch (Exception $e) {
                $output->writeln('<error>' . $e->getMessage() . '</error>');
            }
        }
    }
ChangeStatusCommand