xref: /webtrees/app/Schema/Migration26.php (revision 2836aa05d87d478edc3ef1f1983e9d37862ded10)
1<?php
2namespace Fisharebest\Webtrees\Schema;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18use Fisharebest\Webtrees\Database;
19
20/**
21 * Class Migration26 - upgrade the database schema from version 26 to version 27.
22 */
23class Migration26 implements MigrationInterface {
24	/** {@inheritDoc} */
25	public function upgrade() {
26		// Earlier versions of webtrees put quote marks round soundex codes.
27		// These are harmless, but clean them up for consistency.
28		Database::exec(
29			"UPDATE `##name` SET" .
30			" n_soundex_givn_std = TRIM('''' FROM n_soundex_givn_std)," .
31			" n_soundex_surn_std = TRIM('''' FROM n_soundex_surn_std)," .
32			" n_soundex_givn_dm  = TRIM('''' FROM n_soundex_givn_dm )," .
33			" n_soundex_surn_dm  = TRIM('''' FROM n_soundex_surn_dm )"
34		);
35
36		// Earlier versions of webtrees added zero codes for names without phonetic content.
37		// These are harmless, but clean them up for consistency.
38		Database::exec(
39			"UPDATE `##name` SET" .
40			" n_soundex_givn_std = REPLACE(n_soundex_givn_std, '0000:',   '')," .
41			" n_soundex_surn_std = REPLACE(n_soundex_surn_std, '0000:',   '')," .
42			" n_soundex_givn_dm  = REPLACE(n_soundex_givn_dm,  '000000:', '')," .
43			" n_soundex_surn_dm  = REPLACE(n_soundex_surn_dm,  '000000:', '')"
44		);
45		Database::exec(
46			"UPDATE `##name` SET" .
47			" n_soundex_givn_std = REPLACE(n_soundex_givn_std, ':0000',   '')," .
48			" n_soundex_surn_std = REPLACE(n_soundex_surn_std, ':0000',   '')," .
49			" n_soundex_givn_dm  = REPLACE(n_soundex_givn_dm,  ':000000', '')," .
50			" n_soundex_surn_dm  = REPLACE(n_soundex_surn_dm,  ':000000', '')"
51		);
52		Database::exec(
53			"UPDATE `##name` SET" .
54			" n_soundex_givn_std = NULLIF(n_soundex_givn_std, '0000'  )," .
55			" n_soundex_surn_std = NULLIF(n_soundex_surn_std, '0000'  )," .
56			" n_soundex_givn_dm  = NULLIF(n_soundex_givn_dm,  '000000')," .
57			" n_soundex_surn_dm  = NULLIF(n_soundex_surn_dm,  '000000')"
58		);
59
60		Database::exec(
61			"UPDATE `##places` SET" .
62			" p_std_soundex = REPLACE(p_std_soundex, '0000:',   '')," .
63			" p_dm_soundex  = REPLACE(p_dm_soundex,  '000000:', '')"
64		);
65		Database::exec(
66			"UPDATE `##places` SET" .
67			" p_std_soundex = REPLACE(p_std_soundex, ':0000',   '')," .
68			" p_dm_soundex  = REPLACE(p_dm_soundex,  ':000000', '')"
69		);
70		Database::exec(
71			"UPDATE `##places` SET" .
72			" p_std_soundex = NULLIF(p_std_soundex, '0000'  )," .
73			" p_dm_soundex  = NULLIF(p_dm_soundex,  '000000')"
74		);
75	}
76}
77