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