/////////////////////////////////////////////////////////////////////////// Add the new task to the replica.
| 55 | //////////////////////////////////////////////////////////////////////////////// |
| 56 | // Add the new task to the replica. |
| 57 | void TDB2::add(Task& task) { |
| 58 | // Ensure the task is consistent, and provide defaults if necessary. |
| 59 | // bool argument to validate() is "applyDefault", to apply default values for |
| 60 | // properties not otherwise given. |
| 61 | task.validate(true); |
| 62 | |
| 63 | rust::Vec<tc::Operation> ops; |
| 64 | maybe_add_undo_point(ops); |
| 65 | |
| 66 | auto uuid = task.get("uuid"); |
| 67 | changes[uuid] = task; |
| 68 | tc::Uuid tcuuid = tc::uuid_from_string(uuid); |
| 69 | |
| 70 | // run hooks for this new task |
| 71 | Context::getContext().hooks.onAdd(task); |
| 72 | |
| 73 | auto taskdata = tc::create_task(tcuuid, ops); |
| 74 | |
| 75 | // add the task attributes |
| 76 | for (auto& attr : task.all()) { |
| 77 | // TaskChampion does not store uuid or id in the task data |
| 78 | if (attr == "uuid" || attr == "id") { |
| 79 | continue; |
| 80 | } |
| 81 | |
| 82 | taskdata->update(attr, task.get(attr), ops); |
| 83 | } |
| 84 | replica()->commit_operations(std::move(ops)); |
| 85 | |
| 86 | invalidate_cached_info(); |
| 87 | |
| 88 | // get the ID that was assigned to this task |
| 89 | auto id = working_set()->by_uuid(tcuuid); |
| 90 | if (id > 0) { |
| 91 | task.id = id; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | //////////////////////////////////////////////////////////////////////////////// |
| 96 | // Modify the task in storage to match the given task. |
nothing calls this directly
no test coverage detected