]> git.mxchange.org Git - friendica.git/blob - src/Worker/RemoveContact.php
Merge pull request #6209 from MrPetovan/task/move-config-to-php-array
[friendica.git] / src / Worker / RemoveContact.php
1 <?php
2 /**
3  * @file src/Worker/RemoveContact.php
4  * @brief Removes orphaned data from deleted contacts
5  */
6 namespace Friendica\Worker;
7
8 use Friendica\Database\DBA;
9 use Friendica\Core\Protocol;
10 use Friendica\Model\Item;
11
12 class RemoveContact {
13         public static function execute($id) {
14
15                 // Only delete if the contact is to be deleted
16                 $condition = ['network' => Protocol::PHANTOM, 'id' => $id];
17                 $contact = DBA::selectFirst('contact', ['uid'], $condition);
18                 if (!DBA::isResult($contact)) {
19                         return;
20                 }
21
22                 // Now we delete the contact and all depending tables
23                 $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
24                 do {
25                         $items = Item::select(['id'], $condition, ['limit' => 100]);
26                         while ($item = Item::fetch($items)) {
27                                 DBA::delete('item', ['id' => $item['id']]);
28                         }
29                         DBA::close($items);
30                 } while (Item::exists($condition));
31
32                 DBA::delete('contact', ['id' => $id]);
33         }
34 }