Merge pull request #19877 from woocommerce/fix/19863

Fix CSV import cleanup methods
This commit is contained in:
Claudiu Lodromanean 2018-04-26 13:05:27 -07:00 committed by GitHub
commit 3b24aa9791
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 20 deletions

View File

@ -235,26 +235,34 @@ class WC_Admin_Importers {
update_user_option( get_current_user_id(), 'product_import_error_log', $error_log ); update_user_option( get_current_user_id(), 'product_import_error_log', $error_log );
if ( 100 === $percent_complete ) { if ( 100 === $percent_complete ) {
// Clear temp meta. // @codingStandardsIgnoreStart.
$wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_original_id' ) ); // @codingStandardsIgnoreLine. $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_original_id' ) );
$wpdb->query( $wpdb->delete( $wpdb->posts, array(
"DELETE {$wpdb->posts}, {$wpdb->postmeta}, {$wpdb->term_relationships} 'post_type' => 'product',
FROM {$wpdb->posts} 'post_status' => 'importing',
LEFT JOIN {$wpdb->term_relationships} ON ( {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id ) ) );
LEFT JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id ) $wpdb->delete( $wpdb->posts, array(
LEFT JOIN {$wpdb->term_taxonomy} ON ( {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id ) 'post_type' => 'product_variation',
LEFT JOIN {$wpdb->terms} ON ( {$wpdb->terms}.term_id = {$wpdb->term_taxonomy}.term_id ) 'post_status' => 'importing',
WHERE {$wpdb->posts}.post_type IN ( 'product', 'product_variation' ) ) );
AND {$wpdb->posts}.post_status = 'importing'" // @codingStandardsIgnoreEnd.
);
// Clear orphan variations. // Clean up orphaned data.
$wpdb->query( $wpdb->query( "
"DELETE products DELETE {$wpdb->posts}.* FROM {$wpdb->posts}
FROM {$wpdb->posts} products LEFT JOIN {$wpdb->posts} wp ON wp.ID = {$wpdb->posts}.post_parent
LEFT JOIN {$wpdb->posts} wp ON wp.ID = products.post_parent WHERE wp.ID IS NULL AND {$wpdb->posts}.post_type = 'product_variation'
WHERE wp.ID IS NULL AND products.post_type = 'product_variation';" " );
); $wpdb->query( "
DELETE {$wpdb->postmeta}.* FROM {$wpdb->postmeta}
LEFT JOIN {$wpdb->posts} wp ON wp.ID = {$wpdb->postmeta}.post_id
WHERE wp.ID IS NULL
" );
$wpdb->query( "
DELETE {$wpdb->term_relationships}.* FROM {$wpdb->term_relationships}
LEFT JOIN {$wpdb->posts} wp ON wp.ID = {$wpdb->term_relationships}.object_id
WHERE wp.ID IS NULL
" );
// Send success. // Send success.
wp_send_json_success( wp_send_json_success(

View File

@ -543,7 +543,7 @@ class WC_Product_CSV_Importer extends WC_Product_Importer {
* @return int * @return int
*/ */
public function parse_int_field( $value ) { public function parse_int_field( $value ) {
// Remove the ' prepended to fields that start with - if needed // Remove the ' prepended to fields that start with - if needed.
$value = $this->unescape_negative_number( $value ); $value = $this->unescape_negative_number( $value );
return intval( $value ); return intval( $value );