xref: /webtrees/app/Schema/Migration27.php (revision 2836aa05d87d478edc3ef1f1983e9d37862ded10)
1<?php
2namespace Fisharebest\Webtrees\Schema;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18use Fisharebest\Webtrees\Database;
19use PDOException;
20
21/**
22 * Class Migration27 - upgrade the database schema from version 27 to version 28.
23 */
24class Migration27 implements MigrationInterface {
25	/** {@inheritDoc} */
26	public function upgrade() {
27		// Delete old/unused settings
28		Database::exec(
29			"DELETE FROM `##gedcom_setting` WHERE setting_name IN ('USE_GEONAMES')"
30		);
31
32		try {
33			// Indexes created by setup.php or schema update 17-18
34			Database::exec("ALTER TABLE `##site_access_rule` DROP INDEX ix1, DROP INDEX ix2, DROP INDEX ix3");
35			// Indexes created by schema update 17-18
36			Database::exec("ALTER TABLE `##site_access_rule` DROP INDEX ix4, DROP INDEX ix5, DROP INDEX ix6");
37		} catch (PDOException $ex) {
38			// Already done?
39		}
40
41		// User data may contains duplicates - these will prevent us from creating the new indexes
42		Database::exec(
43			"DELETE t1 FROM `##site_access_rule` AS t1 JOIN (SELECT MIN(site_access_rule_id) AS site_access_rule_id, ip_address_end, ip_address_start, user_agent_pattern FROM `##site_access_rule`) AS t2 ON t1.ip_address_end = t2.ip_address_end AND t1.ip_address_start = t2.ip_address_start AND t1.user_agent_pattern = t2.user_agent_pattern AND t1.site_access_rule_id <> t2.site_access_rule_id"
44		);
45
46		// ix1 - covering index for visitor lookup
47		// ix2 - for total counts in admin page
48		try {
49			Database::exec(
50				"ALTER TABLE `##site_access_rule`" .
51				" ADD UNIQUE INDEX `##site_access_rule_ix1` (ip_address_end, ip_address_start, user_agent_pattern, rule)," .
52				" ADD        INDEX `##site_access_rule_ix2` (rule)"
53			);
54		} catch (PDOException $ex) {
55			// Already done?
56		}
57	}
58}
59