mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-14 12:07:46 +02:00
fix(episode-unpublish): set consistent posts_counts' increments/decrements for actors and episodes
Some episodes could not be unpublished because of out of range error when removing posts. fixes #233
This commit is contained in:
parent
9cc2996261
commit
8acdafd260
5 changed files with 40 additions and 45 deletions
|
|
@ -277,10 +277,12 @@ class PostModel extends BaseUuidModel
|
|||
}
|
||||
|
||||
if ($post->in_reply_to_id === null) {
|
||||
// increment posts_count only if not reply
|
||||
// post is not a reply
|
||||
model('ActorModel', false)
|
||||
->where('id', $post->actor_id)
|
||||
->increment('posts_count');
|
||||
|
||||
Events::trigger('on_post_add', $post);
|
||||
}
|
||||
|
||||
if ($registerActivity) {
|
||||
|
|
@ -314,8 +316,6 @@ class PostModel extends BaseUuidModel
|
|||
]);
|
||||
}
|
||||
|
||||
Events::trigger('on_post_add', $post);
|
||||
|
||||
$this->clearCache($post);
|
||||
|
||||
$this->db->transComplete();
|
||||
|
|
@ -365,26 +365,13 @@ class PostModel extends BaseUuidModel
|
|||
{
|
||||
$this->db->transStart();
|
||||
|
||||
model('ActorModel', false)
|
||||
->where('id', $post->actor_id)
|
||||
->decrement('posts_count');
|
||||
|
||||
if ($post->in_reply_to_id !== null) {
|
||||
// Post to remove is a reply
|
||||
model('PostModel', false)
|
||||
->where('id', $this->uuid->fromString($post->in_reply_to_id) ->getBytes())
|
||||
->decrement('replies_count');
|
||||
|
||||
Events::trigger('on_reply_remove', $post);
|
||||
}
|
||||
|
||||
// remove all post reblogs
|
||||
foreach ($post->reblogs as $reblog) {
|
||||
// FIXME: issue when actor is not local, can't get actor information
|
||||
$this->removePost($reblog);
|
||||
$this->undoReblog($reblog);
|
||||
}
|
||||
|
||||
// remove all post replies
|
||||
// remove all replies
|
||||
foreach ($post->replies as $reply) {
|
||||
$this->removePost($reply);
|
||||
}
|
||||
|
|
@ -427,11 +414,24 @@ class PostModel extends BaseUuidModel
|
|||
]);
|
||||
}
|
||||
|
||||
if ($post->in_reply_to_id === null && $post->reblog_of_id === null) {
|
||||
model('ActorModel', false)
|
||||
->where('id', $post->actor_id)
|
||||
->decrement('posts_count');
|
||||
|
||||
Events::trigger('on_post_remove', $post);
|
||||
} elseif ($post->in_reply_to_id !== null) {
|
||||
// Post to remove is a reply
|
||||
model('PostModel', false)
|
||||
->where('id', $this->uuid->fromString($post->in_reply_to_id) ->getBytes())
|
||||
->decrement('replies_count');
|
||||
|
||||
Events::trigger('on_reply_remove', $post);
|
||||
}
|
||||
|
||||
$result = model('PostModel', false)
|
||||
->delete($post->id);
|
||||
|
||||
Events::trigger('on_post_remove', $post);
|
||||
|
||||
$this->clearCache($post);
|
||||
|
||||
$this->db->transComplete();
|
||||
|
|
@ -574,11 +574,11 @@ class PostModel extends BaseUuidModel
|
|||
]);
|
||||
}
|
||||
|
||||
Events::trigger('on_post_undo_reblog', $reblogPost);
|
||||
|
||||
$result = model('PostModel', false)
|
||||
->delete($reblogPost->id);
|
||||
|
||||
Events::trigger('on_post_undo_reblog', $reblogPost);
|
||||
|
||||
$this->clearCache($reblogPost);
|
||||
|
||||
$this->db->transComplete();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue