From 6c7aecc2a6b665299514e4838f5cbc8b26ac023e Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sun, 6 Sep 2015 00:20:03 +0200 Subject: [PATCH] CmdImport: Neglect attributes with dynamic default values If not explicitly stated on import, values with default dynamic values (such as modified, entry or end) can produce a false notion of incoming 'modified' data, where the only difference between the data in the database and data being imported is that the dynamic defaults differ, since they have been generated at different times. Solve the issue by neglecting the attributes with dynamic defaults, if they have been generated. --- src/commands/CmdImport.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/commands/CmdImport.cpp b/src/commands/CmdImport.cpp index 6ec292aa5..44cdcc136 100644 --- a/src/commands/CmdImport.cpp +++ b/src/commands/CmdImport.cpp @@ -176,17 +176,39 @@ void CmdImport::importSingleTask (json::object* obj) { // Parse the whole thing, validate the data. Task task (obj); + + bool hasGeneratedEntry = not task.has ("entry"); + bool hasExplicitEnd = task.has ("end"); + task.validate (); + bool hasGeneratedEnd = not hasExplicitEnd and task.has ("end"); + // Check whether the imported task is new or a modified existing task. Task before; if (context.tdb2.get (task.get ("uuid"), before)) { - // "modified:" is automatically set to the current time when a task is - // changed. If the imported task has a modification timestamp we need - // to ignore it in task comparison in order to check for meaningful - // differences. Setting it to the previous value achieves just that. + // We need to neglect updates from attributes with dynamic defaults + // unless they have been explicitly specified on import. + // + // There are three attributes with dynamic defaults, besites uuid: + // - modified: Ignored in any case. + // - entry: Ignored if generated. + // - end: Ignored if generated. + + // The 'modified' attribute is ignored in any case, since if it + // were the only difference between the tasks, it would have been + // neglected anyway, since it is bumped on each modification. task.set ("modified", before.get ("modified")); + + // Other generated values are replaced by values from existing task, + // so that they are ignored on comparison. + if (hasGeneratedEntry) + task.set ("entry", before.get ("entry")); + + if (hasGeneratedEnd) + task.set ("end", before.get ("end")); + if (before != task) { CmdModify modHelper;