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