Fix for bug 92266: Prevent dataloss in the bugs_activity table by wrapping

entries into additional entries if they're too long to fit. Patch by Dave Miller <justdave@syndicomm.com> r= jake@acutex.net
parent c05c60cf
...@@ -895,18 +895,65 @@ sub SnapShotDeps { ...@@ -895,18 +895,65 @@ sub SnapShotDeps {
my $timestamp; my $timestamp;
sub FindWrapPoint {
my ($string, $startpos) = @_;
if (!$string) { return 0 }
if (length($string) < $startpos) { return length($string) }
my $wrappoint = rindex($string, ",", $startpos); # look for comma
if ($wrappoint < 0) { # can't find comma
$wrappoint = rindex($string, " ", $startpos); # look for space
if ($wrappoint < 0) { # can't find space
$wrappoint = rindex($string, "-", $startpos); # look for hyphen
if ($wrappoint < 0) { # can't find hyphen
$wrappoint = $startpos; # just truncate it
} else {
$wrappoint++; # leave hyphen on the left side
}
}
}
return $wrappoint;
}
sub LogActivityEntry {
my ($i,$col,$removed,$added) = @_;
# in the case of CCs, deps, and keywords, there's a possibility that someone
# might try to add or remove a lot of them at once, which might take more
# space than the activity table allows. We'll solve this by splitting it
# into multiple entries if it's too long.
while ($removed || $added) {
my ($removestr, $addstr) = ($removed, $added);
if (length($removestr) > 254) {
my $commaposition = FindWrapPoint($removed, 254);
$removestr = substr($removed,0,$commaposition);
$removed = substr($removed,$commaposition);
$removed =~ s/^[,\s]+//; # remove any comma or space
} else {
$removed = ""; # no more entries
}
if (length($addstr) > 254) {
my $commaposition = FindWrapPoint($added, 254);
$addstr = substr($added,0,$commaposition);
$added = substr($added,$commaposition);
$added =~ s/^[,\s]+//; # remove any comma or space
} else {
$added = ""; # no more entries
}
$addstr = SqlQuote($addstr);
$removestr = SqlQuote($removestr);
my $fieldid = GetFieldID($col);
SendSQL("INSERT INTO bugs_activity " .
"(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
"($i,$whoid,$timestamp,$fieldid,$removestr,$addstr)");
}
}
sub LogDependencyActivity { sub LogDependencyActivity {
my ($i, $oldstr, $target, $me) = (@_); my ($i, $oldstr, $target, $me) = (@_);
my $newstr = SnapShotDeps($i, $target, $me); my $newstr = SnapShotDeps($i, $target, $me);
if ($oldstr ne $newstr) { if ($oldstr ne $newstr) {
# Figure out what's really different... # Figure out what's really different...
my ($removed, $added) = DiffStrings($oldstr, $newstr); my ($removed, $added) = DiffStrings($oldstr, $newstr);
$added = SqlQuote($added); LogActivityEntry($i,$target,$removed,$added);
$removed = SqlQuote($removed);
my $fieldid = GetFieldID($target);
SendSQL("INSERT INTO bugs_activity " .
"(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
"($i,$whoid,$timestamp,$fieldid,$removed,$added)");
return 1; return 1;
} }
return 0; return 0;
...@@ -1147,12 +1194,9 @@ The changes made were: ...@@ -1147,12 +1194,9 @@ The changes made were:
# If any changes were found, record it in the activity log # If any changes were found, record it in the activity log
if (scalar(@removed) || scalar(@added)) { if (scalar(@removed) || scalar(@added)) {
my $col = GetFieldID('cc'); my $removed = join(", ", @removed);
my $removed = SqlQuote(join(", ", @removed)); my $added = join(", ", @added);
my $added = SqlQuote(join(", ", @added)); LogActivityEntry($id,"cc",$removed,$added);
SendSQL("INSERT INTO bugs_activity " .
"(bug_id,who,bug_when,fieldid,removed,added) VALUES " .
"($id,$whoid,'$timestamp',$col,$removed,$added)");
} }
} }
...@@ -1322,12 +1366,7 @@ The changes made were: ...@@ -1322,12 +1366,7 @@ The changes made were:
RemoveVotes($id, 0, RemoveVotes($id, 0,
"This bug has been moved to a different product"); "This bug has been moved to a different product");
} }
$col = GetFieldID($col); LogActivityEntry($id,$col,$old,$new);
$old = SqlQuote($old);
$new = SqlQuote($new);
my $q = "insert into bugs_activity (bug_id,who,bug_when,fieldid,removed,added) values ($id,$whoid,'$timestamp',$col,$old,$new)";
# puts "<pre>$q</pre>"
SendSQL($q);
} }
} }
...@@ -1360,10 +1399,7 @@ The changes made were: ...@@ -1360,10 +1399,7 @@ The changes made were:
unless ($isreporter || $isoncc || ! $::FORM{'confirm_add_duplicate'}) { unless ($isreporter || $isoncc || ! $::FORM{'confirm_add_duplicate'}) {
# The reporter is oblivious to the existance of the new bug and is permitted access # The reporter is oblivious to the existance of the new bug and is permitted access
# ... add 'em to the cc (and record activity) # ... add 'em to the cc (and record activity)
my $ccid = GetFieldID("cc"); LogActivityEntry($duplicate,"cc","",DBID_to_name($reporter));
my $whochange = DBNameToIdAndCheck($::FORM{'who'});
SendSQL("INSERT INTO bugs_activity (bug_id,who,bug_when,fieldid,removed,added) VALUES " .
"('$duplicate','$whochange',now(),$ccid,'','" . DBID_to_name($reporter) . "')");
SendSQL("INSERT INTO cc (who, bug_id) VALUES ($reporter, " . SqlQuote($duplicate) . ")"); SendSQL("INSERT INTO cc (who, bug_id) VALUES ($reporter, " . SqlQuote($duplicate) . ")");
} }
AppendComment($duplicate, $::FORM{'who'}, "*** Bug $::FORM{'id'} has been marked as a duplicate of this bug. ***"); AppendComment($duplicate, $::FORM{'who'}, "*** Bug $::FORM{'id'} has been marked as a duplicate of this bug. ***");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment