diff options
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Attachment.pm | 27 | ||||
-rwxr-xr-x | Bugzilla/Bug.pm | 11 | ||||
-rw-r--r-- | Bugzilla/DB/Schema.pm | 2 | ||||
-rw-r--r-- | Bugzilla/Install/DB.pm | 28 |
4 files changed, 61 insertions, 7 deletions
diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index cc3e16893..e3fe39f3a 100644 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -91,6 +91,7 @@ sub _retrieve { 'attachments.submitter_id AS _attacher_id', Bugzilla->dbh->sql_date_format('attachments.creation_ts', '%Y.%m.%d %H:%i') . " AS attached", + 'attachments.modification_time', 'attachments.filename AS filename', 'attachments.ispatch AS ispatch', 'attachments.isurl AS isurl', @@ -208,6 +209,21 @@ sub attached { =over +=item C<modification_time> + +the date and time on which the attachment was last modified. + +=back + +=cut + +sub modification_time { + my $self = shift; + return $self->{modification_time}; +} + +=over + =item C<filename> the name of the file the attacher attached @@ -826,10 +842,10 @@ sub insert_attachment_for_bug { # Insert the attachment into the database. my $sth = $dbh->do( "INSERT INTO attachments - (bug_id, creation_ts, filename, description, + (bug_id, creation_ts, modification_time, filename, description, mimetype, ispatch, isurl, isprivate, submitter_id) - VALUES (?,?,?,?,?,?,?,?,?)", undef, ($bug->bug_id, $timestamp, $filename, - $description, $contenttype, $cgi->param('ispatch'), + VALUES (?,?,?,?,?,?,?,?,?,?)", undef, ($bug->bug_id, $timestamp, $timestamp, + $filename, $description, $contenttype, $cgi->param('ispatch'), $isurl, $isprivate, $user->id)); # Retrieve the ID of the newly created attachment record. my $attachid = $dbh->bz_last_key('attachments', 'attach_id'); @@ -877,8 +893,9 @@ sub insert_attachment_for_bug { # This call must be done before updating the 'attachments' table. Bugzilla::Flag::CancelRequests($bug, $obsolete_attachment, $timestamp); - $dbh->do('UPDATE attachments SET isobsolete = 1 WHERE attach_id = ?', - undef, $obsolete_attachment->id); + $dbh->do('UPDATE attachments SET isobsolete = 1, modification_time = ? + WHERE attach_id = ?', + undef, ($timestamp, $obsolete_attachment->id)); $dbh->do('INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index a8f1ede5d..0a45daf14 100755 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -2573,11 +2573,11 @@ sub format_comment { # Get the activity of a bug, starting from $starttime (if given). # This routine assumes ValidateBugID has been previously called. sub GetBugActivity { - my ($id, $starttime) = @_; + my ($bug_id, $attach_id, $starttime) = @_; my $dbh = Bugzilla->dbh; # Arguments passed to the SQL query. - my @args = ($id); + my @args = ($bug_id); # Only consider changes since $starttime, if given. my $datepart = ""; @@ -2587,6 +2587,12 @@ sub GetBugActivity { $datepart = "AND bugs_activity.bug_when > ?"; } + my $attachpart = ""; + if ($attach_id) { + push(@args, $attach_id); + $attachpart = "AND bugs_activity.attach_id = ?"; + } + # Only includes attachments the user is allowed to see. my $suppjoins = ""; my $suppwhere = ""; @@ -2616,6 +2622,7 @@ sub GetBugActivity { ON profiles.userid = bugs_activity.who WHERE bugs_activity.bug_id = ? $datepart + $attachpart $suppwhere ORDER BY bugs_activity.bug_when"; diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index 1c6ee352e..61f894f83 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -372,6 +372,7 @@ use constant ABSTRACT_SCHEMA => { PRIMARYKEY => 1}, bug_id => {TYPE => 'INT3', NOTNULL => 1}, creation_ts => {TYPE => 'DATETIME', NOTNULL => 1}, + modification_time => {TYPE => 'DATETIME', NOTNULL => 1}, description => {TYPE => 'MEDIUMTEXT', NOTNULL => 1}, mimetype => {TYPE => 'MEDIUMTEXT', NOTNULL => 1}, ispatch => {TYPE => 'BOOLEAN'}, @@ -389,6 +390,7 @@ use constant ABSTRACT_SCHEMA => { INDEXES => [ attachments_bug_id_idx => ['bug_id'], attachments_creation_ts_idx => ['creation_ts'], + attachments_modification_time_idx => ['modification_time'], attachments_submitter_id_idx => ['submitter_id', 'bug_id'], ], }, diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index 9934e058f..485c771b1 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -515,6 +515,9 @@ sub update_table_definitions { # 2007-08-21 wurblzap@gmail.com - Bug 365378 _make_lang_setting_dynamic(); + # 2007-09-09 LpSolit@gmail.com - Bug 99215 + _fix_attachment_modification_date(); + ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ @@ -2898,6 +2901,31 @@ sub _make_lang_setting_dynamic { } } +sub _fix_attachment_modification_date { + my $dbh = Bugzilla->dbh; + if (!$dbh->bz_column_info('attachments', 'modification_time')) { + # Allow NULL values till the modification time has been set. + $dbh->bz_add_column('attachments', 'modification_time', {TYPE => 'DATETIME'}); + + print "Setting the modification time for attachments...\n"; + $dbh->do('UPDATE attachments SET modification_time = creation_ts'); + + # Now force values to be always defined. + $dbh->bz_alter_column('attachments', 'modification_time', + {TYPE => 'DATETIME', NOTNULL => 1}); + + # Update the modification time for attachments which have been modified. + my $attachments = + $dbh->selectall_arrayref('SELECT attach_id, MAX(bug_when) FROM bugs_activity + WHERE attach_id IS NOT NULL ' . + $dbh->sql_group_by('attach_id')); + + my $sth = $dbh->prepare('UPDATE attachments SET modification_time = ? + WHERE attach_id = ?'); + $sth->execute($_->[1], $_->[0]) foreach (@$attachments); + } +} + 1; __END__ |