X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FWorker%2FRemoveContact.php;h=28a32160a014c7c830f5f5d5fb71952701792030;hb=d4f7bfa676bc9a8ffcb304912b48b360453d0f3c;hp=9a7a257770ba8982b42d6df1fca13341e08babd6;hpb=39ff6e9ce9251fe69b56ba05ea7bdc1896f34de2;p=friendica.git diff --git a/src/Worker/RemoveContact.php b/src/Worker/RemoveContact.php index 9a7a257770..28a32160a0 100644 --- a/src/Worker/RemoveContact.php +++ b/src/Worker/RemoveContact.php @@ -1,25 +1,54 @@ . + * */ -namespace Friendica\Worker; -use Friendica\Core\Config; -use dba; +namespace Friendica\Worker; -require_once 'include/dba.php'; +use Friendica\Core\Logger; +use Friendica\Database\DBA; +use Friendica\Core\Protocol; +use Friendica\Model\Item; +/** + * Removes orphaned data from deleted contacts + */ class RemoveContact { public static function execute($id) { - // Only delete if the contact doesn't exist (anymore) - $r = dba::exists('contact', ['id' => $id]); - if ($r) { + // Only delete if the contact is to be deleted + $contact = DBA::selectFirst('contact', ['uid'], ['deleted' => true]); + if (!DBA::isResult($contact)) { return; } - // Now we delete all the depending table entries - dba::delete('contact', ['id' => $id]); + // Now we delete the contact and all depending tables + $condition = ['uid' => $contact['uid'], 'contact-id' => $id]; + do { + $items = Item::select(['id', 'guid'], $condition, ['limit' => 100]); + while ($item = Item::fetch($items)) { + Logger::info('Delete removed contact item', ['id' => $item['id'], 'guid' => $item['guid']]); + DBA::delete('item', ['id' => $item['id']]); + } + DBA::close($items); + } while (Item::exists($condition)); + + DBA::delete('contact', ['id' => $id]); } }