[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
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\user; 20 use Symfony\Component\Console\Helper\ProgressBar; 21 use Symfony\Component\Console\Input\InputInterface; 22 use Symfony\Component\Console\Output\OutputInterface; 23 use Symfony\Component\Console\Style\SymfonyStyle; 24 25 class reclean extends command 26 { 27 /** @var driver_interface */ 28 protected $db; 29 30 /** @var language */ 31 protected $language; 32 33 /** @var int A count of the number of re-cleaned user names */ 34 protected $processed; 35 36 /** @var ProgressBar */ 37 protected $progress; 38 39 /** 40 * Construct method 41 * 42 * @param user $user 43 * @param driver_interface $db 44 * @param language $language 45 */ 46 public function __construct(user $user, driver_interface $db, language $language) 47 { 48 $this->db = $db; 49 $this->language = $language; 50 51 parent::__construct($user); 52 } 53 54 /** 55 * Sets the command name and description 56 * 57 * @return null 58 */ 59 protected function configure() 60 { 61 $this 62 ->setName('user:reclean') 63 ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_RECLEAN')) 64 ->setHelp($this->language->lang('CLI_HELP_USER_RECLEAN')) 65 ; 66 } 67 68 /** 69 * Executes the command user:reclean 70 * 71 * Cleans user names that are unclean. 72 * 73 * @param InputInterface $input The input stream used to get the options 74 * @param OutputInterface $output The output stream, used to print messages 75 * 76 * @return int 0 if all is well, 1 if any errors occurred 77 */ 78 protected function execute(InputInterface $input, OutputInterface $output) 79 { 80 $io = new SymfonyStyle($input, $output); 81 82 $io->section($this->language->lang('CLI_USER_RECLEAN_START')); 83 84 $this->processed = 0; 85 86 $this->progress = $this->create_progress_bar($this->get_count(), $io, $output); 87 $this->progress->setMessage($this->language->lang('CLI_USER_RECLEAN_START')); 88 $this->progress->start(); 89 90 $stage = 0; 91 while ($stage !== true) 92 { 93 $stage = $this->reclean_usernames($stage); 94 } 95 96 $this->progress->finish(); 97 98 $io->newLine(2); 99 $io->success($this->language->lang('CLI_USER_RECLEAN_DONE', $this->processed)); 100 101 return 0; 102 } 103 104 /** 105 * Re-clean user names 106 * Only user names that are unclean will be re-cleaned 107 * 108 * @param int $start An offset index 109 * @return bool|int Return the next offset index or true if all records have been processed. 110 */ 111 protected function reclean_usernames($start = 0) 112 { 113 $limit = 500; 114 $i = 0; 115 116 $this->db->sql_transaction('begin'); 117 118 $sql = 'SELECT user_id, username, username_clean FROM ' . USERS_TABLE; 119 $result = $this->db->sql_query_limit($sql, $limit, $start); 120 while ($row = $this->db->sql_fetchrow($result)) 121 { 122 $i++; 123 $username_clean = $this->db->sql_escape(utf8_clean_string($row['username'])); 124 125 if ($username_clean != $row['username_clean']) 126 { 127 $sql = 'UPDATE ' . USERS_TABLE . " 128 SET username_clean = '$username_clean' 129 WHERE user_id = {$row['user_id']}"; 130 $this->db->sql_query($sql); 131 132 $this->processed++; 133 } 134 135 $this->progress->advance(); 136 } 137 $this->db->sql_freeresult($result); 138 139 $this->db->sql_transaction('commit'); 140 141 return ($i < $limit) ? true : $start + $i; 142 } 143 144 /** 145 * Get the count of users in the database 146 * 147 * @return int 148 */ 149 protected function get_count() 150 { 151 $sql = 'SELECT COUNT(user_id) AS count FROM ' . USERS_TABLE; 152 $result = $this->db->sql_query($sql); 153 $count = (int) $this->db->sql_fetchfield('count'); 154 $this->db->sql_freeresult($result); 155 156 return $count; 157 } 158 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |