Make WordPress Core

Opened 9 months ago

Last modified 9 months ago

#57385 new defect (bug)

Disable foreign key checks when dropping tables inside wp_uninitialize_site() function

Reported by: naveen17797's profile naveen17797 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Database Keywords: dev-feedback has-patch
Focuses: multisite Cc:

Description

By default when removing the tables from a subsite, if the table has foreign key constraint it wont drop the table resulting in tables not being removed.

so this line should be changed from this to

	foreach ( (array) $drop_tables as $table ) {
		$wpdb->query( "DROP TABLE IF EXISTS `$table`" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
	}
<?php

    $wpdb->query('SET FOREIGN_KEY_CHECKS=0;');
        foreach ( (array) $drop_tables as $table ) {
                $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
        }
    $wpdb->query('SET FOREIGN_KEY_CHECKS=1;');

or any other better alternative.

Change History (1)

This ticket was mentioned in PR #3801 on WordPress/wordpress-develop by @naveen17797.


9 months ago
#1

  • Keywords has-patch added; needs-patch removed
Note: See TracTickets for help on using tickets.