summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--app/Model/SubtaskTimeTracking.php19
-rw-r--r--app/Subscriber/SubtaskTimeTrackingSubscriber.php1
-rw-r--r--doc/subtasks.markdown2
-rw-r--r--tests/units/Model/SubtaskTimeTrackingTest.php26
5 files changed, 24 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog
index 441fc686..76b30f61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -26,6 +26,7 @@ Bug fixes:
* Fix typo in template that prevent the Gitlab oauth link to be displayed
* Fix Markdown preview links focus
* Avoid dropdown menu to be truncated inside a column with scrolling
+* Deleting subtask doesn't update task time tracking
Version 1.0.18
--------------
diff --git a/app/Model/SubtaskTimeTracking.php b/app/Model/SubtaskTimeTracking.php
index 997031e8..56998769 100644
--- a/app/Model/SubtaskTimeTracking.php
+++ b/app/Model/SubtaskTimeTracking.php
@@ -339,20 +339,7 @@ class SubtaskTimeTracking extends Base
*/
public function updateTaskTimeTracking($task_id)
{
- $result = $this->calculateSubtaskTime($task_id);
- $values = array();
-
- if ($result['total_spent'] > 0) {
- $values['time_spent'] = $result['total_spent'];
- }
-
- if ($result['total_estimated'] > 0) {
- $values['time_estimated'] = $result['total_estimated'];
- }
-
- if (empty($values)) {
- return true;
- }
+ $values = $this->calculateSubtaskTime($task_id);
return $this->db
->table(Task::TABLE)
@@ -373,8 +360,8 @@ class SubtaskTimeTracking extends Base
->table(Subtask::TABLE)
->eq('task_id', $task_id)
->columns(
- 'SUM(time_spent) AS total_spent',
- 'SUM(time_estimated) AS total_estimated'
+ 'SUM(time_spent) AS time_spent',
+ 'SUM(time_estimated) AS time_estimated'
)
->findOne();
}
diff --git a/app/Subscriber/SubtaskTimeTrackingSubscriber.php b/app/Subscriber/SubtaskTimeTrackingSubscriber.php
index e45b2c93..2d3b5f99 100644
--- a/app/Subscriber/SubtaskTimeTrackingSubscriber.php
+++ b/app/Subscriber/SubtaskTimeTrackingSubscriber.php
@@ -12,6 +12,7 @@ class SubtaskTimeTrackingSubscriber extends \Core\Base implements EventSubscribe
{
return array(
Subtask::EVENT_CREATE => array('updateTaskTime', 0),
+ Subtask::EVENT_DELETE => array('updateTaskTime', 0),
Subtask::EVENT_UPDATE => array(
array('logStartEnd', 10),
array('updateTaskTime', 0),
diff --git a/doc/subtasks.markdown b/doc/subtasks.markdown
index 3c9e8350..e1acd98c 100644
--- a/doc/subtasks.markdown
+++ b/doc/subtasks.markdown
@@ -40,5 +40,5 @@ Subtask timer
- Each time a subtask is in progress, the timer is also started. The timer can be started and stopped at any time.
- The timer records the time spent on the subtask automatically. You can also change manually the value of the time spent field when you edit a subtask.
- The time calculated is rounded to the nearest quarter. This information is recorded in a separate table.
-- The task time spent is updated automatically according to the sum of all subtasks time spent.
+- The task time spent and time estimated are updated automatically according to the sum of all subtasks.
diff --git a/tests/units/Model/SubtaskTimeTrackingTest.php b/tests/units/Model/SubtaskTimeTrackingTest.php
index ed286287..f68f283d 100644
--- a/tests/units/Model/SubtaskTimeTrackingTest.php
+++ b/tests/units/Model/SubtaskTimeTrackingTest.php
@@ -151,8 +151,8 @@ class SubtaskTimeTrackingTest extends Base
$time = $st->calculateSubtaskTime(1);
$this->assertNotempty($time);
$this->assertCount(2, $time);
- $this->assertEquals(3.3, $time['total_spent'], 'Total spent', 0.01);
- $this->assertEquals(7.7, $time['total_estimated'], 'Total estimated', 0.01);
+ $this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
}
public function testUpdateSubtaskTimeSpent()
@@ -184,13 +184,13 @@ class SubtaskTimeTrackingTest extends Base
$time = $st->calculateSubtaskTime(1);
$this->assertNotempty($time);
- $this->assertEquals(4.2, $time['total_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
+ $this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
$time = $st->calculateSubtaskTime(2);
$this->assertNotempty($time);
- $this->assertEquals(0, $time['total_spent'], 'Total spent', 0.01);
- $this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
+ $this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
+ $this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
}
public function testUpdateTaskTimeTracking()
@@ -205,7 +205,7 @@ class SubtaskTimeTrackingTest extends Base
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
- $this->assertEquals(3, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
+ $this->assertEquals(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
@@ -231,8 +231,18 @@ class SubtaskTimeTrackingTest extends Base
$task = $tf->getById(3);
$this->assertNotEmpty($task);
- $this->assertEquals(4, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_estimated']);
$this->assertEquals(8, $task['time_spent']);
+
+ $this->assertTrue($s->remove(3));
+ $this->assertTrue($s->remove(4));
+
+ $st->updateTaskTimeTracking(2);
+
+ $task = $tf->getById(2);
+ $this->assertNotEmpty($task);
+ $this->assertEquals(0, $task['time_estimated']);
+ $this->assertEquals(0, $task['time_spent']);
}
public function testGetCalendarEvents()