Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
add_user_last_active | |
0.00% |
0 / 31 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
depends_on | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
update_schema | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
revert_schema | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
update_data | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
set_user_last_active | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 |
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\db\migration\data\v33x; |
15 | |
16 | use phpbb\db\migration\migration; |
17 | |
18 | class add_user_last_active extends migration |
19 | { |
20 | public static function depends_on() |
21 | { |
22 | return [ |
23 | '\phpbb\db\migration\data\v33x\v3311', |
24 | ]; |
25 | } |
26 | |
27 | public function update_schema() |
28 | { |
29 | return [ |
30 | 'add_columns' => [ |
31 | $this->table_prefix . 'users' => [ |
32 | 'user_last_active' => ['TIMESTAMP', 0, 'after' => 'user_lastvisit'], |
33 | ], |
34 | ], |
35 | ]; |
36 | } |
37 | |
38 | public function revert_schema() |
39 | { |
40 | return [ |
41 | 'drop_columns' => [ |
42 | $this->table_prefix . 'users' => ['user_last_active'], |
43 | ], |
44 | ]; |
45 | } |
46 | |
47 | public function update_data() |
48 | { |
49 | return [ |
50 | ['custom', [[$this, 'set_user_last_active']]], |
51 | ]; |
52 | } |
53 | |
54 | public function set_user_last_active($start = 0) |
55 | { |
56 | // Get maximum user id from database |
57 | $sql = "SELECT MAX(user_id) AS max_user_id |
58 | FROM {$this->table_prefix}users"; |
59 | $result = $this->db->sql_query($sql); |
60 | $max_id = (int) $this->db->sql_fetchfield('max_user_id'); |
61 | $this->db->sql_freeresult($result); |
62 | |
63 | if ($start > $max_id) |
64 | { |
65 | return; |
66 | } |
67 | |
68 | // Keep setting user_last_active time |
69 | $next_start = $start + 10000; |
70 | |
71 | $sql = 'UPDATE ' . $this->table_prefix . 'users |
72 | SET user_last_active = user_lastvisit |
73 | WHERE user_id > ' . (int) $start . ' |
74 | AND user_id <= ' . (int) ($next_start); |
75 | $this->db->sql_query($sql); |
76 | |
77 | return $next_start; |
78 | } |
79 | } |