Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib/Db
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2019-06-12 15:32:20 +0300
committerJulius Härtl <jus@bitgrid.net>2019-06-12 15:32:42 +0300
commit6824232ab2269a7b815c66f2b7cc57612f15f201 (patch)
tree61ab9e1f0a4221502187895c7c770bc97e132531 /lib/Db
parenta0e5b0ddab7ebbaa4f09b379a7c98ad298b9b90d (diff)
Cleanup sessions/steps when no session are active anymore
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/Db')
-rw-r--r--lib/Db/DocumentMapper.php8
-rw-r--r--lib/Db/SessionMapper.php11
-rw-r--r--lib/Db/StepMapper.php9
3 files changed, 27 insertions, 1 deletions
diff --git a/lib/Db/DocumentMapper.php b/lib/Db/DocumentMapper.php
index 9f4113a9d..a4f097b1b 100644
--- a/lib/Db/DocumentMapper.php
+++ b/lib/Db/DocumentMapper.php
@@ -35,7 +35,12 @@ class DocumentMapper extends QBMapper {
parent::__construct($db, 'text_documents', Document::class);
}
- public function find($documentId) {
+ /**
+ * @param $documentId
+ * @return Document
+ * @throws DoesNotExistException
+ */
+ public function find($documentId): Document {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('*')
@@ -50,4 +55,5 @@ class DocumentMapper extends QBMapper {
}
return Document::fromRow($data);
}
+
}
diff --git a/lib/Db/SessionMapper.php b/lib/Db/SessionMapper.php
index 36e355d00..87e305cff 100644
--- a/lib/Db/SessionMapper.php
+++ b/lib/Db/SessionMapper.php
@@ -73,6 +73,17 @@ class SessionMapper extends QBMapper {
return $this->findEntities($qb);
}
+ public function findAllInactive() {
+ /* @var $qb IQueryBuilder */
+ $qb = $this->db->getQueryBuilder();
+ $qb->select('id','color','document_id', 'last_contact','user_id','guest_name')
+ ->from($this->getTableName())
+ ->where($qb->expr()->gt('last_contact', $qb->createNamedParameter(time()-SessionService::SESSION_VALID_TIME)))
+ ->execute();
+
+ return $this->findEntities($qb);
+ }
+
public function deleteInactive($documentId) {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
diff --git a/lib/Db/StepMapper.php b/lib/Db/StepMapper.php
index b39c1d79b..1f0ec698e 100644
--- a/lib/Db/StepMapper.php
+++ b/lib/Db/StepMapper.php
@@ -59,4 +59,13 @@ class StepMapper extends QBMapper {
->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
->execute();
}
+
+ public function deleteBeforeVersion($documentId, $version) {
+ /* @var $qb IQueryBuilder */
+ $qb = $this->db->getQueryBuilder();
+ $qb->delete($this->getTableName())
+ ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId)))
+ ->andWhere($qb->expr()->lte('version', $qb->createNamedParameter($version)))
+ ->execute();
+ }
}