Skip to content

Commit

Permalink
Enforce completing subtasks before parent task.
Browse files Browse the repository at this point in the history
Bug: 12308
  • Loading branch information
mrubinsk committed Jan 30, 2016
1 parent a76ee17 commit a639379
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 6 additions & 1 deletion nag/app/controllers/SaveTask.php
Expand Up @@ -72,7 +72,12 @@ public function processRequest(Horde_Controller_Request $request, Horde_Controll
->getInstance('Nag_Factory_Driver')
->create($info['old_tasklist']);
$info['tasklist'] = $info['tasklist_id'];
$result = $storage->modify($info['task_id'], $info);
try {
$storage->modify($info['task_id'], $info);
} catch (Nag_Exception $e) {
$notification->push(sprintf(_("There was a problem saving the task: %s."), $e->getMessage()), 'horde.error');
Horde::url('list.php', true)->redirect();
}
} else {
/* Check permissions. */
$perms = $this->getInjector()->getInstance('Horde_Core_Perms');
Expand Down
10 changes: 8 additions & 2 deletions nag/lib/Api.php
Expand Up @@ -970,7 +970,8 @@ public function quickAdd($text, $tasklist = null)
* @param string $tasklist_id The tasklist that contains the task.
*
* @return boolean|string True if the task has been toggled, a due date if
* there are still incomplete recurrences.
* there are still incomplete recurrences, otherwise
* false.
*/
public function toggleCompletion($task_id, $tasklist_id)
{
Expand All @@ -985,7 +986,12 @@ public function toggleCompletion($task_id, $tasklist_id)
}
$task = Nag::getTask($tasklist_id, $task_id);
$completed = $task->completed;
$task->toggleComplete();
try {
$task->toggleComplete();
} catch (Nag_Exception $e) {
Horde::log($e->getMessage(), 'DEBUG');
return false;
}
$task->save();
$due = $task->getNextDue();
if ($task->completed == $completed) {
Expand Down
9 changes: 8 additions & 1 deletion nag/lib/Task.php
Expand Up @@ -574,10 +574,17 @@ public function recurs()

/**
* Toggles completion status of this task. Moves a recurring task
* to the next occurence on completion.
* to the next occurence on completion. Enforces the rule that sub
* tasks must be completed before parent tasks.
*
*
*/
public function toggleComplete()
{
$this->loadChildren();
if (!$this->completed && !$this->childrenCompleted()) {
throw new Nag_Exception(_("Must complete all children tasks."));
}
if ($this->completed) {
$this->completed_date = null;
$this->completed = false;
Expand Down

0 comments on commit a639379

Please sign in to comment.