Skip to content

Commit 9bffb53

Browse files
authored
Merge pull request #123 from cloudinary/hotfix/sync-status
New sync status
2 parents 07452d6 + aa9c4fe commit 9bffb53

File tree

12 files changed

+75
-16
lines changed

12 files changed

+75
-16
lines changed

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/cloudinary.svg

Lines changed: 2 additions & 0 deletions
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/_variables.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ $color-green : #558b2f;
33
$color-red : #dd2c00;
44
$color-light-grey : #e5e5e5;
55
$color-white : #ffffff;
6-
$color-blue : #0078ff;
6+
$color-blue : #0071ba;
77
$color-orange : #fd9d2c;

cloudinary-image-management-and-manipulation-in-the-cloud-cdn/css/src/components/_brand.scss

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
@font-face {
22
font-family : 'cloudinary';
3-
src : url('fonts/cloudinary.eot?fj77m5');
4-
src : url('fonts/cloudinary.eot?fj77m5#iefix') format('embedded-opentype'),
5-
url('fonts/cloudinary.ttf?fj77m5') format('truetype'),
6-
url('fonts/cloudinary.woff?fj77m5') format('woff'),
7-
url('fonts/cloudinary.svg?fj77m5#cloudinary') format('svg');
3+
src : url('fonts/cloudinary.eot?xr4567gh');
4+
src : url('fonts/cloudinary.eot?xr4567gh#iefix') format('embedded-opentype'),
5+
url('fonts/cloudinary.ttf?xr4567gh') format('truetype'),
6+
url('fonts/cloudinary.woff?xr4567gh') format('woff'),
7+
url('fonts/cloudinary.svg?xr4567gh#cloudinary') format('svg');
88
font-weight : normal;
99
font-style : normal;
1010
}
@@ -48,12 +48,20 @@
4848
}
4949
}
5050

51-
&.warning {
52-
color : $color-orange;
51+
&.info {
52+
color : $color-blue;
5353
}
5454

55-
&.warning {
56-
color : $color-orange;
55+
&.downloading {
56+
&:before {
57+
content: '\e903';
58+
}
59+
}
60+
61+
&.syncing {
62+
&:before {
63+
content: '\e904';
64+
}
5765
}
5866
}
5967
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,7 @@ public function media_column_value( $column_name, $attachment_id ) {
10961096
'state' => 'inactive',
10971097
'note' => esc_html__( 'Not Synced', 'cloudinary' ),
10981098
);
1099+
add_filter( 'cloudinary_flag_sync', '__return_true' );
10991100
if ( false === $this->cloudinary_id( $attachment_id ) ) {
11001101
// If false, lets check why by seeing if the file size is too large.
11011102
$file = get_attached_file( $attachment_id ); // Get the file size to make sure it can exist in cloudinary.
@@ -1112,6 +1113,7 @@ public function media_column_value( $column_name, $attachment_id ) {
11121113
'note' => esc_html__( 'Synced', 'cloudinary' ),
11131114
);
11141115
}
1116+
remove_filter( 'cloudinary_flag_sync', '__return_true' );
11151117
// filter status.
11161118
$status = apply_filters( 'cloudinary_media_status', $status, $attachment_id );
11171119
?>

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class Sync implements Setup, Assets {
4949
'sync_error' => '_sync_error',
5050
'cloudinary' => '_cloudinary_v2',
5151
'folder_sync' => '_folder_sync',
52+
'syncing' => '_cloudinary_syncing',
53+
'downloading' => '_cloudinary_downloading',
5254
);
5355

5456
/**
@@ -100,14 +102,18 @@ public function is_active() {
100102
* @return bool
101103
*/
102104
public function is_synced( $post_id ) {
103-
$return = false;
104105
$signature = $this->get_signature( $post_id );
105106
$expecting = $this->generate_signature( $post_id );
107+
106108
if ( ! empty( $signature ) && ! empty( $expecting ) && $expecting === $signature ) {
107-
$return = $signature;
109+
return true;
108110
}
109111

110-
return $return;
112+
if ( apply_filters( 'cloudinary_flag_sync', '__return_false' ) ) {
113+
update_post_meta( $post_id, Sync::META_KEYS['syncing'], true );
114+
}
115+
116+
return false;
111117
}
112118

113119
/**

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ public function check_cloudinary_version( $cloudinary_id, $attachment_id ) {
9696
return $cloudinary_id;
9797
}
9898

99+
/**
100+
* Checks the status of the media item.
101+
*
102+
* @param array $status Array of state and note.
103+
* @param int $attachment_id The attachment id.
104+
*
105+
* @return array
106+
*/
107+
public function filter_status( $status, $attachment_id ) {
108+
109+
if ( get_post_meta( $attachment_id, Sync::META_KEYS['downloading'] ) ) {
110+
$status['state'] = 'info downloading';
111+
$status['note'] = __( 'Downloading', 'cloudinary' );
112+
}
113+
114+
if ( get_post_meta( $attachment_id, Sync::META_KEYS['syncing'] ) ) {
115+
$status['state'] = 'info syncing';
116+
$status['note'] = __( 'Syncing metadata', 'cloudinary' );
117+
}
118+
119+
return $status;
120+
}
121+
99122
/**
100123
* Convert an image post that was created from Cloudinary v1.
101124
*
@@ -139,6 +162,10 @@ function ( $val ) use ( $media ) {
139162
$path = pathinfo( $public_id );
140163
$public_id = strstr( $public_id, '.' . $path['extension'], true );
141164
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id );
165+
166+
// Flag the download
167+
update_post_meta( $attachment_id, Sync::META_KEYS['downloading'], true );
168+
142169
if ( ! defined( 'DOING_BULK_SYNC' ) ) {
143170
$this->sync->managers['upload']->add_to_sync( $attachment_id ); // Auto sync if upgrading outside of bulk sync.
144171
}
@@ -152,6 +179,9 @@ function ( $val ) use ( $media ) {
152179
public function setup_hooks() {
153180
add_filter( 'validate_cloudinary_id', array( $this, 'check_cloudinary_version' ), 10, 2 ); // Priority 10, to allow prep_on_demand_upload.
154181

182+
// Show sync status.
183+
add_filter( 'cloudinary_media_status', array( $this, 'filter_status' ), 20, 2 );
184+
155185
// Add a redirection to the new plugin settings, from the old plugin.
156186
if ( is_admin() ) {
157187
add_action( 'admin_menu', function () {

0 commit comments

Comments
 (0)