Skip to content

Commit

Permalink
Fixed install issues on some specified WordPress installations.
Browse files Browse the repository at this point in the history
  • Loading branch information
remcotolsma committed Mar 27, 2020
1 parent ea6df3a commit 593e4ff
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@ private function add_foreign_keys() {
private function add_foreign_key( $item ) {
global $wpdb;

/**
* Suppress errors.
*
* We suppress errors because adding foreign keys to for example
* a `$wpdb->users` MyISAM table will trigger the following error:
*
* "Error in query (1005): Can't create table '●●●●●●●●. # Sql-●●●●●●●●●●' (errno: 150)"
*
* @link https://github.com/WordPress/WordPress/blob/5.3/wp-includes/wp-db.php#L1544-L1559
*/
$suppress_errors = $wpdb->suppress_errors( true );

/**
* Check if foreign key exists
*
Expand Down Expand Up @@ -303,6 +315,8 @@ private function add_foreign_key( $item ) {
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared.
$result = $wpdb->query( $item->query );

$wpdb->suppress_errors( $suppress_errors );

if ( false === $result ) {
throw new \Exception(
\sprintf(
Expand All @@ -313,6 +327,8 @@ private function add_foreign_key( $item ) {
);
}
}

$wpdb->suppress_errors( $suppress_errors );
}

/**
Expand Down Expand Up @@ -356,6 +372,24 @@ private function convert_user_meta() {
);
}

/**
* Collate caluse.
*
* Force a specific collate to fix:
* "Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and
* (utf8mb4_unicode_520_ci,IMPLICIT) for operation '='. ".
*
* @link https://dev.mysql.com/doc/refman/8.0/en/charset-collate.html
*/
$collate_clause = '';

if ( ! empty( $wpdb->collate ) ) {
$collate_clause = \sprintf(
'COLLATE %s',
$wpdb->collate
);
}

$query = "
INSERT IGNORE INTO $wpdb->pronamic_pay_mollie_customer_users (
customer_id,
Expand All @@ -368,7 +402,7 @@ private function convert_user_meta() {
$wpdb->pronamic_pay_mollie_customers AS mollie_customer
INNER JOIN
$wpdb->usermeta AS wp_user_meta
ON wp_user_meta.meta_value = mollie_customer.mollie_id COLLATE $wpdb->collate
ON wp_user_meta.meta_value = mollie_customer.mollie_id $collate_clause
INNER JOIN
$wpdb->users AS wp_user
ON wp_user_meta.user_id = wp_user.ID
Expand Down

0 comments on commit 593e4ff

Please sign in to comment.