From 122c3dfd370ab7b94d1e736963deeaf025c144db Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 14 Jul 2021 17:17:31 +0100 Subject: [PATCH 1/3] Keep metas that allow getting the ID from given sync keys --- php/class-media.php | 6 ++++++ php/media/class-upgrade.php | 4 ++-- php/sync/class-upload-sync.php | 7 +++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index 4fa67ad65..b3ae11f72 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1508,6 +1508,12 @@ private function create_attachment( $asset, $public_id ) { $this->update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] ); } + // Create a trackable key in post meta to allow getting public id from URL with transformations. + update_post_meta( $attachment_id, '_' . md5( $sync_key ), true ); + + // Create a trackable key in post meta to allow getting public id from URL. + update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true ); + // capture the delivery type. $this->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $asset['type'] ); // Capture the ALT Text. diff --git a/php/media/class-upgrade.php b/php/media/class-upgrade.php index e70ea727f..f406225d4 100644 --- a/php/media/class-upgrade.php +++ b/php/media/class-upgrade.php @@ -142,8 +142,8 @@ public function convert_cloudinary_version( $attachment_id ) { if ( ! empty( $transformations ) ) { $sync_key .= wp_json_encode( $transformations ); } - delete_post_meta( $attachment_id, '_' . md5( $sync_key ), true ); - delete_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true ); + update_post_meta( $attachment_id, '_' . md5( $sync_key ), true ); + update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true ); // Get a new uncached signature. $this->sync->get_signature( $attachment_id, true ); diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php index d9362db4d..f32e06c97 100644 --- a/php/sync/class-upload-sync.php +++ b/php/sync/class-upload-sync.php @@ -282,6 +282,13 @@ function ( $is_synced, $post_id ) use ( $attachment_id ) { $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $result['version'] ); // Set the delivery type. $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $result['type'] ); + + // Create a trackable key in post meta to allow getting public id from URL with transformations. + update_post_meta( $attachment_id, '_' . md5( $options['public_id'] ), true ); + + // Create a trackable key in post meta to allow getting public id from URL. + update_post_meta( $attachment_id, '_' . md5( 'base_' . $options['public_id'] ), true ); + // Update signature for all that use the same method. $this->sync->sync_signature_by_type( $attachment_id, $type ); // Update options and public_id as well (full sync). From 58638e69a484308877995708a5ff360818fc63f5 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Wed, 14 Jul 2021 17:25:01 +0100 Subject: [PATCH 2/3] Update comment --- php/class-media.php | 4 ++-- php/sync/class-upload-sync.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index b3ae11f72..9cf197e53 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1508,10 +1508,10 @@ private function create_attachment( $asset, $public_id ) { $this->update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] ); } - // Create a trackable key in post meta to allow getting public id from URL with transformations. + // Create a trackable key in post meta to allow getting the attachment id from URL with transformations. update_post_meta( $attachment_id, '_' . md5( $sync_key ), true ); - // Create a trackable key in post meta to allow getting public id from URL. + // Create a trackable key in post meta to allow getting the attachment id from URL. update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true ); // capture the delivery type. diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php index f32e06c97..d8683bcf8 100644 --- a/php/sync/class-upload-sync.php +++ b/php/sync/class-upload-sync.php @@ -283,10 +283,10 @@ function ( $is_synced, $post_id ) use ( $attachment_id ) { // Set the delivery type. $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $result['type'] ); - // Create a trackable key in post meta to allow getting public id from URL with transformations. + // Create a trackable key in post meta to allow getting the attachment id from URL with transformations. update_post_meta( $attachment_id, '_' . md5( $options['public_id'] ), true ); - // Create a trackable key in post meta to allow getting public id from URL. + // Create a trackable key in post meta to allow getting the attachment id from URL. update_post_meta( $attachment_id, '_' . md5( 'base_' . $options['public_id'] ), true ); // Update signature for all that use the same method. From 36514330f2137b8d967b00249aedd766f431455c Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Thu, 15 Jul 2021 00:22:29 +0100 Subject: [PATCH 3/3] The GT override meta is not part of the Cloudinary key --- php/class-delivery.php | 2 +- php/class-media.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/php/class-delivery.php b/php/class-delivery.php index b69b438c3..a47cfb018 100644 --- a/php/class-delivery.php +++ b/php/class-delivery.php @@ -184,7 +184,7 @@ public function process_featured_image( $html, $post_id, $attachment_id ) { $tag_element['atts']['class'][] = 'wp-image-' . $attachment_id; $tag_element['atts']['class'][] = 'wp-post-' . $post_id; - if ( true === (bool) $this->media->get_post_meta( $post_id, Global_Transformations::META_FEATURED_IMAGE_KEY, true ) ) { + if ( true === (bool) get_post_meta( $post_id, Global_Transformations::META_FEATURED_IMAGE_KEY, true ) ) { $tag_element['atts']['class'][] = 'cld-overwrite'; } diff --git a/php/class-media.php b/php/class-media.php index 9cf197e53..58c9a1b6f 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -2107,7 +2107,7 @@ public function get_upload_options( $attachment_id ) { public function maybe_overwrite_featured_image( $attachment_id ) { $overwrite = false; if ( $this->doing_featured_image && $this->doing_featured_image === (int) $attachment_id ) { - $overwrite = (bool) $this->get_post_meta( get_the_ID(), Global_Transformations::META_FEATURED_IMAGE_KEY, true ); + $overwrite = (bool) get_post_meta( get_the_ID(), Global_Transformations::META_FEATURED_IMAGE_KEY, true ); } return $overwrite;