xref: /webtrees/app/Schema/Migration21.php (revision 1062a1429914c995339f502856821457aa975a5a)
13bfb94b0SGreg Roach<?php
23bfb94b0SGreg Roach/**
33bfb94b0SGreg Roach * webtrees: online genealogy
4*1062a142SGreg Roach * Copyright (C) 2018 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 */
1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Schema;
1776692c8bSGreg Roach
183bfb94b0SGreg Roachuse Fisharebest\Webtrees\Database;
193bfb94b0SGreg Roach
203bfb94b0SGreg Roach/**
2176692c8bSGreg Roach * Upgrade the database schema from version 21 to version 22.
223bfb94b0SGreg Roach */
233bfb94b0SGreg Roachclass Migration21 implements MigrationInterface {
2476692c8bSGreg Roach	/**
2576692c8bSGreg Roach	 * Upgrade to to the next version
2676692c8bSGreg Roach	 */
273bfb94b0SGreg Roach	public function upgrade() {
283bfb94b0SGreg Roach		// Data fix for bug #1072477
293bfb94b0SGreg Roach		Database::exec("UPDATE `##default_resn` SET xref     = NULL WHERE xref     = ''");
303bfb94b0SGreg Roach		Database::exec("UPDATE `##default_resn` SET tag_type = NULL WHERE tag_type = ''");
313bfb94b0SGreg Roach
323bfb94b0SGreg Roach		// Delete old settings
333bfb94b0SGreg Roach		Database::exec("DELETE FROM `##gedcom_setting` WHERE setting_name IN ('AUTO_GENERATE_THUMBS', 'POSTAL_CODE', 'MEDIA_DIRECTORY_LEVELS', 'USE_MEDIA_VIEWER')");
343bfb94b0SGreg Roach
353bfb94b0SGreg Roach		// Delete old settings
363bfb94b0SGreg Roach		Database::exec("DELETE FROM `##module_setting` WHERE module_name='lightbox'");
373bfb94b0SGreg Roach
383bfb94b0SGreg Roach		// Very old versions of phpGedView allowed media paths beginning “./”
393bfb94b0SGreg Roach		// Remove these
403bfb94b0SGreg Roach		Database::exec(
413bfb94b0SGreg Roach			"UPDATE `##media` m" .
423bfb94b0SGreg Roach			" SET" .
433bfb94b0SGreg Roach			"  m_filename = TRIM(LEADING './' FROM m_filename)," .
443bfb94b0SGreg Roach			"  m_gedcom   = REPLACE(m_gedcom, '\n1 FILE ./', '\n1 FILE ')"
453bfb94b0SGreg Roach		);
463bfb94b0SGreg Roach		Database::exec(
473bfb94b0SGreg Roach			"UPDATE `##change` c" .
483bfb94b0SGreg Roach			" SET new_gedcom = REPLACE(new_gedcom, '\n1 FILE ./', '\n1 FILE ')" .
493bfb94b0SGreg Roach			" WHERE status = 'pending'"
503bfb94b0SGreg Roach		);
513bfb94b0SGreg Roach
523bfb94b0SGreg Roach		// Previous versions of webtrees included the MEDIA_DIRECTORY setting in the
533bfb94b0SGreg Roach		// FILE tag of the OBJE records. Remove it…
543bfb94b0SGreg Roach		Database::exec(
553bfb94b0SGreg Roach			"UPDATE `##media` m" .
563bfb94b0SGreg Roach			" JOIN `##gedcom_setting` gs ON (m.m_file = gs.gedcom_id AND gs.setting_name = 'MEDIA_DIRECTORY')" .
573bfb94b0SGreg Roach			" SET" .
583bfb94b0SGreg Roach			"  m_filename = TRIM(LEADING gs.setting_value FROM m_filename)," .
593bfb94b0SGreg Roach			"  m_gedcom   = REPLACE(m_gedcom, CONCAT('\n1 FILE ', gs.setting_value), '\n1 FILE ')"
603bfb94b0SGreg Roach		);
613bfb94b0SGreg Roach		// …don’t forget pending changes
623bfb94b0SGreg Roach		Database::exec(
633bfb94b0SGreg Roach			"UPDATE `##change` c" .
643bfb94b0SGreg Roach			" JOIN `##gedcom_setting` gs ON (c.gedcom_id = gs.gedcom_id AND gs.setting_name = 'MEDIA_DIRECTORY')" .
653bfb94b0SGreg Roach			" SET new_gedcom = REPLACE(new_gedcom, CONCAT('\n1 FILE ', gs.setting_value), '\n1 FILE ')" .
663bfb94b0SGreg Roach			" WHERE status = 'pending'"
673bfb94b0SGreg Roach		);
683bfb94b0SGreg Roach	}
693bfb94b0SGreg Roach}
70