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