Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions public_html/lists/admin/mergeduplicates.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,43 @@ function mergeUsers($original, $duplicate)

echo '<h2>Add HEX column</h2>';
//# add a hex column on email, for better indexing
Sql_Query('alter table phplist_user_user add column hexemail varchar(255) not null default ""');
Sql_Query('alter table phplist_user_user add index hexemailidx (hexemail)');
Sql_Query('update phplist_user_user set hexemail = hex(email)');
Sql_Query(sprintf('alter table %s add column hexemail varchar(255) not null default ""', $GLOBALS['tables']['user']));
Sql_Query(sprintf('alter table %s add index hexemailidx (hexemail)', $GLOBALS['tables']['user']));
Sql_Query(sprintf('update %s set hexemail = hex(email)', $GLOBALS['tables']['user']));

echo '<h2>Add HEX Test column</h2>';
//# add another column for the test value
Sql_Query('alter table phplist_user_user add column hexemailtest varchar(255) not null default ""');
Sql_Query('alter table phplist_user_user add index hexemailtestidx (hexemailtest)');
Sql_Query('update phplist_user_user set hexemailtest = concat(hexemail,"0D")');
Sql_Query(sprintf('alter table %s add column hexemailtest varchar(255) not null default ""', $GLOBALS['tables']['user']));
Sql_Query(sprintf('alter table %s add index hexemailtestidx (hexemailtest)', $GLOBALS['tables']['user']));
Sql_Query(sprintf('update %s set hexemailtest = concat(hexemail,"0D")', $GLOBALS['tables']['user']));

//# this should render no results
//select u1.id,u2.id,hex(u1.email),hex(u2.email) from phplist_user_user u1 left join phplist_user_user u2 on u1.hexemail = u2.hexemail where u1.id != u2.id;

// find the ones that match on email with 0D added (\r -> carriage return)
echo '<h2>Merge on CR</h2>';
$req = Sql_Verbose_Query('select u1.id,u2.id from phplist_user_user u1
left join phplist_user_user u2 on u1.hexemailtest = u2.hexemail where u1.id != u2.id');
$req = Sql_Verbose_Query(sprintf('select u1.id,u2.id from %s u1
left join %s u2 on u1.hexemailtest = u2.hexemail where u1.id != u2.id', $GLOBALS['tables']['user'], $GLOBALS['tables']['user']));
while ($row = Sql_Fetch_Row($req)) {
mergeUsers($row[0], $row[1]);
}

echo '<h2>Merge on NL</h2>';
// find the ones that match on email with 0A added (\n -> newline)
Sql_Query('update phplist_user_user set hexemailtest = concat(hexemail,"0A")');
$req = Sql_Verbose_Query('select u1.id,u2.id from phplist_user_user u1
left join phplist_user_user u2 on u1.hexemailtest = u2.hexemail where u1.id != u2.id');
Sql_Query(sprintf('update %s set hexemailtest = concat(hexemail,"0A")', $GLOBALS['tables']['user']));
$req = Sql_Verbose_Query(sprintf('select u1.id,u2.id from %s u1
left join %s u2 on u1.hexemailtest = u2.hexemail where u1.id != u2.id', $GLOBALS['tables']['user'], $GLOBALS['tables']['user']));
while ($row = Sql_Fetch_Row($req)) {
mergeUsers($row[0], $row[1]);
}

echo '<h2>Merge on TAB</h2>';
// find the ones that match on email with 09 added (\t -> tab)
Sql_Query('update phplist_user_user set hexemailtest = concat(hexemail,"09")');
$req = Sql_Verbose_Query('select u1.id,u2.id from phplist_user_user u1
left join phplist_user_user u2 on u1.hexemailtest = u2.hexemail where u1.id != u2.id');
Sql_Query(sprintf('update %s set hexemailtest = concat(hexemail,"09")', $GLOBALS['tables']['user']));
$req = Sql_Verbose_Query(sprintf('select u1.id,u2.id from %s u1
left join %s u2 on u1.hexemailtest = u2.hexemail where u1.id != u2.id', $GLOBALS['tables']['user'], $GLOBALS['tables']['user']));
while ($row = Sql_Fetch_Row($req)) {
mergeUsers($row[0], $row[1]);
}

Sql_Query('alter table phplist_user_user drop index hexemailidx, drop index hexemailtestidx, drop column hexemail, drop column hexemailtest');
Sql_Query(sprintf('alter table %s drop index hexemailidx, drop index hexemailtestidx, drop column hexemail, drop column hexemailtest', $GLOBALS['tables']['user']));
Loading