Skip to content

Commit

Permalink
Merge pull request #108 from netgen/cloudinary-callback-notification-…
Browse files Browse the repository at this point in the history
…system-issue

Add casting to string to fix error for callback notifications
  • Loading branch information
RandyCupic authored Sep 19, 2024
2 parents 1c44f2a + 04c511c commit 21a41df
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bundle/Controller/Callback/Cloudinary/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private function handleContextChanged(array $requestContent): void
continue;
}

$filenameFromUrl = basename($publicId);
$filenameFromUrl = basename((string) $publicId);

try {
$apiResource = Uploader::explicit(
Expand Down
4 changes: 2 additions & 2 deletions bundle/Controller/Resource/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ protected function formatResource(RemoteResource $resource): array
'size' => $resource->getSize(),
'width' => $resource->getMetadataProperty('width'),
'height' => $resource->getMetadataProperty('height'),
'filename' => $resource->getName(),
'originalFilename' => $resource->getOriginalFilename(),
'filename' => (string) $resource->getName(),
'originalFilename' => (string) $resource->getOriginalFilename(),
'format' => $resource->getMetadataProperty('format'),
'browseUrl' => $this->resolveImageUrl($resource, 'browse'),
'previewUrl' => $this->resolveImageUrl($resource, 'preview'),
Expand Down
8 changes: 4 additions & 4 deletions lib/API/Values/RemoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@ public function setUrl(string $url): self
return $this;
}

public function getName(): string
public function getName(): ?string
{
return $this->name;
}

public function setName(string $name): self
public function setName(?string $name): self
{
$this->name = $name;

return $this;
}

public function getOriginalFilename(): string
public function getOriginalFilename(): ?string
{
return $this->originalFilename;
}

public function setOriginalFilename(string $originalFilename): self
public function setOriginalFilename(?string $originalFilename): self
{
$this->originalFilename = $originalFilename;

Expand Down
2 changes: 1 addition & 1 deletion lib/Core/Provider/Cloudinary/CloudinaryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function updateOnRemote(RemoteResource $resource): void
[
'alt' => $resource->getAltText(),
'caption' => $resource->getCaption(),
'original_filename' => $resource->getOriginalFilename(),
'original_filename' => (string) $resource->getOriginalFilename(),
],
),
'tags' => $resource->getTags(),
Expand Down
2 changes: 1 addition & 1 deletion lib/Core/Provider/Cloudinary/Factory/RemoteResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function resolveOriginalFilename(array $data): string
return $data['context']['custom']['original_filename'];
}

return $data['context']['original_filename'] ?? basename($data['secure_url']);
return $data['context']['original_filename'] ?? basename((string) $data['secure_url']);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/bundle/Controller/Resource/BrowseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public function test(): void
'width' => null,
'height' => null,
'filename' => 'image.jpg',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/images/image.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/images/image.jpg',
Expand All @@ -193,6 +194,7 @@ public function test(): void
'width' => null,
'height' => null,
'filename' => 'image2.jpg',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/images/image2.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/images/image2.jpg',
Expand All @@ -210,6 +212,7 @@ public function test(): void
'width' => null,
'height' => null,
'filename' => 'example.mp4',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/videos/example.mp4.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/videos/example.mp4.jpg',
Expand Down
6 changes: 5 additions & 1 deletion tests/bundle/Controller/Resource/UploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testUpload(): void
type: 'image',
url: 'https://cloudinary.com/test/upload/image/media/image/sample_image.jpg',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'https://cloudinary.com/test/upload/image/media/image/sample_image.jpg',
name: 'sample_image.jpg',
folder: Folder::fromPath('media/image'),
size: 123,
);
Expand Down Expand Up @@ -152,6 +152,7 @@ public function testUpload(): void
'width' => null,
'height' => null,
'filename' => 'sample_image.jpg',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/image/media/image/sample_image.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/image/media/image/sample_image.jpg',
Expand Down Expand Up @@ -304,6 +305,7 @@ public function testUploadProtectedWithContext(): void
'width' => null,
'height' => null,
'filename' => 'sample_image.jpg',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/authenticated/image/media/image/sample_image.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/authenticated/image/media/image/sample_image.jpg',
Expand Down Expand Up @@ -468,6 +470,7 @@ public function testUploadExistingFile(): void
'width' => null,
'height' => null,
'filename' => 'sample_image.jpg',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/image/sample_image.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/image/sample_image.jpg',
Expand Down Expand Up @@ -628,6 +631,7 @@ public function testUploadExistingFileName(): void
'width' => null,
'height' => null,
'filename' => 'sample_image.jpg',
'originalFilename' => '',
'format' => null,
'browseUrl' => 'https://cloudinary.com/test/c_fit_160_120/upload/image/media/image/sample_image.jpg',
'previewUrl' => 'https://cloudinary.com/test/c_fit_800_600/upload/image/media/image/sample_image.jpg',
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/Core/Provider/Cloudinary/CloudinaryProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ public function testUpdateOnRemote(): void
'caption' => $resource->getCaption(),
'source' => 'user_upload',
'type' => 'product_image',
'original_filename' => $resource->getOriginalFilename(),
],
'tags' => $resource->getTags(),
];
Expand Down Expand Up @@ -396,6 +397,7 @@ public function testUpdateOnRemoteWithEmptyTags(): void
'context' => [
'alt' => $resource->getAltText(),
'caption' => $resource->getCaption(),
'original_filename' => $resource->getOriginalFilename(),
],
'tags' => $resource->getTags(),
];
Expand Down Expand Up @@ -431,6 +433,7 @@ public function testUpdateOnRemoteNotFound(): void
'context' => [
'alt' => $resource->getAltText(),
'caption' => $resource->getCaption(),
'original_filename' => $resource->getOriginalFilename(),
],
'tags' => $resource->getTags(),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static function createDataProvider(): array
url: 'https://res.cloudinary.com/myCloud/image/upload/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e12',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.jpg',
version: '1371995958',
size: 120253,
altText: 'alt text',
Expand Down Expand Up @@ -151,6 +152,7 @@ public static function createDataProvider(): array
url: 'https://res.cloudinary.com/myCloud/image/upload/other/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0',
visibility: 'public',
folder: Folder::fromPath('other'),
size: 120253,
Expand All @@ -176,6 +178,7 @@ public static function createDataProvider(): array
'created_at' => '2013-06-23T13:59:18Z',
'bytes' => 120253,
'url' => 'http://res.cloudinary.com/myCloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
'secure_url' => 'http://res.cloudinary.com/myCloud/video/upload/v1371995958/c87hg9xfxrd4itiim3t0.mp4',
'tags' => ['tag1', 'tag2'],
'overwritten' => 'false',
'context' => [
Expand All @@ -194,6 +197,7 @@ public static function createDataProvider(): array
url: 'https://res.cloudinary.com/myCloud/video/upload/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
version: '13711295958',
size: 120253,
altText: 'alt text',
Expand Down Expand Up @@ -237,6 +241,7 @@ public static function createDataProvider(): array
url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0',
md5: 'a522f23sf81aa0afd03387c37e2b6eax',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp4',
version: '1371995958',
visibility: 'protected',
size: 120253,
Expand Down Expand Up @@ -278,6 +283,7 @@ public static function createDataProvider(): array
url: 'https://res.cloudinary.com/myCloud/video/authenticated/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c37e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0.mp3',
version: '1371995958',
visibility: 'protected',
size: 12025,
Expand Down Expand Up @@ -318,6 +324,7 @@ public static function createDataProvider(): array
url: 'https://res.cloudinary.com/myCloud/raw/test/media/raw/new/c87hg9xfxrd4itiim3t0',
md5: 'e522f43cf89aa0afd03387c38e2b6e29',
name: 'c87hg9xfxrd4itiim3t0',
originalFilename: 'c87hg9xfxrd4itiim3t0',
version: '1371995958',
visibility: 'public',
folder: Folder::fromPath('media/raw/new'),
Expand Down

0 comments on commit 21a41df

Please sign in to comment.