X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPost%2FUser.php;h=7bd570699731ab1bea3267a46dfe5194bdbe306c;hb=6abb4d40d6456f58a748077f161f5101b4048659;hp=6a6837c63bb54a09112585665d0096804a4e5882;hpb=befc2af5043a3afde251721c0d27df695db1bb7e;p=friendica.git diff --git a/src/Model/Post/User.php b/src/Model/Post/User.php index 6a6837c63b..7bd5706997 100644 --- a/src/Model/Post/User.php +++ b/src/Model/Post/User.php @@ -1,6 +1,6 @@ $uri_id, 'uid' => $uid])) { - return false; - } - - $fields = DBStructure::getFieldsForTable('post-user', $data); + $fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data); // Additionally assign the key fields $fields['uri-id'] = $uri_id; @@ -58,6 +54,33 @@ class User $fields['unseen'] = false; } + // Does the entry already exist? + if (DBA::exists('post-user', ['uri-id' => $uri_id, 'uid' => $uid])) { + $postuser = DBA::selectFirst('post-user', [], ['uri-id' => $uri_id, 'uid' => $uid]); + + // We quit here, when there are obvious differences + foreach (['created', 'owner-id', 'author-id', 'vid', 'network', 'private', 'wall', 'origin'] as $key) { + if ($fields[$key] != $postuser[$key]) { + return 0; + } + } + + $update = []; + foreach (['gravity', 'parent-uri-id', 'thr-parent-id'] as $key) { + if ($fields[$key] != $postuser[$key]) { + $update[$key] = $fields[$key]; + } + } + + // When the parents changed, we apply these changes to the existing entry + if (!empty($update)) { + DBA::update('post-user', $update, ['id' => $postuser['id']]); + return $postuser['id']; + } else { + return 0; + } + } + if (!DBA::insert('post-user', $fields, Database::INSERT_IGNORE)) { return 0; } @@ -81,7 +104,7 @@ class User throw new BadMethodCallException('Empty URI_id'); } - $fields = DBStructure::getFieldsForTable('post-user', $data); + $fields = DI::dbaDefinition()->truncateFieldsForTable('post-user', $data); // Remove the key fields unset($fields['uri-id']);