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