Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
.travis.yml
behat.yml
circle.yml
phpcs.xml.dist
phpunit.xml.dist
bin/
features/
utils/
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vendor/
*.tar.gz
composer.lock
*.log
phpunit.xml
phpcs.xml
.phpcs.xml
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/extension-command": "^1.2 || ^2",
"wp-cli/import-command": "^1 || ^2",
"wp-cli/wp-cli-tests": "^2.0.7"
"wp-cli/wp-cli-tests": "^2.1"
},
"config": {
"process-timeout": 7200,
Expand Down
6 changes: 3 additions & 3 deletions export-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
return;
}

$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $autoload ) ) {
require_once $autoload;
$wpcli_export_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
if ( file_exists( $wpcli_export_autoloader ) ) {
require_once $wpcli_export_autoloader;
}

WP_CLI::add_command( 'export', 'Export_Command' );
15 changes: 8 additions & 7 deletions features/export.feature
Original file line number Diff line number Diff line change
Expand Up @@ -454,31 +454,32 @@ Feature: Export content.

Scenario: Export posts using --max_num_posts
Given a WP install
And I run `wp site empty --yes`
And a count-instances.php file:
"""
<?php
echo preg_match_all( '#<wp:post_type>' . $args[0] . '<\/wp:post_type>#', file_get_contents( 'php://stdin' ), $matches );
echo 'count=' . preg_match_all( '#<wp:post_type>' . $args[0] . '<\/wp:post_type>#', file_get_contents( 'php://stdin' ), $matches );
"""

When I run `wp post generate --post_type=post --count=10`
And I run `wp export --post_type=post --max_num_posts=1 --stdout | wp --skip-wordpress eval-file count-instances.php post`
Then STDOUT should be:
Then STDOUT should contain:
"""
1
count=1
"""

When I run `wp post generate --post_type=post --count=10`
And I run `wp post generate --post_type=attachment --count=10`
And I run `wp export --max_num_posts=1 --stdout | wp --skip-wordpress eval-file count-instances.php "(post|attachment)"`
Then STDOUT should be:
Then STDOUT should contain:
"""
1
count=1
"""

When I run `wp export --max_num_posts=5 --stdout | wp --skip-wordpress eval-file count-instances.php "(post|attachment)"`
Then STDOUT should be:
Then STDOUT should contain:
"""
5
count=5
"""

Scenario: Export a site with a custom filename format
Expand Down
33 changes: 12 additions & 21 deletions functions.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
<?php

// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound -- Renaming breaks Phar compat.
function wp_export( $args = array() ) {
$defaults = array(
'filters' => array(),
'format' => 'WP_Export_WXR_Formatter',
'writer' => 'WP_Export_Returner',
$defaults = array(
'filters' => array(),
'format' => 'WP_Export_WXR_Formatter',
'writer' => 'WP_Export_Returner',
'writer_args' => null,
);
$args = wp_parse_args( $args, $defaults );
$args = wp_parse_args( $args, $defaults );
$export_query = new WP_Export_Query( $args['filters'] );
$formatter = new $args['format']( $export_query );
$writer = new $args['writer']( $formatter, $args['writer_args'] );
$formatter = new $args['format']( $export_query );
$writer = new $args['writer']( $formatter, $args['writer_args'] );
try {
return $writer->export();
} catch ( WP_Export_Exception $e ) {
return new WP_Error( 'wp-export-error', $e->getMessage() );
}
}

function wp_export_new_style_args_from_old_style_args( $args ) {
if ( isset( $args['content'] ) ) {
if ( 'all' == $args['content'] ) {
unset( $args['content'] );
} else {
$args['post_type'] = $args['content'];
}
}
return $args;
}

// TEMPORARY
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound,WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid -- Renaming breaks Phar compat.
function _wp_export_build_IN_condition( $column_name, $values, $format = '%s' ) {
global $wpdb;

if ( !is_array( $values ) || empty( $values ) ) {
if ( ! is_array( $values ) || empty( $values ) ) {
return '';
}
$formats = implode( ', ', array_fill( 0, count( $values ), $format ) );
return $wpdb->prepare( "$column_name IN ($formats)", $values );
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- $column_name_sql escaped as ident, $formats hardcoded value.
return $wpdb->prepare( "{$column_name} IN ({$formats})", $values );
}
71 changes: 71 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0"?>
<ruleset name="WP-CLI-export">
<description>Custom ruleset for WP-CLI export-command</description>

<!--
#############################################################################
COMMAND LINE ARGUMENTS
For help understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
For help using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
#############################################################################
-->

<!-- What to scan. -->
<file>.</file>

<!-- Show progress. -->
<arg value="p"/>

<!-- Strip the filepaths down to the relevant bit. -->
<arg name="basepath" value="./"/>

<!-- Check up to 8 files simultaneously. -->
<arg name="parallel" value="8"/>

<!--
#############################################################################
USE THE WP_CLI_CS RULESET
#############################################################################
-->

<rule ref="WP_CLI_CS"/>

<!--
#############################################################################
PROJECT SPECIFIC CONFIGURATION FOR SNIFFS
#############################################################################
-->

<!-- For help understanding the `testVersion` configuration setting:
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
<config name="testVersion" value="5.4-"/>

<!-- Verify that everything in the global namespace is either namespaced or prefixed.
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="WP_CLI\Export"/><!-- Namespaces. -->
<element value="wpcli_export"/><!-- Global variables and such. -->
</property>
</properties>
</rule>

<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
<exclude-pattern>*/src/Export_Command\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_(Map|Post_IDs)_Iterator\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_(Export_Term|Iterator)_Exception\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_Export_WXR_Formatter\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_Export_XML_Over_HTTP\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_Export_(Base|File|Split_Files|Stdout)?_Writer\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_Export_(Exception|Oxymel|Query|Returner)\.php$</exclude-pattern>
</rule>


<!-- Exclude the word `wordpress` from being forced into "trademarked" capitalization in the file names. -->
<rule ref="WordPress.WP.CapitalPDangit.Misspelled">
<exclude-pattern>*/src/Export_Command\.php$</exclude-pattern>
</rule>

</ruleset>
Loading