/** * Attaches all the tags to each bug in the group action. * @param integer Bug ID * @return boolean True if all tags attach properly */ function action_attach_tags_process($p_bug_id) { global $g_action_attach_tags_attach, $g_action_attach_tags_create; $t_user_id = auth_get_current_user_id(); foreach ($g_action_attach_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name'], $t_user_id); $g_action_attach_tags_attach[] = $t_tag_row; } $g_action_attach_tags_create = array(); foreach ($g_action_attach_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $p_bug_id)) { tag_bug_attach($t_tag_row['id'], $p_bug_id, $t_user_id); } } return true; }
function mci_tag_set_for_issue($p_issue_id, $p_tags, $p_user_id) { $t_tag_ids_to_attach = array(); $t_tag_ids_to_detach = array(); $t_submitted_tag_ids = array(); $t_attached_tags = tag_bug_get_attached($p_issue_id); $t_attached_tag_ids = array(); foreach ($t_attached_tags as $t_attached_tag) { $t_attached_tag_ids[] = $t_attached_tag['id']; } foreach ($p_tags as $t_tag) { $t_tag = SoapObjectsFactory::unwrapObject($t_tag); $t_submitted_tag_ids[] = $t_tag['id']; if (in_array($t_tag['id'], $t_attached_tag_ids)) { continue; } else { $t_tag_ids_to_attach[] = $t_tag['id']; } } foreach ($t_attached_tag_ids as $t_attached_tag_id) { if (in_array($t_attached_tag_id, $t_submitted_tag_ids)) { continue; } else { $t_tag_ids_to_detach[] = $t_attached_tag_id; } } foreach ($t_tag_ids_to_detach as $t_tag_id) { if (access_has_bug_level(config_get('tag_detach_threshold'), $p_issue_id, $p_user_id)) { tag_bug_detach($t_tag_id, $p_issue_id); } } foreach ($t_tag_ids_to_attach as $t_tag_id) { if (access_has_bug_level(config_get('tag_attach_threshold'), $p_issue_id, $p_user_id)) { tag_bug_attach($t_tag_id, $p_issue_id); } } }
/** * Attaches a bunch of tags to the specified issue. * * @param int $p_bug_id The bug id. * @param string $p_tag_string String of tags separated by configured separator. * @param int $p_tag_id Tag id to add or 0 to skip. * @return array|bool true for success, otherwise array of failures. The array elements follow the tag_parse_string() * format. */ function tag_attach_many($p_bug_id, $p_tag_string, $p_tag_id = 0) { # If no work, then there is no need to do access check. if ($p_tag_id === 0 && is_blank($p_tag_string)) { return true; } access_ensure_bug_level(config_get('tag_attach_threshold'), $p_bug_id); $t_tags = tag_parse_string($p_tag_string); $t_can_create = access_has_global_level(config_get('tag_create_threshold')); $t_tags_create = array(); $t_tags_attach = array(); $t_tags_failed = array(); foreach ($t_tags as $t_tag_row) { if (-1 == $t_tag_row['id']) { if ($t_can_create) { $t_tags_create[] = $t_tag_row; } else { $t_tags_failed[] = $t_tag_row; } } else { if (-2 == $t_tag_row['id']) { $t_tags_failed[] = $t_tag_row; } else { $t_tags_attach[] = $t_tag_row; } } } if (0 < $p_tag_id && tag_exists($p_tag_id)) { $t_tags_attach[] = tag_get($p_tag_id); } # failed to attach at least one tag if (count($t_tags_failed) > 0) { return $t_tags_failed; } foreach ($t_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name']); $t_tags_attach[] = $t_tag_row; } foreach ($t_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $p_bug_id)) { tag_bug_attach($t_tag_row['id'], $p_bug_id); } } event_signal('EVENT_TAG_ATTACHED', array($p_bug_id, $t_tags_attach)); return true; }
?> <tr class="spacer"><td colspan="2"></td></tr> <tr> <th class="category"><?php echo lang_get('tag_attach_long'); ?> </th> <td> <?php print_tag_attach_form($f_bug_id, $t_tag_string); ?> </td> </tr> </table> <?php html_page_bottom(); // end failed to attach tag } else { foreach ($t_tags_create as $t_tag_row) { $t_tag_row['id'] = tag_create($t_tag_row['name'], $t_user_id); $t_tags_attach[] = $t_tag_row; } foreach ($t_tags_attach as $t_tag_row) { if (!tag_bug_is_attached($t_tag_row['id'], $f_bug_id)) { tag_bug_attach($t_tag_row['id'], $f_bug_id, $t_user_id); } } event_signal('EVENT_TAG_ATTACHED', array($f_bug_id, $t_tags_attach)); form_security_purge('tag_attach'); print_successful_redirect_to_bug($f_bug_id); }
/** * Set tag(s) for a given issue id * @param integer $p_issue_id Issue id. * @param array $p_tags Array of tags. * @param integer $p_user_id User id. * @return void */ function mci_tag_set_for_issue($p_issue_id, array $p_tags, $p_user_id) { $t_tag_ids_to_attach = array(); $t_tag_ids_to_detach = array(); $t_submitted_tag_ids = array(); $t_attached_tags = tag_bug_get_attached($p_issue_id); $t_attached_tag_ids = array(); foreach ($t_attached_tags as $t_attached_tag) { $t_attached_tag_ids[] = $t_attached_tag['id']; } foreach ($p_tags as $t_tag) { $t_tag = SoapObjectsFactory::unwrapObject($t_tag); $t_submitted_tag_ids[] = $t_tag['id']; if (in_array($t_tag['id'], $t_attached_tag_ids)) { continue; } else { $t_tag_ids_to_attach[] = $t_tag['id']; } } foreach ($t_attached_tag_ids as $t_attached_tag_id) { if (in_array($t_attached_tag_id, $t_submitted_tag_ids)) { continue; } else { $t_tag_ids_to_detach[] = $t_attached_tag_id; } } foreach ($t_tag_ids_to_detach as $t_tag_id) { if (access_has_bug_level(config_get('tag_detach_threshold'), $p_issue_id, $p_user_id)) { log_event(LOG_WEBSERVICE, 'detaching tag id \'' . $t_tag_id . '\' from issue \'' . $p_issue_id . '\''); tag_bug_detach($t_tag_id, $p_issue_id); } } foreach ($t_tag_ids_to_attach as $t_tag_id) { if (access_has_bug_level(config_get('tag_attach_threshold'), $p_issue_id, $p_user_id)) { log_event(LOG_WEBSERVICE, 'attaching tag id \'' . $t_tag_id . '\' to issue \'' . $p_issue_id . '\''); tag_bug_attach($t_tag_id, $p_issue_id); } } }