Committer: ailyin
do not allow this SQL query to crashU trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm =================================================================== --- trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm 2010-11-30 12:31:15 UTC (rev 9773) +++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm 2010-12-01 05:01:48 UTC (rev 9774) @@ -378,10 +378,16 @@ $add_sql = "DATE_ADD(NOW(), INTERVAL $qtv $units)"; } - $dbh->do("INSERT INTO paiduser (userid, paiduntil) VALUES (?, $add_sql)", - undef, $userid); - if ($dbh->err) { + my $affected_rows = int $dbh->do(qq{ + INSERT IGNORE + INTO paiduser + (userid, paiduntil) + VALUES + (?, $add_sql) + }, undef, $userid); + unless ($affected_rows) { + $add_sql = "DATE_ADD(GREATEST(IFNULL(paiduntil, NOW()), NOW()), INTERVAL $qtv $units)" unless $units eq 'epoch';