[ Index ]

PHP Cross Reference of phpBB-3.3.11-deutsch

title

Body

[close]

/phpbb/console/command/user/ -> delete.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\console\command\user;
  15  
  16  use phpbb\console\command\command;
  17  use phpbb\db\driver\driver_interface;
  18  use phpbb\language\language;
  19  use phpbb\log\log_interface;
  20  use phpbb\user;
  21  use phpbb\user_loader;
  22  use Symfony\Component\Console\Input\InputArgument;
  23  use Symfony\Component\Console\Input\InputInterface;
  24  use Symfony\Component\Console\Input\InputOption;
  25  use Symfony\Component\Console\Output\OutputInterface;
  26  use Symfony\Component\Console\Question\ConfirmationQuestion;
  27  use Symfony\Component\Console\Style\SymfonyStyle;
  28  
  29  class delete extends command
  30  {
  31      /** @var driver_interface */
  32      protected $db;
  33  
  34      /** @var language */
  35      protected $language;
  36  
  37      /** @var log_interface */
  38      protected $log;
  39  
  40      /** @var user_loader */
  41      protected $user_loader;
  42  
  43      /**
  44       * phpBB root path
  45       *
  46       * @var string
  47       */
  48      protected $phpbb_root_path;
  49  
  50      /**
  51       * PHP extension.
  52       *
  53       * @var string
  54       */
  55      protected $php_ext;
  56  
  57      /**
  58       * Construct method
  59       *
  60       * @param user             $user
  61       * @param driver_interface $db
  62       * @param language         $language
  63       * @param log_interface    $log
  64       * @param user_loader      $user_loader
  65       * @param string           $phpbb_root_path
  66       * @param string           $php_ext
  67       */
  68  	public function __construct(user $user, driver_interface $db, language $language, log_interface $log, user_loader $user_loader, $phpbb_root_path, $php_ext)
  69      {
  70          $this->db = $db;
  71          $this->language = $language;
  72          $this->log = $log;
  73          $this->user_loader = $user_loader;
  74          $this->phpbb_root_path = $phpbb_root_path;
  75          $this->php_ext = $php_ext;
  76  
  77          $this->language->add_lang('acp/users');
  78          parent::__construct($user);
  79      }
  80  
  81      /**
  82       * Sets the command name and description
  83       *
  84       * @return null
  85       */
  86  	protected function configure()
  87      {
  88          $this
  89              ->setName('user:delete')
  90              ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_DELETE'))
  91              ->addArgument(
  92                  'username',
  93                  InputArgument::REQUIRED,
  94                  $this->language->lang('CLI_DESCRIPTION_USER_DELETE_USERNAME')
  95              )
  96              ->addOption(
  97                  'delete-posts',
  98                  null,
  99                  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  }


Generated: Sat Nov 4 14:26:03 2023 Cross-referenced by PHPXref 0.7.1