Related to bug #649

- You can no longer directly complete or delete parent recurring tasks.
This commit is contained in:
Paul Beckingham 2011-02-12 15:30:05 -05:00
parent 6608cbf287
commit f93273ef23
2 changed files with 77 additions and 64 deletions

View file

@ -1573,54 +1573,78 @@ int handleDelete (std::string& outs)
foreach (task, tasks) foreach (task, tasks)
{ {
if (context.hooks.trigger ("pre-delete", *task)) if (task->getStatus () == Task::pending ||
task->getStatus () == Task::waiting)
{ {
std::stringstream question; if (context.hooks.trigger ("pre-delete", *task))
question << "Permanently delete task "
<< task->id
<< " '"
<< task->get ("description")
<< "'?";
if (!context.config.getBoolean ("confirmation") || confirm (question.str ()))
{ {
// Check for the more complex case of a recurring task. If this is a std::stringstream question;
// recurring task, get confirmation to delete them all. question << "Permanently delete task "
std::string parent = task->get ("parent"); << task->id
if (parent != "") << " '"
<< task->get ("description")
<< "'?";
if (!context.config.getBoolean ("confirmation") || confirm (question.str ()))
{ {
if (confirm ("This is a recurring task. Do you want to delete all pending recurrences of this same task?")) // Check for the more complex case of a recurring task. If this is a
// recurring task, get confirmation to delete them all.
std::string parent = task->get ("parent");
if (parent != "")
{ {
// Scan all pending tasks for siblings of this task, and the parent if (confirm ("This is a recurring task. Do you want to delete all pending recurrences of this same task?"))
// itself, and delete them.
foreach (sibling, all)
{ {
if (sibling->get ("parent") == parent || // Scan all pending tasks for siblings of this task, and the parent
sibling->get ("uuid") == parent) // itself, and delete them.
foreach (sibling, all)
{ {
sibling->setStatus (Task::deleted); if (sibling->get ("parent") == parent ||
sibling->get ("uuid") == parent)
{
sibling->setStatus (Task::deleted);
// Don't want a 'delete' to clobber the end date that may have // Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command. // been written by a 'done' command.
if (! sibling->has ("end")) if (! sibling->has ("end"))
sibling->set ("end", endTime); sibling->set ("end", endTime);
context.tdb.update (*sibling); context.tdb.update (*sibling);
if (context.config.getBoolean ("echo.command")) if (context.config.getBoolean ("echo.command"))
out << "Deleting recurring task " out << "Deleting recurring task "
<< sibling->id << sibling->id
<< " '" << " '"
<< sibling->get ("description") << sibling->get ("description")
<< "'.\n"; << "'.\n";
}
} }
} }
else
{
// Update mask in parent.
task->setStatus (Task::deleted);
updateRecurrenceMask (all, *task);
// Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command.
if (! task->has ("end"))
task->set ("end", endTime);
context.tdb.update (*task);
out << "Deleting recurring task "
<< task->id
<< " '"
<< task->get ("description")
<< "'.\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task));
}
} }
else else
{ {
// Update mask in parent.
task->setStatus (Task::deleted); task->setStatus (Task::deleted);
updateRecurrenceMask (all, *task);
// Don't want a 'delete' to clobber the end date that may have // Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command. // been written by a 'done' command.
@ -1629,11 +1653,12 @@ int handleDelete (std::string& outs)
context.tdb.update (*task); context.tdb.update (*task);
out << "Deleting recurring task " if (context.config.getBoolean ("echo.command"))
<< task->id out << "Deleting task "
<< " '" << task->id
<< task->get ("description") << " '"
<< "'.\n"; << task->get ("description")
<< "'.\n";
dependencyChainOnComplete (*task); dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task)); context.footnote (onProjectChange (*task));
@ -1641,33 +1666,21 @@ int handleDelete (std::string& outs)
} }
else else
{ {
task->setStatus (Task::deleted); out << "Task not deleted.\n";
rc = 1;
// Don't want a 'delete' to clobber the end date that may have
// been written by a 'done' command.
if (! task->has ("end"))
task->set ("end", endTime);
context.tdb.update (*task);
if (context.config.getBoolean ("echo.command"))
out << "Deleting task "
<< task->id
<< " '"
<< task->get ("description")
<< "'.\n";
dependencyChainOnComplete (*task);
context.footnote (onProjectChange (*task));
} }
}
else
{
out << "Task not deleted.\n";
rc = 1;
}
context.hooks.trigger ("post-delete", *task); context.hooks.trigger ("post-delete", *task);
}
}
else
{
out << "Task "
<< task->id
<< " '"
<< task->get ("description")
<< "' is neither pending nor waiting.\n";
rc = 1;
} }
} }

View file

@ -47,7 +47,7 @@ qx{../src/task rc:bug.rc add Test due:3d rec:1w};
# Result: Immediately delete the created task # Result: Immediately delete the created task
my $output = qx{../src/task rc:bug.rc done 1}; my $output = qx{../src/task rc:bug.rc done 1};
like ($output, qr/Completed/ms, 'New recurring task can be immediately deleted.'); unlike ($output, qr/Completed/ms, 'New recurring task cannot be immediately completed.');
# Cleanup. # Cleanup.
unlink 'pending.data'; unlink 'pending.data';