Stores the full data in the user cache so they do not need to be loaded again
Returns the user id so you may use get_user() from the returned value
public load_user_by_username ( string $username ) : integer | ||
$username | string | Raw username to load (will be cleaned) |
Résultat | integer | User ID for the username |
/** * 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; }
/** * Executes the command user:activate * * Activate (or deactivate) a user account * * @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) { $io = new SymfonyStyle($input, $output); $name = $input->getArgument('username'); $mode = $input->getOption('deactivate') ? 'deactivate' : 'activate'; $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; } // Check if the user is already active (or inactive) if ($mode == 'activate' && $user_row['user_type'] != USER_INACTIVE) { $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE')); return 1; } else { if ($mode == 'deactivate' && $user_row['user_type'] == USER_INACTIVE) { $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE')); return 1; } } // Activate the user account if (!function_exists('user_active_flip')) { require $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext; } user_active_flip($mode, $user_row['user_id']); // Notify the user upon activation if ($mode == 'activate' && $this->config['require_activation'] == USER_ACTIVATION_ADMIN) { $this->send_notification($user_row, $input); } // Log and display the result $msg = $mode == 'activate' ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED'; $log = $mode == 'activate' ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE'; $this->log->add('admin', ANONYMOUS, '', $log, false, array($user_row['username'])); $this->log->add('user', ANONYMOUS, '', $log . '_USER', false, array('reportee_id' => $user_row['user_id'])); $io->success($this->language->lang($msg)); return 0; }