summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Auth.php22
-rw-r--r--app/Family.php13
-rw-r--r--app/GedcomRecord.php12
-rw-r--r--app/Individual.php12
-rw-r--r--app/Media.php12
-rw-r--r--app/Source.php15
6 files changed, 84 insertions, 2 deletions
diff --git a/app/Auth.php b/app/Auth.php
index 0f51b08cd2..34c5a5d5b8 100644
--- a/app/Auth.php
+++ b/app/Auth.php
@@ -2,7 +2,7 @@
/**
* webtrees: online genealogy
- * Copyright (C) 2019 webtrees development team
+ * Copyright (C) 2020 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -229,6 +229,8 @@ class Auth
}
if ($edit && $family->canEdit()) {
+ $family->lock();
+
return $family;
}
@@ -254,6 +256,8 @@ class Auth
}
if ($edit && $header->canEdit()) {
+ $header->lock();
+
return $header;
}
@@ -280,6 +284,8 @@ class Auth
}
if ($edit && $individual->canEdit()) {
+ $individual->lock();
+
return $individual;
}
@@ -309,6 +315,8 @@ class Auth
}
if ($edit && $media->canEdit()) {
+ $media->lock();
+
return $media;
}
@@ -334,6 +342,8 @@ class Auth
}
if ($edit && $note->canEdit()) {
+ $note->lock();
+
return $note;
}
@@ -359,6 +369,8 @@ class Auth
}
if ($edit && $record->canEdit()) {
+ $record->lock();
+
return $record;
}
@@ -384,6 +396,8 @@ class Auth
}
if ($edit && $repository->canEdit()) {
+ $repository->lock();
+
return $repository;
}
@@ -409,6 +423,8 @@ class Auth
}
if ($edit && $source->canEdit()) {
+ $source->lock();
+
return $source;
}
@@ -434,6 +450,8 @@ class Auth
}
if ($edit && $submitter->canEdit()) {
+ $submitter->lock();
+
return $submitter;
}
@@ -459,6 +477,8 @@ class Auth
}
if ($edit && $submission->canEdit()) {
+ $submission->lock();
+
return $submission;
}
diff --git a/app/Family.php b/app/Family.php
index e73d075e47..6e135f668c 100644
--- a/app/Family.php
+++ b/app/Family.php
@@ -21,6 +21,7 @@ namespace Fisharebest\Webtrees;
use Closure;
use Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage;
+use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Collection;
/**
@@ -460,4 +461,16 @@ class Family extends GedcomRecord
$this->formatFirstMajorFact(Gedcom::MARRIAGE_EVENTS, 1) .
$this->formatFirstMajorFact(Gedcom::DIVORCE_EVENTS, 1);
}
+
+ /**
+ * Lock the database row, to prevent concurrent edits.
+ */
+ public function lock(): void
+ {
+ DB::table('families')
+ ->where('f_file', '=', $this->tree->id())
+ ->where('f_id', '=', $this->xref())
+ ->lockForUpdate()
+ ->get();
+ }
}
diff --git a/app/GedcomRecord.php b/app/GedcomRecord.php
index f299be6042..c883c199b2 100644
--- a/app/GedcomRecord.php
+++ b/app/GedcomRecord.php
@@ -1327,4 +1327,16 @@ class GedcomRecord
// Different types of record have different privacy rules
return $this->canShowByType($access_level);
}
+
+ /**
+ * Lock the database row, to prevent concurrent edits.
+ */
+ public function lock(): void
+ {
+ DB::table('other')
+ ->where('o_file', '=', $this->tree->id())
+ ->where('o_id', '=', $this->xref())
+ ->lockForUpdate()
+ ->get();
+ }
}
diff --git a/app/Individual.php b/app/Individual.php
index b602008579..b5eed42f64 100644
--- a/app/Individual.php
+++ b/app/Individual.php
@@ -1198,4 +1198,16 @@ class Individual extends GedcomRecord
$this->formatFirstMajorFact(Gedcom::BIRTH_EVENTS, 1) .
$this->formatFirstMajorFact(Gedcom::DEATH_EVENTS, 1);
}
+
+ /**
+ * Lock the database row, to prevent concurrent edits.
+ */
+ public function lock(): void
+ {
+ DB::table('individuals')
+ ->where('i_file', '=', $this->tree->id())
+ ->where('i_id', '=', $this->xref())
+ ->lockForUpdate()
+ ->get();
+ }
}
diff --git a/app/Media.php b/app/Media.php
index 4dc0fa8a4f..59174be390 100644
--- a/app/Media.php
+++ b/app/Media.php
@@ -209,4 +209,16 @@ class Media extends GedcomRecord
// No image?
return '';
}
+
+ /**
+ * Lock the database row, to prevent concurrent edits.
+ */
+ public function lock(): void
+ {
+ DB::table('media')
+ ->where('m_file', '=', $this->tree->id())
+ ->where('m_id', '=', $this->xref())
+ ->lockForUpdate()
+ ->get();
+ }
}
diff --git a/app/Source.php b/app/Source.php
index 8744569d31..a045c44062 100644
--- a/app/Source.php
+++ b/app/Source.php
@@ -2,7 +2,7 @@
/**
* webtrees: online genealogy
- * Copyright (C) 2019 webtrees development team
+ * Copyright (C) 2020 webtrees development team
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
@@ -21,6 +21,7 @@ namespace Fisharebest\Webtrees;
use Closure;
use Fisharebest\Webtrees\Http\RequestHandlers\SourcePage;
+use Illuminate\Database\Capsule\Manager as DB;
/**
* A GEDCOM source (SOUR) object.
@@ -106,4 +107,16 @@ class Source extends GedcomRecord
{
$this->extractNamesFromFacts(1, 'TITL', $this->facts(['TITL']));
}
+
+ /**
+ * Lock the database row, to prevent concurrent edits.
+ */
+ public function lock(): void
+ {
+ DB::table('sources')
+ ->where('s_file', '=', $this->tree->id())
+ ->where('s_id', '=', $this->xref())
+ ->lockForUpdate()
+ ->get();
+ }
}