Skip to content

Commit 58fbad4

Browse files
committed
Improve metadata types && isExifSegment() verification for jpeg
1 parent bed58c5 commit 58fbad4

File tree

7 files changed

+17
-20
lines changed

7 files changed

+17
-20
lines changed

app/code/Magento/MediaGalleryMetadata/Model/GetIptcMetadata.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterface;
1111
use Magento\MediaGalleryMetadataApi\Api\Data\MetadataInterfaceFactory;
12-
use Magento\MediaGalleryMetadataApi\Model\SegmentInterface;
1312

1413
/**
1514
* Get metadata from IPTC block
@@ -42,8 +41,8 @@ public function __construct(
4241
*/
4342
public function execute(string $data): MetadataInterface
4443
{
45-
$title = '';
46-
$description = '';
44+
$title = null;
45+
$description = null;
4746
$keywords = [];
4847

4948
if (is_callable('iptcparse')) {
@@ -65,7 +64,7 @@ public function execute(string $data): MetadataInterface
6564
return $this->metadataFactory->create([
6665
'title' => $title,
6766
'description' => $description,
68-
'keywords' => $keywords
67+
'keywords' => !empty($keywords) ? $keywords : null
6968
]);
7069
}
7170
}

app/code/Magento/MediaGalleryMetadata/Model/Jpeg/Segment/ReadExif.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,19 @@ private function getExifData(string $filePath): MetadataInterface
7070
{
7171
$title = null;
7272
$description = null;
73-
$keywords = [];
73+
$keywords = null;
7474

7575
$data = exif_read_data($filePath);
7676

77-
if ($data) {
77+
if (!empty($data)) {
7878
$title = isset($data['DocumentName']) ? $data['DocumentName'] : null;
7979
$description = isset($data['ImageDescription']) ? $data['ImageDescription'] : null;
80-
$keywords = '';
8180
}
8281

8382
return $this->metadataFactory->create([
8483
'title' => $title,
8584
'description' => $description,
86-
'keywords' => !empty($keywords) ? $keywords : null
85+
'keywords' => $keywords
8786
]);
8887
}
8988

@@ -97,9 +96,9 @@ private function isExifSegment(SegmentInterface $segment): bool
9796
{
9897
return $segment->getName() === self::EXIF_SEGMENT_NAME
9998
&& strncmp(
100-
substr($segment->getData(), self::EXIF_DATA_START_POSITION, 4),
99+
substr($segment->getData(), self::EXIF_DATA_START_POSITION, 5),
101100
self::EXIF_SEGMENT_START,
102-
self::EXIF_DATA_START_POSITION
101+
5
103102
) == 0;
104103
}
105104
}

app/code/Magento/MediaGalleryMetadata/Model/Jpeg/Segment/ReadIptc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public function execute(FileInterface $file): MetadataInterface
5656
}
5757
}
5858
return $this->metadataFactory->create([
59-
'title' => '',
60-
'description' => '',
61-
'keywords' => []
59+
'title' => null,
60+
'description' => null,
61+
'keywords' => null
6262
]);
6363
}
6464

app/code/Magento/MediaGalleryMetadata/Model/Jpeg/Segment/ReadXmp.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function execute(FileInterface $file): MetadataInterface
5454
}
5555
}
5656
return $this->metadataFactory->create([
57-
'title' => '',
58-
'description' => '',
59-
'keywords' => []
57+
'title' => null,
58+
'description' => null,
59+
'keywords' => null
6060
]);
6161
}
6262

app/code/Magento/MediaGalleryMetadata/Model/Png/Segment/ReadExif.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ private function getExifData(SegmentInterface $segment): MetadataInterface
7575
if ($data) {
7676
$title = isset($data['DocumentName']) ? $data['DocumentName'] : null;
7777
$description = isset($data['ImageDescription']) ? $data['ImageDescription'] : null;
78-
$keywords = '';
7978
}
8079

8180
return $this->metadataFactory->create([

app/code/Magento/MediaGalleryMetadata/Model/Png/Segment/ReadXmp.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function execute(FileInterface $file): MetadataInterface
5555
}
5656
}
5757
return $this->metadataFactory->create([
58-
'title' => '',
59-
'description' => '',
60-
'keywords' => []
58+
'title' => null,
59+
'description' => null,
60+
'keywords' => null
6161
]);
6262
}
6363

Loading

0 commit comments

Comments
 (0)