Skip to content

Commit

Permalink
fix task bundle reset to setup up tasks added back with the proper re…
Browse files Browse the repository at this point in the history
…view_status needed for reviewing
  • Loading branch information
CollinBeczak committed Mar 11, 2024
1 parent 96668fc commit 1e31724
Showing 1 changed file with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ package org.maproulette.framework.repository
import org.slf4j.LoggerFactory

import anorm.ToParameterValue
import anorm._
import anorm.SqlParser.scalar

import org.maproulette.cache.CacheManager
import anorm._, postgresql._
import javax.inject.{Inject, Singleton}
Expand Down Expand Up @@ -201,13 +204,29 @@ class TaskBundleRepository @Inject() (
)
.executeUpdate()

// Define the fallback value
val fallbackStatus: Int = 0

// Retrieve the status of the primary task
val primaryTaskStatus = SQL(
val primaryTaskStatus: Int = SQL(
"""SELECT status FROM tasks WHERE id = {primaryTaskId}"""
).on(
"primaryTaskId" -> primaryTaskId
)
.as(SqlParser.scalar[Int].single)
.as(scalar[Int].singleOpt)
.getOrElse(fallbackStatus)

// Define the fallback value for review status
val fallbackReviewStatus: Int = 0

// Retrieve the review status of the primary task
val primaryTaskReviewStatus: Int = SQL(
"""SELECT review_status FROM task_review WHERE id = {primaryTaskId}"""
).on(
"primaryTaskId" -> primaryTaskId
)
.as(scalar[Int].singleOpt)
.getOrElse(fallbackReviewStatus)

val lockedTasks = this.withListLocking(user, Some(TaskType())) { () =>
this.taskDAL.retrieveListById(-1, 0)(tasksToAdd)
Expand All @@ -222,14 +241,17 @@ class TaskBundleRepository @Inject() (
SQL(
"""UPDATE tasks
SET status = {primaryTaskStatus}
WHERE bundle_id = {bundleId}
WHERE id = {taskId}
"""
).on(
"primaryTaskStatus" -> primaryTaskStatus,
"bundleId" -> bundleId
"taskId" -> task.id
)
.executeUpdate()

SQL"""INSERT INTO task_review (task_id, review_status)
VALUES (${task.id}, ${primaryTaskReviewStatus})""".executeUpdate()

this.cacheManager.withOptionCaching { () =>
Some(
task.copy(
Expand Down

0 comments on commit 1e31724

Please sign in to comment.