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); }
/** * allows bug deletion : * delete the bug, bugtext, bugnote, and bugtexts selected * @param array p_bug_id integer representing bug id * @return bool (always true) * @access public */ function bug_delete($p_bug_id) { $c_bug_id = (int) $p_bug_id; $t_bug_table = db_get_table('mantis_bug_table'); $t_bug_text_table = db_get_table('mantis_bug_text_table'); # call pre-deletion custom function helper_call_custom_function('issue_delete_validate', array($p_bug_id)); # log deletion of bug history_log_event_special($p_bug_id, BUG_DELETED, bug_format_id($p_bug_id)); email_bug_deleted($p_bug_id); # call post-deletion custom function. We call this here to allow the custom function to access the details of the bug before # they are deleted from the database given it's id. The other option would be to move this to the end of the function and # provide it with bug data rather than an id, but this will break backward compatibility. helper_call_custom_function('issue_delete_notify', array($p_bug_id)); # Unmonitor bug for all users bug_unmonitor($p_bug_id, null); # Delete custom fields custom_field_delete_all_values($p_bug_id); # Delete bugnotes bugnote_delete_all($p_bug_id); # Delete all sponsorships sponsorship_delete_all($p_bug_id); # MASC RELATIONSHIP # we delete relationships even if the feature is currently off. relationship_delete_all($p_bug_id); # MASC RELATIONSHIP # Delete files file_delete_attachments($p_bug_id); # Detach tags tag_bug_detach_all($p_bug_id, false); # Delete the bug history history_delete($p_bug_id); # Delete bug info revisions bug_revision_delete($p_bug_id); # Delete the bugnote text $t_bug_text_id = bug_get_field($p_bug_id, 'bug_text_id'); $query = "DELETE FROM {$t_bug_text_table}\n\t\t\t\t WHERE id=" . db_param(); db_query_bound($query, array($t_bug_text_id)); # Delete the bug entry $query = "DELETE FROM {$t_bug_table}\n\t\t\t\t WHERE id=" . db_param(); db_query_bound($query, array($c_bug_id)); bug_clear_cache($p_bug_id); bug_text_clear_cache($p_bug_id); # db_query errors on failure so: return true; }
function bug_delete($p_bug_id) { $c_bug_id = db_prepare_int($p_bug_id); $t_bug_table = config_get('mantis_bug_table'); $t_bug_text_table = config_get('mantis_bug_text_table'); # log deletion of bug history_log_event_special($p_bug_id, BUG_DELETED, bug_format_id($p_bug_id)); email_bug_deleted($p_bug_id); # Unmonitor bug for all users bug_unmonitor($p_bug_id, null); # Delete custom fields custom_field_delete_all_values($p_bug_id); # Delete bugnotes bugnote_delete_all($p_bug_id); # Delete all sponsorships sponsorship_delete(sponsorship_get_all_ids($p_bug_id)); # MASC RELATIONSHIP # we delete relationships even if the feature is currently off. relationship_delete_all($p_bug_id); # MASC RELATIONSHIP # Delete files file_delete_attachments($p_bug_id); # Delete the bug history history_delete($p_bug_id); # Delete the bugnote text $t_bug_text_id = bug_get_field($p_bug_id, 'bug_text_id'); $query = "DELETE FROM {$t_bug_text_table}\n\t\t\t\t WHERE id='{$t_bug_text_id}'"; db_query($query); # Delete the bug entry $query = "DELETE FROM {$t_bug_table}\n\t\t\t\t WHERE id='{$c_bug_id}'"; db_query($query); bug_clear_cache($p_bug_id); bug_text_clear_cache($p_bug_id); # db_query() errors on failure so: return true; }