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