]> git.mxchange.org Git - friendica.git/commitdiff
Add missing public contacts and account-user entries
authorMichael <heluecht@pirati.ca>
Tue, 18 Mar 2025 05:33:01 +0000 (05:33 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 18 Mar 2025 05:33:01 +0000 (05:33 +0000)
src/Worker/Cron.php
src/Worker/FixContacts.php [new file with mode: 0644]

index b576f09ae78003107456f5b768a80386aba7184b..cf0529c8b4ce5a42cf980b11c30afb9bc9ea5a07 100644 (file)
@@ -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 (file)
index 0000000..2961962
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+namespace Friendica\Worker;
+
+use Friendica\Database\DBA;
+use Friendica\DI;
+use Friendica\Model\Contact;
+
+/**
+ * add missing public contacts and account-user entries
+ */
+class FixContacts
+{
+       public static function execute()
+       {
+               $added = 0;
+               DI::logger()->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]);
+               }
+       }
+}