Skip to content

Add --skip-duplicates flag to wp media import#241

Draft
Copilot wants to merge 11 commits intomainfrom
copilot/skip-duplicates-feature
Draft

Add --skip-duplicates flag to wp media import#241
Copilot wants to merge 11 commits intomainfrom
copilot/skip-duplicates-feature

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

  • Add --skip-duplicates flag to import() docblock and @param type hint
  • Add $skips = 0 variable in import()
  • Add duplicate detection for local files using _wp_attached_file basename match
  • Add duplicate detection for remote files using _wp_attached_file basename match (extracted from URL)
  • Use RIGHT(meta_value, N) = '/basename' query to match year/month subdirectory paths without % wildcards
  • Use mb_strlen() with strlen() fallback for correct character counting
  • Use explode() instead of strtok() consistently for URL query-string stripping
  • Pass $skips to report_batch_operation_results only when --skip-duplicates is active
  • Add find_duplicate_attachment() private helper method
  • Fix duplicate detection for WP 5.3+ scaled images: derive basename-scaled.ext from the input basename and include it in the _wp_attached_file search — WordPress stores the scaled variant name in _wp_attached_file, not as a separate meta key
  • Add Behat test scenarios for --skip-duplicates (local file, remote file, mixed batch)
  • Fix CI failures: local file skip test and mixed-batch skip test were failing because large-image.jpg is large enough to trigger WP scaling
Original prompt

This section details on the original issue you should resolve

<issue_title>Skip Duplicates</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

I have a directory that I regularly update with images, audio, video, and documents. I want to run wp media import on this directory but have it skip any files that have already been imported. I can't think of a way to do this today other than some complicated scripting on my side that would compare file names and date modified between the two systems.

Describe the solution you'd like

I would love a flag that I could run as part of the command that could automatically do this for me. I plan on setting up a batch job to continuously import from the directory, it would be great if I could just run wp media import --skip_existing or something along those lines.
</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@github-actions github-actions bot added command:media-import Related to 'media import' command help-wanted Extra attention is needed scope:distribution Related to distribution state:unconfirmed labels Mar 19, 2026
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add skip duplicates functionality Add --skip-duplicates flag to wp media import Mar 19, 2026
Copilot AI requested a review from swissspidy March 19, 2026 23:01
@swissspidy

This comment was marked as resolved.

…s for non-skip-duplicates paths

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

This comment was marked as resolved.

swissspidy and others added 2 commits March 20, 2026 09:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ile handling

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy

This comment was marked as resolved.

…age_file

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

…e variant

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Media_Command.php 95.34% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:media-import Related to 'media import' command help-wanted Extra attention is needed scope:distribution Related to distribution state:unconfirmed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skip Duplicates

3 participants