2017-11-17 23:16:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file src/Worker/RemoveContact.php
|
2020-01-19 07:05:23 +01:00
|
|
|
* Removes orphaned data from deleted contacts
|
2017-11-17 23:16:34 +01:00
|
|
|
*/
|
|
|
|
namespace Friendica\Worker;
|
|
|
|
|
2018-07-20 14:19:26 +02:00
|
|
|
use Friendica\Database\DBA;
|
2018-08-15 11:27:25 +02:00
|
|
|
use Friendica\Core\Protocol;
|
2018-10-24 06:46:45 +02:00
|
|
|
use Friendica\Model\Item;
|
2017-11-17 23:16:34 +01:00
|
|
|
|
|
|
|
class RemoveContact {
|
|
|
|
public static function execute($id) {
|
|
|
|
|
2018-09-12 08:05:14 +02:00
|
|
|
// Only delete if the contact is to be deleted
|
2020-01-11 18:22:37 +01:00
|
|
|
$contact = DBA::selectFirst('contact', ['uid'], ['deleted' => true]);
|
2018-10-24 06:50:27 +02:00
|
|
|
if (!DBA::isResult($contact)) {
|
2017-11-17 23:16:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-12 19:15:47 +02:00
|
|
|
// Now we delete the contact and all depending tables
|
2018-10-24 06:50:27 +02:00
|
|
|
$condition = ['uid' => $contact['uid'], 'contact-id' => $id];
|
2018-10-24 06:46:45 +02:00
|
|
|
do {
|
|
|
|
$items = Item::select(['id'], $condition, ['limit' => 100]);
|
|
|
|
while ($item = Item::fetch($items)) {
|
|
|
|
DBA::delete('item', ['id' => $item['id']]);
|
|
|
|
}
|
|
|
|
DBA::close($items);
|
|
|
|
} while (Item::exists($condition));
|
|
|
|
|
2018-07-20 14:19:26 +02:00
|
|
|
DBA::delete('contact', ['id' => $id]);
|
2017-11-17 23:16:34 +01:00
|
|
|
}
|
|
|
|
}
|