Skip to content

Commit 122c3df

Browse files
author
Marco Pereirinha
committed
Keep metas that allow getting the ID from given sync keys
1 parent 7af3814 commit 122c3df

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

php/class-media.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,6 +1508,12 @@ private function create_attachment( $asset, $public_id ) {
15081508
$this->update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset['transformations'] );
15091509
}
15101510

1511+
// Create a trackable key in post meta to allow getting public id from URL with transformations.
1512+
update_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
1513+
1514+
// Create a trackable key in post meta to allow getting public id from URL.
1515+
update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true );
1516+
15111517
// capture the delivery type.
15121518
$this->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $asset['type'] );
15131519
// Capture the ALT Text.

php/media/class-upgrade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ public function convert_cloudinary_version( $attachment_id ) {
142142
if ( ! empty( $transformations ) ) {
143143
$sync_key .= wp_json_encode( $transformations );
144144
}
145-
delete_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
146-
delete_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true );
145+
update_post_meta( $attachment_id, '_' . md5( $sync_key ), true );
146+
update_post_meta( $attachment_id, '_' . md5( 'base_' . $public_id ), true );
147147
// Get a new uncached signature.
148148
$this->sync->get_signature( $attachment_id, true );
149149

php/sync/class-upload-sync.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,13 @@ function ( $is_synced, $post_id ) use ( $attachment_id ) {
282282
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $result['version'] );
283283
// Set the delivery type.
284284
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['delivery'], $result['type'] );
285+
286+
// Create a trackable key in post meta to allow getting public id from URL with transformations.
287+
update_post_meta( $attachment_id, '_' . md5( $options['public_id'] ), true );
288+
289+
// Create a trackable key in post meta to allow getting public id from URL.
290+
update_post_meta( $attachment_id, '_' . md5( 'base_' . $options['public_id'] ), true );
291+
285292
// Update signature for all that use the same method.
286293
$this->sync->sync_signature_by_type( $attachment_id, $type );
287294
// Update options and public_id as well (full sync).

0 commit comments

Comments
 (0)