CmdPurge: Move dependency handling into separate method
This commit is contained in:
committed by
Paul Beckingham
parent
894eb3ab79
commit
c04bdc48aa
@@ -51,6 +51,25 @@ CmdPurge::CmdPurge ()
|
|||||||
_category = Command::Category::operation;
|
_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&)
|
int CmdPurge::execute (std::string&)
|
||||||
{
|
{
|
||||||
@@ -82,19 +101,8 @@ int CmdPurge::execute (std::string&)
|
|||||||
if (permission (question, filtered.size ()))
|
if (permission (question, filtered.size ()))
|
||||||
{
|
{
|
||||||
context.tdb2.purge (task);
|
context.tdb2.purge (task);
|
||||||
|
handleDeps(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
class CmdPurge : public Command
|
class CmdPurge : public Command
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
void handleDeps (Task& task);
|
||||||
public:
|
public:
|
||||||
CmdPurge ();
|
CmdPurge ();
|
||||||
int execute (std::string&);
|
int execute (std::string&);
|
||||||
|
|||||||
Reference in New Issue
Block a user