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

Improve SQLite support #48

Closed
remcotolsma opened this issue Mar 27, 2024 · 0 comments · Fixed by #49
Closed

Improve SQLite support #48

remcotolsma opened this issue Mar 27, 2024 · 0 comments · Fixed by #49
Assignees

Comments

@remcotolsma
Copy link
Member

The INSERT IGNORE should be INSERT OR IGNORE:
https://stackoverflow.com/questions/12105198/sqlite-how-to-get-insert-or-ignore-to-work

And the BINARY in ON BINARY wp_user_meta.meta_value = mollie_customer.mollie_id is also a problem:

/**
* Convert user meta.
*
* @return void
* @throws \Exception Throws exception when database update query fails.
*/
private function convert_user_meta() {
global $wpdb;
$query = "
INSERT IGNORE 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
FROM
$wpdb->usermeta
WHERE
meta_key IN (
'_pronamic_pay_mollie_customer_id',
'_pronamic_pay_mollie_customer_id_test'
)
AND
meta_value != ''
;
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared.
$result = $wpdb->query( $query );
if ( false === $result ) {
throw new \Exception(
\sprintf(
'Could not convert user meta, database error: %s.',
\esc_html( $wpdb->last_error )
)
);
}
$query = "
INSERT IGNORE INTO $wpdb->pronamic_pay_mollie_customer_users (
customer_id,
user_id
)
SELECT
mollie_customer.id AS mollie_customer_id,
wp_user.ID AS wp_user_id
FROM
$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
INNER JOIN
$wpdb->users AS wp_user
ON wp_user_meta.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 != ''
;
";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Query is prepared.
$result = $wpdb->query( $query );
if ( false === $result ) {
throw new \Exception(
\sprintf(
'Could not convert user meta, database error: %s.',
\esc_html( $wpdb->last_error )
)
);
}
}

Related issues:

Originally posted by @remcotolsma in pronamic/wp-pronamic-pay-with-mollie-for-gravity-forms#4 (comment)

@remcotolsma remcotolsma self-assigned this Mar 27, 2024
@remcotolsma remcotolsma linked a pull request Mar 27, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from Todo to Done in Pronamic Pay Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant