xref: /webtrees/app/Schema/Migration26.php (revision 76692c8b291f16d9251d67f27078779f6737fe7e)
13bfb94b0SGreg Roach<?php
23bfb94b0SGreg Roach/**
33bfb94b0SGreg Roach * webtrees: online genealogy
43bfb94b0SGreg Roach * Copyright (C) 2015 webtrees development team
53bfb94b0SGreg Roach * This program is free software: you can redistribute it and/or modify
63bfb94b0SGreg Roach * it under the terms of the GNU General Public License as published by
73bfb94b0SGreg Roach * the Free Software Foundation, either version 3 of the License, or
83bfb94b0SGreg Roach * (at your option) any later version.
93bfb94b0SGreg Roach * This program is distributed in the hope that it will be useful,
103bfb94b0SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
113bfb94b0SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
123bfb94b0SGreg Roach * GNU General Public License for more details.
133bfb94b0SGreg Roach * You should have received a copy of the GNU General Public License
143bfb94b0SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
153bfb94b0SGreg Roach */
16*76692c8bSGreg Roachnamespace Fisharebest\Webtrees\Schema;
17*76692c8bSGreg Roach
183bfb94b0SGreg Roachuse Fisharebest\Webtrees\Database;
193bfb94b0SGreg Roach
203bfb94b0SGreg Roach/**
21*76692c8bSGreg Roach * Upgrade the database schema from version 26 to version 27.
223bfb94b0SGreg Roach */
233bfb94b0SGreg Roachclass Migration26 implements MigrationInterface {
24*76692c8bSGreg Roach	/**
25*76692c8bSGreg Roach	 * Upgrade to to the next version
26*76692c8bSGreg Roach	 */
273bfb94b0SGreg Roach	public function upgrade() {
283bfb94b0SGreg Roach		// Earlier versions of webtrees put quote marks round soundex codes.
293bfb94b0SGreg Roach		// These are harmless, but clean them up for consistency.
303bfb94b0SGreg Roach		Database::exec(
313bfb94b0SGreg Roach			"UPDATE `##name` SET" .
323bfb94b0SGreg Roach			" n_soundex_givn_std = TRIM('''' FROM n_soundex_givn_std)," .
333bfb94b0SGreg Roach			" n_soundex_surn_std = TRIM('''' FROM n_soundex_surn_std)," .
343bfb94b0SGreg Roach			" n_soundex_givn_dm  = TRIM('''' FROM n_soundex_givn_dm )," .
353bfb94b0SGreg Roach			" n_soundex_surn_dm  = TRIM('''' FROM n_soundex_surn_dm )"
363bfb94b0SGreg Roach		);
373bfb94b0SGreg Roach
383bfb94b0SGreg Roach		// Earlier versions of webtrees added zero codes for names without phonetic content.
393bfb94b0SGreg Roach		// These are harmless, but clean them up for consistency.
403bfb94b0SGreg Roach		Database::exec(
413bfb94b0SGreg Roach			"UPDATE `##name` SET" .
423bfb94b0SGreg Roach			" n_soundex_givn_std = REPLACE(n_soundex_givn_std, '0000:',   '')," .
433bfb94b0SGreg Roach			" n_soundex_surn_std = REPLACE(n_soundex_surn_std, '0000:',   '')," .
443bfb94b0SGreg Roach			" n_soundex_givn_dm  = REPLACE(n_soundex_givn_dm,  '000000:', '')," .
453bfb94b0SGreg Roach			" n_soundex_surn_dm  = REPLACE(n_soundex_surn_dm,  '000000:', '')"
463bfb94b0SGreg Roach		);
473bfb94b0SGreg Roach		Database::exec(
483bfb94b0SGreg Roach			"UPDATE `##name` SET" .
493bfb94b0SGreg Roach			" n_soundex_givn_std = REPLACE(n_soundex_givn_std, ':0000',   '')," .
503bfb94b0SGreg Roach			" n_soundex_surn_std = REPLACE(n_soundex_surn_std, ':0000',   '')," .
513bfb94b0SGreg Roach			" n_soundex_givn_dm  = REPLACE(n_soundex_givn_dm,  ':000000', '')," .
523bfb94b0SGreg Roach			" n_soundex_surn_dm  = REPLACE(n_soundex_surn_dm,  ':000000', '')"
533bfb94b0SGreg Roach		);
543bfb94b0SGreg Roach		Database::exec(
553bfb94b0SGreg Roach			"UPDATE `##name` SET" .
563bfb94b0SGreg Roach			" n_soundex_givn_std = NULLIF(n_soundex_givn_std, '0000'  )," .
573bfb94b0SGreg Roach			" n_soundex_surn_std = NULLIF(n_soundex_surn_std, '0000'  )," .
583bfb94b0SGreg Roach			" n_soundex_givn_dm  = NULLIF(n_soundex_givn_dm,  '000000')," .
593bfb94b0SGreg Roach			" n_soundex_surn_dm  = NULLIF(n_soundex_surn_dm,  '000000')"
603bfb94b0SGreg Roach		);
613bfb94b0SGreg Roach
623bfb94b0SGreg Roach		Database::exec(
633bfb94b0SGreg Roach			"UPDATE `##places` SET" .
643bfb94b0SGreg Roach			" p_std_soundex = REPLACE(p_std_soundex, '0000:',   '')," .
653bfb94b0SGreg Roach			" p_dm_soundex  = REPLACE(p_dm_soundex,  '000000:', '')"
663bfb94b0SGreg Roach		);
673bfb94b0SGreg Roach		Database::exec(
683bfb94b0SGreg Roach			"UPDATE `##places` SET" .
693bfb94b0SGreg Roach			" p_std_soundex = REPLACE(p_std_soundex, ':0000',   '')," .
703bfb94b0SGreg Roach			" p_dm_soundex  = REPLACE(p_dm_soundex,  ':000000', '')"
713bfb94b0SGreg Roach		);
723bfb94b0SGreg Roach		Database::exec(
733bfb94b0SGreg Roach			"UPDATE `##places` SET" .
743bfb94b0SGreg Roach			" p_std_soundex = NULLIF(p_std_soundex, '0000'  )," .
753bfb94b0SGreg Roach			" p_dm_soundex  = NULLIF(p_dm_soundex,  '000000')"
763bfb94b0SGreg Roach		);
773bfb94b0SGreg Roach	}
783bfb94b0SGreg Roach}
79