Skip to content

Commit 7c98a74

Browse files
author
Marco Pereirinha
committed
Abstract is syncable delivery types
1 parent b45adb7 commit 7c98a74

File tree

5 files changed

+31
-48
lines changed

5 files changed

+31
-48
lines changed

php/class-media.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,14 +1688,7 @@ public function media_column( $cols ) {
16881688
*/
16891689
public function media_column_value( $column_name, $attachment_id ) {
16901690
if ( 'cld_status' === $column_name ) {
1691-
if (
1692-
$this->is_media( $attachment_id ) &&
1693-
in_array(
1694-
$this->get_media_delivery( $attachment_id ),
1695-
$this->get_syncable_delivery_types(),
1696-
true
1697-
)
1698-
) :
1691+
if ( $this->sync->is_syncable( $attachment_id ) ) :
16991692
$status = array(
17001693
'state' => 'inactive',
17011694
'note' => esc_html__( 'Not Synced', 'cloudinary' ),

php/class-sync.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,7 @@ public function can_sync( $attachment_id, $type = 'file' ) {
244244
}
245245

246246
// Can sync only syncable delivery types.
247-
if (
248-
! in_array(
249-
$this->managers['media']->get_media_delivery( $attachment_id ),
250-
$this->managers['media']->get_syncable_delivery_types(),
251-
true
252-
)
253-
) {
247+
if ( ! $this->is_syncable( $attachment_id ) ) {
254248
$can = false;
255249
}
256250

@@ -328,6 +322,29 @@ public function generate_public_id( $attachment_id ) {
328322
return ltrim( $public_id, '/' );
329323
}
330324

325+
/**
326+
* Is syncable asset.
327+
*
328+
* @param int $attachment_id The attachment ID.
329+
*
330+
* @return bool
331+
*/
332+
public function is_syncable( $attachment_id ) {
333+
$syncable = false;
334+
if (
335+
$this->managers['media']->is_media( $attachment_id )
336+
&& in_array(
337+
$this->managers['media']->get_media_delivery( $attachment_id ),
338+
$this->managers['media']->get_syncable_delivery_types(),
339+
true
340+
)
341+
) {
342+
$syncable = true;
343+
}
344+
345+
return $syncable;
346+
}
347+
331348
/**
332349
* Register a new sync type.
333350
*

php/sync/class-push-sync.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,7 @@ public function process_assets( $attachments = array() ) {
202202
continue;
203203
}
204204
// Skip unsyncable delivery types.
205-
if (
206-
! in_array(
207-
$this->media->get_media_delivery( $attachment_id ),
208-
$this->media->get_syncable_delivery_types(),
209-
true
210-
)
211-
) {
205+
if ( ! $this->sync->is_syncable( $attachment_id ) ) {
212206
continue;
213207
}
214208
// Flag attachment as being processed.

php/sync/class-upload-sync.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,7 @@ public function add_inline_action( $actions, $post ) {
118118
if ( ! $this->media->is_local_media( $post->ID ) ) {
119119
return $actions;
120120
}
121-
if (
122-
! in_array(
123-
$this->media->get_media_delivery( $post->ID ),
124-
$this->media->get_syncable_delivery_types(),
125-
true
126-
)
127-
) {
121+
if ( ! $this->sync->is_syncable( $post->ID ) ) {
128122
return $actions;
129123
}
130124
if ( ! $this->plugin->components['sync']->is_synced( $post->ID ) ) {
@@ -168,13 +162,7 @@ public function handle_bulk_actions( $location, $action, $post_ids ) {
168162
$this->sync->delete_cloudinary_meta( $post_id );
169163
continue;
170164
}
171-
if (
172-
! in_array(
173-
$this->media->get_media_delivery( $post_id ),
174-
$this->media->get_syncable_delivery_types(),
175-
true
176-
)
177-
) {
165+
if ( ! $this->sync->is_syncable( $post_id ) ) {
178166
continue;
179167
}
180168
$this->sync->set_signature_item( $post_id, 'file', '' );

php/traits/trait-cli.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,7 @@ protected function process_sync( $posts, $total ) {
201201
if (
202202
! $this->plugin->get_component( 'sync' )->is_synced( $asset )
203203
&& $this->plugin->get_component( 'media' )->is_local_media( $asset )
204-
&& in_array(
205-
$this->plugin->get_component( 'media' )->get_media_delivery( $asset ),
206-
$this->plugin->get_component( 'media' )->get_syncable_delivery_types(),
207-
true
208-
)
204+
&& $this->plugin->get_component( 'sync' )->is_syncable( $asset )
209205
) {
210206
$this->plugin->get_component( 'sync' )->managers['push']->process_assets( $asset, $bar );
211207
}
@@ -248,13 +244,8 @@ protected function process_analyze( $posts, $total ) {
248244
$done ++;
249245
$key = '_cld_unsupported';
250246
if (
251-
$this->plugin->get_component( 'media' )->is_media( $asset )
252-
&& $this->plugin->get_component( 'media' )->is_local_media( $asset )
253-
&& in_array(
254-
$this->plugin->get_component( 'media' )->get_media_delivery( $asset ),
255-
$this->plugin->get_component( 'media' )->get_syncable_delivery_types(),
256-
true
257-
)
247+
$this->plugin->get_component( 'media' )->is_local_media( $asset )
248+
&& $this->plugin->get_component( 'sync' )->is_syncable( $asset )
258249
) {
259250
// Add a key.
260251
$key = '_cld_synced';

0 commit comments

Comments
 (0)