mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Fix item merge when merging tags and text fields
Also hard delete the remaining items. They are empty (have no attachments), because data is moved if possible. Doesn't make much sense to keep them, because restoring them isn't much useful.
This commit is contained in:
@ -58,7 +58,7 @@ object Merge {
|
|||||||
)
|
)
|
||||||
_ <- EitherT.right[Error](
|
_ <- EitherT.right[Error](
|
||||||
NonEmptyList.fromList(items.tail.map(_.id)) match {
|
NonEmptyList.fromList(items.tail.map(_.id)) match {
|
||||||
case Some(nel) => itemOps.setDeletedState(nel, collective)
|
case Some(nel) => itemOps.deleteItemMultiple(nel, collective)
|
||||||
case None => 0.pure[F]
|
case None => 0.pure[F]
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -146,7 +146,7 @@ object Merge {
|
|||||||
|
|
||||||
case CustomFieldType.Text =>
|
case CustomFieldType.Text =>
|
||||||
val text = fields.toList
|
val text = fields.toList
|
||||||
.map(fv => CustomFieldType.Text.parseValue(fv.value).toOption)
|
.flatMap(fv => CustomFieldType.Text.parseValue(fv.value).toOption)
|
||||||
.mkString(", ")
|
.mkString(", ")
|
||||||
fields.head.copy(value = CustomFieldType.Text.valueString(text))
|
fields.head.copy(value = CustomFieldType.Text.valueString(text))
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,21 @@ object RTagItem {
|
|||||||
def insert(v: RTagItem): ConnectionIO[Int] =
|
def insert(v: RTagItem): ConnectionIO[Int] =
|
||||||
DML.insert(T, T.all, fr"${v.tagItemId},${v.itemId},${v.tagId}")
|
DML.insert(T, T.all, fr"${v.tagItemId},${v.itemId},${v.tagId}")
|
||||||
|
|
||||||
def moveTags(from: Ident, to: Ident): ConnectionIO[Int] =
|
def moveTags(fromItem: Ident, toItem: Ident): ConnectionIO[Int] =
|
||||||
DML.update(T, T.itemId === from, DML.set(T.itemId.setTo(to)))
|
for {
|
||||||
|
both <- intersect(
|
||||||
|
Select(select(T.tagId), from(T), T.itemId === fromItem).distinct,
|
||||||
|
Select(select(T.tagId), from(T), T.itemId === toItem).distinct
|
||||||
|
).build
|
||||||
|
.query[Ident]
|
||||||
|
.to[List]
|
||||||
|
skipIds = NonEmptyList.fromList(both)
|
||||||
|
n <- DML.update(
|
||||||
|
T,
|
||||||
|
T.itemId === fromItem &&? skipIds.map(ids => T.tagId.notIn(ids)),
|
||||||
|
DML.set(T.itemId.setTo(toItem))
|
||||||
|
)
|
||||||
|
} yield n
|
||||||
|
|
||||||
def deleteItemTags(item: Ident): ConnectionIO[Int] =
|
def deleteItemTags(item: Ident): ConnectionIO[Int] =
|
||||||
DML.delete(T, T.itemId === item)
|
DML.delete(T, T.itemId === item)
|
||||||
|
Reference in New Issue
Block a user