v1.1.0
This commit is contained in:
parent
5cdf7f48e5
commit
2c300652a6
9 changed files with 230 additions and 82 deletions
|
|
@ -84,7 +84,8 @@ class Robotstxt_Mlp2_Mlp5_Table_Preparer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return all tables in the database with the original MLP2 prefix.
|
||||
* Return all tables in the database with the original MLP2 prefix,
|
||||
* excluding tables that belong to this plugin.
|
||||
*
|
||||
* @return string[] Array of full table names.
|
||||
*/
|
||||
|
|
@ -96,7 +97,21 @@ class Robotstxt_Mlp2_Mlp5_Table_Preparer {
|
|||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
$tables = $wpdb->get_col( $wpdb->prepare( 'SHOW TABLES LIKE %s', $like ) );
|
||||
|
||||
return is_array( $tables ) ? $tables : array();
|
||||
if ( ! is_array( $tables ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$prefix = $wpdb->base_prefix . self::ORIGINAL_FRAGMENT;
|
||||
|
||||
return array_values(
|
||||
array_filter(
|
||||
$tables,
|
||||
static function ( string $table ) use ( $prefix ): bool {
|
||||
$suffix = substr( $table, strlen( $prefix ) );
|
||||
return ! in_array( $suffix, self::PLUGIN_TABLE_SUFFIXES, true );
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,6 +130,73 @@ class Robotstxt_Mlp2_Mlp5_Table_Preparer {
|
|||
return is_array( $tables ) ? $tables : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sitemeta key prefix used by MLP2 that blocks MLP5 activation.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SITEMETA_ORIGINAL_PREFIX = 'inpsyde_multilingual';
|
||||
|
||||
/**
|
||||
* Prefix prepended to MLP2 sitemeta keys when backing them up.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const SITEMETA_BACKUP_PREFIX = 'mlp2bak_inpsyde_multilingual';
|
||||
|
||||
/**
|
||||
* Rename MLP2 blocking sitemeta keys to backup names.
|
||||
*
|
||||
* MLP5's SystemChecker detects any sitemeta key starting with
|
||||
* `inpsyde_multilingual` and refuses to activate. This method renames
|
||||
* those keys to `mlp2bak_inpsyde_multilingual*` so MLP5 can activate
|
||||
* cleanly while the original data is preserved for restore or cleanup.
|
||||
*
|
||||
* @return int Number of sitemeta rows renamed.
|
||||
*/
|
||||
public static function rename_mlp2_sitemeta(): int {
|
||||
global $wpdb;
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
$renamed = $wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$wpdb->sitemeta} SET meta_key = CONCAT( %s, SUBSTR( meta_key, %d ) ) WHERE meta_key LIKE %s AND site_id = %d",
|
||||
'mlp2bak_',
|
||||
1,
|
||||
$wpdb->esc_like( self::SITEMETA_ORIGINAL_PREFIX ) . '%',
|
||||
get_current_network_id()
|
||||
)
|
||||
);
|
||||
|
||||
return is_int( $renamed ) ? $renamed : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore backup sitemeta keys to their original MLP2 names.
|
||||
*
|
||||
* Reverses rename_mlp2_sitemeta(). Only use this before MLP5 has been
|
||||
* activated, as restoring these keys will block MLP5 activation again.
|
||||
*
|
||||
* @return int Number of sitemeta rows restored.
|
||||
*/
|
||||
public static function restore_mlp2_sitemeta(): int {
|
||||
global $wpdb;
|
||||
|
||||
$prefix_length = strlen( 'mlp2bak_' ) + 1; // SUBSTR is 1-indexed.
|
||||
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
|
||||
$restored = $wpdb->query(
|
||||
$wpdb->prepare(
|
||||
"UPDATE {$wpdb->sitemeta} SET meta_key = SUBSTR( meta_key, %d ) WHERE meta_key LIKE %s AND site_id = %d",
|
||||
$prefix_length,
|
||||
$wpdb->esc_like( self::SITEMETA_BACKUP_PREFIX ) . '%',
|
||||
get_current_network_id()
|
||||
)
|
||||
);
|
||||
|
||||
return is_int( $restored ) ? $restored : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether any original MLP2 tables exist in the database.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue