CmdPurge: Move dependency handling into separate method

This commit is contained in:
Tomas Babej 2016-03-20 15:16:05 +01:00 committed by Paul Beckingham
parent fd0d2fc917
commit b0336dfd50
2 changed files with 22 additions and 12 deletions

View file

@ -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);
}
}
}
}
}

View file

@ -32,6 +32,8 @@
class CmdPurge : public Command
{
private:
void handleDeps (Task& task);
public:
CmdPurge ();
int execute (std::string&);