Skip to content

Commit

Permalink
rename the column user to userid on user-message-bounce to avoid rese…
Browse files Browse the repository at this point in the history
…rved word clashes
  • Loading branch information
michield committed Dec 25, 2023
1 parent aaf6f21 commit 7ea7958
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion public_html/lists/admin/actions/bounces.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from
%s as message_bounce
where
user = %d', $GLOBALS['tables']['user_message_bounce'], $user['id']));
userid = %d', $GLOBALS['tables']['user_message_bounce'], $user['id']));

if (Sql_Affected_Rows()) {
while ($row = Sql_Fetch_Array($req)) {
Expand Down
6 changes: 3 additions & 3 deletions public_html/lists/admin/actions/campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
abs(unix_timestamp(entered) - unix_timestamp(viewed)) as responsetime,
(select max(time)
from %s umb
where umb.message = messageid and umb.user = userid
where umb.message = messageid and umb.userid = um.userid
) as bouncetime
from %s
where userid = %d and status = "sent"
from %s um
where um.userid = %d and status = "sent"
order by entered desc',
$GLOBALS['tables']['user_message_bounce'],
$GLOBALS['tables']['usermessage'],
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/actions/domainstats.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
SELECT COUNT(lcase(substring_index(u.email, "@", -1))) num,
lcase(substring_index(u.email, "@", -1)) domain
FROM %s AS u
RIGHT JOIN %s AS b ON u.id = b.user
RIGHT JOIN %s AS umb ON u.id = umb.userid
GROUP BY domain
ORDER BY num DESC
LIMIT 25;
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/actions/listbounces.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
sleep($_SESSION['LoadDelay']);
}
$req = Sql_Query(sprintf('select listuser.listid,count(distinct userid) as numusers from %s list, %s listuser,
%s umb, %s lm where %s list.id = listuser.listid and listuser.listid = lm.listid and listuser.userid = umb.user group by listuser.listid
%s umb, %s lm where %s list.id = listuser.listid and listuser.listid = lm.listid and listuser.userid = umb.userid group by listuser.listid
order by listuser.listid limit 250', $GLOBALS['tables']['list'], $GLOBALS['tables']['listuser'],
$GLOBALS['tables']['user_message_bounce'], $GLOBALS['tables']['listmessage'], $isowner_and));
$ls = new WebblerListing(s('Choose a list'));
Expand Down
4 changes: 2 additions & 2 deletions public_html/lists/admin/actions/reconcileusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
++$cnt;
set_time_limit(60);
if (preg_match('/([\d]+) marked unconfirmed/',$row['comment'],$regs)) {
$exists = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where user = %d and message = -1 and bounce = %d',$tables['user_message_bounce'],$regs[1],$row['id']));
$exists = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where userid = %d and message = -1 and bounce = %d',$tables['user_message_bounce'],$regs[1],$row['id']));
if (empty($exists[0])) {
Sql_Query(sprintf('insert into %s (user,message,bounce,time) values(%d,-1,%d,"%s")',$tables['user_message_bounce'],$regs[1],$row['id'],$row['date']));
Sql_Query(sprintf('insert into %s (userid,message,bounce,time) values(%d,-1,%d,"%s")',$tables['user_message_bounce'],$regs[1],$row['id'],$row['date']));
++$done;
}
}
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/exportuserdata.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
from
%s as message_bounce
where
user = %d', $GLOBALS['tables']['user_message_bounce'], $user['id']));
userid = %d', $GLOBALS['tables']['user_message_bounce'], $user['id']));

while ($row = Sql_Fetch_Assoc($bouncesrows))
fputcsv($output, $row, $csvColumnDelimiter);
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/inc/userlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function deleteUserRecordsLeaveBlacklistRecords($id)
Sql_Query('delete from '.$tables['usermessage'].' where userid = '.$id);
Sql_Query('delete from '.$tables['user_attribute'].' where userid = '.$id);
Sql_Query('delete from '.$tables['user_history'].' where userid = '.$id);
Sql_Query('delete from '.$tables['user_message_bounce'].' where user = '.$id);
Sql_Query('delete from '.$tables['user_message_bounce'].' where userid = '.$id);
Sql_Query('delete from '.$tables['user_message_forward'].' where user = '.$id);
Sql_Query('delete from '.$tables['user'].' where id = '.$id);
Sql_Query('delete from '.$tables['user_message_view'].' where userid = '.$id);
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/listbounces.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

return;
}
$query = sprintf('select lu.userid, count(umb.bounce) as numbounces from %s lu join %s umb on lu.userid = umb.user
$query = sprintf('select lu.userid, count(umb.bounce) as numbounces from %s lu join %s umb on lu.userid = umb.userid
where ' .
// now() < date_add(umb.time,interval 6 month) and
' lu.listid = %d
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/mclicks.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
$messagedata = Sql_Fetch_Array_query("SELECT * FROM {$tables['message']} where id = $id $subselect");
$totalusers = Sql_Fetch_Row_Query(sprintf('select count(userid) from %s where messageid = %d and status = "sent"',
$GLOBALS['tables']['usermessage'], $id));
$totalbounced = Sql_Fetch_Row_Query(sprintf('select count(user) from %s where message = %d',
$totalbounced = Sql_Fetch_Row_Query(sprintf('select count(userid) from %s where message = %d',
$GLOBALS['tables']['user_message_bounce'], $id));
//unique clicks
$totalclicked = Sql_Fetch_Row_Query(sprintf('select count(distinct userid) from %s where messageid = %d',
Expand Down
6 changes: 3 additions & 3 deletions public_html/lists/admin/mergeduplicates.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ function mergeUsers($original, $duplicate)
Sql_Query(sprintf('update %s set userid = %d, entered = "%s" where userid = %d and entered = "%s"',
$GLOBALS['tables']['usermessage'], $original, $um['entered'], $duplicate, $um['entered']), 1);
}
$bncreq = Sql_Query(sprintf('select * from %s where user = %d', $GLOBALS['tables']['user_message_bounce'],
$bncreq = Sql_Query(sprintf('select * from %s where userid = %d', $GLOBALS['tables']['user_message_bounce'],
$duplicate));
while ($bnc = Sql_Fetch_Array($bncreq)) {
Sql_Query(sprintf('update %s set user = %d, time = "%s" where user = %d and time = "%s"',
Sql_Query(sprintf('update %s set userid = %d, time = "%s" where userid = %d and time = "%s"',
$GLOBALS['tables']['user_message_bounce'], $original, $bnc['time'], $duplicate, $bnc['time']), 1);
}
$listreq = Sql_Query(sprintf('select * from %s where userid = %d', $GLOBALS['tables']['listuser'], $duplicate));
Expand All @@ -30,7 +30,7 @@ function mergeUsers($original, $duplicate)
1);
}
Sql_Query(sprintf('delete from %s where userid = %d', $GLOBALS['tables']['listuser'], $duplicate));
Sql_Query(sprintf('delete from %s where user = %d', $GLOBALS['tables']['user_message_bounce'], $duplicate));
Sql_Query(sprintf('delete from %s where userid = %d', $GLOBALS['tables']['user_message_bounce'], $duplicate));
Sql_Query(sprintf('delete from %s where userid = %d', $GLOBALS['tables']['usermessage'], $duplicate));
// if (MERGE_DUPLICATES_DELETE_DUPLICATE) {
deleteUser($duplicate);
Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/msgbounces.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
mb.bounce,
mb.time
from {$tables['user_message_bounce']} mb
join {$tables['user']} u on u.id = mb.user
join {$tables['user']} u on u.id = mb.userid
where mb.message = $messageid
END;
$req = Sql_Query($query);
Expand Down
40 changes: 16 additions & 24 deletions public_html/lists/admin/processbounces.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ function processBounceData($bounceid, $msgid, $userid, $bounceDate = null)
#Use the date of the bounce, instead of "now" as processing may be different
Sql_Query(sprintf('INSERT INTO %s
(
user,
userid,
message,
bounce,
time
Expand Down Expand Up @@ -271,11 +271,11 @@ function processBounceData($bounceid, $msgid, $userid, $bounceDate = null)
} elseif (!empty($msgid) && !empty($userid)) {
//# check if we already have this um as a bounce
//# so that we don't double count "delayed" like bounces
$exists = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where user = %d and message = %d',
$exists = Sql_Fetch_Row_Query(sprintf('select count(*) from %s where userid = %d and message = %d',
$tables['user_message_bounce'], $userid, $msgid));
if (empty($exists[0])) {
Sql_Query(sprintf('insert into %s
set user = %d, message = %d, bounce = %d',
set userid = %d, message = %d, bounce = %d',
$tables['user_message_bounce'],
$userid, $msgid, $bounceid));
Sql_Query(sprintf('update %s
Expand All @@ -298,7 +298,7 @@ function processBounceData($bounceid, $msgid, $userid, $bounceDate = null)
} else {
//# we create the relationship, but don't increase counters
Sql_Query(sprintf('insert into %s
set user = %d, message = %d, bounce = %d',
set userid = %d, message = %d, bounce = %d',
$tables['user_message_bounce'],
$userid, $msgid, $bounceid));

Expand Down Expand Up @@ -582,14 +582,14 @@ function processMessages($link, $max)
}
// cl_output(memory_get_usage());

// outputProcessBounce('User '.$row['user']);
// outputProcessBounce('User '.$row['userid']);
$rule = matchBounceRules($row['header']."\n\n".$row['data'], $bouncerules);
// outputProcessBounce('Action '.$rule['action']);
// outputProcessBounce('Rule'.$rule['id']);
$userdata = array();
if ($rule && is_array($rule)) {
if ($row['user']) {
$userdata = Sql_Fetch_Array_Query("select * from {$tables['user']} where id = ".$row['user']);
if ($row['userid']) {
$userdata = Sql_Fetch_Array_Query("select * from {$tables['user']} where id = ".$row['userid']);
}
$report_linkroot = $GLOBALS['admin_scheme'].'://'.$GLOBALS['website'].$GLOBALS['adminpages'];

Expand All @@ -599,7 +599,7 @@ function processMessages($link, $max)
$GLOBALS['tables']['bounceregex_bounce'], $rule['id'], $row['bounce']));

//17860 - check the current status to avoid doing it over and over
$currentStatus = Sql_Fetch_Assoc_Query(sprintf('select confirmed,blacklisted from %s where id = %d', $GLOBALS['tables']['user'],$row['user']));
$currentStatus = Sql_Fetch_Assoc_Query(sprintf('select confirmed,blacklisted from %s where id = %d', $GLOBALS['tables']['user'],$row['userid']));
$confirmed = !empty($currentStatus['confirmed']);
$blacklisted = !empty($currentStatus['blacklisted']);

Expand All @@ -609,14 +609,14 @@ function processMessages($link, $max)
$rule['id']));
$advanced_report .= 'User '.$userdata['email'].' Id '.$userdata['id'].' deleted by bounce rule '.$rule['id'].PHP_EOL;
$advanced_report .= 'Rule: '.$report_linkroot.'/?page=bouncerule&amp;id='.$rule['id'].PHP_EOL;
deleteUser($row['user']);
deleteUser($row['userid']);
break;
case 'unconfirmuser':
if ($confirmed) {
logEvent('User ' . $userdata['email'] . ' unconfirmed by bounce rule ' . PageLink2('bouncerule&amp;id=' . $rule['id'],
$rule['id']));
Sql_Query(sprintf('update %s set confirmed = 0 where id = %d', $GLOBALS['tables']['user'],
$row['user']));
$row['userid']));
$advanced_report .= 'User ' . $userdata['email'] . ' made unconfirmed by bounce rule ' . $rule['id'] . PHP_EOL;
$advanced_report .= 'User: ' . $report_linkroot . '/?page=user&amp;id=' . $userdata['id'] . PHP_EOL;
$advanced_report .= 'Rule: ' . $report_linkroot . '/?page=bouncerule&amp;id=' . $rule['id'] . PHP_EOL;
Expand All @@ -630,15 +630,15 @@ function processMessages($link, $max)
$rule['id']));
$advanced_report .= 'User '.$userdata['email'].' Id '.$userdata['id'].' deleted by bounce rule '.$rule['id'].PHP_EOL;
$advanced_report .= 'Rule: '.$report_linkroot.'/?page=bouncerule&amp;id='.$rule['id'].PHP_EOL;
deleteUser($row['user']);
deleteUser($row['userid']);
deleteBounce($row['bounce']);
break;
case 'unconfirmuseranddeletebounce':
if ($confirmed) {
logEvent('User ' . $userdata['email'] . ' unconfirmed by bounce rule ' . PageLink2('bouncerule&amp;id=' . $rule['id'],
$rule['id']));
Sql_Query(sprintf('update %s set confirmed = 0 where id = %d', $GLOBALS['tables']['user'],
$row['user']));
$row['userid']));
$advanced_report .= 'User ' . $userdata['email'] . ' made unconfirmed by bounce rule ' . $rule['id'] . PHP_EOL;
$advanced_report .= 'User: ' . $report_linkroot . '/?page=user&amp;id=' . $userdata['id'] . PHP_EOL;
$advanced_report .= 'Rule: ' . $report_linkroot . '/?page=bouncerule&amp;id=' . $rule['id'] . PHP_EOL;
Expand Down Expand Up @@ -724,8 +724,8 @@ function processMessages($link, $max)
outputProcessBounce($GLOBALS['I18N']->get('Identifying consecutive bounces'));

// we only need users who are confirmed at the moment
$userid_req = Sql_query(sprintf('select distinct umb.user from %s umb, %s u
where u.id = umb.user and u.confirmed and !u.blacklisted',
$userid_req = Sql_query(sprintf('select distinct umb.userid from %s umb, %s u
where u.id = umb.userid and u.confirmed and !u.blacklisted',
$tables['user_message_bounce'],
$tables['user']
));
Expand All @@ -739,17 +739,9 @@ function processMessages($link, $max)
while ($user = Sql_Fetch_Row($userid_req)) {
keepLock($process_id);
set_time_limit(600);
//$msg_req = Sql_Query(sprintf('select * from
//%s um left join %s umb on (um.messageid = umb.message and userid = user)
//where userid = %d and um.status = "sent"
//order by entered desc',
//$tables["usermessage"],$tables["user_message_bounce"],
//$user[0]));

//# 17361 - update of the above query, to include the bounce table and to exclude duplicate bounces
$msg_req = Sql_Query(sprintf('select umb.*,um.*,b.status,b.comment from %s um left join %s umb on (um.messageid = umb.message and userid = user)
$msg_req = Sql_Query(sprintf('select umb.*,um.*,b.status,b.comment from %s um left join %s umb on (um.messageid = umb.message and um.userid = umb.userid)
left join %s b on umb.bounce = b.id
where userid = %d and um.status = "sent"
where um.userid = %d and um.status = "sent"
order by entered desc',
$tables['usermessage'], $tables['user_message_bounce'], $tables['bounce'],
$user[0]));
Expand Down
14 changes: 7 additions & 7 deletions public_html/lists/admin/reconcileusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ function mergeUser($userid)
Sql_Query(sprintf('update %s set userid = %d, entered = "%s" where userid = %d and entered = "%s"',
$GLOBALS['tables']['usermessage'], $orig[0], $um['entered'], $duplicate['id'], $um['entered']), 1);
}
$bncreq = Sql_Query("select * from {$GLOBALS['tables']['user_message_bounce']} where user = ".$duplicate['id']);
$bncreq = Sql_Query("select * from {$GLOBALS['tables']['user_message_bounce']} where userid = ".$duplicate['id']);
while ($bnc = Sql_Fetch_Array($bncreq)) {
Sql_Query(sprintf('update %s set user = %d, time = "%s" where user = %d and time = "%s"',
Sql_Query(sprintf('update %s set userid = %d, time = "%s" where userid = %d and time = "%s"',
$GLOBALS['tables']['user_message_bounce'], $orig[0], $bnc['time'], $duplicate['id'], $bnc['time']),
1);
}
Sql_Query("delete from {$GLOBALS['tables']['listuser']} where userid = ".$duplicate['id']);
Sql_Query("delete from {$GLOBALS['tables']['user_message_bounce']} where user = ".$duplicate['id']);
Sql_Query("delete from {$GLOBALS['tables']['user_message_bounce']} where userid = ".$duplicate['id']);
Sql_Query("delete from {$GLOBALS['tables']['usermessage']} where userid = ".$duplicate['id']);
if (MERGE_DUPLICATES_DELETE_DUPLICATE) {
deleteUser($duplicate['id']);
Expand Down Expand Up @@ -370,12 +370,12 @@ function addUniqID($userid)
while ($row = Sql_Fetch_Row($req)) {
Sql_Query("delete from {$tables['usermessage']} where userid = $row[0]");
}
$req = Sql_Verbose_Query("select {$tables['user_message_bounce']}.user
from {$tables['user_message_bounce']} left join {$tables['user']} on {$tables['user_message_bounce']}.user = {$tables['user']}.id
where {$tables['user']}.id IS NULL group by {$tables['user_message_bounce']}.user");
$req = Sql_Verbose_Query("select {$tables['user_message_bounce']}.userid
from {$tables['user_message_bounce']} left join {$tables['user']} on {$tables['user_message_bounce']}.userid = {$tables['user']}.id
where {$tables['user']}.id IS NULL group by {$tables['user_message_bounce']}.userid");
echo Sql_Affected_Rows().' '.s('entries apply').'<br/>';
while ($row = Sql_Fetch_Row($req)) {
Sql_Query("delete from {$tables['user_message_bounce']} where user = $row[0]");
Sql_Query("delete from {$tables['user_message_bounce']} where userid = $row[0]");
}
}

Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/statsoverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
$ls->addColumn($element,'&nbsp;',$messagedata['bouncecount']);
*/
//Bounced
$bounced = Sql_Fetch_Row_Query(sprintf('select count(distinct user) from %s where message = %d',
$bounced = Sql_Fetch_Row_Query(sprintf('select count(distinct userid) from %s where message = %d',
$tables['user_message_bounce'], $id));
$element = ucfirst(s('Bounced'));
$ls->addElement($element);
Expand Down
8 changes: 4 additions & 4 deletions public_html/lists/admin/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,18 @@
),
'user_message_bounce' => array( // bounce. We can have one usermessage bounce multiple times
'id' => array('integer not null primary key auto_increment', 'ID'),
'user' => array('integer not null', 'subscriber ID'),
'userid' => array('integer not null', 'subscriber ID'),
'message' => array('integer not null', 'Message ID'),
'bounce' => array('integer not null', 'Bounce ID'),
'time' => array('timestamp', 'When did it bounce'),
'index_1' => array('umbindex (user,message,bounce)', 'index'),
'index_2' => array('useridx (user)', 'index'),
'index_1' => array('umbindex (userid,message,bounce)', 'index'),
'index_2' => array('useridx (userid)', 'index'),
'index_3' => array('msgidx (message)', 'index'),
'index_4' => array('bounceidx (bounce)', 'index'),
),
'user_message_forward' => array(
'id' => array('integer not null primary key auto_increment', 'ID'),
'user' => array('integer not null', 'subscriber ID'),
'userid' => array('integer not null', 'subscriber ID'),
'message' => array('integer not null', 'Message ID'),
'forward' => array('varchar(255)', 'Forward email'),
'status' => array('varchar(255)', 'Status of forward'),
Expand Down
8 changes: 8 additions & 0 deletions public_html/lists/admin/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ function output($message)
Sql_Query("alter table {$GLOBALS['tables']['admin']} modify modifiedby varchar(66) default ''");
}

if (Sql_Table_column_exists($GLOBALS['tables']['user_message_bounce'],'user')) {
Sql_Query('drop index umbindex on '.$GLOBALS['tables']['user_message_bounce']);
Sql_Query('drop index useridx on '.$GLOBALS['tables']['user_message_bounce']);
Sql_Query('alter table '.$GLOBALS['tables']['user_message_bounce'].' change column user userid integer not null');
Sql_Query('alter table '.$GLOBALS['tables']['user_message_bounce'].' add index umbindex (userid,message,bounce)' );
Sql_Query('alter table '.$GLOBALS['tables']['user_message_bounce'].' add index useridx (userid)' );
}

//# longblobs are better at mixing character encoding. We don't know the encoding of anything we may want to store in cache
//# before converting, it's quickest to clear the cache
clearPageCache();
Expand Down

0 comments on commit 7ea7958

Please sign in to comment.