diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/StepMapper.php | 1 | ||||
-rw-r--r-- | lib/Service/ApiService.php | 20 | ||||
-rw-r--r-- | lib/Service/DocumentService.php | 4 | ||||
-rw-r--r-- | lib/Service/SessionService.php | 13 |
4 files changed, 24 insertions, 14 deletions
diff --git a/lib/Db/StepMapper.php b/lib/Db/StepMapper.php index 31005cce3..b39c1d79b 100644 --- a/lib/Db/StepMapper.php +++ b/lib/Db/StepMapper.php @@ -41,7 +41,6 @@ class StepMapper extends QBMapper { ->from($this->getTableName()) ->where($qb->expr()->eq('document_id', $qb->createNamedParameter($documentId))) ->andWhere($qb->expr()->gt('version', $qb->createNamedParameter($fromVersion))); - // WIP: only return steps that were persisted completely if ($lastAckedVersion) { $qb->andWhere($qb->expr()->lte('version', $qb->createNamedParameter($lastAckedVersion))); } diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 07ea15e8f..82e4763d8 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -24,6 +24,7 @@ namespace OCA\Text\Service; +use OC\Files\Node\File; use OCA\Text\DocumentSaveConflictException; use OCA\Text\VersionMismatchException; use OCP\AppFramework\Http\DataResponse; @@ -45,14 +46,14 @@ class ApiService { $this->documentService = $documentService; } - public function create($fileId = null, $file = null, $token = null): DataResponse { + public function create($fileId = null, $filePath = null, $token = null): DataResponse { try { if ($token) { - $document = $this->documentService->createDocumentByShareToken($token, $file); + $document = $this->documentService->createDocumentByShareToken($token, $filePath); } else if ($fileId) { $document = $this->documentService->createDocumentByFileId($fileId); - } else if ($file) { - $document = $this->documentService->createDocumentByPath($file); + } else if ($filePath) { + $document = $this->documentService->createDocumentByPath($filePath); } else { return new DataResponse('No valid file argument provided', 500); } @@ -80,7 +81,10 @@ class ApiService { } public function close($documentId, $sessionId, $sessionToken): DataResponse { - // TODO: To implement + $this->sessionService->closeSession($documentId, $sessionId, $sessionToken); + //if ($this->documentService->) + //$this->sessionService->cleanupSessions(); + $this->sessionService->removeInactiveSessions($documentId); return new DataResponse([]); } @@ -106,11 +110,15 @@ class ApiService { try { $document = $this->documentService->autosave($documentId, $version, $autosaveContent, $force, $manualSave, $token); } catch (DocumentSaveConflictException $e) { - /** @var \OC\Files\Node\File $file */ + /** @var File $file */ $file = $this->documentService->getFileByShareToken($token); return new DataResponse([ 'outsideChange' => $file->getContent() ], 409); + } catch (\Exception $e) { + return new DataResponse([ + 'message' => $e->getMessage() + ], 500); } return new DataResponse([ 'steps' => $this->documentService->getSteps($documentId, $version), diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index af9570610..e846b0c1b 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -358,4 +358,8 @@ class DocumentService { } } + public function hasUnsavedChanges(Document $document) { + return $document->getCurrentVersion() !== $document->getLastSavedVersion(); + } + } diff --git a/lib/Service/SessionService.php b/lib/Service/SessionService.php index c46a1fef4..a23447914 100644 --- a/lib/Service/SessionService.php +++ b/lib/Service/SessionService.php @@ -64,13 +64,12 @@ class SessionService { return $this->sessionMapper->insert($session); } - /** - * @throws DoesNotExistException - */ - public function closeSession($documentId, $sessionId, $token): void { - $session = $this->sessionMapper->find($documentId, $sessionId, $token); - // TODO: check for unpersisited changes from session? - $this->sessionMapper->delete($session); + public function closeSession(int $documentId, int $sessionId, string $token): void { + try { + $session = $this->sessionMapper->find($documentId, $sessionId, $token); + $this->sessionMapper->delete($session); + } catch (DoesNotExistException $e) { + } } public function getActiveSessions($documentId): array { |