@@ -30,9 +30,9 @@ discard block |
||
30 | 30 | |
31 | 31 | $controller = new PageController; |
32 | 32 | $controller |
33 | - ->restrictAccess(Auth::isManager($WT_TREE)) |
|
34 | - ->setPageTitle(I18N::translate('Merge family trees')) |
|
35 | - ->pageHeader(); |
|
33 | + ->restrictAccess(Auth::isManager($WT_TREE)) |
|
34 | + ->setPageTitle(I18N::translate('Merge family trees')) |
|
35 | + ->pageHeader(); |
|
36 | 36 | |
37 | 37 | ?> |
38 | 38 | <ol class="breadcrumb small"> |
@@ -49,159 +49,159 @@ discard block |
||
49 | 49 | $tree2_id = Filter::post('tree2_id'); |
50 | 50 | |
51 | 51 | if ($tree1_id && $tree2_id != $tree1_id) { |
52 | - // Every XREF used by both trees |
|
53 | - $xrefs = Database::prepare( |
|
54 | - "SELECT xref, type FROM (" . |
|
55 | - " SELECT i_id AS xref, 'INDI' AS type FROM `##individuals` WHERE i_file = ?" . |
|
56 | - " UNION " . |
|
57 | - " SELECT f_id AS xref, 'FAM' AS type FROM `##families` WHERE f_file = ?" . |
|
58 | - " UNION " . |
|
59 | - " SELECT s_id AS xref, 'SOUR' AS type FROM `##sources` WHERE s_file = ?" . |
|
60 | - " UNION " . |
|
61 | - " SELECT m_id AS xref, 'OBJE' AS type FROM `##media` WHERE m_file = ?" . |
|
62 | - " UNION " . |
|
63 | - " SELECT o_id AS xref, o_type AS type FROM `##other` WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" . |
|
64 | - ") AS this_tree JOIN (" . |
|
65 | - " SELECT xref FROM `##change` WHERE gedcom_id = ?" . |
|
66 | - " UNION " . |
|
67 | - " SELECT i_id AS xref FROM `##individuals` WHERE i_file = ?" . |
|
68 | - " UNION " . |
|
69 | - " SELECT f_id AS xref FROM `##families` WHERE f_file = ?" . |
|
70 | - " UNION " . |
|
71 | - " SELECT s_id AS xref FROM `##sources` WHERE s_file = ?" . |
|
72 | - " UNION " . |
|
73 | - " SELECT m_id AS xref FROM `##media` WHERE m_file = ?" . |
|
74 | - " UNION " . |
|
75 | - " SELECT o_id AS xref FROM `##other` WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" . |
|
76 | - ") AS other_trees USING (xref)" |
|
77 | - )->execute(array( |
|
78 | - $tree1_id, $tree1_id, $tree1_id, $tree1_id, $tree1_id, |
|
79 | - $tree2_id, $tree2_id, $tree2_id, $tree2_id, $tree2_id, $tree2_id, |
|
80 | - ))->fetchAssoc(); |
|
52 | + // Every XREF used by both trees |
|
53 | + $xrefs = Database::prepare( |
|
54 | + "SELECT xref, type FROM (" . |
|
55 | + " SELECT i_id AS xref, 'INDI' AS type FROM `##individuals` WHERE i_file = ?" . |
|
56 | + " UNION " . |
|
57 | + " SELECT f_id AS xref, 'FAM' AS type FROM `##families` WHERE f_file = ?" . |
|
58 | + " UNION " . |
|
59 | + " SELECT s_id AS xref, 'SOUR' AS type FROM `##sources` WHERE s_file = ?" . |
|
60 | + " UNION " . |
|
61 | + " SELECT m_id AS xref, 'OBJE' AS type FROM `##media` WHERE m_file = ?" . |
|
62 | + " UNION " . |
|
63 | + " SELECT o_id AS xref, o_type AS type FROM `##other` WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" . |
|
64 | + ") AS this_tree JOIN (" . |
|
65 | + " SELECT xref FROM `##change` WHERE gedcom_id = ?" . |
|
66 | + " UNION " . |
|
67 | + " SELECT i_id AS xref FROM `##individuals` WHERE i_file = ?" . |
|
68 | + " UNION " . |
|
69 | + " SELECT f_id AS xref FROM `##families` WHERE f_file = ?" . |
|
70 | + " UNION " . |
|
71 | + " SELECT s_id AS xref FROM `##sources` WHERE s_file = ?" . |
|
72 | + " UNION " . |
|
73 | + " SELECT m_id AS xref FROM `##media` WHERE m_file = ?" . |
|
74 | + " UNION " . |
|
75 | + " SELECT o_id AS xref FROM `##other` WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" . |
|
76 | + ") AS other_trees USING (xref)" |
|
77 | + )->execute(array( |
|
78 | + $tree1_id, $tree1_id, $tree1_id, $tree1_id, $tree1_id, |
|
79 | + $tree2_id, $tree2_id, $tree2_id, $tree2_id, $tree2_id, $tree2_id, |
|
80 | + ))->fetchAssoc(); |
|
81 | 81 | |
82 | - if ($xrefs) { |
|
83 | - $tree1 = Tree::findById($tree1_id); |
|
84 | - $tree2 = Tree::findById($tree2_id); |
|
85 | - echo |
|
86 | - '<p>', I18N::translate('In a family tree, each record has an internal reference number (called an “XREF”) such as “F123” or “R14”.'), '</p>', |
|
87 | - '<p>', |
|
88 | - I18N::plural( |
|
89 | - /* I18N: An XREF is the identification number used in GEDCOM files. */ |
|
90 | - 'The two family trees have %1$s record which uses the same “XREF”.', |
|
91 | - 'The two family trees have %1$s records which use the same “XREF”.', |
|
92 | - count($xrefs), count($xrefs) |
|
93 | - ), |
|
94 | - '</p>', |
|
95 | - '<p>', |
|
96 | - I18N::translate('You must renumber the records in one of the trees before you can merge them.'), |
|
97 | - '</p>', |
|
98 | - '<p>', |
|
99 | - '<a class="current" href="admin_trees_renumber.php?ged=', $tree1->getNameUrl(), '">', |
|
100 | - I18N::translate('Renumber family tree'), ' — ', $tree1->getTitleHtml(), |
|
101 | - '</a>', |
|
102 | - '</p>', |
|
103 | - '<p>', |
|
104 | - '<a class="current" href="admin_trees_renumber.php?ged=', $tree2->getNameUrl(), '">', |
|
105 | - I18N::translate('Renumber family tree'), ' — ', $tree2->getTitleHtml(), |
|
106 | - '</a>', |
|
107 | - '</p>'; |
|
108 | - } else { |
|
109 | - Database::beginTransaction(); |
|
110 | - Database::exec( |
|
111 | - "LOCK TABLE" . |
|
112 | - " `##individuals` WRITE," . |
|
113 | - " `##individuals` AS individuals2 READ," . |
|
114 | - " `##families` WRITE," . |
|
115 | - " `##families` AS families2 READ," . |
|
116 | - " `##sources` WRITE," . |
|
117 | - " `##sources` AS sources2 READ," . |
|
118 | - " `##media` WRITE," . |
|
119 | - " `##media` AS media2 READ," . |
|
120 | - " `##other` WRITE," . |
|
121 | - " `##other` AS other2 READ," . |
|
122 | - " `##name` WRITE," . |
|
123 | - " `##name` AS name2 READ," . |
|
124 | - " `##placelinks` WRITE," . |
|
125 | - " `##placelinks` AS placelinks2 READ," . |
|
126 | - " `##change` WRITE," . |
|
127 | - " `##change` AS change2 READ," . |
|
128 | - " `##dates` WRITE," . |
|
129 | - " `##dates` AS dates2 READ," . |
|
130 | - " `##default_resn` WRITE," . |
|
131 | - " `##default_resn` AS default_resn2 READ," . |
|
132 | - " `##hit_counter` WRITE," . |
|
133 | - " `##hit_counter` AS hit_counter2 READ," . |
|
134 | - " `##link` WRITE," . |
|
135 | - " `##link` AS link2 READ" |
|
136 | - ); |
|
137 | - Database::prepare( |
|
138 | - "INSERT INTO `##individuals` (i_id, i_file, i_rin, i_sex, i_gedcom)" . |
|
139 | - " SELECT i_id, ?, i_rin, i_sex, i_gedcom FROM `##individuals` AS individuals2 WHERE i_file = ?" |
|
140 | - )->execute(array($tree2_id, $tree1_id)); |
|
141 | - Database::prepare( |
|
142 | - "INSERT INTO `##families` (f_id, f_file, f_husb, f_wife, f_gedcom, f_numchil)" . |
|
143 | - " SELECT f_id, ?, f_husb, f_wife, f_gedcom, f_numchil FROM `##families` AS families2 WHERE f_file = ?" |
|
144 | - )->execute(array($tree2_id, $tree1_id)); |
|
145 | - Database::prepare( |
|
146 | - "INSERT INTO `##sources` (s_id, s_file, s_name, s_gedcom)" . |
|
147 | - " SELECT s_id, ?, s_name, s_gedcom FROM `##sources` AS sources2 WHERE s_file = ?" |
|
148 | - )->execute(array($tree2_id, $tree1_id)); |
|
149 | - Database::prepare( |
|
150 | - "INSERT INTO `##media` (m_id, m_ext, m_type, m_titl, m_filename, m_file, m_gedcom)" . |
|
151 | - " SELECT m_id, m_ext, m_type, m_titl, m_filename, ?, m_gedcom FROM `##media` AS media2 WHERE m_file = ?" |
|
152 | - )->execute(array($tree2_id, $tree1_id)); |
|
153 | - Database::prepare( |
|
154 | - "INSERT INTO `##other` (o_id, o_file, o_type, o_gedcom)" . |
|
155 | - " SELECT o_id, ?, o_type, o_gedcom FROM `##other` AS other2 WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" |
|
156 | - )->execute(array($tree2_id, $tree1_id)); |
|
82 | + if ($xrefs) { |
|
83 | + $tree1 = Tree::findById($tree1_id); |
|
84 | + $tree2 = Tree::findById($tree2_id); |
|
85 | + echo |
|
86 | + '<p>', I18N::translate('In a family tree, each record has an internal reference number (called an “XREF”) such as “F123” or “R14”.'), '</p>', |
|
87 | + '<p>', |
|
88 | + I18N::plural( |
|
89 | + /* I18N: An XREF is the identification number used in GEDCOM files. */ |
|
90 | + 'The two family trees have %1$s record which uses the same “XREF”.', |
|
91 | + 'The two family trees have %1$s records which use the same “XREF”.', |
|
92 | + count($xrefs), count($xrefs) |
|
93 | + ), |
|
94 | + '</p>', |
|
95 | + '<p>', |
|
96 | + I18N::translate('You must renumber the records in one of the trees before you can merge them.'), |
|
97 | + '</p>', |
|
98 | + '<p>', |
|
99 | + '<a class="current" href="admin_trees_renumber.php?ged=', $tree1->getNameUrl(), '">', |
|
100 | + I18N::translate('Renumber family tree'), ' — ', $tree1->getTitleHtml(), |
|
101 | + '</a>', |
|
102 | + '</p>', |
|
103 | + '<p>', |
|
104 | + '<a class="current" href="admin_trees_renumber.php?ged=', $tree2->getNameUrl(), '">', |
|
105 | + I18N::translate('Renumber family tree'), ' — ', $tree2->getTitleHtml(), |
|
106 | + '</a>', |
|
107 | + '</p>'; |
|
108 | + } else { |
|
109 | + Database::beginTransaction(); |
|
110 | + Database::exec( |
|
111 | + "LOCK TABLE" . |
|
112 | + " `##individuals` WRITE," . |
|
113 | + " `##individuals` AS individuals2 READ," . |
|
114 | + " `##families` WRITE," . |
|
115 | + " `##families` AS families2 READ," . |
|
116 | + " `##sources` WRITE," . |
|
117 | + " `##sources` AS sources2 READ," . |
|
118 | + " `##media` WRITE," . |
|
119 | + " `##media` AS media2 READ," . |
|
120 | + " `##other` WRITE," . |
|
121 | + " `##other` AS other2 READ," . |
|
122 | + " `##name` WRITE," . |
|
123 | + " `##name` AS name2 READ," . |
|
124 | + " `##placelinks` WRITE," . |
|
125 | + " `##placelinks` AS placelinks2 READ," . |
|
126 | + " `##change` WRITE," . |
|
127 | + " `##change` AS change2 READ," . |
|
128 | + " `##dates` WRITE," . |
|
129 | + " `##dates` AS dates2 READ," . |
|
130 | + " `##default_resn` WRITE," . |
|
131 | + " `##default_resn` AS default_resn2 READ," . |
|
132 | + " `##hit_counter` WRITE," . |
|
133 | + " `##hit_counter` AS hit_counter2 READ," . |
|
134 | + " `##link` WRITE," . |
|
135 | + " `##link` AS link2 READ" |
|
136 | + ); |
|
137 | + Database::prepare( |
|
138 | + "INSERT INTO `##individuals` (i_id, i_file, i_rin, i_sex, i_gedcom)" . |
|
139 | + " SELECT i_id, ?, i_rin, i_sex, i_gedcom FROM `##individuals` AS individuals2 WHERE i_file = ?" |
|
140 | + )->execute(array($tree2_id, $tree1_id)); |
|
141 | + Database::prepare( |
|
142 | + "INSERT INTO `##families` (f_id, f_file, f_husb, f_wife, f_gedcom, f_numchil)" . |
|
143 | + " SELECT f_id, ?, f_husb, f_wife, f_gedcom, f_numchil FROM `##families` AS families2 WHERE f_file = ?" |
|
144 | + )->execute(array($tree2_id, $tree1_id)); |
|
145 | + Database::prepare( |
|
146 | + "INSERT INTO `##sources` (s_id, s_file, s_name, s_gedcom)" . |
|
147 | + " SELECT s_id, ?, s_name, s_gedcom FROM `##sources` AS sources2 WHERE s_file = ?" |
|
148 | + )->execute(array($tree2_id, $tree1_id)); |
|
149 | + Database::prepare( |
|
150 | + "INSERT INTO `##media` (m_id, m_ext, m_type, m_titl, m_filename, m_file, m_gedcom)" . |
|
151 | + " SELECT m_id, m_ext, m_type, m_titl, m_filename, ?, m_gedcom FROM `##media` AS media2 WHERE m_file = ?" |
|
152 | + )->execute(array($tree2_id, $tree1_id)); |
|
153 | + Database::prepare( |
|
154 | + "INSERT INTO `##other` (o_id, o_file, o_type, o_gedcom)" . |
|
155 | + " SELECT o_id, ?, o_type, o_gedcom FROM `##other` AS other2 WHERE o_file = ? AND o_type NOT IN ('HEAD', 'TRLR')" |
|
156 | + )->execute(array($tree2_id, $tree1_id)); |
|
157 | 157 | // Old versions of webtrees (pre 1.4?) created entries for HEAD and TRLR. |
158 | 158 | // Ignore these, as they will break unique indexes |
159 | - Database::prepare( |
|
160 | - "INSERT INTO `##name` (n_file, n_id, n_num, n_type, n_sort, n_full, n_surname, n_surn, n_givn, n_soundex_givn_std, n_soundex_surn_std, n_soundex_givn_dm, n_soundex_surn_dm)" . |
|
161 | - " SELECT ?, n_id, n_num, n_type, n_sort, n_full, n_surname, n_surn, n_givn, n_soundex_givn_std, n_soundex_surn_std, n_soundex_givn_dm, n_soundex_surn_dm FROM `##name` AS name2 WHERE n_file = ? AND n_type NOT IN ('HEAD', 'TRLR')" |
|
162 | - )->execute(array($tree2_id, $tree1_id)); |
|
163 | - Database::prepare( |
|
164 | - "INSERT INTO `##placelinks` (pl_p_id, pl_gid, pl_file)" . |
|
165 | - " SELECT pl_p_id, pl_gid, ? FROM `##placelinks` AS placelinks2 WHERE pl_file = ?" |
|
166 | - )->execute(array($tree2_id, $tree1_id)); |
|
167 | - Database::prepare( |
|
168 | - "INSERT INTO `##dates` (d_day, d_month, d_mon, d_year, d_julianday1, d_julianday2, d_fact, d_gid, d_file, d_type)" . |
|
169 | - " SELECT d_day, d_month, d_mon, d_year, d_julianday1, d_julianday2, d_fact, d_gid, ?, d_type FROM `##dates` AS dates2 WHERE d_file = ?" |
|
170 | - )->execute(array($tree2_id, $tree1_id)); |
|
171 | - Database::prepare( |
|
172 | - "INSERT INTO `##default_resn` (gedcom_id, xref, tag_type, resn)" . |
|
173 | - " SELECT ?, xref, tag_type, resn FROM `##default_resn` AS default_resn2 WHERE gedcom_id = ?" |
|
174 | - )->execute(array($tree2_id, $tree1_id)); |
|
175 | - Database::prepare( |
|
176 | - "INSERT INTO `##link` (l_file, l_from, l_type, l_to)" . |
|
177 | - " SELECT ?, l_from, l_type, l_to FROM `##link` AS link2 WHERE l_file = ?" |
|
178 | - )->execute(array($tree2_id, $tree1_id)); |
|
179 | - // This table may contain old (deleted) references, which could clash. IGNORE these. |
|
180 | - Database::prepare( |
|
181 | - "INSERT IGNORE INTO `##change` (change_time, status, gedcom_id, xref, old_gedcom, new_gedcom, user_id)" . |
|
182 | - " SELECT change_time, status, ?, xref, old_gedcom, new_gedcom, user_id FROM `##change` AS change2 WHERE gedcom_id = ?" |
|
183 | - )->execute(array($tree2_id, $tree1_id)); |
|
184 | - // This table may contain old (deleted) references, which could clash. IGNORE these. |
|
185 | - Database::prepare( |
|
186 | - "INSERT IGNORE INTO `##hit_counter` (gedcom_id, page_name, page_parameter, page_count)" . |
|
187 | - " SELECT ?, page_name, page_parameter, page_count FROM `##hit_counter` AS hit_counter2 WHERE gedcom_id = ? AND page_name <> 'index.php'" |
|
188 | - )->execute(array($tree2_id, $tree1_id)); |
|
189 | - Database::exec("UNLOCK TABLES"); |
|
190 | - Database::commit(); |
|
191 | - echo '<p>', I18N::translate('The family trees have been merged successfully.'), '</p>'; |
|
192 | - } |
|
159 | + Database::prepare( |
|
160 | + "INSERT INTO `##name` (n_file, n_id, n_num, n_type, n_sort, n_full, n_surname, n_surn, n_givn, n_soundex_givn_std, n_soundex_surn_std, n_soundex_givn_dm, n_soundex_surn_dm)" . |
|
161 | + " SELECT ?, n_id, n_num, n_type, n_sort, n_full, n_surname, n_surn, n_givn, n_soundex_givn_std, n_soundex_surn_std, n_soundex_givn_dm, n_soundex_surn_dm FROM `##name` AS name2 WHERE n_file = ? AND n_type NOT IN ('HEAD', 'TRLR')" |
|
162 | + )->execute(array($tree2_id, $tree1_id)); |
|
163 | + Database::prepare( |
|
164 | + "INSERT INTO `##placelinks` (pl_p_id, pl_gid, pl_file)" . |
|
165 | + " SELECT pl_p_id, pl_gid, ? FROM `##placelinks` AS placelinks2 WHERE pl_file = ?" |
|
166 | + )->execute(array($tree2_id, $tree1_id)); |
|
167 | + Database::prepare( |
|
168 | + "INSERT INTO `##dates` (d_day, d_month, d_mon, d_year, d_julianday1, d_julianday2, d_fact, d_gid, d_file, d_type)" . |
|
169 | + " SELECT d_day, d_month, d_mon, d_year, d_julianday1, d_julianday2, d_fact, d_gid, ?, d_type FROM `##dates` AS dates2 WHERE d_file = ?" |
|
170 | + )->execute(array($tree2_id, $tree1_id)); |
|
171 | + Database::prepare( |
|
172 | + "INSERT INTO `##default_resn` (gedcom_id, xref, tag_type, resn)" . |
|
173 | + " SELECT ?, xref, tag_type, resn FROM `##default_resn` AS default_resn2 WHERE gedcom_id = ?" |
|
174 | + )->execute(array($tree2_id, $tree1_id)); |
|
175 | + Database::prepare( |
|
176 | + "INSERT INTO `##link` (l_file, l_from, l_type, l_to)" . |
|
177 | + " SELECT ?, l_from, l_type, l_to FROM `##link` AS link2 WHERE l_file = ?" |
|
178 | + )->execute(array($tree2_id, $tree1_id)); |
|
179 | + // This table may contain old (deleted) references, which could clash. IGNORE these. |
|
180 | + Database::prepare( |
|
181 | + "INSERT IGNORE INTO `##change` (change_time, status, gedcom_id, xref, old_gedcom, new_gedcom, user_id)" . |
|
182 | + " SELECT change_time, status, ?, xref, old_gedcom, new_gedcom, user_id FROM `##change` AS change2 WHERE gedcom_id = ?" |
|
183 | + )->execute(array($tree2_id, $tree1_id)); |
|
184 | + // This table may contain old (deleted) references, which could clash. IGNORE these. |
|
185 | + Database::prepare( |
|
186 | + "INSERT IGNORE INTO `##hit_counter` (gedcom_id, page_name, page_parameter, page_count)" . |
|
187 | + " SELECT ?, page_name, page_parameter, page_count FROM `##hit_counter` AS hit_counter2 WHERE gedcom_id = ? AND page_name <> 'index.php'" |
|
188 | + )->execute(array($tree2_id, $tree1_id)); |
|
189 | + Database::exec("UNLOCK TABLES"); |
|
190 | + Database::commit(); |
|
191 | + echo '<p>', I18N::translate('The family trees have been merged successfully.'), '</p>'; |
|
192 | + } |
|
193 | 193 | } else { |
194 | - echo '<form method="post">'; |
|
195 | - echo '<input type="hidden" name="go" value="1">'; |
|
196 | - echo '<p>', I18N::translate(/* I18N: Copy all the records from [family tree 1] into [family tree 2] */ |
|
197 | - 'Copy all the records from %1$s into %2$s.', |
|
198 | - FunctionsEdit::selectEditControl('tree1_id', Tree::getIdList(), '', null), |
|
199 | - FunctionsEdit::selectEditControl('tree2_id', Tree::getIdList(), '', null) |
|
200 | - ), |
|
201 | - '</p>'; |
|
194 | + echo '<form method="post">'; |
|
195 | + echo '<input type="hidden" name="go" value="1">'; |
|
196 | + echo '<p>', I18N::translate(/* I18N: Copy all the records from [family tree 1] into [family tree 2] */ |
|
197 | + 'Copy all the records from %1$s into %2$s.', |
|
198 | + FunctionsEdit::selectEditControl('tree1_id', Tree::getIdList(), '', null), |
|
199 | + FunctionsEdit::selectEditControl('tree2_id', Tree::getIdList(), '', null) |
|
200 | + ), |
|
201 | + '</p>'; |
|
202 | 202 | |
203 | - echo '<button type="submit" class="btn btn-primary">'; |
|
204 | - echo '<i class="fa fa-check"></i> ', /* I18N: A button label. */ I18N::translate('continue'); |
|
205 | - echo '</button>'; |
|
206 | - echo '</form>'; |
|
203 | + echo '<button type="submit" class="btn btn-primary">'; |
|
204 | + echo '<i class="fa fa-check"></i> ', /* I18N: A button label. */ I18N::translate('continue'); |
|
205 | + echo '</button>'; |
|
206 | + echo '</form>'; |
|
207 | 207 | } |