///////////////////////////////////////////////////////////////////////////
| 121 | |
| 122 | //////////////////////////////////////////////////////////////////////////////// |
| 123 | int CmdPurge::execute(std::string&) { |
| 124 | int rc = 0; |
| 125 | std::vector<Task> tasks; |
| 126 | bool matched_deleted = false; |
| 127 | |
| 128 | Filter filter; |
| 129 | std::vector<Task> filtered; |
| 130 | |
| 131 | // Apply filter. |
| 132 | filter.subset(filtered); |
| 133 | if (filtered.size() == 0) { |
| 134 | Context::getContext().footnote("No tasks specified."); |
| 135 | return 1; |
| 136 | } |
| 137 | |
| 138 | for (auto& task : filtered) { |
| 139 | // Allow purging of deleted tasks only. Hence no need to deal with: |
| 140 | // - unblocked tasks notifications (deleted tasks are not blocking) |
| 141 | // - project changes (deleted tasks not included in progress) |
| 142 | // It also has the nice property of being explicit - users need to |
| 143 | // mark tasks as deleted before purging. |
| 144 | if (task.getStatus() == Task::deleted) { |
| 145 | // Mark that at least one deleted task matched the filter |
| 146 | matched_deleted = true; |
| 147 | |
| 148 | std::string question; |
| 149 | question = format("Permanently remove task {1} '{2}'?", task.identifier(true), |
| 150 | task.get("description")); |
| 151 | |
| 152 | if (permission(question, filtered.size())) handleRelations(task, tasks); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // Now that any exceptions are handled, actually purge the tasks. |
| 157 | for (auto& task : tasks) { |
| 158 | Context::getContext().tdb2.purge(task); |
| 159 | } |
| 160 | |
| 161 | if (filtered.size() > 0 and !matched_deleted) |
| 162 | Context::getContext().footnote( |
| 163 | "No deleted tasks specified. Maybe you forgot to delete tasks first?"); |
| 164 | |
| 165 | feedback_affected(tasks.size() == 1 ? "Purged {1} task." : "Purged {1} tasks.", tasks.size()); |
| 166 | return rc; |
| 167 | } |
| 168 | |
| 169 | //////////////////////////////////////////////////////////////////////////////// |
nothing calls this directly
no test coverage detected