Automattic / Automattic/newspack-migration-tools

Update existing image matching to also check against alt/captions.

Open
#69 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
20
Forks
5
PR merge metrics
No merged PRs in 30d

Description

The function `maybe_get_existing_attachment_id()` ([code](https://github.com/Automattic/newspack-migration-tools/blob/1d8ce878adeb414be4ae4f0017cb46a97dd86945/src/Logic/Attachments.php#L137)) will check if an existing image exists.

It would be nice to also make sure the alt/caption is also the same before assuming an image is the same. Sometimes an image can have the same binary data `md5_file()` but we may need store two separate images in the database if they have different meta data (alt, caption, etc).

To make this change, we'd need to pass in `$args` info [here](https://github.com/Automattic/newspack-migration-tools/blob/1d8ce878adeb414be4ae4f0017cb46a97dd86945/src/Logic/Attachments.php#L97) so we can do a comparison.

FYI: For the cases where we know for sure we need multiple images created (ie: no comparison is possible at image creation time) we created a way to skip the `maybe_get_existing_attachment_id()` completely. That PR was [merged here](https://github.com/Automattic/newspack-migration-tools/pull/66).

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/Logic/Attachments.php by reading maybe_get_existing_attachment_id() and its caller, including the $args flow described in the issue. Trace how the existing image is selected, then verify that matching considers the relevant alt and caption metadata before reusing an attachment; done means images with different metadata are kept separate while identical metadata can still reuse the existing image.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend, content
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.