From 7ce2561c4b272916d66d0b1298699388730aed34 Mon Sep 17 00:00:00 2001 From: Michael J Rubinsky Date: Sat, 30 Jan 2016 12:12:00 -0500 Subject: [PATCH] Enforce completing subtasks before parent task. Bug: 12308 --- nag/app/controllers/SaveTask.php | 7 ++++++- nag/lib/Api.php | 10 ++++++++-- nag/lib/Task.php | 9 ++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/nag/app/controllers/SaveTask.php b/nag/app/controllers/SaveTask.php index 441a52235c8..d5b7b494efc 100644 --- a/nag/app/controllers/SaveTask.php +++ b/nag/app/controllers/SaveTask.php @@ -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(); + } $method = Nag::ITIP_UPDATE; $newid = array($info['task_id']); } else { diff --git a/nag/lib/Api.php b/nag/lib/Api.php index 6ff287db743..3e209af6d42 100644 --- a/nag/lib/Api.php +++ b/nag/lib/Api.php @@ -1131,7 +1131,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) { @@ -1146,7 +1147,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) { diff --git a/nag/lib/Task.php b/nag/lib/Task.php index 17dd2096ae6..9910957e8c6 100644 --- a/nag/lib/Task.php +++ b/nag/lib/Task.php @@ -618,10 +618,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;