Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer use INSERT IGNORE and BINARY operator #49

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,27 @@ private function convert_user_meta() {
global $wpdb;

$query = "
INSERT IGNORE INTO $wpdb->pronamic_pay_mollie_customers (
INSERT INTO $wpdb->pronamic_pay_mollie_customers (
mollie_id,
test_mode
)
SELECT
meta_value AS mollie_id,
'_pronamic_pay_mollie_customer_id_test' = meta_key AS test_mode
usermeta.meta_value AS mollie_id,
'_pronamic_pay_mollie_customer_id_test' = usermeta.meta_key AS test_mode
FROM
$wpdb->usermeta
$wpdb->usermeta AS usermeta
LEFT JOIN
$wpdb->pronamic_pay_mollie_customers AS mollie_customer
ON CAST( usermeta.meta_value AS BINARY ) = CAST( mollie_customer.mollie_id AS BINARY )
WHERE
meta_key IN (
usermeta.meta_key IN (
'_pronamic_pay_mollie_customer_id',
'_pronamic_pay_mollie_customer_id_test'
)
AND
meta_value != ''
usermeta.meta_value != ''
AND
mollie_customer.id IS NULL
;
";

Expand All @@ -343,7 +348,7 @@ private function convert_user_meta() {
}

$query = "
INSERT IGNORE INTO $wpdb->pronamic_pay_mollie_customer_users (
INSERT INTO $wpdb->pronamic_pay_mollie_customer_users (
customer_id,
user_id
)
Expand All @@ -354,17 +359,22 @@ private function convert_user_meta() {
$wpdb->pronamic_pay_mollie_customers AS mollie_customer
INNER JOIN
$wpdb->usermeta AS wp_user_meta
ON BINARY wp_user_meta.meta_value = mollie_customer.mollie_id
ON CAST( wp_user_meta.meta_value AS BINARY ) = CAST( mollie_customer.mollie_id AS BINARY )
INNER JOIN
$wpdb->users AS wp_user
ON wp_user_meta.user_id = wp_user.ID
LEFT JOIN
$wpdb->pronamic_pay_mollie_customer_users AS mollie_customer_user
ON ( mollie_customer_user.customer_id = mollie_customer.id AND mollie_customer_user.user_id = wp_user.ID )
WHERE
wp_user_meta.meta_key IN (
'_pronamic_pay_mollie_customer_id',
'_pronamic_pay_mollie_customer_id_test'
)
AND
wp_user_meta.meta_value != ''
AND
mollie_customer_user.id IS NULL
;
";

Expand Down
Loading