///////////////////////////////////////////////////////////////////////////
| 61 | |
| 62 | //////////////////////////////////////////////////////////////////////////////// |
| 63 | int CmdDelete::execute(std::string&) { |
| 64 | auto rc = 0; |
| 65 | auto count = 0; |
| 66 | |
| 67 | // Apply filter. |
| 68 | Filter filter; |
| 69 | std::vector<Task> filtered; |
| 70 | filter.subset(filtered); |
| 71 | if (filtered.size() == 0) { |
| 72 | Context::getContext().footnote("No tasks specified."); |
| 73 | return 1; |
| 74 | } |
| 75 | |
| 76 | // Accumulated project change notifications. |
| 77 | std::map<std::string, std::string> projectChanges; |
| 78 | |
| 79 | if (filtered.size() > 1) { |
| 80 | feedback_affected("This command will alter {1} tasks.", filtered.size()); |
| 81 | } |
| 82 | for (auto& task : filtered) { |
| 83 | Task before(task); |
| 84 | |
| 85 | if (task.getStatus() != Task::deleted) { |
| 86 | // Delete the specified task. |
| 87 | std::string question; |
| 88 | question = format("Delete task {1} '{2}'?", task.identifier(true), task.get("description")); |
| 89 | |
| 90 | task.modify(Task::modAnnotate); |
| 91 | task.setStatus(Task::deleted); |
| 92 | if (!task.has("end")) task.setAsNow("end"); |
| 93 | |
| 94 | if (permission(question, filtered.size())) { |
| 95 | updateRecurrenceMask(task); |
| 96 | ++count; |
| 97 | Context::getContext().tdb2.modify(task); |
| 98 | feedback_affected("Deleting task {1} '{2}'.", task); |
| 99 | feedback_unblocked(task); |
| 100 | dependencyChainOnComplete(task); |
| 101 | if (Context::getContext().verbose("project")) |
| 102 | projectChanges[task.get("project")] = onProjectChange(task); |
| 103 | |
| 104 | // Delete siblings. |
| 105 | if (task.has("parent")) { |
| 106 | if ((Context::getContext().config.get("recurrence.confirmation") == "prompt" && |
| 107 | confirm(STRING_CMD_DELETE_CONFIRM_R)) || |
| 108 | Context::getContext().config.getBoolean("recurrence.confirmation")) { |
| 109 | std::vector<Task> siblings = Context::getContext().tdb2.siblings(task); |
| 110 | for (auto& sibling : siblings) { |
| 111 | sibling.modify(Task::modAnnotate); |
| 112 | sibling.setStatus(Task::deleted); |
| 113 | if (!sibling.has("end")) sibling.setAsNow("end"); |
| 114 | |
| 115 | updateRecurrenceMask(sibling); |
| 116 | Context::getContext().tdb2.modify(sibling); |
| 117 | feedback_affected(STRING_CMD_DELETE_TASK_R, sibling); |
| 118 | feedback_unblocked(sibling); |
| 119 | ++count; |
| 120 | } |
nothing calls this directly
no test coverage detected