]> git.mxchange.org Git - friendica.git/blob - src/Worker/RemoveUser.php
Merge pull request #7851 from annando/mail-header
[friendica.git] / src / Worker / RemoveUser.php
1 <?php
2 /**
3  * @file src/Worker/RemoveUser.php
4  * @brief Removes orphaned data from deleted users
5  */
6 namespace Friendica\Worker;
7
8 use Friendica\Database\DBA;
9 use Friendica\Model\Item;
10
11 class RemoveUser {
12         public static function execute($uid)
13         {
14                 // Only delete if the user is archived
15                 $condition = ['account_removed' => true, 'uid' => $uid];
16                 if (!DBA::exists('user', $condition)) {
17                         return;
18                 }
19
20                 // Now we delete all user items
21                 $condition = ['uid' => $uid, 'deleted' => false];
22                 do {
23                         $items = Item::select(['id'], $condition, ['limit' => 100]);
24                         while ($item = Item::fetch($items)) {
25                                 Item::deleteById($item['id'], PRIORITY_NEGLIGIBLE);
26                         }
27                         DBA::close($items);
28                 } while (Item::exists($condition));
29         }
30 }