Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 76 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
update_user_and_post_data | |
0.00% |
0 / 76 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
2 | |||
run | |
0.00% |
0 / 60 |
|
0.00% |
0 / 1 |
20 | |||
get_step_count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get_task_lang_name | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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\install\module\install_database\task; |
15 | |
16 | use phpbb\install\database_task; |
17 | use phpbb\install\exception\resource_limit_reached_exception; |
18 | use phpbb\install\helper\config; |
19 | use phpbb\install\helper\container_factory; |
20 | use phpbb\install\helper\database; |
21 | use phpbb\install\helper\iohandler\iohandler_interface; |
22 | use phpbb\language\language; |
23 | |
24 | /** |
25 | * Update the admin's info as well as the welcome post. |
26 | */ |
27 | class update_user_and_post_data extends database_task |
28 | { |
29 | /** @var config */ |
30 | private $install_config; |
31 | |
32 | private $iohandler; |
33 | |
34 | /** @var language */ |
35 | private $language; |
36 | |
37 | /** @var \phpbb\passwords\manager */ |
38 | private $password_manager; |
39 | |
40 | /** @var string */ |
41 | private $forums_table; |
42 | |
43 | /** @var string */ |
44 | private $moderator_cache_table; |
45 | |
46 | /** @var string */ |
47 | private $posts_table; |
48 | |
49 | /** @var string */ |
50 | private $topics_table; |
51 | |
52 | /** @var string */ |
53 | private $user_table; |
54 | |
55 | /** |
56 | * Constructor. |
57 | * |
58 | * @param config $install_config |
59 | * @param container_factory $container |
60 | * @param database $db_helper |
61 | * @param iohandler_interface $iohandler |
62 | * @param language $language |
63 | */ |
64 | public function __construct( |
65 | config $install_config, |
66 | container_factory $container, |
67 | database $db_helper, |
68 | iohandler_interface $iohandler, |
69 | language $language) |
70 | { |
71 | $this->install_config = $install_config; |
72 | $this->iohandler = $iohandler; |
73 | $this->language = $language; |
74 | $this->password_manager = $container->get('passwords.manager'); |
75 | |
76 | $this->forums_table = $container->get_parameter('tables.forums'); |
77 | $this->moderator_cache_table = $container->get_parameter('tables.moderator_cache'); |
78 | $this->posts_table = $container->get_parameter('tables.posts'); |
79 | $this->topics_table = $container->get_parameter('tables.topics'); |
80 | $this->user_table = $container->get_parameter('tables.users'); |
81 | |
82 | parent::__construct( |
83 | self::get_doctrine_connection($db_helper, $install_config), |
84 | $this->iohandler, |
85 | true |
86 | ); |
87 | } |
88 | |
89 | /** |
90 | * {@inheritdoc} |
91 | */ |
92 | public function run() |
93 | { |
94 | // Force a refresh. |
95 | $count = $this->install_config->get('correct_user_and_post_data_count'); |
96 | if ($count === false) |
97 | { |
98 | if ($this->install_config->get_time_remaining() < 5) |
99 | { |
100 | $this->install_config->set('correct_user_and_post_data_count', 1); |
101 | throw new resource_limit_reached_exception(); |
102 | } |
103 | } |
104 | |
105 | $user_ip = phpbb_ip_normalise($this->iohandler->get_server_variable('REMOTE_ADDR')); |
106 | $user_ip = ($user_ip === false) ? '' : $user_ip; |
107 | $current_time = $this->install_config->get('install_board_time', time()); |
108 | |
109 | // Update user data |
110 | $sql = 'UPDATE ' . $this->user_table |
111 | . ' SET username = :username,' |
112 | . ' user_password = :password,' |
113 | . ' user_ip = :ip,' |
114 | . ' user_lang = :lang,' |
115 | . ' user_email = :email,' |
116 | . ' user_dateformat = :dateformat,' |
117 | . ' username_clean = :clean_username,' |
118 | . ' user_timezone = :timezone' |
119 | . ' WHERE username = \'Admin\''; |
120 | |
121 | $this->create_and_execute_prepared_stmt($sql, [ |
122 | 'username' => $this->install_config->get('admin_name'), |
123 | 'password' => $this->password_manager->hash($this->install_config->get('admin_passwd')), |
124 | 'ip' => $user_ip, |
125 | 'lang' => $this->install_config->get('user_language', 'en'), |
126 | 'email' => $this->install_config->get('board_email'), |
127 | 'dateformat' => $this->language->lang('default_dateformat'), |
128 | 'clean_username' => utf8_clean_string($this->install_config->get('admin_name')), |
129 | 'timezone' => $this->install_config->get('admin_timezone'), |
130 | ]); |
131 | $this->exec_sql('UPDATE ' . $this->user_table . ' SET user_regdate = ' . $current_time); |
132 | |
133 | // Update forums table |
134 | $sql = 'UPDATE ' . $this->forums_table |
135 | . ' SET forum_last_poster_name = :poster_name' |
136 | . ' WHERE forum_last_poster_name = \'Admin\''; |
137 | $this->create_and_execute_prepared_stmt($sql, [ |
138 | 'poster_name' => $this->install_config->get('admin_name'), |
139 | ]); |
140 | $this->exec_sql('UPDATE ' . $this->forums_table . ' SET forum_last_post_time = ' . $current_time); |
141 | |
142 | // Topics table |
143 | $sql = 'UPDATE ' . $this->topics_table |
144 | . ' SET topic_first_poster_name = :poster_name,' |
145 | . ' topic_last_poster_name = :poster_name' |
146 | . ' WHERE topic_first_poster_name = \'Admin\'' |
147 | . ' OR topic_last_poster_name = \'Admin\''; |
148 | $this->create_and_execute_prepared_stmt($sql, [ |
149 | 'poster_name' => $this->install_config->get('admin_name'), |
150 | ]); |
151 | $this->exec_sql('UPDATE ' . $this->topics_table |
152 | . ' SET topic_time = ' . $current_time . ', topic_last_post_time = ' . $current_time |
153 | ); |
154 | |
155 | // Posts table |
156 | $sql = 'UPDATE ' . $this->posts_table |
157 | . ' SET post_time = :post_time,' |
158 | . ' poster_ip = :poster_ip'; |
159 | $this->create_and_execute_prepared_stmt($sql, [ |
160 | 'post_time' => $current_time, |
161 | 'poster_ip' => $user_ip, |
162 | ]); |
163 | |
164 | // Moderator cache |
165 | $sql = 'UPDATE ' . $this->moderator_cache_table |
166 | . ' SET username = :username' |
167 | . ' WHERE username = \'Admin\''; |
168 | $this->create_and_execute_prepared_stmt($sql, [ |
169 | 'username' => $this->install_config->get('admin_name'), |
170 | ]); |
171 | } |
172 | |
173 | /** |
174 | * {@inheritdoc} |
175 | */ |
176 | public static function get_step_count() : int |
177 | { |
178 | return 1; |
179 | } |
180 | |
181 | /** |
182 | * {@inheritdoc} |
183 | */ |
184 | public function get_task_lang_name() : string |
185 | { |
186 | return 'TASK_UPDATE_POSTS'; |
187 | } |
188 | } |