From a0cb6b409dae4e832a1278f8b93bc8fbbf34448e Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 6 Sep 2020 09:39:47 +0000 Subject: [PATCH] Avoid "Duplicate entry" error in apcontact --- src/Model/APContact.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 634ce441a2..d31aa5d372 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -320,13 +320,18 @@ class APContact $apcontact['updated'] = DateTimeFormat::utcNow(); - DBA::update('apcontact', $apcontact, ['url' => $url], true); - // We delete the old entry when the URL is changed - if (($url != $apcontact['url']) && DBA::exists('apcontact', ['url' => $url]) && DBA::exists('apcontact', ['url' => $apcontact['url']])) { + if ($url != $apcontact['url']) { + Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]); DBA::delete('apcontact', ['url' => $url]); } + if (DBA::exists('apcontact', ['url' => $apcontact['url']])) { + DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]); + } else { + DBA::replace('apcontact', $apcontact); + } + Logger::info('Updated profile', ['url' => $url]); return $apcontact;