[wp-trac] [WordPress Trac] #55329: add_clean_index function throws PHP notice error

WordPress Trac noreply at wordpress.org
Sat Nov 2 18:04:59 UTC 2024


#55329: add_clean_index function throws PHP notice error
-----------------------------+------------------------------
 Reporter:  gvgvgvijayan     |       Owner:  (none)
     Type:  defect (bug)     |      Status:  new
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Upgrade/Install  |     Version:
 Severity:  normal           |  Resolution:
 Keywords:                   |     Focuses:  administration
-----------------------------+------------------------------

Comment (by loondretzoon):

 The PHP notice error in the add_clean_index function likely arises from
 the drop_index function being called without proper checks. To resolve it,
 ensure the column exists before adding the index and handle errors
 gracefully. You can modify your code to check if the column was added
 successfully before attempting to create the index. Here's a quick
 adjustment:
 {{{#!php
 <?php
 function add_country_iso_code_column() {
     global $wpdb;

     $table_name  = $wpdb->base_prefix . 'defender_lockout_log';
     $column_name = 'country_iso_code';
     $create_ddl  = "ALTER TABLE {$table_name} ADD {$column_name} CHAR(2)
 DEFAULT NULL";

     maybe_add_column($table_name, $column_name, $create_ddl);

     // Check if the column was added
     if ($wpdb->get_results("SHOW COLUMNS FROM {$table_name} LIKE
 '{$column_name}'")) {
         add_clean_index($table_name, $column_name);
     } else {
         error_log("Column {$column_name} not added to {$table_name}");
     }
 }

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55329#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list