@@ -540,7 +540,6 @@ sub insert {
540
540
my ($flags , $new_flags ) = Bugzilla::Flag-> extract_flags_from_cgi(
541
541
$bug , $attachment , $vars , SKIP_REQUESTEE_ON_ERROR);
542
542
$attachment -> set_flags($flags , $new_flags );
543
- $attachment -> update($timestamp );
544
543
545
544
# Insert a comment about the new attachment into the database.
546
545
my $comment = $cgi -> param(' comment' );
@@ -549,71 +548,76 @@ sub insert {
549
548
type => CMT_ATTACHMENT_CREATED,
550
549
extra_data => $attachment -> id });
551
550
552
- # Assign the bug to the user, if they are allowed to take it
553
- my $owner = " " ;
554
- if ($cgi -> param(' takebug' ) && $user -> in_group(' editbugs' , $bug -> product_id)) {
555
- # When taking a bug, we have to follow the workflow.
556
- my $bug_status = $cgi -> param(' bug_status' ) || ' ' ;
557
- ($bug_status ) = grep {$_ -> name eq $bug_status } @{$bug -> status-> can_change_to};
558
-
559
- if ($bug_status && $bug_status -> is_open
560
- && ($bug_status -> name ne ' UNCONFIRMED'
561
- || $bug -> product_obj-> allows_unconfirmed))
562
- {
563
- $bug -> set_bug_status($bug_status -> name);
564
- $bug -> clear_resolution();
565
- }
566
- # Make sure the person we are taking the bug from gets mail.
567
- $owner = $bug -> assigned_to-> login;
568
- $bug -> set_assigned_to($user );
569
- }
551
+ # Assign the bug to the user, if they are allowed to take it
552
+ my $owner = " " ;
553
+ if ($cgi -> param(' takebug' ) && $user -> in_group(' editbugs' , $bug -> product_id)) {
554
+ # When taking a bug, we have to follow the workflow.
555
+ my $bug_status = $cgi -> param(' bug_status' ) || ' ' ;
556
+ ($bug_status ) = grep { $_ -> name eq $bug_status }
557
+ @{ $bug -> status-> can_change_to };
558
+
559
+ if ($bug_status && $bug_status -> is_open
560
+ && ($bug_status -> name ne ' UNCONFIRMED'
561
+ || $bug -> product_obj-> allows_unconfirmed))
562
+ {
563
+ $bug -> set_bug_status($bug_status -> name);
564
+ $bug -> clear_resolution();
565
+ }
566
+ # Make sure the person we are taking the bug from gets mail.
567
+ $owner = $bug -> assigned_to-> login;
568
+ $bug -> set_assigned_to($user );
569
+ }
570
+
571
+ $bug -> add_cc($user ) if $cgi -> param(' addselfcc' );
572
+ $bug -> update($timestamp );
570
573
571
- $bug -> add_cc($user ) if $cgi -> param(' addselfcc' );
572
- $bug -> update($timestamp );
574
+ # We have to update the attachment after updating the bug, to ensure new
575
+ # comments are available.
576
+ $attachment -> update($timestamp );
573
577
574
- $dbh -> bz_commit_transaction;
578
+ $dbh -> bz_commit_transaction;
575
579
576
- # Define the variables and functions that will be passed to the UI template.
577
- $vars -> {' attachment' } = $attachment ;
578
- # We cannot reuse the $bug object as delta_ts has eventually been updated
579
- # since the object was created.
580
- $vars -> {' bugs' } = [new Bugzilla::Bug($bugid )];
581
- $vars -> {' header_done' } = 1;
582
- $vars -> {' contenttypemethod' } = $cgi -> param(' contenttypemethod' );
580
+ # Define the variables and functions that will be passed to the UI template.
581
+ $vars -> {' attachment' } = $attachment ;
582
+ # We cannot reuse the $bug object as delta_ts has eventually been updated
583
+ # since the object was created.
584
+ $vars -> {' bugs' } = [new Bugzilla::Bug($bugid )];
585
+ $vars -> {' header_done' } = 1;
586
+ $vars -> {' contenttypemethod' } = $cgi -> param(' contenttypemethod' );
583
587
584
- my $recipients = { ' changer' => $user , ' owner' => $owner };
585
- $vars -> {' sent_bugmail' } = Bugzilla::BugMail::Send($bugid , $recipients );
588
+ my $recipients = { ' changer' => $user , ' owner' => $owner };
589
+ $vars -> {' sent_bugmail' } = Bugzilla::BugMail::Send($bugid , $recipients );
586
590
587
- print $cgi -> header();
588
- # Generate and return the UI (HTML page) from the appropriate template.
589
- $template -> process(" attachment/created.html.tmpl" , $vars )
590
- || ThrowTemplateError($template -> error());
591
+ print $cgi -> header();
592
+ # Generate and return the UI (HTML page) from the appropriate template.
593
+ $template -> process(" attachment/created.html.tmpl" , $vars )
594
+ || ThrowTemplateError($template -> error());
591
595
}
592
596
593
597
# Displays a form for editing attachment properties.
594
598
# Any user is allowed to access this page, unless the attachment
595
599
# is private and the user does not belong to the insider group.
596
600
# Validations are done later when the user submits changes.
597
601
sub edit {
598
- my $attachment = validateID();
602
+ my $attachment = validateID();
599
603
600
- my $bugattachments =
601
- Bugzilla::Attachment-> get_attachments_by_bug($attachment -> bug);
604
+ my $bugattachments =
605
+ Bugzilla::Attachment-> get_attachments_by_bug($attachment -> bug);
602
606
603
- my $any_flags_requesteeble =
604
- grep { $_ -> is_requestable && $_ -> is_requesteeble } @{ $attachment -> flag_types};
605
- # Useful in case a flagtype is no longer requestable but a requestee
606
- # has been set before we turned off that bit.
607
- $any_flags_requesteeble ||= grep { $_ -> requestee_id } @{$attachment -> flags};
608
- $vars -> {' any_flags_requesteeble' } = $any_flags_requesteeble ;
609
- $vars -> {' attachment' } = $attachment ;
610
- $vars -> {' attachments' } = $bugattachments ;
607
+ my $any_flags_requesteeble = grep { $_ -> is_requestable && $_ -> is_requesteeble }
608
+ @{ $attachment -> flag_types };
609
+ # Useful in case a flagtype is no longer requestable but a requestee
610
+ # has been set before we turned off that bit.
611
+ $any_flags_requesteeble ||= grep { $_ -> requestee_id } @{ $attachment -> flags };
612
+ $vars -> {' any_flags_requesteeble' } = $any_flags_requesteeble ;
613
+ $vars -> {' attachment' } = $attachment ;
614
+ $vars -> {' attachments' } = $bugattachments ;
611
615
612
- print $cgi -> header();
616
+ print $cgi -> header();
613
617
614
- # Generate and return the UI (HTML page) from the appropriate template.
615
- $template -> process(" attachment/edit.html.tmpl" , $vars )
616
- || ThrowTemplateError($template -> error());
618
+ # Generate and return the UI (HTML page) from the appropriate template.
619
+ $template -> process(" attachment/edit.html.tmpl" , $vars )
620
+ || ThrowTemplateError($template -> error());
617
621
}
618
622
619
623
# Updates an attachment record. Only users with "editbugs" privileges,
@@ -715,16 +719,18 @@ sub update {
715
719
# Figure out when the changes were made.
716
720
my $timestamp = $dbh -> selectrow_array(' SELECT LOCALTIMESTAMP(0)' );
717
721
722
+ # Commit the comment, if any.
723
+ # This has to happen before updating the attachment, to ensure new comments
724
+ # are available to $attachment->update.
725
+ $bug -> update($timestamp );
726
+
718
727
if ($can_edit ) {
719
728
my $changes = $attachment -> update($timestamp );
720
729
# If there are changes, we updated delta_ts in the DB. We have to
721
730
# reflect this change in the bug object.
722
731
$bug -> {delta_ts } = $timestamp if scalar (keys %$changes );
723
732
}
724
733
725
- # Commit the comment, if any.
726
- $bug -> update($timestamp );
727
-
728
734
# Commit the transaction now that we are finished updating the database.
729
735
$dbh -> bz_commit_transaction();
730
736
0 commit comments