/** * Update changeset relations to affected bugs. */ function save_bugs($p_user_id = null) { $t_bug_table = plugin_table('bug', 'Source'); $this->bugs = array_unique($this->bugs); $this->__bugs = array_unique($this->__bugs); $t_bugs_added = array_unique(array_diff($this->bugs, $this->__bugs)); $t_bugs_deleted = array_unique(array_diff($this->__bugs, $this->bugs)); $this->load_repo(); $t_vcs = SourceVCS::repo($this->repo); $t_user_id = (int) $p_user_id; if ($t_user_id < 1) { if ($this->committer_id > 0) { $t_user_id = $this->committer_id; } else { if ($this->user_id > 0) { $t_user_id = $this->user_id; } } } if (count($t_bugs_deleted)) { $t_bugs_deleted_str = join(',', $t_bugs_deleted); $t_query = "DELETE FROM {$t_bug_table} WHERE change_id=" . $this->id . " AND bug_id IN ( {$t_bugs_deleted_str} )"; db_query_bound($t_query); foreach ($t_bugs_deleted as $t_bug_id) { plugin_history_log($t_bug_id, 'changeset_removed', $this->repo->name . ' ' . $t_vcs->show_changeset($this->repo, $this), '', $t_user_id, 'Source'); bug_update_date($t_bug_id); } } if (count($t_bugs_added) > 0) { $t_query = "INSERT INTO {$t_bug_table} ( change_id, bug_id ) VALUES "; $t_count = 0; $t_params = array(); foreach ($t_bugs_added as $t_bug_id) { $t_query .= ($t_count == 0 ? '' : ', ') . '(' . db_param() . ', ' . db_param() . ')'; $t_params[] = $this->id; $t_params[] = $t_bug_id; $t_count++; } db_query_bound($t_query, $t_params); foreach ($t_bugs_added as $t_bug_id) { plugin_history_log($t_bug_id, 'changeset_attached', '', $this->repo->name . ' ' . $t_vcs->show_changeset($this->repo, $this), $t_user_id, 'Source'); bug_update_date($t_bug_id); } } }
/** * Set the bugnote text * @param integer $p_bugnote_id A bugnote identifier. * @param string $p_bugnote_text The bugnote text to set. * @return boolean * @access public */ function bugnote_set_text($p_bugnote_id, $p_bugnote_text) { $t_old_text = bugnote_get_text($p_bugnote_id); if ($t_old_text == $p_bugnote_text) { return true; } # MySQL 4-bytes UTF-8 chars workaround #21101 $p_bugnote_text = db_mysql_fix_utf8($p_bugnote_text); $t_bug_id = bugnote_get_field($p_bugnote_id, 'bug_id'); $t_bugnote_text_id = bugnote_get_field($p_bugnote_id, 'bugnote_text_id'); # insert an 'original' revision if needed if (bug_revision_count($t_bug_id, REV_BUGNOTE, $p_bugnote_id) < 1) { $t_user_id = bugnote_get_field($p_bugnote_id, 'reporter_id'); $t_timestamp = bugnote_get_field($p_bugnote_id, 'last_modified'); bug_revision_add($t_bug_id, $t_user_id, REV_BUGNOTE, $t_old_text, $p_bugnote_id, $t_timestamp); } db_param_push(); $t_query = 'UPDATE {bugnote_text} SET note=' . db_param() . ' WHERE id=' . db_param(); db_query($t_query, array($p_bugnote_text, $t_bugnote_text_id)); # updated the last_updated date bugnote_date_update($p_bugnote_id); bug_update_date($t_bug_id); # insert a new revision $t_user_id = auth_get_current_user_id(); $t_revision_id = bug_revision_add($t_bug_id, $t_user_id, REV_BUGNOTE, $p_bugnote_text, $p_bugnote_id); # log new bugnote history_log_event_special($t_bug_id, BUGNOTE_UPDATED, bugnote_format_id($p_bugnote_id), $t_revision_id); return true; }
/** * Set the bugnote text * @param int $p_bugnote_id bugnote id * @param string $p_bugnote_text bugnote text * @return bool * @access public */ function bugnote_set_text($p_bugnote_id, $p_bugnote_text) { $t_old_text = bugnote_get_text($p_bugnote_id); if ($t_old_text == $p_bugnote_text) { return true; } $t_bug_id = bugnote_get_field($p_bugnote_id, 'bug_id'); $t_bugnote_text_id = bugnote_get_field($p_bugnote_id, 'bugnote_text_id'); $t_bugnote_text_table = db_get_table('mantis_bugnote_text_table'); # insert an 'original' revision if needed if (bug_revision_count($t_bug_id, REV_BUGNOTE, $p_bugnote_id) < 1) { $t_user_id = bugnote_get_field($p_bugnote_id, 'reporter_id'); $t_timestamp = bugnote_get_field($p_bugnote_id, 'last_modified'); bug_revision_add($t_bug_id, $t_user_id, REV_BUGNOTE, $t_old_text, $p_bugnote_id, $t_timestamp); } $query = "UPDATE {$t_bugnote_text_table}\n\t\t\tSET note=" . db_param() . " WHERE id=" . db_param(); db_query_bound($query, array($p_bugnote_text, $t_bugnote_text_id)); # updated the last_updated date bugnote_date_update($p_bugnote_id); bug_update_date($t_bug_id); # insert a new revision $t_user_id = auth_get_current_user_id(); $t_revision_id = bug_revision_add($t_bug_id, $t_user_id, REV_BUGNOTE, $p_bugnote_text, $p_bugnote_id); # log new bugnote history_log_event_special($t_bug_id, BUGNOTE_UPDATED, bugnote_format_id($p_bugnote_id), $t_revision_id); return true; }
# @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); bug_set_field($t_bug_id, 'sticky', intval(!$f_sticky)); helper_call_custom_function('issue_update_notify', array($t_bug_id)); } else { $t_failed_ids[$t_bug_id] = lang_get('bug_actiongroup_access'); } break; case 'CUSTOM': if (0 === $f_custom_field_id) { trigger_error(ERROR_GENERIC, ERROR); } # @todo we need to issue a helper_call_custom_function( 'issue_update_validate', array( $t_bug_id, $t_bug_data, $f_bugnote_text ) ); $t_form_var = 'custom_field_' . $f_custom_field_id; $t_custom_field_value = gpc_get_custom_field($t_form_var, $t_custom_field_def['type'], null); custom_field_set_value($f_custom_field_id, $t_bug_id, $t_custom_field_value); bug_update_date($t_bug_id); email_bug_updated($t_bug_id); helper_call_custom_function('issue_update_notify', array($t_bug_id)); break; default: trigger_error(ERROR_GENERIC, ERROR); } # Bug Action Event event_signal('EVENT_BUG_ACTION', array($f_action, $t_bug_id)); } form_security_purge($t_form_name); $t_redirect_url = 'view_all_bug_page.php'; if (count($t_failed_ids) > 0) { html_page_top(); echo '<div><br />'; echo '<table class="width75">';
# retrieve the destination bug of the relationship $t_dest_bug_id = relationship_get_linked_bug_id($f_rel_id, $f_bug_id); # user can access to the related bug at least as viewer, if it's exist... if (bug_exists($t_dest_bug_id)) { if (!access_has_bug_level(VIEWER, $t_dest_bug_id)) { error_parameters($t_dest_bug_id); trigger_error(ERROR_RELATIONSHIP_ACCESS_LEVEL_TO_DEST_BUG_TOO_LOW, ERROR); } } helper_ensure_confirmed(lang_get('delete_relationship_sure_msg'), lang_get('delete_relationship_button')); $t_bug_relationship_data = relationship_get($f_rel_id); $t_rel_type = $t_bug_relationship_data->type; # delete relationship from the DB relationship_delete($f_rel_id); # update bug last updated (just for the src bug) bug_update_date($f_bug_id); # set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug if ($f_bug_id == $t_bug_relationship_data->src_bug_id) { $t_bug_rel_type = $t_rel_type; $t_dest_bug_rel_type = relationship_get_complementary_type($t_rel_type); } else { $t_bug_rel_type = relationship_get_complementary_type($t_rel_type); $t_dest_bug_rel_type = $t_rel_type; } # send email and update the history for the src issue history_log_event_special($f_bug_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_bug_id); email_relationship_deleted($f_bug_id, $t_dest_bug_id, $t_bug_rel_type); if (bug_exists($t_dest_bug_id)) { # send email and update the history for the dest issue history_log_event_special($t_dest_bug_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $f_bug_id); email_relationship_deleted($t_dest_bug_id, $f_bug_id, $t_dest_bug_rel_type);
/** * Delete the relationship with the specified target id. * * @param string $p_username The name of the user trying to add a note to an issue. * @param string $p_password The password of the user. * @param integer $p_issue_id The id of the source issue for the relationship. * @param integer $p_relationship_id The id of relationship to delete. * @return boolean true: success, false: failure */ function mc_issue_relationship_delete($p_username, $p_password, $p_issue_id, $p_relationship_id) { global $g_project_override; $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return mci_soap_fault_login_failed(); } $t_project_id = bug_get_field($p_issue_id, 'project_id'); $g_project_override = $t_project_id; if (!mci_has_readwrite_access($t_user_id, $t_project_id)) { return mci_soap_fault_access_denied($t_user_id); } # user has access to update the bug... if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) { return mci_soap_fault_access_denied($t_user_id, 'Active user does not have access level required to remove a relationship from this issue.'); } # bug is not read-only... if (bug_is_readonly($p_issue_id)) { return mci_soap_fault_access_denied($t_user_id, 'Issue \'' . $p_issue_id . '\' is readonly.'); } # retrieve the destination bug of the relationship $t_dest_issue_id = relationship_get_linked_bug_id($p_relationship_id, $p_issue_id); # user can access to the related bug at least as viewer, if it's exist... if (bug_exists($t_dest_issue_id)) { if (!access_has_bug_level(config_get('view_bug_threshold', null, null, $t_project_id), $t_dest_issue_id, $t_user_id)) { return mci_soap_fault_access_denied($t_user_id, 'The issue \'' . $t_dest_issue_id . '\' requires higher access level.'); } } $t_bug_relationship_data = relationship_get($p_relationship_id); $t_rel_type = $t_bug_relationship_data->type; # delete relationship from the DB log_event(LOG_WEBSERVICE, 'deleting relationship id \'' . $p_relationship_id . '\''); relationship_delete($p_relationship_id); # update bug last updated bug_update_date($p_issue_id); bug_update_date($t_dest_issue_id); # set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug if ($p_issue_id == $t_bug_relationship_data->src_bug_id) { $t_bug_rel_type = $t_rel_type; $t_dest_bug_rel_type = relationship_get_complementary_type($t_rel_type); } else { $t_bug_rel_type = relationship_get_complementary_type($t_rel_type); $t_dest_bug_rel_type = $t_rel_type; } # send email and update the history for the src issue history_log_event_special($p_issue_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_issue_id); email_relationship_deleted($p_issue_id, $t_dest_issue_id, $t_bug_rel_type); if (bug_exists($t_dest_issue_id)) { # send email and update the history for the dest issue history_log_event_special($t_dest_issue_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $p_issue_id); email_relationship_deleted($t_dest_issue_id, $p_issue_id, $t_dest_bug_rel_type); } return true; }
/** * Delete the relationship with the specified target id. * * @param string $p_username The name of the user trying to add a note to an issue. * @param string $p_password The password of the user. * @param integer $p_issue_id The id of the source issue for the relationship * @param integer $p_relationship_id The id of relationship to delete. * @return true: success, false: failure */ function mc_issue_relationship_delete($p_username, $p_password, $p_issue_id, $p_relationship_id) { $t_user_id = mci_check_login($p_username, $p_password); if ($t_user_id === false) { return new soap_fault('Client', '', 'Access Denied'); } $t_project_id = bug_get_field($p_issue_id, 'project_id'); if (!mci_has_readwrite_access($t_user_id, $t_project_id)) { return new soap_fault('Client', '', 'Access Denied'); } # user has access to update the bug... if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) { return new soap_fault('Client', '', "Active user does not have access level required to remove a relationship from this issue."); } # bug is not read-only... if (bug_is_readonly($p_issue_id)) { return new soap_fault('Client', '', "Issue '{$p_issue_id}' is readonly."); } # retrieve the destination bug of the relationship $t_dest_issue_id = relationship_get_linked_bug_id($p_relationship_id, $p_issue_id); # user can access to the related bug at least as viewer, if it's exist... if (bug_exists($t_dest_issue_id)) { if (!access_has_bug_level(VIEWER, $t_dest_issue_id, $t_user_id)) { return new soap_fault('Client', '', "The issue '{$t_dest_issue_id}' requires higher access level."); } } $t_bug_relationship_data = relationship_get($p_relationship_id); $t_rel_type = $t_bug_relationship_data->type; # delete relationship from the DB relationship_delete($p_relationship_id); # update bug last updated (just for the src bug) bug_update_date($p_issue_id); # set the rel_type for both bug and dest_bug based on $t_rel_type and on who is the dest bug if ($p_issue_id == $t_bug_relationship_data->src_bug_id) { $t_bug_rel_type = $t_rel_type; $t_dest_bug_rel_type = relationship_get_complementary_type($t_rel_type); } else { $t_bug_rel_type = relationship_get_complementary_type($t_rel_type); $t_dest_bug_rel_type = $t_rel_type; } # send email and update the history for the src issue history_log_event_special($p_issue_id, BUG_DEL_RELATIONSHIP, $t_bug_rel_type, $t_dest_issue_id); email_relationship_deleted($p_issue_id, $t_dest_issue_id, $t_bug_rel_type); if (bug_exists($t_dest_issue_id)) { # send email and update the history for the dest issue history_log_event_special($t_dest_issue_id, BUG_DEL_RELATIONSHIP, $t_dest_bug_rel_type, $p_issue_id); email_relationship_deleted($t_dest_issue_id, $p_issue_id, $t_dest_bug_rel_type); } return true; }
/** * Detach a tag from a bug. * @param integer Tag ID * @param integer Bug ID * @param boolean Add history entries to bug * @param integer User Id (or null for current logged in user) */ function tag_bug_detach($p_tag_id, $p_bug_id, $p_add_history = true, $p_user_id = null) { if ($p_user_id === null) { $t_user_id = auth_get_current_user_id(); } else { $t_user_id = $p_user_id; } if (!tag_bug_is_attached($p_tag_id, $p_bug_id)) { trigger_error(TAG_NOT_ATTACHED, ERROR); } $t_tag_row = tag_bug_get_row($p_tag_id, $p_bug_id); if ($t_user_id == tag_get_field($p_tag_id, 'user_id') || $t_user_id == $t_tag_row['user_id']) { $t_detach_level = config_get('tag_detach_own_threshold'); } else { $t_detach_level = config_get('tag_detach_threshold'); } access_ensure_bug_level($t_detach_level, $p_bug_id, $t_user_id); $c_tag_id = db_prepare_int($p_tag_id); $c_bug_id = db_prepare_int($p_bug_id); $t_bug_tag_table = db_get_table('bug_tag'); $query = "DELETE FROM {$t_bug_tag_table}\n\t\t\t\t\tWHERE tag_id=" . db_param() . ' AND bug_id=' . db_param(); db_query_bound($query, array($c_tag_id, $c_bug_id)); if ($p_add_history) { $t_tag_name = tag_get_field($p_tag_id, 'name'); history_log_event_special($p_bug_id, TAG_DETACHED, $t_tag_name); } # updated the last_updated date bug_update_date($p_bug_id); return true; }
function event_bug_action($p_event, $p_action, $p_bug_id) { global $agilemantis_pb; global $agilemantis_commonlib; global $agilemantis_sprint; // Only projects with agilMantis backlog if (!$agilemantis_commonlib->projectHasBacklogs(helper_get_current_project())) { return; } $agilemantis_commonlib->getAdditionalProjectFields(); $t_custom_field_id = $_SESSION['custom_field_id']; $pb_id = $agilemantis_commonlib->getProductBacklogIDByBugId($p_bug_id); $list_sprints = $agilemantis_commonlib->getSprintsByBacklogId($pb_id); $current_sprint = $agilemantis_commonlib->getSprintByBugId($p_bug_id); $t_custom_field_value = $_SESSION['custom_field'][$p_bug_id]; if (!$t_custom_field_value) { $t_custom_field_value = ''; } $t_status = bug_get_field($p_bug_id, 'status'); # restore story points value if ($t_custom_field_id == $agilemantis_commonlib->sp) { if ($current_sprint[0]['status'] > 1 || $pb_id == 0 || $t_status >= 80) { $agilemantis_commonlib->restoreCustomFieldValue($p_bug_id, $t_custom_field_id, $t_custom_field_value); } } # restore product backlog value if ($t_custom_field_id == $agilemantis_commonlib->pb) { $pbl = $agilemantis_commonlib->getProjectProductBacklogs(helper_get_current_project()); $do_not_reset = false; if (!empty($pbl)) { foreach ($pbl as $key => $value) { if ($value['pb_id'] == $pb_id) { $do_not_reset = true; } } } $value_resettet = false; if ($current_sprint[0]['name'] != '' || $pb_id == 0 || empty($pbl) || $do_not_reset == false) { $agilemantis_commonlib->restoreCustomFieldValue($p_bug_id, $t_custom_field_id, $t_custom_field_value); $value_resettet = true; } if (empty($t_custom_field_value) && $value_resettet == false) { $agilemantis_commonlib->setTrackerStatus($p_bug_id, 50); $agilemantis_commonlib->id = $pb_id; $backlog = $agilemantis_commonlib->getSelectedProductBacklog(); $agilemantis_commonlib->updateTrackerHandler($p_bug_id, $backlog[0]['user_id'], $pb_id); } } if ($t_custom_field_id == $agilemantis_commonlib->spr) { if (empty($list_sprints)) { $agilemantis_commonlib->restoreCustomFieldValue($p_bug_id, $t_custom_field_id, $t_custom_field_value); } # old sprint information $agilemantis_commonlib->sprint_id = $t_custom_field_value; $sprintInfo = $agilemantis_sprint->getSprintById(); if ($current_sprint[0]['pb_id'] != $pb_id) { $agilemantis_commonlib->restoreCustomFieldValue($p_bug_id, $t_custom_field_id, $t_custom_field_value); } if ($current_sprint[0]['status'] > 1 || $pb_id == 0 || $t_status >= 80) { $agilemantis_commonlib->restoreCustomFieldValue($p_bug_id, $t_custom_field_id, $t_custom_field_value); } } # update bug date bug_update_date($p_bug_id); }
function bug_assign($p_bug_id, $p_user_id, $p_bugnote_text = '', $p_bugnote_private = false) { $c_bug_id = db_prepare_int($p_bug_id); $c_user_id = db_prepare_int($p_user_id); if ($c_user_id != NO_USER && !access_has_bug_level(config_get('handle_bug_threshold'), $p_bug_id, $p_user_id)) { trigger_error(ERROR_USER_DOES_NOT_HAVE_REQ_ACCESS); } # extract current information into history variables $h_status = bug_get_field($p_bug_id, 'status'); $h_handler_id = bug_get_field($p_bug_id, 'handler_id'); if (ON == config_get('auto_set_status_to_assigned') && NO_USER != $p_user_id) { $t_ass_val = config_get('bug_assigned_status'); } else { $t_ass_val = $h_status; } $t_bug_table = config_get('mantis_bug_table'); if ($t_ass_val != $h_status || $p_user_id != $h_handler_id) { # get user id $query = "UPDATE {$t_bug_table}\n\t\t\t\t\t SET handler_id='{$c_user_id}', status='{$t_ass_val}'\n\t\t\t\t\t WHERE id='{$c_bug_id}'"; db_query($query); # log changes history_log_event_direct($c_bug_id, 'status', $h_status, $t_ass_val); history_log_event_direct($c_bug_id, 'handler_id', $h_handler_id, $p_user_id); # Add bugnote if supplied ignore false return bugnote_add($p_bug_id, $p_bugnote_text, 0, $p_bugnote_private, 0, '', NULL, FALSE); # updated the last_updated date bug_update_date($p_bug_id); bug_clear_cache($p_bug_id); # send assigned to email email_assign($p_bug_id); } return true; }
function save_bug($p_project_id, $p_user_id) { require 'ProfileAcraExt.php'; $t_project_id = $p_project_id; global $g_cache_current_user_id; $g_cache_current_user_id = $p_user_id; $t_bug_data = new BugData(); $t_bug_data->project_id = $t_project_id; $t_bug_data->reporter_id = $p_user_id; $t_bug_data->build = gpc_get_string('APP_VERSION_CODE', ''); $t_bug_data->platform = "Android"; $t_bug_data->os = gpc_get_string('ANDROID_VERSION', ''); //gpc_get_string( 'os', '' ); $t_os_build = gpc_get_string('BUILD', ''); if (preg_match('/DISPLAY\\s*=\\s*(.*)/', $t_os_build, $t_match)) { var_dump($t_match); $t_os_build = $t_match[1]; } else { $t_os_build = gpc_get_string('ANDROID_VERSION', ''); } $t_bug_data->os_build = $t_os_build; //gpc_get_string( 'os_build', '' ); $t_bug_data->version = gpc_get_string('APP_VERSION_NAME', ''); $t_bug_data->profile_id = profile_create_unique(ALL_USERS, $t_bug_data->platform, $t_bug_data->os, $t_bug_data->os_build, ""); $t_bug_data->handler_id = gpc_get_int('handler_id', 0); $t_bug_data->view_state = gpc_get_int('view_state', config_get('default_bug_view_status', 'VS_PRIVATE', 'acra_reporter')); $t_bug_data->category_id = $this->get_category_id($p_project_id); //gpc_get_int( 'category_id', 0 ); $t_bug_data->reproducibility = 10; //gpc_get_int( 'reproducibility', config_get( 'default_bug_reproducibility' ) ); $t_bug_data->severity = CRASH; //gpc_get_int( 'severity', config_get( 'default_bug_severity' ) ); $t_bug_data->priority = HIGH; //gpc_get_int( 'priority', config_get( 'default_bug_priority' ) ); $t_bug_data->projection = gpc_get_int('projection', config_get('default_bug_projection')); $t_bug_data->eta = gpc_get_int('eta', config_get('default_bug_eta')); $t_bug_data->resolution = OPEN; //gpc_get_string('resolution', config_get( 'default_bug_resolution' ) ); $t_bug_data->status = NEW_; //gpc_get_string( 'status', config_get( 'bug_submit_status' ) ); $t_bug_data->description = gpc_get_string('STACK_TRACE'); //gpc_get_string( 'description' ); $t_bug_data->summary = get_bug_summary_by_version(gpc_get_string('APP_VERSION_NAME', ''), $t_bug_data->description, $t_project_id); $t_bug_data->steps_to_reproduce = gpc_get_string('LOGCAT', ""); $t_bug_data->additional_information = gpc_get_string('CRASH_CONFIGURATION', ""); $t_bug_data->due_date = gpc_get_string('USER_CRASH_DATE', ''); if (is_blank($t_bug_data->due_date)) { $t_bug_data->due_date = date_get_null(); } $f_files = gpc_get_file('ufile', null); /** @todo (thraxisp) Note that this always returns a structure */ $f_report_stay = gpc_get_bool('report_stay', false); $f_copy_notes_from_parent = gpc_get_bool('copy_notes_from_parent', false); helper_call_custom_function('issue_create_validate', array($t_bug_data)); # Validate the custom fields before adding the bug. $t_related_custom_field_ids = custom_field_get_linked_ids($t_bug_data->project_id); foreach ($t_related_custom_field_ids as $t_id) { $t_def = custom_field_get_definition($t_id); # Produce an error if the field is required but wasn't posted if (!gpc_isset_custom_field($t_id, $t_def['type']) && $t_def['require_report']) { error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name'))); trigger_error(ERROR_EMPTY_FIELD, ERROR); } if (!custom_field_validate($t_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], NULL))) { error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name'))); trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR); } } # Allow plugins to pre-process bug data $t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data); # Ensure that resolved bugs have a handler if ($t_bug_data->handler_id == NO_USER && $t_bug_data->status >= config_get('bug_resolved_status_threshold')) { $t_bug_data->handler_id = $this->get_user_id(); } # Create the bug $t_bug_id = $t_bug_data->create(); # Mark the added issue as visited so that it appears on the last visited list. last_visited_issue($t_bug_id); # Handle the file upload if ($f_files != null) { $t_files = helper_array_transpose($f_files); if ($t_files != null) { foreach ($t_files as $t_file) { if (!empty($t_file['name'])) { file_add($t_bug_id, $t_file, 'bug'); } } } } # Handle custom field submission foreach ($t_related_custom_field_ids as $t_id) { # Do not set custom field value if user has no write access if (!custom_field_has_write_access($t_id, $t_bug_id)) { continue; } $t_def = custom_field_get_definition($t_id); if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']), false)) { error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name'))); trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR); } } $f_master_bug_id = gpc_get_int('m_id', 0); $f_rel_type = gpc_get_int('rel_type', -1); if ($f_master_bug_id > 0) { # it's a child generation... let's create the relationship and add some lines in the history # update master bug last updated bug_update_date($f_master_bug_id); # Add log line to record the cloning action history_log_event_special($t_bug_id, BUG_CREATED_FROM, '', $f_master_bug_id); history_log_event_special($f_master_bug_id, BUG_CLONED_TO, '', $t_bug_id); if ($f_rel_type >= 0) { # Add the relationship relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type); # Add log line to the history (both issues) history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id); history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id); # update relationship target bug last updated bug_update_date($t_bug_id); # Send the email notification email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type)); } # copy notes from parent if ($f_copy_notes_from_parent) { $t_parent_bugnotes = bugnote_get_all_bugnotes($f_master_bug_id); foreach ($t_parent_bugnotes as $t_parent_bugnote) { $t_private = $t_parent_bugnote->view_state == VS_PRIVATE; bugnote_add($t_bug_id, $t_parent_bugnote->note, $t_parent_bugnote->time_tracking, $t_private, $t_parent_bugnote->note_type, $t_parent_bugnote->note_attr, $t_parent_bugnote->reporter_id, FALSE, FALSE); } } } helper_call_custom_function('issue_create_notify', array($t_bug_id)); # Allow plugins to post-process bug data with the new bug ID event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id)); email_new_bug($t_bug_id); // log status and resolution changes if they differ from the default if ($t_bug_data->status != config_get('bug_submit_status')) { history_log_event($t_bug_id, 'status', config_get('bug_submit_status')); } if ($t_bug_data->resolution != config_get('default_bug_resolution')) { history_log_event($t_bug_id, 'resolution', config_get('default_bug_resolution')); } return $t_bug_id; }
/** * Add a file to the system using the configured storage method * * @param integer $p_bug_id the bug id (should be 0 when adding project doc) * @param array $p_file the uploaded file info, as retrieved from gpc_get_file() * @param string $p_table 'bug' or 'project' depending on attachment type * @param string $p_title file title * @param string $p_desc file description * @param int $p_user_id user id (defaults to current user) * @param int $p_date_added date added * @param bool $p_skip_bug_update skip bug last modification update (useful when importing bug attachments) */ function file_add($p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false) { file_ensure_uploaded($p_file); $t_file_name = $p_file['name']; $t_tmp_file = $p_file['tmp_name']; if (!file_type_check($t_file_name)) { trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR); } if (!file_is_name_unique($t_file_name, $p_bug_id)) { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } $t_file_size = filesize($t_tmp_file); if (0 == $t_file_size) { trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR); } $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size')); if ($t_file_size > $t_max_file_size) { trigger_error(ERROR_FILE_TOO_BIG, ERROR); } if ('bug' == $p_table) { $t_project_id = bug_get_field($p_bug_id, 'project_id'); $t_id = (int) $p_bug_id; $t_bug_id = bug_format_id($p_bug_id); } else { $t_project_id = helper_get_current_project(); $t_id = $t_project_id; $t_bug_id = 0; } if ($p_user_id === null) { $p_user_id = auth_get_current_user_id(); } if ($p_date_added <= 0) { $p_date_added = db_now(); } if ($t_project_id == ALL_PROJECTS) { $t_file_path = config_get('absolute_path_default_upload_folder'); } else { $t_file_path = project_get_field($t_project_id, 'file_path'); if (is_blank($t_file_path)) { $t_file_path = config_get('absolute_path_default_upload_folder'); } } $t_file_hash = 'bug' == $p_table ? $t_bug_id : config_get('document_files_prefix') . '-' . $t_project_id; $t_unique_name = file_generate_unique_name($t_file_hash . '-' . $t_file_name, $t_file_path); $t_disk_file_name = $t_file_path . $t_unique_name; $t_method = config_get('file_upload_method'); switch ($t_method) { case FTP: case DISK: file_ensure_valid_upload_path($t_file_path); if (!file_exists($t_disk_file_name)) { if (FTP == $t_method) { $conn_id = file_ftp_connect(); file_ftp_put($conn_id, $t_disk_file_name, $t_tmp_file); file_ftp_disconnect($conn_id); } if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) { trigger_error(ERROR_FILE_MOVE_FAILED, ERROR); } chmod($t_disk_file_name, config_get('attachments_file_permissions')); $c_content = ''; } else { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } break; case DATABASE: $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size)); break; default: trigger_error(ERROR_GENERIC, ERROR); } $t_file_table = db_get_table($p_table . '_file'); $t_id_col = $p_table . "_id"; $t_query_fields = "\n\t\t{$t_id_col}, title, description, diskfile, filename, folder,\n\t\tfilesize, file_type, date_added, user_id"; $t_param = array($t_id, $p_title, $p_desc, $t_unique_name, $t_file_name, $t_file_path, $t_file_size, $p_file['type'], $p_date_added, (int) $p_user_id); # oci8 stores contents in a BLOB, which is updated separately if (!db_is_oracle()) { $t_query_fields .= ", content"; $t_param[] = $c_content; } $t_query_param = db_param(); for ($i = 1; $i < count($t_param); $i++) { $t_query_param .= ", " . db_param(); } $t_query = "INSERT INTO {$t_file_table} ( {$t_query_fields} )\n\tVALUES\n\t\t( {$t_query_param} )"; db_query_bound($t_query, $t_param); if (db_is_oracle()) { db_update_blob($t_file_table, 'content', $c_content, "diskfile='{$t_unique_name}'"); } if ('bug' == $p_table) { # update the last_updated date if (!$p_skip_bug_update) { $result = bug_update_date($p_bug_id); } # log file added to bug history history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name); } }
helper_call_custom_function('issue_create_notify', array($t_bug_id)); # Allow plugins to post-process bug data with the new bug ID event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id)); email_new_bug($t_bug_id); // log status and resolution changes if they differ from the default if ($t_bug_data->status != config_get('bug_submit_status')) { history_log_event($t_bug_id, 'status', config_get('bug_submit_status')); } if ($t_bug_data->resolution != config_get('default_bug_resolution')) { history_log_event($t_bug_id, 'resolution', config_get('default_bug_resolution')); } if (!$f_report_stay) { if ($t_bug_data->status < config_get('bug_readonly_status_threshold')) { html_meta_redirect('view.php?id=' . $t_bug_id); } else { bug_update_date($t_bug_id, $t_bug_data->date_submitted); $t_category_table = db_get_table('mantis_category_table'); $result = db_query_bound("SELECT `name` FROM " . $t_category_table . " WHERE `id` = " . db_param(), array($t_bug_data->category_id)); $row = db_fetch_array($result); html_meta_redirect('browse.php?reset=true&category=' . $row['name']); } } ?> <br /> <div align="center"> <?php echo lang_get('operation_successful') . '<br />'; print_bracket_link(string_get_bug_view_url($t_bug_id), sprintf(lang_get('view_submitted_bug_link'), $t_bug_id)); print_bracket_link('view_all_bug_page.php', lang_get('view_bugs_link')); if ($f_report_stay) { ?>
/** * Update bug to reflect sponsorship change * This is to be called after adding/updating/deleting sponsorships * @param int $p_bug_id * @return null */ function sponsorship_update_bug($p_bug_id) { $t_total_amount = sponsorship_get_amount(sponsorship_get_all_ids($p_bug_id)); bug_set_field($p_bug_id, 'sponsorship_total', $t_total_amount); bug_update_date($p_bug_id); }
function copyUserStory($us_id, $status, $sprintname) { global $agilemantis_pb; global $agilemantis_tasks; global $agilemantis_sprint; $new_bug_id = bug_copy($us_id, null, true, true, false, true, true, true); $agilemantis_pb->doUserStoryToSprint($new_bug_id, $sprintname); relationship_add($new_bug_id, $us_id, 0); $task = $agilemantis_sprint->getSprintTasks($us_id); $agilemantis_sprint->sprint_id = $sprintname; $sprintinfo = $agilemantis_sprint->getSprintById(); $old_userstory = $agilemantis_pb->checkForUserStory($us_id); $agilemantis_pb->addStoryPoints($new_bug_id, $old_userstory['storypoints']); $agilemantis_pb->addBusinessValue($new_bug_id, $old_userstory['businessValue']); $agilemantis_pb->addRankingOrder($new_bug_id, $old_userstory['rankingorder']); $agilemantis_pb->addTechnical($new_bug_id, $old_userstory['technical']); $agilemantis_pb->addPresentable($new_bug_id, $old_userstory['presentable']); $agilemantis_pb->AddInReleaseDocu($new_bug_id, $old_userstory['inReleaseDocu']); $agilemantis_pb->AddPlannedWork($new_bug_id, $old_userstory['plannedWork']); history_delete($new_bug_id); $bugnote_text_new = plugin_lang_get('divide_userstories_from') . $agilemantis_pb->getUserName(auth_get_current_user_id()) . plugin_lang_get('divide_userstories_of') . ' #' . $us_id . plugin_lang_get('divide_userstories_splitted'); $bugnote_text_old = plugin_lang_get('divide_userstories_from') . $agilemantis_pb->getUserName(auth_get_current_user_id()) . plugin_lang_get('divide_userstories_from') . ', #' . $new_bug_id . plugin_lang_get('divide_userstories_splitted'); $agilemantis_sprint->sprint_id = $old_userstory['sprint']; $sprintinfo = $agilemantis_sprint->getSprintById(); $userstory_performed = false; $wmu = 0; $spmu = 0; if (!empty($task)) { foreach ($task as $key => $value) { if ($value['performed_capacity'] > 0 || $value['status'] >= 4) { $userstory_performed = true; } if ($value['status'] < 4) { $agilemantis_tasks->user_id = auth_get_current_user_id(); $agilemantis_tasks->name = $value['name']; $agilemantis_tasks->us_id = $value['us_id']; $agilemantis_tasks->description = $value['description']; $agilemantis_tasks->developer = $value['developer_id']; $agilemantis_tasks->status = 5; $agilemantis_tasks->capacity = $value['performed_capacity']; $agilemantis_tasks->planned_capacity = $value['planned_capacity']; $agilemantis_tasks->rest_capacity = 0; $agilemantis_tasks->id = $value['id']; $agilemantis_tasks->unit = $value['unit']; $agilemantis_tasks->editTask(); $agilemantis_tasks->saveDailyPerformance(0); $agilemantis_tasks->id = 0; $agilemantis_tasks->name = $value['name']; $agilemantis_tasks->us_id = $new_bug_id; $agilemantis_tasks->description = $value['description']; $agilemantis_tasks->status = $value['status']; if ($value['status'] == 3) { $agilemantis_tasks->status = 2; } $agilemantis_tasks->developer = $value['developer_id']; if ($agilemantis_sprint->getUnitId(plugin_config_get('gadiv_task_unit_mode')) != $sprintinfo['unit_planned_task']) { $agilemantis_tasks->planned_capacity = 0; $agilemantis_tasks->rest_capacity = 0; } else { $agilemantis_tasks->planned_capacity = $value['rest_capacity']; $agilemantis_tasks->rest_capacity = $value['rest_capacity']; } $agilemantis_tasks->addFinishedNote($value['us_id'], $value['id'], auth_get_current_user_id()); $agilemantis_tasks->editTask(); $agilemantis_tasks->id = 0; $agilemantis_tasks->updateTaskLog($value['id'], auth_get_current_user_id(), "closed"); $agilemantis_tasks->setTaskStatus($value['id'], 5); $wmu += $value['rest_capacity']; $new_storypoints += $value['performed_capacity']; } } } if ($sprintinfo['unit_planned_task'] == 3) { $spmu = $wmu; } else { $spmu = 0; } # collect all user story splitting information and write these into database $agilemantis_sprint->setSplittingInformation($us_id, $new_bug_id, $wmu, $spmu); if ($userstory_performed === true) { if ($sprintinfo['unit_planned_task'] < 3) { $agilemantis_pb->addStoryPoints($new_bug_id, ''); } elseif ($sprintinfo['unit_planned_task'] == 3) { $agilemantis_pb->addStoryPoints($new_bug_id, $old_userstory['storypoints'] - $new_storypoints); } $bugnote_text_new .= plugin_lang_get('divide_userstories_old_estimation') . " #" . $us_id . plugin_lang_get('divide_userstories_with') . $old_userstory['storypoints'] . " SP."; bugnote_add($new_bug_id, $bugnote_text_new); } # add bug note bugnote_add($us_id, $bugnote_text_old); $agilemantis_tasks->setUserStoryStatus($us_id, $status, auth_get_current_user_id()); $agilemantis_tasks->closeUserStory($us_id, $status, auth_get_current_user_id()); bug_update_date($us_id); }
/** * Update a bug from the given data structure * If the third parameter is true, also update the longer strings table * @param bool p_update_extended * @param bool p_bypass_email Default false, set to true to avoid generating emails (if sending elsewhere) * @return bool (always true) * @access public */ function update($p_update_extended = false, $p_bypass_mail = false) { self::validate($p_update_extended); $c_bug_id = $this->id; if (is_blank($this->due_date)) { $this->due_date = date_get_null(); } $t_old_data = bug_get($this->id, true); $t_bug_table = db_get_table('mantis_bug_table'); # Update all fields # Ignore date_submitted and last_updated since they are pulled out # as unix timestamps which could confuse the history log and they # shouldn't get updated like this anyway. If you really need to change # them use bug_set_field() $query = "UPDATE {$t_bug_table}\n\t\t\t\t\tSET project_id=" . db_param() . ', reporter_id=' . db_param() . ",\n\t\t\t\t\t\thandler_id=" . db_param() . ', duplicate_id=' . db_param() . ",\n\t\t\t\t\t\tpriority=" . db_param() . ', severity=' . db_param() . ",\n\t\t\t\t\t\treproducibility=" . db_param() . ', status=' . db_param() . ",\n\t\t\t\t\t\tresolution=" . db_param() . ', projection=' . db_param() . ",\n\t\t\t\t\t\tcategory_id=" . db_param() . ', eta=' . db_param() . ",\n\t\t\t\t\t\tos=" . db_param() . ', os_build=' . db_param() . ",\n\t\t\t\t\t\tplatform=" . db_param() . ', version=' . db_param() . ",\n\t\t\t\t\t\tbuild=" . db_param() . ', fixed_in_version=' . db_param() . ','; $t_fields = array($this->project_id, $this->reporter_id, $this->handler_id, $this->duplicate_id, $this->priority, $this->severity, $this->reproducibility, $this->status, $this->resolution, $this->projection, $this->category_id, $this->eta, $this->os, $this->os_build, $this->platform, $this->version, $this->build, $this->fixed_in_version); $t_roadmap_updated = false; if (access_has_project_level(config_get('roadmap_update_threshold'))) { $query .= "\n\t\t\t\t\t\ttarget_version=" . db_param() . ","; $t_fields[] = $this->target_version; $t_roadmap_updated = true; } $query .= "\n\t\t\t\t\t\tview_state=" . db_param() . ",\n\t\t\t\t\t\tsummary=" . db_param() . ",\n\t\t\t\t\t\tsponsorship_total=" . db_param() . ",\n\t\t\t\t\t\tsticky=" . db_param() . ",\n\t\t\t\t\t\tdue_date=" . db_param() . "\n\t\t\t\t\tWHERE id=" . db_param(); $t_fields[] = $this->view_state; $t_fields[] = $this->summary; $t_fields[] = $this->sponsorship_total; $t_fields[] = (bool) $this->sticky; $t_fields[] = $this->due_date; $t_fields[] = $this->id; db_query_bound($query, $t_fields); bug_clear_cache($this->id); # log changes history_log_event_direct($c_bug_id, 'project_id', $t_old_data->project_id, $this->project_id); history_log_event_direct($c_bug_id, 'reporter_id', $t_old_data->reporter_id, $this->reporter_id); history_log_event_direct($c_bug_id, 'handler_id', $t_old_data->handler_id, $this->handler_id); history_log_event_direct($c_bug_id, 'priority', $t_old_data->priority, $this->priority); history_log_event_direct($c_bug_id, 'severity', $t_old_data->severity, $this->severity); history_log_event_direct($c_bug_id, 'reproducibility', $t_old_data->reproducibility, $this->reproducibility); history_log_event_direct($c_bug_id, 'status', $t_old_data->status, $this->status); history_log_event_direct($c_bug_id, 'resolution', $t_old_data->resolution, $this->resolution); history_log_event_direct($c_bug_id, 'projection', $t_old_data->projection, $this->projection); history_log_event_direct($c_bug_id, 'category', category_full_name($t_old_data->category_id, false), category_full_name($this->category_id, false)); history_log_event_direct($c_bug_id, 'eta', $t_old_data->eta, $this->eta); history_log_event_direct($c_bug_id, 'os', $t_old_data->os, $this->os); history_log_event_direct($c_bug_id, 'os_build', $t_old_data->os_build, $this->os_build); history_log_event_direct($c_bug_id, 'platform', $t_old_data->platform, $this->platform); history_log_event_direct($c_bug_id, 'version', $t_old_data->version, $this->version); history_log_event_direct($c_bug_id, 'build', $t_old_data->build, $this->build); history_log_event_direct($c_bug_id, 'fixed_in_version', $t_old_data->fixed_in_version, $this->fixed_in_version); if ($t_roadmap_updated) { history_log_event_direct($c_bug_id, 'target_version', $t_old_data->target_version, $this->target_version); } history_log_event_direct($c_bug_id, 'view_state', $t_old_data->view_state, $this->view_state); history_log_event_direct($c_bug_id, 'summary', $t_old_data->summary, $this->summary); history_log_event_direct($c_bug_id, 'sponsorship_total', $t_old_data->sponsorship_total, $this->sponsorship_total); history_log_event_direct($c_bug_id, 'sticky', $t_old_data->sticky, $this->sticky); history_log_event_direct($c_bug_id, 'due_date', $t_old_data->due_date != date_get_null() ? $t_old_data->due_date : null, $this->due_date != date_get_null() ? $this->due_date : null); # Update extended info if requested if ($p_update_extended) { $t_bug_text_table = db_get_table('mantis_bug_text_table'); $t_bug_text_id = bug_get_field($c_bug_id, 'bug_text_id'); $query = "UPDATE {$t_bug_text_table}\n\t\t\t\t\t\t\tSET description=" . db_param() . ",\n\t\t\t\t\t\t\t\tsteps_to_reproduce=" . db_param() . ",\n\t\t\t\t\t\t\t\tadditional_information=" . db_param() . "\n\t\t\t\t\t\t\tWHERE id=" . db_param(); db_query_bound($query, array($this->description, $this->steps_to_reproduce, $this->additional_information, $t_bug_text_id)); bug_text_clear_cache($c_bug_id); $t_current_user = auth_get_current_user_id(); if ($t_old_data->description != $this->description) { if (bug_revision_count($c_bug_id, REV_DESCRIPTION) < 1) { $t_revision_id = bug_revision_add($c_bug_id, $t_old_data->reporter_id, REV_DESCRIPTION, $t_old_data->description, 0, $t_old_data->date_submitted); } $t_revision_id = bug_revision_add($c_bug_id, $t_current_user, REV_DESCRIPTION, $this->description); history_log_event_special($c_bug_id, DESCRIPTION_UPDATED, $t_revision_id); } if ($t_old_data->steps_to_reproduce != $this->steps_to_reproduce) { if (bug_revision_count($c_bug_id, REV_STEPS_TO_REPRODUCE) < 1) { $t_revision_id = bug_revision_add($c_bug_id, $t_old_data->reporter_id, REV_STEPS_TO_REPRODUCE, $t_old_data->steps_to_reproduce, 0, $t_old_data->date_submitted); } $t_revision_id = bug_revision_add($c_bug_id, $t_current_user, REV_STEPS_TO_REPRODUCE, $this->steps_to_reproduce); history_log_event_special($c_bug_id, STEP_TO_REPRODUCE_UPDATED, $t_revision_id); } if ($t_old_data->additional_information != $this->additional_information) { if (bug_revision_count($c_bug_id, REV_ADDITIONAL_INFO) < 1) { $t_revision_id = bug_revision_add($c_bug_id, $t_old_data->reporter_id, REV_ADDITIONAL_INFO, $t_old_data->additional_information, 0, $t_old_data->date_submitted); } $t_revision_id = bug_revision_add($c_bug_id, $t_current_user, REV_ADDITIONAL_INFO, $this->additional_information); history_log_event_special($c_bug_id, ADDITIONAL_INFO_UPDATED, $t_revision_id); } } # Update the last update date bug_update_date($c_bug_id); # allow bypass if user is sending mail separately if (false == $p_bypass_mail) { # bug assigned if ($t_old_data->handler_id != $this->handler_id) { email_generic($c_bug_id, 'owner', 'email_notification_title_for_action_bug_assigned'); return true; } # status changed if ($t_old_data->status != $this->status) { $t_status = MantisEnum::getLabel(config_get('status_enum_string'), $this->status); $t_status = str_replace(' ', '_', $t_status); email_generic($c_bug_id, $t_status, 'email_notification_title_for_status_bug_' . $t_status); return true; } # @todo handle priority change if it requires special handling # generic update notification email_generic($c_bug_id, 'updated', 'email_notification_title_for_action_bug_updated'); } return true; }
function bugnote_add($p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_private = false, $p_type = 0, $p_attr = '', $p_user_id = null, $p_send_email = TRUE) { $c_bug_id = db_prepare_int($p_bug_id); $c_bugnote_text = db_prepare_string($p_bugnote_text); $c_time_tracking = db_prepare_time($p_time_tracking); $c_private = db_prepare_bool($p_private); $c_type = db_prepare_int($p_type); $c_attr = db_prepare_string($p_attr); $t_bugnote_text_table = config_get('mantis_bugnote_text_table'); $t_bugnote_table = config_get('mantis_bugnote_table'); $t_time_tracking_enabled = config_get('time_tracking_enabled'); $t_time_tracking_without_note = config_get('time_tracking_without_note'); if (ON == $t_time_tracking_enabled && $c_time_tracking > 0) { if (is_blank($p_bugnote_text) && OFF == $t_time_tracking_without_note) { error_parameters(lang_get('bugnote')); trigger_error(ERROR_EMPTY_FIELD, ERROR); } $c_type = TIME_TRACKING; } else { if (is_blank($p_bugnote_text)) { return false; } } # insert bugnote text $query = "INSERT INTO {$t_bugnote_text_table}\r\n\t\t \t\t( note )\r\n\t\t \t VALUES\r\n\t\t \t\t( '{$c_bugnote_text}' )"; db_query($query); # retrieve bugnote text id number $t_bugnote_text_id = db_insert_id($t_bugnote_text_table); # get user information if ($p_user_id === null) { $c_user_id = auth_get_current_user_id(); } else { $c_user_id = db_prepare_int($p_user_id); } # Check for private bugnotes. # @@@ VB: Should we allow users to report private bugnotes, and possibly see only their own private ones if ($p_private && access_has_bug_level(config_get('private_bugnote_threshold'), $p_bug_id, $c_user_id)) { $t_view_state = VS_PRIVATE; } else { $t_view_state = VS_PUBLIC; } # insert bugnote info $query = "INSERT INTO {$t_bugnote_table}\r\n\t\t\t\t\t(bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified, note_type, note_attr, time_tracking )\r\n\t\t \t VALUES\r\n\t\t\t\t\t('{$c_bug_id}', '{$c_user_id}','{$t_bugnote_text_id}', '{$t_view_state}', " . db_now() . "," . db_now() . ", '{$c_type}', '{$c_attr}', '{$c_time_tracking}' )"; db_query($query); # get bugnote id $t_bugnote_id = db_insert_id($t_bugnote_table); # update bug last updated bug_update_date($p_bug_id); # log new bug history_log_event_special($p_bug_id, BUGNOTE_ADDED, bugnote_format_id($t_bugnote_id)); # only send email if the text is not blank, otherwise, it is just recording of time without a comment. if ($p_send_email && !is_blank($p_bugnote_text)) { email_bugnote_add($p_bug_id); } return $t_bugnote_id; }
/** * Add a file to the system using the configured storage method * * @param integer $p_bug_id the bug id * @param array $p_file the uploaded file info, as retrieved from gpc_get_file() */ function file_add($p_bug_id, $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null) { file_ensure_uploaded($p_file); $t_file_name = $p_file['name']; $t_tmp_file = $p_file['tmp_name']; if (!file_type_check($t_file_name)) { trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR); } if (!file_is_name_unique($t_file_name, $p_bug_id)) { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } if ('bug' == $p_table) { $t_project_id = bug_get_field($p_bug_id, 'project_id'); $t_bug_id = bug_format_id($p_bug_id); } else { $t_project_id = helper_get_current_project(); $t_bug_id = 0; } if ($p_user_id === null) { $c_user_id = auth_get_current_user_id(); } else { $c_user_id = (int) $p_user_id; } # prepare variables for insertion $c_bug_id = db_prepare_int($p_bug_id); $c_project_id = db_prepare_int($t_project_id); $c_file_type = db_prepare_string($p_file['type']); $c_title = db_prepare_string($p_title); $c_desc = db_prepare_string($p_desc); if ($t_project_id == ALL_PROJECTS) { $t_file_path = config_get('absolute_path_default_upload_folder'); } else { $t_file_path = project_get_field($t_project_id, 'file_path'); if (is_blank($t_file_path)) { $t_file_path = config_get('absolute_path_default_upload_folder'); } } $c_file_path = db_prepare_string($t_file_path); $c_new_file_name = db_prepare_string($t_file_name); $t_file_hash = 'bug' == $p_table ? $t_bug_id : config_get('document_files_prefix') . '-' . $t_project_id; $t_unique_name = file_generate_unique_name($t_file_hash . '-' . $t_file_name, $t_file_path); $t_disk_file_name = $t_file_path . $t_unique_name; $c_unique_name = db_prepare_string($t_unique_name); $t_file_size = filesize($t_tmp_file); if (0 == $t_file_size) { trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR); } $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size')); if ($t_file_size > $t_max_file_size) { trigger_error(ERROR_FILE_TOO_BIG, ERROR); } $c_file_size = db_prepare_int($t_file_size); $t_method = config_get('file_upload_method'); switch ($t_method) { case FTP: case DISK: file_ensure_valid_upload_path($t_file_path); if (!file_exists($t_disk_file_name)) { if (FTP == $t_method) { $conn_id = file_ftp_connect(); file_ftp_put($conn_id, $t_disk_file_name, $t_tmp_file); file_ftp_disconnect($conn_id); } if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) { trigger_error(ERROR_FILE_MOVE_FAILED, ERROR); } chmod($t_disk_file_name, config_get('attachments_file_permissions')); $c_content = "''"; } else { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } break; case DATABASE: $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size)); break; default: trigger_error(ERROR_GENERIC, ERROR); } $t_file_table = db_get_table('mantis_' . $p_table . '_file_table'); $c_id = 'bug' == $p_table ? $c_bug_id : $c_project_id; $query = "INSERT INTO {$t_file_table}\n\t\t\t\t\t\t(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id)\n\t\t\t\t\t VALUES\n\t\t\t\t\t\t({$c_id}, '{$c_title}', '{$c_desc}', '{$c_unique_name}', '{$c_new_file_name}', '{$c_file_path}', {$c_file_size}, '{$c_file_type}', '" . db_now() . "', {$c_content}, {$c_user_id})"; db_query($query); if ('bug' == $p_table) { # updated the last_updated date $result = bug_update_date($p_bug_id); # log new bug history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name); } }
# there is already a relationship between them -> we have to update it and not to add a new one helper_ensure_confirmed( lang_get( 'replace_relationship_sure_msg' ), lang_get( 'replace_relationship_button' ) ); # Update the relationship relationship_update( $t_old_id_relationship, $f_src_bug_id, $f_dest_bug_id, $f_rel_type ); # Add log line to the history (both bugs) history_log_event_special( $f_src_bug_id, BUG_REPLACE_RELATIONSHIP, $f_rel_type, $f_dest_bug_id ); history_log_event_special( $f_dest_bug_id, BUG_REPLACE_RELATIONSHIP, relationship_get_complementary_type( $f_rel_type ), $f_src_bug_id ); } else { # Add the new relationship relationship_add( $f_src_bug_id, $f_dest_bug_id, $f_rel_type ); # Add log line to the history (both bugs) history_log_event_special( $f_src_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_dest_bug_id ); history_log_event_special( $f_dest_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type( $f_rel_type ), $f_src_bug_id ); } # update bug last updated for both bugs bug_update_date( $f_src_bug_id ); bug_update_date( $f_dest_bug_id ); # send email notification to the users addressed by both the bugs email_relationship_added( $f_src_bug_id, $f_dest_bug_id, $f_rel_type ); email_relationship_added( $f_dest_bug_id, $f_src_bug_id, relationship_get_complementary_type( $f_rel_type ) ); } form_security_purge( 'bug_relationship_add' ); print_header_redirect_view( $f_src_bug_id );
/** * Add a file to the system using the configured storage method * * @param integer $p_bug_id The bug id (should be 0 when adding project doc). * @param array $p_file The uploaded file info, as retrieved from gpc_get_file(). * @param string $p_table Either 'bug' or 'project' depending on attachment type. * @param string $p_title File title. * @param string $p_desc File description. * @param integer $p_user_id User id (defaults to current user). * @param integer $p_date_added Date added. * @param boolean $p_skip_bug_update Skip bug last modification update (useful when importing bug attachments). * @return void */ function file_add($p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false) { file_ensure_uploaded($p_file); $t_file_name = $p_file['name']; $t_tmp_file = $p_file['tmp_name']; if (!file_type_check($t_file_name)) { trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR); } if (!file_is_name_unique($t_file_name, $p_bug_id)) { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } $t_file_size = filesize($t_tmp_file); if (0 == $t_file_size) { trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR); } $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size')); if ($t_file_size > $t_max_file_size) { trigger_error(ERROR_FILE_TOO_BIG, ERROR); } if ('bug' == $p_table) { $t_project_id = bug_get_field($p_bug_id, 'project_id'); $t_id = (int) $p_bug_id; $t_bug_id = bug_format_id($p_bug_id); } else { $t_project_id = helper_get_current_project(); $t_id = $t_project_id; $t_bug_id = 0; } if ($p_user_id === null) { $p_user_id = auth_get_current_user_id(); } if ($p_date_added <= 0) { $p_date_added = db_now(); } if ($t_project_id == ALL_PROJECTS) { $t_file_path = config_get('absolute_path_default_upload_folder'); } else { $t_file_path = project_get_field($t_project_id, 'file_path'); if (is_blank($t_file_path)) { $t_file_path = config_get('absolute_path_default_upload_folder'); } } $t_unique_name = file_generate_unique_name($t_file_path); $t_method = config_get('file_upload_method'); switch ($t_method) { case DISK: file_ensure_valid_upload_path($t_file_path); $t_disk_file_name = $t_file_path . $t_unique_name; if (!file_exists($t_disk_file_name)) { if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) { trigger_error(ERROR_FILE_MOVE_FAILED, ERROR); } chmod($t_disk_file_name, config_get('attachments_file_permissions')); $c_content = ''; } else { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } break; case DATABASE: $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size)); $t_file_path = ''; break; default: trigger_error(ERROR_GENERIC, ERROR); } $t_file_table = db_get_table($p_table . '_file'); $t_id_col = $p_table . '_id'; $t_query = 'INSERT INTO ' . $t_file_table . ' ( ' . $t_id_col . ', title, description, diskfile, filename, folder, filesize, file_type, date_added, user_id ) VALUES ( ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ' )'; db_query($t_query, array($t_id, $p_title, $p_desc, $t_unique_name, $t_file_name, $t_file_path, $t_file_size, $p_file['type'], $p_date_added, (int) $p_user_id)); $t_attachment_id = db_insert_id($t_file_table); if (db_is_oracle()) { db_update_blob($t_file_table, 'content', $c_content, 'diskfile=\'$t_unique_name\''); } else { $t_query = 'UPDATE ' . $t_file_table . ' SET content=' . db_param() . ' WHERE id = ' . db_param(); db_query($t_query, array($c_content, $t_attachment_id)); } if ('bug' == $p_table) { # update the last_updated date if (!$p_skip_bug_update) { bug_update_date($p_bug_id); } # log file added to bug history history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name); } }
/** * Add a bugnote to a bug * return the ID of the new bugnote * @param int $p_bug_id bug id * @param string $p_bugnote_text bugnote text * @param string $p_time_tracking hh:mm string * @param bool $p_private whether bugnote is private * @param int $p_type bugnote type * @param string $p_attr * @param int $p_user_id user id * @param bool $p_send_email generate email? * @param int $p_date_submitted date submitted (defaults to now()) * @param int $p_last_modified last modification date (defaults to now()) * @param bool $p_skip_bug_update skip bug last modification update (useful when importing bugs/bugnotes) * @return false|int false or indicating bugnote id added * @access public */ function bugnote_add($p_bug_id, $p_bugnote_text, $p_time_tracking = '0:00', $p_private = false, $p_type = 0, $p_attr = '', $p_user_id = null, $p_send_email = TRUE, $p_date_submitted = 0, $p_last_modified = 0, $p_skip_bug_update = FALSE) { $c_bug_id = db_prepare_int($p_bug_id); $c_time_tracking = helper_duration_to_minutes($p_time_tracking); $c_private = db_prepare_bool($p_private); $c_type = db_prepare_int($p_type); $c_date_submitted = $p_date_submitted <= 0 ? db_now() : db_prepare_int($p_date_submitted); $c_last_modified = $p_last_modified <= 0 ? db_now() : db_prepare_int($p_last_modified); $t_bugnote_text_table = db_get_table('bugnote_text'); $t_bugnote_table = db_get_table('bugnote'); $t_time_tracking_enabled = config_get('time_tracking_enabled'); $t_time_tracking_without_note = config_get('time_tracking_without_note'); if (ON == $t_time_tracking_enabled && $c_time_tracking > 0) { if (is_blank($p_bugnote_text) && OFF == $t_time_tracking_without_note) { error_parameters(lang_get('bugnote')); trigger_error(ERROR_EMPTY_FIELD, ERROR); } $c_type = TIME_TRACKING; } else { if (is_blank($p_bugnote_text)) { return false; } } $t_bugnote_text = $p_bugnote_text; # Event integration $t_bugnote_text = event_signal('EVENT_BUGNOTE_DATA', $t_bugnote_text, $c_bug_id); # insert bugnote text $query = 'INSERT INTO ' . $t_bugnote_text_table . ' ( note ) VALUES ( ' . db_param() . ' )'; db_query_bound($query, array($t_bugnote_text)); # retrieve bugnote text id number $t_bugnote_text_id = db_insert_id($t_bugnote_text_table); # get user information if ($p_user_id === null) { $c_user_id = auth_get_current_user_id(); } else { $c_user_id = db_prepare_int($p_user_id); } # Check for private bugnotes. if ($c_private && access_has_bug_level(config_get('set_view_status_threshold'), $p_bug_id, $c_user_id)) { $t_view_state = VS_PRIVATE; } else { $t_view_state = VS_PUBLIC; } # insert bugnote info $query = "INSERT INTO {$t_bugnote_table}\n\t\t\t\t(bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified, note_type, note_attr, time_tracking )\n\t\t\tVALUES\n\t\t\t\t(" . db_param() . ', ' . db_param() . ',' . db_param() . ', ' . db_param() . ', ' . db_param() . ',' . db_param() . ', ' . db_param() . ', ' . db_param() . ', ' . db_param() . ' )'; db_query_bound($query, array($c_bug_id, $c_user_id, $t_bugnote_text_id, $t_view_state, $c_date_submitted, $c_last_modified, $c_type, $p_attr, $c_time_tracking)); # get bugnote id $t_bugnote_id = db_insert_id($t_bugnote_table); # update bug last updated if (!$p_skip_bug_update) { bug_update_date($p_bug_id); } # log new bug history_log_event_special($p_bug_id, BUGNOTE_ADDED, bugnote_format_id($t_bugnote_id)); # Event integration event_signal('EVENT_BUGNOTE_ADD', array($p_bug_id, $t_bugnote_id)); # only send email if the text is not blank, otherwise, it is just recording of time without a comment. if (TRUE == $p_send_email && !is_blank($t_bugnote_text)) { email_bugnote_add($p_bug_id); } return $t_bugnote_id; }
/** * Add a file to the system using the configured storage method * * @param integer $p_bug_id The bug id (should be 0 when adding project doc). * @param array $p_file The uploaded file info, as retrieved from gpc_get_file(). * @param string $p_table Either 'bug' or 'project' depending on attachment type. * @param string $p_title File title. * @param string $p_desc File description. * @param integer $p_user_id User id (defaults to current user). * @param integer $p_date_added Date added. * @param boolean $p_skip_bug_update Skip bug last modification update (useful when importing bug attachments). * @return void */ function file_add($p_bug_id, array $p_file, $p_table = 'bug', $p_title = '', $p_desc = '', $p_user_id = null, $p_date_added = 0, $p_skip_bug_update = false) { file_ensure_uploaded($p_file); $t_file_name = $p_file['name']; $t_tmp_file = $p_file['tmp_name']; if (!file_type_check($t_file_name)) { trigger_error(ERROR_FILE_NOT_ALLOWED, ERROR); } $t_org_filename = $t_file_name; $t_suffix_id = 1; while (!file_is_name_unique($t_file_name, $p_bug_id)) { $t_suffix_id++; $t_dot_index = strripos($t_org_filename, '.'); if ($t_dot_index === false) { $t_file_name = $t_org_filename . '-' . $t_suffix_id; } else { $t_extension = substr($t_org_filename, $t_dot_index, strlen($t_org_filename) - $t_dot_index); $t_file_name = substr($t_org_filename, 0, $t_dot_index) . '-' . $t_suffix_id . $t_extension; } } antispam_check(); $t_file_size = filesize($t_tmp_file); if (0 == $t_file_size) { trigger_error(ERROR_FILE_NO_UPLOAD_FAILURE, ERROR); } $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size')); if ($t_file_size > $t_max_file_size) { trigger_error(ERROR_FILE_TOO_BIG, ERROR); } if ('bug' == $p_table) { $t_project_id = bug_get_field($p_bug_id, 'project_id'); $t_id = (int) $p_bug_id; } else { $t_project_id = helper_get_current_project(); $t_id = $t_project_id; } if ($p_user_id === null) { $p_user_id = auth_get_current_user_id(); } if ($p_date_added <= 0) { $p_date_added = db_now(); } if ($t_project_id == ALL_PROJECTS) { $t_file_path = config_get('absolute_path_default_upload_folder'); } else { $t_file_path = project_get_field($t_project_id, 'file_path'); if (is_blank($t_file_path)) { $t_file_path = config_get('absolute_path_default_upload_folder'); } } $t_unique_name = file_generate_unique_name($t_file_path); $t_method = config_get('file_upload_method'); switch ($t_method) { case DISK: file_ensure_valid_upload_path($t_file_path); $t_disk_file_name = $t_file_path . $t_unique_name; if (!file_exists($t_disk_file_name)) { if (!move_uploaded_file($t_tmp_file, $t_disk_file_name)) { trigger_error(ERROR_FILE_MOVE_FAILED, ERROR); } chmod($t_disk_file_name, config_get('attachments_file_permissions')); $c_content = ''; } else { trigger_error(ERROR_FILE_DUPLICATE, ERROR); } break; case DATABASE: $c_content = db_prepare_binary_string(fread(fopen($t_tmp_file, 'rb'), $t_file_size)); $t_file_path = ''; break; default: trigger_error(ERROR_GENERIC, ERROR); } $t_file_table = db_get_table($p_table . '_file'); $t_id_col = $p_table . '_id'; $t_param = array($t_id_col => $t_id, 'title' => $p_title, 'description' => $p_desc, 'diskfile' => $t_unique_name, 'filename' => $t_file_name, 'folder' => $t_file_path, 'filesize' => $t_file_size, 'file_type' => $p_file['type'], 'date_added' => $p_date_added, 'user_id' => (int) $p_user_id); # Oracle has to update BLOBs separately if (!db_is_oracle()) { $t_param['content'] = $c_content; } $t_query_param = db_param(); for ($i = 1; $i < count($t_param); $i++) { $t_query_param .= ', ' . db_param(); } $t_query = 'INSERT INTO ' . $t_file_table . ' ( ' . implode(', ', array_keys($t_param)) . ' ) VALUES ( ' . $t_query_param . ' )'; db_query($t_query, array_values($t_param)); if (db_is_oracle()) { db_update_blob($t_file_table, 'content', $c_content, "diskfile='{$t_unique_name}'"); } if ('bug' == $p_table) { # update the last_updated date if (!$p_skip_bug_update) { bug_update_date($p_bug_id); } # log file added to bug history history_log_event_special($p_bug_id, FILE_ADDED, $t_file_name); } }
# Do not set custom field value if user has no write access. if (!custom_field_has_write_access($t_id, $t_bug_id)) { continue; } $t_def = custom_field_get_definition($t_id); if (!custom_field_set_value($t_id, $t_bug_id, gpc_get_custom_field("custom_field_{$t_id}", $t_def['type'], $t_def['default_value']))) { error_parameters(lang_get_defaulted(custom_field_get_field($t_id, 'name'))); trigger_error(ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR); } } $f_master_bug_id = gpc_get_int('m_id', 0); $f_rel_type = gpc_get_int('rel_type', -1); if ($f_master_bug_id > 0) { # it's a child generation... let's create the relationship and add some lines in the history # update master bug last updated bug_update_date($f_master_bug_id); # Add log line to record the cloning action history_log_event_special($t_bug_id, BUG_CREATED_FROM, '', $f_master_bug_id); history_log_event_special($f_master_bug_id, BUG_CLONED_TO, '', $t_bug_id); if ($f_rel_type >= 0) { # Add the relationship relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type); # Add log line to the history (both issues) history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id); history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id); # Send the email notification email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type)); } } email_new_bug($t_bug_id); helper_call_custom_function('issue_create_notify', array($t_bug_id));
} # check if there is other relationship between the bugs... $t_old_id_relationship = relationship_same_type_exists($f_src_bug_id, $f_dest_bug_id, $f_rel_type); if ($t_old_id_relationship == -1) { # the relationship type is exactly the same of the new one. No sense to proceed trigger_error(ERROR_RELATIONSHIP_ALREADY_EXISTS, ERROR); } else { if ($t_old_id_relationship > 0) { # there is already a relationship between them -> we have to update it and not to add a new one helper_ensure_confirmed(lang_get('replace_relationship_sure_msg'), lang_get('replace_relationship_button')); # Update the relationship relationship_update($t_old_id_relationship, $f_src_bug_id, $f_dest_bug_id, $f_rel_type); # Add log line to the history (both bugs) history_log_event_special($f_src_bug_id, BUG_REPLACE_RELATIONSHIP, $f_rel_type, $f_dest_bug_id); history_log_event_special($f_dest_bug_id, BUG_REPLACE_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $f_src_bug_id); } else { # Add the new relationship relationship_add($f_src_bug_id, $f_dest_bug_id, $f_rel_type); # Add log line to the history (both bugs) history_log_event_special($f_src_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_dest_bug_id); history_log_event_special($f_dest_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $f_src_bug_id); } } # update bug last updated (just for the src bug) bug_update_date($f_src_bug_id); # send email notification to the users addressed by both the bugs email_relationship_added($f_src_bug_id, $f_dest_bug_id, $f_rel_type); email_relationship_added($f_dest_bug_id, $f_src_bug_id, relationship_get_complementary_type($f_rel_type)); } form_security_purge('bug_relationship_add'); print_header_redirect_view($f_src_bug_id);
/** * Add a file * @param integer $p_id File id. * @param string $p_name File name. * @param string $p_content File content to write. * @param string $p_file_type File type. * @param string $p_table Database table name. * @param string $p_title Title. * @param string $p_desc Description. * @param string $p_user_id User id. * @return mixed */ function mci_file_add($p_id, $p_name, $p_content, $p_file_type, $p_table, $p_title = '', $p_desc = '', $p_user_id = null) { if (!file_type_check($p_name)) { return SoapObjectsFactory::newSoapFault('Client', 'File type not allowed.'); } if (!file_is_name_unique($p_name, $p_id)) { return SoapObjectsFactory::newSoapFault('Client', 'Duplicate filename.'); } $t_file_size = strlen($p_content); $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size')); if ($t_file_size > $t_max_file_size) { return SoapObjectsFactory::newSoapFault('Client', 'File is too big.'); } if ('bug' == $p_table) { $t_project_id = bug_get_field($p_id, 'project_id'); $t_id = (int) $p_id; $t_issue_id = bug_format_id($p_id); } else { $t_project_id = $p_id; $t_id = $t_project_id; $t_issue_id = 0; } if ($p_user_id === null) { $p_user_id = auth_get_current_user_id(); } if ($t_project_id == ALL_PROJECTS) { $t_file_path = config_get('absolute_path_default_upload_folder'); } else { $t_file_path = project_get_field($t_project_id, 'file_path'); if (is_blank($t_file_path)) { $t_file_path = config_get('absolute_path_default_upload_folder'); } } $t_unique_name = file_generate_unique_name($t_file_path); $t_disk_file_name = $t_file_path . $t_unique_name; $t_method = config_get('file_upload_method'); switch ($t_method) { case DISK: if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) { return SoapObjectsFactory::newSoapFault('Server', 'Upload folder \'' . $t_file_path . '\' doesn\'t exist.'); } file_ensure_valid_upload_path($t_file_path); if (!file_exists($t_disk_file_name)) { mci_file_write_local($t_disk_file_name, $p_content); chmod($t_disk_file_name, config_get('attachments_file_permissions')); $c_content = "''"; } break; case DATABASE: $c_content = db_prepare_binary_string($p_content); $t_file_path = ''; break; } $t_file_table = db_get_table($p_table . '_file'); $t_id_col = $p_table . '_id'; $t_param = array($t_id_col => $t_id, 'title' => $p_title, 'description' => $p_desc, 'diskfile' => $t_unique_name, 'filename' => $p_name, 'folder' => $t_file_path, 'filesize' => $t_file_size, 'file_type' => $p_file_type, 'date_added' => db_now(), 'user_id' => (int) $p_user_id); # Oracle has to update BLOBs separately if (!db_is_oracle()) { $t_param['content'] = $c_content; } $t_query_param = db_param(); for ($i = 1; $i < count($t_param); $i++) { $t_query_param .= ', ' . db_param(); } $t_query = 'INSERT INTO ' . $t_file_table . ' ( ' . implode(', ', array_keys($t_param)) . ' ) VALUES ( ' . $t_query_param . ' )'; db_query($t_query, array_values($t_param)); # get attachment id $t_attachment_id = db_insert_id($t_file_table); if (db_is_oracle()) { db_update_blob($t_file_table, 'content', $c_content, "diskfile='{$t_unique_name}'"); } if ('bug' == $p_table) { # bump the last_updated date bug_update_date($t_issue_id); # add history entry history_log_event_special($t_issue_id, FILE_ADDED, $p_name); } return $t_attachment_id; }
function mci_file_add($p_id, $p_name, $p_content, $p_file_type, $p_table, $p_title = '', $p_desc = '', $p_user_id = null) { if (!file_type_check($p_name)) { return new soap_fault('Client', '', 'File type not allowed.'); } if (!file_is_name_unique($p_name, $p_id)) { return new soap_fault('Client', '', 'Duplicate filename.'); } $t_file_size = strlen($p_content); $t_max_file_size = (int) min(ini_get_number('upload_max_filesize'), ini_get_number('post_max_size'), config_get('max_file_size')); if ($t_file_size > $t_max_file_size) { return new soap_fault('Client', '', 'File is too big.'); } if ('bug' == $p_table) { $t_project_id = bug_get_field($p_id, 'project_id'); $t_issue_id = bug_format_id($p_id); } else { $t_project_id = $p_id; $t_issue_id = 0; } # prepare variables for insertion $c_issue_id = db_prepare_int($t_issue_id); $c_project_id = db_prepare_int($t_project_id); $c_file_type = db_prepare_string($p_file_type); $c_title = db_prepare_string($p_title); $c_desc = db_prepare_string($p_desc); if ($p_user_id === null) { $c_user_id = auth_get_current_user_id(); } else { $c_user_id = (int) $p_user_id; } if ($t_project_id == ALL_PROJECTS) { $t_file_path = config_get('absolute_path_default_upload_folder'); } else { $t_file_path = project_get_field($t_project_id, 'file_path'); if ($t_file_path == '') { $t_file_path = config_get('absolute_path_default_upload_folder'); } } $c_file_path = db_prepare_string($t_file_path); $c_new_file_name = db_prepare_string($p_name); $t_file_hash = $t_issue_id; $t_disk_file_name = $t_file_path . file_generate_unique_name($t_file_hash . '-' . $p_name, $t_file_path); $c_disk_file_name = db_prepare_string($t_disk_file_name); $t_file_size = strlen($p_content); $c_file_size = db_prepare_int($t_file_size); $t_method = config_get('file_upload_method'); switch ($t_method) { case FTP: case DISK: if (!file_exists($t_file_path) || !is_dir($t_file_path) || !is_writable($t_file_path) || !is_readable($t_file_path)) { return new soap_fault('Server', '', "Upload folder '{$t_file_path}' doesn't exist."); } file_ensure_valid_upload_path($t_file_path); if (!file_exists($t_disk_file_name)) { mci_file_write_local($t_disk_file_name, $p_content); if (FTP == $t_method) { $conn_id = file_ftp_connect(); file_ftp_put($conn_id, $t_disk_file_name, $t_disk_file_name); file_ftp_disconnect($conn_id); file_delete_local($t_disk_file_name); } else { chmod($t_disk_file_name, config_get('attachments_file_permissions')); } $c_content = "''"; } break; case DATABASE: $c_content = db_prepare_binary_string($p_content); break; } $t_file_table = db_get_table($p_table . '_file'); $c_id = 'bug' == $p_table ? $c_issue_id : $c_project_id; $query = "INSERT INTO {$t_file_table}\n\t\t\t(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id)\n\t\tVALUES\n\t\t\t({$c_id}, '{$c_title}', '{$c_desc}', '{$c_disk_file_name}', '{$c_new_file_name}', '{$c_file_path}', {$c_file_size}, '{$c_file_type}', '" . db_now() . "', {$c_content}, {$c_user_id})"; db_query($query); # get attachment id $t_attachment_id = db_insert_id($t_file_table); if ('bug' == $p_table) { # updated the last_updated date $result = bug_update_date($c_issue_id); # log new bug history_log_event_special($c_issue_id, FILE_ADDED, $c_new_file_name); } return $t_attachment_id; }
private function add_bug(&$p_email, $p_overwrite_project_id = FALSE) { $this->show_memory_usage('Start add bug'); //Merge References and In-Reply-To headers into one array $t_references = $p_email['References']; $t_references[] = $p_email['In-Reply-To']; if ($this->_mail_add_bugnotes) { $t_bug_id = $this->mail_is_a_bugnote($p_email['Subject'], $t_references); } else { $t_bug_id = FALSE; } if ($t_bug_id !== FALSE && !bug_is_readonly($t_bug_id)) { // @TODO@ Disabled for now until we find a good solution on how to handle the reporters possible lack of access permissions // access_ensure_bug_level( config_get( 'add_bugnote_threshold' ), $f_bug_id ); $t_description = $p_email['X-Mantis-Body']; $t_description = $this->identify_replies($t_description); $t_description = $this->strip_signature($t_description); $t_description = $this->add_additional_info('note', $p_email, $t_description); $t_project_id = bug_get_field($t_bug_id, 'project_id'); ERP_set_temporary_overwrite('project_override', $t_project_id); # Event integration # Core mantis event already exists within bugnote_add function $t_description = event_signal('EVENT_ERP_BUGNOTE_DATA', $t_description, $t_bug_id); if (bug_is_resolved($t_bug_id)) { # Reopen issue and add a bug note bug_reopen($t_bug_id, $t_description); } elseif (!is_blank($t_description)) { # Add a bug note bugnote_add($t_bug_id, $t_description); } } elseif ($this->_mail_add_bug_reports) { // @TODO@ Disabled for now until we find a good solution on how to handle the reporters possible lack of access permissions // access_ensure_project_level( config_get('report_bug_threshold' ) ); $f_master_bug_id = $t_bug_id !== FALSE && bug_is_readonly($t_bug_id) ? $t_bug_id : 0; $this->fix_empty_fields($p_email); $t_project_id = $p_overwrite_project_id === FALSE ? $this->_mailbox['project_id'] : $p_overwrite_project_id; ERP_set_temporary_overwrite('project_override', $t_project_id); $t_bug_data = new BugData(); $t_bug_data->build = ''; $t_bug_data->platform = ''; $t_bug_data->os = ''; $t_bug_data->os_build = ''; $t_bug_data->version = ''; $t_bug_data->profile_id = 0; $t_bug_data->handler_id = 0; $t_bug_data->view_state = (int) config_get('default_bug_view_status'); $t_bug_data->category_id = (int) $this->_mailbox['global_category_id']; $t_bug_data->reproducibility = (int) config_get('default_bug_reproducibility'); $t_bug_data->severity = (int) config_get('default_bug_severity'); $t_bug_data->priority = (int) ($this->_mail_use_bug_priority ? $p_email['Priority'] : config_get('default_bug_priority')); $t_bug_data->projection = (int) config_get('default_bug_projection'); $t_bug_data->eta = (int) config_get('default_bug_eta'); $t_bug_data->resolution = config_get('default_bug_resolution'); $t_bug_data->status = config_get('bug_submit_status'); $t_bug_data->summary = $p_email['Subject']; $t_description = $p_email['X-Mantis-Body']; $t_description = $this->strip_signature($t_description); $t_description = $this->add_additional_info('issue', $p_email, $t_description); $t_bug_data->description = $t_description; $t_bug_data->steps_to_reproduce = config_get('default_bug_steps_to_reproduce'); $t_bug_data->additional_information = config_get('default_bug_additional_info'); $t_bug_data->due_date = date_get_null(); $t_bug_data->project_id = $t_project_id; $t_bug_data->reporter_id = $p_email['Reporter_id']; // This function might do stuff that EmailReporting cannot handle. Disabled //helper_call_custom_function( 'issue_create_validate', array( $t_bug_data ) ); // @TODO@ Disabled for now but possibly needed for other future features # Validate the custom fields before adding the bug. /* $t_related_custom_field_ids = custom_field_get_linked_ids( $t_bug_data->project_id ); foreach( $t_related_custom_field_ids as $t_id ) { $t_def = custom_field_get_definition( $t_id ); # Produce an error if the field is required but wasn't posted if ( !gpc_isset_custom_field( $t_id, $t_def['type'] ) && ( $t_def['require_report'] || $t_def['type'] == CUSTOM_FIELD_TYPE_ENUM || $t_def['type'] == CUSTOM_FIELD_TYPE_LIST || $t_def['type'] == CUSTOM_FIELD_TYPE_MULTILIST || $t_def['type'] == CUSTOM_FIELD_TYPE_RADIO ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_EMPTY_FIELD, ERROR ); } if ( !custom_field_validate( $t_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], NULL ) ) ) { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } }*/ # Allow plugins to pre-process bug data $t_bug_data = event_signal('EVENT_REPORT_BUG_DATA', $t_bug_data); $t_bug_data = event_signal('EVENT_ERP_REPORT_BUG_DATA', $t_bug_data); # Create the bug $t_bug_id = $t_bug_data->create(); // @TODO@ Disabled for now but possibly needed for other future features # Handle custom field submission /* foreach( $t_related_custom_field_ids as $t_id ) { # Do not set custom field value if user has no write access. if( !custom_field_has_write_access( $t_id, $t_bug_id ) ) { continue; } $t_def = custom_field_get_definition( $t_id ); if( !custom_field_set_value( $t_id, $t_bug_id, gpc_get_custom_field( "custom_field_$t_id", $t_def['type'], '' ), false ) ) { { error_parameters( lang_get_defaulted( custom_field_get_field( $t_id, 'name' ) ) ); trigger_error( ERROR_CUSTOM_FIELD_INVALID_VALUE, ERROR ); } }*/ // Lets link a readonly already existing bug to the newly created one if ($f_master_bug_id > 0) { $f_rel_type = BUG_RELATED; # update master bug last updated bug_update_date($f_master_bug_id); # Add the relationship relationship_add($t_bug_id, $f_master_bug_id, $f_rel_type); # Add log line to the history (both issues) history_log_event_special($f_master_bug_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($f_rel_type), $t_bug_id); history_log_event_special($t_bug_id, BUG_ADD_RELATIONSHIP, $f_rel_type, $f_master_bug_id); # Send the email notification email_relationship_added($f_master_bug_id, $t_bug_id, relationship_get_complementary_type($f_rel_type)); } helper_call_custom_function('issue_create_notify', array($t_bug_id)); # Allow plugins to post-process bug data with the new bug ID event_signal('EVENT_REPORT_BUG', array($t_bug_data, $t_bug_id)); email_new_bug($t_bug_id); } else { // Not allowed to add issues and not allowed / able to add notes. Need to stop processing $this->custom_error('Not allowed to create a new issue. Email ignored'); return; } $this->custom_error('Reporter: ' . $p_email['Reporter_id'] . ' - ' . $p_email['From_parsed']['email'] . ' --> Issue ID: #' . $t_bug_id, FALSE); $this->show_memory_usage('Finished add bug'); $this->show_memory_usage('Start processing attachments'); # Add files if ($this->_allow_file_upload) { if (count($p_email['X-Mantis-Parts']) > 0) { $t_rejected_files = NULL; while ($t_part = array_shift($p_email['X-Mantis-Parts'])) { $t_file_rejected = $this->add_file($t_bug_id, $t_part); if ($t_file_rejected !== TRUE) { $t_rejected_files .= $t_file_rejected; } } if ($t_rejected_files !== NULL) { $t_part = array('name' => 'Rejected files.txt', 'ctype' => 'text/plain', 'body' => 'List of rejected files' . "\n\n" . $t_rejected_files); $t_reject_rejected_files = $this->add_file($t_bug_id, $t_part); if ($t_reject_rejected_files !== TRUE) { $t_part['body'] .= $t_reject_rejected_files; $this->custom_error('Failed to add "' . $t_part['name'] . '" to the issue. See below for all errors.' . "\n" . $t_part['body']); } } } } //Add the users in Cc and To list in mail header $this->add_monitors($t_bug_id, $p_email); //Add the message-id to the database $this->add_msg_id($t_bug_id, $p_email['Message-ID']); ERP_set_temporary_overwrite('project_override', NULL); $this->show_memory_usage('Finished processing attachments'); }
$different_units = true; } if ($request['action'] == 'save') { if (!empty($request['assume'])) { foreach ($request['assume'] as $num => $row) { $tasked = $agilemantis_sprint->getSprintTasks($row, 0); if (!empty($tasked) && $different_units) { foreach ($tasked as $key => $value) { if ($value['rest_capacity'] > 0) { $agilemantis_sprint->resetPlanned($value['id']); $resetPlannedCapacity = true; } } } $agilemantis_pb->doUserStoryToSprint($row, $sprintName); bug_update_date($row); } if ($resetPlannedCapacity) { echo '<br><center><span class="message_error">' . plugin_lang_get('assume_userstories_error_106C00') . '</span></center>'; } echo '<br><center><span class="message_ok">' . plugin_lang_get('assume_userstories_assume_successfull') . '</span></center>'; } else { echo '<br><center><span class="message_error">' . plugin_lang_get('assume_userstories_error_120C00') . '</span></center>'; } } # set different filters for assume new user stories if (!config_is_set('current_user_assume_userstories_filter', auth_get_current_user_id())) { config_set('current_user_assume_userstories_filter', '', auth_get_current_user_id()); } if (!config_is_set('current_user_assume_userstories_filter_direction', auth_get_current_user_id())) { config_set('current_user_assume_userstories_filter_direction', 'ASC', auth_get_current_user_id());
function bugnote_add($p_bug_id, $p_bugnote_text, $p_private = false, $p_type = 0, $p_attr = '', $p_user_id = null) { $c_bug_id = db_prepare_int($p_bug_id); $c_bugnote_text = db_prepare_string($p_bugnote_text); $c_private = db_prepare_bool($p_private); $c_type = db_prepare_int($p_type); $c_attr = db_prepare_string($p_attr); $t_bugnote_text_table = config_get('mantis_bugnote_text_table'); $t_bugnote_table = config_get('mantis_bugnote_table'); # insert bugnote text $query = "INSERT INTO {$t_bugnote_text_table}\n\t\t \t\t( note )\n\t\t \t VALUES\n\t\t \t\t( '{$c_bugnote_text}' )"; db_query($query); # retrieve bugnote text id number $t_bugnote_text_id = db_insert_id($t_bugnote_text_table); # get user information if ($p_user_id === null) { $c_user_id = auth_get_current_user_id(); } else { $c_user_id = db_prepare_int($p_user_id); } # Check for private bugnotes. # @@@ VB: Should we allow users to report private bugnotes, and possibly see only their own private ones if ($p_private && access_has_bug_level(config_get('private_bugnote_threshold'), $p_bug_id, $c_user_id)) { $t_view_state = VS_PRIVATE; } else { $t_view_state = VS_PUBLIC; } # insert bugnote info $query = "INSERT INTO {$t_bugnote_table}\n\t\t \t\t(bug_id, reporter_id, bugnote_text_id, view_state, date_submitted, last_modified, note_type, note_attr )\n\t\t \t VALUES\n\t\t \t\t('{$c_bug_id}', '{$c_user_id}','{$t_bugnote_text_id}', '{$t_view_state}', " . db_now() . "," . db_now() . ", '{$c_type}', '{$c_attr}')"; db_query($query); # get bugnote id $t_bugnote_id = db_insert_id($t_bugnote_table); # update bug last updated bug_update_date($p_bug_id); # log new bug history_log_event_special($p_bug_id, BUGNOTE_ADDED, bugnote_format_id($t_bugnote_id)); return $t_bugnote_id; }