summaryrefslogtreecommitdiff
path: root/app/Schema/Migration27.php
blob: d2096b8def69a653f398bbac1fc6a9389b2a0558 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Fisharebest\Webtrees\Schema;

/**
 * webtrees: online genealogy
 * Copyright (C) 2015 webtrees development team
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
use Fisharebest\Webtrees\Database;
use PDOException;

/**
 * Class Migration27 - upgrade the database schema from version 27 to version 28.
 */
class Migration27 implements MigrationInterface {
	/** {@inheritDoc} */
	public function upgrade() {
		// Delete old/unused settings
		Database::exec(
			"DELETE FROM `##gedcom_setting` WHERE setting_name IN ('USE_GEONAMES')"
		);

		try {
			// Indexes created by setup.php or schema update 17-18
			Database::exec("ALTER TABLE `##site_access_rule` DROP INDEX ix1, DROP INDEX ix2, DROP INDEX ix3");
			// Indexes created by schema update 17-18
			Database::exec("ALTER TABLE `##site_access_rule` DROP INDEX ix4, DROP INDEX ix5, DROP INDEX ix6");
		} catch (PDOException $ex) {
			// Already done?
		}

		// User data may contains duplicates - these will prevent us from creating the new indexes
		Database::exec(
			"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"
		);

		// ix1 - covering index for visitor lookup
		// ix2 - for total counts in admin page
		try {
			Database::exec(
				"ALTER TABLE `##site_access_rule`" .
				" ADD UNIQUE INDEX `##site_access_rule_ix1` (ip_address_end, ip_address_start, user_agent_pattern, rule)," .
				" ADD        INDEX `##site_access_rule_ix2` (rule)"
			);
		} catch (PDOException $ex) {
			// Already done?
		}
	}
}