Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions php/class-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ public function get_cloudinary_id( $attachment_id ) {
$extension = $image_format;
}
}
$cloudinary_id = $public_id;
if ( 'fetch' !== $this->get_media_delivery( $attachment_id ) ) {
$cloudinary_id = $public_id . '.' . $extension;
}
Expand Down Expand Up @@ -1687,14 +1688,7 @@ public function media_column( $cols ) {
*/
public function media_column_value( $column_name, $attachment_id ) {
if ( 'cld_status' === $column_name ) {
if (
$this->is_media( $attachment_id ) &&
in_array(
$this->get_media_delivery( $attachment_id ),
$this->get_syncable_delivery_types(),
true
)
) :
if ( $this->sync->is_syncable( $attachment_id ) ) :
$status = array(
'state' => 'inactive',
'note' => esc_html__( 'Not Synced', 'cloudinary' ),
Expand Down
62 changes: 55 additions & 7 deletions php/class-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Cloudinary\Sync\Push_Sync;
use Cloudinary\Sync\Sync_Queue;
use Cloudinary\Sync\Upload_Sync;
use WP_Error;

/**
* Class Sync
Expand Down Expand Up @@ -244,13 +245,7 @@ public function can_sync( $attachment_id, $type = 'file' ) {
}

// Can sync only syncable delivery types.
if (
! in_array(
$this->managers['media']->get_media_delivery( $attachment_id ),
$this->managers['media']->get_syncable_delivery_types(),
true
)
) {
if ( ! $this->is_syncable( $attachment_id ) ) {
$can = false;
}

Expand Down Expand Up @@ -304,6 +299,18 @@ public function get_signature( $attachment_id, $cached = true ) {
$return = wp_parse_args( $signature, $this->sync_types );
}

/**
* Filter the get signature of the asset.
*
* @hook cloudinary_get_signature
*
* @param $signature {array} The attachment signature.
* @param $attachment_id {int} The attachment ID.
*
* @return {array}
*/
$return = apply_filters( 'cloudinary_get_signature', $signatures[ $attachment_id ], $attachment_id );

return $return;
}

Expand All @@ -328,6 +335,29 @@ public function generate_public_id( $attachment_id ) {
return ltrim( $public_id, '/' );
}

/**
* Is syncable asset.
*
* @param int $attachment_id The attachment ID.
*
* @return bool
*/
public function is_syncable( $attachment_id ) {
$syncable = false;
if (
$this->managers['media']->is_media( $attachment_id )
&& in_array(
$this->managers['media']->get_media_delivery( $attachment_id ),
$this->managers['media']->get_syncable_delivery_types(),
true
)
) {
$syncable = true;
}

return $syncable;
}

/**
* Register a new sync type.
*
Expand Down Expand Up @@ -856,6 +886,23 @@ public function filter_get_cloudinary_folder( $value, $slug ) {
return $value;
}

/**
* Filter the signature.
*
* @param array $signature The signature array.
* @param int $attachment_id The attachment ID.
*
* @return array|bool|string|WP_Error
*/
public function get_signature_syncable_type( $signature, $attachment_id ) {

if ( ! $this->is_syncable( $attachment_id ) ) {
$signature = $this->generate_signature( $attachment_id );
}

return $signature;
}

/**
* Checks if auto sync feature is enabled.
*
Expand Down Expand Up @@ -916,6 +963,7 @@ public function setup() {
$this->managers['queue']->setup( $this );

add_filter( 'cloudinary_setting_get_value', array( $this, 'filter_get_cloudinary_folder' ), 10, 2 );
add_filter( 'cloudinary_get_signature', array( $this, 'get_signature_syncable_type' ), 10, 2 );
}
}

Expand Down
8 changes: 1 addition & 7 deletions php/sync/class-push-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,7 @@ public function process_assets( $attachments = array() ) {
continue;
}
// Skip unsyncable delivery types.
if (
! in_array(
$this->media->get_media_delivery( $attachment_id ),
$this->media->get_syncable_delivery_types(),
true
)
) {
if ( ! $this->sync->is_syncable( $attachment_id ) ) {
continue;
}
// Flag attachment as being processed.
Expand Down
16 changes: 2 additions & 14 deletions php/sync/class-upload-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,7 @@ public function add_inline_action( $actions, $post ) {
if ( ! $this->media->is_local_media( $post->ID ) ) {
return $actions;
}
if (
! in_array(
$this->media->get_media_delivery( $post->ID ),
$this->media->get_syncable_delivery_types(),
true
)
) {
if ( ! $this->sync->is_syncable( $post->ID ) ) {
return $actions;
}
if ( ! $this->plugin->components['sync']->is_synced( $post->ID ) ) {
Expand Down Expand Up @@ -168,13 +162,7 @@ public function handle_bulk_actions( $location, $action, $post_ids ) {
$this->sync->delete_cloudinary_meta( $post_id );
continue;
}
if (
! in_array(
$this->media->get_media_delivery( $post_id ),
$this->media->get_syncable_delivery_types(),
true
)
) {
if ( ! $this->sync->is_syncable( $post_id ) ) {
continue;
}
$this->sync->set_signature_item( $post_id, 'file', '' );
Expand Down
15 changes: 3 additions & 12 deletions php/traits/trait-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ protected function process_sync( $posts, $total ) {
if (
! $this->plugin->get_component( 'sync' )->is_synced( $asset )
&& $this->plugin->get_component( 'media' )->is_local_media( $asset )
&& in_array(
$this->plugin->get_component( 'media' )->get_media_delivery( $asset ),
$this->plugin->get_component( 'media' )->get_syncable_delivery_types(),
true
)
&& $this->plugin->get_component( 'sync' )->is_syncable( $asset )
) {
$this->plugin->get_component( 'sync' )->managers['push']->process_assets( $asset, $bar );
}
Expand Down Expand Up @@ -248,13 +244,8 @@ protected function process_analyze( $posts, $total ) {
$done ++;
$key = '_cld_unsupported';
if (
$this->plugin->get_component( 'media' )->is_media( $asset )
&& $this->plugin->get_component( 'media' )->is_local_media( $asset )
&& in_array(
$this->plugin->get_component( 'media' )->get_media_delivery( $asset ),
$this->plugin->get_component( 'media' )->get_syncable_delivery_types(),
true
)
$this->plugin->get_component( 'media' )->is_local_media( $asset )
&& $this->plugin->get_component( 'sync' )->is_syncable( $asset )
) {
// Add a key.
$key = '_cld_synced';
Expand Down