mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-27 12:16:21 +02:00
CmdPurge: Move dependency handling into separate method
This commit is contained in:
parent
fd0d2fc917
commit
b0336dfd50
2 changed files with 22 additions and 12 deletions
|
@ -51,6 +51,25 @@ CmdPurge::CmdPurge ()
|
|||
_category = Command::Category::operation;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Makes sure that any task having the dependency on the task being purged
|
||||
// has that dependency removed, to preserve referential integrity.
|
||||
void CmdPurge::handleDeps (Task& task)
|
||||
{
|
||||
std::string uuid = task.get ("uuid");
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdPurge::execute (std::string&)
|
||||
{
|
||||
|
@ -82,19 +101,8 @@ int CmdPurge::execute (std::string&)
|
|||
if (permission (question, filtered.size ()))
|
||||
{
|
||||
context.tdb2.purge (task);
|
||||
handleDeps(task);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
|
||||
class CmdPurge : public Command
|
||||
{
|
||||
private:
|
||||
void handleDeps (Task& task);
|
||||
public:
|
||||
CmdPurge ();
|
||||
int execute (std::string&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue