@@ -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_exists = true ;
161+ if ( $ this ->settings ['offload ' ] !== 'cld ' ) {
162+ $ attachment_file = get_attached_file ( $ attachment_id );
163+ if ( ! file_exists ( $ attachment_file ) ) {
164+ $ file_exists = $ attachment_file ;
165+ }
166+ }
167+
168+ return $ this ->settings ['offload ' ] . $ this ->media ->get_post_meta ( $ attachment_id , Sync::META_KEYS ['public_id ' ], true ) . $ file_exists ;
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 );
@@ -198,7 +207,8 @@ public function sync( $attachment_id ) {
198207 if ( 'cld ' !== $ previous_state ) {
199208 $ this ->remove_local_assets ( $ attachment_id );
200209 }
201- $ this ->download ->download_asset ( $ attachment_id , $ url );
210+ $ date = get_post_datetime ( $ attachment_id );
211+ $ this ->download ->download_asset ( $ attachment_id , $ url , $ date ->format ( 'Y/m ' ) );
202212 }
203213
204214 $ this ->sync ->set_signature_item ( $ attachment_id , 'storage ' );
0 commit comments