mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-06 23:04:58 +00:00
Update DropFile to handle object versioning
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user