? basic_changes.patch
? useful-crap.txt
Index: Attachment.pm
===================================================================
RCS file: /cvs/gnome/bugzilla-new/Attachment.pm,v
retrieving revision 1.1.1.1
diff -p -u -r1.1.1.1 Attachment.pm
--- Attachment.pm	15 Jul 2002 21:51:26 -0000	1.1.1.1
+++ Attachment.pm	15 Mar 2005 02:12:43 -0000
@@ -65,6 +65,11 @@ sub query
         $a{'date'} = "$1-$2-$3 $4:$5";
     }
 
+    # Start with the attachstatusname; the algorithm used to determine
+    # the status to use for this is also used in process_bug.cgi
+    $a{'attachstatusname'} = 'none';
+    $a{'attachstatusname'} = 'obsolete' if ($a{'isobsolete'});
+
     # Retrieve a list of status flags that have been set on the attachment.
     &::PushGlobalSQLState();
     &::SendSQL(" 
@@ -78,6 +83,7 @@ sub query
     while (&::MoreSQLData()) { 
       my ($status) = &::FetchSQLData(); 
       push @statuses , $status;
+      $a{'attachstatusname'}=$status if ($a{'attachstatusname'} eq 'none');
     }
     $a{'statuses'} = \@statuses;
     &::PopGlobalSQLState();
Index: bug_form.pl
===================================================================
RCS file: /cvs/gnome/bugzilla-new/bug_form.pl,v
retrieving revision 1.7
diff -p -u -r1.7 bug_form.pl
--- bug_form.pl	26 Feb 2005 21:23:16 -0000	1.7
+++ bug_form.pl	15 Mar 2005 02:12:43 -0000
@@ -274,6 +274,21 @@ sub show_bug {    
         $bug{'keywords'} = \@keywords;
     }    
 
+    SendSQL("SELECT
+               attachstatusdefs.name 
+             FROM
+               attachstatusdefs
+             WHERE 
+               attachstatusdefs.product = '_gg_global' OR
+               attachstatusdefs.product = '$bug{'product'}'
+             ORDER BY
+               attachstatusdefs.sortkey");
+    my @attachstatusnames = ("none", "obsolete");
+    while (MoreSQLData()) {
+      push(@attachstatusnames, FetchOneColumn());
+    }
+    $vars->{'attachstatusnames'} = \@attachstatusnames;
+
     # Attachments
     $bug{'attachments'} = Attachment::query($id);
 
Index: process_bug.cgi
===================================================================
RCS file: /cvs/gnome/bugzilla-new/process_bug.cgi,v
retrieving revision 1.17
diff -p -u -r1.17 process_bug.cgi
--- process_bug.cgi	27 Feb 2005 22:26:55 -0000	1.17
+++ process_bug.cgi	15 Mar 2005 02:12:44 -0000
@@ -930,7 +930,8 @@ foreach my $id (@idlist) {
             "cc AS selectVisible_cc $write, duplicates $write, " .
             "profiles $write, dependencies $write, votes $write, " .
             "keywords $write, longdescs $write, fielddefs $write, " .
-            "keyworddefs READ, groups READ, attachments READ, products READ");
+            "attachments $write, attachstatuses $write, attachstatusdefs READ, " .
+            "keyworddefs READ, groups READ, products READ");
     my @oldvalues = SnapShotBug($id);
     my %oldhash;
     my $i = 0;
@@ -1284,6 +1285,101 @@ foreach my $id (@idlist) {
             SendSQL("UPDATE bugs SET groupset = groupset - $groupbit WHERE bug_id = $id");
         }
 
+    }
+
+    #
+    # Handle change of status for patches
+    #
+
+    # Gather data to determine what, if anything, has changed
+    SendSQL("
+              SELECT attach_id, isobsolete
+              FROM attachments WHERE bug_id = $id ORDER BY attach_id
+            ");
+    my @attachments = ();
+    while (MoreSQLData()) {
+      my ($attachid, $isobsolete) = FetchSQLData();
+
+      my $newstatus = "";
+      if (defined $::FORM{'attach' . $attachid . 'status'}) {
+        $newstatus = $::FORM{'attach' . $attachid . 'status'};
+      }
+
+      # Retrieve a list of status flags that have been set on the attachment;
+      # uses same algorithm as Attachment::query to determine current status
+      my $status = 'none';
+      $status = 'obsolete' if ($isobsolete);
+      PushGlobalSQLState();
+      SendSQL(" 
+                SELECT   name 
+                FROM     attachstatuses, attachstatusdefs 
+                WHERE    attach_id = $attachid
+                AND      attachstatuses.statusid = attachstatusdefs.id
+                ORDER BY sortkey
+              ");
+      my @oldstatuses = ();
+      while (MoreSQLData()) { 
+        my ($nextvalue) = FetchSQLData(); 
+        push @oldstatuses, $nextvalue;
+        $status = $nextvalue if ($status eq 'none');
+      }
+
+      # Only add this to the list of attachments that had changes if the
+      # current status and the newstatus don't match
+      if ($status ne $newstatus) {
+        push @attachments, { id          => $attachid,
+                             obsolete    => $isobsolete, 
+                             status      => $newstatus, 
+                             oldstatuses => \@oldstatuses };
+      }
+      PopGlobalSQLState();
+    }
+
+    # Now, make the appropriate changes to both attachstatuses and bugs_activity
+    foreach my $attachment (@attachments) {
+      # Unconditionally remove all attachstatuses; we'll manually add only the
+      # newly chosen one
+      SendSQL("DELETE FROM attachstatuses WHERE attach_id = ${$attachment}{id}");
+
+      my $oldstatuslist = join(", ", @{${$attachment}{oldstatuses}});
+      my $newstatuslist = ${$attachment}{status};
+      my $isobsolete = 0;
+      $isobsolete = 1 if $newstatuslist eq 'obsolete';
+
+      if ($newstatuslist eq 'none' || $newstatuslist eq 'obsolete') {
+        $newstatuslist = "";
+      } else {
+        # Add the new status (well, it's id) to attachstatuses
+        SendSQL("SELECT attachstatusdefs.id FROM attachstatusdefs 
+                 WHERE attachstatusdefs.name = '$newstatuslist'");
+        my ($status_id) = FetchSQLData();
+        SendSQL("INSERT INTO attachstatuses 
+                 (attach_id, statusid) VALUES (${$attachment}{id}, $status_id)");
+      }
+
+      # If the obsolete field is changing update attachments and bugs_activity
+      if ( ${$attachment}{obsolete} != $isobsolete ) {
+        SendSQL("UPDATE attachments SET isobsolete = $isobsolete 
+                 WHERE attach_id = ${$attachment}{id}");
+        my $fieldid = GetFieldID('attachments.isobsolete');
+        SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
+                 VALUES ($id, ${$attachment}{id}, $whoid," . SqlQuote($timestamp) . ", $fieldid, 
+                         ${$attachment}{obsolete}, $isobsolete)");
+      }
+
+      # If the status lists have changed update bugs_activity
+      if ($oldstatuslist ne $newstatuslist) {
+        my ($removed, $added) = DiffStrings($oldstatuslist, $newstatuslist);
+        my $quotedremoved = SqlQuote($removed);
+        my $quotedadded = SqlQuote($added);
+        my $fieldid = GetFieldID('attachstatusdefs.name');
+        SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added) 
+                 VALUES ($id, ${$attachment}{id}, $whoid," . SqlQuote($timestamp) . ", $fieldid, 
+                         $quotedremoved, $quotedadded)");
+      }
+
+      # Record the fact that the bug changed
+      $bug_changed = 1;
     }
   
     # get a snapshot of the newly set values out of the database, 
Index: template/en/default/attachment/list.html.tmpl
===================================================================
RCS file: /cvs/gnome/bugzilla-new/template/en/default/attachment/list.html.tmpl,v
retrieving revision 1.5
diff -p -u -r1.5 list.html.tmpl
--- template/en/default/attachment/list.html.tmpl	12 Mar 2005 22:18:20 -0000	1.5
+++ template/en/default/attachment/list.html.tmpl	15 Mar 2005 02:12:44 -0000
@@ -49,15 +49,15 @@
 
       <td valign="top">[% attachment.date %]</td>
 
-      <td valign="top">
-        [% IF attachment.statuses.size == 0 %]
-          <i>none</i>
-        [% ELSE %]
-          [% FOREACH s = attachment.statuses %]
-            [% s FILTER html FILTER replace('\s', '&nbsp;') %]<br>
-          [% END %]
-        [% END %]
-      </td>
+      [% IF user.canedit AND attachment.ispatch %]
+        [% PROCESS selectattach selname  => "attachstatusnames"
+                                id       =  attachment.attachid
+                                curvalue =  attachment.attachstatusname %]
+      [% ELSE %]
+        <input type="hidden" name="attach[% attachment.attachid %]status" 
+               value="[% attachment.attachstatusname FILTER html %]">
+        <td> [% attachment.attachstatusname FILTER html %] </td>
+      [% END %]
 
       <td valign="top">
         [% IF attachment.canedit %]
@@ -79,3 +79,19 @@
   </tr>
 </table>
 <br>
+
+[%############################################################################%]
+[%# Block for SELECTATTACH field                                             #%]
+[%############################################################################%]
+
+[% BLOCK selectattach %]  
+  <td>
+    <select name="attach[% id %]status">
+      [% FOREACH x = ${selname} %]
+        <option value="[% x FILTER html %]"
+          [% " selected" IF x == curvalue %]>[% x FILTER html %]
+        </option>
+      [% END %]
+    </select>
+  </td>
+[% END %]
