From 7b617a7b6ecc4e6b403251496ff7ec3f357f4249 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 14 Sep 2014 15:25:37 -0400 Subject: [PATCH] TDB2 - Consolidated most of the processing in ::add and ::modify into ::update. --- src/TDB2.cpp | 76 +++++++++++++++++++--------------------------------- src/TDB2.h | 1 + 2 files changed, 28 insertions(+), 49 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index d9ae11636..3baf8a2c6 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -574,6 +574,33 @@ void TDB2::add (Task& task, bool add_to_backlog /* = true */) // TODO call hooks. // context.hooks.onAdd (changes); + update (uuid, task, add_to_backlog, changes); +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB2::modify (Task& task, bool add_to_backlog /* = true */) +{ + // Ensure the task is consistent, and provide defaults if necessary. + task.validate (false); + std::string uuid = task.get ("uuid"); + + // Create a vector tasks, as hooks can cause them to multiply. + std::vector changes; + changes.push_back (task); + + // TODO call hooks. + // context.hooks.onModify (changes); + + update (uuid, task, add_to_backlog, changes); +} + +//////////////////////////////////////////////////////////////////////////////// +void TDB2::update ( + const std::string& uuid, + Task& task, + const bool add_to_backlog, + std::vector & changes) +{ std::vector ::iterator i; for (i = changes.begin (); i != changes.end (); ++i) { @@ -623,55 +650,6 @@ void TDB2::add (Task& task, bool add_to_backlog /* = true */) } } -//////////////////////////////////////////////////////////////////////////////// -void TDB2::modify (Task& task, bool add_to_backlog /* = true */) -{ - // Ensure the task is consistent, and provide defaults if necessary. - task.validate (false); - std::string uuid = task.get ("uuid"); - - // Create a vector tasks, as hooks can cause them to multiply. - std::vector toModify; - toModify.push_back (task); - - // TODO call hooks. - // context.hooks.onModify (toModify); - - std::vector ::iterator i; - for (i = toModify.begin (); i != toModify.end (); ++i) - { - // Find task, overwrite it. - Task original; - get (task.get ("uuid"), original); - - if (taskDiff (original, task)) - { - // TODO Upgrade to add or modify, not just add. - - // Update the task, wherever it is. - if (!pending.modify_task (task)) - completed.modify_task (task); - - // time