mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
CmdPurge: Handle child tasks of recurrence templates
This commit is contained in:
parent
4465b48f75
commit
ec38b3afd8
3 changed files with 57 additions and 0 deletions
|
@ -31,6 +31,7 @@
|
|||
#include <i18n.h>
|
||||
#include <main.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
|
@ -54,10 +55,12 @@ CmdPurge::CmdPurge ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Purges the task, while taking care of:
|
||||
// - dependencies on this task
|
||||
// - child tasks
|
||||
void CmdPurge::purgeTask (Task& task, int& count)
|
||||
{
|
||||
context.tdb2.purge (task);
|
||||
handleDeps (task);
|
||||
handleChildren (task, count);
|
||||
count++;
|
||||
}
|
||||
|
||||
|
@ -80,6 +83,56 @@ void CmdPurge::handleDeps (Task& task)
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Makes sure that with any recurrence parent are all the child tasks removed
|
||||
// as well. If user chooses not to, the whole command is aborted.
|
||||
void CmdPurge::handleChildren (Task& task, int& count)
|
||||
{
|
||||
// If this is not a recurrence parent, we have no job here
|
||||
if (!task.has ("mask"))
|
||||
return;
|
||||
|
||||
std::string uuid = task.get ("uuid");
|
||||
std::vector<Task> children;
|
||||
|
||||
// Find all child tasks
|
||||
for (auto& childConst: context.tdb2.all_tasks ())
|
||||
{
|
||||
Task& child = const_cast<Task&> (childConst);
|
||||
|
||||
if (child.get ("parent") == uuid)
|
||||
{
|
||||
if (child.getStatus () != Task::deleted)
|
||||
// In case any child task is not deleted, bail out
|
||||
throw format (STRING_CMD_PURGE_NDEL_CHILD,
|
||||
task.get ("description"),
|
||||
child.identifier (true));
|
||||
else
|
||||
children.push_back (child);
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no children, our job is done
|
||||
if (children.empty ())
|
||||
return;
|
||||
|
||||
// Ask for confirmation to purge them, if needed
|
||||
std::string question = format (STRING_CMD_PURGE_CONFIRM_R,
|
||||
task.get ("description"),
|
||||
children.size ());
|
||||
|
||||
if (context.config.getBoolean ("recurrence.confirmation") ||
|
||||
(context.config.get ("recurrence.confirmation") == "prompt"
|
||||
&& confirm (question)))
|
||||
{
|
||||
for (auto& child: children)
|
||||
purgeTask (child, count);
|
||||
}
|
||||
else
|
||||
throw std::string (STRING_CMD_PURGE_ABRT);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdPurge::execute (std::string&)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,7 @@ class CmdPurge : public Command
|
|||
{
|
||||
private:
|
||||
void purgeTask (Task& task, int& count);
|
||||
void handleChildren (Task& task, int& count);
|
||||
void handleDeps (Task& task);
|
||||
public:
|
||||
CmdPurge ();
|
||||
|
|
|
@ -397,9 +397,12 @@
|
|||
#define STRING_CMD_DUPLICATE_N "Duplicated {1} tasks."
|
||||
|
||||
#define STRING_CMD_PURGE_USAGE "Removes the specified tasks from the data files. Causes permanent loss of data."
|
||||
#define STRING_CMD_PURGE_ABRT "Purge operation aborted."
|
||||
#define STRING_CMD_PURGE_1 "Purged {1} task."
|
||||
#define STRING_CMD_PURGE_N "Purged {1} tasks."
|
||||
#define STRING_CMD_PURGE_CONFIRM "Permanently remove task {1} '{2}'?"
|
||||
#define STRING_CMD_PURGE_CONFIRM_R "Task '{1}' is a recurrence template. All its {2} deleted children tasks will be purged as well. Continue?"
|
||||
#define STRING_CMD_PURGE_NDEL_CHILD "Task '{1}' is a recurrence template. Its child task {2} must be deleted before it can be purged."
|
||||
|
||||
#define STRING_CMD_START_USAGE "Marks specified task as started"
|
||||
#define STRING_CMD_START_NO "Task not started."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue