From 02afac057b84dd60eeec4bd927b5558026542886 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 3 May 2021 12:55:53 +0100 Subject: [PATCH 1/2] Ensure to use core update_post_mate for public_id as it should only be present at root level --- php/class-media.php | 2 +- php/sync/class-upload-sync.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/php/class-media.php b/php/class-media.php index 302b91fa0..a1bb5b672 100644 --- a/php/class-media.php +++ b/php/class-media.php @@ -1477,7 +1477,7 @@ private function create_attachment( $asset, $public_id ) { $sync_key = $asset['sync_key']; // Capture public_id. Use core update_post_meta since this attachment data doesnt exist yet. - $this->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); + update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); // Capture version number. $this->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $asset['version'] ); if ( ! empty( $asset['transformations'] ) ) { diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php index cc613ca06..aa7f068a9 100644 --- a/php/sync/class-upload-sync.php +++ b/php/sync/class-upload-sync.php @@ -271,7 +271,7 @@ function ( $is_synced, $post_id ) use ( $attachment_id ) { // Set folder Synced. $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], $this->media->is_folder_synced( $attachment_id ) ); // Set public_id. - $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); + update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id ); // Set version. $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $result['version'] ); // Set the delivery type. @@ -307,7 +307,7 @@ public function context_update( $attachment_id ) { if ( ! is_wp_error( $result ) ) { $this->sync->set_signature_item( $attachment_id, $type ); - $this->media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $options['public_id'] ); + update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $options['public_id'] ); } return $result; From 237051277d66d16863a5bf87e901182d7ce1bc35 Mon Sep 17 00:00:00 2001 From: Marco Pereirinha Date: Mon, 3 May 2021 12:56:31 +0100 Subject: [PATCH 2/2] Cleanup previous sync and force a new upload of the asset --- php/sync/class-upload-sync.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/php/sync/class-upload-sync.php b/php/sync/class-upload-sync.php index aa7f068a9..ddbac25b5 100644 --- a/php/sync/class-upload-sync.php +++ b/php/sync/class-upload-sync.php @@ -157,14 +157,11 @@ public function handle_bulk_actions( $location, $action, $post_ids ) { switch ( $action ) { case 'cloudinary-push': foreach ( $post_ids as $post_id ) { - if ( ! $this->media->is_local_media( $post_id ) ) { - // Clean up for previous attempts to sync. - $this->sync->delete_cloudinary_meta( $post_id ); - continue; - } if ( ! $this->sync->is_syncable( $post_id ) ) { continue; } + // Clean up for previous syncs and start over. + $this->sync->delete_cloudinary_meta( $post_id ); $this->sync->set_signature_item( $post_id, 'file', '' ); $this->media->delete_post_meta( $post_id, Sync::META_KEYS['public_id'] ); $this->sync->add_to_sync( $post_id );