xref: /webtrees/app/Schema/Migration38.php (revision 342dcecd8628deacd49d86f3247fd77e64bf33c3)
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;
19use PDOException;
20
21/**
22 * Upgrade the database schema from version 38 to version 39.
23 */
24class Migration38 implements MigrationInterface
25{
26    /**
27     * Upgrade to to the next version
28     */
29    public function upgrade()
30    {
31        // The geographic data is now handled by the core code.
32        // The following migrations were once part of the old googlemap module.
33        try {
34            // Create the tables, as per PhpGedView 4.2.1
35            Database::exec(
36                "CREATE TABLE IF NOT EXISTS `##placelocation` (" .
37                " pl_id        INTEGER      NOT NULL," .
38                " pl_parent_id INTEGER          NULL," .
39                " pl_level     INTEGER          NULL," .
40                " pl_place     VARCHAR(255)     NULL," .
41                " pl_long      VARCHAR(30)      NULL," .
42                " pl_lati      VARCHAR(30)      NULL," .
43                " pl_zoom      INTEGER          NULL," .
44                " pl_icon      VARCHAR(255)     NULL," .
45                " PRIMARY KEY     (pl_id)," .
46                "         KEY ix1 (pl_level)," .
47                "         KEY ix2 (pl_long)," .
48                "         KEY ix3 (pl_lati)," .
49                "         KEY ix4 (pl_place)," .
50                "         KEY ix5 (pl_parent_id)" .
51                ") COLLATE utf8_unicode_ci ENGINE=InnoDB"
52            );
53        } catch (PDOException $ex) {
54            // Already done?
55        }
56
57        try {
58            Database::exec(
59                "ALTER TABLE `##placelocation` ADD (" .
60                " pl_media      VARCHAR(60)     NULL," .
61                " sv_long       FLOAT           NOT NULL DEFAULT 0," .
62                " sv_lati       FLOAT           NOT NULL DEFAULT 0," .
63                " sv_bearing    FLOAT           NOT NULL DEFAULT 0," .
64                " sv_elevation  FLOAT           NOT NULL DEFAULT 0," .
65                " sv_zoom       FLOAT           NOT NULL DEFAULT 1" .
66                ")"
67            );
68        } catch (PDOException $ex) {
69            // Already done?
70        }
71
72        try {
73            Database::exec(
74                "ALTER TABLE `##placelocation`" .
75                " DROP COLUMN pl_media," .
76                " DROP COLUMN sv_long," .
77                " DROP COLUMN sv_lati," .
78                " DROP COLUMN sv_bearing," .
79                " DROP COLUMN sv_elevation," .
80                " DROP COLUMN sv_zoom," .
81                " DROP INDEX ix1," .
82                " DROP INDEX ix2," .
83                " DROP INDEX ix3," .
84                " DROP INDEX ix4," .
85                " DROP INDEX ix5," .
86                " ADD UNIQUE INDEX ix1 (pl_parent_id, pl_place)," .
87                " ADD INDEX ix2 (pl_parent_id)," .
88                " ADD INDEX ix3 (pl_place)"
89            );
90        } catch (PDOException $ex) {
91            // Already done?
92        }
93
94        // Convert flag icons from .gif to .png
95        Database::exec("UPDATE `##placelocation` SET pl_icon=REPLACE(pl_icon, '.gif', '.png')");
96
97        // Delete old settings
98        Database::exec("DELETE FROM `##module_setting` WHERE module_name='googlemap'");
99        Database::exec("DELETE FROM `##module_privacy` WHERE module_name='googlemap'");
100        Database::exec("DELETE FROM `##module` WHERE module_name='googlemap'");
101    }
102}
103