aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/upgrades/2010040201.php
blob: 92c7d6a5c234353ce8d8e686c654f732b10b9b5d (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
<?php
/**
 * Pull admin metadata setting into users_entity table column
 */

$siteadmin = get_metastring_id('siteadmin');
$admin = get_metastring_id('admin');
$yes = get_metastring_id('yes');
$one = get_metastring_id('1');

$qs = array();

$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity DISABLE KEYS";

$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity
	ADD admin ENUM('yes', 'no') NOT NULL DEFAULT 'no' AFTER `banned`";

$qs[] = "UPDATE {$CONFIG->dbprefix}users_entity SET admin = 'yes' where guid IN (select x.guid FROM(
SELECT * FROM {$CONFIG->dbprefix}users_entity as e,
	{$CONFIG->dbprefix}metadata as md
	WHERE (
		md.name_id IN ('$admin', '$siteadmin')
		AND md.value_id IN ('$yes', '$one')
		AND e.guid = md.entity_guid
		AND e.banned = 'no'
	)) as x)";

$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ADD KEY admin (admin)";

$qs[] = "ALTER TABLE {$CONFIG->dbprefix}users_entity ENABLE KEYS";

$qs[] = "DELETE FROM {$CONFIG->dbprefix}metadata
	WHERE (
		name_id IN ('$admin', '$siteadmin')
		AND value_id IN ('$yes', '$one')
	)";

foreach ($qs as $q) {
	update_data($q);
}