From 988ab7ada04c73e64c0bee4652e4cb69777aa161 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 12 Oct 2011 00:20:05 -0400 Subject: [PATCH] Logic Bug - Fixed logic bug dealing wiht bulk updates and recurring tasks. --- src/commands/CmdAppend.cpp | 77 +++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/src/commands/CmdAppend.cpp b/src/commands/CmdAppend.cpp index 776f7ad38..9db0e0ef7 100644 --- a/src/commands/CmdAppend.cpp +++ b/src/commands/CmdAppend.cpp @@ -25,15 +25,15 @@ // //////////////////////////////////////////////////////////////////////////////// - #define L10N // Localization complete. #include #include #include -#include +#include #include #include +#include #include extern Context context; @@ -64,7 +64,7 @@ int CmdAppend::execute (std::string& output) return 1; } - // Apply the command line modifications to the started task. + // Apply the command line modifications to the new task. A3 modifications = context.a3.extract_modifications (); if (!modifications.size ()) throw std::string (STRING_CMD_XPEND_NEED_TEXT); @@ -73,44 +73,69 @@ int CmdAppend::execute (std::string& output) if (filtered.size () > (size_t) context.config.getInteger ("bulk")) permission.bigSequence (); - // A non-zero value forces a file write. - int changes = 0; - std::vector ::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) { + Task before (*task); + + // Append to the specified task. + std::string question = format (STRING_CMD_APPEND_QUESTION, + task->id, + task->get ("description")); + modify_task_description_append (*task, modifications); - ++changes; - context.tdb2.modify (*task); - std::vector siblings = context.tdb2.siblings (*task); - std::vector ::iterator sibling; - for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling) + if (permission.confirmed (*task, taskDifferences (before, *task) + question)) { - Task before (*sibling); + context.tdb2.modify (*task); + ++count; - // Apply other deltas. - modify_task_description_append (*sibling, modifications); - ++changes; + if (context.verbose ("affected") || + context.config.getBoolean ("echo.command")) // Deprecated 2.0 + out << format (task->has ("parent") + ? STRING_CMD_APPEND_RECURRING + : STRING_CMD_APPEND_DELETING, + task->id, + task->get ("description")) + << "\n"; - if (taskDiff (before, *sibling)) + context.footnote (onProjectChange (*task, true)); + + // Append to siblings. + if (task->has ("parent")) { - if (changes && permission.confirmed (before, taskDifferences (before, *sibling) + "Proceed with change?")) + std::vector siblings = context.tdb2.siblings (*task); + if (siblings.size () && + confirm (STRING_CMD_APPEND_CONF_RECUR)) { - context.tdb2.modify (*sibling); + std::vector ::iterator sibling; + for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling) + { + modify_task_description_append (*sibling, modifications); + context.tdb2.modify (*sibling); + ++count; - if (context.verbose ("affected") || - context.config.getBoolean ("echo.command")) // Deprecated 2.0 - out << format (STRING_CMD_APPEND_DONE, sibling->id) - << "\n"; + if (context.verbose ("affected") || + context.config.getBoolean ("echo.command")) // Deprecated 2.0 + out << format (STRING_CMD_APPEND_RECURRING, + sibling->id, + sibling->get ("description")) + << "\n"; + } - if (before.get ("project") != sibling->get ("project")) - context.footnote (onProjectChange (before, *sibling)); - - ++count; + // Append to the parent + Task parent; + context.tdb2.get (task->get ("parent"), parent); + modify_task_description_append (parent, modifications); + context.tdb2.modify (parent); } } } + else + { + out << STRING_CMD_DELETE_NOT << "\n"; + rc = 1; + } } context.tdb2.commit ();