@@ -231,9 +231,9 @@ public function rest_push_attachments( \WP_REST_Request $request ) {
231231 public function resume_queue () {
232232 // Check if there is a Cloudinary ID in case this was synced on-demand before being processed by the queue.
233233 add_filter ( 'cloudinary_on_demand_sync_enabled ' , '__return_false ' ); // Disable the on-demand sync since we want the status.
234- add_filter ( 'cloudinary_id ' , ' __return_false ' ); // Disable the on-demand sync since we want the status .
234+ define ( 'DOING_BULK_SYNC ' , true ); // Define bulk sync in action .
235235
236- if ( false === $ this ->plugin ->components ['media ' ]->cloudinary_id ( $ this ->post_id ) ) {
236+ if ( ! $ this ->plugin ->components ['sync ' ]->is_synced ( $ this ->post_id ) ) {
237237 $ stat = $ this ->push_attachments ( array ( $ this ->post_id ) );
238238 if ( ! empty ( $ stat ['processed ' ] ) ) {
239239 $ result = 'done ' ;
@@ -357,6 +357,7 @@ public function prepare_upload( $post, $down_sync = false ) {
357357 // First check if this has a file and it can be uploaded.
358358 $ file = get_attached_file ( $ post ->ID );
359359 $ file_size = 0 ;
360+ $ downsync = false ;
360361 if ( empty ( $ file ) ) {
361362 return new \WP_Error ( 'attachment_no_file ' , __ ( 'Attachment did not have a file. ' , 'cloudinary ' ) );
362363 } elseif ( ! file_exists ( $ file ) ) {
@@ -373,6 +374,7 @@ public function prepare_upload( $post, $down_sync = false ) {
373374 }
374375 $ file = get_attached_file ( $ post ->ID );
375376 $ file_size = filesize ( $ file );
377+ $ downsync = true ;
376378 }
377379 }
378380 } else {
@@ -414,7 +416,7 @@ public function prepare_upload( $post, $down_sync = false ) {
414416 }
415417 // Check if this asset is a folder sync.
416418 $ folder_sync = $ media ->get_post_meta ( $ post ->ID , Sync::META_KEYS ['folder_sync ' ], true );
417- if ( ! empty ( $ folder_sync ) ) {
419+ if ( ! empty ( $ folder_sync ) && false === $ downsync ) {
418420 $ public_id_folder = $ cld_folder ; // Ensure the public ID folder is constant.
419421 } else {
420422 // Not folder synced, so set the folder to the folder that the asset originally came from.
@@ -490,7 +492,7 @@ public function prepare_upload( $post, $down_sync = false ) {
490492 $ public_id = ltrim ( $ public_id_folder . $ options ['public_id ' ], '/ ' );
491493 $ return = array (
492494 'file ' => $ file ,
493- 'folder ' => $ cld_folder ,
495+ 'folder ' => ltrim ( $ cld_folder, ' / ' ) ,
494496 'public_id ' => $ public_id ,
495497 'breakpoints ' => array (),
496498 'options ' => $ options ,
@@ -542,7 +544,10 @@ public function push_attachments( $attachments ) {
542544 // Go over each attachment.
543545 foreach ( $ attachments as $ attachment ) {
544546 $ attachment = get_post ( $ attachment );
545- $ upload = $ this ->prepare_upload ( $ attachment ->ID , true );
547+ // Clear upload option cache for this item to allow down sync.
548+ $ this ->upload_options [ $ attachment ->ID ] = false ;
549+
550+ $ upload = $ this ->prepare_upload ( $ attachment ->ID , true );
546551
547552 // Filter out any attachments with problematic options.
548553 if ( is_wp_error ( $ upload ) ) {
0 commit comments