Skip to content

Commit fc6c099

Browse files
committed
set error and remove on success
1 parent 3495303 commit fc6c099

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
5959
// Has public ID, but still has cloudinary, check pending status.
6060
$is_pending = $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['pending'], true );
6161
$attempts = (int) $this->media->get_post_meta( $attachment_id, Sync::META_KEYS['attempts'], true );
62-
$expire = time() - 5;// * 60;
63-
if ( ( empty( $is_pending ) || $is_pending < $expire ) && 10 >= $attempts ) {
62+
if ( ( empty( $is_pending ) || $is_pending < time() - 5 * 60 ) && 10 > $attempts ) {
6463
// Timeout.
6564
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['attempts'], $attempts + 1 );
6665

66+
// return proposed ID to allow front render.
6767
return $this->convert_cloudinary_version( $attachment_id );
6868
}
6969
$cloudinary_id = $public_id;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function handle_failed_download( $attachment_id, $error ) {
9494
$is_pending = $this->plugin->components['media']->get_post_meta( $attachment_id, Sync::META_KEYS['pending'], true );
9595
if ( ! empty( $is_pending ) ) {
9696
// Dont delete if it's a downsync.
97-
delete_post_meta( $attachment_id, Sync::META_KEYS['pending'] );
97+
$this->plugin->components['media']->update_post_meta( $attachment_id, Sync::META_KEYS['sync_error'], __( 'Could not download asset', 'cloudinary' ) );
9898
} else {
9999
// Delete attachment temp.
100100
wp_delete_attachment( $attachment_id, true );
@@ -191,6 +191,7 @@ public function rest_download_asset( \WP_REST_Request $request ) {
191191

192192
// Remove pending.
193193
delete_post_meta( $attachment_id, Sync::META_KEYS['pending'] );
194+
delete_post_meta( $attachment_id, Sync::META_KEYS['sync_error'] );
194195

195196
return rest_ensure_response( $response );
196197
}

0 commit comments

Comments
 (0)