xref: /webtrees/app/Schema/Migration3.php (revision e34358135208d3a19cf4a72223731c09dded622b)
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 3 to version 4.
22 */
23class Migration3 implements MigrationInterface
24{
25    /**
26     * Upgrade to to the next version
27     *
28     * @return void
29     */
30    public function upgrade()
31    {
32        // Update the max_relation_path_length from a separate
33        // user setting and gedcom setting to a combined user-gedcom
34        // setting.
35        // Also clean out some old/unused values.
36
37        Database::exec(
38            "INSERT IGNORE INTO `##user_gedcom_setting` (user_id, gedcom_id, setting_name, setting_value)" .
39            " SELECT u.user_id, g.gedcom_id, 'RELATIONSHIP_PATH_LENGTH', LEAST(us1.setting_value, gs1.setting_value)" .
40            " FROM   `##user` u" .
41            " CROSS  JOIN `##gedcom` g" .
42            " LEFT   JOIN `##user_setting`   us1 ON (u.user_id  =us1.user_id   AND us1.setting_name='max_relation_path')" .
43            " LEFT   JOIN `##user_setting`   us2 ON (u.user_id  =us2.user_id   AND us2.setting_name='relationship_privacy')" .
44            " LEFT   JOIN `##gedcom_setting` gs1 ON (g.gedcom_id=gs1.gedcom_id AND gs1.setting_name='MAX_RELATION_PATH_LENGTH')" .
45            " LEFT   JOIN `##gedcom_setting` gs2 ON (g.gedcom_id=gs2.gedcom_id AND gs2.setting_name='USE_RELATIONSHIP_PRIVACY')" .
46            " WHERE  us2.setting_value AND gs2.setting_value"
47        );
48
49        // Delete old/unused settings
50        Database::exec(
51            "DELETE FROM `##site_setting` WHERE setting_name IN ('SESSION_SAVE_PATH')"
52        );
53        Database::exec(
54            "DELETE FROM `##gedcom_setting` WHERE setting_name IN ('HOME_SITE_TEXT', 'HOME_SITE_URL', 'CHECK_MARRIAGE_RELATIONS', 'MAX_RELATION_PATH_LENGTH', 'USE_RELATIONSHIP_PRIVACY')"
55        );
56        Database::exec(
57            "DELETE FROM `##user_setting` WHERE setting_name IN ('loggedin', 'relationship_privacy', 'max_relation_path_length')"
58        );
59
60        // Fix Mc/Mac problems - See SVN9701
61        Database::exec(
62            "UPDATE `##name` SET n_surn=CONCAT('MC', SUBSTRING(n_surn, 4)) WHERE n_surn LIKE 'MC0%'"
63        );
64    }
65}
66