]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Fix expected implementation of JsonLD::fetchElementArray
[friendica.git] / src / Model / Contact.php
index 428bc3684e024a6d73dadaa5fed4bf13e8f76caf..67b9c903831f04abb46f2fbb71add565aefd85d8 100644 (file)
@@ -91,6 +91,8 @@ class Contact
         * @}
         */
 
+       const LOCK_INSERT = 'contact-insert';
+
        /**
         * Account types
         *
@@ -752,7 +754,6 @@ class Contact
                        $item['title'] = '';
                        $item['guid'] = '';
                        $item['uri-id'] = 0;
-                       $item['attach'] = '';
                        $slap = OStatus::salmon($item, $user);
 
                        if (!empty($contact['notify'])) {
@@ -1125,19 +1126,23 @@ class Contact
                        $condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
 
                        // Before inserting we do check if the entry does exist now.
-                       DBA::lock('contact');
-                       $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
-                       if (DBA::isResult($contact)) {
-                               $contact_id = $contact['id'];
-                               Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
-                       } else {
-                               DBA::insert('contact', $fields);
-                               $contact_id = DBA::lastInsertId();
-                               if ($contact_id) {
-                                       Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+                       if (DI::lock()->acquire(self::LOCK_INSERT, 0)) {
+                               $contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
+                               if (DBA::isResult($contact)) {
+                                       $contact_id = $contact['id'];
+                                       Logger::notice('Contact had been created (shortly) before', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+                               } else {
+                                       DBA::insert('contact', $fields);
+                                       $contact_id = DBA::lastInsertId();
+                                       if ($contact_id) {
+                                               Logger::info('Contact inserted', ['id' => $contact_id, 'url' => $url, 'uid' => $uid]);
+                                       }
                                }
+                               DI::lock()->release(self::LOCK_INSERT);
+                       } else {
+                               Logger::warning('Contact lock had not been acquired');
                        }
-                       DBA::unlock();
+
                        if (!$contact_id) {
                                Logger::info('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
                                return 0;
@@ -2227,7 +2232,6 @@ class Contact
                                $item['title'] = '';
                                $item['guid'] = '';
                                $item['uri-id'] = 0;
-                               $item['attach'] = '';
 
                                $slap = OStatus::salmon($item, $owner);