Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to prevent remote fetches #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

edavis
Copy link

@edavis edavis commented Jun 23, 2018

Hello — Figured I'd open this PR to see if there was any interest. If not, that's okay.

The use case is actually a real-world scenario I'm dealing with right now :)

I've got a site with over 2,000 attachments I'm trying to import into an existing site. To speed things up, I downloaded all the files inside the uploads directory to my local machine via FTP.

I then created an export on the source site (All content + Media) and then started an import on the destination site. Problem is, the destination site still wants to download all the files from the source site even though they already exist locally.

With this PR, a new constant for wp-config.php is introduced (IMPORT_PREVENT_REMOTE_FETCH) and when set to true the fetch_remote_file() function is short-circuited to return an array of info on the locally existing file for the attachment. There is also an import_prevent_remote_fetch filter that receives the value of the constant, the URL, and the attachment to provide more fine-tuned control.

Looking forward to any feedback. Thanks!

This can be useful if the attachments from the source site already
exist within the destination site -- say, by way of FTP or rsync --
and you just need the attachment records added to the database.
@ChrisHardie
Copy link

Just wanted to say thanks for creating this - it came in very handy while creating the Flickr-to-WordPress migration tool at https://github.com/ChrisHardie/flickr-to-wordpress (described in some more detail at https://chrishardie.com/2019/02/moving-photos-flickr-wordpress/ ). I appreciate it!

@edavis
Copy link
Author

edavis commented Feb 21, 2019

@ChrisHardie You're very welcome! Glad you found it useful. Your photos site looks great!

@steevhise
Copy link

hmm looks like this patch no longer works...

@steevhise
Copy link

looks like the same functionality is now in place for the plugin, the import_allow_fetch_attachments filter. maybe.

@dd32
Copy link
Member

dd32 commented Jan 23, 2024

looks like the same functionality is now in place for the plugin, the import_allow_fetch_attachments filter. maybe.

The functionality of that filter is that it skips importing attachments entirely.

This PR is with the intention of skipping the remote-fetch of attachments, for when the attachment already exists on disk but not within the media library. So the file isn't created, but the WP_Post is.
I don't personally feel like this is a use-case that would be added to the plugin myself.

@carstingaxion
Copy link

This PR is with the intention of skipping the remote-fetch of attachments, for when the attachment already exists on disk but not within the media library. So the file isn't created, but the WP_Post is.

THIS is exactly my use-case.

I'm would like to use WordPress Playground as a tool to not only show, but also edit & save demo-data. So I created a blueprint, that imports all data from a wxr inside a Github repo. After editing your imported content in Playground, it is exported as wxr and commited back to the repo. (That's the short version, of what's happening)

New uploaded files, get also added to the repo with the final commit.

But next time the Playground is started the import starts again, and that is the moment, where it would be absolutely use- and helpful, if we could rely on:

the attachment already exists on disk [...] So the file isn't created, but the WP_Post is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants