/**
* Executes the command user:delete
*
* Deletes a user from the database. An option to delete the user's posts
* is available, by default posts will be retained.
*
* @param InputInterface $input The input stream used to get the options
* @param OutputInterface $output The output stream, used to print messages
*
* @return int 0 if all is well, 1 if any errors occurred
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('username');
$mode = $input->getOption('delete-posts') ? 'remove' : 'retain';
if ($name) {
$io = new SymfonyStyle($input, $output);
$user_id = $this->user_loader->load_user_by_username($name);
$user_row = $this->user_loader->get_user($user_id);
if ($user_row['user_id'] == ANONYMOUS) {
$io->error($this->language->lang('NO_USER'));
return 1;
}
if (!function_exists('user_delete')) {
require $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext;
}
user_delete($mode, $user_row['user_id'], $user_row['username']);
$this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username']));
$io->success($this->language->lang('USER_DELETED'));
}
return 0;
}