install/schemas/upgrade/1.1.6-1.1.7.php
author Dan
Fri, 18 Dec 2009 20:57:28 -0500
changeset 1179 ac861c01a764
child 1181 91911e183685
permissions -rw-r--r--
Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1179
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     1
<?php
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     2
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     3
// Migrate usernames in the logs table
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     4
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     5
global $db, $session, $paths, $template, $plugins; // Common objects
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     6
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     7
$q = $db->sql_query('SELECT user_id, username FROM users;');
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     8
if ( !$q )
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
     9
  $db->_die();
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    10
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    11
$map = array();
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    12
while($row = $db->fetchrow())
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    13
{
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    14
  $map[ $row['username'] ] = $row['user_id'];
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    15
}
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    16
$db->free_result();
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    17
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    18
$q = $db->sql_query('SELECT author FROM logs WHERE author_uid = 1;');
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    19
if ( !$q )
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    20
  $db->_die();
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    21
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    22
$updated = array();
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    23
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    24
while ( $row = $db->fetchrow($q) )
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    25
{
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    26
  if ( isset($map[ $row['author'] ]) && !is_valid_ip($row['author']) && !in_array($row['author'], $updated) )
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    27
  {
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    28
    $author = $db->escape($row['author']);
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    29
    $sql = "UPDATE logs SET author_uid = {$map[ $row['author'] ]} WHERE author = '$author';";
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    30
    if ( !$db->sql_query($sql) )
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    31
      $db->_die();
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    32
    $updated[] = $row['author'];
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    33
  }
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    34
}
ac861c01a764 Added an upgrade hook to populate the author_uid column in logs, pending test by Neal
Dan
parents:
diff changeset
    35