Added initial fill of attribute values for variations in the init procedure.

This commit is contained in:
Peter Fabian 2018-11-30 13:54:21 +01:00
parent 9389cf4089
commit bfcb709eef
2 changed files with 33 additions and 0 deletions

View File

@ -119,6 +119,10 @@ class WC_Install {
), ),
'3.5.2' => array( '3.5.2' => array(
'wc_update_352_drop_download_log_fk', 'wc_update_352_drop_download_log_fk',
),
'3.5.3' => array(
'wc_update_353_db_version',
'wc_update_353_set_attrib_values_to_excerpt',
) )
); );

View File

@ -1894,3 +1894,32 @@ function wc_update_352_drop_download_log_fk() {
$wpdb->query( "ALTER TABLE {$wpdb->prefix}wc_download_log DROP FOREIGN KEY fk_wc_download_log_permission_id" ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared $wpdb->query( "ALTER TABLE {$wpdb->prefix}wc_download_log DROP FOREIGN KEY fk_wc_download_log_permission_id" ); // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
} }
} }
/**
* Update DB Version.
*/
function wc_update_353_db_version() {
WC_Install::update_db_version( '3.5.3' );
}
/*
* Add attribute values to post_excerpt to allow searching variations without JOINs for each attribute.
*/
function wc_update_353_set_attrib_values_to_excerpt() {
global $wpdb;
$variation_ids = $wpdb->get_results( "SELECT ID from {$wpdb->prefix}posts WHERE post_type='product_variation'", ARRAY_A );
foreach ( $variation_ids as $variation_id ) {
$variation_id = $variation_id['ID'];
$variation_product = wc_get_product( $variation_id );
$attribute_values = wc_get_formatted_variation( $variation_product, true, false );
if ( '' !== $attribute_values ) {
$wpdb->query(
$wpdb->prepare(
"UPDATE {$wpdb->prefix}posts SET post_excerpt=%s WHERE ID=%d",
$attribute_values, $variation_id
)
);
}
}
}