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/Controller/Backend/SetupController.php +92 -31 2.3.16 → 2.1.11 View file →
@@ -1,50 +1,95 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * SetupController.php
4 + *
5 + * The SetupController 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\Controller\Backend;
6 16
7 17 use UserAccessManager\Config\WordpressConfig;
8 18 use UserAccessManager\Controller\Controller;
9 19 use UserAccessManager\Database\Database;
10 -use UserAccessManager\Setup\Database\MissingColumnsException;
11 20 use UserAccessManager\Setup\SetupHandler;
12 21 use UserAccessManager\UserAccessManager;
13 22 use UserAccessManager\Wrapper\Php;
14 23 use UserAccessManager\Wrapper\Wordpress;
15 24
25 +/**
26 + * Class SetupController
27 + *
28 + * @package UserAccessManager\Controller
29 + */
16 30 class SetupController extends Controller
17 31 {
18 - public const SETUP_UPDATE_NONCE = 'uamSetupUpdate';
19 - public const SETUP_REVERT_NONCE = 'uamSetupRevert';
20 - public const SETUP_REPAIR_NONCE = 'uamSetupRepair';
21 - public const SETUP_DELETE_BACKUP_NONCE = 'uamSetupDeleteBackup';
22 - public const SETUP_RESET_NONCE = 'uamSetupReset';
23 - public const UPDATE_BLOG = 'blog';
24 - public const UPDATE_NETWORK = 'network';
32 + const SETUP_UPDATE_NONCE = 'uamSetupUpdate';
33 + const SETUP_REVERT_NONCE = 'uamSetupRevert';
34 + const SETUP_REPAIR_NONCE = 'uamSetupRepair';
35 + const SETUP_DELETE_BACKUP_NONCE = 'uamSetupDeleteBackup';
36 + const SETUP_RESET_NONCE = 'uamSetupReset';
37 + const UPDATE_BLOG = 'blog';
38 + const UPDATE_NETWORK = 'network';
25 39
26 - protected ?string $template = 'AdminSetup.php';
40 + /**
41 + * @var string
42 + */
43 + protected $template = 'AdminSetup.php';
27 44
45 + /**
46 + * @var SetupHandler
47 + */
48 + private $setupHandler;
49 +
50 + /**
51 + * @var Database
52 + */
53 + private $database;
54 +
55 + /**
56 + * SetupController constructor.
57 + *
58 + * @param Php $php
59 + * @param Wordpress $wordpress
60 + * @param WordpressConfig $wordpressConfig
61 + * @param Database $database
62 + * @param SetupHandler $setupHandler
63 + */
28 64 public function __construct(
29 65 Php $php,
30 66 Wordpress $wordpress,
31 67 WordpressConfig $wordpressConfig,
32 - private Database $database,
33 - private SetupHandler $setupHandler
68 + Database $database,
69 + SetupHandler $setupHandler
34 70 ) {
35 71 parent::__construct($php, $wordpress, $wordpressConfig);
72 + $this->database = $database;
73 + $this->setupHandler = $setupHandler;
36 74 }
37 75
38 76 /**
39 - * @throws MissingColumnsException
77 + * Returns if a database update is necessary.
78 + *
79 + * @return bool
40 80 */
41 - public function isDatabaseUpdateNecessary(): bool
81 + public function isDatabaseUpdateNecessary()
42 82 {
43 83 return $this->setupHandler->getDatabaseHandler()->isDatabaseUpdateNecessary();
44 84 }
45 85
46 - public function showNetworkUpdate(): bool
86 + /**
87 + * Checks if a network update is nessary.
88 + *
89 + * @return bool
90 + */
91 + public function showNetworkUpdate()
47 92 {
48 93 return $this->wordpress->isSuperAdmin() === true
49 94 && defined('MULTISITE') === true && MULTISITE === true
50 95 && defined('WP_ALLOW_MULTISITE') === true && WP_ALLOW_MULTISITE === true;
@@ -49,19 +94,27 @@
49 94 && defined('MULTISITE') === true && MULTISITE === true
50 95 && defined('WP_ALLOW_MULTISITE') === true && WP_ALLOW_MULTISITE === true;
51 96 }
52 97
53 - public function getBackups(): array
98 + /**
99 + * Returns the existing backups
100 + *
101 + * @return array
102 + */
103 + public function getBackups()
54 104 {
55 105 return $this->setupHandler->getDatabaseHandler()->getBackups();
56 106 }
57 107
58 - public function updateDatabaseAction(): void
108 + /**
109 + * The database update action.
110 + */
111 + public function updateDatabaseAction()
59 112 {
60 113 $success = true;
61 114 $this->verifyNonce(self::SETUP_UPDATE_NONCE);
62 115 $update = $this->getRequestParameter('uam_update_db');
63 - $backup = (bool) $this->getRequestParameter('uam_backup_db', false);
116 + $backup = (bool)$this->getRequestParameter('uam_backup_db', false);
64 117
65 118 if ($update === self::UPDATE_BLOG || $update === self::UPDATE_NETWORK) {
66 119 $currentBlogId = $this->database->getCurrentBlogId();
67 120 $blogIds = ($update === self::UPDATE_NETWORK) ? $this->setupHandler->getBlogIds() : [$currentBlogId];
@@ -76,14 +129,17 @@
76 129 $success = $success && $this->setupHandler->update();
77 130 $this->wordpress->restoreCurrentBlog();
78 131 }
79 132
80 - $message = $success === true ? TXT_UAM_UAM_DB_UPDATE_SUCCESS : TXT_UAM_UAM_DB_UPDATE_FAILURE;
81 - $this->setUpdateMessage($message);
133 + $message = $success === true ? TXT_UAM_UAM_DB_UPDATE_SUCCESS : TXT_UAM_UAM_DB_UPDATE_FAILURE;
134 + $this->setUpdateMessage($message);
82 135 }
83 136 }
84 137
85 - public function revertDatabaseAction(): void
138 + /**
139 + * Reverts the database to the given version.
140 + */
141 + public function revertDatabaseAction()
86 142 {
87 143 $this->verifyNonce(self::SETUP_REVERT_NONCE);
88 144 $version = $this->getRequestParameter('uam_revert_database');
89 145
@@ -92,11 +148,13 @@
92 148 }
93 149 }
94 150
95 151 /**
96 - * @throws MissingColumnsException
152 + * Checks if the database is broken.
153 + *
154 + * @return bool
97 155 */
98 - public function isDatabaseBroken(): bool
156 + public function isDatabaseBroken()
99 157 {
100 158 $information = $this->setupHandler->getDatabaseHandler()->getCorruptedDatabaseInformation();
101 159
102 160 $numberOfIssues = array_reduce(
@@ -110,11 +168,11 @@
110 168 return $numberOfIssues > 0;
111 169 }
112 170
113 171 /**
114 - * @throws MissingColumnsException
172 + * Repairs the database.
115 173 */
116 - public function repairDatabaseAction(): void
174 + public function repairDatabaseAction()
117 175 {
118 176 $this->verifyNonce(self::SETUP_REPAIR_NONCE);
119 177
120 178 $databaseHandler = $this->setupHandler->getDatabaseHandler();
@@ -129,12 +187,15 @@
129 187 $this->wordpress->updateOption('uam_db_version', UserAccessManager::DB_VERSION);
130 188 }
131 189 }
132 190
133 - public function deleteDatabaseBackupAction(): void
191 + /**
192 + * Deletes the given database backup.
193 + */
194 + public function deleteDatabaseBackupAction()
134 195 {
135 196 $this->verifyNonce(self::SETUP_DELETE_BACKUP_NONCE);
136 - $version = (string) $this->getRequestParameter('uam_delete_backup');
197 + $version = $this->getRequestParameter('uam_delete_backup');
137 198
138 199 if ($this->setupHandler->getDatabaseHandler()->deleteBackup($version) === true) {
139 200 $this->setUpdateMessage(TXT_UAM_DELETE_DATABASE_BACKUP_SUCCESS);
140 201 }
@@ -140,11 +201,11 @@
140 201 }
141 202 }
142 203
143 204 /**
144 - * @throws MissingColumnsException
205 + * The reset action.
145 206 */
146 - public function resetUamAction(): void
207 + public function resetUamAction()
147 208 {
148 209 $this->verifyNonce(self::SETUP_RESET_NONCE);
149 210 $reset = $this->getRequestParameter('uam_reset');
150 211