WordPress.org

Make WordPress Core

Opened 10 years ago

Closed 10 years ago

#11707 closed enhancement (fixed)

Automatic repair of plugin-created tables

Reported by: neoxx Owned by: nacin
Milestone: 3.0 Priority: normal
Severity: normal Version: 2.9
Component: Plugins Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

Hi,

I've just noticed that additional tables that are created by plugins are not included in the new automatic repair procedure because of the following code in /wp-admin/maint/repair.php.

// Loop over the WP tables, checking and repairing as needed.
foreach ($wpdb->tables as $table)

What do you think about changing the loop to include all tables which adhere to the $wpdb->prefix syntax (see attached patch)? Imho, if an author follows all the instructions of the tutorial 'Creating Tables with Plugins' http://codex.wordpress.org/Creating_Tables_with_Plugins he/she should also benefit from this new functionality.

Greetz,
Berny

Attachments (2)

11707.diff (3.4 KB) - added by neoxx 10 years ago.
11707_include_all_tables.diff (3.3 KB) - added by neoxx 10 years ago.

Download all attachments as: .zip

Change History (9)

#1 @Denis-de-Bernardy
10 years ago

+1 to the idea, but we also need the custom users table and the custom usermeta table, if either or both are defined.

#2 @Denis-de-Bernardy
10 years ago

some kind of filter would also be a good idea, in the event that a plugin adds a few domain-wide tables that aren't prefixed.

#3 @dd32
10 years ago

+1 for a filter.

Personally i'd just do a merge of the SQL Query + $wpdb->tables and filter duplicates.

@neoxx
10 years ago

#4 @neoxx
10 years ago

Thanks for the feedback. - I've updated the patch attachment:ticket:11707:11707.diff which now includes a filter called repair_tables and merged the tables retrieved from the SQL query with the default wp tables whereas old tables are excluded.

As repairing and optimizing the database would - in my opinion - mean no harm, we could also use the second variant of the patch attachment:ticket:11707:11707_include_all_tables.diff which simple queries for all tables in the current database.

Let me know what you think.

Remark: This patch also removes two typos.

#5 @nacin
10 years ago

Typos patched for 2.9.2 - #11715.

I like the idea of also including CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE if they're defined.

#6 @nacin
10 years ago

  • Keywords needs-patch added; plugins repair db has-patch removed
  • Owner changed from westi to nacin
  • Status changed from new to reviewing

repair.php now uses wpdb::tables(), so custom user tables are now handled. It also has some MS support now. I suggest we array_merge() apply_filters( 'tables_to_repair', array() ); as a start.

#7 @nacin
10 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed
Note: See TracTickets for help on using tickets.