From f394b2ed4f175bf6076747ba7792e182841091ab Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 30 Nov 2007 01:49:12 +0000 Subject: Bug 99215: Attachments have no midair collision protection - Patch by Frédéric Buclin r=mkanat r=justdave a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bugzilla/Install/DB.pm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'Bugzilla/Install') 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__ -- cgit v1.2.3-24-g4f1b