Skip to content

Commit

Permalink
fix: prevent duplicate downloads of fallback images
Browse files Browse the repository at this point in the history
  • Loading branch information
girishpanchal30 committed Dec 12, 2024
1 parent f6c89d5 commit 7a5937a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions includes/admin/feedzy-rss-feeds-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,7 @@ function ( $attr, $key ) {
$image_source_url = '';
$img_success = true;
$new_post_id = 0;
$img_title = $item['item_title'];
$feed_img_tag = ! empty( $import_featured_img ) && is_string( $import_featured_img ) ? $import_featured_img : '';

// image tag
Expand All @@ -1765,10 +1766,11 @@ function ( $attr, $key ) {
}
} else {
$image_source_url = $feed_img_tag;
$img_title = pathinfo( basename( $image_source_url ), PATHINFO_FILENAME );
}

if ( ! empty( $image_source_url ) ) {
$img_success = $this->try_save_featured_image( $image_source_url, 0, $item['item_title'], $import_errors, $import_info, $new_post );
$img_success = $this->try_save_featured_image( $image_source_url, 0, $img_title, $import_errors, $import_info, $new_post );
$new_post_id = $img_success;
}

Expand Down Expand Up @@ -1850,8 +1852,9 @@ function( $term ) {
do_action( 'feedzy_import_extra', $job, $item_obj, $new_post_id, $import_errors, $import_info );

if ( ! empty( $import_featured_img ) && 'attachment' !== $import_post_type ) {
$image_source_url = '';
$img_success = true;
$image_source_url = '';
$img_success = true;
$img_title = $item['item_title'];

$feed_img_tag = false === strpos( $import_featured_img, '[[{"value":' ) ? $import_featured_img : '[#item_image]'; // Use feed default image when we are using chained actions.

Expand All @@ -1874,6 +1877,7 @@ function( $term ) {
}
} elseif ( wp_http_validate_url( $import_featured_img ) ) {
$image_source_url = $import_featured_img;
$img_title = pathinfo( basename( $image_source_url ), PATHINFO_FILENAME );
}

// Fetch image from graby.
Expand Down Expand Up @@ -1920,7 +1924,7 @@ function( $term ) {
}
}

if ( 'yes' === $import_item_img_url || ! $this->tryReuseExistingFeaturedImage( $img_success, $item['item_title'], $new_post_id ) ) {
if ( 'yes' === $import_item_img_url || ! $this->tryReuseExistingFeaturedImage( $img_success, $img_title, $new_post_id ) ) {
// Run chained actions.
$import_featured_img = rawurldecode( $import_featured_img );
$import_featured_img = trim( $import_featured_img );
Expand All @@ -1934,7 +1938,7 @@ function( $term ) {
update_post_meta( $new_post_id, 'feedzy_item_external_url', $image_source_url );
} else {
// if import_featured_img is a tag.
$img_success = $this->try_save_featured_image( $image_source_url, $new_post_id, $item['item_title'], $import_errors, $import_info );
$img_success = $this->try_save_featured_image( $image_source_url, $new_post_id, $img_title, $import_errors, $import_info );
}
}
}
Expand Down

0 comments on commit 7a5937a

Please sign in to comment.