Skip to content

Commit 4c1587e

Browse files
authored
Merge pull request #1595 from hashtopolis/1593-bug-taskwrappers-weird-state-when-tasks-have-been-deleted
1593 bug taskwrappers weird state when tasks have been deleted
2 parents d68b703 + 9e072b7 commit 4c1587e

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

src/inc/apiv2/common/AbstractModelAPI.class.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,9 @@ protected function updateToManyRelationship(Request $request, array $data, array
15261526
if ($relationKey == null) {
15271527
throw new HttpError("Relation does not exist!");
15281528
}
1529+
if ($relation["readonly"] === true) {
1530+
throw new HttpError("This relationship is readonly");
1531+
}
15291532

15301533
$relationType = $relation['relationType'];
15311534
$features = $this->getFeaturesOther($relationType);
@@ -1593,7 +1596,10 @@ public function postToManyRelationshipLink(Request $request, Response $response,
15931596
$relation = $this->getToManyRelationships()[$args['relation']];
15941597
$relationKey = $relation['relationKey'];
15951598
if ($relationKey == null) {
1596-
throw new HttpError("Relation does not exist!");
1599+
throw new HttpError('Relation does not exist!');
1600+
}
1601+
if ($relation['readonly'] === true) {
1602+
throw new HttpError('This relationship is readonly');
15971603
}
15981604

15991605
// check if the object queried exists

src/inc/apiv2/model/taskwrappers.routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public static function getToManyRelationships(): array {
9292

9393
'relationType' => Task::class,
9494
'relationKey' => Task::TASK_WRAPPER_ID,
95+
'readonly' => true // Not allowed to change tasks of a taskwrapper
9596
],
9697
];
9798
}

src/inc/utils/TaskUtils.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,6 +1140,11 @@ public static function deleteTask($task) {
11401140
$qF = new QueryFilter(Chunk::TASK_ID, $task->getId(), "=");
11411141
Factory::getChunkFactory()->massDeletion([Factory::FILTER => $qF]);
11421142
Factory::getTaskFactory()->delete($task);
1143+
$taskWrapper = Factory::getTaskWrapperFactory()->get($task->getTaskWrapperId());
1144+
// If last task of taskwrapper has been deleted, delete taskwrapper aswell
1145+
if (count(self::getTasksOfWrapper($taskWrapper->getId())) === 0) {
1146+
Factory::getTaskWrapperFactory()->delete($taskWrapper);
1147+
}
11431148
LockUtils::deleteLockFile($task->getId());
11441149
}
11451150

0 commit comments

Comments
 (0)