xref: /webtrees/app/Schema/Migration26.php (revision f0a114195ac1eac96981ed21f4681b1f2d0de72c)
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     * @return void
29     */
30    public function upgrade()
31    {
32        // Earlier versions of webtrees put quote marks round soundex codes.
33        // These are harmless, but clean them up for consistency.
34        Database::exec(
35            "UPDATE `##name` SET" .
36            " n_soundex_givn_std = TRIM('''' FROM n_soundex_givn_std)," .
37            " n_soundex_surn_std = TRIM('''' FROM n_soundex_surn_std)," .
38            " n_soundex_givn_dm  = TRIM('''' FROM n_soundex_givn_dm )," .
39            " n_soundex_surn_dm  = TRIM('''' FROM n_soundex_surn_dm )"
40        );
41
42        // Earlier versions of webtrees added zero codes for names without phonetic content.
43        // These are harmless, but clean them up for consistency.
44        Database::exec(
45            "UPDATE `##name` SET" .
46            " n_soundex_givn_std = REPLACE(n_soundex_givn_std, '0000:',   '')," .
47            " n_soundex_surn_std = REPLACE(n_soundex_surn_std, '0000:',   '')," .
48            " n_soundex_givn_dm  = REPLACE(n_soundex_givn_dm,  '000000:', '')," .
49            " n_soundex_surn_dm  = REPLACE(n_soundex_surn_dm,  '000000:', '')"
50        );
51        Database::exec(
52            "UPDATE `##name` SET" .
53            " n_soundex_givn_std = REPLACE(n_soundex_givn_std, ':0000',   '')," .
54            " n_soundex_surn_std = REPLACE(n_soundex_surn_std, ':0000',   '')," .
55            " n_soundex_givn_dm  = REPLACE(n_soundex_givn_dm,  ':000000', '')," .
56            " n_soundex_surn_dm  = REPLACE(n_soundex_surn_dm,  ':000000', '')"
57        );
58        Database::exec(
59            "UPDATE `##name` SET" .
60            " n_soundex_givn_std = NULLIF(n_soundex_givn_std, '0000'  )," .
61            " n_soundex_surn_std = NULLIF(n_soundex_surn_std, '0000'  )," .
62            " n_soundex_givn_dm  = NULLIF(n_soundex_givn_dm,  '000000')," .
63            " n_soundex_surn_dm  = NULLIF(n_soundex_surn_dm,  '000000')"
64        );
65
66        Database::exec(
67            "UPDATE `##places` SET" .
68            " p_std_soundex = REPLACE(p_std_soundex, '0000:',   '')," .
69            " p_dm_soundex  = REPLACE(p_dm_soundex,  '000000:', '')"
70        );
71        Database::exec(
72            "UPDATE `##places` SET" .
73            " p_std_soundex = REPLACE(p_std_soundex, ':0000',   '')," .
74            " p_dm_soundex  = REPLACE(p_dm_soundex,  ':000000', '')"
75        );
76        Database::exec(
77            "UPDATE `##places` SET" .
78            " p_std_soundex = NULLIF(p_std_soundex, '0000'  )," .
79            " p_dm_soundex  = NULLIF(p_dm_soundex,  '000000')"
80        );
81    }
82}
83