Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
delete.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\console\command\user;
015
016 use phpbb\console\command\command;
017 use phpbb\db\driver\driver_interface;
018 use phpbb\language\language;
019 use phpbb\log\log_interface;
020 use phpbb\user;
021 use phpbb\user_loader;
022 use Symfony\Component\Console\Input\InputArgument;
023 use Symfony\Component\Console\Input\InputInterface;
024 use Symfony\Component\Console\Input\InputOption;
025 use Symfony\Component\Console\Output\OutputInterface;
026 use Symfony\Component\Console\Question\ConfirmationQuestion;
027 use Symfony\Component\Console\Style\SymfonyStyle;
028
029 class delete extends command
030 {
031 /** @var driver_interface */
032 protected $db;
033
034 /** @var language */
035 protected $language;
036
037 /** @var log_interface */
038 protected $log;
039
040 /** @var user_loader */
041 protected $user_loader;
042
043 /**
044 * phpBB root path
045 *
046 * @var string
047 */
048 protected $phpbb_root_path;
049
050 /**
051 * PHP extension.
052 *
053 * @var string
054 */
055 protected $php_ext;
056
057 /**
058 * Construct method
059 *
060 * @param user $user
061 * @param driver_interface $db
062 * @param language $language
063 * @param log_interface $log
064 * @param user_loader $user_loader
065 * @param string $phpbb_root_path
066 * @param string $php_ext
067 */
068 public function __construct(user $user, driver_interface $db, language $language, log_interface $log, user_loader $user_loader, $phpbb_root_path, $php_ext)
069 {
070 $this->db = $db;
071 $this->language = $language;
072 $this->log = $log;
073 $this->user_loader = $user_loader;
074 $this->phpbb_root_path = $phpbb_root_path;
075 $this->php_ext = $php_ext;
076
077 $this->language->add_lang('acp/users');
078 parent::__construct($user);
079 }
080
081 /**
082 * Sets the command name and description
083 *
084 * @return null
085 */
086 protected function configure()
087 {
088 $this
089 ->setName('user:delete')
090 ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_DELETE'))
091 ->addArgument(
092 'username',
093 InputArgument::REQUIRED,
094 $this->language->lang('CLI_DESCRIPTION_USER_DELETE_USERNAME')
095 )
096 ->addOption(
097 'delete-posts',
098 null,
099 InputOption::VALUE_NONE,
100 $this->language->lang('CLI_DESCRIPTION_USER_DELETE_OPTION_POSTS')
101 )
102 ;
103 }
104
105 /**
106 * Executes the command user:delete
107 *
108 * Deletes a user from the database. An option to delete the user's posts
109 * is available, by default posts will be retained.
110 *
111 * @param InputInterface $input The input stream used to get the options
112 * @param OutputInterface $output The output stream, used to print messages
113 *
114 * @return int 0 if all is well, 1 if any errors occurred
115 */
116 protected function execute(InputInterface $input, OutputInterface $output)
117 {
118 $name = $input->getArgument('username');
119 $mode = ($input->getOption('delete-posts')) ? 'remove' : 'retain';
120
121 if ($name)
122 {
123 $io = new SymfonyStyle($input, $output);
124
125 $user_id = $this->user_loader->load_user_by_username($name);
126 $user_row = $this->user_loader->get_user($user_id);
127
128 if ($user_row['user_id'] == ANONYMOUS)
129 {
130 $io->error($this->language->lang('NO_USER'));
131 return 1;
132 }
133
134 if (!function_exists('user_delete'))
135 {
136 require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
137 }
138
139 user_delete($mode, $user_row['user_id'], $user_row['username']);
140
141 $this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username']));
142
143 $io->success($this->language->lang('USER_DELETED'));
144 }
145
146 return 0;
147 }
148
149 /**
150 * Interacts with the user.
151 * Confirm they really want to delete the account...last chance!
152 *
153 * @param InputInterface $input An InputInterface instance
154 * @param OutputInterface $output An OutputInterface instance
155 */
156 protected function interact(InputInterface $input, OutputInterface $output)
157 {
158 $helper = $this->getHelper('question');
159
160 $question = new ConfirmationQuestion(
161 $this->language->lang('CLI_USER_DELETE_CONFIRM', $input->getArgument('username')),
162 false
163 );
164
165 if (!$helper->ask($input, $output, $question))
166 {
167 $input->setArgument('username', false);
168 }
169 }
170 }
171