CmdPurge: Remove purged tasks from dependencies
This commit is contained in:
committed by
Paul Beckingham
parent
70a0e256b0
commit
909b2e2713
@@ -29,6 +29,7 @@
|
|||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Filter.h>
|
#include <Filter.h>
|
||||||
#include <i18n.h>
|
#include <i18n.h>
|
||||||
|
#include <main.h>
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
@@ -55,9 +56,10 @@ int CmdPurge::execute (std::string&)
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
// Apply filter.
|
|
||||||
Filter filter;
|
Filter filter;
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
|
|
||||||
|
// Apply filter.
|
||||||
filter.subset (filtered);
|
filter.subset (filtered);
|
||||||
if (filtered.size () == 0)
|
if (filtered.size () == 0)
|
||||||
{
|
{
|
||||||
@@ -67,13 +69,28 @@ int CmdPurge::execute (std::string&)
|
|||||||
|
|
||||||
for (auto& task : filtered)
|
for (auto& task : filtered)
|
||||||
{
|
{
|
||||||
|
std::string uuid = task.get ("uuid");
|
||||||
|
|
||||||
if (task.getStatus () == Task::deleted)
|
if (task.getStatus () == Task::deleted)
|
||||||
{
|
{
|
||||||
context.tdb2.purge (task);
|
context.tdb2.purge (task);
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
|
// Remove dependencies on the task being purged
|
||||||
|
for (auto& blockedConst: context.tdb2.all_tasks ())
|
||||||
|
{
|
||||||
|
Task& blocked = const_cast<Task&>(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;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -397,6 +397,8 @@
|
|||||||
#define STRING_CMD_DUPLICATE_N "Duplicated {1} tasks."
|
#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_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_USAGE "Marks specified task as started"
|
||||||
#define STRING_CMD_START_NO "Task not started."
|
#define STRING_CMD_START_NO "Task not started."
|
||||||
|
|||||||
Reference in New Issue
Block a user