1<?php 2/** 3 * @copyright Copyright (c) 2016, ownCloud, Inc. 4 * 5 * @author Joas Schilling <coding@schilljs.com> 6 * @author Roeland Jago Douma <roeland@famdouma.nl> 7 * @author Thomas Müller <thomas.mueller@tmit.eu> 8 * 9 * @license AGPL-3.0 10 * 11 * This code is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Affero General Public License, version 3, 13 * as published by the Free Software Foundation. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Affero General Public License for more details. 19 * 20 * You should have received a copy of the GNU Affero General Public License, version 3, 21 * along with this program. If not, see <http://www.gnu.org/licenses/> 22 * 23 */ 24namespace OC\Core\Command\User; 25 26use OCP\IUserManager; 27use Symfony\Component\Console\Command\Command; 28use Symfony\Component\Console\Input\InputArgument; 29use Symfony\Component\Console\Input\InputInterface; 30use Symfony\Component\Console\Output\OutputInterface; 31 32class Disable extends Command { 33 /** @var IUserManager */ 34 protected $userManager; 35 36 /** 37 * @param IUserManager $userManager 38 */ 39 public function __construct(IUserManager $userManager) { 40 $this->userManager = $userManager; 41 parent::__construct(); 42 } 43 44 protected function configure() { 45 $this 46 ->setName('user:disable') 47 ->setDescription('disables the specified user') 48 ->addArgument( 49 'uid', 50 InputArgument::REQUIRED, 51 'the username' 52 ); 53 } 54 55 protected function execute(InputInterface $input, OutputInterface $output): int { 56 $user = $this->userManager->get($input->getArgument('uid')); 57 if (is_null($user)) { 58 $output->writeln('<error>User does not exist</error>'); 59 return 1; 60 } 61 62 $user->setEnabled(false); 63 $output->writeln('<info>The specified user is disabled</info>'); 64 return 0; 65 } 66} 67