Skip to content

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

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

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

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

Running wp media import on a regularly-updated directory had no mechanism to skip already-imported files, resulting in duplicate attachments on repeated runs.

Changes

  • New --skip-duplicates flag on wp media import — skips files that already exist in the media library before any expensive I/O (no temp copy created, no download initiated)
  • Local file deduplication via _wp_attached_file meta: matches exact basename (for root-level uploads) or %/basename (for year/month subdirectory paths)
  • Remote URL deduplication via _source_url meta: exact URL match against what media_handle_sideload stores
  • Skip reporting integrated into existing batch result output via the $skips parameter of report_batch_operation_results

Usage

# Safely re-run on a watched directory — already-imported files are skipped
wp media import /media/uploads/*.jpg --skip-duplicates
# Skipped importing file '/media/uploads/photo.jpg'. Reason: already exists as attachment ID 42.
# Success: Imported 3 of 5 items (2 skipped).

Behat tests added

  • Skip local file already in library
  • Skip remote URL already in library
  • Mixed batch: one duplicate skipped, one new file imported
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
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

2 participants