summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2025-06-03 14:26:09 +0100
committerGreg Roach <greg@subaqua.co.uk>2025-06-03 14:36:43 +0100
commit85077687541941260bc4696c678259aa583d91ba (patch)
tree10bd0eb57573600224215eed834542b9a674f943
parentac2380f4b6c5d3d3b64e96340e062e496a22d826 (diff)
downloadwebtrees-85077687541941260bc4696c678259aa583d91ba.tar.gz
webtrees-85077687541941260bc4696c678259aa583d91ba.tar.bz2
webtrees-85077687541941260bc4696c678259aa583d91ba.zip
Fix: #5099 - wrong binding order in querybuilder
-rw-r--r--app/Services/AdminService.php17
-rw-r--r--phpstan-baseline.neon6
2 files changed, 10 insertions, 13 deletions
diff --git a/app/Services/AdminService.php b/app/Services/AdminService.php
index bd49e017a4..d7157e7b0e 100644
--- a/app/Services/AdminService.php
+++ b/app/Services/AdminService.php
@@ -62,9 +62,12 @@ class AdminService
*/
public function countCommonXrefs(Tree $tree1, Tree $tree2): int
{
- $subquery1 = DB::table('individuals')
- ->where('i_file', '=', $tree1->id())
- ->select(['i_id AS xref'])
+ $subquery1 = DB::table('change')
+ ->where('gedcom_id', '=', $tree1->id())
+ ->select(['xref AS xref1'])
+ ->union(DB::table('individuals')
+ ->where('i_file', '=', $tree1->id())
+ ->select(['i_id AS xref']))
->union(DB::table('families')
->where('f_file', '=', $tree1->id())
->select(['f_id AS xref']))
@@ -81,7 +84,7 @@ class AdminService
$subquery2 = DB::table('change')
->where('gedcom_id', '=', $tree2->id())
- ->select(['xref AS other_xref'])
+ ->select(['xref AS xref2'])
->union(DB::table('individuals')
->where('i_file', '=', $tree2->id())
->select(['i_id AS xref']))
@@ -99,9 +102,9 @@ class AdminService
->whereNotIn('o_type', [Header::RECORD_TYPE, 'TRLR'])
->select(['o_id AS xref']));
- return DB::table(new Expression('(' . $subquery1->toSql() . ') AS sub1'))
- ->mergeBindings($subquery1)
- ->joinSub($subquery2, 'sub2', 'other_xref', '=', 'xref')
+ return DB::query()
+ ->fromSub($subquery1, 'sub1')
+ ->joinSub($subquery2, 'sub2', 'xref1', '=', 'xref2')
->count();
}
diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon
index f4d8feda78..96f5f442f2 100644
--- a/phpstan-baseline.neon
+++ b/phpstan-baseline.neon
@@ -6157,12 +6157,6 @@ parameters:
path: app/Services/AdminService.php
-
- message: '#^Parameter \#1 \$table of static method Illuminate\\Database\\Capsule\\Manager\:\:table\(\) expects Closure\|Illuminate\\Database\\Query\\Builder\|string, Illuminate\\Database\\Query\\Expression\<non\-falsy\-string\> given\.$#'
- identifier: argument.type
- count: 1
- path: app/Services/AdminService.php
-
- -
message: '#^Parameter \#2 \$subject of function preg_match expects string, string\|false given\.$#'
identifier: argument.type
count: 1