[wp-trac] [WordPress Trac] #57385: Disable foreign key checks when dropping tables inside wp_uninitialize_site() function

WordPress Trac noreply at wordpress.org
Sat Dec 24 15:01:09 UTC 2022


#57385: Disable foreign key checks when dropping tables inside
wp_uninitialize_site() function
--------------------------+--------------------------------------
 Reporter:  naveen17797   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Database      |    Version:
 Severity:  normal        |   Keywords:  dev-feedback needs-patch
  Focuses:  multisite     |
--------------------------+--------------------------------------
 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
 <?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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57385>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list