PluginProbe
User Access Manager / 2.2.25
User Access Manager v2.2.25
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 +55 -12 2.3.172.2.25 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * DatabaseUpdate1.php
4 + *
5 + * The DatabaseUpdate1 class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
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 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\Setup\Update;
@@ -5,15 +18,29 @@
5 18 namespace UserAccessManager\Setup\Update;
6 19
7 20 use UserAccessManager\Setup\Database\DatabaseUpdate;
8 21
22 +/**
23 + * Class DatabaseUpdate1
24 + *
25 + * @package UserAccessManager\Setup\Update
26 + */
9 27 class DatabaseUpdate1 extends DatabaseUpdate
10 28 {
29 + /**
30 + * Returns the version.
31 + * @return string
32 + */
11 33 public function getVersion(): string
12 34 {
13 35 return '1.0';
14 36 }
15 37
38 + /**
39 + * Updates the user group table to version 1.0.
40 + * @param string $userGroupTable
41 + * @return bool
42 + */
16 43 private function updateToUserGroupTableUpdate(string $userGroupTable): bool
17 44 {
18 45 $alterQuery = "ALTER TABLE {$userGroupTable}
19 46 ADD read_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'";
55 + $selectQuery = "SHOW columns FROM {$userGroupTable} LIKE 'ip_range'";
29 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,8 +62,17 @@
35 62
36 63 return $success;
37 64 }
38 65
66 + /**
67 + * Returns the select query for the object type.
68 + * @param string $objectType
69 + * @param string $userGroupToPost
70 + * @param string $userGroupToCategory
71 + * @param string $userGroupToUser
72 + * @param string $userGroupToRole
73 + * @return null|string
74 + */
39 75 private function getObjectSelectQuery(
40 76 string $objectType,
41 77 string $userGroupToPost,
42 78 string $userGroupToCategory,
@@ -47,9 +83,9 @@
47 83
48 84 if ($this->objectHandler->isPostType($objectType) === true) {
49 85 $dbIdName = 'post_id';
50 86 $database = $userGroupToPost . ', ' . $this->database->getPostsTable();
51 - $addition = " WHERE post_id = ID AND post_type = '$objectType'";
87 + $addition = " WHERE post_id = ID AND post_type = '{$objectType}'";
52 88 } elseif ($objectType === 'category') {
53 89 $dbIdName = 'category_id';
54 90 $database = $userGroupToCategory;
55 91 } elseif ($objectType === 'user') {
@@ -61,11 +97,14 @@
61 97 } else {
62 98 return null;
63 99 }
64 100
65 - return "SELECT $dbIdName AS id, group_id AS groupId FROM $database $addition";
101 + return "SELECT {$dbIdName} AS id, group_id AS groupId FROM {$database} {$addition}";
66 102 }
67 103
104 + /**
105 + * Updates the user group to object table to version 1.0.
106 + */
68 107 private function updateToUserGroupToObjectTableUpdate(): bool
69 108 {
70 109 $prefix = $this->database->getPrefix();
71 110
@@ -75,10 +114,10 @@
75 114 $userGroupToUser = $prefix . 'uam_accessgroup_to_user';
76 115 $userGroupToCategory = $prefix . 'uam_accessgroup_to_category';
77 116 $userGroupToRole = $prefix . 'uam_accessgroup_to_role';
78 117
79 - $alterQuery = "ALTER TABLE '$userGroupToObject'
80 - CHANGE 'object_id' 'object_id' VARCHAR(64) $charsetCollate";
118 + $alterQuery = "ALTER TABLE '{$userGroupToObject}'
119 + CHANGE 'object_id' 'object_id' VARCHAR(64) {$charsetCollate}";
81 120 $success = $this->database->query($alterQuery) !== false;
82 121
83 122 if ($success === false) {
84 123 return false;
@@ -118,21 +157,25 @@
118 157 $success = $success && $insert !== false;
119 158 }
120 159 }
121 160
122 - $dropQuery = "DROP TABLE $userGroupToPost,
123 - $userGroupToUser,
124 - $userGroupToCategory,
125 - $userGroupToRole";
161 + $dropQuery = "DROP TABLE {$userGroupToPost},
162 + {$userGroupToUser},
163 + {$userGroupToCategory},
164 + {$userGroupToRole}";
126 165
127 166 return $success && $this->database->query($dropQuery) !== false;
128 167 }
129 168
169 + /**
170 + * Executes the update.
171 + * @return bool
172 + */
130 173 public function update(): bool
131 174 {
132 175 $success = true;
133 176 $userGroupTable = $this->database->getUserGroupTable();
134 - $dbUserGroup = $this->database->getVariable("SHOW TABLES LIKE '$userGroupTable'");
177 + $dbUserGroup = $this->database->getVariable("SHOW TABLES LIKE '{$userGroupTable}'");
135 178
136 179 if ($dbUserGroup === $userGroupTable) {
137 180 $success = $this->updateToUserGroupTableUpdate($userGroupTable);
138 181 }