Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
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 |
reclean.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\user;
020 use Symfony\Component\Console\Helper\ProgressBar;
021 use Symfony\Component\Console\Input\InputInterface;
022 use Symfony\Component\Console\Output\OutputInterface;
023 use Symfony\Component\Console\Style\SymfonyStyle;
024
025 class reclean extends command
026 {
027 /** @var driver_interface */
028 protected $db;
029
030 /** @var language */
031 protected $language;
032
033 /** @var int A count of the number of re-cleaned user names */
034 protected $processed;
035
036 /** @var ProgressBar */
037 protected $progress;
038
039 /**
040 * Construct method
041 *
042 * @param user $user
043 * @param driver_interface $db
044 * @param language $language
045 */
046 public function __construct(user $user, driver_interface $db, language $language)
047 {
048 $this->db = $db;
049 $this->language = $language;
050
051 parent::__construct($user);
052 }
053
054 /**
055 * Sets the command name and description
056 *
057 * @return null
058 */
059 protected function configure()
060 {
061 $this
062 ->setName('user:reclean')
063 ->setDescription($this->language->lang('CLI_DESCRIPTION_USER_RECLEAN'))
064 ->setHelp($this->language->lang('CLI_HELP_USER_RECLEAN'))
065 ;
066 }
067
068 /**
069 * Executes the command user:reclean
070 *
071 * Cleans user names that are unclean.
072 *
073 * @param InputInterface $input The input stream used to get the options
074 * @param OutputInterface $output The output stream, used to print messages
075 *
076 * @return int 0 if all is well, 1 if any errors occurred
077 */
078 protected function execute(InputInterface $input, OutputInterface $output)
079 {
080 $io = new SymfonyStyle($input, $output);
081
082 $io->section($this->language->lang('CLI_USER_RECLEAN_START'));
083
084 $this->processed = 0;
085
086 $this->progress = $this->create_progress_bar($this->get_count(), $io, $output);
087 $this->progress->setMessage($this->language->lang('CLI_USER_RECLEAN_START'));
088 $this->progress->start();
089
090 $stage = 0;
091 while ($stage !== true)
092 {
093 $stage = $this->reclean_usernames($stage);
094 }
095
096 $this->progress->finish();
097
098 $io->newLine(2);
099 $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 }
159