Changeset 663

Show
Ignore:
Timestamp:
12/01/06 23:11:32 (2 years ago)
Author:
Neal
Message:

Ticket #1: Users can no longer appear twice in the online table

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/punbb-1.3-dev/extras/db_update.php

    r659 r663  
    322322        } 
    323323 
     324        // We need to add a unique index to avoid users having multiple rows in the online table 
     325        if ($db_type == 'mysql' || $db_type == 'mysqli') 
     326        { 
     327                $result = $db->query('SHOW INDEX FROM '.$db->prefix.'online WHERE Key_name = "'.$db->prefix.'online_user_id_ident_idx"') or error('Unable to check DB structure.', __FILE__, __LINE__, $db->error()); 
     328                 
     329                if ($db->num_rows($result) == 0) 
     330                        $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()); 
     331        } 
     332         
    324333        // Finally, we update the version number 
    325334        $db->query('UPDATE '.$db->prefix.'config SET conf_value=\''.$update_to.'\' WHERE conf_name=\'o_cur_version\'') or error('Unable to update version.', __FILE__, __LINE__, $db->error()); 
  • branches/punbb-1.3-dev/upload/include/functions.php

    r662 r663  
    102102                        { 
    103103                                $pun_user['logged'] = $now; 
    104                                 $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()); 
    105  
     104                                 
     105                                // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table 
     106                                switch ($db_type) 
     107                                { 
     108                                        case 'mysql': 
     109                                        case 'mysqli': 
     110                                                $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()); 
     111                                                break; 
     112 
     113                                        default: 
     114                                                $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()); 
     115                                                break; 
     116                                } 
     117                                 
    106118                                // Reset tracked topics 
    107119                                set_tracked_topics(null); 
     
    146158        // Update online list 
    147159        if (!$pun_user['logged']) 
    148                 $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()); 
     160        { 
     161                // With MySQL/MySQLi, REPLACE INTO avoids a user having two rows in the online table 
     162                switch ($db_type) 
     163                { 
     164                        case 'mysql': 
     165                        case 'mysqli': 
     166                                $db->query('REPLACE 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()); 
     167                                break; 
     168 
     169                        default: 
     170                                $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()); 
     171                                break; 
     172                } 
     173        } 
    149174        else 
    150175                $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()); 
  • branches/punbb-1.3-dev/upload/install.php

    r652 r663  
    13071307                case 'mysqli': 
    13081308                        // We use MySQL's ALTER TABLE ... ADD INDEX syntax instead of CREATE INDEX to avoid problems with users lacking the INDEX privilege 
     1309                        $queries[] = 'ALTER TABLE '.$db_prefix.'online ADD UNIQUE INDEX '.$db_prefix.'online_user_id_ident_idx(user_id,ident)'; 
    13091310                        $queries[] = 'ALTER TABLE '.$db_prefix.'online ADD INDEX '.$db_prefix.'online_user_id_idx(user_id)'; 
    13101311                        $queries[] = 'ALTER TABLE '.$db_prefix.'posts ADD INDEX '.$db_prefix.'posts_topic_id_idx(topic_id)';