Skip to content

Commit e124f2d

Browse files
committed
add folder_sync upgrade script for 1.2.1 and below.
1 parent 043b82c commit e124f2d

File tree

1 file changed

+18
-0
lines changed
  • cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media

1 file changed

+18
-0
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/php/media/class-upgrade.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
6262
// Has public ID, but not fully down synced.
6363
$cloudinary_id = $public_id;
6464
}
65+
} else {
66+
// Backwards compat.
67+
$folder_sync = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], true );
68+
if ( 0 === strlen( $folder_sync ) ) {
69+
// Does not exist, add it to be compatible with v1.2.2.
70+
$public_id = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['public_id'], true );
71+
// Set the folder sync to 0 to flag it by default as not synced.
72+
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], '0' );
73+
if ( false !== strpos( $public_id, '/' ) ) {
74+
$path = pathinfo( $public_id );
75+
$asset_folder = trailingslashit( $path['dirname'] );
76+
$cloudinary_folder = trailingslashit( $this->media->plugin->config['settings']['sync_media']['cloudinary_folder'] );
77+
if ( $asset_folder === $cloudinary_folder ) {
78+
// The asset folder matches the defined cloudinary folder, flag it as being in a folder sync.
79+
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['folder_sync'], '1' );
80+
}
81+
}
82+
}
6583
}
6684

6785
return $cloudinary_id;

0 commit comments

Comments
 (0)