Ticket #113 (open enhancement)
Username not changed in quotes
- Created: 2010-08-31 13:36:56
- Reported by: adaur
- Milestone: 2.0-alpha3
- Priority: normal
- Assigned to: None
- Component: parser
Hello
When an username is changed in profile.php, it is updated everywhere, except on posts including quotes.
Example:
Text
OldUsername is not updated when replaced by NewUsername.
History
Franz 2010-08-31 14:04:03
Well, yes. But this is definitely not a bug - much rather by design. As quotes are constructed with the username of the user and not with their ID, there is no other choice.
And then, one could say this is a feature, because it allows me to do things like this:
When an username is changed in profile.php, it is updated everywhere, except on posts including quotes.
However, going through potentially thousands of posts just to fix the display of possibly very old topics when renaming users is far too much.
adaur 2010-08-31 14:38:33
In profile.php, after
$db->query('UPDATE '.$db->prefix.'online SET ident=\''.$db->escape($form['username']).'\' WHERE ident=\''.$db->escape($old_username).'\'') or error('Unable to update online list', __FILE__, __LINE__, $db->error());adding
$db->query('UPDATE '.$db->prefix.'posts SET message=REPLACE(message,\''.$db->escape($old_username).'\',\''.$db->escape($form['username']).'\') WHERE message LIKE \'%[quote='.$db->escape($old_username).']%\'') or error('Unable to update private messages', __FILE__, __LINE__, $db->error());solves the bug.
I don't think this query is very expensive, because it is limited to [ quote=Username].
Reines 2010-08-31 16:16:02
If someone has the name "the", that will match any message with quote=the in it, then replace all occurances of the word the, not just the quoted ones. That includes normal words, as well as stuff inside code tags etc.
Also, I'm not sure, but I imagine that REPLACE() is MySQL specific.
adaur 2010-08-31 19:11:47
@Reines:
If you replace the previous query by this one:
$db->query('UPDATE '.$db->prefix.'posts SET message=REPLACE(message,\'[quote='.$db->escape($old_username).']\',\'[quote='.$db->escape($form['username']).']\') WHERE message LIKE \'%[quote='.$db->escape($old_username).']%\'') or error('Unable to update quote informations', __FILE__, __LINE__, $db->error());I have tested it with success, with two users called Usertest & Usertestt, so the usernames are very similar. And it worked: Usertest has been replaced by Newusertest (or an other username), but the second username (Usertestt) didn't change.
I don't know what is the equivalent for Postegre or SQlite, but you can do:
switch ($db_type)
{
case 'mysql':
case 'mysqli':
case 'mysql_innodb':
case 'mysqli_innodb':
$db->query('UPDATE '.$db->prefix.'posts SET message=REPLACE(message,\'[quote='.$db->escape($old_username).']\',\'[quote='.$db->escape($form['username']).']\') WHERE message LIKE \'%[quote='.$db->escape($old_username).']%\'') or error('Unable to update quote informations', __FILE__, __LINE__, $db->error());
break;
}That way, you have an extra-feature if your database is MySQL, otherwise, there is no changes and no errors
.

