From fc2175260f8b32db464a5b2d131c590f9268ab88 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 12 Oct 2021 20:14:56 -0400 Subject: [PATCH] Move Worker task RemoveContact to Contact\Remove --- src/Model/Contact.php | 2 +- src/Worker/CheckDeletedContacts.php | 2 +- src/Worker/Contact/Remove.php | 47 +++++++++++++++++ src/Worker/RemoveContact.php | 79 ----------------------------- 4 files changed, 49 insertions(+), 81 deletions(-) create mode 100644 src/Worker/Contact/Remove.php delete mode 100644 src/Worker/RemoveContact.php diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 88cd8fdaf3..9aed40cf59 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -823,7 +823,7 @@ class Contact self::update(['archive' => true, 'network' => Protocol::PHANTOM, 'deleted' => true], ['id' => $id]); // Delete it in the background - Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $id); + Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $id); } /** diff --git a/src/Worker/CheckDeletedContacts.php b/src/Worker/CheckDeletedContacts.php index 505d026e3a..385cdc12d5 100644 --- a/src/Worker/CheckDeletedContacts.php +++ b/src/Worker/CheckDeletedContacts.php @@ -34,7 +34,7 @@ class CheckDeletedContacts { $contacts = DBA::select('contact', ['id'], ['deleted' => true]); while ($contact = DBA::fetch($contacts)) { - Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $contact['id']); + Worker::add(PRIORITY_MEDIUM, 'Contact\Remove', $contact['id']); } DBA::close($contacts); } diff --git a/src/Worker/Contact/Remove.php b/src/Worker/Contact/Remove.php new file mode 100644 index 0000000000..a3378fd5aa --- /dev/null +++ b/src/Worker/Contact/Remove.php @@ -0,0 +1,47 @@ +. + * + */ + +namespace Friendica\Worker\Contact; + +use Friendica\Core\Logger; +use Friendica\Database\DBA; + +/** + * Removes a contact and all its related content + */ +class Remove extends RemoveContent +{ + public static function execute(int $id): array + { + $contact = parent::execute($id); + + if (!empty($contact)) { + return []; + } + + $ret = DBA::delete('contact', ['id' => $id]); + Logger::info('Deleted contact', ['id' => $id, 'result' => $ret]); + + $contact['id'] = null; + + return $contact; + } +} diff --git a/src/Worker/RemoveContact.php b/src/Worker/RemoveContact.php deleted file mode 100644 index f64d4d02d5..0000000000 --- a/src/Worker/RemoveContact.php +++ /dev/null @@ -1,79 +0,0 @@ -. - * - */ - -namespace Friendica\Worker; - -use Friendica\Core\Logger; -use Friendica\Database\DBA; -use Friendica\Database\DBStructure; -use Friendica\Model\Photo; -use Friendica\Model\Post; - -/** - * Removes orphaned data from deleted contacts - */ -class RemoveContact { - public static function execute($id) { - if (empty($id)) { - return; - } - - // Only delete if the contact is to be deleted - $contact = DBA::selectFirst('contact', ['id', 'uid', 'url', 'nick', 'name'], ['deleted' => true, 'id' => $id]); - if (!DBA::isResult($contact)) { - return; - } - - Logger::info('Start deleting contact', ['contact' => $contact]); - - // Now we delete the contact and all depending tables - DBA::delete('post-tag', ['cid' => $id]); - - if (DBStructure::existsTable('item')) { - DBA::delete('item', ['author-id' => $id]); - DBA::delete('item', ['owner-id' => $id]); - DBA::delete('item', ['causer-id' => $id]); - DBA::delete('item', ['contact-id' => $id]); - } - - DBA::delete('mail', ['contact-id' => $id]); - DBA::delete('mail', ['author-id' => $id]); - - Post\ThreadUser::delete(['author-id' => $id]); - Post\ThreadUser::delete(['owner-id' => $id]); - Post\ThreadUser::delete(['causer-id' => $id]); - Post\ThreadUser::delete(['contact-id' => $id]); - Post\Thread::delete(['author-id' => $id]); - Post\Thread::delete(['owner-id' => $id]); - Post\Thread::delete(['causer-id' => $id]); - Post\User::delete(['author-id' => $id]); - Post\User::delete(['owner-id' => $id]); - Post\User::delete(['causer-id' => $id]); - Post\User::delete(['contact-id' => $id]); - Post::delete(['author-id' => $id]); - Post::delete(['owner-id' => $id]); - Post::delete(['causer-id' => $id]); - - Photo::delete(['contact-id' => $id]); - $ret = DBA::delete('contact', ['id' => $id]); - Logger::info('Deleted contact', ['id' => $id, 'result' => $ret]); - } -}