PluginProbe
User Access Manager / 2.1.3
User Access Manager v2.1.3
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 / Controller / Backend / SetupController.php

SetupController.php in User Access Manager 2.1.3, at src/Controller/Backend/SetupController.php

176 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * SetupController.php
4 *
5 * The SetupController 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 */
15 namespace UserAccessManager\Controller\Backend;
16
17 use UserAccessManager\Config\WordpressConfig;
18 use UserAccessManager\Controller\Controller;
19 use UserAccessManager\Database\Database;
20 use UserAccessManager\Setup\SetupHandler;
21 use UserAccessManager\Wrapper\Php;
22 use UserAccessManager\Wrapper\Wordpress;
23
24 /**
25 * Class SetupController
26 *
27 * @package UserAccessManager\Controller
28 */
29 class SetupController extends Controller
30 {
31 const SETUP_UPDATE_NONCE = 'uamSetupUpdate';
32 const SETUP_REVERT_NONCE = 'uamSetupRevert';
33 const SETUP_DELETE_BACKUP_NONCE = 'uamSetupDeleteBackup';
34 const SETUP_RESET_NONCE = 'uamSetupReset';
35 const UPDATE_BLOG = 'blog';
36 const UPDATE_NETWORK = 'network';
37
38 /**
39 * @var string
40 */
41 protected $template = 'AdminSetup.php';
42
43 /**
44 * @var SetupHandler
45 */
46 private $setupHandler;
47
48 /**
49 * @var Database
50 */
51 private $database;
52
53 /**
54 * SetupController constructor.
55 *
56 * @param Php $php
57 * @param Wordpress $wordpress
58 * @param WordpressConfig $wordpressConfig
59 * @param Database $database
60 * @param SetupHandler $setupHandler
61 */
62 public function __construct(
63 Php $php,
64 Wordpress $wordpress,
65 WordpressConfig $wordpressConfig,
66 Database $database,
67 SetupHandler $setupHandler
68 ) {
69 parent::__construct($php, $wordpress, $wordpressConfig);
70 $this->database = $database;
71 $this->setupHandler = $setupHandler;
72 }
73
74 /**
75 * Returns if a database update is necessary.
76 *
77 * @return bool
78 */
79 public function isDatabaseUpdateNecessary()
80 {
81 return $this->setupHandler->isDatabaseUpdateNecessary();
82 }
83
84 /**
85 * Checks if a network update is nessary.
86 *
87 * @return bool
88 */
89 public function showNetworkUpdate()
90 {
91 return $this->wordpress->isSuperAdmin() === true
92 && defined('MULTISITE') === true && MULTISITE === true
93 && defined('WP_ALLOW_MULTISITE') === true && WP_ALLOW_MULTISITE === true;
94 }
95
96 /**
97 * Returns the existing backups
98 *
99 * @return array
100 */
101 public function getBackups()
102 {
103 return $this->setupHandler->getBackups();
104 }
105
106 /**
107 * The database update action.
108 */
109 public function updateDatabaseAction()
110 {
111 $this->verifyNonce(self::SETUP_UPDATE_NONCE);
112 $update = $this->getRequestParameter('uam_update_db');
113 $backup = (bool)$this->getRequestParameter('uam_backup_db', false);
114
115 if ($update === self::UPDATE_BLOG || $update === self::UPDATE_NETWORK) {
116 $currentBlogId = $this->database->getCurrentBlogId();
117 $blogIds = ($update === self::UPDATE_NETWORK) ? $this->setupHandler->getBlogIds() : [$currentBlogId];
118 $currentBlogId = $this->database->getCurrentBlogId();
119
120 foreach ($blogIds as $blogId) {
121 $this->wordpress->switchToBlog($blogId);
122
123 if ($backup === true) {
124 $this->setupHandler->backupDatabase();
125 }
126
127 $this->setupHandler->update();
128 }
129
130 $this->wordpress->switchToBlog($currentBlogId);
131 $this->setUpdateMessage(TXT_UAM_UAM_DB_UPDATE_SUCCESS);
132 }
133 }
134
135 /**
136 * Reverts the database to the given version.
137 */
138 public function revertDatabaseAction()
139 {
140 $this->verifyNonce(self::SETUP_REVERT_NONCE);
141 $version = $this->getRequestParameter('uam_revert_database');
142
143 if ($this->setupHandler->revertDatabase($version) === true) {
144 $this->setUpdateMessage(TXT_UAM_REVERT_DATABASE_SUCCESS);
145 }
146 }
147
148 /**
149 * Deletes the given database backup.
150 */
151 public function deleteDatabaseBackupAction()
152 {
153 $this->verifyNonce(self::SETUP_DELETE_BACKUP_NONCE);
154 $version = $this->getRequestParameter('uam_delete_backup');
155
156 if ($this->setupHandler->deleteBackup($version) === true) {
157 $this->setUpdateMessage(TXT_UAM_DELETE_DATABASE_BACKUP_SUCCESS);
158 }
159 }
160
161 /**
162 * The reset action.
163 */
164 public function resetUamAction()
165 {
166 $this->verifyNonce(self::SETUP_RESET_NONCE);
167 $reset = $this->getRequestParameter('uam_reset');
168
169 if ($reset === 'reset') {
170 $this->setupHandler->uninstall();
171 $this->setupHandler->install(true);
172 $this->setUpdateMessage(TXT_UAM_UAM_RESET_SUCCESS);
173 }
174 }
175 }
176