PluginProbe
User Access Manager / 2.3.18
User Access Manager v2.3.18
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Setup/Update/DatabaseUpdate1.php +18 -32 trunk2.3.18 View file →
@@ -12,23 +12,23 @@
12 12 }
13 13
14 14 private function updateToUserGroupTableUpdate(string $userGroupTable): bool
15 15 {
16 - $alterQuery = "ALTER TABLE `{$userGroupTable}`
17 - ADD `read_access` TINYTEXT NOT NULL DEFAULT '',
18 - ADD `write_access` TINYTEXT NOT NULL DEFAULT '',
19 - ADD `ip_range` MEDIUMTEXT NULL DEFAULT ''";
16 + $alterQuery = "ALTER TABLE {$userGroupTable}
17 + ADD read_access TINYTEXT NOT NULL DEFAULT '',
18 + ADD write_access TINYTEXT NOT NULL DEFAULT '',
19 + ADD ip_range MEDIUMTEXT NULL DEFAULT ''";
20 20
21 21 $this->database->query($alterQuery);
22 22
23 - $updateQuery = "UPDATE `$userGroupTable` SET `read_access` = 'group', `write_access` = 'group'";
23 + $updateQuery = "UPDATE $userGroupTable SET read_access = 'group', write_access = 'group'";
24 24 $success = $this->database->query($updateQuery) !== false;
25 25
26 - $selectQuery = "SHOW COLUMNS FROM `$userGroupTable` LIKE 'ip_range'";
26 + $selectQuery = "SHOW columns FROM $userGroupTable LIKE 'ip_range'";
27 27 $dbIpRange = (string) $this->database->getVariable($selectQuery);
28 28
29 29 if ($dbIpRange !== 'ip_range') {
30 - $alterQuery = "ALTER TABLE `$userGroupTable` ADD `ip_range` MEDIUMTEXT NULL DEFAULT ''";
30 + $alterQuery = "ALTER TABLE $userGroupTable ADD ip_range MEDIUMTEXT NULL DEFAULT ''";
31 31 $success = $this->database->query($alterQuery) !== false;
32 32 }
33 33
34 34 return $success;
@@ -39,12 +39,12 @@
39 39 */
40 40 private function getObjectSelectQuery(string $objectType, array $legacyTables): ?string
41 41 {
42 42 if ($this->objectHandler->isPostType($objectType) === true) {
43 - $source = '`' . $legacyTables['post'] . '`, `' . $this->database->getPostsTable() . '`';
43 + $source = $legacyTables['post'] . ', ' . $this->database->getPostsTable();
44 44
45 - return "SELECT `post_id` AS `id`, `group_id` AS `groupId` FROM $source"
46 - . " WHERE `post_id` = `ID` AND `post_type` = '$objectType'";
45 + return "SELECT post_id AS id, group_id AS groupId FROM $source"
46 + . " WHERE post_id = ID AND post_type = '$objectType'";
47 47 }
48 48
49 49 $idColumns = [
50 50 'category' => 'category_id',
@@ -55,28 +55,15 @@
55 55 if (isset($idColumns[$objectType]) === false) {
56 56 return null;
57 57 }
58 58
59 - return "SELECT `{$idColumns[$objectType]}` AS `id`, `group_id` AS `groupId`
60 - FROM `{$legacyTables[$objectType]}`";
59 + return "SELECT {$idColumns[$objectType]} AS id, group_id AS groupId FROM {$legacyTables[$objectType]}";
61 60 }
62 61
63 - /**
64 - * The object types whose assignments the legacy tables can hold. getObjectTypes() only
65 - * knows post types and taxonomies, so the user and role types have to be added for
66 - * their own legacy tables, whose rows would otherwise be dropped unmigrated.
67 - *
68 - * @return string[]
69 - */
70 - private function getMigratableObjectTypes(): array
71 - {
72 - return array_merge($this->objectHandler->getObjectTypes(), ['user', 'role']);
73 - }
74 -
75 62 private function updateToUserGroupToObjectTableUpdate(): bool
76 63 {
77 64 $prefix = $this->database->getPrefix();
78 - $charsetCollate = $this->database->getColumnCharset();
65 + $charsetCollate = $this->database->getCharset();
79 66 $userGroupToObject = $prefix . 'uam_accessgroup_to_object';
80 67 $legacyTables = [
81 68 'post' => $prefix . 'uam_accessgroup_to_post',
82 69 'user' => $prefix . 'uam_accessgroup_to_user',
@@ -83,10 +70,10 @@
83 70 'category' => $prefix . 'uam_accessgroup_to_category',
84 71 'role' => $prefix . 'uam_accessgroup_to_role'
85 72 ];
86 73
87 - $alterQuery = "ALTER TABLE `$userGroupToObject`
88 - CHANGE `object_id` `object_id` VARCHAR(64) $charsetCollate";
74 + $alterQuery = "ALTER TABLE '$userGroupToObject'
75 + CHANGE 'object_id' 'object_id' VARCHAR(64) $charsetCollate";
89 76 $success = $this->database->query($alterQuery) !== false;
90 77
91 78 if ($success === false) {
92 79 return false;
@@ -91,9 +78,9 @@
91 78 if ($success === false) {
92 79 return false;
93 80 }
94 81
95 - foreach ($this->getMigratableObjectTypes() as $objectType) {
82 + foreach ($this->objectHandler->getObjectTypes() as $objectType) {
96 83 $query = $this->getObjectSelectQuery($objectType, $legacyTables);
97 84
98 85 if ($query === null) {
99 86 continue;
@@ -108,12 +95,11 @@
108 95 'group_id' => $dbObject->groupId,
109 96 'object_id' => $dbObject->id,
110 97 'object_type' => $objectType
111 98 ],
112 - // All three are strings, roles carry their name as the object id.
113 99 [
114 - '%s',
115 - '%s',
100 + '%d',
101 + '%d',
116 102 '%s'
117 103 ]
118 104 );
119 105 $success = $success && $insert !== false;
@@ -119,9 +105,9 @@
119 105 $success = $success && $insert !== false;
120 106 }
121 107 }
122 108
123 - $dropQuery = 'DROP TABLE IF EXISTS `' . implode('`, `', $legacyTables) . '`';
109 + $dropQuery = 'DROP TABLE ' . implode(', ', $legacyTables);
124 110
125 111 return $success && $this->database->query($dropQuery) !== false;
126 112 }
127 113