wp-cli / media-command

Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
MIT License
44 stars 41 forks source link

Cannot bulk import media #114

Open crtl opened 5 years ago

crtl commented 5 years ago

Bug Report

I have around 2.6k images in a subdirectory inside wp-content/uploads/product_images. I tried to import them but get the following error:

$ wp media import ./product_images/*.png --skip-copy
/.../Composer/vendor/wp-cli/wp-cli/bin/wp: line 45: /c/xampp/php/php: Argument list too long
/.../Composer/vendor/wp-cli/wp-cli/bin/wp: line 45: /c/xampp/php/php: No error

The command evaluates the blob and just appends all files as arguments for the php command which seems to be too long for php to handle.

schlessera commented 5 years ago

@crtl The ./product_images/*.png bit in your command is already expanded by your shell in this case. The shell will expand this while examining the filesystem and then pass on a file list that matches this pattern to the actual tool being called, like so:

$ wp media import ./product_images/image1.png ./product_images/image2.png ./product_images/image3.png ... --skip-copy

So there's nothing that WP-CLI can do here, as the problem already occurs before you're even hitting the WP-CLI tool.

However, I notice now that the documentation says the command would support glob capabilities, which doesn't seem to be the case as far as I can see from the source code. If that would be the case, you could provide the "unglobbed" string to wp media import by quoting it, which I don't think works right now:

wp media import './products_images/*.png' --skip-copy

So a solution to this problem would be to add actual globbing support to the command and then handling the expansion within PHP memory.

crtl commented 5 years ago

The solution would be to support passing directory names and a recursive option to the command.

schlessera commented 5 years ago

Directory names are not precise enough for this. Actual globbing would be preferable, and PHP already supports this out of the box, so it'd be easier to implement as well.

crtl commented 5 years ago

How can you decide whats precise and what not. The command is pretty useless if you can only upload a limited amount of images because for small amounts you can just use the normal media upload in the admin dashboard.

schlessera commented 5 years ago

The goal is to make this more useful by allowing you to control what to include at the WP-CLI level, instead of relying on the shell.

But adding folders and a recursive option is both more complicated and less flexible than just passing the provided argument through the PHP glob() function.

bgoewert commented 2 years ago

Was getting an error while attempting to bulk import. Warning: Unable to import file 'images/*.webp'. Reason: File doesn't exist.

Then I realized that I had the path in quotes. The docs show an example for bulk imports with an unquoted path. Removing the quotes fixed the issue.

It's not a huge deal, but I was expecting the string path to work too.

Any update on this?