From 77e4b1d4ff67d252ae2f8b59e51d966f4c965fc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Sat, 7 Jan 2023 20:53:03 +0100 Subject: [PATCH] Fixed: use the new native implementation of putFile to handle last-modified-timestamp correctly --- composer.json | 5 +- .../src/Service/Wopi/ChillWopi.php | 93 +------------------ 2 files changed, 5 insertions(+), 93 deletions(-) diff --git a/composer.json b/composer.json index 4dfdf7203..27f090933 100644 --- a/composer.json +++ b/composer.json @@ -11,9 +11,10 @@ "php": "^7.4", "ext-redis": "*", "ext-json": "*", + "ext-openssl": "*", "champs-libres/async-uploader-bundle": "dev-sf4#d57134aee8e504a83c902ff0cf9f8d36ac418290", - "champs-libres/wopi-bundle": "dev-master#6dd8e0a14e00131eb4b889ecc30270ee4a0e5224", - "champs-libres/wopi-lib": "dev-master#8615f4a45a39fc2b6a98765ea835fcfd39618787", + "champs-libres/wopi-bundle": "dev-master@dev", + "champs-libres/wopi-lib": "dev-master@dev", "doctrine/doctrine-bundle": "^2.1", "doctrine/doctrine-migrations-bundle": "^3.0", "doctrine/orm": "^2.13.0", diff --git a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php index 3cafc4c5d..2062080a7 100644 --- a/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php +++ b/src/Bundle/ChillWopiBundle/src/Service/Wopi/ChillWopi.php @@ -19,6 +19,7 @@ use loophp\psr17\Psr17Interface; use Psr\Cache\CacheItemPoolInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\User\UserProviderInterface; use function strlen; @@ -152,97 +153,7 @@ final class ChillWopi implements WopiInterface string $xWopiEditors, RequestInterface $request ): ResponseInterface { - $document = $this->documentManager->findByDocumentId($fileId); - $version = $this->documentManager->getVersion($document); - - // File is unlocked, we must reject the document, except if collabora is autosaving - if (false === $this->documentManager->hasLock($document) && 'true' !== ($request->getHeader('x-lool-wopi-isexitsave') ?? ['false'])[0]) { - if (0 !== $this->documentManager->getSize($document)) { - return $this - ->psr17 - ->createResponse(409) - ->withHeader( - WopiInterface::HEADER_ITEM_VERSION, - sprintf('v%s', $version) - ); - } - } - - // File is locked, we check for the lock - if ($this->documentManager->hasLock($document)) { - if ($xWopiLock !== $currentLock = $this->documentManager->getLock($document)) { - return $this - ->psr17 - ->createResponse(409) - ->withHeader( - WopiInterface::HEADER_LOCK, - $currentLock - ) - ->withHeader( - WopiInterface::HEADER_ITEM_VERSION, - sprintf('v%s', $version) - ); - } - } - - // for collabora online editor, check timestamp if present - /* delete because it seems that collabora send always the first wopi-timestamp, not the last known one - // example: - // load the doc: the last-wopi is 12:00 in FileInfo - // save the doc: x-cool-wopi-timestamp is 12:00, but we replace the ts with the time of save (12:05) - // save the doc again: x-cool-wopi-timestamp is still 12:00... - if ($request->hasHeader('x-cool-wopi-timestamp')) { - $date = DateTimeImmutable::createFromFormat( - DateTimeImmutable::ATOM, - $request->getHeader('x-cool-wopi-timestamp')[0] - ); - - if (false === $date) { - throw new RuntimeException('Error parsing date: ' . implode('', DateTimeImmutable::getLastErrors())); - } - - if ($this->documentManager->getLastModifiedDate($document)->getTimestamp() < $date->getTimestamp()) { - return $this - ->psr17 - ->createResponse(409) - ->withHeader( - WopiInterface::HEADER_LOCK, - $currentLock - ) - ->withHeader( - WopiInterface::HEADER_ITEM_VERSION, - sprintf('v%s', $version) - ) - ->withBody( - $this->psr17->createStream( - json_encode(['COOLStatusCode' => 1010]) - ) - ); - } - } - */ - - $body = (string) $request->getBody(); - $this->documentManager->write( - $document, - [ - 'content' => $body, - 'size' => (string) strlen($body), - ] - ); - $version = $this->documentManager->getVersion($document); - - return $this - ->psr17 - ->createResponse() - ->withHeader( - WopiInterface::HEADER_LOCK, - $xWopiLock - ) - ->withHeader( - WopiInterface::HEADER_ITEM_VERSION, - sprintf('v%s', $version) - ); + return $this->wopi->putFile($fileId, $accessToken, $xWopiLock, $xWopiEditors, $request); } public function putRelativeFile(string $fileId, string $accessToken, ?string $suggestedTarget, ?string $relativeTarget, bool $overwriteRelativeTarget, int $size, RequestInterface $request): ResponseInterface