Don't delete the post when there is some undeleted post-user

This commit is contained in:
Michael 2022-08-13 12:24:25 +00:00
parent bc3a6b2bb7
commit c6de91a8ec
2 changed files with 7 additions and 0 deletions

View file

@ -565,6 +565,12 @@ class Post
$posts = DBA::select('post-user-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]); $posts = DBA::select('post-user-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
while ($rows = DBA::toArray($posts, false, 100)) { while ($rows = DBA::toArray($posts, false, 100)) {
$uriids = array_column($rows, 'uri-id'); $uriids = array_column($rows, 'uri-id');
// Only delete the "post" entry when all "post-user" entries are deleted
if (!empty($update_fields['deleted']) && DBA::exists('post-user', ['uri-id' => $uriids, 'deleted' => false])) {
unset($update_fields['deleted']);
}
if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) { if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) {
DBA::rollback(); DBA::rollback();
Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]); Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]);

View file

@ -1112,5 +1112,6 @@ function update_1457()
function update_1480() function update_1480()
{ {
DBA::update('contact', ['next-update' => DBA::NULL_DATETIME], ['network' => Protocol::FEDERATED]); DBA::update('contact', ['next-update' => DBA::NULL_DATETIME], ['network' => Protocol::FEDERATED]);
DBA::update('post', ['deleted' => false], ["`uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted`)"]);
return Update::SUCCESS; return Update::SUCCESS;
} }