awesomemotive / wp-mail-logging

:envelope: Logs each email sent by WordPress.
49 stars 24 forks source link

Change DB table charset to utf8mb4 #173

Closed donmhico closed 1 year ago

donmhico commented 1 year ago

Description

This PR changes the DB charset and collate from utf8 to utf8mb4. We achieve this for 2 user stories: A. New users (fresh plugin install) and B. Existing users (plugin update).

For new users, we change the CREATE table query to use $wpdb->collate. And for existing users, we provide a UI (upgrade button) in "Settings" that when clicked by the user, will perform the ALTER TABLE query. We do it like this for existing users instead of automatically, informing the user and instructing them to make a backup of their database before performing the ALTER TABLE query.

While it shouldn't have any problems since utf8 is a subset of utf8mb4, it's always best to have a backup ready before doing any DB table alteration.

This PR also includes a fix where we delete other options and a transient when "Cleanup" is toggled on and the plugin is de-activated.

Motivation

Fixes #151 and #144.

Testing procedure

For new / fresh install

  1. Activate the plugin.
  2. Send an email with non-utf8 characters such as emojis 🚀🚢 🥳 .
  3. Check that the email with emoji is logged.
Screen Shot 2023-06-05 at 21 51 35

For existing users (plugin update)

  1. Navigate to your Dashboard -> WP Mail Logging -> Email Log.
  2. You should see a warning admin notice. P.S. You should also see this on the SMTP page.
Screen Shot 2023-06-05 at 21 55 36
  1. When you click the link in the warning notice, you'll be redirected to the Settings page where you'll see Database Upgrade. Click the "Upgrade" button
Screen Shot 2023-06-05 at 21 57 07
  1. You'll see a success notice once the DB migration succeeded.
Screen Shot 2023-06-05 at 21 58 12
  1. Test by sending an email with emoji. You should see that the email is logged.