diff --git a/src/commands/CmdPurge.cpp b/src/commands/CmdPurge.cpp index 5ca665efe..2156e9777 100644 --- a/src/commands/CmdPurge.cpp +++ b/src/commands/CmdPurge.cpp @@ -29,6 +29,7 @@ #include #include #include +#include extern Context context; @@ -55,9 +56,10 @@ int CmdPurge::execute (std::string&) int rc = 0; int count = 0; - // Apply filter. Filter filter; std::vector filtered; + + // Apply filter. filter.subset (filtered); if (filtered.size () == 0) { @@ -67,13 +69,28 @@ int CmdPurge::execute (std::string&) for (auto& task : filtered) { + std::string uuid = task.get ("uuid"); + if (task.getStatus () == Task::deleted) { - context.tdb2.purge (task); - count++; + context.tdb2.purge (task); + count++; + + // Remove dependencies on the task being purged + for (auto& blockedConst: context.tdb2.all_tasks ()) + { + Task& blocked = const_cast(blockedConst); + if (blocked.has ("depends") && + blocked.get ("depends").find (uuid) != std::string::npos) + { + blocked.removeDependency (uuid); + context.tdb2.modify (blocked); + } + } } } + feedback_affected (count == 1 ? STRING_CMD_PURGE_1 : STRING_CMD_PURGE_N, count); return rc; } diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index cbc038b76..750e9dc61 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -397,6 +397,8 @@ #define STRING_CMD_DUPLICATE_N "Duplicated {1} tasks." #define STRING_CMD_PURGE_USAGE "Removes the specified task from the data files. Causes permanent loss of data." +#define STRING_CMD_PURGE_1 "Purged {1} task." +#define STRING_CMD_PURGE_N "Purged {1} tasks." #define STRING_CMD_START_USAGE "Marks specified task as started" #define STRING_CMD_START_NO "Task not started."