Skip to content

Commit c4e38a1

Browse files
author
Marco Pereirinha
committed
Cleanup syncing and downloading keys if processes fails
1 parent 0241795 commit c4e38a1

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ public function prepare_upload( $post, $push_sync = false ) {
404404
if ( true === $push_sync ) {
405405
$download = $this->sync->managers['download']->down_sync( $post->ID );
406406
if ( is_wp_error( $download ) ) {
407+
delete_post_meta( $post->ID, Sync::META_KEYS['downloading'] );
407408
update_post_meta( $post->ID, Sync::META_KEYS['sync_error'], $download->get_error_message() );
408409

409410
return new \WP_Error( 'attachment_download_error', $download->get_error_message() );
@@ -681,6 +682,7 @@ public function push_attachments( $attachments ) {
681682
$error = $result->get_error_message();
682683
$stats['fail'][] = $error;
683684
$this->media->update_post_meta( $attachment->ID, Sync::META_KEYS['sync_error'], $error );
685+
delete_post_meta( $attachment->ID, Sync::META_KEYS['syncing'] );
684686
continue;
685687
}
686688

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public function mark( $id, $type = 'done' ) {
140140
$queue[ $type ][] = '<div>' . basename( $file ) . ': ' . $state->get_error_message() . '</div>';
141141
// Add a flag that this file had an error as to not try process it again.
142142
update_post_meta( $id, Sync::META_KEYS['sync_error'], $state->get_error_message() );
143+
delete_post_meta( $id, Sync::META_KEYS['syncing'], $state->get_error_message() );
143144
}
144145
} else {
145146
if ( ! in_array( $id, $queue[ $type ], true ) ) {

0 commit comments

Comments
 (0)