1
0
Fork 0

Fix several database issues

This commit is contained in:
Michael 2021-02-16 22:04:03 +00:00
commit 60a6dfa23c
7 changed files with 43 additions and 30 deletions

View file

@ -224,7 +224,7 @@ class Post
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
if ($view == 'post-thread-view') {
$selected = array_merge($selected, ['ignored', 'iid']);
$selected = array_merge($selected, ['ignored']);
}
}

View file

@ -68,9 +68,12 @@ class Profile extends BaseModule
$last_updated = $last_updated_array[$last_updated_key] ?? 0;
// If the page user is the owner of the page we should query for unseen
// items. Otherwise use a timestamp of the last succesful update request.
if ($is_owner || !$last_updated) {
if ($_GET['force'] && !empty($_GET['item'])) {
// When the parent is provided, we only fetch this
$sql_extra4 = " AND `parent` = " . intval($_GET['item']);
} elseif ($is_owner || !$last_updated) {
// If the page user is the owner of the page we should query for unseen
// items. Otherwise use a timestamp of the last succesful update request.
$sql_extra4 = " AND `unseen`";
} else {
$gmupdate = gmdate(DateTimeFormat::MYSQL, $last_updated);

View file

@ -32,6 +32,10 @@ use Friendica\Model\Post;
*/
class RemoveContact {
public static function execute($id) {
if (empty($id)) {
return;
}
// Only delete if the contact is to be deleted
$contact = DBA::selectFirst('contact', ['uid'], ['deleted' => true, 'id' => $id]);
if (!DBA::isResult($contact)) {
@ -47,20 +51,31 @@ class RemoveContact {
} else {
$condition = ['uid' => $contact['uid'], 'contact-id' => $id];
}
do {
$items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
while ($item = Post::fetch($items)) {
Logger::info('Delete removed contact item', ['id' => $item['item-id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
if (DBStructure::existsTable('item')) {
DBA::delete('item', ['id' => $item['item-id']]);
if (DBStructure::existsTable('item')) {
do {
$items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
while ($item = Post::fetch($items)) {
Logger::info('Delete removed contact item', ['id' => $item['item-id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
DBA::delete('item', ['id' => $item['item-id']]);
}
Post::delete(['uri-id' => $item['uri-id']]);
Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]);
Post\Thread::delete(['uri-id' => $item['uri-id']]);
Post\User::delete(['id' => $item['post-user-id']]);
}
DBA::close($items);
} while (Post::exists($condition));
DBA::close($items);
} while (Post::exists($condition));
}
Post\User::delete(['author-id' => $id]);
Post\User::delete(['owner-id' => $id]);
Post\User::delete(['causer-id' => $id]);
Post\User::delete(['contact-id' => $id]);
Post\ThreadUser::delete(['author-id' => $id]);
Post\ThreadUser::delete(['owner-id' => $id]);
Post\ThreadUser::delete(['causer-id' => $id]);
Post\ThreadUser::delete(['contact-id' => $id]);
Post\Thread::delete(['author-id' => $id]);
Post\Thread::delete(['owner-id' => $id]);
Post\Thread::delete(['causer-id' => $id]);
Post::delete(['author-id' => $id]);
Post::delete(['owner-id' => $id]);
Post::delete(['causer-id' => $id]);
Photo::delete(['contact-id' => $id]);
$ret = DBA::delete('contact', ['id' => $id]);