Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Same bucket, different keyPrefixes, treat as "Two Buckets" mode #64

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Classes/S3Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function publishCollection(CollectionInterface $collection, callable $cal
{
$storage = $collection->getStorage();

if ($storage instanceof S3Storage && $storage->getBucketName() === $this->bucketName) {
if ($storage instanceof S3Storage && $storage->getBucketName() === $this->bucketName && $storage->getKeyPrefix() === $this->keyPrefix) {
// TODO do we need to update the content-type on the objects?
$this->systemLogger->debug(sprintf('Skipping resource publishing for bucket "%s", storage and target are the same.', $this->bucketName), LogEnvironment::fromMethodName(__METHOD__));
return;
Expand Down Expand Up @@ -359,7 +359,7 @@ public function publishResource(PersistentResource $resource, CollectionInterfac
{
$storage = $collection->getStorage();
if ($storage instanceof S3Storage) {
if ($storage->getBucketName() === $this->bucketName) {
if ($storage->getBucketName() === $this->bucketName && $storage->getKeyPrefix() === $this->keyPrefix) {
// to update the Content-Type the object must be copied to itself…
$this->copyObject(
function (PersistentResource $resource) use ($storage): string {
Expand Down Expand Up @@ -410,7 +410,7 @@ private function copyObject(\Closure $sourceBuilder, \Closure $targetBuilder, Re
}
try {
$this->s3Client->copyObject($options);
$this->systemLogger->debug(sprintf('Successfully published resource as object "%s" (SHA1: %s) by copying from "%s" to bucket "%s"', $target, $resource->getSha1() ?: 'unknown', $source, $this->bucketName));
$this->systemLogger->debug(sprintf('Successfully published resource as object "%s" (SHA1: %s) by copying from "%s" to bucket "%s"', $target, $resource->getSha1() ?: 'unknown', $source, $this->bucketName), $options);
} catch (S3Exception $e) {
$this->systemLogger->critical($e, LogEnvironment::fromMethodName(__METHOD__));
$message = sprintf('Could not publish resource with SHA1 hash %s (source object: %s) through "CopyObject" because the S3 client reported an error: %s', $resource->getSha1(), $source, $e->getMessage());
Expand All @@ -432,7 +432,7 @@ public function unpublishResource(PersistentResource $resource)
}

$storage = $this->resourceManager->getCollection($resource->getCollectionName())->getStorage();
if ($storage instanceof S3Storage && $storage->getBucketName() === $this->bucketName) {
if ($storage instanceof S3Storage && $storage->getBucketName() === $this->bucketName && $storage->getKeyPrefix() === $this->keyPrefix) {
// Unpublish for same-bucket setups is a NOOP, because the storage object will already be deleted.
$this->systemLogger->debug(sprintf('Skipping resource unpublishing %s from bucket "%s", because storage and target are the same.', $resource->getSha1() ?: 'unknown', $this->bucketName));
return;
Expand Down