3 * @file src/Worker/RemoveContact.php
4 * @brief Removes orphaned data from deleted contacts
6 namespace Friendica\Worker;
8 use Friendica\Database\DBA;
9 use Friendica\Core\Protocol;
10 use Friendica\Model\Item;
12 require_once 'include/dba.php';
15 public static function execute($id) {
17 // Only delete if the contact is to be deleted
18 $condition = ['network' => Protocol::PHANTOM, 'id' => $id];
19 $contact = DBA::selectFirst('contact', ['uid'], $condition);
20 if (!DBA::isResult($contact)) {
24 // Now we delete the contact and all depending tables
25 $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
27 $items = Item::select(['id'], $condition, ['limit' => 100]);
28 while ($item = Item::fetch($items)) {
29 DBA::delete('item', ['id' => $item['id']]);
32 } while (Item::exists($condition));
34 DBA::delete('contact', ['id' => $id]);