-
Notifications
You must be signed in to change notification settings - Fork 41
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 --skip-copy
flag to allow import of media from local filesystem without moving on disk
#21
Conversation
@emirpprime Each pull request should only contain one conceptual change. Can you make sure this pull request only contains the specific change you're submitting? |
This reverts commit 3f27d46.
@danielbachhuber Done, I think - I could only see that there was a WPCS commit in there accidentally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of changes to start with. Still thinking this through generally.
src/Media_Command.php
Outdated
@@ -174,6 +174,9 @@ function regenerate( $args, $assoc_args = array() ) { | |||
* [--desc=<description>] | |||
* : "Description" field (post content) of attachment post. | |||
* | |||
* [--import_only] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about calling this --skip-copy
or similar, to better communicate that we're skipping existing behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that makes sense to me too.
""" | ||
Success: Imported 1 of 1 items. | ||
""" | ||
And the {CACHE_DIR}/large-image.jpg file should exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also assert that there's no file in the new destination
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. I should get this updated later today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber I'm struggling to work out how to write this.
Can you point me ot any docs or examples that would help?
I guess I need to learn what Behat actually does with the image if it imports it? Does it move to {CACHE_DIR}/wp-content/uploads/year/month
?
Then I think I'll need to create a new variable in FeatureContext.php for {UPLOADS_DIR} to use in the test. Is that about right?
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just need And the wp-content/uploads/large-image.jpg file should not exist
- see media-regenerate.feature
for examples.
Edit - Should add that Daniel is offline till Wednesday slack#cli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @gitlost, can't believe I didn't think to check in there :/
src/Media_Command.php
Outdated
$post_array['post_status'] = 'inherit'; | ||
|
||
$success = wp_insert_attachment( $post_array, $file, $assoc_args['post_id'] ); | ||
if ( ! is_wp_error( $success ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should switch the conditions and bail early on error.
So, instead of this:
if ( ! is_wp_error( $success ) ) {
// Handle success.
}
if ( is_wp_error( $success ) ) {
// Handle failure.
continue;
}
you should prefer something like this:
if ( is_wp_error( $success ) ) {
// Handle failure.
continue;
}
// Handle success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@schlessera I've updated the error handling part.
Since $success
is used in areas these changes don't touch, shall I submit that as a seperate PR once this is resolved? Or is it ok to handle it in here?
$post_array['post_mime_type'] = $wp_filetype['type']; | ||
$post_array['post_status'] = 'inherit'; | ||
|
||
$success = wp_insert_attachment( $post_array, $file, $assoc_args['post_id'] ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the variable $success
is being used several times here, and mostly refers to a "non-success", I would prefer the name to be changed to something like $result
instead. Naming it $success
seems misleading.
(Yes, I know that name was already in the code... 😄 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can handle this in a subsequent PR.
I don't think that check fail was due to my code... |
@emirpprime no it's ImageMagick doing its thing (randomly seg faulting) - trying to make it go away in #26 |
@@ -69,6 +69,25 @@ Feature: Manage WordPress attachments | |||
My fabulous caption | |||
""" | |||
|
|||
Scenario: Import a file as attachment from a local image and leave it in it's current location | |||
Given download: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After Given download
, you'll also need to run:
And I run `wp option update uploads_use_yearmonth_folders 0`
Otherwise, your file path assertion below will always be invalid, because WordPress will always used date-based folders.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--skip-copy
flag to allow import of media from local filesystem without moving on disk
@emirpprime Can you merge master to adopt the testing fix? |
I did this:
|
Can handle the issue in a subsequent PR
Thanks for your work on this, @emirpprime ! |
Add `--skip-copy` flag to allow import of media from local filesystem without moving on disk
Allow import of media from local filesystem without moving on disk
Fixes #24