forked from fisharebest/webtrees
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_trees_duplicates.php
184 lines (158 loc) · 5.3 KB
/
admin_trees_duplicates.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* webtrees: online genealogy
* Copyright (C) 2015 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
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Fisharebest\Webtrees;
/**
* Defined in session.php
*
* @global Tree $WT_TREE
*/
global $WT_TREE;
use Fisharebest\Webtrees\Controller\PageController;
define('WT_SCRIPT_NAME', 'admin_trees_duplicates.php');
require './includes/session.php';
$controller = new PageController;
$controller
->restrictAccess(Auth::isManager($WT_TREE))
->setPageTitle(I18N::translate('Find duplicates') . ' — ' . $WT_TREE->getTitleHtml())
->pageHeader();
$repositories = Database::prepare(
"SELECT GROUP_CONCAT(n_id) AS xrefs " .
" FROM `##other`" .
" JOIN `##name` ON o_id = n_id AND o_file = n_file" .
" WHERE o_file = :tree_id AND o_type = 'REPO'" .
" GROUP BY n_full" .
" HAVING COUNT(n_id) > 1"
)->execute(array(
'tree_id' => $WT_TREE->getTreeId(),
))->fetchAll();
$repositories = array_map(
function (\stdClass $x) use ($WT_TREE) {
$tmp = explode(',', $x->xrefs);
return array_map(function ($y) use ($WT_TREE) {
return Repository::getInstance($y, $WT_TREE);
}, $tmp);
}, $repositories
);
$sources = Database::prepare(
"SELECT GROUP_CONCAT(n_id) AS xrefs " .
" FROM `##sources`" .
" JOIN `##name` ON s_id = n_id AND s_file = n_file" .
" WHERE s_file = :tree_id" .
" GROUP BY n_full" .
" HAVING COUNT(n_id) > 1"
)->execute(array(
'tree_id' => $WT_TREE->getTreeId(),
))->fetchAll();
$sources = array_map(
function (\stdClass $x) use ($WT_TREE) {
$tmp = explode(',', $x->xrefs);
return array_map(function ($y) use ($WT_TREE) {
return Source::getInstance($y, $WT_TREE);
}, $tmp);
}, $sources
);
$individuals = Database::prepare(
"SELECT DISTINCT GROUP_CONCAT(d_gid ORDER BY d_gid) AS xrefs" .
" FROM `##dates` AS d" .
" JOIN `##name` ON d_file = n_file AND d_gid = n_id" .
" WHERE d_file = :tree_id AND d_fact IN ('BIRT', 'CHR', 'BAPM', 'DEAT', 'BURI')" .
" GROUP BY d_day, d_month, d_year, d_type, d_fact, n_type, n_full" .
" HAVING COUNT(DISTINCT d_gid) > 1"
)->execute(array(
'tree_id' => $WT_TREE->getTreeId(),
))->fetchAll();
$individuals = array_map(
function (\stdClass $x) use ($WT_TREE) {
$tmp = explode(',', $x->xrefs);
return array_map(function ($y) use ($WT_TREE) {
return Individual::getInstance($y, $WT_TREE);
}, $tmp);
}, $individuals
);
$families = Database::prepare(
"SELECT GROUP_CONCAT(f_id) AS xrefs " .
" FROM `##families`" .
" WHERE f_file = :tree_id" .
" GROUP BY LEAST(f_husb, f_wife), GREATEST(f_husb, f_wife)" .
" HAVING COUNT(f_id) > 1"
)->execute(array(
'tree_id' => $WT_TREE->getTreeId(),
))->fetchAll();
$families = array_map(
function (\stdClass $x) use ($WT_TREE) {
$tmp = explode(',', $x->xrefs);
return array_map(function ($y) use ($WT_TREE) {
return Family::getInstance($y, $WT_TREE);
}, $tmp);
}, $families
);
$media = Database::prepare(
"SELECT GROUP_CONCAT(m_id) AS xrefs " .
" FROM `##media`" .
" WHERE m_file = :tree_id" .
" GROUP BY m_titl" .
" HAVING COUNT(m_id) > 1"
)->execute(array(
'tree_id' => $WT_TREE->getTreeId(),
))->fetchAll();
$media = array_map(
function (\stdClass $x) use ($WT_TREE) {
$tmp = explode(',', $x->xrefs);
return array_map(function ($y) use ($WT_TREE) {
return Media::getInstance($y, $WT_TREE);
}, $tmp);
}, $media
);
$all_duplicates = array(
I18N::translate('Repositories') => $repositories,
I18N::translate('Sources') => $sources,
I18N::translate('Individuals') => $individuals,
I18N::translate('Families') => $families,
I18N::translate('Media objects') => $media,
);
?>
<ol class="breadcrumb small">
<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
<li><a href="admin_trees_manage.php"><?php echo I18N::translate('Manage family trees'); ?></a></li>
<li class="active"><?php echo $controller->getPageTitle(); ?></li>
</ol>
<h1><?php echo $controller->getPageTitle(); ?></h1>
<?php foreach ($all_duplicates as $title => $duplicate_list): ?>
<h2><?php echo $title; ?></h2>
<?php if ($duplicate_list): ?>
<ul>
<?php foreach ($duplicate_list as $duplicates): ?>
<li>
<?php echo $duplicates[0]->getFullName(); ?>
<?php foreach ($duplicates as $record): ?>
—
<a href="<?php echo $record->getHtmlUrl(); ?>">
<?php echo $record->getXref(); ?>
</a>
<?php endforeach; ?>
<?php if (count($duplicates) === 2): ?>
—
<a href="admin_site_merge.php?ged=<?php echo $WT_TREE->getNameHtml(); ?>&gid1=<?php echo $duplicates[0]->getXref(); ?>&gid2=<?php echo $duplicates[1]->getXref(); ?>&url=admin_trees_duplicates.php">
<?php echo I18N::translate('Merge'); ?>
</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p><?php echo I18N::translate('No duplicates have been found.'); ?></p>
<?php endif; ?>
<?php endforeach; ?>