From 1d9b40eee1d7009b9d88d92b5937cf135f9cfa60 Mon Sep 17 00:00:00 2001 From: FredericoAndrade Date: Mon, 11 Nov 2024 13:48:55 +0100 Subject: [PATCH] update all serialized license urls to strings. closes #245 --- readme.md | 10 +++-- .../includes/unserialize_license_link.php | 38 +++++++++++++++++++ .../themes/blankslate-child/single-videos.php | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 wp-content/themes/blankslate-child/includes/unserialize_license_link.php diff --git a/readme.md b/readme.md index 5c3f71b2..71d4934d 100644 --- a/readme.md +++ b/readme.md @@ -148,9 +148,7 @@ Database access through Beekeeper Studio is only possible while the SSH tunnel i - **Database User Not Allowed**: Use the MariaDB console to grant appropriate privileges (`GRANT ALL PRIVILEGES` commands) as described in Step 2. ## Database Sync -Work is underway to syncronize databases across environments -Utilizing WP-CLI -Local database syncs are accomplished with the `tool-sync-db-from-prod.sh` script. +Work is underway to syncronize databases across environments. To sync your local database up with Prod, run `bash tool-sync-db-from-prod.sh` from your local terminal. # CSS and Compiling Stylus @@ -191,6 +189,12 @@ Some of our advanced features are maintained as custom plugins. At present, we h /includes/templates/* ``` +# Errors + +Localhost db view error: `The user specified as a definer ('wikitong_master'@'localhost') does not exist` +1. `DROP VIEW IF EXISTS languages_view;` +1. Recreate the View + # To-Do ## Code structure and styles diff --git a/wp-content/themes/blankslate-child/includes/unserialize_license_link.php b/wp-content/themes/blankslate-child/includes/unserialize_license_link.php new file mode 100644 index 00000000..ecff3dca --- /dev/null +++ b/wp-content/themes/blankslate-child/includes/unserialize_license_link.php @@ -0,0 +1,38 @@ +get_results(" + SELECT meta_id, meta_value + FROM {$wpdb->postmeta} + WHERE meta_key = 'license_link' + AND (meta_value LIKE 'a:%' OR meta_value LIKE 's:%') +"); + +foreach ($serialized_entries as $entry) { + $meta_id = $entry->meta_id; + $serialized_value = maybe_unserialize($entry->meta_value); + + // Check if it's an array (from serialized data), get the first item; otherwise, use the value as-is. + $plain_text_value = is_array($serialized_value) ? $serialized_value[0] : $serialized_value; + + // Update the meta_value with the plain text URL. + $updated = $wpdb->update( + $wpdb->postmeta, + ['meta_value' => $plain_text_value], + ['meta_id' => $meta_id], + ['%s'], + ['%d'] + ); + + if ($updated) { + echo "Updated meta_id {$meta_id} to: {$plain_text_value}\n"; + } else { + echo "No update was made for meta_id {$meta_id}. It may already be plain text or an error occurred.\n"; + } +} + +echo "All serialized entries for 'license_link' have been processed.\n"; diff --git a/wp-content/themes/blankslate-child/single-videos.php b/wp-content/themes/blankslate-child/single-videos.php index c36f6a62..ee10d26f 100644 --- a/wp-content/themes/blankslate-child/single-videos.php +++ b/wp-content/themes/blankslate-child/single-videos.php @@ -13,7 +13,7 @@ $reversed_license_link = array_reverse($license_link); $video_license_url = array_pop($reversed_license_link); } else { - $video_license_url = ''; + $video_license_url = $license_link; } $featured_languages = get_field('featured_languages');