* @}
*/
+ const LOCK_INSERT = 'contact-insert';
+
/**
* Account types
*
$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;
const PT_FETCHED = 75;
const PT_PERSONAL_NOTE = 128;
- const LOCK_ITEM = 'item-insert';
+ const LOCK_INSERT = 'item-insert';
// Field list that is used to display the items
const DISPLAY_FIELDLIST = [
}
}
- if (DI::lock()->acquire(self::LOCK_ITEM, 0)) {
+ if (DI::lock()->acquire(self::LOCK_INSERT, 0)) {
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
if (DBA::exists('item', $condition)) {
- DI::lock()->release(self::LOCK_ITEM);
+ DI::lock()->release(self::LOCK_INSERT);
Logger::notice('Item is already inserted - aborting', $condition);
return 0;
}
// When the item was successfully stored we fetch the ID of the item.
$current_post = DBA::lastInsertId();
- DI::lock()->release(self::LOCK_ITEM);
+ DI::lock()->release(self::LOCK_INSERT);
} else {
+ Logger::warning('Item lock had not been acquired');
$result = false;
$current_post = 0;
}