Skip to content

Commit 1e31724

Browse files
committed
fix task bundle reset to setup up tasks added back with the proper review_status needed for reviewing
1 parent 96668fc commit 1e31724

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

app/org/maproulette/framework/repository/TaskBundleRepository.scala

+26-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ package org.maproulette.framework.repository
88
import org.slf4j.LoggerFactory
99

1010
import anorm.ToParameterValue
11+
import anorm._
12+
import anorm.SqlParser.scalar
13+
1114
import org.maproulette.cache.CacheManager
1215
import anorm._, postgresql._
1316
import javax.inject.{Inject, Singleton}
@@ -201,13 +204,29 @@ class TaskBundleRepository @Inject() (
201204
)
202205
.executeUpdate()
203206

207+
// Define the fallback value
208+
val fallbackStatus: Int = 0
209+
204210
// Retrieve the status of the primary task
205-
val primaryTaskStatus = SQL(
211+
val primaryTaskStatus: Int = SQL(
206212
"""SELECT status FROM tasks WHERE id = {primaryTaskId}"""
207213
).on(
208214
"primaryTaskId" -> primaryTaskId
209215
)
210-
.as(SqlParser.scalar[Int].single)
216+
.as(scalar[Int].singleOpt)
217+
.getOrElse(fallbackStatus)
218+
219+
// Define the fallback value for review status
220+
val fallbackReviewStatus: Int = 0
221+
222+
// Retrieve the review status of the primary task
223+
val primaryTaskReviewStatus: Int = SQL(
224+
"""SELECT review_status FROM task_review WHERE id = {primaryTaskId}"""
225+
).on(
226+
"primaryTaskId" -> primaryTaskId
227+
)
228+
.as(scalar[Int].singleOpt)
229+
.getOrElse(fallbackReviewStatus)
211230

212231
val lockedTasks = this.withListLocking(user, Some(TaskType())) { () =>
213232
this.taskDAL.retrieveListById(-1, 0)(tasksToAdd)
@@ -222,14 +241,17 @@ class TaskBundleRepository @Inject() (
222241
SQL(
223242
"""UPDATE tasks
224243
SET status = {primaryTaskStatus}
225-
WHERE bundle_id = {bundleId}
244+
WHERE id = {taskId}
226245
"""
227246
).on(
228247
"primaryTaskStatus" -> primaryTaskStatus,
229-
"bundleId" -> bundleId
248+
"taskId" -> task.id
230249
)
231250
.executeUpdate()
232251

252+
SQL"""INSERT INTO task_review (task_id, review_status)
253+
VALUES (${task.id}, ${primaryTaskReviewStatus})""".executeUpdate()
254+
233255
this.cacheManager.withOptionCaching { () =>
234256
Some(
235257
task.copy(

0 commit comments

Comments
 (0)