Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

delete_id.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 5.79 KiB


 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_id 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      /** @var string Bots table */
 044      protected $bots_table;
 045   
 046      /** @var string User group table */
 047      protected $user_group_table;
 048   
 049      /** @var string Users table */
 050      protected $users_table;
 051   
 052      /** @var string phpBB root path */
 053      protected $phpbb_root_path;
 054   
 055      /** @var string PHP extension */
 056      protected $php_ext;
 057   
 058      /**
 059       * Construct method
 060       *
 061       * @param driver_interface $db
 062       * @param language         $language
 063       * @param log_interface    $log
 064       * @param user             $user
 065       * @param user_loader      $user_loader
 066       * @param string           $bots_table
 067       * @param string           $user_group_table
 068       * @param string           $users_table
 069       * @param string           $phpbb_root_path
 070       * @param string           $php_ext
 071       */
 072      public function __construct(driver_interface $db, language $language, log_interface $log, user $user, user_loader $user_loader,
 073                                  string $bots_table, string $user_group_table, string $users_table, string $phpbb_root_path, string $php_ext)
 074      {
 075          $this->db = $db;
 076          $this->language = $language;
 077          $this->log = $log;
 078          $this->user_loader = $user_loader;
 079          $this->bots_table = $bots_table;
 080          $this->user_group_table = $user_group_table;
 081          $this->users_table = $users_table;
 082          $this->phpbb_root_path = $phpbb_root_path;
 083          $this->php_ext = $php_ext;
 084   
 085          $this->language->add_lang('acp/users');
 086          parent::__construct($user);
 087      }
 088   
 089      /**
 090       * Sets the command name and description
 091       *
 092       * @return void
 093       */
 094      protected function configure(): void
 095      {
 096          $this
 097              ->setName('user:delete_id')
 098              ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_DELETE_ID'))
 099              ->addArgument(
 100                  'user_ids',
 101                  InputArgument::REQUIRED | InputArgument::IS_ARRAY,
 102                  $this->language->lang('CLI_DESCRIPTION_USER_DELETE_ID_OPTION_ID')
 103              )
 104              ->addOption(
 105                  'delete-posts',
 106                  null,
 107                  InputOption::VALUE_NONE,
 108                  $this->language->lang('CLI_DESCRIPTION_USER_DELETE_OPTION_POSTS')
 109              )
 110          ;
 111      }
 112   
 113      /**
 114       * Executes the command user:delete_ids
 115       *
 116       * Deletes a list of user ids from the database. An option to delete the users' posts
 117       * is available, by default posts will be retained.
 118       *
 119       * @param InputInterface  $input  The input stream used to get the options
 120       * @param OutputInterface $output The output stream, used to print messages
 121       *
 122       * @return int 0 if all is well, 1 if any errors occurred
 123       */
 124      protected function execute(InputInterface $input, OutputInterface $output): int
 125      {
 126          $user_ids = $input->getArgument('user_ids');
 127          $mode = ($input->getOption('delete-posts')) ? 'remove' : 'retain';
 128          $deleted_users = 0;
 129          $io = new SymfonyStyle($input, $output);
 130   
 131          if (count($user_ids) > 0)
 132          {
 133              $this->user_loader->load_users($user_ids);
 134   
 135              $progress = $this->create_progress_bar(count($user_ids), $io, $output);
 136              $progress->setMessage($this->language->lang('CLI_USER_DELETE_ID_START'));
 137              $progress->start();
 138   
 139              foreach ($user_ids as $user_id)
 140              {
 141                  $user_row = $this->user_loader->get_user($user_id);
 142   
 143                  // Skip anonymous user
 144                  if ($user_row['user_id'] == ANONYMOUS)
 145                  {
 146                      $progress->advance();
 147                      continue;
 148                  }
 149                  else if ($user_row['user_type'] == USER_IGNORE)
 150                  {
 151                      $this->delete_bot_user($user_row);
 152                  }
 153                  else
 154                  {
 155                      if (!function_exists('user_delete'))
 156                      {
 157                          require($this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext);
 158                      }
 159   
 160                      user_delete($mode, $user_row['user_id'], $user_row['username']);
 161   
 162                      $this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username']));
 163                  }
 164   
 165                  $progress->advance();
 166                  $deleted_users++;
 167              }
 168   
 169              $progress->finish();
 170   
 171              if ($deleted_users > 0)
 172              {
 173                  $io->success($this->language->lang('CLI_USER_DELETE_ID_SUCCESS'));
 174              }
 175          }
 176   
 177          if (!$deleted_users)
 178          {
 179              $io->note($this->language->lang('CLI_USER_DELETE_NONE'));
 180          }
 181   
 182          return 0;
 183      }
 184   
 185      /**
 186       * Interacts with the user.
 187       * Confirm they really want to delete the account...last chance!
 188       *
 189       * @param InputInterface  $input  An InputInterface instance
 190       * @param OutputInterface $output An OutputInterface instance
 191       */
 192      protected function interact(InputInterface $input, OutputInterface $output): void
 193      {
 194          $helper = $this->getHelper('question');
 195   
 196          $user_ids = $input->getArgument('user_ids');
 197          if (count($user_ids) > 0)
 198          {
 199              $question = new ConfirmationQuestion(
 200                  $this->language->lang('CLI_USER_DELETE_ID_CONFIRM', implode(',', $user_ids)),
 201                  false
 202              );
 203   
 204              if (!$helper->ask($input, $output, $question))
 205              {
 206                  $input->setArgument('user_ids', []);
 207              }
 208          }
 209      }
 210   
 211      /**
 212       * Deletes a bot user
 213       *
 214       * @param array $user_row
 215       * @return void
 216       */
 217      protected function delete_bot_user(array $user_row): void
 218      {
 219          $delete_tables = [$this->bots_table, $this->user_group_table, $this->users_table];
 220          foreach ($delete_tables as $table)
 221          {
 222              $sql = "DELETE FROM $table
 223                  WHERE user_id = " . (int) $user_row['user_id'];
 224              $this->db->sql_query($sql);
 225          }
 226      }
 227  }
 228