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
user-access-manager / src / Setup / Update / DatabaseUpdate4.php

DatabaseUpdate4.php in User Access Manager 2.3.18, at src/Setup/Update/DatabaseUpdate4.php

49 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Setup\Update;
6
7 use UserAccessManager\Object\ObjectHandler;
8
9 class DatabaseUpdate4 extends DatabaseUpdate
10 {
11 public function getVersion(): string
12 {
13 return '1.4.1';
14 }
15
16 public function update(): bool
17 {
18 $dbAccessGroupToObject = $this->database->getUserGroupToObjectTable();
19 $alterQuery = "ALTER TABLE {$dbAccessGroupToObject}
20 ADD general_object_type VARCHAR(64) NOT NULL AFTER object_id";
21
22 $success = $this->database->query($alterQuery) !== false;
23
24 $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
32 foreach ($objectTypeConditions as $generalObjectType => $condition) {
33 $query = "UPDATE {$dbAccessGroupToObject}
34 SET general_object_type = '$generalObjectType'
35 WHERE $condition";
36
37 $success = $success && $this->database->query($query) !== false;
38 }
39
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'";
45
46 return $success && $this->database->query($query) !== false;
47 }
48 }
49