Simplify contraint

This commit is contained in:
claudiulodro 2018-11-27 11:08:47 -08:00
parent f7f7eebc1c
commit d5f7afbff3
1 changed files with 2 additions and 3 deletions

View File

@ -597,19 +597,18 @@ class WC_Install {
// Add constraint to download logs if the columns matches.
if ( ! empty( $download_permissions_column_type ) && ! empty( $download_log_column_type ) && $download_permissions_column_type === $download_log_column_type ) {
$constraint_prefix = ! is_multisite() || ( is_main_site() && is_main_network() ) ? 'fk_' . $wpdb->prefix : str_replace( $wpdb->base_prefix, 'fk_', $wpdb->prefix );
$fk_result = $wpdb->get_row( "
SELECT COUNT(*) AS fk_count
FROM information_schema.TABLE_CONSTRAINTS
WHERE CONSTRAINT_SCHEMA = '{$wpdb->dbname}'
AND CONSTRAINT_NAME = '{$constraint_prefix}wc_download_log_permission_id'
AND CONSTRAINT_NAME = 'fk_{$wpdb->prefix}wc_download_log_permission_id'
AND CONSTRAINT_TYPE = 'FOREIGN KEY'
AND TABLE_NAME = '{$wpdb->prefix}wc_download_log'
" ); // WPCS: unprepared SQL ok.
if ( 0 === (int) $fk_result->fk_count ) {
$wpdb->query( "
ALTER TABLE `{$wpdb->prefix}wc_download_log`
ADD CONSTRAINT `{$constraint_prefix}wc_download_log_permission_id`
ADD CONSTRAINT `fk_{$wpdb->prefix}wc_download_log_permission_id`
FOREIGN KEY (`permission_id`)
REFERENCES `{$wpdb->prefix}woocommerce_downloadable_product_permissions` (`permission_id`) ON DELETE CASCADE;
" ); // WPCS: unprepared SQL ok.