Repository navigation
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. |
danielbachhuber
left a comment
There was a problem hiding this comment.
Couple of changes to start with. Still thinking this through generally.
| * [--desc=<description>] | ||
| * : "Description" field (post content) of attachment post. | ||
| * | ||
| * [--import_only] |
There was a problem hiding this comment.
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.
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.
We should also assert that there's no file in the new destination
There was a problem hiding this comment.
Will do. I should get this updated later today.
There was a problem hiding this comment.
@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.
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.
Thanks @gitlost, can't believe I didn't think to check in there :/
| $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.
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.
@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.
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.
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 |
| """ | ||
|
|
||
| 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.
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.
--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