PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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 +79 -33 2.3.16 → 2.1.11 View file →
@@ -1,20 +1,47 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * DatabaseUpdate1.php
4 + *
5 + * The DatabaseUpdate1 class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
5 15 namespace UserAccessManager\Setup\Update;
6 16
7 17 use UserAccessManager\Setup\Database\DatabaseUpdate;
8 18
19 +/**
20 + * Class DatabaseUpdate1
21 + *
22 + * @package UserAccessManager\Setup\Update
23 + */
9 24 class DatabaseUpdate1 extends DatabaseUpdate
10 25 {
11 - public function getVersion(): string
26 + /**
27 + * Returns the version.
28 + *
29 + * @return string
30 + */
31 + public function getVersion()
12 32 {
13 33 return '1.0';
14 34 }
15 35
16 - private function updateToUserGroupTableUpdate(string $userGroupTable): bool
36 + /**
37 + * Updates the user group table to version 1.0.
38 + *
39 + * @param string $userGroupTable
40 + *
41 + * @return bool
42 + */
43 + private function updateToUserGroupTableUpdate($userGroupTable)
17 44 {
18 45 $alterQuery = "ALTER TABLE {$userGroupTable}
19 46 ADD read_access TINYTEXT NOT NULL DEFAULT '',
20 47 ADD write_access TINYTEXT NOT NULL DEFAULT '',
@@ -21,16 +48,16 @@
21 48 ADD ip_range MEDIUMTEXT NULL DEFAULT ''";
22 49
23 50 $this->database->query($alterQuery);
24 51
25 - $updateQuery = "UPDATE $userGroupTable SET read_access = 'group', write_access = 'group'";
52 + $updateQuery = "UPDATE {$userGroupTable} SET read_access = 'group', write_access = 'group'";
26 53 $success = $this->database->query($updateQuery) !== false;
27 54
28 - $selectQuery = "SHOW columns FROM $userGroupTable LIKE 'ip_range'";
29 - $dbIpRange = (string) $this->database->getVariable($selectQuery);
55 + $selectQuery = "SHOW columns FROM {$userGroupTable} LIKE 'ip_range'";
56 + $dbIpRange = (string)$this->database->getVariable($selectQuery);
30 57
31 58 if ($dbIpRange !== 'ip_range') {
32 - $alterQuery = "ALTER TABLE $userGroupTable ADD ip_range MEDIUMTEXT NULL DEFAULT ''";
59 + $alterQuery = "ALTER TABLE {$userGroupTable} ADD ip_range MEDIUMTEXT NULL DEFAULT ''";
33 60 $success = $this->database->query($alterQuery) !== false;
34 61 }
35 62
36 63 return $success;
@@ -35,21 +62,32 @@
35 62
36 63 return $success;
37 64 }
38 65
66 + /**
67 + * Returns the select query for the object type.
68 + *
69 + * @param string $objectType
70 + * @param string $userGroupToPost
71 + * @param string $userGroupToCategory
72 + * @param string $userGroupToUser
73 + * @param string $userGroupToRole
74 + *
75 + * @return null|string
76 + */
39 77 private function getObjectSelectQuery(
40 - string $objectType,
41 - string $userGroupToPost,
42 - string $userGroupToCategory,
43 - string $userGroupToUser,
44 - string $userGroupToRole
45 - ): ?string {
78 + $objectType,
79 + $userGroupToPost,
80 + $userGroupToCategory,
81 + $userGroupToUser,
82 + $userGroupToRole
83 + ) {
46 84 $addition = '';
47 85
48 86 if ($this->objectHandler->isPostType($objectType) === true) {
49 87 $dbIdName = 'post_id';
50 - $database = $userGroupToPost . ', ' . $this->database->getPostsTable();
51 - $addition = " WHERE post_id = ID AND post_type = '$objectType'";
88 + $database = $userGroupToPost.', '.$this->database->getPostsTable();
89 + $addition = " WHERE post_id = ID AND post_type = '{$objectType}'";
52 90 } elseif ($objectType === 'category') {
53 91 $dbIdName = 'category_id';
54 92 $database = $userGroupToCategory;
55 93 } elseif ($objectType === 'user') {
@@ -61,24 +99,27 @@
61 99 } else {
62 100 return null;
63 101 }
64 102
65 - return "SELECT $dbIdName AS id, group_id AS groupId FROM $database $addition";
103 + return "SELECT {$dbIdName} AS id, group_id AS groupId FROM {$database} {$addition}";
66 104 }
67 105
68 - private function updateToUserGroupToObjectTableUpdate(): bool
106 + /**
107 + * Updates the user group to object table to version 1.0.
108 + */
109 + private function updateToUserGroupToObjectTableUpdate()
69 110 {
70 111 $prefix = $this->database->getPrefix();
71 112
72 113 $charsetCollate = $this->database->getCharset();
73 - $userGroupToObject = $prefix . 'uam_accessgroup_to_object';
74 - $userGroupToPost = $prefix . 'uam_accessgroup_to_post';
75 - $userGroupToUser = $prefix . 'uam_accessgroup_to_user';
76 - $userGroupToCategory = $prefix . 'uam_accessgroup_to_category';
77 - $userGroupToRole = $prefix . 'uam_accessgroup_to_role';
114 + $userGroupToObject = $prefix.'uam_accessgroup_to_object';
115 + $userGroupToPost = $prefix.'uam_accessgroup_to_post';
116 + $userGroupToUser = $prefix.'uam_accessgroup_to_user';
117 + $userGroupToCategory = $prefix.'uam_accessgroup_to_category';
118 + $userGroupToRole = $prefix.'uam_accessgroup_to_role';
78 119
79 - $alterQuery = "ALTER TABLE '$userGroupToObject'
80 - CHANGE 'object_id' 'object_id' VARCHAR(64) $charsetCollate";
120 + $alterQuery = "ALTER TABLE '{$userGroupToObject}'
121 + CHANGE 'object_id' 'object_id' VARCHAR(64) {$charsetCollate}";
81 122 $success = $this->database->query($alterQuery) !== false;
82 123
83 124 if ($success === false) {
84 125 return false;
@@ -98,9 +139,9 @@
98 139 if ($query === null) {
99 140 continue;
100 141 }
101 142
102 - $dbObjects = (array) $this->database->getResults($query);
143 + $dbObjects = (array)$this->database->getResults($query);
103 144
104 145 foreach ($dbObjects as $dbObject) {
105 146 $insert = $this->database->insert(
106 147 $userGroupToObject,
@@ -118,21 +159,26 @@
118 159 $success = $success && $insert !== false;
119 160 }
120 161 }
121 162
122 - $dropQuery = "DROP TABLE $userGroupToPost,
123 - $userGroupToUser,
124 - $userGroupToCategory,
125 - $userGroupToRole";
163 + $dropQuery = "DROP TABLE {$userGroupToPost},
164 + {$userGroupToUser},
165 + {$userGroupToCategory},
166 + {$userGroupToRole}";
126 167
127 168 return $success && $this->database->query($dropQuery) !== false;
128 169 }
129 170
130 - public function update(): bool
171 + /**
172 + * Executes the update.
173 + *
174 + * @return bool
175 + */
176 + public function update()
131 177 {
132 178 $success = true;
133 179 $userGroupTable = $this->database->getUserGroupTable();
134 - $dbUserGroup = $this->database->getVariable("SHOW TABLES LIKE '$userGroupTable'");
180 + $dbUserGroup = $this->database->getVariable("SHOW TABLES LIKE '{$userGroupTable}'");
135 181
136 182 if ($dbUserGroup === $userGroupTable) {
137 183 $success = $this->updateToUserGroupTableUpdate($userGroupTable);
138 184 }