PluginProbe
User Access Manager / 2.3.13
User Access Manager v2.3.13
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/DatabaseUpdate4.php +40 -19 trunk2.3.13 View file →
@@ -4,8 +4,9 @@
4 4
5 5 namespace UserAccessManager\Setup\Update;
6 6
7 7 use UserAccessManager\Object\ObjectHandler;
8 +use UserAccessManager\Setup\Database\DatabaseUpdate;
8 9
9 10 class DatabaseUpdate4 extends DatabaseUpdate
10 11 {
11 12 public function getVersion(): string
@@ -15,34 +16,54 @@
15 16
16 17 public function update(): bool
17 18 {
18 19 $dbAccessGroupToObject = $this->database->getUserGroupToObjectTable();
19 - $alterQuery = "ALTER TABLE `{$dbAccessGroupToObject}`
20 - ADD `general_object_type` VARCHAR(64) NOT NULL AFTER `object_id`";
20 + $alterQuery = "ALTER TABLE {$dbAccessGroupToObject}
21 + ADD general_object_type VARCHAR(64) NOT NULL AFTER object_id";
21 22
22 23 $success = $this->database->query($alterQuery) !== false;
23 24
25 + // Update post entries
26 + $generalPostType = ObjectHandler::GENERAL_POST_OBJECT_TYPE;
27 +
28 + $query = "UPDATE {$dbAccessGroupToObject}
29 + SET general_object_type = '$generalPostType'
30 + WHERE object_type IN ('post', 'page', 'attachment')";
31 +
32 + $success = $success && $this->database->query($query) !== false;
33 +
34 + // Update role entries
35 + $generalRoleType = ObjectHandler::GENERAL_ROLE_OBJECT_TYPE;
36 +
37 + $query = "UPDATE {$dbAccessGroupToObject}
38 + SET general_object_type = '$generalRoleType'
39 + WHERE object_type = 'role'";
40 +
41 + $success = $success && $this->database->query($query) !== false;
42 +
43 + // Update user entries
44 + $generalUserType = ObjectHandler::GENERAL_USER_OBJECT_TYPE;
45 +
46 + $query = "UPDATE {$dbAccessGroupToObject}
47 + SET general_object_type = '$generalUserType'
48 + WHERE object_type = 'user'";
49 +
50 + $success = $success && $this->database->query($query) !== false;
51 +
52 + // Update term entries
24 53 $generalTermType = ObjectHandler::GENERAL_TERM_OBJECT_TYPE;
25 - $objectTypeConditions = [
26 - ObjectHandler::GENERAL_POST_OBJECT_TYPE => "`object_type` IN ('post', 'page', 'attachment')",
27 - ObjectHandler::GENERAL_ROLE_OBJECT_TYPE => "`object_type` = 'role'",
28 - ObjectHandler::GENERAL_USER_OBJECT_TYPE => "`object_type` = 'user'",
29 - $generalTermType => "`object_type` = 'term'"
30 - ];
31 54
32 - foreach ($objectTypeConditions as $generalObjectType => $condition) {
33 - $query = "UPDATE `{$dbAccessGroupToObject}`
34 - SET `general_object_type` = '$generalObjectType'
35 - WHERE $condition";
55 + $query = "UPDATE {$dbAccessGroupToObject}
56 + SET general_object_type = '$generalTermType'
57 + WHERE object_type = 'term'";
36 58
37 - $success = $success && $this->database->query($query) !== false;
38 - }
59 + $success = $success && $this->database->query($query) !== false;
39 60
40 - $query = "UPDATE `$dbAccessGroupToObject` AS `gto`
41 - LEFT JOIN `{$this->database->getTermTaxonomyTable()}` AS `tt`
42 - ON `gto`.`object_id` = `tt`.`term_id`
43 - SET `gto`.`object_type` = `tt`.`taxonomy`
44 - WHERE `gto`.`general_object_type` = '$generalTermType'";
61 + $query = "UPDATE $dbAccessGroupToObject AS gto
62 + LEFT JOIN {$this->database->getTermTaxonomyTable()} AS tt
63 + ON gto.object_id = tt.term_id
64 + SET gto.object_type = tt.taxonomy
65 + WHERE gto.general_object_type = '$generalTermType'";
45 66
46 67 return $success && $this->database->query($query) !== false;
47 68 }
48 69 }