equal
deleted
inserted
replaced
|
1 <?php |
|
2 |
|
3 // Migrate usernames in the logs table |
|
4 |
|
5 global $db, $session, $paths, $template, $plugins; // Common objects |
|
6 |
|
7 $q = $db->sql_query('SELECT user_id, username FROM users;'); |
|
8 if ( !$q ) |
|
9 $db->_die(); |
|
10 |
|
11 $map = array(); |
|
12 while($row = $db->fetchrow()) |
|
13 { |
|
14 $map[ $row['username'] ] = $row['user_id']; |
|
15 } |
|
16 $db->free_result(); |
|
17 |
|
18 $q = $db->sql_query('SELECT author FROM logs WHERE author_uid = 1;'); |
|
19 if ( !$q ) |
|
20 $db->_die(); |
|
21 |
|
22 $updated = array(); |
|
23 |
|
24 while ( $row = $db->fetchrow($q) ) |
|
25 { |
|
26 if ( isset($map[ $row['author'] ]) && !is_valid_ip($row['author']) && !in_array($row['author'], $updated) ) |
|
27 { |
|
28 $author = $db->escape($row['author']); |
|
29 $sql = "UPDATE logs SET author_uid = {$map[ $row['author'] ]} WHERE author = '$author';"; |
|
30 if ( !$db->sql_query($sql) ) |
|
31 $db->_die(); |
|
32 $updated[] = $row['author']; |
|
33 } |
|
34 } |
|
35 |