Skip to content

Commit 08f6e73

Browse files
authored
Merge pull request #410 from cloudinary/fix/migration-update-sync
fix local check and upgrade
2 parents f33e77f + ceef70b commit 08f6e73

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

php/class-media.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ public function get_syncable_delivery_types() {
190190
*/
191191
return apply_filters( 'cloudinary_syncable_delivery_types', $types );
192192
}
193+
193194
/**
194195
* Get convertible extensions and converted file types.
195196
*
@@ -273,9 +274,10 @@ public function is_media( $attachment_id ) {
273274
*/
274275
public function is_local_media( $attachment_id ) {
275276
$local_host = wp_parse_url( get_site_url(), PHP_URL_HOST );
276-
$media_host = wp_parse_url( get_the_guid( $attachment_id ), PHP_URL_HOST );
277+
$guid = get_the_guid( $attachment_id );
278+
$media_host = wp_parse_url( $guid, PHP_URL_HOST );
277279

278-
return $local_host === $media_host;
280+
return $local_host === $media_host || $this->is_cloudinary_url( $guid );
279281
}
280282

281283
/**
@@ -1379,7 +1381,7 @@ public function is_cloudinary_url( $url ) {
13791381
* @return bool
13801382
*/
13811383
public function is_cloudinary_sync_folder( $url ) {
1382-
$path = wp_parse_url( $url, PHP_URL_PATH );
1384+
$path = wp_parse_url( $url, PHP_URL_PATH );
13831385
$parts = explode( '/', $path );
13841386

13851387
// Remove public id and file name.
@@ -1714,18 +1716,15 @@ public function media_column_value( $column_name, $attachment_id ) {
17141716
?>
17151717
<span class="dashicons-cloudinary <?php echo esc_attr( $status['state'] ); ?>" title="<?php echo esc_attr( $status['note'] ); ?>"></span>
17161718
<?php
1717-
endif;
1718-
if ( ! $this->is_local_media( $attachment_id ) ) :
1719+
elseif ( ! $this->is_local_media( $attachment_id ) ) :
17191720
?>
17201721
<span class="dashicons-cloudinary info" title="<?php esc_attr_e( 'Not syncable. This is an external media.', 'cloudinary' ); ?>"></span>
17211722
<?php
1722-
endif;
1723-
if ( 'fetch' === $this->get_media_delivery( $attachment_id ) ) :
1723+
elseif ( 'fetch' === $this->get_media_delivery( $attachment_id ) ) :
17241724
?>
17251725
<span class="dashicons-cloudinary info" title="<?php esc_attr_e( 'This media is Fetch type.', 'cloudinary' ); ?>"></span>
17261726
<?php
1727-
endif;
1728-
if ( 'sprite' === $this->get_media_delivery( $attachment_id ) ) :
1727+
elseif ( 'sprite' === $this->get_media_delivery( $attachment_id ) ) :
17291728
?>
17301729
<span class="dashicons-cloudinary info" title="<?php esc_attr_e( 'This media is Sprite type.', 'cloudinary' ); ?>"></span>
17311730
<?php

php/class-sync.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,14 +302,14 @@ public function get_signature( $attachment_id, $cached = true ) {
302302
/**
303303
* Filter the get signature of the asset.
304304
*
305-
* @hook cloudinary_get_signature
305+
* @hook cloudinary_get_signature
306306
*
307-
* @param $signature {array} The attachment signature.
307+
* @param $return {array} The attachment signature.
308308
* @param $attachment_id {int} The attachment ID.
309309
*
310310
* @return {array}
311311
*/
312-
$return = apply_filters( 'cloudinary_get_signature', $signatures[ $attachment_id ], $attachment_id );
312+
$return = apply_filters( 'cloudinary_get_signature', $return, $attachment_id );
313313

314314
return $return;
315315
}
@@ -496,7 +496,7 @@ public function setup_sync_base_struct() {
496496
),
497497
'meta_cleanup' => array(
498498
'generate' => function ( $attachment_id ) {
499-
$meta = $this->managers['media']->get_post_meta( $attachment_id );
499+
$meta = $this->managers['media']->get_post_meta( $attachment_id );
500500
$return = false;
501501
foreach ( $meta as $key => $value ) {
502502
if ( get_post_meta( $attachment_id, $key, true ) === $value ) {

php/media/class-upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function convert_cloudinary_version( $attachment_id ) {
9898
// Remove extension.
9999
$path = pathinfo( $public_id );
100100
$public_id = str_replace( $path['basename'], $path['filename'], $public_id );
101-
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id );
101+
update_post_meta( $attachment_id, Sync::META_KEYS['public_id'], $public_id );
102102
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['version'], $asset_version );
103103
if ( ! empty( $asset_transformations ) ) {
104104
$this->media->update_post_meta( $attachment_id, Sync::META_KEYS['transformation'], $asset_transformations );

0 commit comments

Comments
 (0)