xref: /webtrees/app/Schema/Migration21.php (revision 3d7a8a4ca809135634f38216b734b15acff479f7)
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 Migration21 - upgrade the database schema from version 21 to version 22.
22 */
23class Migration21 implements MigrationInterface {
24	/** {@inheritDoc} */
25	public function upgrade() {
26		// Data fix for bug #1072477
27		Database::exec("UPDATE `##default_resn` SET xref     = NULL WHERE xref     = ''");
28		Database::exec("UPDATE `##default_resn` SET tag_type = NULL WHERE tag_type = ''");
29
30		// Delete old settings
31		Database::exec("DELETE FROM `##gedcom_setting` WHERE setting_name IN ('AUTO_GENERATE_THUMBS', 'POSTAL_CODE', 'MEDIA_DIRECTORY_LEVELS', 'USE_MEDIA_VIEWER')");
32
33		// Delete old settings
34		Database::exec("DELETE FROM `##module_setting` WHERE module_name='lightbox'");
35
36		// Very old versions of phpGedView allowed media paths beginning “./”
37		// Remove these
38		Database::exec(
39			"UPDATE `##media` m" .
40			" SET" .
41			"  m_filename = TRIM(LEADING './' FROM m_filename)," .
42			"  m_gedcom   = REPLACE(m_gedcom, '\n1 FILE ./', '\n1 FILE ')"
43		);
44		Database::exec(
45			"UPDATE `##change` c" .
46			" SET new_gedcom = REPLACE(new_gedcom, '\n1 FILE ./', '\n1 FILE ')" .
47			" WHERE status = 'pending'"
48		);
49
50		// Previous versions of webtrees included the MEDIA_DIRECTORY setting in the
51		// FILE tag of the OBJE records.  Remove it…
52		Database::exec(
53			"UPDATE `##media` m" .
54			" JOIN `##gedcom_setting` gs ON (m.m_file = gs.gedcom_id AND gs.setting_name = 'MEDIA_DIRECTORY')" .
55			" SET" .
56			"  m_filename = TRIM(LEADING gs.setting_value FROM m_filename)," .
57			"  m_gedcom   = REPLACE(m_gedcom, CONCAT('\n1 FILE ', gs.setting_value), '\n1 FILE ')"
58		);
59		// …don’t forget pending changes
60		Database::exec(
61			"UPDATE `##change` c" .
62			" JOIN `##gedcom_setting` gs ON (c.gedcom_id = gs.gedcom_id AND gs.setting_name = 'MEDIA_DIRECTORY')" .
63			" SET new_gedcom = REPLACE(new_gedcom, CONCAT('\n1 FILE ', gs.setting_value), '\n1 FILE ')" .
64			" WHERE status = 'pending'"
65		);
66	}
67}
68