mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-27 10:07:19 +02:00
TDB2
- TDB2::add no longer assumes that adding one task results in only one task begin added, as hook processing may expand the set.
This commit is contained in:
parent
f3c035d2b8
commit
ac833c183a
1 changed files with 68 additions and 37 deletions
45
src/TDB2.cpp
45
src/TDB2.cpp
|
@ -560,31 +560,49 @@ void TDB2::add (Task& task, bool add_to_backlog /* = true */)
|
||||||
{
|
{
|
||||||
// Ensure the task is consistent, and provide defaults if necessary.
|
// Ensure the task is consistent, and provide defaults if necessary.
|
||||||
task.validate ();
|
task.validate ();
|
||||||
|
std::string uuid = task.get ("uuid");
|
||||||
|
|
||||||
// If the tasks are loaded, then verify that this uuid is not already in
|
// If the tasks are loaded, then verify that this uuid is not already in
|
||||||
// the file.
|
// the file.
|
||||||
if (!verifyUniqueUUID (task.get ("uuid")))
|
if (!verifyUniqueUUID (uuid))
|
||||||
throw format (STRING_TDB2_UUID_NOT_UNIQUE, task.get ("uuid"));
|
throw format (STRING_TDB2_UUID_NOT_UNIQUE, uuid);
|
||||||
|
|
||||||
|
// Create a vector tasks, as hooks can cause them to multiply.
|
||||||
|
std::vector <Task> toAdd;
|
||||||
|
toAdd.push_back (task);
|
||||||
|
|
||||||
|
// TODO call hooks.
|
||||||
|
// context.hooks.onAdd (toAdd);
|
||||||
|
|
||||||
|
std::vector <Task>::iterator i;
|
||||||
|
for (i = toAdd.begin (); i != toAdd.end (); ++i)
|
||||||
|
{
|
||||||
|
// TODO Upgrade to add or modify, not just add.
|
||||||
|
|
||||||
// Add new task to either pending or completed.
|
// Add new task to either pending or completed.
|
||||||
std::string status = task.get ("status");
|
std::string status = i->get ("status");
|
||||||
if (status == "completed" ||
|
if (status == "completed" ||
|
||||||
status == "deleted")
|
status == "deleted")
|
||||||
completed.add_task (task);
|
completed.add_task (*i);
|
||||||
else
|
else
|
||||||
pending.add_task (task);
|
pending.add_task (*i);
|
||||||
|
|
||||||
// Add undo data lines:
|
// Add undo data lines:
|
||||||
// time <time>
|
// time <time>
|
||||||
// new <task>
|
// new <task>
|
||||||
// ---
|
// ---
|
||||||
undo.add_line ("time " + Date ().toEpochString () + "\n");
|
undo.add_line ("time " + Date ().toEpochString () + "\n");
|
||||||
undo.add_line ("new " + task.composeF4 () + "\n");
|
undo.add_line ("new " + i->composeF4 () + "\n");
|
||||||
undo.add_line ("---\n");
|
undo.add_line ("---\n");
|
||||||
|
|
||||||
// Add task to backlog.
|
// Add task to backlog.
|
||||||
if (add_to_backlog)
|
if (add_to_backlog)
|
||||||
backlog.add_line (task.composeJSON () + "\n");
|
backlog.add_line (i->composeJSON () + "\n");
|
||||||
|
|
||||||
|
// The original task may be further referenced by the caller.
|
||||||
|
if (i->get ("uuid") == uuid)
|
||||||
|
task = *i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -593,12 +611,24 @@ void TDB2::modify (Task& task, bool add_to_backlog /* = true */)
|
||||||
// Ensure the task is consistent, and provide defaults if necessary.
|
// Ensure the task is consistent, and provide defaults if necessary.
|
||||||
task.validate (false);
|
task.validate (false);
|
||||||
|
|
||||||
|
// Create a vector tasks, as hooks can cause them to multiply.
|
||||||
|
std::vector <Task> toModify;
|
||||||
|
toModify.push_back (task);
|
||||||
|
|
||||||
|
// TODO call hooks.
|
||||||
|
// context.hooks.onModify (toModify);
|
||||||
|
|
||||||
|
std::vector <Task>::iterator i;
|
||||||
|
for (i = toModify.begin (); i != toModify.end (); ++i)
|
||||||
|
{
|
||||||
// Find task, overwrite it.
|
// Find task, overwrite it.
|
||||||
Task original;
|
Task original;
|
||||||
get (task.get ("uuid"), original);
|
get (task.get ("uuid"), original);
|
||||||
|
|
||||||
if (taskDiff (original, task))
|
if (taskDiff (original, task))
|
||||||
{
|
{
|
||||||
|
// TODO Upgrade to add or modify, not just add.
|
||||||
|
|
||||||
// Update the task, wherever it is.
|
// Update the task, wherever it is.
|
||||||
if (!pending.modify_task (task))
|
if (!pending.modify_task (task))
|
||||||
completed.modify_task (task);
|
completed.modify_task (task);
|
||||||
|
@ -616,6 +646,7 @@ void TDB2::modify (Task& task, bool add_to_backlog /* = true */)
|
||||||
if (add_to_backlog)
|
if (add_to_backlog)
|
||||||
backlog.add_line (task.composeJSON () + "\n");
|
backlog.add_line (task.composeJSON () + "\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue