Fixed: use the new native implementation of putFile to handle last-modified-timestamp correctly

This commit is contained in:
Julien Fastré 2023-01-07 20:53:03 +01:00
parent b23019cb3a
commit 77e4b1d4ff
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 5 additions and 93 deletions

View File

@ -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",

View File

@ -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