From c0c244251c574693ed3a54741a8b653b0a29b050 Mon Sep 17 00:00:00 2001 From: To-om Date: Mon, 7 Feb 2022 08:30:34 +0100 Subject: [PATCH] #2335 Fix schema initialisation --- ScalliGraph | 2 +- .../thp/thehive/migration/th4/Output.scala | 31 +++++++++++-------- .../services/IntegrityCheckActor.scala | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/ScalliGraph b/ScalliGraph index 5c0d2b13ec..ad52dd66ba 160000 --- a/ScalliGraph +++ b/ScalliGraph @@ -1 +1 @@ -Subproject commit 5c0d2b13ece711ca2b9e254e0f103c229eeea768 +Subproject commit ad52dd66bad873f7cff2dd0e763c95099c7822fd diff --git a/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala b/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala index 9e30053e43..605f1f5dbc 100644 --- a/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala +++ b/migration/src/main/scala/org/thp/thehive/migration/th4/Output.scala @@ -164,21 +164,25 @@ class Output @Inject() ( override def startMigration(): Try[Unit] = { implicit val authContext: AuthContext = LocalUserSrv.getSystemAuthContext - if (resumeMigration) { + if (resumeMigration) db.addSchemaIndexes(theHiveSchema) .flatMap(_ => db.addSchemaIndexes(cortexSchema)) - db.roTransaction { implicit graph => - profiles ++= profileSrv.startTraversal.toSeq.map(p => p.name -> p) - organisations ++= organisationSrv.startTraversal.toSeq.map(o => o.name -> o) - users ++= userSrv.startTraversal.toSeq.map(u => u.name -> u) - impactStatuses ++= impactStatusSrv.startTraversal.toSeq.map(s => s.value -> s) - resolutionStatuses ++= resolutionStatusSrv.startTraversal.toSeq.map(s => s.value -> s) - observableTypes ++= observableTypeSrv.startTraversal.toSeq.map(o => o.name -> o) - customFields ++= customFieldSrv.startTraversal.toSeq.map(c => c.name -> c) - caseTemplates ++= caseTemplateSrv.startTraversal.toSeq.map(c => c.name -> c) - } - Success(()) - } else + .flatMap { _ => + db.roTransaction { implicit graph => + profiles ++= profileSrv.startTraversal.toSeq.map(p => p.name -> p) + organisations ++= organisationSrv.startTraversal.toSeq.map(o => o.name -> o) + users ++= userSrv.startTraversal.toSeq.map(u => u.name -> u) + impactStatuses ++= impactStatusSrv.startTraversal.toSeq.map(s => s.value -> s) + resolutionStatuses ++= resolutionStatusSrv.startTraversal.toSeq.map(s => s.value -> s) + observableTypes ++= observableTypeSrv.startTraversal.toSeq.map(o => o.name -> o) + customFields ++= customFieldSrv.startTraversal.toSeq.map(c => c.name -> c) + caseTemplates ++= caseTemplateSrv.startTraversal.toSeq.map(c => c.name -> c) + } + Success(()) + } + else { + db.setVersion(theHiveSchema.name, theHiveSchema.operations.lastVersion) + db.setVersion(cortexSchema.name, cortexSchema.operations.lastVersion) db.tryTransaction { implicit graph => profiles ++= Profile.initialValues.flatMap(p => profileSrv.createEntity(p).map(p.name -> _).toOption) resolutionStatuses ++= ResolutionStatus.initialValues.flatMap(p => resolutionStatusSrv.createEntity(p).map(p.value -> _).toOption) @@ -188,6 +192,7 @@ class Output @Inject() ( users ++= User.initialValues.flatMap(p => userSrv.createEntity(p).map(p.login -> _).toOption) Success(()) } + } } override def endMigration(): Try[Unit] = { diff --git a/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala b/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala index d69f303239..988aab42f4 100644 --- a/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala +++ b/thehive/app/org/thp/thehive/services/IntegrityCheckActor.scala @@ -221,7 +221,7 @@ object IntegrityCheck { case FinishGlobal(name, cancel, result) => logger.info(s"End of global check of $name${if (cancel) " (cancelled)" else ""}:${result.map(kv => s"\n ${kv._1}: ${kv._2}").mkString}") val state = states.getOrElse(name, CheckState.empty) - val newState = state.copy(dedupStats = state.dedupStats + result, globalCheckRequested = false, globalCheckIsRunning = false) + val newState = state.copy(globalStats = state.globalStats + result, globalCheckRequested = false, globalCheckIsRunning = false) onMessage(states + (name -> newState)) case CancelCheck =>