| @@ -1,5 +1,18 @@ | ||
| 1 | 1 | <?php |
| 2 | +/** | |
| 3 | + * DatabaseUpdate4.php | |
| 4 | + * | |
| 5 | + * The DatabaseUpdate4 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; |
| @@ -4,45 +17,81 @@ | ||
| 4 | 17 | |
| 5 | 18 | namespace UserAccessManager\Setup\Update; |
| 6 | 19 | |
| 7 | 20 | use UserAccessManager\Object\ObjectHandler; |
| 21 | +use UserAccessManager\Setup\Database\DatabaseUpdate; | |
| 8 | 22 | |
| 23 | +/** | |
| 24 | + * Class DatabaseUpdate4 | |
| 25 | + * | |
| 26 | + * @package UserAccessManager\Setup\Update | |
| 27 | + */ | |
| 9 | 28 | class DatabaseUpdate4 extends DatabaseUpdate |
| 10 | 29 | { |
| 30 | + /** | |
| 31 | + * Returns the version. | |
| 32 | + * @return string | |
| 33 | + */ | |
| 11 | 34 | public function getVersion(): string |
| 12 | 35 | { |
| 13 | 36 | return '1.4.1'; |
| 14 | 37 | } |
| 15 | 38 | |
| 39 | + /** | |
| 40 | + * Executes the update. | |
| 41 | + * @return bool | |
| 42 | + */ | |
| 16 | 43 | public function update(): bool |
| 17 | 44 | { |
| 45 | + $success = true; | |
| 46 | + | |
| 18 | 47 | $dbAccessGroupToObject = $this->database->getUserGroupToObjectTable(); |
| 19 | 48 | $alterQuery = "ALTER TABLE {$dbAccessGroupToObject} |
| 20 | 49 | ADD general_object_type VARCHAR(64) NOT NULL AFTER object_id"; |
| 21 | 50 | |
| 22 | - $success = $this->database->query($alterQuery) !== false; | |
| 51 | + $success = $success && $this->database->query($alterQuery) !== false; | |
| 23 | 52 | |
| 53 | + // Update post entries | |
| 54 | + $generalPostType = ObjectHandler::GENERAL_POST_OBJECT_TYPE; | |
| 55 | + | |
| 56 | + $query = "UPDATE {$dbAccessGroupToObject} | |
| 57 | + SET general_object_type = '{$generalPostType}' | |
| 58 | + WHERE object_type IN ('post', 'page', 'attachment')"; | |
| 59 | + | |
| 60 | + $success = $success && $this->database->query($query) !== false; | |
| 61 | + | |
| 62 | + // Update role entries | |
| 63 | + $generalRoleType = ObjectHandler::GENERAL_ROLE_OBJECT_TYPE; | |
| 64 | + | |
| 65 | + $query = "UPDATE {$dbAccessGroupToObject} | |
| 66 | + SET general_object_type = '{$generalRoleType}' | |
| 67 | + WHERE object_type = 'role'"; | |
| 68 | + | |
| 69 | + $success = $success && $this->database->query($query) !== false; | |
| 70 | + | |
| 71 | + // Update user entries | |
| 72 | + $generalUserType = ObjectHandler::GENERAL_USER_OBJECT_TYPE; | |
| 73 | + | |
| 74 | + $query = "UPDATE {$dbAccessGroupToObject} | |
| 75 | + SET general_object_type = '{$generalUserType}' | |
| 76 | + WHERE object_type = 'user'"; | |
| 77 | + | |
| 78 | + $success = $success && $this->database->query($query) !== false; | |
| 79 | + | |
| 80 | + // Update term entries | |
| 24 | 81 | $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 | 82 | |
| 32 | - foreach ($objectTypeConditions as $generalObjectType => $condition) { | |
| 33 | - $query = "UPDATE {$dbAccessGroupToObject} | |
| 34 | - SET general_object_type = '$generalObjectType' | |
| 35 | - WHERE $condition"; | |
| 83 | + $query = "UPDATE {$dbAccessGroupToObject} | |
| 84 | + SET general_object_type = '{$generalTermType}' | |
| 85 | + WHERE object_type = 'term'"; | |
| 36 | 86 | |
| 37 | - $success = $success && $this->database->query($query) !== false; | |
| 38 | - } | |
| 87 | + $success = $success && $this->database->query($query) !== false; | |
| 39 | 88 | |
| 40 | - $query = "UPDATE $dbAccessGroupToObject AS gto | |
| 89 | + $query = "UPDATE {$dbAccessGroupToObject} AS gto | |
| 41 | 90 | LEFT JOIN {$this->database->getTermTaxonomyTable()} AS tt |
| 42 | 91 | ON gto.object_id = tt.term_id |
| 43 | 92 | SET gto.object_type = tt.taxonomy |
| 44 | - WHERE gto.general_object_type = '$generalTermType'"; | |
| 93 | + WHERE gto.general_object_type = '{$generalTermType}'"; | |
| 45 | 94 | |
| 46 | 95 | return $success && $this->database->query($query) !== false; |
| 47 | 96 | } |
| 48 | 97 | } |