xref: /webtrees/app/Schema/Migration37.php (revision 12c79f746ea1903d66aea1fe0412eda6149a5532)
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 37 to version 38.
23 */
24class Migration37 implements MigrationInterface
25{
26    /**
27     * Upgrade to to the next version
28     *
29     * @return void
30     */
31    public function upgrade()
32    {
33        Database::prepare(
34            "DROP TABLE IF EXISTS `##site_access_rule`"
35        )->execute();
36
37        try {
38            Database::prepare(
39                "INSERT INTO `##site_setting` (setting_name, setting_value)" .
40                " SELECT 'next_xref', MAX(next_id) FROM `##next_id`"
41            )->execute();
42        } catch (PDOException $ex) {
43            // Already done?
44        }
45
46        Database::prepare(
47            "DELETE FROM `##gedcom_setting` WHERE setting_name in ('FAM_ID_PREFIX', 'GEDCOM_ID_PREFIX', 'MEDIA_ID_PREFIX', 'NOTE_ID_PREFIX', 'REPO_ID_PREFIX', 'SOURCE_ID_PREFIX')"
48        )->execute();
49
50        Database::prepare(
51            "DROP TABLE IF EXISTS `##next_id`"
52        )->execute();
53
54        Database::prepare(
55            "CREATE TABLE IF NOT EXISTS `##media_file` (" .
56            "id                   INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY," .
57            "m_id                 VARCHAR(20)  NOT NULL," .
58            "m_file               INTEGER      NOT NULL," .
59            "multimedia_file_refn VARCHAR(512) NOT NULL," . // GEDCOM only allows 30 characters
60            "multimedia_format    VARCHAR(4)   NOT NULL," .
61            "source_media_type    VARCHAR(15)  NOT NULL," .
62            "descriptive_title    VARCHAR(248) NOT NULL," .
63            "KEY `##media_file_ix1` (m_id, m_file)," .
64            "KEY `##media_file_ix2` (m_file, m_id)," .
65            "KEY `##media_file_ix3` (m_file, multimedia_file_refn)," .
66            "KEY `##media_file_ix4` (m_file, multimedia_format)," .
67            "KEY `##media_file_ix5` (m_file, source_media_type)," .
68            "KEY `##media_file_ix6` (m_file, descriptive_title)" .
69            ") ENGINE=InnoDB COLLATE=utf8_unicode_ci"
70        )->execute();
71
72        try {
73            Database::prepare(
74                "INSERT INTO `##media_file` (" .
75                "m_id, m_file, multimedia_file_refn, multimedia_format, source_media_type, descriptive_title" .
76                ") SELECT m_id, m_file, m_filename, m_ext, LEFT(m_type, 15), m_titl FROM `##media`"
77            )->execute();
78        } catch (PDOException $ex) {
79            // Already done?
80        }
81
82        try {
83            Database::prepare(
84                "ALTER TABLE `##media`" .
85                " DROP COLUMN m_filename," .
86                " DROP COLUMN m_ext," .
87                " DROP COLUMN m_type," .
88                " DROP COLUMN m_titl"
89            )->execute();
90        } catch (PDOException $ex) {
91            // Already done?
92        }
93    }
94}
95