Skip to content

Commit 56e8cd0

Browse files
committed
use storage to determine if a download should happen
1 parent 1acb4bf commit 56e8cd0

File tree

1 file changed

+11
-2
lines changed
  • cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync

1 file changed

+11
-2
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/sync/class-storage.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,15 @@ public function validate_file_folder_sync( $attachment_id ) {
157157
* @return string
158158
*/
159159
public function generate_signature( $attachment_id ) {
160-
return $this->settings['offload'] . $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true );
160+
$file_exsts = true;
161+
if ( $this->settings['offload'] !== 'cld' ) {
162+
$attachment_file = get_attached_file( $attachment_id );
163+
if ( ! file_exists( $attachment_file ) ) {
164+
$file_exsts = $attachment_file;
165+
}
166+
}
167+
168+
return $this->settings['offload'] . $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true ) . $file_exsts;
161169
}
162170

163171
/**
@@ -184,7 +192,8 @@ public function sync( $attachment_id ) {
184192
$url = $this->media->cloudinary_url( $attachment_id, '', $transformations, null, false, true );
185193
break;
186194
case 'dual_full':
187-
if ( ! empty( $previous_state ) && 'dual_full' !== $previous_state ) {
195+
$exists = get_attached_file( $attachment_id );
196+
if ( ! empty( $previous_state ) && ! file_exists( $exists ) ) {
188197
// Only do this is it's changing a state.
189198
$transformations = $this->media->get_transformation_from_meta( $attachment_id );
190199
$url = $this->media->cloudinary_url( $attachment_id, '', $transformations, null, false, false );

0 commit comments

Comments
 (0)