Commands - duplicate

- Migrated handleDuplicate to CmdDuplicate.
This commit is contained in:
Paul Beckingham
2011-05-30 12:35:56 -04:00
parent 73e9f52793
commit 61c2e2b439
9 changed files with 186 additions and 101 deletions

View File

@@ -659,99 +659,6 @@ int handleModify (std::string& outs)
return 0;
}
////////////////////////////////////////////////////////////////////////////////
int handleDuplicate (std::string& outs)
{
int rc = 0;
std::stringstream out;
int count = 0;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
Filter filter;
context.tdb.loadPending (tasks, filter);
// Filter sequence.
context.filter.applySequence (tasks, context.sequence);
if (tasks.size () == 0)
{
std::cout << "No tasks specified.\n";
return 1;
}
foreach (task, tasks)
{
Task dup (*task);
dup.set ("uuid", uuid ()); // Needs a new UUID.
dup.setStatus (Task::pending);
dup.remove ("start"); // Does not inherit start date.
dup.remove ("end"); // Does not inherit end date.
// Recurring tasks are duplicated and downgraded to regular tasks.
if (task->getStatus () == Task::recurring)
{
dup.remove ("parent");
dup.remove ("recur");
dup.remove ("until");
dup.remove ("imak");
dup.remove ("imask");
out << "Note: task "
<< task->id
<< " was a recurring task. The new task is not.\n";
}
// Apply deltas.
deltaDescription (dup);
deltaTags (dup);
deltaAttributes (dup);
deltaSubstitutions (dup);
// A New task needs a new entry time.
char entryTime[16];
sprintf (entryTime, "%u", (unsigned int) time (NULL));
dup.set ("entry", entryTime);
// Only allow valid tasks.
dup.validate ();
context.tdb.add (dup);
if (context.config.getBoolean ("echo.command"))
out << "Duplicated "
<< task->id
<< " '"
<< task->get ("description")
<< "'.\n";
context.footnote (onProjectChange (dup));
++count;
}
if (tasks.size () == 0)
{
out << "No matches.\n";
rc = 1;
}
else if (context.config.getBoolean ("echo.command"))
{
#ifdef FEATURE_NEW_ID
// All this, just for an id number.
std::vector <Task> all;
Filter none;
context.tdb.loadPending (all, none);
out << "Created task " << context.tdb.nextId () << ".\n";
#endif
}
context.tdb.commit ();
context.tdb.unlock ();
outs = out.str ();
return rc;
}
////////////////////////////////////////////////////////////////////////////////
int deltaAppend (Task& task)
{