@@ -932,6 +932,117 @@ sub extract_flags_from_cgi {
932932
933933=over
934934
935+ =item C<multi_extract_flags_from_cgi($bug, $hr_vars) >
936+
937+ Checks whether or not there are new flags to create and returns an
938+ array of hashes. This array is then passed to Flag::create(). This differs
939+ from the previous sub-routine as it is called for changing multiple bugs
940+
941+ =back
942+
943+ =cut
944+
945+ sub multi_extract_flags_from_cgi {
946+ my ($class , $bug , $vars , $skip ) = @_ ;
947+ my $cgi = Bugzilla-> cgi;
948+
949+ my $match_status = Bugzilla::User::match_field({
950+ ' ^requestee(_type)?-(\d+)$' => { ' type' => ' multi' },
951+ }, undef , $skip );
952+
953+ $vars -> {' match_field' } = ' requestee' ;
954+ if ($match_status == USER_MATCH_FAILED) {
955+ $vars -> {' message' } = ' user_match_failed' ;
956+ }
957+ elsif ($match_status == USER_MATCH_MULTIPLE) {
958+ $vars -> {' message' } = ' user_match_multiple' ;
959+ }
960+
961+ # Extract a list of flag type IDs from field names.
962+ my @flagtype_ids = map (/ ^flag_type-(\d +)$ / ? $1 : (), $cgi -> param());
963+
964+ my (@new_flags , @flags );
965+
966+ # Get a list of active flag types available for this product/component.
967+ my $flag_types = Bugzilla::FlagType::match(
968+ { ' product_id' => $bug -> {' product_id' },
969+ ' component_id' => $bug -> {' component_id' },
970+ ' is_active' => 1 });
971+
972+ foreach my $flagtype_id (@flagtype_ids ) {
973+ # Checks if there are unexpected flags for the product/component.
974+ if (!scalar (grep { $_ -> id == $flagtype_id } @$flag_types )) {
975+ $vars -> {' message' } = ' unexpected_flag_types' ;
976+ last ;
977+ }
978+ }
979+
980+ foreach my $flag_type (@$flag_types ) {
981+ my $type_id = $flag_type -> id;
982+
983+ # Bug flags are only valid for bugs
984+ next unless ($flag_type -> target_type eq ' bug' );
985+
986+ # We are only interested in flags the user tries to create.
987+ next unless scalar (grep { $_ == $type_id } @flagtype_ids );
988+
989+ # Get the flags of this type already set for this bug.
990+ my $current_flags = $class -> match(
991+ { ' type_id' => $type_id ,
992+ ' target_type' => ' bug' ,
993+ ' bug_id' => $bug -> bug_id });
994+
995+ # We will update existing flags (instead of creating new ones)
996+ # if the flag exists and the user has not chosen the 'always add'
997+ # option
998+ my $update = scalar (@$current_flags ) && ! $cgi -> param(" flags_add-$type_id " );
999+
1000+ my $status = $cgi -> param(" flag_type-$type_id " );
1001+ trick_taint($status );
1002+
1003+ my @logins = $cgi -> param(" requestee_type-$type_id " );
1004+ if ($status eq " ?" && scalar (@logins )) {
1005+ foreach my $login (@logins ) {
1006+ if ($update ) {
1007+ foreach my $current_flag (@$current_flags ) {
1008+ push (@flags , { id => $current_flag -> id,
1009+ status => $status ,
1010+ requestee => $login ,
1011+ skip_roe => $skip });
1012+ }
1013+ }
1014+ else {
1015+ push (@new_flags , { type_id => $type_id ,
1016+ status => $status ,
1017+ requestee => $login ,
1018+ skip_roe => $skip });
1019+ }
1020+
1021+ last unless $flag_type -> is_multiplicable;
1022+ }
1023+ }
1024+ else {
1025+ if ($update ) {
1026+ foreach my $current_flag (@$current_flags ) {
1027+ push (@flags , { id => $current_flag -> id,
1028+ status => $status });
1029+ }
1030+ }
1031+ else {
1032+ push (@new_flags , { type_id => $type_id ,
1033+ status => $status });
1034+ }
1035+ }
1036+ }
1037+
1038+ # Return the list of flags to update and/or to create.
1039+ return (\@flags , \@new_flags );
1040+ }
1041+
1042+ =pod
1043+
1044+ =over
1045+
9351046=item C<notify($flag, $old_flag, $object, $timestamp) >
9361047
9371048Sends an email notification about a flag being created, fulfilled
0 commit comments