Check if the user exists before trying to delete him

This commit is contained in:
Joas Schilling 2015-04-23 12:32:46 +02:00
parent f8f354b351
commit 07627084e4
1 changed files with 12 additions and 5 deletions

View File

@ -22,19 +22,20 @@
namespace OC\Core\Command\User;
use OCP\IUserManager;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
class Delete extends Command {
/** @var \OC\User\Manager */
/** @var IUserManager */
protected $userManager;
/**
* @param \OC\User\Manager $userManager
* @param IUserManager $userManager
*/
public function __construct(\OC\User\Manager $userManager) {
public function __construct(IUserManager $userManager) {
$this->userManager = $userManager;
parent::__construct();
}
@ -51,11 +52,17 @@ class Delete extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output) {
$wasSuccessful = $this->userManager->get($input->getArgument('uid'))->delete();
if($wasSuccessful === true) {
$user = $this->userManager->get($input->getArgument('uid'));
if (is_null($user)) {
$output->writeln('User does not exist');
return;
}
if ($user->delete()) {
$output->writeln('The specified user was deleted');
return;
}
$output->writeln('<error>The specified could not be deleted. Please check the logs.</error>');
}
}