diff --git a/src/TDB2.cpp b/src/TDB2.cpp index b89d63fde..d9ae11636 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -568,32 +568,50 @@ void TDB2::add (Task& task, bool add_to_backlog /* = true */) throw format (STRING_TDB2_UUID_NOT_UNIQUE, uuid); // Create a vector tasks, as hooks can cause them to multiply. - std::vector toAdd; - toAdd.push_back (task); + std::vector changes; + changes.push_back (task); // TODO call hooks. - // context.hooks.onAdd (toAdd); + // context.hooks.onAdd (changes); std::vector ::iterator i; - for (i = toAdd.begin (); i != toAdd.end (); ++i) + for (i = changes.begin (); i != changes.end (); ++i) { - // TODO Upgrade to add or modify, not just add. + // If the task already exists, it is a modification, else addition. + Task original; + if (get (i->get ("uuid"), original)) + { + // Update the task, wherever it is. + if (!pending.modify_task (*i)) + completed.modify_task (*i); - // Add new task to either pending or completed. - std::string status = i->get ("status"); - if (status == "completed" || - status == "deleted") - completed.add_task (*i); + // time