X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPost.php;h=aae847664db2093efee10ebc45575a2fa44a39ad;hb=a24febb8b656217a7cd88db205007420cb64485e;hp=5845e713c50402353b5c4c14822089dbfb13fe3c;hpb=d37f3de3e66056bf53f7c311aeed0bb69a088db9;p=friendica.git diff --git a/src/Model/Post.php b/src/Model/Post.php index 5845e713c5..aae847664d 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -1,6 +1,6 @@ $segment])) { + $posts = DBA::select('post-user-view', ['post-user-id'], $condition); + while ($rows = DBA::toArray($posts, false, 100)) { + $puids = array_column($rows, 'post-user-id'); + if (!DBA::update('post-user', $update_fields, ['id' => $puids])) { DBA::rollback(); Logger::notice('Updating post-user failed', ['fields' => $update_fields, 'condition' => $condition]); return false; } $affected_count += DBA::affectedRows(); } - $affected = $affected_count; + DBA::close($posts); + $affected = $affected_count; } $update_fields = DBStructure::getFieldsForTable('post-content', $fields); if (!empty($update_fields)) { $affected_count = 0; - $rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]); - $uriids = array_column($rows, 'uri-id'); - $elements = $uriids; - while (!empty($elements)) { - $segment = array_splice($elements, 0, 100); - if (!DBA::update('post-content', $update_fields, ['uri-id' => $segment])) { + $posts = DBA::select('post-user-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]); + while ($rows = DBA::toArray($posts, false, 100)) { + $uriids = array_column($rows, 'uri-id'); + if (!DBA::update('post-content', $update_fields, ['uri-id' => $uriids])) { DBA::rollback(); Logger::notice('Updating post-content failed', ['fields' => $update_fields, 'condition' => $condition]); return false; } $affected_count += DBA::affectedRows(); } + DBA::close($posts); $affected = max($affected, $affected_count); } $update_fields = DBStructure::getFieldsForTable('post', $fields); if (!empty($update_fields)) { $affected_count = 0; - if (empty($uriids)) { - $rows = DBA::selectToArray('post-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)) { $uriids = array_column($rows, 'uri-id'); - } - $elements = $uriids; - while (!empty($elements)) { - $segment = array_splice($elements, 0, 100); - if (!DBA::update('post', $update_fields, ['uri-id' => $segment])) { + if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) { DBA::rollback(); Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]); return false; } $affected_count += DBA::affectedRows(); } + DBA::close($posts); $affected = max($affected, $affected_count); } $update_fields = Post\DeliveryData::extractFields($fields); if (!empty($update_fields)) { $affected_count = 0; - if (empty($uriids)) { - $rows = DBA::selectToArray('post-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)) { $uriids = array_column($rows, 'uri-id'); - } - $elements = $uriids; - while (!empty($elements)) { - $segment = array_splice($elements, 0, 100); - if (!DBA::update('post-delivery-data', $update_fields, ['uri-id' => $segment])) { + if (!DBA::update('post-delivery-data', $update_fields, ['uri-id' => $uriids])) { DBA::rollback(); Logger::notice('Updating post-delivery-data failed', ['fields' => $update_fields, 'condition' => $condition]); return false; } $affected_count += DBA::affectedRows(); } + DBA::close($posts); $affected = max($affected, $affected_count); } $update_fields = DBStructure::getFieldsForTable('post-thread', $fields); if (!empty($update_fields)) { $affected_count = 0; - $rows = DBA::selectToArray('post-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]); - $uriids = array_column($rows, 'uri-id'); - while (!empty($uriids)) { - $segment = array_splice($uriids, 0, 100); - if (!DBA::update('post-thread', $update_fields, ['uri-id' => $segment])) { + $posts = DBA::select('post-user-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]); + while ($rows = DBA::toArray($posts, false, 100)) { + $uriids = array_column($rows, 'uri-id'); + if (!DBA::update('post-thread', $update_fields, ['uri-id' => $uriids])) { DBA::rollback(); Logger::notice('Updating post-thread failed', ['fields' => $update_fields, 'condition' => $condition]); return false; } $affected_count += DBA::affectedRows(); } + DBA::close($posts); $affected = max($affected, $affected_count); } $update_fields = DBStructure::getFieldsForTable('post-thread-user', $fields); if (!empty($update_fields)) { $affected_count = 0; - $rows = DBA::selectToArray('post-view', ['post-user-id'], $thread_condition); - $thread_puids = array_column($rows, 'post-user-id'); - while (!empty($thread_puids)) { - $segment = array_splice($thread_puids, 0, 100); - if (!DBA::update('post-thread-user', $update_fields, ['post-user-id' => $segment])) { + $posts = DBA::select('post-user-view', ['post-user-id'], $thread_condition); + while ($rows = DBA::toArray($posts, false, 100)) { + $thread_puids = array_column($rows, 'post-user-id'); + if (!DBA::update('post-thread-user', $update_fields, ['post-user-id' => $thread_puids])) { DBA::rollback(); Logger::notice('Updating post-thread-user failed', ['fields' => $update_fields, 'condition' => $condition]); return false; } - $affected_count += DBA::affectedRows(); + $affected_count += DBA::affectedRows(); } + DBA::close($posts); $affected = max($affected, $affected_count); }