Subscriptions being deleted
We use distributor very intensively in our setup, even have several add-ons (not documented yet, but working very well for us https://github.com/NovemBit?utf8=%E2%9C%93&q=distributor&type=&language= ) so, there is chance that problem is coming from our add-ons, however, I would like to hear your thoughts as well.
We have only external connections, no multi-site or internal connections, we have a central site (CMS) from where we are distributing posts to other sites (receiving sites). I monitored one of our receiving site's today and have found ~ 3900 dt_original_post_id meta values, but when I'm filtering meta values on CMS with dt_subscription_target_url where value contains that receiving site's URL, there is ~2700 rows, which means we have ~1200 subscriptions deleted from CMS, do you have an idea how this can happen ? How can subscription be deleted, is there a way that receiving site can send a notification to delete subscription from where the post has been distributed ? As much as I can see it tries to do something like that, but looks like there is a bug and it cannot work.
While looking in code, I can see that subscription can be deleted if post was not found on remote, i.e. get_post returns empty value, this looks good to me https://github.com/10up/distributor/blob/025cc7ea5e8e693ad35f676809cd95e2e093cb78/includes/classes/API/SubscriptionsController.php#L199
The other case is a bit confused, we are trying to delete subscription before deleting a post https://github.com/10up/distributor/blob/025cc7ea5e8e693ad35f676809cd95e2e093cb78/includes/subscriptions.php#L24
Then, if post has dt_original_source_id and dt_original_post_id, we are trying to instantiate an external connection based on dt_original_source_id, this is a bit strange, since dt_original_source_id must be the connection post ID from where it has been distributed (at least this is how it works in our case)
https://github.com/10up/distributor/blob/025cc7ea5e8e693ad35f676809cd95e2e093cb78/includes/subscriptions.php#L195
Finally, we are trying to get dt_external_connection_type meta on this post, which obviously is wrong, even if it will return that value :)
https://github.com/10up/distributor/blob/025cc7ea5e8e693ad35f676809cd95e2e093cb78/includes/classes/ExternalConnection.php#L130
I really don't think if our problems come from here, so, if you have other ideas, will be happy to hear them.
Also, I'm wondering why we don't remove subscriptions from dt_connection_map meta, when post on receiving end has been deleted , as you can see in, we update only dt_subscriptions meta
https://github.com/10up/distributor/blob/025cc7ea5e8e693ad35f676809cd95e2e093cb78/includes/subscriptions.php#L317
@arsendovlatyan can you confirm any other plugins installed to help triage if there's a plugin conflict at play here?
@jeffpaul we have ~250 plugins installed, also, some add-ons for Distributor that we built (like Woo integration, ACF integration etc), so, I have created this issue more for code review, it seems to be outdated.