Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix featured image delete push issue #310

Merged
merged 7 commits into from
Sep 14, 2023

Conversation

ravichdev
Copy link
Contributor

If we delete the featured image for a post, it does not delete for the distributed post. This happens only if the featured image is selected from Media Library, works fine if the featured image is uploaded to the actual post.

Steps to reproduce:

  • Create a new post and select a feature image from the Media library, make sure to use an existing image
  • Distribute the post
  • The distributed post will show the featured image
  • Remove the featured image in the original/source post and update
  • The distributed post will still show the featured image

This PR contains an else statement to delete featured image if distributor_media is empty. There are still other places (NetworkSiteConnection.php) which would need a similar condition, I am happy to add those as well if this approach looks good to you.

@helen
Copy link
Contributor

helen commented Jan 29, 2019

Meta deletion is broadly a problem, see #284. Happy to keep this PR open and milestone it if media should be handled separately though, I haven't dug into the code to find out.

@dkotter
Copy link
Collaborator

dkotter commented Feb 26, 2019

So we do handle media and meta separately at the moment (as far as processing and setting), so I think we will probably handle the deletion separately as well. That said, in my mind it makes sense to deal with deletion as one larger task, so we keep in mind all scenarios when implementing this.

I'm not opposed to the approach in this PR but a couple things come to my mind:

  1. Some posts might have media set but not have an actual featured image set. If that post then removes those media items, this approach would delete the featured image meta, even though that meta isn't actually set. Not a huge deal but I like the idea of only deleting things that should be deleted.
  2. This approach only deals with deleting the featured image meta. What about other media meta that might get changed or deleted? Or what about the media items themselves? If the original post removes those, should we delete those entirely from the receiving site?

@adamsilverstein
Copy link

What about other media meta that might get changed or deleted? Or what about the media items themselves? If the original post removes those, should we delete those entirely from the receiving site?

This feels dangerous: what if the images themselves had been used in another post on the destination site?

@jeffpaul jeffpaul added this to the 1.5.0 milestone May 28, 2019
@jeffpaul jeffpaul added the type:enhancement New feature or request. label Jun 6, 2019
@helen
Copy link
Contributor

helen commented Jul 17, 2019

Doesn't seem like we're quite at a consensus about approach/result yet, punting pending further dedicated discussion.

@helen helen modified the milestones: 1.5.0, 1.6.0 Jul 17, 2019
@jeffpaul
Copy link
Member

First, let's separate the terms removal and deletion as they seem to be used interchangably in this PR when they should be considered separate cases. Removal, to me, is that the image is unattached from the post but still available in the Media Library. Deletion, to me, is that the image is deleted/trashed from the site and no longer available on the post or in the Media Library.

My feeling on this is that we could limit this PR to the following use case:
An origin post removes the feature image and that removal is handled on distributed remote posts as well, however it merely removes the featured image from those posts, the image is still available in the remote Medial Libraries, and does not delete the image from those remote sites.

For all other cases, we can cover them via a separate PR in a future release that more fully handles meta and other media removals/deletions.

@jeffpaul jeffpaul added the needs:discussion This requires discussion to determine next steps. label Mar 26, 2020
@arsendovlatyan
Copy link
Contributor

arsendovlatyan commented Mar 30, 2020

Side note: I think it will be good to blacklist _thumbnail_id meta, the value that we are pushing with this meta never works as expected, it's the attachment ID in source, but in destination, it's something else and we are updating this value during media handling process.

For deletion we developed our solution, which is based on dt_original_media_id . Every time, before applying updates on a post in destination, we retrieve all original media IDs of all attachments, that are connected with the post being updated, then we look up this IDs in new update, if an ID is not found, we delete that attachment. For example, we a have post in source website, which has attachments with following IDs (1, 2, 3), when you distribute this post, a new post in destination will have this attachments with different IDs, like ( 5, 6, 7), but their original media ID is saved in dt_original_media_id , if at some point destination receives an update, where attachment IDs are (1, 3), it's means 2 has been deleted in the source, so, we can delete 6 in destination.

I'm not sure if this approach is acceptable or not, but you can find our solution here https://github.com/NovemBit/distributor/blob/develop/includes/utils.php ( I know that it needs improvements before PR)

I think this behavior is safe as long as dt_original_media_id exists only if media was created by Distributor, so, you won't delete attachments created and attached in destination.

@jeffpaul
Copy link
Member

As this PR still needs discussion and we're working to clear the milestone to get nearer a release, I'm going to punt this to the next release in hopes we can get through our discussion and to an agreed approach by then.

@jeffpaul jeffpaul modified the milestones: 1.6.0, 2.1.0 Apr 16, 2020
@helen helen removed their request for review November 15, 2021 17:29
@ravinderk ravinderk requested a review from a team as a code owner June 5, 2023 16:35
@ravinderk ravinderk requested review from dkotter and removed request for a team June 5, 2023 16:35
@jeffpaul jeffpaul requested review from peterwilsoncc and removed request for tlovett1 June 29, 2023 16:04
Copy link
Collaborator

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks good to me and worked while testing with:

  • internal push
  • internal pull
  • external push
  • external pull

It looks like the set_media() utility function was intended to handle this situation but the empty() check means the relevant code doesn't run:

if ( ! $found_featured_image ) {
delete_post_meta( $post_id, '_thumbnail_id' );
}

I've put in a couple of coding style nitpicks but otherwise consider this PR as approved. ✅

This PR is on the 2.1.0 milestone so I'm going to hold of clicking the approve button for now so I don't accidentally merge it prior to the release of 2.0.0 in the coming weeks.

includes/classes/API/SubscriptionsController.php Outdated Show resolved Hide resolved
includes/rest-api.php Outdated Show resolved Hide resolved
Co-authored-by: Peter Wilson <[email protected]>
Copy link
Collaborator

@peterwilsoncc peterwilsoncc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hitting the approve button and merging now that 2.0.0 is released.

This has been added to the milestone for 2.0.1 so should be in the next release.

@peterwilsoncc peterwilsoncc merged commit 726a7e1 into develop Sep 14, 2023
17 checks passed
@peterwilsoncc peterwilsoncc deleted the fix/featured-image-delete branch September 14, 2023 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:discussion This requires discussion to determine next steps. type:enhancement New feature or request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants