summaryrefslogtreecommitdiff
path: root/includes/db_schema/db_schema_21_22.php
blob: f754a2f7f610a42c0aeba0398fb78f194e8780c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace Fisharebest\Webtrees;

/**
 * webtrees: online genealogy
 * Copyright (C) 2015 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

// Update the database schema from version 21-22
// - delete some old/unused configuration settings
// - data update for 1.4.0 media changes

// Data fix for bug #1072477
Database::exec("UPDATE `##default_resn` SET xref    =NULL WHERE xref    =''");
Database::exec("UPDATE `##default_resn` SET tag_type=NULL WHERE tag_type=''");

// Delete old settings
Database::exec("DELETE FROM `##gedcom_setting` WHERE setting_name IN ('AUTO_GENERATE_THUMBS', 'POSTAL_CODE', 'MEDIA_DIRECTORY_LEVELS', 'USE_MEDIA_VIEWER')");

// Delete old settings
Database::exec("DELETE FROM `##module_setting` WHERE module_name='lightbox'");

// Very old versions of phpGedView allowed media paths beginning “./”
// Remove these
Database::exec(
	"UPDATE `##media` m" .
	" SET" .
	"  m_filename = TRIM(LEADING './' FROM m_filename)," .
	"  m_gedcom   = REPLACE(m_gedcom, '\n1 FILE ./', '\n1 FILE ')"
);
Database::exec(
	"UPDATE `##change` c" .
	" SET new_gedcom = REPLACE(new_gedcom, '\n1 FILE ./', '\n1 FILE ')" .
	" WHERE status = 'pending'"
);

// Previous versions of webtrees included the MEDIA_DIRECTORY setting in the
// FILE tag of the OBJE records.  Remove it…
Database::exec(
	"UPDATE `##media` m" .
	" JOIN `##gedcom_setting` gs ON (m.m_file = gs.gedcom_id AND gs.setting_name = 'MEDIA_DIRECTORY')" .
	" SET" .
	"  m_filename = TRIM(LEADING gs.setting_value FROM m_filename)," .
	"  m_gedcom   = REPLACE(m_gedcom, CONCAT('\n1 FILE ', gs.setting_value), '\n1 FILE ')"
);
// …don’t forget pending changes
Database::exec(
	"UPDATE `##change` c" .
	" JOIN `##gedcom_setting` gs ON (c.gedcom_id = gs.gedcom_id AND gs.setting_name = 'MEDIA_DIRECTORY')" .
	" SET new_gedcom = REPLACE(new_gedcom, CONCAT('\n1 FILE ', gs.setting_value), '\n1 FILE ')" .
	" WHERE status = 'pending'"
);

// Update the version to indicate success
Site::setPreference($schema_name, $next_version);