]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Patch for bug 273339: Make attachment.cgi consistent with its activity log timestamps...
authorjocuri%softhome.net <>
Wed, 29 Dec 2004 07:39:05 +0000 (07:39 +0000)
committerjocuri%softhome.net <>
Wed, 29 Dec 2004 07:39:05 +0000 (07:39 +0000)
Bugzilla/Flag.pm
attachment.cgi

index a246394ba5c1a94964c9ad7c2bb621a5bf0c08b7..666513aaf98e46c0200604cef530c46d4564687c 100644 (file)
@@ -341,12 +341,16 @@ sub migrate {
     # Moves a flag from one attachment to another.  Useful for migrating
     # a flag from an obsolete attachment to the attachment that obsoleted it.
 
-    my ($old_attach_id, $new_attach_id) = @_;
+    my ($old_attach_id, $new_attach_id, $timestamp) = @_;
+
+    # Use the date/time we were given if possible (allowing calling code
+    # to synchronize the comment's timestamp with those of other records).
+    $timestamp = ($timestamp ? &::SqlQuote($timestamp) : "NOW()");
 
     # Update the record in the flags table to point to the new attachment.
     &::SendSQL("UPDATE flags " . 
                "SET    attach_id = $new_attach_id , " . 
-               "       modification_date = NOW() " . 
+               "       modification_date = $timestamp " . 
                "WHERE  attach_id = $old_attach_id");
 }
 
index 127d820c7c1e3d37c7761ac21f53445db06e4dd9..9847dc2898d04edff1a99754bb6ff01f8899a53e 100755 (executable)
@@ -858,9 +858,13 @@ sub insert
   my $thedata = SqlQuote($data);
   my $isprivate = $::FORM{'isprivate'} ? 1 : 0;
 
+  # Figure out when the changes were made.
+  my ($timestamp) = Bugzilla->dbh->selectrow_array("SELECT NOW()"); 
+  my $sql_timestamp = SqlQuote($timestamp); 
+
   # Insert the attachment into the database.
   SendSQL("INSERT INTO attachments (bug_id, creation_ts, filename, description, mimetype, ispatch, isprivate, submitter_id, thedata) 
-           VALUES ($::FORM{'bugid'}, now(), $filename, $description, $contenttype, $::FORM{'ispatch'}, $isprivate, $::userid, $thedata)");
+           VALUES ($::FORM{'bugid'}, $sql_timestamp, $filename, $description, $contenttype, $::FORM{'ispatch'}, $isprivate, $::userid, $thedata)");
 
   # Retrieve the ID of the newly created attachment record.
   SendSQL("SELECT LAST_INSERT_ID()");
@@ -878,19 +882,20 @@ sub insert
   AppendComment($::FORM{'bugid'}, 
                 $::COOKIE{"Bugzilla_login"},
                 $comment,
-                $isprivate);
+                $isprivate,
+                $timestamp);
 
   # Make existing attachments obsolete.
   my $fieldid = GetFieldID('attachments.isobsolete');
   foreach my $obsolete_id (@{$::MFORM{'obsolete'}}) {
       SendSQL("UPDATE attachments SET isobsolete = 1 WHERE attach_id = $obsolete_id");
       SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
-               VALUES ($::FORM{'bugid'}, $obsolete_id, $::userid, NOW(), $fieldid, '0', '1')");
+               VALUES ($::FORM{'bugid'}, $obsolete_id, $::userid, $sql_timestamp, $fieldid, '0', '1')");
       # If the obsolete attachment has pending flags, migrate them to the new attachment.
       if (Bugzilla::Flag::count({ 'attach_id' => $obsolete_id , 
                                   'status' => 'pending',
                                   'is_active' => 1 })) {
-        Bugzilla::Flag::migrate($obsolete_id, $attachid);
+        Bugzilla::Flag::migrate($obsolete_id, $attachid, $timestamp);
       }
   }
 
@@ -898,8 +903,6 @@ sub insert
   my $owner = "";
   
   if ($::FORM{'takebug'} && UserInGroup("editbugs")) {
-      SendSQL("select NOW()");
-      my $timestamp = FetchOneColumn();
       
       my @fields = ("assigned_to", "bug_status", "resolution", "login_name");
       
@@ -933,7 +936,7 @@ sub insert
               SendSQL("INSERT INTO bugs_activity " .
                       "(bug_id, who, bug_when, fieldid, removed, added) " .
                       " VALUES ($::FORM{'bugid'}, $::userid, " . 
-                      SqlQuote($timestamp) . 
+                      "$sql_timestamp " . 
                       ", $fieldid, $oldvalues[$i], $newvalues[$i])");
           }
       }      
@@ -1075,11 +1078,10 @@ sub update
          ");
 
   # Figure out when the changes were made.
-  SendSQL("SELECT NOW()");
-  my $timestamp = FetchOneColumn();
+  my ($timestamp) = Bugzilla->dbh->selectrow_array("SELECT NOW()"); 
+  my $sql_timestamp = SqlQuote($timestamp); 
     
   # Record changes in the activity table.
-  my $sql_timestamp = SqlQuote($timestamp);
   if ($olddescription ne $::FORM{'description'}) {
     my $quotedolddescription = SqlQuote($olddescription);
     my $fieldid = GetFieldID('attachments.description');
@@ -1096,7 +1098,7 @@ sub update
     my $quotedoldfilename = SqlQuote($oldfilename);
     my $fieldid = GetFieldID('attachments.filename');
     SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
-             VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $quotedoldfilename, $quotedfilename)");
+             VALUES ($bugid, $::FORM{'id'}, $::userid, $sql_timestamp, $fieldid, $quotedoldfilename, $quotedfilename)");
   }
   if ($oldispatch ne $::FORM{'ispatch'}) {
     my $fieldid = GetFieldID('attachments.ispatch');
@@ -1111,7 +1113,7 @@ sub update
   if ($oldisprivate ne $::FORM{'isprivate'}) {
     my $fieldid = GetFieldID('attachments.isprivate');
     SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
-             VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $oldisprivate, $::FORM{'isprivate'})");
+             VALUES ($bugid, $::FORM{'id'}, $::userid, $sql_timestamp, $fieldid, $oldisprivate, $::FORM{'isprivate'})");
   }
   
   # Update flags.