From fcb8892e2fa4055ed4ed3404881bfac8faa554ef Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 18 Mar 2025 05:33:01 +0000 Subject: [PATCH] Add missing public contacts and account-user entries --- src/Worker/Cron.php | 3 +++ src/Worker/FixContacts.php | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 src/Worker/FixContacts.php diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index b576f09ae7..cf0529c8b4 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -121,6 +121,9 @@ class Cron Worker::add(Worker::PRIORITY_LOW, 'UpdateAllSuggestions'); + // add missing public contacts and account-user entries + Worker::add(Worker::PRIORITY_LOW, 'FixContacts'); + if (DI::config()->get('system', 'optimize_tables')) { Worker::add(Worker::PRIORITY_LOW, 'OptimizeTables'); } diff --git a/src/Worker/FixContacts.php b/src/Worker/FixContacts.php new file mode 100644 index 0000000000..2961962bc8 --- /dev/null +++ b/src/Worker/FixContacts.php @@ -0,0 +1,51 @@ +info('Add missing public contacts'); + $contacts = DBA::p("SELECT `contact`.`id` FROM `contact` LEFT JOIN `contact` AS `pcontact` ON `contact`.`uri-id` = `pcontact`.`uri-id` WHERE `pcontact`.`id` IS NULL"); + while ($contact = DBA::fetch($contacts)) { + Contact::selectAccountUserById($contact['id'], ['id']); + $added++; + } + DBA::close($contacts); + + if ($added == 0) { + DI::logger()->info('No public contacts have been added'); + } else { + DI::logger()->info('Missing public contacts have been added', ['added' => $added]); + } + + $added = 0; + DI::logger()->info('Add missing account-user entries'); + $contacts = DBA::p("SELECT `contact`.`id`, `contact`.`uid`, `contact`.`uri-id`, `contact`.`url` FROM `contact` LEFT JOIN `account-user` ON `contact`.`id` = `account-user`.`id` WHERE `contact`.`id` > ? AND `account-user`.`id` IS NULL", 0); + while ($contact = DBA::fetch($contacts)) { + Contact::setAccountUser($contact['id'], $contact['uid'], $contact['uri-id'], $contact['url']); + $added++; + } + DBA::close($contacts); + + if ($added == 0) { + DI::logger()->info('No account-user entries have been added'); + } else { + DI::logger()->info('Missing account-user entries have been added', ['added' => $added]); + } + } +}