Update DropFile to handle object versioning

This commit is contained in:
2024-09-02 16:24:23 +02:00
parent b6edbb3eed
commit 3d49c959e0
42 changed files with 857 additions and 539 deletions

View File

@@ -101,6 +101,37 @@ final class StoredObjectManager implements StoredObjectManagerInterface
return strlen($this->read($document));
}
/**
* @throws TransportExceptionInterface
* @throws StoredObjectManagerException
*/
public function exists(StoredObject|StoredObjectVersion $document): bool
{
$version = $document instanceof StoredObject ? $document->getCurrentVersion() : $document;
if ($this->hasCache($version)) {
return true;
}
try {
$response = $this
->client
->request(
Request::METHOD_HEAD,
$this
->tempUrlGenerator
->generate(
Request::METHOD_HEAD,
$version->getFilename()
)
->url
);
return 200 === $response->getStatusCode();
} catch (TransportExceptionInterface $exception) {
throw StoredObjectManagerException::errorDuringHttpRequest($exception);
}
}
public function etag(StoredObject|StoredObjectVersion $document): string
{
$version = $document instanceof StoredObject ? $document->getCurrentVersion() : $document;
@@ -117,7 +148,7 @@ final class StoredObjectManager implements StoredObjectManagerInterface
->tempUrlGenerator
->generate(
Request::METHOD_HEAD,
$document->getFilename()
$version->getFilename()
)
->url
);
@@ -214,6 +245,8 @@ final class StoredObjectManager implements StoredObjectManagerInterface
throw StoredObjectManagerException::invalidStatusCode($response->getStatusCode());
}
$this->clearCache();
return $version;
}

View File

@@ -14,6 +14,7 @@ namespace Chill\DocStoreBundle\Service;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Entity\StoredObjectVersion;
use Chill\DocStoreBundle\Exception\StoredObjectManagerException;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
interface StoredObjectManagerInterface
{
@@ -27,6 +28,11 @@ interface StoredObjectManagerInterface
*/
public function getContentLength(StoredObject|StoredObjectVersion $document): int;
/**
* @throws TransportExceptionInterface
*/
public function exists(StoredObject|StoredObjectVersion $document): bool;
/**
* Get the content of a StoredObject.
*