]> git.mxchange.org Git - friendica.git/commitdiff
Fix user-contact rows not being updated in Contact\User::updateByContactUpdate
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 10 Nov 2021 12:30:02 +0000 (07:30 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 21 Nov 2021 23:59:37 +0000 (18:59 -0500)
- Add new update function to regenerate potentially outdated user-contact rows

src/Model/Contact/User.php
update.php

index 05530cccc5a7cdf503bf1c1fbcf1a9551c6cd76f..984d1ce986501887067b23e362968d24f39bc9c1 100644 (file)
@@ -95,16 +95,17 @@ class User
                $update_fields = self::preparedFields($fields);
                if (!empty($update_fields)) {
                        $contacts = DBA::select('contact', ['uri-id', 'uid'], $condition);
-                       while ($row = DBA::fetch($contacts)) {
-                               if (empty($row['uri-id']) || empty($contact['uid'])) {
+                       while ($contact = DBA::fetch($contacts)) {
+                               if (empty($contact['uri-id']) || empty($contact['uid'])) {
                                        continue;
                                }
-                               $ret = DBA::update('user-contact', $update_fields, ['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
-                               Logger::info('Updated user contact', ['uid' => $row['uid'], 'uri-id' => $row['uri-id'], 'ret' => $ret]);
+                               $ret = DBA::update('user-contact', $update_fields, ['uri-id' => $contact['uri-id'], 'uid' => $contact['uid']]);
+                               Logger::info('Updated user contact', ['uid' => $contact['uid'], 'uri-id' => $contact['uri-id'], 'ret' => $ret]);
                        }
 
                        DBA::close($contacts);
                }
+
                DBA::commit();  
        }
 
index 368b70b228bb26a76dcbbea9c0b1841e09873147..81e5be8d649875be0c76d4810003ba5cc909e72f 100644 (file)
@@ -1000,14 +1000,6 @@ function update_1434()
        return Update::SUCCESS;
 }
 
-function update_1435()
-{
-       $contacts = DBA::select('contact', [], ["`uid` != ?", 0]);
-       while ($contact = DBA::fetch($contacts)) {
-               Contact\User::insertForContactArray($contact);
-       }
-}
-
 function update_1438()
 {
        DBA::update('photo', ['photo-type' => Photo::USER_AVATAR], ['profile' => true]);
@@ -1061,3 +1053,20 @@ function update_1442()
 
        return Update::SUCCESS;
 }
+
+/**
+ * A bug in Contact\User::updateByContactUpdate prevented any update to the user-contact table since the rows have been
+ * created in version 1435. This version fixes this bug but the user-contact rows are outdated, we need to regenerate
+ * them.
+ */
+function update_1444()
+{
+       DBA::e('TRUNCATE TABLE `user-contact`');
+
+       $contacts = DBA::select('contact', [], ["`uid` != ?", 0]);
+       while ($contact = DBA::fetch($contacts)) {
+               Contact\User::insertForContactArray($contact);
+       }
+
+       return Update::SUCCESS;
+}