mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 18:38:26 +00:00
Change "empty trash" settings for a collective and submit the job
This commit is contained in:
@ -0,0 +1,6 @@
|
||||
CREATE TABLE "empty_trash_setting" (
|
||||
"cid" varchar(254) not null primary key,
|
||||
"schedule" varchar(254) not null,
|
||||
"created" timestamp not null,
|
||||
foreign key ("cid") references "collective"("cid")
|
||||
);
|
@ -0,0 +1,6 @@
|
||||
CREATE TABLE `empty_trash_setting` (
|
||||
`cid` varchar(254) not null primary key,
|
||||
`schedule` varchar(254) not null,
|
||||
`created` timestamp not null,
|
||||
foreign key (`cid`) references `collective`(`cid`)
|
||||
);
|
@ -0,0 +1,6 @@
|
||||
CREATE TABLE "empty_trash_setting" (
|
||||
"cid" varchar(254) not null primary key,
|
||||
"schedule" varchar(254) not null,
|
||||
"created" timestamp not null,
|
||||
foreign key ("cid") references "collective"("cid")
|
||||
);
|
@ -13,6 +13,7 @@ import docspell.common._
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
|
||||
import com.github.eikek.calev._
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
@ -73,17 +74,21 @@ object RCollective {
|
||||
T.integration.setTo(settings.integrationEnabled)
|
||||
)
|
||||
)
|
||||
cls <-
|
||||
Timestamp
|
||||
.current[ConnectionIO]
|
||||
.map(now => settings.classifier.map(_.toRecord(cid, now)))
|
||||
now <- Timestamp.current[ConnectionIO]
|
||||
cls = settings.classifier.map(_.toRecord(cid, now))
|
||||
n2 <- cls match {
|
||||
case Some(cr) =>
|
||||
RClassifierSetting.update(cr)
|
||||
case None =>
|
||||
RClassifierSetting.delete(cid)
|
||||
}
|
||||
} yield n1 + n2
|
||||
n3 <- settings.emptyTrash match {
|
||||
case Some(trashSchedule) =>
|
||||
REmptyTrashSetting.update(REmptyTrashSetting(cid, trashSchedule, now))
|
||||
case None =>
|
||||
REmptyTrashSetting.delete(cid)
|
||||
}
|
||||
} yield n1 + n2 + n3
|
||||
|
||||
// this hides categories that have been deleted in the meantime
|
||||
// they are finally removed from the json array once the learn classifier task is run
|
||||
@ -99,6 +104,7 @@ object RCollective {
|
||||
import RClassifierSetting.stringListMeta
|
||||
val c = RCollective.as("c")
|
||||
val cs = RClassifierSetting.as("cs")
|
||||
val es = REmptyTrashSetting.as("es")
|
||||
|
||||
Select(
|
||||
select(
|
||||
@ -107,9 +113,10 @@ object RCollective {
|
||||
cs.schedule.s,
|
||||
cs.itemCount.s,
|
||||
cs.categories.s,
|
||||
cs.listType.s
|
||||
cs.listType.s,
|
||||
es.schedule.s
|
||||
),
|
||||
from(c).leftJoin(cs, cs.cid === c.id),
|
||||
from(c).leftJoin(cs, cs.cid === c.id).leftJoin(es, es.cid === c.id),
|
||||
c.id === coll
|
||||
).build.query[Settings].option
|
||||
}
|
||||
@ -160,7 +167,8 @@ object RCollective {
|
||||
case class Settings(
|
||||
language: Language,
|
||||
integrationEnabled: Boolean,
|
||||
classifier: Option[RClassifierSetting.Classifier]
|
||||
classifier: Option[RClassifierSetting.Classifier],
|
||||
emptyTrash: Option[CalEvent]
|
||||
)
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2020 Docspell Contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package docspell.store.records
|
||||
|
||||
import cats.data.NonEmptyList
|
||||
import cats.implicits._
|
||||
|
||||
import docspell.common._
|
||||
import docspell.store.qb.DSL._
|
||||
import docspell.store.qb._
|
||||
|
||||
import com.github.eikek.calev._
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
final case class REmptyTrashSetting(
|
||||
cid: Ident,
|
||||
schedule: CalEvent,
|
||||
created: Timestamp
|
||||
)
|
||||
|
||||
object REmptyTrashSetting {
|
||||
|
||||
final case class Table(alias: Option[String]) extends TableDef {
|
||||
val tableName = "empty_trash_setting"
|
||||
|
||||
val cid = Column[Ident]("cid", this)
|
||||
val schedule = Column[CalEvent]("schedule", this)
|
||||
val created = Column[Timestamp]("created", this)
|
||||
val all = NonEmptyList.of[Column[_]](cid, schedule, created)
|
||||
}
|
||||
|
||||
val T = Table(None)
|
||||
def as(alias: String): Table =
|
||||
Table(Some(alias))
|
||||
|
||||
def insert(v: REmptyTrashSetting): ConnectionIO[Int] =
|
||||
DML.insert(
|
||||
T,
|
||||
T.all,
|
||||
fr"${v.cid},${v.schedule},${v.created}"
|
||||
)
|
||||
|
||||
def update(v: REmptyTrashSetting): ConnectionIO[Int] =
|
||||
for {
|
||||
n1 <- DML.update(
|
||||
T,
|
||||
T.cid === v.cid,
|
||||
DML.set(
|
||||
T.schedule.setTo(v.schedule)
|
||||
)
|
||||
)
|
||||
n2 <- if (n1 <= 0) insert(v) else 0.pure[ConnectionIO]
|
||||
} yield n1 + n2
|
||||
|
||||
def findById(id: Ident): ConnectionIO[Option[REmptyTrashSetting]] = {
|
||||
val sql = run(select(T.all), from(T), T.cid === id)
|
||||
sql.query[REmptyTrashSetting].option
|
||||
}
|
||||
|
||||
def delete(coll: Ident): ConnectionIO[Int] =
|
||||
DML.delete(T, T.cid === coll)
|
||||
|
||||
}
|
Reference in New Issue
Block a user