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