-
Notifications
You must be signed in to change notification settings - Fork 27
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
support exporting attachments when specific post ids are requested #16
Conversation
About the change in |
Using In general, the process should be to open an issue first describing the problem that you're trying to solve, and then we can discuss details like the names of the arguments together, before you spend time writing code. See the section about the pull request workflow in the handbook. I think going with a So, the flag should default to This will not only allow what you have proposed above, but will also allow to disable attachments for any of the other use case if needed. What do you think? |
One nit: |
src/WP_Export_Query.php
Outdated
@@ -262,7 +266,7 @@ private function category_where() { | |||
|
|||
private function attachments_for_specific_post_types( $post_ids ) { | |||
global $wpdb; | |||
if ( !$this->filters['post_type'] ) { |
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.
In the WordPress admin, exporting a specific post type doesn't include attachments. We need to persist the current behavior here. If the --with-attachments
flag is included, then we can include the attachments.
> @@ -262,7 +266,7 @@ private function category_where() {
private function attachments_for_specific_post_types( $post_ids ) {
global $wpdb;
- if ( !$this->filters['post_type'] ) {
I'd expect this hunk to cause trouble.
But I'd rather let you decide the future for this function and the way
this must be changed (if it really has to)
|
Thanks for the feedbacks about PR #13 is 2 weeks old, all its issues have been addressed (except an inoffensive For that reason the I'd really loved if you, knowledgeable maintainers, responsible of codebase quality, could manage the 5 or 10% left for a PR rather than expecting outside contributor to reroll the patch X times to reach a perfect the 100% quality expected. Would make wp-cli contribution experience much less frustrating for the best of the software. For the context, I'm working on a plugin + continuous integration (to ensure code quality and avoid regression). wp-cli is just a tool for that end and I intend to make it more performant for the task in the hope it benefit to other WP dev, but I currently can't afford dozens of hours to wp-cli itself. |
All you need to do is ask :) |
37c5135
to
7bb16b2
Compare
thx for the positive reply @danielbachhuber |
For the record I although wanted to include comments' images in my fixtures.
A long-term solution may be a hook allowing specific plugin to interpret the semantic of the |
src/WP_Export_Query.php
Outdated
@@ -188,6 +194,11 @@ private function post_type_where() { | |||
$this->wheres[] = 'p.post_type IS NULL'; | |||
return; | |||
} | |||
|
|||
if ( $this->filters['with_attachments'] == FALSE && ( !$this->filters['post_type'] || !in_array( "attachment", $this->filters['post_type'] ) ) ) { |
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.
WPCS code style: space after !
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.
in_array()
should always be used with its third $strict
argument set to true, to avoid getting unexpected results.
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.
No need for double quotes for "attachment"
.
src/WP_Export_Query.php
Outdated
@@ -260,9 +271,9 @@ private function category_where() { | |||
$this->wheres[] = $wpdb->prepare( 'tr.term_taxonomy_id = %d', $category->term_taxonomy_id ); | |||
} | |||
|
|||
private function attachments_for_specific_post_types( $post_ids ) { | |||
private function include_attachments_ids( $post_ids ) { |
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.
Please rename to include_attachment_ids()
(only IDs in plural).
src/Export_Command.php
Outdated
if ( is_null( $with ) ) | ||
return true; | ||
|
||
if ( (int) $with <> 0 && (int) $with <> 1 ) { |
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.
--with-attachments
should be handled as a flag, not a parameter taking a value. To improve the readability with flag negation ( --no-<flag>
), I'd like to also rename the flag to --include-attachments
.
So, instead of having values like this:
--with-attachments=0
=> off
--with-attachments=1
=> on
...it should be the standard flag behaviour:
--include-attachments
=> on
--no-include-attachments
=> off
This will then also support setting a different default through a config file, and override it with --include-attachments
instead.
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.
yeah but currently, all other options use a "_" between words, so that would mean:
--no-with_attachments
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.
Hmm, good point. I think the underscore in this command came about because it is using some of the variable names from WP.
I'll discuss this in tomorrow's office hours to see what the best approach is.
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.
I discussed this with @danielbachhuber , and we agreed to use --with_attachments
as flag, knowing that the negation will be a weird --no-with_attachments
.
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.
Do you need assistance with converting the parameter into flag notation?
ff9369c
to
b57e5f9
Compare
…chments export, specifically in the case of --post__in Do not consider --post__in=0 as a valid value (ignore it smoothly) 0 is a special value for post without parent. When people use this value, for example --post__in=1,2,,3 --attachment=1 filter-out the spurious post__in=0 to avoid adding all attachment having post_parent = 0
NB: I had no other option than fully recreate the branch because |
My biggest concern with this PR is that we aren't introducing a change in the existing behavior. It's not quite clear to me based on a cursory review, so would be worthwhile to make sure there are tests around the current behavior. |
I'll add tests by building the tests first, and only then applying the patch, just to stay on the safe side. |
…rt files directly. As it turns out, `wp import` does not import attachments that don't come with an actual file to upload. Related wp-cli/wp-cli#928
@danielbachhuber You can review and merge this PR now. To make sure we don't change the default behaviour, I verified that the normal |
support exporting attachments when specific post ids are requested
Does I'm interested in some portability between blogging platforms and the WXR/XML format could achieve this, if export/import can support embedding the images/attachments/resources inside the WXR. |
I don't think WordPress supports base64/cdata in WXR files. Therefore it's not something WP-CLI supports. I see you just opened #118 so let's continue discussion there instead of a 7 year old closed PR :) |
support exporting attachments when specific post ids are requested (assuming the post whose ids were specified were not attachment themselves)
getenv()
to limit merge-conflict with other pending PR + fact that there may be long debates about how to pass the option, eg:--attachments
/--force-attachment
/--post__in=+<num>,-<num>,...
/--with-deps
/ ...