Changeset 773

Show
Ignore:
Timestamp:
01/15/07 01:07:18 (2 years ago)
Author:
Neal
Message:

Fix for users appearing multiple times in the online list. Also fixes "Mark topics as read" failing after timeout.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/extras/12_to_1214_update.php

    r603 r773  
    124124        } 
    125125 
     126        // We need to add a unique index to avoid users having multiple rows in the online table 
     127        if ($db_type == 'mysql' || $db_type == 'mysqli') 
     128        { 
     129                $result = $db->query('SHOW INDEX FROM '.$db->prefix.'online') or error('Unable to check DB structure.', __FILE__, __LINE__, $db->error()); 
     130 
     131                if ($db->num_rows($result) == 1) 
     132                        $db->query('ALTER TABLE '.$db->prefix.'online ADD UNIQUE INDEX '.$db->prefix.'online_user_id_ident_idx(user_id,ident)') or error('Unable to alter DB structure.', __FILE__, __LINE__, $db->error()); 
     133        } 
    126134 
    127135        // This feels like a good time to synchronize the forums 
  • trunk/upload/include/functions.php

    r602 r773  
    2828function check_cookie(&$pun_user) 
    2929{ 
    30         global $db, $pun_config, $cookie_name, $cookie_seed; 
     30        global $db, $db_type, $pun_config, $cookie_name, $cookie_seed; 
    3131 
    3232        $now = time(); 
     
    7676                        // Update the online list 
    7777                        if (!$pun_user['logged']) 
    78                                 $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); 
     78                        { 
     79                                $pun_user['logged'] = $now; 
     80                                 
     81                                // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table 
     82                                switch ($db_type) 
     83                                { 
     84                                        case 'mysql': 
     85                                        case 'mysqli': 
     86                                                $db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); 
     87                                                break; 
     88 
     89                                        default: 
     90                                                $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$db->escape($pun_user['username']).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); 
     91                                                break; 
     92                                } 
     93                        } 
    7994                        else 
    8095                        { 
     
    103118function set_default_user() 
    104119{ 
    105         global $db, $pun_user, $pun_config; 
     120        global $db, $db_type, $pun_user, $pun_config; 
    106121 
    107122        $remote_addr = get_remote_address(); 
     
    116131        // Update online list 
    117132        if (!$pun_user['logged']) 
    118                 $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.time().')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); 
     133        { 
     134                $pun_user['logged'] = time(); 
     135 
     136                // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table 
     137                switch ($db_type) 
     138                { 
     139                        case 'mysql': 
     140                        case 'mysqli': 
     141                                $db->query('REPLACE INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); 
     142                                break; 
     143 
     144                        default: 
     145                                $db->query('INSERT INTO '.$db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$db->escape($remote_addr).'\', '.$pun_user['logged'].')') or error('Unable to insert into online list', __FILE__, __LINE__, $db->error()); 
     146                                break; 
     147                } 
     148        } 
    119149        else 
    120150                $db->query('UPDATE '.$db->prefix.'online SET logged='.time().' WHERE ident=\''.$db->escape($remote_addr).'\'') or error('Unable to update online list', __FILE__, __LINE__, $db->error()); 
  • trunk/upload/install.php

    r603 r773  
    12351235                case 'mysqli': 
    12361236                        // We use MySQL's ALTER TABLE ... ADD INDEX syntax instead of CREATE INDEX to avoid problems with users lacking the INDEX privilege 
     1237                        $queries[] = 'ALTER TABLE '.$db_prefix.'online ADD UNIQUE INDEX '.$db_prefix.'online_user_id_ident_idx(user_id,ident)'; 
    12371238                        $queries[] = 'ALTER TABLE '.$db_prefix.'online ADD INDEX '.$db_prefix.'online_user_id_idx(user_id)'; 
    12381239                        $queries[] = 'ALTER TABLE '.$db_prefix.'posts ADD INDEX '.$db_prefix.'posts_topic_id_idx(topic_id)';